File: ns-source.tcl

package info (click to toggle)
ns2 2.35%2Bdfsg-3.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 78,808 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 (400 lines) | stat: -rw-r--r-- 11,697 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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
#
# Copyright (c) 1996 Regents of the University of California.
# All rights reserved.
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software
#    must display the following acknowledgement:
# 	This product includes software developed by the MASH Research
# 	Group at the University of California Berkeley.
# 4. Neither the name of the University nor of the Research Group may be
#    used to endorse or promote products derived from this software without
#    specific prior written permission.
# 
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# @(#) $Header: /cvsroot/nsnam/ns-2/tcl/lib/ns-source.tcl,v 1.25 2000/11/01 21:47:59 xuanc Exp $
#

#  NOTE:  Could consider renaming this file to ns-app.tcl and moving the
#  backward compatible code to ns-compat.tcl

#set ns_telnet(interval) 1000ms
#set ns_bursty(interval) 0
#set ns_bursty(burst-size) 2
#set ns_message(packet-size) 40

Class Application/FTP -superclass Application

Application/FTP instproc init {} {
	$self next
}

Application/FTP instproc start {} {
	[$self agent] send -1
}

# Causes TCP to send no more new data.
Application/FTP instproc stop {} {
	[$self agent] advance 0
	[$self agent] close
}

Application/FTP instproc send {nbytes} {
	[$self agent] send $nbytes
}

# For sending packets.  Sends $pktcnt packets.
Application/FTP instproc produce { pktcnt } {
	[$self agent] advance $pktcnt
}

# For sending packets.  Sends $pktcnt more packets.
Application/FTP instproc producemore { pktcnt } {
	[$self agent] advanceby $pktcnt
}

# Backward compatibility
Application/Traffic instproc set args {
	$self instvar packetSize_ rate_
	if { [lindex $args 0] == "packet_size_" } {
		if { [llength $args] == 2 } {
			set packetSize_ [lindex $args 1]
			return
		} elseif { [llength $args] == 1 } {
			return $packetSize_
		}
	}
	eval $self next $args
}
# Helper function to convert rate_ into an interval_
#Hicked to generate pulse UDP traffic (seperate rate_ and interval_).
Application/Traffic/CBR instproc set args {
	$self instvar packetSize_ rate_
	if { [lindex $args 0] == "interval_" } {
		if { [llength $args] == 2 } {
			set ns_ [Simulator instance]
			set interval_ [$ns_ delay_parse [lindex $args 1]]
			$self set rate_ [expr $packetSize_ * 8.0/$interval_]
			return
		} elseif { [llength $args] == 1 } {
			return [expr $packetSize_ * 8.0/$rate_]
		}
	}
	eval $self next $args
}

#
# Below are backward compatible components
#

Class Agent/CBR -superclass Agent/UDP
Class Agent/CBR/UDP -superclass Agent/UDP
Class Agent/CBR/RTP -superclass Agent/RTP
Class Agent/CBR/UDP/SA -superclass Agent/SA

Agent/SA instproc attach-traffic tg {
	$tg attach-agent $self
	eval $self cmd attach-traffic $tg
}

Agent/CBR/UDP instproc attach-traffic tg {
	$self instvar trafgen_
	$tg attach-agent $self
	set trafgen_ $tg
}

Agent/CBR/UDP instproc done {} { }

Agent/CBR/UDP instproc start {} {
	$self instvar trafgen_
	$trafgen_ start
}

Agent/CBR/UDP instproc stop {} {
	$self instvar trafgen_
	$trafgen_ stop
}

Agent/CBR/UDP instproc advance args {
	$self instvar trafgen_
	eval $trafgen_ advance $args
}

Agent/CBR/UDP instproc advanceby args {
	$self instvar trafgen_
	eval $trafgen_ advanceby $args
}

