ns2 有线UDP模拟
原创
©著作权归作者所有:来自51CTO博客作者wx64015c4b4bc07的原创作品,请联系作者获取转载授权,否则将追究法律责任
set ns [new Simulator]
set tracefile [open out.tr w]
$ns trace-all $tracefile
set nf [open out.nam w]
$ns namtrace-all $nf
proc finish {} {
global ns tracefile nf
$ns flush-trace
close $nf
close $tracefile
exec nam out.nam &
exit 0
}
set n0 [$ns node]
set n1 [$ns node]
$ns duplex-link $n0 $n1 0.01Mb 1ms DropTail
set udp0 [new Agent/UDP]
set udp1 [new Agent/Null]
$ns attach-agent $n0 $udp0
$ns attach-agent $n1 $udp1
$ns connect $udp0 $udp1
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0
$ns at 0.0 "$cbr0 start"
$ns at 5.0 "$cbr0 stop"
$ns at 6.0 "finish"
$ns run