1:下載NetAnim
ns3中并沒有下載NetAnim,可以使用下面的步驟下載。首先保證你已經(jīng)安裝了mercurial.最新的NetAnim可以使用下面的命令行下載:
$ hg clone http://code.nsnam.org/netanim
2:building netanim
Qt4(4.7以及以上版本)是build NetAnim必須的,使用下面的步驟來安裝:
Debian/Ubuntu linux版本:
$ apt-get install qt4-dev-tools
Red Hat/Fedora 版本:
$ yum install qt4
$ yum install qt4-devel
對(duì)于Mac/OSX用戶,請(qǐng)參考鏈接:http://qt.nokia.com/downloads
3:build 步驟
$ cd netanim
$ make clean
$ qmake NetAnim.pro (For MAC Users: qmake -spec macx-g++ NetAnim.pro)
$ make
Note:在某些系統(tǒng)中,qmake 可能需要使用qmake-qt4代替。
上面的命令完成之后,會(huì)在當(dāng)前目錄中生成一個(gè)“NetAnim”的文件,使用下面的命令查看:
$ ls -l NetAnim
-rwxr-xr-x 1 john john 390395 2012-05-22 08:32 NetAnim
用法:
第一步:產(chǎn)生xml文件
第二步:加載xml文件到NetAnim中。
添加頭文件:
#include "ns3/netanim-module.h"
【對(duì)于使用ns-3.13以前版本的,需要使用代碼:“anim.SetXMLOutput()”設(shè)置輸出XML模式,并使用“anim.StartAnimation()”啟動(dòng)】
第一步:產(chǎn)生XML文件
AnimationInterface anim("animation.xml"); 將會(huì)產(chǎn)生一個(gè)xml文件。
anim.SetMobilityPollInterval (Seconds (1));
AnimationInterface默認(rèn)250ms記錄一次所有節(jié)點(diǎn)的位置。這個(gè)方法設(shè)置了AnimationInterface記錄所有節(jié)點(diǎn)位置的時(shí)間間隔。如果節(jié)點(diǎn)的位置預(yù)料每次變化非常小,那么設(shè)置高流動(dòng)性輪訓(xùn)間隔將是非常有用的。否則,將會(huì)產(chǎn)生非常大的xml文件。
anim.SetConstantPosition (Ptr< Node > n, double x, double y);
AnimationInterface允許設(shè)置所有節(jié)點(diǎn)的位置。在ns3中,該設(shè)置與MobillityModel關(guān)聯(lián)。該方法是非??旖莸姆绞絹碓O(shè)置一個(gè)靜止的節(jié)點(diǎn)位置。
anim.SetStartTime (Seconds(150));
anim.SetStopTime (Seconds(150));
AnimationInterface會(huì)產(chǎn)生比較大的xml文件。上面的方法可以限制AnimationInterface記錄的時(shí)間窗口。這樣可以達(dá)到只關(guān)注于與仿真相關(guān)聯(lián)的部分,同時(shí)產(chǎn)生比較小的xml文件。
AnimationInterface anim ("animation.xml", 50000);
該構(gòu)造器保證產(chǎn)生的xml文件只記錄5000個(gè)packets。例如,如果AnimationInterface抓取到了150000個(gè)packets,使用這個(gè)構(gòu)造器可以產(chǎn)生三個(gè)文件
? animation.xml - containing the packet range 1-50000
? animation.xml-1 - containing the packet range 50001-100000
? animation.xml-2 - containing the packet range 100001-150000
anim.EnablePacketMetadata (true);
使用該方法,則AnimationInterface會(huì)在產(chǎn)生的xml文件中記錄每一個(gè)packet的元數(shù)據(jù)。記錄了元數(shù)據(jù)之后,可以使用比較簡(jiǎn)單的與每個(gè)packet相關(guān)的信息,這樣就方便NetAnim提供更好的統(tǒng)計(jì)和過濾,例如,TCP序列號(hào),源IP,目的地IP等。
CAUTION:使用這樣的屬性,將會(huì)導(dǎo)致比較大的XML文件產(chǎn)生。不要在使用Wimax links的時(shí)候使用該屬性。
anim.UpdateNodeDescription (5, "Access-point");
使用該方法,AnimationInterface將會(huì)把節(jié)點(diǎn)5標(biāo)記為“Access-point”文字。
anim.UpdateNodeSize (6, 1.5, 1.5);
使用該方法,AnimationInterface將會(huì)把節(jié)點(diǎn)大小縮放為1.5倍。NetAnim會(huì)自動(dòng)縮放視圖以適應(yīng)拓?fù)涞倪吔纭_@意味著,NetAnim會(huì)調(diào)整太大或者太小的節(jié)點(diǎn)。使用該方法允許你覆蓋NetAnim默認(rèn)的節(jié)點(diǎn)的size。
anim.UpdateNodeCounter (89, 7, 3.4);
該方法說明,AnimationInterface設(shè)置節(jié)點(diǎn)7的值為3.4 id==89。id=89的節(jié)點(diǎn)必須存在,須先使用AnimationInterface::AddNodeCounter方法設(shè)置之后,才能調(diào)用UpdateNodeCounter方法。實(shí)例用法請(qǐng)參考src/netanim/examples/resources_demo.cc
第二步:加載xml文件到NetAnim
1:假設(shè)NetAnim已經(jīng)build,命令行使用./NetAnim啟動(dòng)NetAnim。如果NetAnim不能啟動(dòng),請(qǐng)參考前面的內(nèi)容。
2:打開NetAnim之后,點(diǎn)擊File按鈕,選擇代碼產(chǎn)生的xml文件
3:點(diǎn)擊play綠色按鈕啟動(dòng)動(dòng)畫。
這里有可以參看的視頻:http://www.youtube.com/watch?v=tz_hUuNwFDs
Wiki
對(duì)于更多細(xì)節(jié)和安裝“NetAnim”的說明,以及使用NetAnim加載XML文件等信息,可以參看wiki地址:
http://www.nsnam.org/wiki/NetAnim