centos下安装NS2

2018年1月5日 1 条评论 150 次阅读 0 人点赞

据说每个装完ns2的人都会写一篇博客,太麻烦了,安装过程中有很多问题值得说,关键是气呀!版本大同小异,通过版本是回避不了问题的 ,所以我选择2.33版本,因为感觉这个软件 实在是233

在进行网络实验时,经常需要进仿真实验,这里给大家提供一款非常强大的仿真工具:NS2。NS2是在UNIX系统上面开发的,因此UNIX系统和类UNIX系统是最佳平台(当然windows系统也能安装使用)。这里我们主要介绍在类UNIX系统中的安装(以centos为例)。NS2主要有两种安装,一种是纯手动安装,需要依次安装所有依赖包,对于手残党和新手党来说无疑是个噩梦,当然就介绍最懒得安装方式啦:通过allinone包安装

1.安装gcc和g++(注意yum源的g++跟debain的apt-get源的不同)

yum install gcc
yum install gcc-c++

2.安装依赖

yum install libX11-devel*
yum install xorg-x11-proto-devel*
yum install libXt-devel*
yum install libXmu-devel*  

3、下载ns-allinone-2.33.tar.gz

wget http://sourceforge.net/projects/nsnam/files/allinone/ns-allinone-2.33/ns-allinone-2.33.tar.gz/download
tar -xzf ns-allinone-2.33.tar.gz

4.安装NS2

 cd ns-allinone-2.34/    #进入ns2源码目录
 ./install               #一步操作,但是需要耐心等待

如果安装成功,那么将会出现下面的信息
Ns-allinone package has been installed successfully.
Here are the installation places:
tcl8.5.10: /home/ivan/Downloads/ns-allinone-2.35/{bin,include,lib}
tk8.5.10: /home/ivan/Downloads/ns-allinone-2.35/{bin,include,lib}
otcl: /home/ivan/Downloads/ns-allinone-2.35/otcl-1.14
tclcl: /home/ivan/Downloads/ns-allinone-2.35/tclcl-1.20
ns: /home/ivan/Downloads/ns-allinone-2.35/ns-2.35/ns
nam: /home/ivan/Downloads/ns-allinone-2.35/nam-1.15/nam
xgraph: /home/ivan/Downloads/ns-allinone-2.35/xgraph-12.2
gt-itm: /home/ivan/Downloads/ns-allinone-2.35/itm, edriver, sgb2alt, sgb2ns, sgb2comns, sgb2hierns

当然这并没有完成,你会发现除了上面这些信息外,还有其他信息:

Please put /home/ivan/Downloads/ns-allinone-2.35/bin:/home/ivan/Downloads/ns-allinone-2.35/tcl8.5.10/unix:/home/ivan/Downloads/ns-allinone-2.35/tk8.5.10/unix
into your PATH environment; so that you’ll be able to run itm/tclsh/wish/xgraph.

IMPORTANT NOTICES:

(1) You MUST put /home/ivan/Downloads/ns-allinone-2.35/otcl-1.14, /home/ivan/Downloads/ns-allinone-2.33/lib,
into your LD_LIBRARY_PATH environment variable.
If it complains about X libraries, add path to your X libraries
into LD_LIBRARY_PATH.
If you are using csh, you can set it like:
setenv LD_LIBRARY_PATH
If you are using sh, you can set it like:
export LD_LIBRARY_PATH=

(2) You MUST put /home/ivan/Downloads/ns-allinone-2.35/tcl8.5.10/library into your TCL_LIBRARY environmental
variable. Otherwise ns/nam will complain during startup.

After these steps, you can now run the ns validation suite with
cd ns-2.33; ./validate

For trouble shooting, please first read ns problems page
http://www.isi.edu/nsnam/ns/ns-problems.html. Also search the ns mailing list archive
for related posts.

按提示配置环境变量,安装成功

5. 以为这样就结束了吗?一切刚刚开始

以下问题将会导致安装失败:

问题一:

tools/ranvar.cc: In member function ‘virtual double GammaRandomVariable::value()’:

tools/ranvar.cc:219:70: error: cannot call constructor ‘GammaRandomVariable::GammaRandomVariable’ directly

tools/ranvar.cc:219:70: error: for a function-style cast, remove the redundant ‘::GammaRandomVariable’

make: *** [tools/ranvar.o]错误1

Ns make failed!

See http://www.isi.edu/nsnam/ns/ns-problems.html for problems

这是由于gcc版本提高后对类内部函数调用的简化造成的不兼容,解决方法如下:

在ns-allinone-2.33/ ns-2.33/tools文件夹下,找到报错提示中的ranvar.cc文件,打开找到对应的219行删除::GaammaRandomVariable,保存,

即:将219行的 return GammaRandomVariable::GammaRandomVariable(1.0 + alpha_, beta_).value() * pow (u, 1.0 / alpha_);

改为: return GammaRandomVariable(1.0 + alpha_, beta_).value() * pow (u, 1.0 / alpha_);

然后保存退出,重新安装ns2.

问题二:

重新在ns目录下键入$ ./install安装,再次出现同类问题时,

mobile/nakagami.cc: In member function ‘virtual double Nakagami::Pr(PacketStamp*, PacketStamp*, WirelessPhy*)’:

