-
Notifications
You must be signed in to change notification settings - Fork 0
/
wired-cum-wireless-simple_model.tcl
executable file
·224 lines (184 loc) · 7.32 KB
/
wired-cum-wireless-simple_model.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
# ==================================================================== #
# LICENCIA
#
# Copyrigth (C) 2017 Franco Alejandro (0xalen)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# ==================================================================== #
# DESCRIPCIÓN DEL PROGRAMA
#
# Este programa es un modelo simple para una topología híbrica (cableada
# e inalámbrica) desarrollado en base a la documentación disponible en
# el manual (ver isi.edu/nsnam/ns/doc/ns_doc.pdf).
#
# El script fue diseñado con el objetivo de explicar el funcionamiento
# básico para topologías wired-cum-wireless. En ámbito de producción podría
# resultar más conveniente utilizar otras estructuras (e.g. al definir
# los nodos, su movimiento, etc).
# ==================================================================== #
# ======================================================================
# Programa principal
# ======================================================================
# ---------------------------------------------------------------------
# Definir opciones
# ---------------------------------------------------------------------
global val
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(nn) 1 ;# number of mobilenodes
set val(rp) DSDV ;# routing protocol
set val(x) 200
set val(y) 200
#
set wired_nodes 1
set bs_nodes 1
#
set vel 50.0
# ----------------------------------------------------------------------
# Inicializar variables globales y crear archivos de traza
# ----------------------------------------------------------------------
# Crear simulador
set ns_ [new Simulator]
# Configuracion de enrutamiento jerarquico
$ns_ node-config -addressType hierarchical
AddrParams set domain_num_ 2 ; # Numero de dominios
lappend cluster_num 1 2 ; # Numero de clusters por dominio 2 1 1
AddrParams set cluster_num_ $cluster_num ;
lappend eilastlevel 1 1 1 ; # Numero de nodos por cluster 1 1 4 1
AddrParams set nodes_num_ $eilastlevel ; # de cada domino
# Crear archivo de traza
set tracefd [open simple-wcw.tr w]
$ns_ use-newtrace
$ns_ trace-all $tracefd
# Crear archivo de traza de NAM
set ntf [open simple-wcw.nam w]
$ns_ use-newtrace
$ns_ namtrace-all-wireless $ntf $val(x) $val(y)
# Definir procedimiento de salida
proc finish {} {
global ns_ tracefd ntf
$ns_ flush-trace
close $tracefd
close $ntf
exec nam simple-wcw.nam &
exit 0
}
# Definir topografia del objeto
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
# Crear objeto God (General Operations Director)
# En wired-cum-wireless, God necesita saber el num de las interfaces wireless
create-god [expr $val(nn) + $bs_nodes]
# ----------------------------------------------------------------------
# Crear nodos
# NOTA: Para la creacion de cada nodo hay que pasar la direccion jerarquica
# del mismo. Formato de direccion (dominio.cluster.nodo)
# ----------------------------------------------------------------------
# ---------------------------------------------------------------------
# Crear nodos cableados (DOMINIO 0)
set wnode0 [$ns_ node 0.0.0]
# ---------------------------------------------------------------------
# Crear nodos inalambricos y base stations
# Crear canal #1
set chan_1_ [new $val(chan)]
# Configuracion para bs
$ns_ node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propInstance [new $val(prop)] \
-propType $val(prop) \
-phyType $val(netif) \
-topoInstance $topo \
-wiredRouting ON \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace OFF \
-channel $chan_1_
# ---------------------------------------------------------------------
# Crear BS (DOMINIO 1)
set BS0 [$ns_ node 1.0.0]
$BS0 random-motion 0
# Definir coordenadas iniciales para el bs (x, y, z=0)
$BS0 set X_ 10.0
$BS0 set Y_ 10.0
$BS0 set Z_ 0.0
# Configuracion para nodos moviles
$ns_ node-config -wiredRouting OFF
# ---------------------------------------------------------------------
# Crear nodos inalambricos (DOMINIO 2)
set node_2 [ $ns_ node 1.1.0]
$node_2 base-station [AddrParams addr2id [$BS0 node-addr]] ; # asigna al node_2 la dir jerarquica de BS(0)
# Definir coordenadas iniciales para los nodos moviles (x, y, z=0)
$node_2 set X_ 190.0
$node_2 set Y_ 190.0
$node_2 set Z_ 0.0
# Crear enlaces entre nodos cableados y nodos BS
$ns_ duplex-link $wnode0 $BS0 5Mb 2ms DropTail
$ns_ duplex-link-op $wnode0 $BS0 orient right
# ----------------------------------------------------------------------
# Definir movimiento simple para los nodos
# ----------------------------------------------------------------------
#
$ns_ at 0.1 "$node_2 setdest 190.0 190.0 15.0"
#
$ns_ at 10.0 "$node_2 setdest 10.0 50.0 $vel"
$ns_ at 20.0 "$node_2 setdest 70.0 50.0 $vel"
$ns_ at 30.0 "$node_2 setdest 70.0 75.0 $vel"
$ns_ at 40.0 "$node_2 setdest 10.0 150.0 $vel"
$ns_ at 50.0 "$node_2 setdest 120.0 75.0 $vel"
$ns_ at 60.0 "$node_2 setdest 125.0 120.0 $vel"
$ns_ at 80.0 "$node_2 setdest 190.0 180.0 15.0"
# ----------------------------------------------------------------------
# Establecer el trafico entre nodos
# ----------------------------------------------------------------------
# Trafico entre nodo cableado y nodo inalambrico
# De 0 a 2
set tcp02 [new Agent/TCP]
$tcp02 set class_ 2
set sink02 [new Agent/TCPSink]
$ns_ attach-agent $wnode0 $tcp02
$ns_ attach-agent $node_2 $sink02
$ns_ connect $tcp02 $sink02
set ftp02 [new Application/FTP]
$ftp02 attach-agent $tcp02
$ns_ at 10.0 "$ftp02 start"
$ns_ at 70.0 "$ftp02 stop"
# de 2 a 0
set tcp20 [new Agent/TCP]
$tcp20 set class_ 2
set sink20 [new Agent/TCPSink]
$ns_ attach-agent $node_2 $tcp20
$ns_ attach-agent $wnode0 $sink20
$ns_ connect $tcp20 $sink20
set ftp20 [new Application/FTP]
$ftp20 attach-agent $tcp20
$ns_ at 10.0 "$ftp20 start"
$ns_ at 70.0 "$ftp20 stop"
# ----------------------------------------------------------------------
# Finalizar de la simulacion
# ----------------------------------------------------------------------
$ns_ at 100.0 "finish"
$ns_ at 100.01 "puts \"TERMINANDO SIMULACION...\" ; $ns_ halt"
puts "Comenzando simulacion..."
$ns_ run