歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Ubuntu 11.10下安裝NS2.35

Ubuntu 11.10下安裝NS2.35

日期:2017/2/28 15:55:09   编辑:Linux教程

去年學習了2.34的安裝方法,後來換了Ubuntu 11.10後重新安裝發現NS升級到2.35,官方手冊還是使用11年04月的那份。我個人建議學習英文版的手冊,因為版本新,裡面有一些新添加的東西。中文漢化的手冊版本都比較舊,基本都是08年以前的。當然這個因人而異了,中文版看著容易一些而且做了美工,英文版原汁原味。蘿卜白菜,各有所愛。

那麼現在就來說說最新2.35的安裝方法。我們發現2.34安裝時要修復不少小問題,可喜的是2.35裡面都得到了修正,所以安裝起來要容易得多,下面說說具體的步驟吧。

相關閱讀:

Ubuntu 11.04下安裝ns-allinone-2.34.tar.gz http://www.linuxidc.com/Linux/2011-09/43745.htm

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.

[email protected]:/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
Copyright © Linux教程網 All Rights Reserved