-
Notifications
You must be signed in to change notification settings - Fork 1
/
wireless-DSDV.tcl
115 lines (97 loc) · 3.27 KB
/
wireless-DSDV.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
set opt(chan) Channel/WirelessChannel
set opt(prop) Propagation/TwoRayGround
set opt(netif) Phy/WirelessPhy
set opt(mac) Mac/802_11
set opt(ifq) Queue/DropTail/PriQueue
set opt(ll) LL ;#Link Layer
set opt(ant) Antenna/OmniAntenna
set opt(x) 500 ;# X dimension of the topography
set opt(y) 500 ;# Y dimension of the topography
set opt(ifqlen) 50 ;# max packet in ifq
set opt(nn) 100
set opt(connections) 50
set opt(stop) 50
set opt(dataRate) [expr 1.0*256*8] ;#packet size=256 bytes
set opt(adhocRouting) DSDV
set ns_ [new Simulator]
set topo [new Topography]
set opt(fn) "wireless-DSDV"
set tracefd [open $opt(fn).tr w]
set namtrace [open $opt(fn).nam w]
$ns_ trace-all $tracefd
$ns_ namtrace-all-wireless $namtrace $opt(x) $opt(y)
# declare finish program
proc finish {} {
global ns_ tracefd namtrace
$ns_ flush-trace
close $tracefd
close $namtrace
#exec nam wireless.nam
#exec awk -f grphCalc.awk wireless.tr
exit 0
}
# define topology
$topo load_flatgrid $opt(x) $opt(y)
# Create God(Generate Operations Director): stores table of shortest no of hops from 1 node to another
set god_ [create-god $opt(nn)]
# define how node should be created
#global node setting
$ns_ node-config -adhocRouting $opt(adhocRouting) \
-llType $opt(ll) \
-macType $opt(mac) \
-ifqType $opt(ifq) \
-ifqLen $opt(ifqlen) \
-antType $opt(ant) \
-propType $opt(prop) \
-phyType $opt(netif) \
-channelType $opt(chan) \
-topoInstance $topo \
-agentTrace ON \
-movementTrace ON \
-routerTrace ON \
-macTrace ON
# Create the specified number of nodes [$opt(nn)] and "attach" them to the channel.
for {set i 0} {$i < $opt(nn) } {incr i} {
set node_($i) [$ns_ node]
$node_($i) random-motion 1 ;# disable random motion
}
for {set i 0} {$i < $opt(nn) } {incr i} {
$node_($i) set X_ [expr rand()*500]
$node_($i) set Y_ [expr rand()*500]
$node_($i) set Z_ 0
}
for {set i 0} {$i < $opt(nn)} {incr i} {
$ns_ initial_node_pos $node_($i) 20
}
for {set i 0} {$i < $opt(connections)} {incr i} {
#Setup a UDP connection
set udp_($i) [new Agent/UDP]
$ns_ attach-agent $node_($i) $udp_($i)
set null_($i) [new Agent/Null]
$ns_ attach-agent $node_([expr $i+2]) $null_($i)
$ns_ connect $udp_($i) $null_($i)
#Setup a CBR over UDP connection
set cbr_($i) [new Application/Traffic/CBR]
$cbr_($i) attach-agent $udp_($i)
$cbr_($i) set type_ CBR
$cbr_($i) set packet_size_ 256
$cbr_($i) set rate_ $opt(dataRate)
$cbr_($i) set random_ false
$ns_ at 0.0 "$cbr_($i) start"
$ns_ at $opt(stop) "$cbr_($i) stop"
}
# random motion
for {set j 0} {$j < 10} {incr j} {
for {set i 0} {$i < $opt(nn)} {incr i} {
set xx_ [expr rand()*$opt(x)]
set yy_ [expr rand()*$opt(y)]
set rng_time [expr rand()*$opt(stop)]
$ns_ at $rng_time "$node_($i) setdest $xx_ $yy_ 15.0" ;
}
}
# Tell nodes when the simulation ends
for {set i 0} {$i < $opt(nn) } {incr i} {
$ns_ at $opt(stop) "$node_($i) reset";
}
$ns_ at $opt(stop) "finish"
$ns_ run