mobile/nakagami.cc:183:73: error: cannot call constructor ‘ErlangRandomVariable::ErlangRandomVariable’ directly

mobile/nakagami.cc:183:73: error: for a function-style cast, remove the redundant ‘::ErlangRandomVariable’

mobile/nakagami.cc:185:67: error: cannot call constructor ‘GammaRandomVariable::GammaRandomVariable’ directly

mobile/nakagami.cc:185:67: error: for a function-style cast, remove the redundant ‘::GammaRandomVariable’

make: *** [mobile/nakagami.o]错误1

Ns make failed!

See http://www.isi.edu/nsnam/ns/ns-problems.html for problems

解决方法:

在ns-allinone-2.33/ ns-2.33/ mobile文件夹下,找到报错提示中的nakagami.cc文件,打开找到对应的183行删除::ErlangRandomVariable,保存,

即:将183行的 resultPower = ErlangRandomVariable::ErlangRandomVariable(Pr/m, int_m).value();

改为: resultPower = ErlangRandomVariable(Pr/m, int_m).value();

在ns-allinone-2.33/ ns-2.33/ mobile文件夹下,找到报错提示中的nakagami.cc文件,打开找到对应的185行删除::GammaRandomVariable,保存,

即:将185行的 resultPower = GammaRandomVariable::GammaRandomVariable(m, Pr/m).value();

改为: resultPower = GammaRandomVariable(m, Pr/m).value();

重新在ns目录下键入$ ./install安装

问题三:

In file included from mac/mac-802_11Ext.cc:66:0:

mac/mac-802_11Ext.h: In member function ‘u_int32_t PHY_MIBExt::getHdrLen11()’:

mac/mac-802_11Ext.h:175:19: error: expected primary-expression before ‘struct’

mac/mac-802_11Ext.h:175:41: error: ‘dh_body’ was not declared in this scope

mac/mac-802_11Ext.h:175:51: error: ‘offsetof’ was not declared in this scope

mac/mac-802_11Ext.h:177:3: warning: control reaches end of non-void function [-Wreturn-type]

make: *** [mac/mac-802_11Ext.o] Error 1

Ns make failed!

下面是网上找得关于本问题的解决方案:

If you get error like:

mac/mac-802_11Ext.h: In member function ‘u_int32_t PHY_MIBExt::getHdrLen11()’:
mac/mac-802_11Ext.h:176:19: error: expected primary-expression before ‘struct’
mac/mac-802_11Ext.h:176:41: error: ‘dh_body’ was not declared in this scope
mac/mac-802_11Ext.h:176:51: error: ‘offsetof’ was not declared in this scope

open that file and add

#include <cstddef>

to the header files.
在ns-allinone-2.33\ns-2.33\mac\mac-802_11Ext.h 文件添加#include <cstddef>

问题四:

提示make:***[linkstate/ls.o] 错误1
修改ls.h文件:
ns-2.33/linkstate/ls.h 第137行

void eraseAll() { erase(baseMap::begin(), baseMap::end()); }

改为:
void eraseAll() { this->erase(baseMap::begin(), baseMap::end()); }

然后重新 ./install

解决上述问题,即可安装成功。

6.并没有结束

安装成功后,ns2无法运行实例,报错如下:

可能的问题:
系统提示如下,

: no event type or button # or keysym
while executing
"bind Listbox <MouseWheel> {
%W yview scroll [expr {- (%D / 120) * 4}] units
}"
invoked from within
"if {[tk windowingsystem] eq "classic" || [tk windowingsystem] eq "aqua"} {
bind Listbox <MouseWheel> {
%W yview scroll [expr {- (%D)}] units
}
bind Li..."

原因:据说是ns2.33,它的nam调用的tk组件和xproto-7.0.13 不兼容导致的(xproto-7.0.13 新添加了 GenericEvent),所以在安装ns2之前要先打上补丁。如果不打上补丁的话,后面调用nam时会报错。

解决方法为:

(1)打补丁tk-8.4-lastevent.patch

把这个文件移动至ns目录下tk8.4.18下

$cd/ns-allinone-2.33/tk8.4.18

$patch –p1<tk-8.4-lastevent.patch

(2)打补丁tk-8.4.18-tkBind.patch

将文件tk-8.4.18-tkBind.patch移至ns-allinone-2.33目录下,并运行如下命令:
$patch -p0 <tk-8.4.18-tkBind.patch

(3)重新安装ns-allinone-2.33

打上补丁后,再安装ns2.33,输入命令:

$cd ns-allinone-2.33

$./install

至此,安装完成。

 

 

lyssom

这个人太懒什么东西都没留下

文章评论(1)

  • 1

    export PATH=$PATH:/root/ns-allinone-2.35/bin:/root/ns-allinone-2.35/tcl8.5.10/unix:/root/ns-allinone-2.35/tk8.5.10/unix:/root/anaconda3/bin
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/root/ns-allinone-2.35/otcl-1.14:/root/ns-allinone-2.35/lib
    export TCL_LIBRARY=$TCL_LIBRARY:/root/ns-allinone-2.35/tcl8.5.10/library

    2018年1月24日