File: tg.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 (205 lines) | stat: -rw-r--r-- 4,427 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
##
## simple example to demonstrate use of traffic generation modules
##
## topology consists of 6 nodes.  4 traffic sources are attached
## to each of 4 'access' nodes.  These nodes have links to a single
## 'concentrator' node, which is connected by the bottleneck link
## to the destination node.
## 
## there are 4 source agents that generate packets
## 1 generates traffic based on an Exponential On/Off distribution
## 1 generates traffic based on a Pareto On/Off distribution
## 2 generate traffic using the trace file 'example-trace'.
##
set stoptime 10.0
set plottime 11.0

set ns [new Simulator]

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

set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]

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

$ns duplex-link $n0 $n1 1.5Mb 10ms DropTail

$ns duplex-link $n0 $n2 10Mb 5ms DropTail
$ns duplex-link $n0 $n3 10Mb 5ms DropTail
$ns duplex-link $n0 $n4 10Mb 5ms DropTail
$ns duplex-link $n0 $n5 10Mb 5ms DropTail

$ns duplex-link-op $n0 $n1 orient right
$ns duplex-link-op $n0 $n2 orient left-up
$ns duplex-link-op $n0 $n3 orient left
$ns duplex-link-op $n0 $n4 orient left-down
$ns duplex-link-op $n0 $n5 orient down

$ns duplex-link-op $n0 $n1 queuePos 0.5

#$ns trace-queue $n0 $n1 $f

## set up the exponential on/off source, parameterized by packet size,
## ave on time, ave off time and peak rate

set s1 [new Agent/UDP]
$ns attach-agent $n2 $s1

set null1 [new Agent/Null]
$ns attach-agent $n1 $null1

$ns connect $s1 $null1

set exp1 [new Application/Traffic/Exponential]
$exp1 set packetSize_ 210
$exp1 set burst_time_ 500ms
$exp1 set idle_time_ 500ms
$exp1 set rate_ 100k

$exp1 attach-agent $s1

## set up the pareto on/off source, parameterized by packet size,
## ave on time, ave  off time, peak rate and pareto shape parameter

set s2 [new Agent/UDP]
$ns attach-agent $n3 $s2

set null2 [new Agent/Null]
$ns attach-agent $n1 $null2

$ns connect $s2 $null2

set pareto2 [new Application/Traffic/Pareto]
$pareto2 set packetSize_ 210
$pareto2 set burst_time_ 500ms
$pareto2 set idle_time_ 500ms
$pareto2 set rate_ 200k
$pareto2 set shape_ 1.5

$pareto2 attach-agent $s2

## initialize a trace file
set tfile [new Tracefile]
$tfile filename example-trace

## set up a source that uses the trace file

set s3 [new Agent/UDP]
$ns attach-agent $n4 $s3

set null3 [new Agent/Null]
$ns attach-agent $n1 $null3

$ns connect $s3 $null3

set tfile [new Tracefile]
#$tfile filename /tmp/example-trace
$tfile filename example-trace

set trace3 [new Application/Traffic/Trace]
$trace3 attach-tracefile $tfile

$trace3 attach-agent $s3

## attach a 2nd source to the same trace file

set s4 [new Agent/UDP]
$ns attach-agent $n5 $s4

set null4 [new Agent/Null]
$ns attach-agent $n1 $null4

$ns connect $s4 $null4

set trace4 [new Application/Traffic/Trace]
$trace4 attach-tracefile $tfile

$trace4 attach-agent $s4

$ns at 1.0 "$exp1 start"
$ns at 1.0 "$pareto2 start"
$ns at 1.0 "$trace3 start"
$ns at 1.0 "$trace4 start"

$ns at $stoptime "$exp1 stop"
$ns at $stoptime "$pareto2 stop"
$ns at $stoptime "$trace3 stop"
$ns at $stoptime "$trace4 stop"

$ns at $plottime "close $f"
$ns at $plottime "finish tg"

proc finish file {
 
        set f [open temp.rands w]
        puts $f "TitleText: $file"
        puts $f "Device: Postscript"

        exec rm -f temp.p1 temp.p2 temp.p3 temp.p4
        exec touch temp.p1 temp.p2 temp.p3 temp.p4
        #
        #
	exec awk {
		{
			if (($1 == "+") && ($3 != 0) && ($9 == 2.0)) \
			     print $2, 2
		}
	} out.tr > temp.p1
	exec awk {
		{
			if (($1 == "+") && ($3 != 0) && ($9 == 3.0)) \
			     print $2, 3
		}
	} out.tr > temp.p2
	exec awk {
		{
			if (($1 == "+") && ($3 != 0) && ($9 == 4.0)) \
			     print $2, 4
		}
	} out.tr > temp.p3
	exec awk {
		{
			if (($1 == "+") && ($3 != 0) && ($9 == 5.0)) \
			     print $2, 5
		}
	} out.tr > temp.p4

	puts $f [format "\n\"ExpOnOff"]
	flush $f
	exec cat temp.p1 >@ $f
	flush $f
	puts $f [format "\n\"ParetoOnOff"]
	flush $f
	exec cat temp.p2 >@ $f
	flush $f
	puts $f [format "\n\"Trace1"]
	flush $f
	exec cat temp.p3 >@ $f
	flush $f
	puts $f [format "\n\"Trace2"]
	flush $f
	exec cat temp.p4 >@ $f
	flush $f

        close $f
	exec rm -f temp.p1 temp.p2 temp.p3 temp.p4
        exec xgraph -bb -tk -nl -m -x time -y "source node" temp.rands &

	puts "running nam..."
	exec nam out.nam &

	exec rm -f out.tr

}

$ns run


exit 0