安裝完後再下載 nsBench-1.0b3.jar ,可是我無意間發現,如果依照課本
步驟四的路徑從我的電腦去找,會發現之前光碟灌的內容早已有這兩樣
東西在
然後開始安裝jre-1_5_0_03-windows-i586-p.exe
之後就會出現NS2的作業視窗
範例一:
建立四個節點
拖曳到適當的位置
把滑鼠移至n0上等游標變成{+}時按住左鍵拖曳到n2上,此步驟也就是
建立n0到n2的連線
在n0到n2的連線上連續點兩下即可設定參數
此為n1到n2的連線之參數
此為n2到n3的連線之參數
所有link設定完即如此
在n0上建立FTP,因此先點n0一下,在選擇[Insert]-->[Transport]
-->[TCP Tahoe]
先點選n3,然後選[Insert]-->[Transport]-->[TCP Sink]
在n1上建立UDP agent ,在n3上建立Null,並在 UDP agent 上建立CBR
然後udp0和null0作連結,因為是黃線所以看不太清楚
點cbr0兩次設定CBR參數
接著要設定應用程式的開始和結束時間與模擬需要多久
點選[Configuration]-->[Scenario]
然後按[Add Row]
Time是手動輸入,第二,三項可使用點選
Simulation finish at time調成 5.0
設定模擬過程記錄檔名稱
[Configuration]-->[Trace]
儲存project檔
產生TCL檔
觀看TCL程式
用WordPad開啟的sim.tcl檔案
# Creating New Simulator
# Creating New Simulator
set ns [new Simulator]
# Setting up the traces
set f [open out.tr w]
set nf [open out.nam w]
$ns namtrace-all $nf
$ns trace-all $f
proc finish { } {
global ns nf f
$ns flush-trace
puts "Simulation completed."
close $nf
close $f
exit 0
}
#
#Create Nodes
#
set n0 [$ns node]
puts "n0: [$n0 id]"
set n1 [$ns node]
puts "n1: [$n1 id]"
set n2 [$ns node]
puts "n2: [$n2 id]"
set n3 [$ns node]
puts "n3: [$n3 id]"
#
#Setup Connections
#
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns duplex-link $n2 $n3 1.7Mb 10ms DropTail
#
#Set up Transportation Level Connections
#
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink0 [new Agent/TCPSink]
$ns attach-agent $n3 $sink0
set udp0 [new Agent/UDP]
$ns attach-agent $n1 $udp0
set null0 [new Agent/Null]
$ns attach-agent $n3 $null0
#
#
#Setup traffic sources
#
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set rate_ 1Mb
$cbr0 set packetSize_ 1000
$cbr0 attach-agent $udp0
$ns connect $tcp0 $sink0
$tcp0 set fid_ 0
$ns connect $udp0 $null0
$udp0 set fid_ 1
#
#Start up the sources
#
$ns at 0.1 "$cbr0 start"
$ns at 1 "$ftp0 start"
$ns at 4 "$ftp0 stop"
$ns at 4.5 "$cbr0 stop"
$ns at 5.0 "finish"
$ns run
以下是程式執行後的結果
範例二 :
照範例一的方法做出此圖
要模擬 multicast ,首先必須先把 multicast 的功能打開
選擇[Configuration]-->[Rounting]
然後選擇想使用的 multicast 路由協定
點選udp0設定其傳送資料的目的地位置為multicast的位置
點選[Add Row]填入參數
用wordpad開啟的TCL檔案
執行 multicast.tcl 的結果




































沒有留言:
張貼留言