File: test-suite-tagged-trace.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 (310 lines) | stat: -rw-r--r-- 7,717 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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# -*-	Mode:tcl; tcl-indent-level:8; tab-width:8; indent-tabs-mode:t -*-
#
# Copyright (c) 2002 University of Southern California.
# All rights reserved.                                            
#                                                                
# Redistribution and use in source and binary forms are permitted
# provided that the above copyright notice and this paragraph are
# duplicated in all such forms and that any documentation, advertising
# materials, and other materials related to such distribution and use
# acknowledge that the software was developed by the University of
# Southern California, Information Sciences Institute.  The name of the
# University may not be used to endorse or promote products derived from
# this software without specific prior written permission.
# 
# THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
# 
# $Header: /cvsroot/nsnam/ns-2/tcl/test/test-suite-tagged-trace.tcl,v 1.8 2006/01/30 21:27:52 mweigle Exp $

# FOR UPDATING GLOBAL DEFAULTS:
Agent/TCP set precisionReduce_ false ;   # default changed on 2006/1/24.
Agent/TCP set rtxcur_init_ 6.0 ;      # Default changed on 2006/01/21
Agent/TCP set updated_rttvar_ false ;  # Variable added on 2006/1/21
Mac/802_11 set bugFix_timer_ false;     # default changed 2006/1/30

# This test suite is for validating the tagged trace format


set opt(tr) "temp.rands"
set opt(chan)         Channel/WirelessChannel  ;# channel type
set opt(prop)         Propagation/TwoRayGround ;# radio-propagation model
set opt(ant)          Antenna/OmniAntenna      ;# Antenna type
set opt(ll)           LL                       ;# Link layer type
set opt(ifq)          Queue/DropTail/PriQueue  ;# Interface queue type
set opt(ifqlen)       50                       ;# max packet in ifq
set opt(netif)        Phy/WirelessPhy          ;# network interface type
set opt(mac)          Mac/802_11               ;# MAC type
set opt(rp)           DSDV                     ;# ad-hoc routing protocol 

Class TestSuite
proc usage {} {
        global argv0
        puts stderr "usage: ns $argv0 <test> "
        puts "Valid Tests: simple wireless Format-simple"
        exit 1
}

proc runtest {arg} {
        global quiet
        set quiet 0
 
        set b [llength $arg]
        if {$b == 1} {
                set test $arg
        } elseif {$b == 2} {
                set test [lindex $arg 0]
                if {[lindex $arg 1] == "QUIET"} {
                        set quiet 1
                }
        } else {
                usage
        }
        set t [new Test/$test]
        $t run
}


TestSuite instproc init {} {
  global opt tracefd
  $self instvar ns_
  set ns_ [new Simulator]
  $ns_ use-taggedtrace
  set tracefd [open $opt(tr) w]
  $ns_ trace-all $tracefd
}

TestSuite instproc finish {} {
  $self instvar ns_ testName_
  global quiet

  $ns_ flush-trace
  $ns_ halt
 }


# simple test
#
# Network topology:
#
#  A            E
#   \          /
#    ---C--D---
#   /          \
#  B            F
#
# A->E ftp
# B->F cbr
#
# C<->D link is lossy


Class Test/simple -superclass TestSuite

Test/simple instproc init {} {
  $self instvar ns_ testName_
  set testName_ simple

  $self next

  
  set A [$ns_ node]
  set B [$ns_ node]
  set C [$ns_ node]
  set D [$ns_ node]
  set E [$ns_ node]
  set F [$ns_ node]

  $ns_ duplex-link $A $C 10Mb 5ms DropTail
  $ns_ duplex-link $B $C 10Mb 5ms DropTail

  $ns_ duplex-link $C $D 2Mb 20ms DropTail

  $ns_ duplex-link $D $E 10Mb 5ms DropTail
  $ns_ duplex-link $D $F 10Mb 5ms DropTail



  # make the link between C and D drop 1% percent of the packets
  set err [new ErrorModel]
  $err drop-target [new Agent/Null] 
  set rand [new RandomVariable/Uniform]
  $rand set min_ 0
  $rand set max_ 100
  $err ranvar $rand
  $err set rate_ 0.01
  [$ns_ link $C $D] errormodule $err

  # set up TCP flow from A to E
  set tcp [new Agent/TCP]
  set sink [new Agent/TCPSink]
  $ns_ attach-agent $A $tcp
  $ns_ attach-agent $E $sink
  $ns_ connect $tcp $sink
  set ftp [new Application/FTP]
  $ftp attach-agent $tcp

  # set up CBR flow from B to F
  set udp [new Agent/UDP]
  set null [new Agent/Null]
  $ns_ attach-agent $B $udp
  $ns_ attach-agent $F $null
  $ns_ connect $udp $null
  set cbr [new Application/Traffic/CBR]
  $cbr set packetSize_ 500
  $cbr set interval_ 0.005
  $cbr attach-agent $udp

  # set times to start/stop actions

  $ns_ at 0.1 "$ftp start"
  $ns_ at 0.2 "$cbr start"
  $ns_ at 0.8 "$cbr stop"
  $ns_ at 1.2 "$cbr start"
  $ns_ at 1.8 "$cbr stop"
  $ns_ at 1.9 "$ftp stop"
  $ns_ at 2.0 "$self finish"
}

