File: miptest.tcl

package info (click to toggle)
ns2 2.35%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 78,796 kB
  • sloc: cpp: 172,923; tcl: 107,130; perl: 6,391; sh: 6,143; ansic: 5,846; makefile: 816; awk: 525; csh: 355
file content (212 lines) | stat: -rw-r--r-- 5,815 bytes parent folder | download | duplicates (8)
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
# miptest.tcl
#
# To show mobileIP activities.
# Modified from a SUN's original example script
#
# See the comments from SUN below:
#
# kwang: some explanations on how to use this limited implementation of
#        Mobile IP :
# 1. Look into "proc create-topology" below for some necessary commands
#    to activate Mobile IP.
# 2. Reset "Simulator instvar node_factory_" to create specialized
#    nodes (Node/MIPBS and Node/MIPMH); how they'll interact with
#    HierNode or ManualRtNode is unknown.
# 3. Make the mobile links "dynamic"; initially mark the links that are
#    not between MH and HA "down" to fool the route computer
# 4. Specify the links on which BS and MH should broadcast ads and agent
#    solicitations.
# 5. Tell Agent/MIPMH which its HA is.
# 6. For configurable parameters, see the constructors of these modules
#    for the "bind" statements; beacon period can be set by the statement
#    "<name of an Agent/MIPBS or Agent/MIPMH> beacon-period <beacon period>".
# some changes are made by Ya 2/99

set opt(tr)	out
set opt(namtr)	"miptest.nam"
set opt(seed)	0
set opt(stop)	20

set opt(qsize)	100
set opt(bw)	2Mb
set opt(delay)	1ms
set opt(ll)	LL
set opt(ifq)	Queue/DropTail
set opt(mac)	Mac/Csma/Ca
set opt(chan)	Channel
set opt(tcp)	TCP/Reno
set opt(sink)	TCPSink

set opt(source)	FTP


proc Usage {} {
	global opt argv0
	puts "Usage: $argv0 \[-stop sec\] \[-seed value\] \[-node numNodes\]"
	puts "\t\[-tr tracefile\] \[-g\]"
	puts "\t\[-ll lltype\] \[-ifq qtype\] \[-mac mactype\]"
	puts "\t\[-bw $opt(bw)] \[-delay $opt(delay)\]"
	exit 1
}

proc Getopt {} {
	global opt argc argv
	if {$argc == 0} Usage
	for {set i 0} {$i < $argc} {incr i} {
		set key [lindex $argv $i]
		if ![string match {-*} $key] continue
		set key [string range $key 1 end]
		set val [lindex $argv [incr i]]
		set opt($key) $val
		if [string match {-[A-z]*} $val] {
			incr i -1
			continue
		}
		switch $key {
			ll  { set opt($key) LL/$val }
			ifq { set opt($key) Queue/$val }
			mac { set opt($key) Mac/$val }
		}
	}
}


proc finish {} {
	exit 0
}


proc create-trace {} {
	global ns opt

	if [file exists $opt(tr)] {
		catch "exec rm -f $opt(tr) $opt(tr)-bw [glob $opt(tr).*]"
	}

	set trfd [open $opt(tr) w]
	$ns trace-all $trfd
	if {$opt(namtr) != ""} {
		$ns namtrace-all [open $opt(namtr) w]
	}
	return $trfd
}