Agent/CBR instproc init {} {
	$self next
	$self instvar trafgen_ interval_ random_ packetSize_ maxpkts_
	# The following used to be in ns-default.tcl
	set packetSize_ 210
	set random_ 0
	set maxpkts_ 268435456	
	set interval_ 0.00375
	set trafgen_ [new Application/Traffic/CBR]
	$trafgen_ attach-agent $self
	# Convert packetSize_ and interval_ to trafgen_ rate_
	$trafgen_ set rate_ [expr $packetSize_ * 8.0/ $interval_]
	$trafgen_ set random_ [$self set random_]
	$trafgen_ set maxpkts_ [$self set maxpkts_]
	$trafgen_ set packetSize_ [$self set packetSize_]
	# The line below is needed for backward compat with v1 test scripts 
        if {[Simulator set nsv1flag] == 0} { 
        
	    puts "using backward compatible Agent/CBR; use Application/Traffic/CBR instead"
	}    
}



Agent/CBR instproc done {} { }

Agent/CBR instproc start {} {
	$self instvar trafgen_
	$trafgen_ start
}

Agent/CBR instproc stop {} {
	$self instvar trafgen_
	$trafgen_ stop
}

Agent/CBR instproc advance args {
	$self instvar trafgen_
	eval $trafgen_ advance $args
}

Agent/CBR instproc advanceby args {
	$self instvar trafgen_
	eval $trafgen_ advanceby $args
}

# Catches parameter settings for overlying traffic generator object
Agent/CBR instproc set args {
	$self instvar interval_ random_ packetSize_ maxpkts_ trafgen_
	if { [info exists trafgen_] } {
		if { [lindex $args 0] == "packetSize_" } {
			if { [llength $args] == 2 } {
				$trafgen_ set packetSize_ [lindex $args 1]
				set packetSize_ [lindex $args 1]
				# Recompute rate 
				$trafgen_ set rate_ [expr $packetSize_ * 8.0/ $interval_]
                        	return 
                	} elseif { [llength $args] == 1 } {
				return $packetSize_
                	}
		} elseif { [lindex $args 0] == "random_" } {
			if { [llength $args] == 2 } {
				$trafgen_ set random_ [lindex $args 1]
				set random_ [lindex $args 1]
				return
                	} elseif { [llength $args] == 1 } {
				return $random_
			}
		} elseif { [lindex $args 0] == "maxpkts_" } {
			if { [llength $args] == 2 } {
				$trafgen_ set maxpkts_ [lindex $args 1]
				set maxpkts_ [lindex $args 1]
				return
                	} elseif { [llength $args] == 1 } {
				return $maxpkts_
			}
		} elseif { [lindex $args 0] == "interval_" } {
			if { [llength $args] == 2 } {
				set ns_ [Simulator instance]
				set interval_ [$ns_ delay_parse [lindex $args 1]]
				# Convert interval_ to rate for trafgen_
				$trafgen_ set rate_ [expr $packetSize_ * 8.0/ $interval_]
				return
                	} elseif { [llength $args] == 1 } {
				return $interval_
			}
		}
	}
	eval $self next $args
}
 
Class Traffic/Expoo -superclass Application/Traffic/Exponential
Class Traffic/Pareto -superclass Application/Traffic/Pareto
Class Traffic/RealAudio -superclass Application/Traffic/RealAudio
Class Traffic/Trace -superclass Application/Traffic/Trace

# These instprocs are needed to map old Traffic/* type variables
Traffic/Expoo instproc set args {
	$self instvar packetSize_ burst_time_ idle_time_ rate_ 
	if { [lindex $args 0] == "packet-size" } {
		if { [llength $args] == 2 } {
			$self set packetSize_ [lindex $args 1]
                       	return 
               	} elseif { [llength $args] == 1 } {
			return $packetSize_
               	}
	} elseif { [lindex $args 0] == "burst-time" } {
		if { [llength $args] == 2 } {
			$self set burst_time_ [lindex $args 1]
                       	return 
               	} elseif { [llength $args] == 1 } {
			return $burst_time_
               	}
	} elseif { [lindex $args 0] == "idle-time" } {
		if { [llength $args] == 2 } {
			$self set idle_time_ [lindex $args 1]
                       	return 
               	} elseif { [llength $args] == 1 } {
			return $idle_time_
               	}
	} elseif { [lindex $args 0] == "rate" } {
		if { [llength $args] == 2 } {
			$self set rate_ [lindex $args 1]
                       	return 
               	} elseif { [llength $args] == 1 } {
			return $rate_
               	}
	}
	eval $self next $args
}

