ping.tcl
来自「NS-2.28的802.11e协议扩展源代码」· TCL 代码 · 共 52 行
TCL
52 行
#Create a simulator objectset ns [new Simulator]#Open a trace fileset nf [open out.nam w]$ns namtrace-all $nf#Define a 'finish' procedureproc finish {} { global ns nf $ns flush-trace close $nf exec nam out.nam & exit 0}#Create three nodesset n0 [$ns node]set n1 [$ns node]set n2 [$ns node]#Connect the nodes with two links$ns duplex-link $n0 $n1 1Mb 10ms DropTail$ns duplex-link $n1 $n2 1Mb 10ms DropTail#Define a 'recv' function for the class 'Agent/Ping'Agent/Ping instproc recv {from rtt} { $self instvar node_ puts "node [$node_ id] received ping answer from \ $from with round-trip-time $rtt ms."}#Create two ping agents and attach them to the nodes n0 and n2set p0 [new Agent/Ping]$ns attach-agent $n0 $p0set p1 [new Agent/Ping]$ns attach-agent $n2 $p1#Connect the two agents$ns connect $p0 $p1#Schedule events$ns at 0.2 "$p0 send"$ns at 0.4 "$p1 send"$ns at 0.6 "$p0 send"$ns at 0.6 "$p1 send"$ns at 1.0 "finish"#Run the simulation$ns run
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?