proc create-topology {} {
	global ns opt
	global lan node source
	$ns instvar link_

	set node(s) [$ns node]
	set node(g) [$ns node]
	Simulator set node_factory_ Node/MIPBS
	set node(ha) [$ns node]
	$node(ha) shape "hexagon"
	set node(fa) [$ns node]
	$node(fa) shape "hexagon"
	Simulator set node_factory_ Node/MIPMH
	set node(mh) [$ns node]
	$node(mh) shape "circle"

	$ns duplex-link $node(s) $node(g) 2Mb 5ms DropTail 
	$ns duplex-link-op $node(s) $node(g) orient right
	$ns duplex-link $node(g) $node(ha) 2Mb 5ms DropTail
	$ns duplex-link-op $node(g) $node(ha) orient up
	$ns duplex-link $node(g) $node(fa) 2Mb 5ms DropTail
	$ns duplex-link-op $node(g) $node(fa) orient right-up

	$ns duplex-link $node(ha) $node(mh) 2Mb 5ms DropTail 
	$ns duplex-link-op $node(ha) $node(mh) orient right
	$ns duplex-link $node(fa) $node(mh) 4Mb 5ms DropTail 
	$ns duplex-link-op $node(fa) $node(mh) orient left

	set mhid [$node(mh) id]
	set haid [$node(ha) id]
	set faid [$node(fa) id]
	$link_($mhid:$faid) dynamic
	$link_($faid:$mhid) dynamic
	$link_($mhid:$faid) down
	$link_($faid:$mhid) down
	$link_($mhid:$haid) dynamic
	$link_($haid:$mhid) dynamic

	[$node(ha) set regagent_] add-ads-bcast-link $link_($haid:$mhid)
	[$node(fa) set regagent_] add-ads-bcast-link $link_($faid:$mhid)

	[$node(mh) set regagent_] set home_agent_ $haid
	[$node(mh) set regagent_] add-sol-bcast-link $link_($mhid:$haid)
	[$node(mh) set regagent_] add-sol-bcast-link $link_($mhid:$faid)

	$ns at 0.0 "$node(ha) label HomeAgent"
	$ns at 0.0 "$node(fa) label ForeignAgent"
	$ns at 0.0 "$node(mh) label MobileHost"

	$ns at 0.0 "$node(ha) color gold"
	$ns at 0.0 "$node(mh) color gold"

	$ns rtmodel-at 0.1 down $node(mh) $node(fa)

	set swtm [expr 3.0+($opt(stop)-3.0)/4.0]
	$ns rtmodel-at $swtm down $node(mh) $node(ha)
	$ns rtmodel-at $swtm up $node(mh) $node(fa)
	$ns at $swtm "$node(ha) color black"
	$ns at $swtm "$node(fa) color gold"


	set swtm [expr 3.0+($opt(stop)-3.0)/2.0]
	$ns rtmodel-at $swtm down $node(mh) $node(fa)
	$ns rtmodel-at $swtm up $node(mh) $node(ha)
	$ns at $swtm "$node(ha) color gold"
	$ns at $swtm "$node(fa) color black"


	set swtm [expr 3.0+($opt(stop)-3.0)*3.0/4.0]
	$ns rtmodel-at $swtm down $node(mh) $node(ha)
	$ns rtmodel-at $swtm up $node(mh) $node(fa)
	$ns at $swtm "$node(ha) color black"
	$ns at $swtm "$node(fa) color gold"

#	$ns at $swtm "$link_($mhid:$faid) up"
#	$ns at $swtm "$link_($faid:$mhid) up"
#	$ns at [expr $swtm - 1.5] "$link_($mhid:$haid) down"
#	$ns at [expr $swtm - 1.5] "$link_($haid:$mhid) down"

#	set swtm [expr 3.0+($opt(stop)-3.0)/2.0]
#	$ns at $swtm "$link_($mhid:$haid) up"
#	$ns at $swtm "$link_($haid:$mhid) up"
#	$ns at [expr $swtm - 1.5] "$link_($mhid:$faid) down"
#	$ns at [expr $swtm - 1.5] "$link_($faid:$mhid) down"

#	set swtm [expr 3.0+($opt(stop)-3.0)*3.0/4.0]
#	$ns at $swtm "$link_($mhid:$faid) up"
#	$ns at $swtm "$link_($faid:$mhid) up"
#	$ns at [expr $swtm - 1.5] "$link_($mhid:$haid) down"
#	$ns at [expr $swtm - 1.5] "$link_($haid:$mhid) down"
}

proc create-source {} {
	global ns opt
	global lan node source

	set tp [$ns create-connection $opt(tcp) \
		    $node(s) $opt(sink) $node(mh) 0]
	set source [$tp attach-source $opt(source)]
	$ns at 0.0 "$source start"
}


## MAIN ##
Getopt
if {$opt(seed) >= 0} { ns-random $opt(seed) }
if [info exists opt(qsize)] { Queue set limit_ $opt(qsize) }

set ns [new Simulator]
set trfd [create-trace]

create-topology
create-source

#$lan trace $ns $trfd

$ns at $opt(stop) "finish"
$ns run