forked from flymin/aodv-uu-0.9.6_ns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ceshi.tcl
243 lines (214 loc) · 7.04 KB
/
ceshi.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#===============================================================================
# ENSC 835: High-Performance Networks
# Implementation of a Multi-Channel Multi-Interface Ad-Hoc Wireless Networks
#
# Student: Chih-Hao Howard Chang
# 20007-2192
# howardc@sfu.ca
#
# Description: Simulation script for multi-Channel multi-Interface Ad-Hoc
# wireless network in chain topologies
#
# File: wireless_chain_mcmi.tcl
#===============================================================================
#======================================
# MAC Layer Setup
#======================================
Mac/802_11 set dataRate_ 5.4e6 ;# rate for data frames in Mbps
#======================================
# Simulation Parameters Setup
#======================================
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(rp) AODVUU ;# routing protocol
set val(x) 1000 ;# X dimension of topography
set val(y) 1000 ;# Y dimension of topography
set val(stop) 70 ;# nam stop time
set val(nn) 8 ;# number of mobilenodes
set val(nc) 3 ;# number of channels
set val(ni) 3 ;# number of interfaces, <= number of channels
set val(pu) 2 ;# number of PUs
set pktsize 1000 ;# packet size in bytes
set pktrate 0.0016 ;# packet rate in seconds
set filename chain_replace
puts "Ad-Hoc Wireless Network in Chain Topologies - $val(nn) Nodes, $val(nc) Channels, $val(ni) Interfaces"
#======================================
# Initialization
#======================================
# Create a ns simulator
set ns_ [new Simulator]
# Setup topography object
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
set god_ [create-god [expr $val(nn)*$val(nc)]]
# Open the NS trace file
set tracefd [open $filename.tr w]
$ns_ trace-all $tracefd
$ns_ use-newtrace
# Open the NAM trace file
set namfile [open $filename.nam w]
$ns_ namtrace-all $namfile
$ns_ namtrace-all-wireless $namfile $val(x) $val(y)
# Create wireless channels
for {set i 0} {$i < $val(nc)} {incr i} {
set chan($i) [new $val(chan)]
}
#======================================
# Mobile Node Parameter Setup
#======================================
$ns_ node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $chan(0) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-movementTrace OFF \
-ifNum $val(ni) \
-workMode 0 \
-noiseChannel 0
#======================================
# Nodes Definition
#======================================
$ns_ change-numifs $val(nc)
for {set i 0} {$i < $val(nc)} {incr i} {
$ns_ add-channel $i $chan($i)
}
# Create nodes
for {set i 0} {$i < $val(nn)} {incr i} {
set n($i) [$ns_ node]
$god_ new_node $n($i)
}
# Set node positions in horizontal chain topology
set nodedist 250
#for {set i 0} {$i < $val(nn)} {incr i} {
# $n($i) set X_ [expr $i * $nodedist + 20]
# $n($i) set Y_ 50
# $n($i) set Z_ 0.0
# $ns_ initial_node_pos $n($i) 40
# $n($i) random-motion 0
#}
#modified for chain_replace procedure++++++++++++++++++++++++++++++++++++++++++
$n(0) set X_ 0
$n(0) set Y_ 300
$n(0) set Z_ 0.0
$ns_ initial_node_pos $n(0) 50
$n(0) random-motion 0
$n(1) set X_ 100
$n(1) set Y_ 300
$n(1) set Z_ 0.0
$ns_ initial_node_pos $n(1) 50
$n(1) random-motion 0
$n(2) set X_ 300
$n(2) set Y_ 300
$n(2) set Z_ 0.0
$ns_ initial_node_pos $n(2) 50
$n(2) random-motion 0
$n(3) set X_ 300
$n(3) set Y_ 0
$n(3) set Z_ 0.0
$ns_ initial_node_pos $n(3) 50
$n(3) random-motion 0
$n(4) set X_ 500
$n(4) set Y_ 300
$n(4) set Z_ 0.0
$ns_ initial_node_pos $n(4) 50
$n(4) random-motion 0
$n(5) set X_ 600
$n(5) set Y_ 300
$n(5) set Z_ 0.0
$ns_ initial_node_pos $n(5) 50
$n(5) random-motion 0
$n(6) set X_ 900
$n(6) set Y_ 400
$n(6) set Z_ 0.0
$ns_ initial_node_pos $n(6) 50
$n(7) random-motion 0
$n(7) set X_ 900
$n(7) set Y_ 400
$n(7) set Z_ 0.0
$ns_ initial_node_pos $n(7) 50
$n(7) random-motion 0
#motion part added here
$ns_ at 1.0 "$n(2) setdest 300.0 600.0 100.0"
$ns_ at 1.3 "$n(3) setdest 300.0 300.0 100.0"
$ns_ at 12.0 "$n(2) setdest 300.0 300.0 100.0"
$ns_ at 10.0 "$n(3) setdest 300.0 100.0 100.0"
$ns_ at 21.0 "$n(2) setdest 300.0 600.0 100.0"
$ns_ at 24.3 "$n(3) setdest 300.0 300.0 100.0"
#motion modified ends here
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#======================================
# PU Node Parameter Setup
#======================================
$ns_ node-config -workMode -1 \
-noiseChannel 0
set pu_node(0) [$ns_ node]
$god_ new_node $pu_node(0)
$pu_node(0) set X_ 500
$pu_node(0) set Y_ 200
$pu_node(0) set Z_ 0.0
$ns_ initial_node_pos $pu_node(0) 80
$pu_node(0) random-motion 0
$ns_ node-config -workMode -1 \
-noiseChannel 1
set pu_node(1) [$ns_ node]
$god_ new_node $pu_node(1)
$pu_node(1) set X_ 500
$pu_node(1) set Y_ 400
$pu_node(1) set Z_ 0.0
$ns_ initial_node_pos $pu_node(1) 80
$pu_node(1) random-motion 0
#======================================
# Agents Definition
#======================================
set udp0 [new Agent/UDP]
$ns_ attach-agent $n(0) $udp0
set sink0 [new Agent/Null]
set last_node_id [expr $val(nn)-1]
$ns_ attach-agent $n(5) $sink0
$ns_ connect $udp0 $sink0
#======================================
# Applications Definition
#======================================
# Setup a CBR Application over UDP connection
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0
$cbr0 set packetSize_ $pktsize
$cbr0 set interval_ $pktrate
$ns_ at 1.0 "$cbr0 start"
$ns_ at 61.0 "$cbr0 stop"
#======================================
# Simulation Termination
#======================================
# Define a finish procedure
proc finish {} {
global ns_ tracefd filename pktsize last_node_id
global namfile
$ns_ flush-trace
close $tracefd
close $namfile
exec nam $filename.nam &
# Call throughput analyzer (AWK scripts written by Marco Fiore, marco.fiore@polito.it)
# exec awk -f avgStats.awk src=0 dst=$last_node_id flow=0 pkt=$pktsize $filename.tr &
exit 0
}
for {set i 0} {$i < $val(nn) } { incr i } {
$ns_ at $val(stop) "\$n($i) reset"
}
$ns_ at $val(stop) "$ns_ nam-end-wireless $val(stop)"
$ns_ at $val(stop) "finish"
$ns_ at $val(stop) "puts \"done\" ; $ns_ halt"
$ns_ run