2007.07.20
開工啦!!這個禮拜有出任務啦,任務就是要去分析兩章節腳本的每行指令代表的意思,於是我大概分析了一下兩個章節的指令,畢竟大多都是相同的指令,所以其實應該可以挑出來分給一個人講就好,要不然第五章的部份有點少。
--------- 重點分析如下 ---------
兩章節共同部份:
set ns [new Simulator] # 設定節點
set nf [open out.nam w] # 開檔
$ns namtrace-all $nf # namtrace-all
proc finish {} { # 副函式
global ns nf # global
$ns flush-trace # flush-trace
close $nf # close
exec nam out.nam & # exec
exit 0
}
set n0 [$ns node] # node
$ns duplex-link $n0 $n2 1Mb 10ms DropTail # duplex-link、DropTail
set udp0 [new Agent/UDP] # [new Agent/UDP]
$ns attach-agent $n0 $udp0 # attach-agent
set cbr0 [new Application/Traffic/CBR] # cbr、[new Application/Traffic/CBR]
$cbr0 set packetSize_ 500 # set packetSize
$cbr0 set interval_ 0.005 # set interval
$cbr0 attach-agent $udp0 # attach-agent
set null0 [new Agent/Null] # [new Agent/Null]
$ns attach-agent $n3 $null0
$ns connect $udp0 $null0 # connect
$ns at 0.5 "$cbr0 start" # "$cbr0 start"
$ns at 4.0 "$cbr1 stop" # "$cbr1 stop"
$ns at 5.0 "finish" # "finish"
$ns run # run
兩個節點模擬:
set nd [open out.tr w] # open
$ns trace-all $nd # trace-all
多節點模擬:
$ns color 1 Blue # color
$ns duplex-link $n3 $n2 1Mb 10ms SFQ # SFQ
$ns duplex-link-op $n0 $n2 orient right-down # duplex-link-op、right-down
$ns duplex-link-op $n1 $n2 orient right-up # right-up
$ns duplex-link-op $n2 $n3 orient right # right
$ns duplex-link-op $n2 $n3 queuePos 0.5 # queuePos
$udp0 set class_ 1 # class_ 1
set udp1 [new Agent/UDP] # [new Agent/UDP]
$ns attach-agent $n1 $udp1
歡迎對於 NS2 有研究或見解的同學、朋友可以一起討論 by Yo PM 3:12
留言列表