Test/simple instproc run {} {
  $self instvar ns_
  puts "Starting Simulation..."
  $ns_ run
}




# wireless test
#
# A->B ftp
# C->D cbr


Class Test/wireless -superclass TestSuite

Test/wireless instproc init {} {
  global opt
  $self instvar ns_ testName_
  set testName_ simple

  $self next

  set topo [new Topography]
  $topo load_flatgrid 100 100
  create-god 4
  $ns_ node-config -adhocRouting $opt(rp) \
                   -llType $opt(ll) \
                   -macType $opt(mac) \
                   -ifqType $opt(ifq) \
                   -ifqLen $opt(ifqlen) \
                   -antType $opt(ant) \
                   -propType $opt(prop) \
                   -phyType $opt(netif) \
                   -topoInstance $topo \
                   -channel [new $opt(chan)] \
                    -agentTrace ON \
                    -routerTrace ON \
                    -macTrace ON \
                    -movementTrace OFF

  set A [$ns_ node]
  $A random-motion 0
  $A set X_ 5.0
  $A set Y_ 2.0
  $A set Z_ 0.0
  set B [$ns_ node]
  $B random-motion 0
  $B set X_ 15.0
  $B set Y_ 15.0
  $B set Z_ 0.0
  set C [$ns_ node]
  $C random-motion 0
  $C set X_ 2.0
  $C set Y_ 8.0
  $C set Z_ 0.0
  set D [$ns_ node]
  $D random-motion 0
  $D set X_ 10.0
  $D set Y_ 1.0
  $D set Z_ 0.0


  # set up TCP flow from A to B
  set tcp [new Agent/TCP]
  set sink [new Agent/TCPSink]
  $ns_ attach-agent $A $tcp
  $ns_ attach-agent $B $sink
  $ns_ connect $tcp $sink
  set ftp [new Application/FTP]
  $ftp attach-agent $tcp

  # set up CBR flow from C to D
  set udp [new Agent/UDP]
  set null [new Agent/Null]
  $ns_ attach-agent $C $udp
  $ns_ attach-agent $D $null
  $ns_ connect $udp $null
  set cbr [new Application/Traffic/CBR]
  $cbr set packetSize_ 500
  $cbr set interval_ 0.005
  $cbr attach-agent $udp

  # set times to start/stop actions

  $ns_ at 0.1 "$ftp start"
  $ns_ at 0.2 "$cbr start"
  $ns_ at 0.8 "$cbr stop"
  $ns_ at 1.2 "$cbr start"
  $ns_ at 1.8 "$cbr stop"
  $ns_ at 1.9 "$ftp stop"
  $ns_ at 2.0 "$self finish"
}

Test/wireless instproc run {} {
  $self instvar ns_
  puts "Starting Simulation..."
  $ns_ run
}



# The following tests are for testing the file conversion utilities

Class Test/Format-simple -superclass Test/simple

Test/Format-simple instproc init {} {
  global PERL

  # check to make sure prereqs for file conversion are met

  set foo [catch {exec $PERL -I../../bin -MNS::TraceFileEvent -MNS::TraceFileReader -MNS::TraceFileWriter -e exit 2>/dev/null}]

  if [expr $foo != 0] then {
    puts "Required Perl module not found, Format-simple test skipped."
    exit 2
  }

  $self next
}

Test/Format-simple instproc run {} {
  global opt PERL

  # let parent class run ns
  $self next

  # now that ns is done, convert the output file
  exec $PERL -I../../bin ../../bin/ns2oldns.pl < $opt(tr) > $opt(tr).tmp
  exec cp $opt(tr).tmp $opt(tr)	
}





# main program .. runs the test specified by the command line arguments

global argv arg0
runtest $argv