ns2的第一个tcl脚本

set ns [new Simulator]

set tracef [open example1.tr w]
$ns trace-all $tracef
set namtf [open example1.nam w]
$ns namtrace-all $namtf

proc finish {} {//括号之间要有空格
global ns tracef namtf
$ns flush-trace
close $tracef
close $namtf
exec nam example1.nam&
exit 0
}

set n0 [$ns node]//中括号前要有空格
set n1 [$ns node]

$ns duplex-link $n0 $n1 1Mb 10ms DropTail

set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0

set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500//下划线与数字之间要有空格,500是参数
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0

set null0 [new Agent/Null]
$ns attach-agent $n1 $null0

$ns connect $udp0 $null0

$ns at 0.5 "$cbr0 start"//引号前要有空格
$ns at 4.5 "$cbr0 stop"

$ns at 5.0"finish"
$ns run

 

 

总结:不同部分之间基本都要用空格隔开

 

这段话涉及了nam文件的本质,nam的本质。tr文件与nam文件的区别。

posted @ 2019-07-12 15:39  fastchargingpikachu  阅读(334)  评论(0编辑  收藏  举报