我在NS2中实现了距离矢量协议,现在我想执行xgraph以获得吞吐量和数据包延迟。我知道我必须插入吞吐量和延迟的方程式以及exec xgraph命令,但我无法将其集成到我的代码中。有人可以帮帮我。
set ns [new Simulator]
set nr [open thro.tr w]
$ns trace-all $nr
set nf [open thro.nam w]
$ns namtrace-all $nf
proc finish { } { // finish procedure
global ns nr nf
$ns flush-trace
close $nf
close $nr
exec nam thro.nam &
exit 0
}
for { set i 0 } { $i < 12} { incr i 1 } { // Number of nodes
set n($i) [$ns node]}
for {set i 0} {$i < 8} {incr i} {
$ns duplex-link $n($i) $n([expr $i+1]) 1Mb 10ms DropTail } // Link bandwidth and delay
$ns duplex-link $n(0) $n(8) 1Mb 10ms DropTail
$ns duplex-link $n(1) $n(10) 1Mb 10ms DropTail
$ns duplex-link $n(0) $n(9) 1Mb 10ms DropTail
$ns duplex-link $n(9) $n(11) 1Mb 10ms DropTail
$ns duplex-link $n(10) $n(11) 1Mb 10ms DropTail
$ns duplex-link $n(11) $n(5) 1Mb 10ms DropTail
set udp0 [new Agent/UDP] // Traffic UDP
$ns attach-agent $n(0) $udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0
set null0 [new Agent/Null]
$ns attach-agent $n(5) $null0
$ns connect $udp0 $null0
set udp1 [new Agent/UDP]
$ns attach-agent $n(1) $udp1
set cbr1 [new Application/Traffic/CBR]
$cbr1 set packetSize_ 500
$cbr1 set interval_ 0.005
$cbr1 attach-agent $udp1
set null0 [new Agent/Null]
$ns attach-agent $n(5) $null0
$ns connect $udp1 $null0
$ns rtproto DV // routing protocol used
$ns rtmodel-at 10.0 down $n(11) $n(5)
$ns rtmodel-at 15.0 down $n(7) $n(6)
$ns rtmodel-at 30.0 up $n(11) $n(5)
$ns rtmodel-at 20.0 up $n(7) $n(6)
$udp0 set fid_ 1
$udp1 set fid_ 2
$ns color 1 Green
$ns color 2 Blue
$ns at 1.0 "$cbr0 start"
$ns at 2.0 "$cbr1 start"
$ns at 45 "finish"
$ns run
答案 0 :(得分:0)
“VIII。为Xgraph创建输出文件”http://www.isi.edu/nsnam/ns/tutorial/nsscript4.html
Xgraph示例:xgraph_ns2-files-tcl_09.17.tar.gz https://drive.google.com/file/d/0B7S255p3kFXNczFLV0ZnNWdVY2s/view?usp=sharing→→文件n-code.tcl是“DV示例”。
DV-examples-3.tar.gz https://drive.google.com/file/d/0B7S255p3kFXNRzBzOGdRODNwcVU/view?usp=sharing
您可以分析跟踪文件,而不是为Xgraph创建文件 使用 APP-Tool
一些APP-Tool结果,“QasimCool-DV.tcl”https://www.dropbox.com/s/qfij7vhpo49t0r1/DV-QuasimCool.tar.gz?dl=0→→Delay-figure_3.png,Thr-figure_1.png,1-Instantaneous-throughput_thro.tr.txt,Instantaneous-delay_thro.tr .TXT
关于您的文件:“//”不是ns2 file.tcl的有效“注释字符”。编辑第7,16,20,28,48行:
7 proc finish { } { ;# finish procedure
16 for { set i 0 } { $i < 12} { incr i 1 } { ;# Number of nodes
20 $ns duplex-link $n($i) $n([expr $i+1]) 1Mb 10ms DropTail } ;# Link bandwidth and delay
28 set udp0 [new Agent/UDP] ;# Traffic UDP
48 $ns rtproto DV ;# routing protocol used