📄 myauth.tcl
字号:
set ns [new Simulator]
set tf [open out.tr w]
$ns trace-all $tfset nf [open out.nam w]$ns namtrace-all $nfproc finish {} { global ns tf nf $ns flush-trace close $tf
close $nf exec nam out.nam & exit 0}set n0 [$ns node]set n1 [$ns node]$ns duplex-link $n0 $n1 1Mb 10ms DropTail#Define a 'outp' function for the class 'Agent/MyAuth'?????????????????????Agent/MyAuth instproc outp {typ n from rtt} {
$self instvar node_
switch $typ {
send {puts "node [$node_ id] sended seq $n packet."
}
rcv {puts "node [$node_ id] received seq $n packet from \
$from with round-trip-time $rtt ms."
}
auth {puts "node [$node_ id] received seq $n packet from \
$from,which is authenticated."
}
default {puts "args error!"}
}
}
#注意使用跟系统时间有关的随机变量,切忌使用伪随机数。
set em [new ErrorModel]
$em unit pkt
$em set rate_ 0.2
#$em ranvar [new RandomVariable/Uniform]set rng [new RNG]$rng seed 0set e [new RandomVariable/Uniform]$e use-rng $rng$em ranvar $e
$em drop-target [new Agent/Null]
#$ns lossmodel $em $n0 $n1
$ns link-lossmodel $em $n0 $n1
set p0 [new Agent/MyAuth]$ns attach-agent $n0 $p0set p1 [new Agent/MyAuth]$ns attach-agent $n1 $p1#Connect the two agents$ns connect $p0 $p1#Schedule events$ns at 0.01 "$p0 send"
$ns at 0.02 "$p0 send"
$ns at 0.03 "$p0 send"
$ns at 0.04 "$p0 send"
$ns at 0.05 "$p0 send"
$ns at 0.06 "$p0 send"
$ns at 0.07 "$p0 send"
$ns at 0.08 "$p0 send"$ns at 0.09 "$p0 send"$ns at 0.1 "$p0 send"$ns at 3.0 "$p0 send_no"$ns at 3.1 "$p1 rcv_no"
#$ns at 3.2 "$p1 auth"$ns at 3.2 "$p1 auth_no"$ns at 3.3 "$p1 auth_pro"
$ns at 4.0 "finish"$ns run
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -