以進行有線網路模擬
先介紹一下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裡面已經有給我們了,
所以我們直接使用就行了。


選擇建議安裝的功能

完成安裝^_^

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

產生下面的視窗

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



要連的點再放掉



要建立在哪個點就點哪個點燃後按Insert做增加,這裏我們先在n0點一下,
然後按Insert->Transport->TCP Tahoe









點Configuration->Scenariio










====================================
# 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執行模擬
下面是輸入之後產生的結果
沒有留言:
張貼留言