现在的位置: 首页 > 综合 > 正文

ubuntu-9.04-alternate-i386下安装NS2的方法和遇到的问题

2013年04月23日 ⁄ 综合 ⁄ 共 4170字 ⁄ 字号 评论关闭

First of all,what is ns? The following explanations cited from the ns Manual maybe can help the "nood" to understand it.

ns is a Network Simulator. The simulator is written in C++, it uses OTcl as a command and configuration interface. ns v2 has three substantial changes from ns v1:
(1)the more complex objects in ns v1 have been decomposed into simpler simpler components for greater flexibility and composability;
(2)the configuration interface is now OTcl,an object oriented version of Tcl;
(3)and the interface code to the OTcl interpreter is separate from the main simulator.

Ns documentation is available in html, Postscript, and PDF formats.
See
http://www.isi.edu/nsnam/ns/ns-documentation.html for pointers to these.

All right,let's go back to the subject we were discussing!

 

NS2支持Windows、Linux、Unix、Mac以及其他支持POSIX标准的操作系统,它主要支持的OS是Linux OS。当然,NS2也可以安装在Windows下,以前NS可以直接在vc上运行,但是后来的版本就不支持了,要在Windows下运行,还要使用Cygwin(GNU+Cygnus+Windows=Cygwin)这样一个Linux模拟环境,Cygwin提供一个DLL(cygwin1.dll)作为Linux下一API的模拟层,提供Linux API的各种功能特性,同时,它还包含一系列与Linux下一致的工具包和X图形界面等。一言以蔽之,很强大!但是,需要注意的是:
(1)Cygwin与VMware等虚拟机软件是不同的,Cygwin不提供机器的硬件抽象层,而VMware提供一个硬件抽象层,在WMware上可以安装任何PC机可安装的OS。
(2)另外,由于是在Windows环境下运行,Linux系统原有的可执行文件并不能直接在Cygwin环境中运行,而必须在Cygwin环境下重新从源码编译该应用软件才可以在Cygwin下使用。

 

我没有采用这种安装方式,下面是在Linux下的安装方法:

 

(1)下载NS2
到官网,
http://www.isi.edu/nsnam/ns/ 全英文,需要看说明自己找。我选择下载ns-allinone-2.34(目前的最新版本),当然下载这一步可以在Windows下完成,也可以在Linux下完成。我是在Windows下完成的,然后在Linux下mount Windows的分区,然后cp就行了。

 

(2)安装NS2前的准备工作
因为我在安装的时候走了很多弯路,所以在安装之前最后先完成下面的一些工作,防止在安装的时候出现错误。

[a]进入Linux,先将系统更新到最新

[b]完善编译环境

 

(3)安装NS2

首先将ns-allinone-2.34.tar.gz压缩包mv到~目录下,当然也可以安装到/opt(一般用来放第三方软件的)目录下。我放在了~下。

 

安装完毕后,如果没有出现错误的话,shell会显示出下面信息:(/home/wcdj/是我的目录)
IMPORTANT NOTICES:
   (1) You MUST put /home/wcdj/ns2/ns-allinone-2.34/otcl-1.13, /home/wcdj/ns2/ns-allinone-2.34/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 <paths>
    If you are using sh, you can set it like:
                export LD_LIBRARY_PATH=<paths>

   (2) You MUST put /home/wcdj/ns2/ns-allinone-2.34/tcl8.4.18/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.31; ./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.

提示告诉我们还要设置环境变量。

 

(4)设置环境变量
按照提示要设置的环境变量包括:LD_LIBRARY_PATH,TCL_LIBRARY,PATH

 

(5)使环境变量生效

 

(6)测试NS2是否安装好
打开一个终端,输入ns,回车,如果显示%,说明环境变量设置正确,然后在输入一个puts "Hi NS2!"(注意puts后有空格),如果正确会在下面一行显示:Hi NS2! 但是这时还不能说明NS2已经安装好了,再找一个exec nam程序的Tcl脚本例子,输入ns XXX.tcl运行一下,如果能够显示nam的图形界面,基本就没问题了(如果调用nam出错,根据提示错误在网上找相关的补丁修复,一般是兼容性错误)。最后要退出NS2,直接输入exit。

如果你在终端下键入ns,出现了下面的错误提示:

The program 'ns' is currently not installed. You can install it by typing:
sudo apt-get install host...Make sure you have the 'universe' component enabled
bash: ns: command not found

不要 sudo apt-get install host,否则下次你再输入ns,终端提示你用的是host命令,所以不要安装host,解决不了问题。出现这个问题的原因是因为环境变量没有设置正确,需要再打开~/.bashrc文件检查。如果ns成功安装的话,你cd到~/ns-allinone-2.34/bin/目录下,你再在终端输入ns命令,肯定会显示%。这时候用不到你设置的环境变量,这也就进一步说明你设置的环境变量是不对的。好了,现在ns2已经装好了,下来的任务就是how to use it!

 

[References]
The Network Simulator ns-2: Installation Problems, Bug Fixes, and Help
http://www.isi.edu/nsnam/ns/ns-problems.html

NS2 教學手冊 ( NS2 Learning Guide)
http://140.116.72.80/~smallko/ns2/ns2.htm

 

抱歉!评论已关闭.