Debian Codegraph @

tcl/scenario-generation/scen-lib/rmcc.tcl

raw
1 Class ScenLib/RM
2
3 proc usage {prog} {
4 switch $prog {
5 "rmcc-1" {
6 puts stderr "usage: ns rmcc-1.tcl -test 1 \
7 <or 2 or 3 indicating the \
8 testnum> \[other options\]
9 See rmcc-1.tcl for description of each test\
10 conditions\n"
11 exit 1
12 }
13 "rmcc-2" {
14 puts stderr "usage: ns rmcc-2.tcl \
15 \[other options\]"
16 exit 1
17 }
18 "rmcc-3" {
19 puts stderr "usage: ns rmcc-3.tcl \
20 \[other options\]"
21 exit 1
22 }
23 "rmcc-4" {
24 puts stderr "usage: ns rmcc-4.tcl \
25 \[other options\]"
26 exit 1
27 }
28 }
29 }
30
31 proc default_options {prog} {
32 # check here for other options that may be set for the diffrent
33 # experiments
34 global opts
35 set opts(routingProto) CtrMcast
36 set opts(srmSimType) SRM
37 set opts(rmSrcType) CBR
38 set opts(tcpSrcType) FTP
39 set opts(pktSize) 1000
40
41 switch $prog {
42 rmcc-1 {
43 set opts(test) -1
44 set opts(tcpType) TCP
45 set opts(sinkType) TCPSink
46 }
47 rmcc-2 {
48 set opts(tcpType) TCP/Reno
49 set opts(sinkType) TCPSink/DelAck
50 set opts(bottleneckBW) 1Mbps
51 set opts(bottleneckDelay) 20ms
52 set opts(bottleneckQSize) 60
53 }
54 rmcc-3 {
55 set opts(tcpType) TCP
56 set opts(sinkType) TCPSink
57 set opts(bottleneckBW) 1Mbps
58 set opts(bottleneckDelay) 20ms
59 set opts(bottleneckQSize) 30
60 }
61 rmcc-4 {
62 set opts(tcpType) TCP/Sack1
63 set opts(sinkType) TCPSink/Sack1
64 set opts(bottleneckDelay) 20ms
65 set opts(clientNum) 10
66 # other options
67 }
68 }
69 }
70
71 proc process_args {argv } {
72 global prog
73 default_options $prog
74 global opts
75 for {set i 0} {$i < [llength $argv]} {incr i} {
76 set key [lindex $argv $i]
77 regsub {^-} $key {} key
78 if {![info exists opts($key)]} {
79 puts stderr "unknown option \"$key\""
80 }
81 incr i
82 set opts($key) [lindex $argv $i]
83 }
84 }
85
86 ScenLib/RM instproc set_traces {} {
87 global prog opts ns srmStats srmEvents t
88
89 $ns trace-all [open out-$t.tr w]
90 $ns namtrace-all [open out-$t.nam w]
91
92 #set srmStats [open srmStats-$t.tr w]
93 #set srmEvents [open srmEvents-$t.tr w]
94 }
95
96 ScenLib/RM instproc init {} {
97 $self instvar fid_
98 set fid_ 0
99 global prog opts ns n
100 set ns [new Simulator]
101 Simulator set EnableMcast_ 1
102 Simulator set NumberInterfaces_ 1
103
104 #Node expandaddr
105
106 $ns color 0 white ;# data packets
107 $ns color 40 blue ;# session
108 $ns color 41 red ;# request
109 $ns color 42 green ;# repair
110 $ns color 1 azure ;# source node
111 $ns color 2 lavender ;# recvr node
112 $ns color 3 navy ;# traffic
113 $ns color 4 SeaGreen
114 $ns color 5 green
115 $ns color 6 DarkGreen
116 $ns color 7 coral
117 $ns color 8 OrangeRed
118 $ns color 9 maroon
119 $ns color 10 DarkBlue
120
121 $self set_traces
122 return $self
123 }
124
125 proc set_flowMonitor {flowmon output_chan} {
126
127 $flowmon attach $output_chan
128 set bytesInt_ [new Integrator]
129 set pktsInt_ [new Integrator]
130 $flowmon set-bytes-integrator $bytesInt_
131 $flowmon set-pkts-integrator $pktsInt_
132 return $flowmon
133 }
134
135 ScenLib/RM instproc make_flowmon { time args } {
136 global ns
137 $self instvar flowmon_
138 #puts "time = $time"
139 #puts "args = $args"
140 if {[expr [llength $args] % 3] != 0} {
141 puts stderr {Error: Incomplete arguments for make_flowmon..}
142 }
143 #set c 0
144 for {set i 0} {$i < [llength $args]} {incr i} {
145 set node1 [lindex $args $i]
146 incr i
147 set node2 [lindex $args $i]
148 incr i
149 set fout [lindex $args $i]
150 set a [$node1 id]
151 set b [$node2 id]
152 set flow_stat($a:$b) [open $fout w]
153 set flowmon_($a:$b) [$ns makeflowmon Fid]
154 $ns attach-fmon [$ns link $node1 $node2] $flowmon_($a:$b) 0
155 set_flowMonitor $flowmon_($a:$b) $flow_stat($a:$b)
156 #$ns at $time "$flowmon_($a:$b) dump"
157 #incr c
158 }
159 }
160
161 ScenLib/RM instproc dump_flowmon {n1 n2 time} {
162 $self instvar flowmon_
163 global ns n
164 $ns at $time "$flowmon_([$n1 id]:[$n2 id]) dump"
165 }
166
167
168
169 ScenLib/RM instproc make_nodes num {
170 global ns n
171 # setup the nodes
172 for {set i 0} {$i < $num} {incr i} {
173 set n($i) [$ns node]
174 #puts "node($i) -> $n($i)"
175 }
176 }
177
178 ScenLib/RM instproc create_mcast {srcnode switch addgrp time args} {
179 global ns n opts srmStats srmEvents mflag
180 $self instvar mrthandle_ fid_
181 if {$mflag == 0} {
182 set mrthandle_ [$ns mrtproto $opts(routingProto) {}]
183 #puts "setting the mcastproto- $opts(routingProto)"
184 set mflag 1
185 }
186 set dest [Node allocaddr]
187 puts "mcast grp = $dest"
188 $ns at $switch "$mrthandle_ switch-treetype $dest"
189 #puts "ns at $switch $mrthandle_ switch-treetype $dest"
190
191 set src [new Agent/$opts(srmSimType)]
192 $src set dst_ $dest
193 $src set fid_ [incr fid_]
194 #puts "srcnode $srcnode fid -> [$src set fid_]"
195 #$src trace $srmEvents
196 #$src log $srmStats
197 #$ns at 1.0 "$src start"
198 $ns at $addgrp "$src start"
199 # puts "ns at $addgrp src start"
200 $ns attach-agent $n($srcnode) $src
201
202 for {set i 0} {$i < [llength $args]} {incr i} {
203 set j [lindex $args $i]
204 set rcvr($j) [new Agent/$opts(srmSimType)]
205 $rcvr($j) set dst_ $dest
206 $rcvr($j) set fid_ [incr fid_]
207 #puts "Srm-recr $j fid -> [$rcvr($j) set fid_]"
208 #$rcvr($j) trace $srmEvents
209 #$rcvr($j) log $srmStats
210 $ns attach-agent $n($j) $rcvr($j)
211 #$ns at 1.0 "$rcvr($j) start"
212 $ns at $addgrp "$rcvr($j) start"
213 # puts "ns at$addgrp rcvr($j) start"
214 }
215 #setup source
216 set cbr [new Agent/$opts(rmSrcType)]
217 $cbr set packetSize_ $opts(pktSize)
218 $src traffic-source $cbr
219 $src set packetSize_ $opts(pktSize) ;#so repairs are correct
220 $cbr set fid_ [incr fid_]
221 #puts "cbr fid = [$cbr set fid_]"
222 $ns at $time "$src start-source"
223 }
224
225 ScenLib/RM instproc create_cbr { args } {
226 if {[expr [llength $args] % 5] != 0} {
227 puts stderr {uneven number of tcp endpoints}
228 }
229 global ns n opts
230 $self instvar fid_
231 # Attach a CBR source and connect between a sender and recr
232 # node at the given time
233 for {set i 0} {$i < [llength $args]} {incr i} {
234 set k [lindex $args $i]
235 set cbr($k) [new Agent/CBR]
236
237 $cbr($k) set fid_ [incr fid_]
238 $cbr($k) set packetSize_ $opts(pktSize)
239 incr i
240 $cbr($k) set interval_ [lindex $args $i]
241 $ns attach-agent $n($k) $cbr($k)
242 incr i
243 set null($k) [new Agent/Null]
244 $ns attach-agent $n([lindex $args $i]) $null($k)
245 $ns connect $cbr($k) $null($k)
246 incr i
247 $ns at [lindex $args $i] "$cbr($k) start"
248 incr i
249 $ns at [lindex $args $i] "$cbr($k) stop"
250 }
251 }
252
253
254 proc loss-model10 {} {
255 global ns
256 #setup loss model
257 #set loss_module [new ErrorModel]
258 #$loss_module set rate_ 0.1
259 set loss_module [new SRMErrorModel]
260 $loss_module set rate_ 0.1
261 #$loss_module drop-packet 2 200 1
262 $loss_module drop-target [$ns set nullAgent_]
263 return $loss_module
264 }
265
266 proc loss-model5 {} {
267 global ns
268 set loss_module [new SRMErrorModel]
269 $loss_module set rate_ 0.05
270 #$loss_module drop-packet 2 200 1
271 $loss_module drop-target [$ns set nullAgent_]
272 return $loss_module
273 }
274
275 ScenLib/RM instproc loss-model-case1 {time a b} {
276 global ns n
277 set loss_module [loss-model10]
278 $ns at $time "$ns lossmodel $loss_module $n($a) $n($b)"
279 }
280
281 ScenLib/RM instproc loss-model-case2 {time1 time2 a b c d} {
282 global ns n
283 set loss_module1 [loss-model10]
284 set loss_module2 [loss-model10]
285 $ns at $time1 "$ns lossmodel $loss_module1 $n($a) $n($b)"
286 $ns at $time2 "$ns lossmodel $loss_module2 $n($c) $n($d)"
287 }
288
289 ScenLib/RM instproc loss-model-case3 {time1 time2 a b c d} {
290 global ns n
291 set loss_module1 [loss-model5]
292 set loss_module2 [loss-model10]
293 $ns at $time1 "$ns lossmodel $loss_module1 $n($a) $n($b)"
294 $ns at $time2 "$ns lossmodel $loss_module2 $n($c) $n($d)"
295 }
296
297
298 ScenLib/RM instproc create_tcp {args} {
299 if {[expr [llength $args] % 3] != 0} {
300 puts stderr {uneven number of tcp endpoints}
301 }
302 global ns n opts
303 $self instvar fid_
304 #Attach a TCP flow between each src and recvr pair
305 for {set i 0} {$i < [llength $args]} {incr i} {
306 set k [lindex $args $i]
307 set tcp($k) [new Agent/$opts(tcpType)]
308
309 $tcp($k) set fid_ [incr fid_]
310 $tcp($k) set packetSize_ $opts(pktSize)
311 $ns attach-agent $n($k) $tcp($k)
312 #puts "ns attach-agent n($k) tcp (fid [$tcp($k) set fid_]"
313
314 incr i
315 set tcp_sink($k) [new Agent/$opts(sinkType)]
316 $ns attach-agent $n([lindex $args $i]) $tcp_sink($k)
317 #puts "dest=[lindex $args $i]"
318 $ns connect $tcp($k) $tcp_sink($k)
319 incr i
320 set ftp($k) [new Application/$opts(tcpSrcType)]
321 $ftp($k) attach-agent $tcp($k)
322 set time [lindex $args $i]
323 $ns at $time "$ftp($k) start"
324 #puts "At $time, tcp (from node$k) starts.. "
325 }
326 }
327
328 proc finish {} {
329 global prog ns opts srmEvents srmStats t
330 #$src stop
331 puts "Running finish.."
332 $ns flush-trace
333 #close $srmStats
334 #close $srmEvents
335 #XXX
336 #puts "Filtering ..."
337 #exec tclsh8.0 ../../../../nam-1/bin/namfilter.tcl out-$t.nam
338 puts "running nam..."
339 exec nam out-$t.nam &
340 exit 0
341 }
342
343
344
345
346
347
348
349
350