您的位置:首页 > 其它

在Ubuntu11.10上面安装NS2.35

2012-05-23 14:31 288 查看
转自网络,验证可行。

去年学习了2.34的安装方法,后来换了11.10后重新安装发现NS升级到2.35,官方手册还是使用11年04月的那份。我个人建议学习英文版的手册,因为版本新,里面有一些新添加的东西。中文汉化的手册版本都比较旧,基本都是08年以前的。当然这个因人而异了,中文版看着容易一些而且做了美工,英文版原汁原味。萝卜白菜,各有所爱。

那么现在就来说说最新2.35的安装方法。我们发现2.34安装时要修复不少小问题,可喜的是2.35里面都得到了修正,所以安装起来要容易得多,下面说说具体的步骤吧。

1.安装必备包,和2.34一样

sudo apt-get install build-essential

sudo apt-get install tcl8.4 tcl8.4-dev tk8.4 tk8.4-dev

sudo apt-get install libxmu-dev libxmu-headers
sudo apt-get install xorg-dev g++ xgraph


sudo apt-get install g++-4.4

2.将下载好的tar包放到自己想要放置的位置,然后在Terminal进入ns-allinone-2.35文件夹下直接安装

sudo ./install

3.漫长的等待后会出现类似

Please put /usr/local/ns2/ns-allinone-2.34/bin:/usr/local/ns2/ns-allinone-2.34/tcl8.4.18/unix:/usr/local/ns2/ns-allinone-2.34/tk8.4.18/unix

into your PATH environment; so that you'll be able to run itm/tclsh/wish/xgraph.

IMPORTANT NOTICES:

(1) You MUST put /usr/local/ns2/ns-allinone-2.34/otcl-1.13, /usr/local/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 /usr/local/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.34; ./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.
root@dylan:/usr/local/ns2/ns-allinone-2.34#

表明你安装成功了。这时只需更改几个参数:

先输入gedit ~/.bashrc

之后在文本的最后添加

export PATH="$PATH:/usr/local/ns2/ns-allinone-2.35/bin:/usr/local/ns2/ns-allinone-2.35/tcl8.5.10/unix:/usr/local/ns2/ns-allinone-2.35/tk8.5.10/unix"

export LD_LIBRARY_PATH="/usr/local/ns2/ns-allinone-2.35/otcl-1.14:/usr/local/ns2/ns-allinone-2.35/lib"

export TCL_LIBRARY="$TCL_LIBRARY:usr/local/ns2/ns-allinone-2.35/tcl8.5.10/library"

红字部分是相对路径,请更改为自己安装的路径。

之后在Terminal输入ns,显示%就表示运行成功了。可以编辑一个test.tcl文件,里面输入手册一开始提到的例子:

# The preamble

set ns [new Simulator]

;# initialise the simulation

# Predefine tracing

set f [open out.tr w]

$ns trace-all $f

set nf [open out.nam w]

$ns namtrace-all $nf

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]

$ns duplex-link $n0 $n2 5Mb 2ms DropTail

$ns duplex-link $n1 $n2 5Mb 2ms DropTail

$ns duplex-link $n2 $n3 1.5Mb 10ms DropTail

# Some agents.

set udp0 [new Agent/UDP]

$ns attach-agent $n0 $udp0

set cbr0 [new Application/Traffic/CBR]

$cbr0 attach-agent $udp0

$udp0 set class_ 0

;# A UDP agent

;# on node $n0

;# A CBR traffic generator agent

;# attached to the UDP agent

;# actually, the default, but. . .

;# Its sink

;# on node $n3

set null0 [new Agent/Null]

$ns attach-agent $n3 $null0

$ns connect $udp0 $null0

$ns at 1.0 "$cbr0 start"

puts [$cbr0 set packetSize_]

puts [$cbr0 set interval_]

# A FTP over TCP/Tahoe from $n1 to $n3, flowid 2

set tcp [new Agent/TCP]

$tcp set class_ 1

$ns attach-agent $n1 $tcp

set sink [new Agent/TCPSink]

$ns attach-agent $n3 $sink

;# TCP does not generate its own traffic

set ftp [new Application/FTP]

$ftp attach-agent $tcp

$ns at 1.2 "$ftp start"

$ns connect $tcp $sink

$ns at 1.35 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n3 $sink"

# The simulation runs for 3s.

# The simulation comes to an end when the scheduler invokes the finish{} procedure below.

# This procedure closes all trace files, and invokes nam visualization on one of the trace files.

$ns at 3.0 "finish"

proc finish {} {

global ns f nf

$ns flush-trace

close $f

close $nf

puts "running nam..."

exec nam out.nam &

exit 0

}

# Finally, start the simulation.

$ns run

保存之后,Terminal进入文件所在文件夹,运行ns test.tcl,如果成功会打开nam显示模拟情况。

最后,补充一个有用的软件gnuplot,画图利器。

sudo apt-get install gnuplot
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: