Debian Codegraph @

tcl/edu/rts-cts/rts-cts-data-ack.tcl

raw
1 #Copyright (c) 1997 Regents of the University of California.
2 # All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions
6 # are met:
7 # 1. Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 # 2. Redistributions in binary form must reproduce the above copyright
10 # notice, this list of conditions and the following disclaimer in the
11 # documentation and/or other materials provided with the distribution.
12 # 3. All advertising materials mentioning features or use of this software
13 # must display the following acknowledgement:
14 # This product includes software developed by the Computer Systems
15 # Engineering Group at Lawrence Berkeley Laboratory.
16 # 4. Neither the name of the University nor of the Laboratory may be used
17 # to endorse or promote products derived from this software without
18 # specific prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 # SUCH DAMAGE.
31 #
32
33 Mac/Simple set bandwidth_ 1Mb
34
35 set MESSAGE_PORT 42
36 set BROADCAST_ADDR -1
37
38
39 #set val(chan) Channel/WirelessChannel ;#Channel Type
40 set val(prop) Propagation/TwoRayGround ;# radio-propagation model
41 set val(netif) Phy/WirelessPhy ;# network interface type
42
43
44
45 set val(mac) Mac/802_11 ;# MAC type
46 #set val(mac) Mac ;# MAC type
47 #set val(mac) Mac/Simple
48
49
50 set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
51 set val(ll) LL ;# link layer type
52 set val(ant) Antenna/OmniAntenna ;# antenna model
53 set val(ifqlen) 32768 ;# max packet in ifq
54
55
56 set val(rp) DumbAgent
57
58
59 set ns [new Simulator]
60
61 set f [open rts-cts-data-ack.tr w]
62 $ns trace-all $f
63 $ns eventtrace-all
64 set nf [open rts-cts-data-ack-temp.nam w]
65 $ns namtrace-all-wireless $nf 700 200
66
67 # set up topography object
68 set topo [new Topography]
69
70 $topo load_flatgrid 700 200
71
72 $ns color 3 green;
73 $ns color 8 red;
74 $ns color 1 black;
75 $ns color 7 purple;
76 $ns color 6 tan;
77 $ns color 2 orange;
78
79 #
80 # Create God
81 #
82 create-god 3
83
84
85 #set mac0 [new Mac/802_11]
86
87 $ns node-config -adhocRouting $val(rp) \
88 -llType $val(ll) \
89 -macType $val(mac) \
90 -ifqType $val(ifq) \
91 -ifqLen $val(ifqlen) \
92 -antType $val(ant) \
93 -propType $val(prop) \
94 -phyType $val(netif) \
95 -channelType Channel/WirelessChannel \
96 -topoInstance $topo \
97 -agentTrace ON \
98 -routerTrace OFF \
99 -macTrace ON \
100 -movementTrace OFF
101
102 for {set i 0} {$i < 3} {incr i} {
103 set node_($i) [$ns node]
104 $node_($i) random-motion 0
105 }
106
107 $node_(0) color black
108 $node_(1) color black
109 $node_(2) color black
110
111
112 $node_(0) set X_ 200.0
113 $node_(0) set Y_ 30.0
114 $node_(0) set Z_ 0.0
115
116 $node_(1) set X_ 330.0
117 $node_(1) set Y_ 150.0
118 $node_(1) set Z_ 0.0
119
120 $node_(2) set X_ 60.0
121 $node_(2) set Y_ 30.0
122 $node_(2) set Z_ 0.0
123
124 $ns at 0.6 "$node_(2) setdest 330.0 30.0 10000.0"
125 $ns at 1.1 "$node_(2) setdest 500.0 30.0 10000.0"
126
127 # subclass Agent/MessagePassing to make it do flooding
128
129 Class Agent/MessagePassing/Flooding -superclass Agent/MessagePassing
130
131 Agent/MessagePassing/Flooding instproc recv {source sport size data} {
132 $self instvar messages_seen node_
133 global ns 1
134
135 # extract message ID from message
136 set message_id [lindex [split $data ":"] 0]
137 puts "\nNode [$node_ node-addr] got message $message_id\n"
138
139 if {[lsearch $messages_seen $message_id] == -1} {
140 lappend messages_seen $message_id
141 $ns trace-annotate "[$node_ node-addr] received {$data} from $source"
142 $ns trace-annotate "[$node_ node-addr] sending message $message_id"
143 $self sendto $size $data 1 $sport
144 } else {
145 $ns trace-annotate "[$node_ node-addr] received redundant message $message_id from $source"
146 }
147 }
148
149 Agent/MessagePassing/Flooding instproc send_message {size message_id data port} {
150 $self instvar messages_seen node_
151 global ns MESSAGE_PORT 1
152
153 lappend messages_seen $message_id
154 $ns trace-annotate "[$node_ node-addr] sending message $message_id"
155 $self sendto $size "$message_id:$data" 1 $port
156 }
157
158
159
160 # attach a new Agent/MessagePassing/Flooding to each node on port $MESSAGE_PORT
161 for {set i 0} {$i < 3} {incr i} {
162 set a($i) [new Agent/MessagePassing/Flooding]
163 $node_($i) attach $a($i) $MESSAGE_PORT
164 $a($i) set messages_seen {}
165 }
166
167 $ns at 0.1 "$a(0) send_message 500 1 {first_message} $MESSAGE_PORT"
168 $ns at 0.1 "$a(2) send_message 500 2 {second_message} $MESSAGE_PORT"
169
170 $ns at 0.8 "$a(0) send_message 500 5 {fifth_message} $MESSAGE_PORT"
171 $ns at 0.8 "$a(2) send_message 500 6 {sixth_message} $MESSAGE_PORT"
172
173 $ns at 1.3 "$a(2) send_message 500 15 {fifteenth_message} $MESSAGE_PORT"
174 $ns at 1.3 "$a(0) send_message 500 16 {sixteenth_message} $MESSAGE_PORT"
175
176 for {set i 0} {$i < 3} {incr i} {
177 $ns initial_node_pos $node_($i) 30
178 $ns at 20.0 "$node_($i) reset";
179 }
180
181 $ns at 20.0 "finish"
182 $ns at 20.1 "puts \"NS EXITING...\"; $ns halt"
183
184
185
186 #INSERT ANNOTATIONS HERE
187
188 proc finish {} {
189 global ns f nf val
190 $ns flush-trace
191 close $f
192 close $nf
193
194 }
195
196 puts "Starting Simulation..."
197
198 $ns run
199