SHOW:
|
|
- or go back to the newest paste.
1 | #network size | |
2 | set x_dim 1000 | |
3 | set y_dim 1000 | |
4 | ||
5 | #number of nodes and positions | |
6 | set num_row 10 ;#number of row | |
7 | set num_col 5 ;#number of column | |
8 | ||
9 | #number and other attributes of flow | |
10 | set time_duration 5 ;#50 | |
11 | set start_time 10.0 ;#100 | |
12 | set parallel_start_gap 1.0 | |
13 | ||
14 | #energy parameters | |
15 | set val(energymodel_11) EnergyModel ; | |
16 | set val(initialenergy_11) 1000 ;# Initial energy in Joules | |
17 | set val(idlepower_11) 900e-3 ;#Stargate (802.11b) | |
18 | set val(rxpower_11) 925e-3 ;#Stargate (802.11b) | |
19 | set val(txpower_11) 1425e-3 ;#Stargate (802.11b) | |
20 | set val(sleeppower_11) 300e-3 ;#Stargate (802.11b) | |
21 | set val(transitionpower_11) 200e-3 ;#Stargate (802.11b) ??????????????????????????????/ | |
22 | set val(transitiontime_11) 3 ;#Stargate (802.11b) | |
23 | ||
24 | #number of different flows | |
25 | set num_parallel_flow 20 | |
26 | set num_cross_flow 10 | |
27 | set num_random_flow 0 | |
28 | ||
29 | set grid 0 | |
30 | set extra_time 10 ;#10 | |
31 | set cbr_size 1000 | |
32 | set cbr_rate 11.0Mb | |
33 | set cbr_interval 1;# ?????? 1 for 1 packets per second and 0.1 for 10 packets per second | |
34 | ||
35 | set tcp_src Agent/UDP ;# Agent/TCP or Agent/TCP/Reno or Agent/TCP/Newreno or Agent/TCP/FullTcp/Sack or Agent/TCP/Vegas | |
36 | set tcp_sink Agent/Null ;# Agent/TCPSink or Agent/TCPSink/Sack1 | |
37 | ||
38 | #protocols and models for different layers | |
39 | set val(chan) Channel/WirelessChannel ;# channel type | |
40 | set val(prop) Propagation/TwoRayGround ;# radio-propagation model | |
41 | #set val(prop) Propagation/FreeSpace ;# radio-propagation model | |
42 | - | set val(netif) Phy/WirelessPhy ;# network interface type |
42 | + | set val(netif) Phy/WirelessPhy/802_15_4 ;# network interface type |
43 | #set val(mac) Mac/802_11 ;# MAC type | |
44 | set val(mac) Mac/802_15_4 ;# MAC type | |
45 | set val(ifq) Queue/DropTail/PriQueue ;# interface queue type | |
46 | set val(ll) LL ;# link layer type | |
47 | set val(ant) Antenna/OmniAntenna ;# antenna model | |
48 | set val(ifqlen) 50 ;# max packet in ifq | |
49 | set val(rp) DSDV ;# routing protocol | |
50 | ||
51 | #initialize ns | |
52 | set ns [new Simulator] | |
53 | ||
54 | #initialize trace files | |
55 | set tracefile1 [open mobileout.tr w] | |
56 | $ns trace-all $tracefile1 | |
57 | #$ns use-newtrace ;# use the new wireless trace file format | |
58 | ||
59 | set namfile1 [open mobileout.nam w] | |
60 | $ns namtrace-all-wireless $namfile1 $x_dim $y_dim | |
61 | ||
62 | #set topology file | |
63 | set topofile [open "mobiletopo.txt" w] | |
64 | ||
65 | # set up topography object | |
66 | set topo [new Topography] | |
67 | $topo load_flatgrid $x_dim $y_dim | |
68 | #$topo load_flatgrid 1000 1000 | |
69 | ||
70 | #helps us find the distance between two routers | |
71 | #GoD object keeps track of global info like topology, next hop | |
72 | create-god [expr $num_row * $num_col] | |
73 | ||
74 | #node-config | |
75 | $ns node-config -adhocRouting $val(rp) -llType $val(ll) \ | |
76 | -macType $val(mac) -ifqType $val(ifq) \ | |
77 | -ifqLen $val(ifqlen) -antType $val(ant) \ | |
78 | -propType $val(prop) -phyType $val(netif) \ | |
79 | -channel [new $val(chan)] -topoInstance $topo \ | |
80 | -agentTrace ON -routerTrace OFF\ | |
81 | -macTrace ON \ | |
82 | -movementTrace OFF \ | |
83 | -energyModel $val(energymodel_11) \ | |
84 | -idlePower $val(idlepower_11) \ | |
85 | -rxPower $val(rxpower_11) \ | |
86 | -txPower $val(txpower_11) \ | |
87 | -sleepPower $val(sleeppower_11) \ | |
88 | -transitionPower $val(transitionpower_11) \ | |
89 | -transitionTime $val(transitiontime_11) \ | |
90 | -initialEnergy $val(initialenergy_11) | |
91 | ||
92 | #create nodes | |
93 | puts "start node creation" | |
94 | for {set i 0} {$i < [expr $num_row*$num_col]} {incr i} { | |
95 | set node_($i) [$ns node] | |
96 | #static network | |
97 | $node_($i) random-motion 0 | |
98 | } | |
99 | ||
100 | #set positions for nodes | |
101 | set x_start [expr $x_dim/($num_col*2)]; | |
102 | set y_start [expr $y_dim/($num_row*2)]; | |
103 | set i 0; | |
104 | while {$i < $num_row } { | |
105 | #in same column | |
106 | for {set j 0} {$j < $num_col } {incr j} { | |
107 | #in same row | |
108 | set m [expr $i*$num_col+$j]; | |
109 | ||
110 | set x_pos [expr $x_start+$j*($x_dim/$num_col)];#grid settings | |
111 | set y_pos [expr $y_start+$i*($y_dim/$num_row)];#grid settings | |
112 | ||
113 | $node_($m) set X_ $x_pos; | |
114 | $node_($m) set Y_ $y_pos; | |
115 | $node_($m) set Z_ 0.0 | |
116 | # puts "$m" | |
117 | puts -nonewline $topofile "$m x: [$node_($m) set X_] y: [$node_($m) set Y_] \n" | |
118 | } | |
119 | incr i; | |
120 | }; | |
121 | ||
122 | #move the nodes | |
123 | set i 0 | |
124 | while {$i < $num_row*$num_col } { | |
125 | ||
126 | $ns at $i "$node_($i) setdest [expr $x_dim*rand()] [expr $y_dim*rand()] 5" | |
127 | incr i | |
128 | }; | |
129 | ||
130 | ||
131 | #create flows and associate them with nodes | |
132 | #parallel flow | |
133 | #sources and sinks created(Agents) | |
134 | for {set i 0} {$i < [expr $num_parallel_flow + $num_cross_flow + $num_random_flow]} {incr i} { | |
135 | # set udp_($i) [new Agent/UDP] | |
136 | # set null_($i) [new Agent/Null] | |
137 | ||
138 | set udp_($i) [new $tcp_src] | |
139 | $udp_($i) set class_ $i | |
140 | set null_($i) [new $tcp_sink] | |
141 | $udp_($i) set fid_ $i | |
142 | if { [expr $i%2] == 0} { | |
143 | $ns color $i Blue | |
144 | } else { | |
145 | $ns color $i Red | |
146 | } | |
147 | } | |
148 | ||
149 | #parallel flow | |
150 | #sources and sinks are attached with nodes | |
151 | for {set i 0} {$i < $num_parallel_flow } {incr i} { | |
152 | set udp_node $i | |
153 | set null_node [expr (($num_col)*($num_row-1))-$i-1];#CHNG | |
154 | $ns attach-agent $node_($udp_node) $udp_($i) | |
155 | $ns attach-agent $node_($null_node) $null_($i) | |
156 | puts -nonewline $topofile "PARALLEL: Src: $udp_node Dest: $null_node\n" | |
157 | } | |
158 | ||
159 | ||
160 | ||
161 | #udp sources are connected | |
162 | for {set i 0} {$i < $num_parallel_flow } {incr i} { | |
163 | $ns connect $udp_($i) $null_($i) | |
164 | } | |
165 | #cbr application attached | |
166 | for {set i 0} {$i < $num_parallel_flow } {incr i} { | |
167 | set cbr_($i) [new Application/Traffic/CBR] | |
168 | $cbr_($i) set packetSize_ $cbr_size | |
169 | $cbr_($i) set rate_ $cbr_rate | |
170 | $cbr_($i) set interval_ $cbr_interval | |
171 | $cbr_($i) attach-agent $udp_($i) | |
172 | } | |
173 | ||
174 | #cbr started | |
175 | for {set i 0} {$i < $num_parallel_flow } {incr i} { | |
176 | $ns at [expr $start_time+$i*$parallel_start_gap] "$cbr_($i) start" | |
177 | } | |
178 | ||
179 | #tell nodes when simulation ends | |
180 | for {set i 0} {$i < [expr $num_row*$num_col] } {incr i} { | |
181 | $ns at [expr $start_time+$time_duration] "$node_($i) reset"; | |
182 | } | |
183 | $ns at [expr $start_time+$time_duration +$extra_time] "finish" | |
184 | #$ns_ at [expr $start_time+$time_duration +20] "puts \"NS Exiting...\"; $ns_ halt" | |
185 | $ns at [expr $start_time+$time_duration +$extra_time] "$ns nam-end-wireless [$ns now]; puts \"NS Exiting...\"; $ns halt" | |
186 | ||
187 | $ns at [expr $start_time+$time_duration/2] "puts \"half of the simulation is finished\"" | |
188 | $ns at [expr $start_time+$time_duration] "puts \"end of simulation duration\"" | |
189 | ||
190 | proc finish {} { | |
191 | puts "finishing" | |
192 | global ns tracefile1 namfile1 topofile | |
193 | #global ns_ topofile | |
194 | $ns flush-trace | |
195 | close $tracefile1 | |
196 | close $namfile1 | |
197 | close $topofile | |
198 | exec nam mobileout.nam & | |
199 | exit 0 | |
200 | } | |
201 | ||
202 | #defining nodes for NAM | |
203 | for {set i 0} {$i < [expr $num_row*$num_col] } { incr i} { | |
204 | $ns initial_node_pos $node_($i) 4 | |
205 | } | |
206 | ||
207 | puts "Starting Simulation..." | |
208 | $ns run |