Debian Codegraph @

tcl/ex/scuba/complete/demo.tcl

raw
1 #
2 # Copyright (c) @ Regents of the University of California.
3 # All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
7 # are met:
8 # 1. Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
13 # 3. All advertising materials mentioning features or use of this software
14 # must display the following acknowledgement:
15 # This product includes software developed by the MASH Research
16 # Group at the University of California Berkeley.
17 # 4. Neither the name of the University nor of the Research Group may be
18 # used to endorse or promote products derived from this software without
19 # specific prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 # SUCH DAMAGE.
32 #
33 # @(#) $Header: /cvsroot/nsnam/ns-2/tcl/ex/scuba/complete/demo.tcl,v 1.4 1997/11/29 07:11:00 elan Exp $
34 #
35
36 set tcldir ../../../
37
38 source $tcldir/rtp/session-scuba.tcl
39 source $tcldir/rtp/session-rtp.tcl
40
41 proc flash_annotate { start duration msg } {
42 global ns
43 $ns at $start "trace_annotate {$msg}"
44 # $ns at [expr $start+$duration] "trace_annotate {}"
45 }
46
47 set ns [new Simulator]
48 Simulator set EnableMcast_ 1
49 Simulator set NumberInterfaces_ 1
50
51 # rtcp reports
52 $ns color 32 red
53 # scuba reports
54 $ns color 33 green
55
56 $ns color 1 gold
57 $ns color 2 blue
58 $ns color 3 orange
59 $ns color 4 magenta
60
61 for { set i 0 } { $i < 8 } { incr i } {
62 set node($i) [$ns node]
63 }
64 $node(3) shape "square"
65 $node(7) shape "square"
66
67 set f [open out.tr w]
68 $ns trace-all $f
69 set nf [open out.nam w]
70 $ns namtrace-all $nf
71
72 Queue set limit_ 8
73
74 proc makelinks { bw delay pairs } {
75 global ns node
76 foreach p $pairs {
77 set src $node([lindex $p 0])
78 set dst $node([lindex $p 1])
79 $ns duplex-link $src $dst $bw $delay DropTail
80 $ns duplex-link-op $src $dst orient [lindex $p 2]
81 }
82 }
83
84 makelinks 1.5Mb 10ms {
85 { 0 3 right-down }
86 { 1 3 right }
87 { 2 3 right-up }
88 { 7 4 right-up }
89 { 7 5 right }
90 { 7 6 right-down }
91 }
92
93 makelinks 400kb 50ms {
94 { 3 7 right }
95 }
96
97 $ns duplex-link-op $node(3) $node(7) queuePos 0.5
98 set mproto DM
99 set mrthandle [$ns mrtproto $mproto {}]
100
101
102 #for { set i 0 } { $i < 8 } { incr i } {
103 # set dm($i) [new DM $ns $node($i)]
104 #}
105
106 $ns at 0.0 "$ns run-mcast"
107
108 set sessbw 400kb/s
109
110 foreach n { 0 1 2 4 5 6 } {
111 set sess($n) [new Session/RTP]
112 $sess($n) session_bw $sessbw
113 $sess($n) attach-node $node($n)
114 }
115
116 $ns at 0.1 {
117 global sess
118 foreach n { 0 1 2 4 5 6 } {
119 $sess($n) join-group 0x8000
120 }
121 }
122
123 foreach n { 0 1 2 } {
124 set d [$sess($n) set dchan_]
125 $d set class_ [expr $n]
126 }
127
128 flash_annotate 0 0.20 "Equal bandwidth - Saturate"
129 flash_annotate 0.25 0.1 "Starting Receivers..."
130
131 # start receivers
132 $ns at 0.25 {
133 global sess
134 $sess(4) start
135 $sess(5) start
136 $sess(6) start
137 }
138
139 # start senders
140 flash_annotate 0.5 0.2 "Starting sender 0 at 200kb/s..."
141 $ns at 0.5 "$sess(0) start"
142 $ns at 0.5 "$sess(0) transmit 200kb/s"
143
144 flash_annotate 1.0 0.2 "Starting sender 1 at 200kb/s..."
145 $ns at 1.0 "$sess(1) start"
146 $ns at 1.0 "$sess(1) transmit 200kb/s"
147
148 flash_annotate 1.5 0.2 "Starting sender 2 at 200kb/s..."
149 $ns at 1.5 "$sess(2) start"
150 $ns at 1.5 "$sess(2) transmit 200kb/s"
151
152 $ns at 1.75 {
153 global sess
154 foreach n { 0 1 2 } {
155 $sess($n) stop
156 }
157 }
158
159 $ns at 2.0 "trace_annotate {End}"
160
161
162 $ns at 2.5 "trace_annotate {Equal Bandwidth - No Saturation}"
163
164 # start senders
165 flash_annotate 3.0 0.2 "Starting sender 0 at 130kb/s..."
166 $ns at 3.0 "$sess(0) start"
167 $ns at 3.0 "$sess(0) transmit 130kb/s"
168
169 flash_annotate 3.5 0.2 "Starting sender 1 at 130kb/s..."
170 $ns at 3.5 "$sess(1) start"
171 $ns at 3.5 "$sess(1) transmit 130kb/s"
172
173 flash_annotate 4.0 0.2 "Starting sender 2 at 130kb/s..."
174 $ns at 4.0 "$sess(2) start"
175 $ns at 4.0 "$sess(2) transmit 130kb/s"
176
177 $ns at 4.5 {
178 global sess
179 foreach n { 0 1 2 } {
180 $sess($n) stop
181 }
182 }
183
184 $ns at 5.0 "trace_annotate {End}"
185
186
187 set scuba_sim_time 5.5
188 $ns at $scuba_sim_time "scuba_sim $scuba_sim_time"
189 $ns at [expr $scuba_sim_time + 4.7] "finish"
190
191 proc scuba_sim { start } {
192 global ns sess node sessbw
193
194 flash_annotate $start 0.2 {SCUBA}
195 foreach n { 0 1 2 4 5 6 } {
196 set sess($n) [new Session/RTP/Scuba]
197 $sess($n) session_bw $sessbw
198 $sess($n) attach-node $node($n)
199 }
200
201 set t [expr $start+0.5]
202 $ns at $t {
203 global sess
204 foreach n { 0 1 2 4 5 6 } {
205 $sess($n) join-group 0x8000
206 }
207 }
208
209 foreach n { 0 1 2 } {
210 set d [$sess($n) set dchan_]
211 $d set class_ [expr $n]
212 }
213
214 flash_annotate $t 0.2 {Starting receivers...}
215 # start receivers
216 $ns at $t {
217 global sess
218 $sess(4) start 0 1
219 $sess(5) start 0 1
220 $sess(6) start 0 1
221 }
222
223 # start senders
224 flash_annotate [expr $start+1.1] 0.05 "Starting sender 0..."
225 $ns at [expr $start+1.1] "$sess(0) start 1 0"
226
227 flash_annotate [expr $start+1.2] 0.05 "Starting sender 1..."
228 $ns at [expr $start+1.2] "$sess(1) start 1 0"
229
230 flash_annotate [expr $start+1.3] 0.05 "Starting sender 2..."
231 $ns at [expr $start+1.3] "$sess(2) start 1 0"
232
233 # 4 focus on 0
234 flash_annotate [expr $start+1.5] 0.1 "4 focussing on 0..."
235 $ns at [expr $start+1.5] "[$sess(4) set repAgent_] set class_ 4"
236 $ns at [expr $start+1.5] "$sess(4) scuba_focus $sess(0)"
237 $ns at [expr $start+1.55] "[$sess(4) set repAgent_] set class_ 33"
238
239 # 5 focus on 1
240 flash_annotate [expr $start+2.0] 0.1 "5 focussing on 1..."
241 $ns at [expr $start+2.0] "[$sess(5) set repAgent_] set class_ 4"
242 $ns at [expr $start+2.0] "$sess(5) scuba_focus $sess(1)"
243 $ns at [expr $start+2.05] "[$sess(5) set repAgent_] set class_ 33"
244
245 # 5 focus on 0
246 flash_annotate [expr $start+2.5] 0.1 "5 focussing on 0..."
247 $ns at [expr $start+2.5] "[$sess(5) set repAgent_] set class_ 4"
248 $ns at [expr $start+2.5] "$sess(5) scuba_focus $sess(0)"
249 $ns at [expr $start+2.55] "[$sess(5) set repAgent_] set class_ 33"
250
251 # 5 unfocus on 0
252 flash_annotate [expr $start+3.0] 0.1 "5 unfocussing off 0..."
253 $ns at [expr $start+3.0] "[$sess(5) set repAgent_] set class_ 4"
254 $ns at [expr $start+3.0] "$sess(5) scuba_unfocus $sess(0)"
255 $ns at [expr $start+3.05] "[$sess(5) set repAgent_] set class_ 33"
256
257 # 4,5 unfocus on 1,0 and focus on 2
258 flash_annotate [expr $start+3.5] 0.1 "4,5 unfocussing off 1,0 and focus on 2..."
259 $ns at [expr $start+3.5] "[$sess(5) set repAgent_] set class_ 4"
260 $ns at [expr $start+3.5] "[$sess(4) set repAgent_] set class_ 4"
261 $ns at [expr $start+3.5] "$sess(5) scuba_unfocus $sess(1)"
262 $ns at [expr $start+3.5] "$sess(4) scuba_unfocus $sess(0)"
263 $ns at [expr $start+3.5] "$sess(5) scuba_focus $sess(2)"
264 $ns at [expr $start+3.5] "$sess(4) scuba_focus $sess(2)"
265 $ns at [expr $start+3.55] "[$sess(5) set repAgent_] set class_ 33"
266 $ns at [expr $start+3.55] "[$sess(4) set repAgent_] set class_ 33"
267 }
268
269 proc finish {} {
270 trace_annotate "End Simulation"
271 global tcldir
272 puts "converting output to nam format..."
273 global ns
274 $ns flush-trace
275
276 puts "running nam..."
277 exec /usr/local/src/nam-1/nam out.nam &
278 exit 0
279 }
280
281 $ns run
282