Traffic/Pareto instproc set args {
	$self instvar packetSize_ burst_time_ idle_time_ rate_ shape_
	if { [lindex $args 0] == "packet-size" } {
		if { [llength $args] == 2 } {
			$self set packetSize_ [lindex $args 1]
                       	return 
               	} elseif { [llength $args] == 1 } {
			return $packetSize_
               	}
	} elseif { [lindex $args 0] == "burst-time" } {
		if { [llength $args] == 2 } {
			$self set burst_time_ [lindex $args 1]
                       	return 
               	} elseif { [llength $args] == 1 } {
			return $burst_time_
               	}
	} elseif { [lindex $args 0] == "idle-time" } {
		if { [llength $args] == 2 } {
			$self set idle_time_ [lindex $args 1]
                       	return 
               	} elseif { [llength $args] == 1 } {
			return $idle_time_
               	}
	} elseif { [lindex $args 0] == "rate" } {
		if { [llength $args] == 2 } {
			$self set rate_ [lindex $args 1]
                       	return 
               	} elseif { [llength $args] == 1 } {
			return $rate_
               	}
	} elseif { [lindex $args 0] == "shape" } {
		if { [llength $args] == 2 } {
			$self set shape_ [lindex $args 1]
                       	return 
               	} elseif { [llength $args] == 1 } {
			return $shape_
               	}
	}
	eval $self next $args
}

Traffic/RealAudio instproc set args {
	$self instvar packetSize_ burst_time_ idle_time_ rate_ 
	if { [lindex $args 0] == "packet-size" } {
		if { [llength $args] == 2 } {
			$self set packetSize_ [lindex $args 1]
                       	return 
               	} elseif { [llength $args] == 1 } {
			return $packetSize_
               	}
	} elseif { [lindex $args 0] == "burst-time" } {
		if { [llength $args] == 2 } {
			$self set burst_time_ [lindex $args 1]
                       	return 
               	} elseif { [llength $args] == 1 } {
			return $burst_time_
               	}
	} elseif { [lindex $args 0] == "idle-time" } {
		if { [llength $args] == 2 } {
			$self set idle_time_ [lindex $args 1]
                       	return 
               	} elseif { [llength $args] == 1 } {
			return $idle_time_
               	}
	} elseif { [lindex $args 0] == "rate" } {
		if { [llength $args] == 2 } {
			$self set rate_ [lindex $args 1]
                       	return 
               	} elseif { [llength $args] == 1 } {
			return $rate_
               	}
	}
	eval $self next $args
}

Class Source/FTP -superclass Application
Source/FTP set maxpkts_ 268435456

Source/FTP instproc attach o {
	$self instvar agent_
	set agent_ $o
	$self attach-agent $o
}

Source/FTP instproc init {} {
	$self next
	$self instvar maxpkts_ agent_
	set maxpkts_ 268435456
}

Source/FTP instproc start {} {
	$self instvar agent_ maxpkts_
	$agent_ advance $maxpkts_
}

Source/FTP instproc stop {} {
	$self instvar agent_
	$agent_ advance 0
}

Source/FTP instproc produce { pktcnt } {
	$self instvar agent_ 
	$agent_ advance $pktcnt
}

Source/FTP instproc producemore { pktcnt } {
	$self instvar agent_
	$agent_ advanceby $pktcnt
}


#
# For consistency with other applications
#
Class Source/Telnet -superclass Application/Telnet

Source/Telnet set maxpkts_ 268435456

Source/Telnet instproc attach o {
	$self instvar agent_
	set agent_ $o
	$self attach-agent $o
}