以進行有線網路模擬
先介紹一下nsBench是什麼,他使用視窗介面,讓使用者只需要用
滑鼠去點需要的物件就能夠輕輕鬆鬆產生所需模擬的TCL檔案。
目前這個nsBench主要是用來產生有線網路的模擬TCL碼,並沒有
支援無線網路。
如前面所提到的,nsBench是Java開發的,在使用nsBench之前要
先安裝JVM,可以到Sun的網站,我們使用作者使用的
Jre-1_5_0_03-windows-i586-p.exe。安裝完之後再下載nsBench,
下載網址是http://www.mnlab.cs.depaul.edu/projects/nsbench/download/nsBench-1.0b3.jar
這個部份我發現在作者所附的ns-allinone-2.29裡面已經有給我們了,
所以我們直接使用就行了。
先安裝JVM,接受授權合約,然後按下一步
選擇建議安裝的功能

完成安裝^_^

接下來讓我們來使用nsBench吧
首先先打開Cygwin。
然後切換到nsBench檔案的資料夾
(C:\cygwin\home\Allen\ns-allinone-2.29\ns-2.29\book2\lab2)
然後執行nsBench

產生下面的視窗

完成了前置動作之後就讓我們來開始使用它吧!
設計一個簡單的網路模擬環境
先由Insert->Nodes->Node,建立四個點

按照我預想的將四個點排好
接著讓各點接連線,方法是將滑鼠移到原點上讓指標變成十字時按住左鍵拖曳到要連的點再放掉
在線上點兩下會出現可以設定Link的相關參數。
下面的視窗是設定n2和n3的link,這裡把Bandwidth改為1.7Mbps。
所有的link都設定完之後,來建立FTP連線,在建立之前要先建立TCP agent。要建立在哪個點就點哪個點燃後按Insert做增加,這裏我們先在n0點一下,
然後按Insert->Transport->TCP Tahoe
產生之後的物件可以拉到自己希望的位置
接著點n3然後按Insert->Transport->TCP Sink
再來我們點tcp0然後Insert->Traffic->FTP,產生一個FTP的應用程式。
最後我們要在tcp0和sink0之間建立連線。
然後我用同樣的方法在n1上建立UDP agent,在n3上建立Null,並建立CBR應用程式。
在cbr0點兩下設定CBR參數
接下來設定開始時間和結束時間與模擬時間。點Configuration->Scenariio

按Add Row來把相關設定填進去,時間是手動輸入,Application和Action是用選的。

設定模擬過程記錄檔名稱
儲存project檔
產生TCL檔
觀看TCL程式====================================
# 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 udp1 [new Agent/UDP]
$ns attach-agent $n1 $udp1
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 $udp1
$ns connect $tcp0 $sink0
$tcp0 set fid_ 0
$ns connect $udp1 $null0
$udp1 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
# 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 udp1 [new Agent/UDP]
$ns attach-agent $n1 $udp1
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 $udp1
$ns connect $tcp0 $sink0
$tcp0 set fid_ 0
$ns connect $udp1 $null0
$udp1 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
====================================
執行模擬
打開Cygwin,打startxwin.bat先進入nam,
然後且換到ns-allinone-2.29/ns-2.29/book2/lab2/
然後打ns sim.tcl執行模擬
下面是輸入之後產生的結果
執行模擬
打開Cygwin,打startxwin.bat先進入nam,
然後且換到ns-allinone-2.29/ns-2.29/book2/lab2/
然後打ns sim.tcl執行模擬
下面是輸入之後產生的結果


沒有留言:
張貼留言