File: asym-test-2.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 (224 lines) | stat: -rwxr-xr-x 4,173 bytes parent folder | download | duplicates (7)
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
#!/usr/bin/ns
#source ../../../lan/ns-lan.tcl
source ../../../ex/asym/util.tcl

# set up simulation

set ns [new Simulator]

set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]

set f [open out.tr w]
$ns trace-all $f

set tcptrace [open tcp.tr w] 
set sinktrace [open sink.tr w]
set redtrace [open red.tr w]
set graph 0
set connGraphFlag("") 0
set maxdelack 25
set maxburst 3
set upwin 0
set tcpTick 0.1
set ackSize 40
set rbw 28.8Kb
set rqsize 10
set qsize 10
set rgw "DropTail"
set nonfifo 0 
set acksfirst false
set filteracks false
set replace_head false
set midtime 0

proc printUsage {} {
	puts "Usage: "
	exit
}

proc finish {ns traceall tcptrace graph connGraphFlag midtime} {
	upvar $connGraphFlag graphFlag 

	$ns flush-trace
	close $traceall
	flush $tcptrace
	close $tcptrace
	plotgraph $graph $graphFlag $midtime
	exit 0
}	

# read user options and act accordingly
set count 0
while {$count < $argc} {
	set arg [lindex $argv $count]
	incr count 2
	switch -exact '$arg' {
		'-graph' {
			set graph 1
			incr count -1
			continue
		}
		'-mda' {
			set maxdelack [lindex $argv [expr $count-1]]
			continue
		}
		'-acksz' {
			set ackSize [lindex $argv [expr $count-1]]
			continue
		}
		'-mb' {
			set maxburst [lindex $argv [expr $count-1]]
			continue
		}
		'-upwin' {
			set upwin [lindex $argv [expr $count-1]]
			continue
		}
		'-tk' {
			set tcpTick [lindex $argv [expr $count-1]]
			continue
		}
		'-rbw' {
			set rbw [lindex $argv [expr $count-1]]
			continue
		}
		'-rq' {
			set rqsize [lindex $argv [expr $count-1]]
			continue
		}
		'-q' {
			set qsize [lindex $argv [expr $count-1]]
			Queue set limit_ $qsize 
			continue
		}
		'-nonfifo' {
			set nonfifo 1
			incr count -1
			continue
		}
		'-noecn' {
			Agent/TCP set disable_ecn_ 1
			incr count -1
			continue
		}
		'-red' {
			set rgw "RED"
			incr count -1
			continue
		}
		'-acksfirst' {
			set acksfirst true
			incr count -1
			continue
		}
		'-filteracks' {
			set filteracks true
			incr count -1
			continue
		}
		'-replace_head' {
			set replace_head true
			incr count -1
			continue
		}
		'-mid' {
			set midtime [lindex $argv [expr $count-1]]
			continue
		}
		default {
			incr count -2
		} 
	}
	switch -exact '$arg' {
		'-dn' {
			set direction "down"
		}
		'-up' {
			set direction "up"
		}
		default {
			puts "arg $arg"
			printUsage
			exit
		}
	}
	incr count 1
	set arg [lindex $argv $count]
	switch -exact '$arg' {
		'-asym' {
			set type "asym"
		}
		'-asymsrc' {
			set type "asymsrc"
		}
		'-reno' {
			set type "reno"
		}
		default {
			puts "arg $arg"
			printUsage
			exit
		}
	}
	incr count 1
	set arg [lindex $argv $count]
	set startTime $arg
	incr count 1

	set connGraph 0 
	set arg [lindex $argv $count]
	if { $arg == "-graph" } {
		set connGraph 1
		incr count 1
	}

	if { $direction == "down" } {
		set src $n0
		set dst $n3
	} elseif { $direction == "up" } {
		set src $n3
		set dst $n0
	} else {
	}
	
	if { $type == "asym" } {
		set tcp [createTcpSource "TCP/Reno/Asym" $maxburst $tcpTick]
		set sink [createTcpSink "TCPSink/Asym" $sinktrace $ackSize $maxdelack]
	} elseif { $type == "asymsrc" } {
		set tcp [createTcpSource "TCP/Reno/Asym" $maxburst $tcpTick]
		set sink [createTcpSink "TCPSink" $sinktrace $ackSize]
	} elseif { $type == "reno" } {
		set tcp [createTcpSource "TCP/Reno" $tcpTick]
		set sink [createTcpSink "TCPSink" $sinktrace $ackSize]
	}
	
	if { $direction == "up" && $upwin != 0 } {
		$tcp set window_ $upwin
	}
	set ftp [createFtp $ns $src $tcp $dst $sink]
	setupTcpTracing $tcp $tcptrace
	setupGraphing $tcp $connGraph connGraphFlag
	$ns at $startTime "$ftp start" 
}

# topology
#
#      10Mb, 1ms       10Mb, 5ms       10Mb, 1ms
#  n0 ------------ n1 ------------ n2 ------------ n3
#                     28.8Kb, 50ms 
#
$ns duplex-link $n0 $n1 10Mb 1ms DropTail
$ns simplex-link $n1 $n2 10Mb 5ms DropTail
$ns simplex-link $n2 $n1 $rbw 50ms $rgw
$ns duplex-link $n2 $n3 10Mb 1ms DropTail

# configure reverse bottleneck queue
configQueue $ns $n2 $n1 $rgw $redtrace $rqsize $nonfifo $acksfirst $filteracks $replace_head

# end simulation
$ns at 30.0 "finish $ns $f $tcptrace $graph connGraphFlag $midtime"

$ns run