实验环境:Windows10+Vmware虚拟机+Ubuntu 16.04
实验配置:
1.首先去http://www.isi.edu/nsnam/ns/ns-build.html下载ns-allinone-2.35.tar.gz
2. 拷贝到用户目录下 /home/gsk/
3. 更新一下系统 sudo apt-get update #更新源列表
sudo apt-get upgrade #更新已安装的包
4. 安装几个依赖文件
sudo apt-get install build-essential
sudo apt-get install tcl8.5 tcl8.5-dev tk8.5 tk8.5-dev
sudo apt-get install libxmu-dev libxmu-headers
5. 解压 tar -xvzf ns-allinone-2.35.tar.gz
6. 安装 cd /ns-allinone-2.35
sudo ./install
此时安装包出现了一点问题导致安装失败:
In file included from linkstate/ls.cc:67:0:
linkstate/ls.h: In instantiation of ‘void LsMap::eraseAll() [with Key = int; T = LsIdSeq]’:
linkstate/ls.cc:396:28: required from here
linkstate/ls.h:137:20: error: ‘erase’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
linkstate/ls.h:137:20: note: declarations in dependent base ‘std::map, std::allocator > >’ are not found by unqualified lookup
linkstate/ls.h:137:20: note: use ‘this->erase’ instead
make: *** [linkstate/ls.o] Error 1
Ns make failed!
解决方法:
将 ns-allinone-2.35/ns-2.35/linkstate/ls.h中的137行void eraseAll() { erase(baseMap::begin(), baseMap::end()); }改为 void eraseAll() { this->erase(baseMap::begin(), baseMap::end()); }
然后重新执行 sudo ./install
等待一会就安装好了
7. 设置环境变量 sudo gedit /home/gsk/.bashrc
export PATH="$PATH:/home/gsk/ ns-allinone-2.35/bin:/home/gsk/ ns-allinone-2.35/tcl8.5.10/unix:/home/gsk/ ns-allinone-2.35/tk8.5.10/unix"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/home/gsk/ ns-allinone-2.35/otcl-1.14:/home/gsk/ ns-allinone-2.35/lib"
export TCL_LIBRARY="$TCL_LIBRARY:/home/gsk/ ns-allinone-2.35/tcl8.5.10/library"
8. 新开启一个终端,输入ns,出现如下图表面安装成功,也可以进入 ns/ns-2.35, 输入./validate进行验证。顺带试试puts命令。
运行实例:
切到 /ns-allinone-2.35/ns-2.35/tcl/ex目录
用ns simple.tcl命令执行simple.tcl脚本
定义了三个链表并设置相应的速度等参数
为节点设置代理