Ubuntu 13.10下安装ns-2.35及leach协议安装powered by Hong Sheng , Jiangsu university ,Zhenjiang583301743@Tue Nov 25 , 2013之所以选择基于linux的操作系统ubuntu来安装ns2,是因为我个人特别讨厌Microsoft 开发的基于windows的cygwin软件,此软件安装的时候不仅有各种错误,UI也不够友好。
而,有关ubuntu的安装,大家可以自行baidu或google之。
下面只讲解ns-2.35和leach协议的安装过程。
1. Ubuntu 13.10下ns-2.35安装step 1:下载ns2.35,/s/1h8rj0#dir/path=%2FNS解压,放在home/xx下,xx是你的用户名step 2:更新源包,终端输入:sudo apt-get updatestep 3:安装依赖包sudo apt-get install tcl8.5-dev tk8.5-devsudo apt-get install build-essential autoconf automakesudo apt-get install perl xgraph libxt-dev libx11-dev libxmu-devstep 4:修改ns-allinone-2.35中ls.h文件的代码将void eraseAll() { erase(baseMap::begin(), baseMap::end()); } 改为:void eraseAll() { this->erase(baseMap::begin(), baseMap::end()); }step 5:sudo ls /usr/bin/gcc* //查看系统已经安装的gcc版本。
Ubuntu 13.10默认安装了gcc-4.8//和gcc-4.8版本的,如果是其他版本的linux操作系统且没有安装//高于4.0版本的gcc/g++。
则需要手动安装gcc/g++-4.8 sudo apt-get install gcc-4.8 g++-4.8 // 对于Ubuntu 13.10,此项是非必须的sudo export CC=gcc-4.8sudo export CXX=g++-4.8//CC和CXX是全局变量,用来指定make将会用哪个版本的gcc/g++编译器生成//makefile文件。
如果没有这一步,保证你会makefile失败!!!因为,在ns-2.35文件夹//下的makefile.in 中要求配置全局变量。
echo $CCecho $CXX //查看全局变量导入成功了没有,如果成功,则执行sudo ./install //开始进行安装,大概等5分钟左右。
.......出现以下的内容,每个人的/home/xx/不同,我的用户名是nan,所以,显示了以下信息。
Ns-allinone package has been installed successfully.Here are the installation places:tcl8.5.10: /home/nan/ns-allinone-2.35/{bin,include,lib}tk8.5.10: /home/nan/ns-allinone-2.35/{bin,include,lib}otcl: /home/nan/ns-allinone-2.35/otcl-1.14tclcl: /home/nan/ns-allinone-2.35/tclcl-1.20ns: /home/nan/ns-allinone-2.35/ns-2.35/nsnam:/home/nan/ns-allinone-2.35/nam-1.15/namxgraph: /home/nan/ns-allinone-2.35/xgraph-12.2gt-itm: /home/nan/ns-allinone-2.35/itm, edriver, sgb2alt, sgb2ns, sgb2comns, sgb2hiernsPlease put/home/nan/ns-allinone-2.35/bin:/home/nan/ns-allinone-2.35/tcl8.5.10/unix:/home/nan/ns-allin one-2.35/tk8.5.10/unixinto your PATH environment; so that you'll be able to run itm/tclsh/wish/xgraph.IMPORTANT NOTICES:(1) You MUST put /home/nan/ns-allinone-2.35/otcl-1.14, /home/nan/ns-allinone-2.35/lib,into your LD_LIBRARY_PATH environment variable.If it complains about X libraries, add path to your X librariesinto LD_LIBRARY_PA TH.If you are using csh, you can set it like:setenv LD_LIBRARY_PA TH <paths>If you are using sh, you can set it like:export LD_LIBRARY_PA TH=<paths>(2) You MUST put /home/nan/ns-allinone-2.35/tcl8.5.10/library into your TCL_LIBRARYenvironmentalvariable. Otherwise ns/nam will complain during startup.After these steps, you can now run the ns validation suite withcd ns-2.35; ./validatestep 6: 根据提示设置环境变量。
在Ubuntu 系统中有两种设置环境变量PA TH 的方法。
第一种适用于为单一用户设置PATH,第二种是为全局设置PATH。
第一种方法:在用户主目录下有一个.bashrc 文件,可以在此文件中加入PATH 的设置如下:export PATH=”$PATH:/your path1/:/your path2/…..”注意:每一个path 之间要用“:“分隔,PA TH=之间不要有任何空格,否则会导入失败。
第二种方法:在/etc/profile中增加。
PATH="$PATH:/ your path1"export PATH两者之间的区别在于,第一种方法只在当前用户下有效,而第二种方法对所有的用户都有效。
两者是局部与全局的关系。
执行sudo gedit ~.bashrc //~等价于home/xx本文根据环境变量设置的第一种方法,在.bashrc文件尾部加入相应的代码。
如在我的机子上就是:#PA THexportPATH="$PATH:/home/nan/ns-allinone-2.35/bin:/home/nan/ns-allinone-2.35/tcl8.5.10/unix:/h ome/nan/ns-allinone-2.35/tk8.5.10/unix"#LD_LIBRARY_PATHexportLD_LIBRARY_PA TH="$LD_LIBRARY_PATH:/home/nan/ns-allinone-2.35/otcl-1.14:/hom e/nan/ns-allinone-2.35/lib"# TCL_LIBRARYexport TCL_LIBRARY="$TCL_LIBRARY:/home/nan/ns-allinone-2.35/tcl8.5.10/library "2.leach协议安装1.下载mit包/s/1h8rj0#dir/path=%2FNS,解压,将解压之后的文件夹重新命名为leach。
2. 比较leach文件夹与ns-2.35文件夹(Note:不是ns-allinone-2.35),并做以下copy✓将leach目录下的test , leach_test , package_up 3个文件及mit文件夹复制到ns-2.35 ✓将ns-2.35/tcl/ex/wireless.tcl的文件重命名为wireless1.tcl ,再将leach/tcl/ex/wieless.tcl 复制到 ns-2.35/tcl/中✓leach/mac目录下的 ,mac-sensor-timers.h , mac-sensor.h 4个文件复制到ns-2.35/mac目录下✓leach/tcl/mobility目录下的leach-c.tcl , leach.tcl , mte.tcl , stat-clus.tcl 4个文件复制到 ns-2.35/tcl/mobility目录下3.将leach文件夹中的(1) apps / , app.h(2) trace / , cmu-trace.h(3) common / packet.h , , (4) mac / , ll.h , , phy.h , mac / , wireless-phy.h 文件中以 #ifdef MIT_uAMPS开始,以#endif结束的部分添加到ns-2.35文件夹中的对应的文件中。
这个修改的工作量巨大,建议使用Beyond Compare软件协助修改。
修改的时候特别注意,不要覆盖ns-2.35中原来的代码。
4.需要特别修改的部分将wireless-phy.h中(约149行)MobileNode* node_; 前的注释取消掉。
将中(约234行)node_ = (Node *)obj; 改为node_ = (MobileNode *)obj 将mac/里的第133行,node_ =(Node *)obj; 同样改为node_ = (MobileNode *)obj;将common/packet.h里添加的#ifdef MIT_ MPSPT_RCA,#endif 修改为#ifdef MIT_uAMPSstatic const packet_t PT_RCA=73;#endif// insert new packet types herestatic packet_t PT_NTYPE = 74; // This MUST be the LAST one 将mac/wireless-phy.h文件中(约143行)的private注释掉。