forked from flymin/aodv-uu-0.9.6_ns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_2.tcl
125 lines (107 loc) · 3.19 KB
/
test_2.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
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(rp) AODVUU ;# routing protocol
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 4 ;# number of mobilenodes
set val(ni) 3
set val(x) 500
set val(y) 500
# Initialize Global Variables
set ns_ [new Simulator]
set tracefd [open wireless_2.tr w]
$ns_ trace-all $tracefd
set namtrace [open wireless_2.nam w]
$ns_ namtrace-all-wireless $namtrace $val(x) $val(y)
# set up topography object
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
# Create God
create-god [expr $val(nn)*$val(ni)]
$ns_ use-newtrace
# Create channel
for {set i 0} {$i < $val(ni)} {incr i} {
set chan($i) [new $val(chan)]
}
# configure node, please note the change below.
$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) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON \
-channel $chan(0) \
-ifNum $val(ni)
$ns_ change-numifs $val(ni)
for {set i 0} {$i < $val(ni)} {incr i} {
$ns_ add-channel $i $chan($i)
}
for {set i 0} {$i < $val(nn)} {incr i} {
set node_($i) [$ns_ node]
#$ns_ initial_node_pos $node_($i) 20
$node_($i) random-motion 0
}
#
# Provide initial (X,Y, for now Z=0) co-ordinates for mobilenodes
#
$node_(0) set X_ 5.0
$node_(0) set Y_ 20.0
$node_(0) set Z_ 0.0
$ns_ initial_node_pos $node_(0) 30
$node_(1) set X_ 55.0
$node_(1) set Y_ 20.0
$node_(1) set Z_ 0.0
$ns_ initial_node_pos $node_(1) 30
$node_(2) set X_ 105.0
$node_(2) set Y_ 20.0
$node_(2) set Z_ 0.0
$ns_ initial_node_pos $node_(2) 30
$node_(3) set X_ 155.0
$node_(3) set Y_ 20.0
$node_(3) set Z_ 0.0
$ns_ initial_node_pos $node_(3) 30
# set node movement
set god_ [God instance]
$ns_ at 5.0 "$node_(1) setdest 55.0 400.0 60.0"
$ns_ at 5.0 "$node_(3) setdest 400.0 20.0 60.0"
$ns_ at 15.0 "$node_(0) setdest 5.0 490.0 60.0"
$ns_ at 20.0 "$node_(1) setdest 490.0 100.0 60.0"
# Setup traffic flow between nodes
# TCP connections between node_(0) and node_(1)
set tcp [new Agent/TCP]
set sink [new Agent/TCPSink]
$ns_ attach-agent $node_(0) $tcp
$ns_ attach-agent $node_(1) $sink
$ns_ connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns_ at 3.0 "$ftp start"
$ns_ at 99.0 "$ftp stop"
#
# Tell nodes when the simulation ends
#
for {set i 0} {$i < $val(nn) } {incr i} {
$ns_ at 100.0 "$node_($i) reset";
}
$ns_ at 99.0 "stop"
$ns_ at 99.01 "puts \"NS EXITING...\" ; $ns_ halt"
proc stop {} {
global ns_ tracefd namtrace
$ns_ flush-trace
close $tracefd
close $namtrace
exit 0
}
puts "Starting Simulation..."
$ns_ run