寫博客或者看博客都能使我們的知識更加深刻,也能使我們知道很多新東西。就像這個題目中ns-3,
相信沒幾個人聽過,就是我也是幫同學了解畢設才知道的。工作中相信沒幾個人用到,但是新知識能
夠開闊我們的思維,這也是有些人學習新知識快的的原因。
ns-3 is a discrete-event(離散事件) network simulator for Internet systems,
targeted primarily for research and educational use.
官網:http://www.nsnam.org
也就是為研究用的,我感覺唯一的好處或者最大的好處就是學習C++了,
當然使用ns-3網絡通信知識必須懂得才行(汗,俺比較薄弱),ns-3基本上是c++,
當然還有python。所以想仿真模擬網絡通信可以用C++和python編寫,只是對python
支持不完整。ns-3也沒ns-2完善,但是對於畢設已經夠了。ns-3源碼包可以
在官網上下載,目前版本是NS-3.16。
我在ubuntu安裝除了有一點要注意的其他的沒有什么問題,我用的python2.7.3,我的系統默認
python就是python2.7.3。解壓ns-3源碼包后為ns-allinone-3.16,在終端切換到此根目錄下。
根據ns-3-tutorial.pdf中的介紹。在終端中輸入:
./build.py --enable-examples --enable-tests
#如果build.py沒加執行權限可以:
python build.py --enable-examples --enable-tests
ubuntu默認沒有g++,需要我們安裝,在終端輸入sudo apt-get install g++
要注意的是我的build時出錯了,錯誤中有“ascii”字樣。主要是系統安裝時語言選的是中文,
所以“Desktop”變成了“桌面”,由於python腳本對中文支持的原因,編碼出錯了。
在腳本中加入#-*- coding:utf-8 -*-可以解決。但是不想更改,就直接把ns-allinone-3.16
移動到用戶主目錄下算了,我就是這么干的。然后再輸入上面的build命令就OK了。
build時間不算長但也不短,然后在終端切換到ns-allinone-3.16目錄下的ns-3.16目錄中。
輸入./waf完成后。測試一下:
./test.py -c core
在終端會輸出類似這樣的信息:
PASS: TestSuite attributes PASS: TestSuite config PASS: TestSuite global-value PASS: TestSuite command-line PASS: TestSuite basic-random-number PASS: TestSuite object PASS: TestSuite random-number-generators 92 of 92 tests passed (92 passed, 0 failed, 0 crashed, 0 valgrind errors)
然后在終端輸入:
./waf --run hello-simulator
沒意外的話打印的是:
Hello Simulator
Congratulations. You are now an ns-3 user.(引用教程手冊的話)
官方支持的就是類unix系統,但是不是每個人都用,應該說大部分人都不用linux(我是小部分,呵呵)。
也有辦法,cygwin應該用過吧,它把linux上的東西移植到windows的,模擬linux環境的軟件。
中文站點:http://www.cygwin.cn 但是它僅僅提供了setup.exe。下載后需要在線安裝所需的包和工具。
怎樣使用google或者百度的啦,這不是本文的重點。運行setup.exe需要安裝gcc/g++/python不必說,還有各種
庫。盡量多選些。安好后在桌面上有一個叫“Cygwin Terminal”的圖表,打開后不用我說相信也知道是什么了吧,
之后的的工作就同ubuntu上build的過程一樣啦。
在ns-3.26/examples/tutorial目錄下提供了一些簡單的例子。終端當前目錄在ns-3.26下,我們可以:
cp examples/tutorial/first.cc scratch/
然后:
$ ./waf Waf: Entering directory `/cygdrive/c/Users/cf/Desktop/ns-allinone-3.16/ns-3.16/build' [ 720/1819] cxx: scratch/first.cc -> build/scratch/first.cc.1.o [ 721/1819] cxx: scratch/scratch-simulator.cc -> build/scratch/scratch-simulator.cc.2.o [ 722/1819] cxx: scratch/subdir/scratch-simulator-subdir.cc -> build/scratch/subdir/scratch-simulator-subdir.cc.3.o [1808/1819] cxxprogram: build/scratch/first.cc.1.o -> build/scratch/first.exe [1813/1819] cxxprogram: build/scratch/scratch-simulator.cc.2.o -> build/scratch/scratch-simulator.exe [1814/1819] cxxprogram: build/scratch/subdir/scratch-simulator-subdir.cc.3.o -> build/scratch/subdir/subdir.exe Waf: Leaving directory `/cygdrive/c/Users/cf/Desktop/ns-allinone-3.16/ns-3.16/build' 'build' finished successfully (28.098s)
最后運行:
$ ./waf --run scratch/first Waf: Entering directory `/cygdrive/c/Users/cf/Desktop/ns-allinone-3.16/ns-3.16/build' Waf: Leaving directory `/cygdrive/c/Users/cf/Desktop/ns-allinone-3.16/ns-3.16/build' 'build' finished successfully (6.926s) At time 2s client sent 1024 bytes to 10.1.1.2 port 9 At time 2.00369s server received 1024 bytes from 10.1.1.1 port 49153 At time 2.00369s server sent 1024 bytes to 10.1.1.1 port 49153 At time 2.00737s client received 1024 bytes from 10.1.1.2 port 9
后續有什么值得記錄的,還會繼續......
