Debian Codegraph @

tcl/ex/scuba/simple/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/simple/demo.tcl,v 1.3 1997/11/04 22:03:42 haoboy Exp $
34 #
35
36 set tcldir ../../../
37
38 source $tcldir/rtp/session-scuba.tcl
39 source $tcldir/rtp/session-rtp.tcl
40
41 set ns [new Simulator]
42 Simulator set EnableMcast_ 1
43 Simulator set NumberInterfaces_ 1
44
45 # rtcp reports
46 $ns color 32 red
47 # scuba reports
48 $ns color 33 white
49
50 $ns color 1 gold
51 $ns color 2 blue
52 $ns color 3 green
53 $ns color 4 magenta
54
55 for { set i 0 } { $i < 8 } { incr i } {
56 set node($i) [$ns node]
57 }
58 $node(3) shape "square"
59 $node(7) shape "square"
60
61 set f [open out.tr w]
62 $ns trace-all $f
63 set nf [open out.nam w]
64 $ns namtrace-all $nf
65
66 Queue set limit_ 8
67
68 proc makelinks { bw delay pairs } {
69 global ns node
70 foreach p $pairs {
71 set src $node([lindex $p 0])
72 set dst $node([lindex $p 1])
73 $ns duplex-link $src $dst $bw $delay DropTail
74 $ns duplex-link-op $src $dst orient [lindex $p 2]
75 }
76 }
77
78 makelinks 1.5Mb 10ms {
79 { 0 3 right-down }
80 { 1 3 right }
81 { 2 3 right-up }
82 { 7 4 right-up }
83 { 7 5 right }
84 { 7 6 right-down }
85 }
86
87 makelinks 400kb 50ms {
88 { 3 7 right }
89 }
90
91 $ns duplex-link-op $node(3) $node(7) queuePos 0.5
92
93 set mproto DM
94 set mrthandle [$ns mrtproto $mproto {}]
95
96 $ns at 0.0 "$ns run-mcast"
97
98 set sessbw 400kb/s
99
100 foreach n { 0 1 2 4 5 6 } {
101 set sess($n) [new Session/RTP/Scuba]
102 $sess($n) session_bw $sessbw
103 $sess($n) attach-node $node($n)
104 }
105
106 $ns at 1.0 {
107 global sess
108 foreach n { 0 1 2 4 5 6 } {
109 $sess($n) join-group 0x8000
110 }
111 }
112
113 foreach n { 0 1 2 } {
114 set d [$sess($n) set dchan_]
115 $d set class_ [expr $n]
116 }
117
118 $ns at 1.0 "trace_annotate {Starting receivers...}"
119 # start receivers
120 $ns at 1.1 {
121 global sess
122 $sess(4) start 0
123 $sess(5) start 0
124 $sess(6) start 0
125 }
126
127 # start senders
128 $ns at 1.1 "trace_annotate {Starting sender 1...}"
129 $ns at 1.1 "$sess(0) start 1"
130
131 $ns at 1.2 "trace_annotate {Starting sender 2...}"
132 $ns at 1.2 "$sess(1) start 1"
133
134 $ns at 1.3 "trace_annotate {Starting sender 3...}"
135 $ns at 1.3 "$sess(2) start 1"
136
137 # 4 focus on 0
138 $ns at 2.0 "trace_annotate {4 focussing on 0...}"
139 $ns at 2.0 "[$sess(4) set repAgent_] set class_ 3"
140 $ns at 2.0 "$sess(4) scuba_focus $sess(0)"
141
142 # 5 focus on 1
143 $ns at 3.0 "trace_annotate {5 focussing on 1...}"
144 $ns at 3.0 "[$sess(4) set repAgent_] set class_ 3"
145 $ns at 3.0 "$sess(5) scuba_focus $sess(1)"
146
147 # 5 focus on 0
148 $ns at 4.0 "trace_annotate {5 focussing on 0...}"
149 $ns at 4.0 "$sess(5) scuba_focus $sess(0)"
150
151 # 5 unfocus on 0
152 $ns at 5.0 "trace_annotate {5 unfocussing on 0...}"
153 $ns at 5.0 "[$sess(5) set repAgent_] set class_ 4"
154 $ns at 5.0 "$sess(5) scuba_unfocus $sess(0)"
155
156 $ns at 6.0 "finish"
157
158 proc finish {} {
159 global tcldir
160 puts "converting output to nam format..."
161 global ns
162 $ns flush-trace
163
164 puts "running nam..."
165 exec nam out.nam &
166 exit 0
167 }
168
169 $ns run
170