File: test-suite-delaybox.tcl

package info (click to toggle)
ns2 2.35%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 78,120 kB
  • sloc: cpp: 172,923; tcl: 107,127; perl: 6,391; sh: 6,143; ansic: 5,846; makefile: 812; awk: 525; csh: 355
file content (259 lines) | stat: -rw-r--r-- 6,630 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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# test-suite-DelayBox.tcl
#
# Based on ns/tcl/test/test-suite-full.tcl
#
# Modified by Michele Weigle, UNC-Chapel Hill, Dec 2003
#

#*************************************************************************
# Tests to validate DelayBox
#
#  oneway - one-way TCP
#  oneway-asymmetric - one-way TCP and delay only on the data path
#  full - Full-TCP
#  full-asymmetric - Full-TCP and delay only on the data path
#*************************************************************************

# FOR UPDATING GLOBAL DEFAULTS:
Agent/TCP set SetCWRonRetransmit_ false
# The default is being changed to true.


# Agent/TCP/FullTcp set debug_ true;

source misc.tcl

TestSuite instproc finish testname {
	$self instvar ns_
	$ns_ halt
}

Class SkelTopology
Class Topology -superclass SkelTopology

Topology instproc node? num {
    $self instvar node_
    return $node_($num)
}

Class Topology/DB -superclass Topology

#
# DelayBox test topology
#
#           s1                      k1
#             \                    /
#  100Mb, 1ms  \    100Mb, 1ms    / 100Mb, 1ms
#               r1 ----------- r2 
#  100Mb, 1ms  /                 \ 100Mb, 1ms
#             /                   \
#          s2                       k2
#
Topology/DB instproc init ns {
    $self instvar node_
    set node_(s1) [$ns node]
    set node_(s2) [$ns node]
    set node_(r1) [$ns DelayBox]
    set node_(r2) [$ns DelayBox]
    set node_(k1) [$ns node]
    set node_(k2) [$ns node]

    $self next
    $ns duplex-link $node_(s1) $node_(r1) 100Mb 1ms DropTail
    $ns duplex-link $node_(s2) $node_(r1) 100Mb 1ms DropTail
    $ns duplex-link $node_(r1) $node_(r2) 100Mb 1ms DropTail
    $ns duplex-link $node_(k1) $node_(r2) 100Mb 1ms DropTail
    $ns duplex-link $node_(k2) $node_(r2) 100Mb 1ms DropTail
}

