1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
source timer.tcl
global ns
set ns [new Simulator]
$ns color 0 blue
$ns color 1 red
$ns color 2 darkgreen
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
puts n0=[$n0 id]
puts n1=[$n1 id]
puts n2=[$n2 id]
puts n3=[$n3 id]
set f [open out.tr w]
$ns trace-all $f
set nf [open out.nam w]
$ns namtrace-all $nf
#$ns duplex-link $n0 $n1 1.5Mb 10ms DropTail
$ns duplex-link $n0 $n2 10Mb 2ms DropTail
$ns duplex-link $n1 $n2 10Mb 2ms DropTail
$ns duplex-link $n2 $n3 1.5Mb 10ms DropTail
$ns duplex-link-op $n0 $n2 orient right-up
$ns duplex-link-op $n1 $n2 orient right-down
$ns duplex-link-op $n2 $n3 orient right
$ns duplex-link-op $n2 $n3 queuePos 0.5
$ns queue-limit $n2 $n3 8
Class Sender -superclass {Agent/Message Timer}
Class Receiver -superclass Agent/Message
Sender instproc init {} {
$self next
$self reset
$self set window_ 4
}
Sender instproc reset {} {
$self instvar seqno_ ack_
set seqno_ 0
set ack_ 0
}
Sender instproc start {} {
$self transmit
}
Sender instproc reset_timer {} {
$self cancel
$self sched 0.05
}
Sender instproc timeout {} {
$self instvar seqno_ ack_
set seqno_ $ack_
$self transmit
}
Sender instproc cansend {} {
$self instvar seqno_ window_ ack_
return [expr $seqno_ < $ack_ + $window_]
}
Sender instproc sendnext {} {
$self instvar seqno_
$self send $seqno_
incr seqno_
$self reset_timer
}
Sender instproc transmit {} {
while [$self cansend] {
$self sendnext
}
}
Sender instproc recv msg {
$self instvar ack_
set ack_ $msg
$self transmit
}
Sender set packetSize_ 400
Receiver set packetSize_ 40
Receiver instproc init {} {
$self next
$self reset
}
Receiver instproc reset {} {
$self instvar ack_
set ack_ 0
}
Receiver instproc recv msg {
set seqno $msg
$self instvar ack_
if { $seqno == $ack_ } {
incr ack_
}
$self send $ack_
}
set sndr [new Sender]
$ns attach-agent $n0 $sndr
$sndr set fid_ 0
set rcvr [new Receiver]
$ns attach-agent $n3 $rcvr
$rcvr set fid_ 1
$ns connect $sndr $rcvr
$sndr set window_ 1
# start up - stop-and-wait
$ns at 0.0 "$sndr start"
# do pipelining
$ns at 0.2 "$sndr set window_ 6"
# cause queue overflow
$ns at 0.4 "$sndr reset; $rcvr reset; $sndr set window_ 10"
$ns at 0.6 "$ns queue-limit $n2 $n3 20"
$ns at 0.8 "$sndr set window_ 14"
$ns at 1.0 "finish"
proc finish {} {
global nf
close $nf
puts "running nam..."
exec nam out.nam &
exit 0
}
$ns run
|