set tracefd [open no1.tr w] ;#注意此處的no.1
$ns trace-all $tracefd
set namtracefd [open no1.nam w] ;#注意此處的no.1
$ns namtrace-all $namtracefd
proc finish {} {
global ns tracefd namtracefd
$ns flush-trace
close $tracefd
close $namtracefd
exec nam no1.nam & ;#注意此處no.1
exit 0
}
#新建兩個node(節點),分別複製n0 和n1
set n0 [$ns node]
set n1 [$ns node]
#建立一條雙向link(鏈路) 該鏈路的帶寬爲1Mbit/s 延遲爲10ms 隊列類型爲DropTail
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
#新建一個UDP Agent 並綁定到n0上
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
#新建一個CBR的流量發生器 分組大小爲500Byte 發送間隔爲5ms 綁定到udp0上
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0
#新建一個Null Agent 並綁定到n1上,Null是數據接收器
set null0 [new Agent/Null]
$ns attach-agent $n1 $null0
#將udp0 和 null0 連接起來
$ns connect $udp0 $null0
#告知cbr0在0.5s時啓動 在4.5s時停止
$ns at 0.5 "$cbr0 start"
$ns at 4.5 "$cbr0 stop"
#在5s時調用finish過程
$ns at 5.0 "finish"
$ns run
注意無論你給文件起**.tcl 但是裏面的內容不能變