TestSuite instproc setup tcptype {
    $self instvar ns_ node_ testName_

    # clear output files
    exec rm -f temp.rands

    Trace set show_tcphdr_ 1 
    Agent/TCP set minrto_ 1;     # ns-2.27 value

    set stopt 10

    # create TCP Agents
    if {$tcptype == "FullTcp"} {
        set src(0) [new Agent/TCP/FullTcp]
        set sink(0) [new Agent/TCP/FullTcp]
        set src(1) [new Agent/TCP/FullTcp]
        set sink(1) [new Agent/TCP/FullTcp]
    } elseif {$tcptype == "oneway"} {
        set src(0) [new Agent/TCP]
        set sink(0) [new Agent/TCPSink]
        set src(1) [new Agent/TCP]
        set sink(1) [new Agent/TCPSink]
    }

    # setup TCP Agents and connections
    $ns_ attach-agent $node_(s1) $src(0)
    $src(0) set fid_ 0
    $ns_ attach-agent $node_(k1) $sink(0)
    $sink(0) set fid_ 0
    $ns_ attach-agent $node_(s2) $src(1)
    $src(1) set fid_ 1
    $ns_ attach-agent $node_(k2) $sink(1)
    $sink(1) set fid_ 1

    # make the connections
    $ns_ connect $src(0) $sink(0)
    $sink(0) listen
    $ns_ connect $src(1) $sink(1)
    $sink(1) listen
    
    # schedule flows
    $ns_ at 0.7 "$src(0) advance 50"
    $ns_ at 0.8 "$src(1) advance 50"
    $ns_ at 2.0 "$src(0) close"
    $ns_ at 2.0 "$src(1) close"
    $ns_ at $stopt "$self finish $testName_"

   # setup tracing
    set trace_file [open temp.rands w]
    $ns_ trace-queue $node_(s1) $node_(r1) $trace_file
    $ns_ trace-queue $node_(r1) $node_(s1) $trace_file
    $ns_ trace-queue $node_(s2) $node_(r1) $trace_file
    $ns_ trace-queue $node_(r1) $node_(s2) $trace_file
    $ns_ trace-queue $node_(r1) $node_(r2) $trace_file
    $ns_ trace-queue $node_(r2) $node_(r1) $trace_file
    $ns_ trace-queue $node_(k1) $node_(r2) $trace_file
    $ns_ trace-queue $node_(r2) $node_(k1) $trace_file
    $ns_ trace-queue $node_(k2) $node_(r2) $trace_file
    $ns_ trace-queue $node_(r2) $node_(k2) $trace_file

    # create random variables
    set srcd_rng [new RNG];
    set src_delay [new RandomVariable/Uniform];   # delay 20-50 ms
    $src_delay set min_ 20
    $src_delay set max_ 50
    $src_delay use-rng $srcd_rng

    set srcbw_rng [new RNG];
    set src_bw [new RandomVariable/Uniform];      # bw 1-20 Mbps
    $src_bw set min_ 1
    $src_bw set max_ 20
    $src_delay use-rng $srcbw_rng

    set sinkd_rng [new RNG];
    set sink_delay [new RandomVariable/Uniform];   # delay 1-20 ms
    $sink_delay set min_ 1
    $sink_delay set max_ 20
    $sink_delay use-rng $sinkd_rng

    set sinkbw_rng [new RNG];
    set sink_bw [new RandomVariable/Constant];      # bw 100 Mbps
    $sink_bw set val_ 100
    $sink_bw use-rng $sinkbw_rng

    set loss_rng [new RNG];
    set loss_rate [new RandomVariable/Uniform];    # loss 0-1%
    $loss_rate set min_ 0
    $loss_rate set max_ 0.01
    $loss_rate use-rng $loss_rng
    
    # setup rules for DelayBoxes
    $node_(r1) add-rule [$node_(s1) id] [$node_(k1) id] $src_delay \
	    $loss_rate $src_bw
    $node_(r1) add-rule [$node_(s2) id] [$node_(k2) id] $src_delay \
	    $loss_rate $src_bw
    $node_(r2) add-rule [$node_(s1) id] [$node_(k1) id] $sink_delay \
	    $loss_rate $sink_bw
    $node_(r2) add-rule [$node_(s2) id] [$node_(k2) id] $sink_delay \
	    $loss_rate $sink_bw
}


#
# oneway
#
Class Test/oneway -superclass TestSuite
Test/oneway instproc init topo {
        global defaultRNG
	$self instvar net_ defNet_ test_
        $defaultRNG seed 9999
        set net_ $topo
	set defNet_ DB
	set test_ oneway
	$self next 0
}

Test/oneway instproc run {} {
	$self instvar ns_ 
        $self setup oneway
	$ns_ run
}

#
# oneway-asymmetric
#
Class Test/oneway-asymmetric -superclass TestSuite
Test/oneway-asymmetric instproc init topo {
        global defaultRNG
	$self instvar net_ defNet_ test_
        $defaultRNG seed 9999
        set net_ $topo
	set defNet_ DB
	set test_ oneway-asymmetric
	$self next 0
}

Test/oneway-asymmetric instproc run {} {
	$self instvar ns_ node_ 
        $self setup oneway

        $node_(r1) set-asymmetric
        $node_(r2) set-asymmetric

	$ns_ run
}

#
# full
#
Class Test/full -superclass TestSuite
Test/full instproc init topo {
        global defaultRNG
	$self instvar net_ defNet_ test_
        $defaultRNG seed 9999
        set net_ $topo
	set defNet_ DB
	set test_ full
	$self next 0
}

Test/full instproc run {} {
	$self instvar ns_
        $self setup FullTcp
	$ns_ run
}

#
# full-asymmetric
#
Class Test/full-asymmetric -superclass TestSuite
Test/full-asymmetric instproc init topo {
        global defaultRNG
	$self instvar net_ defNet_ test_
        $defaultRNG seed 9999
        set net_ $topo
	set defNet_ DB
	set test_ full-asymmetric
	$self next 0
}

Test/full-asymmetric instproc run {} {
	$self instvar ns_ node_
        $self setup FullTcp

        $node_(r1) set-asymmetric
        $node_(r2) set-asymmetric

	$ns_ run
}

TestSuite runTest