Debian Codegraph @

protolib/src/sim/ns/ns234/ns-lib.tcl

raw
1 # -*- Mode:tcl; tcl-indent-level:8; tab-width:8; indent-tabs-mode:t -*-
2 #
3 # Copyright (c) 1996 Regents of the University of California.
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 # 3. All advertising materials mentioning features or use of this software
15 # must display the following acknowledgement:
16 # This product includes software developed by the MASH Research
17 # Group at the University of California Berkeley.
18 # 4. Neither the name of the University nor of the Research Group may be
19 # used to endorse or promote products derived from this software without
20 # specific prior written permission.
21 #
22 # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 # SUCH DAMAGE.
33 #
34
35 # @(#) $Header: /cvsroot/nsnam/ns-2/tcl/lib/ns-lib.tcl,v 1.277 2009/01/15 06:23:49 tom_henderson Exp $
36
37
38 #
39 # Word of warning to developers:
40 # this code (and all it sources) is compiled into the
41 # ns executable. You need to rebuild ns or explicitly
42 # source this code to see changes take effect.
43 #
44
45
46
47 proc warn {msg} {
48 global warned_
49 if {![info exists warned_($msg)]} {
50 puts stderr "warning: $msg"
51 set warned_($msg) 1
52 }
53 }
54
55 if {[info commands debug] == ""} {
56 proc debug args {
57 warn {Script debugging disabled. Reconfigure with --with-tcldebug, and recompile.}
58 }
59 }
60
61 proc assert args {
62 if [catch "expr $args" ret] {
63 set ret [eval expr $args]
64 }
65 if {! $ret} {
66 error "assertion failed: $args"
67 }
68 }
69
70 proc find-max list {
71 set max 0
72 foreach val $list {
73 if {$val > $max} {
74 set max $val
75 }
76 }
77 return $max
78 }
79
80 proc bw_parse { bspec } {
81 if { [scan $bspec "%f%s" b unit] == 1 } {
82 set unit bps
83 }
84 regsub {[/p]s(ec)?$} $unit {} unit
85 if [string match {*B} $unit] {
86 set b [expr $b*8]
87 set unit "[string trimright $unit B]b"
88 }
89 switch $unit {
90 b { return $b }
91 kb { return [expr $b*1000] }
92 Mb { return [expr $b*1000000] }
93 Gb { return [expr $b*1000000000] }
94 default {
95 puts "error: bw_parse: unknown unit `$unit'"
96 exit 1
97 }
98 }
99 }
100
101 proc time_parse { spec } {
102 if { [scan $spec "%f%s" t unit] == 1 } {
103 set unit s
104 }
105 regsub {sec$} $unit {s} unit
106 switch $unit {
107 s { return $t }
108 ms { return [expr $t*1e-3] }
109 us { return [expr $t*1e-6] }
110 ns { return [expr $t*1e-9] }
111 ps { return [expr $t*1e-12] }
112 default {
113 puts "error: time_parse: unknown unit `$unit'"
114 exit 1
115 }
116 }
117 }
118
119 proc delay_parse { spec } {
120 return [time_parse $spec]
121 }
122
123
124 #
125 # Create the core OTcl class called "Simulator".
126 # This is the principal interface to the simulation engine.
127 #
128 #Class Simulator
129
130 #
131 # XXX Whenever you modify the source list below, please also change the
132 # OTcl script dependency list in Makefile.in
133 #
134 source ns-autoconf.tcl
135 source ns-address.tcl
136 source ns-node.tcl
137 source ns-rtmodule.tcl
138 source ns-hiernode.tcl
139 source ns-mobilenode.tcl
140 source ns-bsnode.tcl
141 source ns-link.tcl
142 source ns-source.tcl
143 source ns-compat.tcl
144 source ns-packet.tcl
145 source ns-queue.tcl
146 source ns-trace.tcl
147 source ns-random.tcl
148 source ns-agent.tcl
149 source ns-route.tcl
150 source ns-errmodel.tcl
151 source ns-intserv.tcl
152 source ns-cmutrace.tcl
153 source ns-mip.tcl
154 source ns-sat.tcl
155 #source ns-nix.tcl
156 source ns-diffusion.tcl
157 source ../rtp/session-rtp.tcl
158 source ../interface/ns-iface.tcl
159 source ../lan/ns-mac.tcl
160
161 # Added by Sushmita to support event tracing for mac-simple and 802.11
162 source ../lan/ns-mac-simple.tcl
163 source ../lan/ns-mac-802_11.tcl
164
165 source ../lan/ns-ll.tcl
166 source ../lan/vlan.tcl
167 source ../lan/abslan.tcl
168 source ../mcast/timer.tcl
169 source ../mcast/ns-mcast.tcl
170 source ns-srcrt.tcl
171 source ../mcast/McastProto.tcl
172 source ../mcast/DM.tcl
173 source ../ctr-mcast/CtrMcast.tcl
174 source ../ctr-mcast/CtrMcastComp.tcl
175 source ../ctr-mcast/CtrRPComp.tcl
176 source ../mcast/BST.tcl
177 source ../mcast/srm.tcl
178 source ../mcast/srm-ssm.tcl
179 # These files removed due to licensing conflicts
180 # source ../mcast/mftp_snd.tcl
181 # source ../mcast/mftp_rcv.tcl
182 # source ../mcast/mftp_rcv_stat.tcl
183 source ../mcast/McastMonitor.tcl
184 source ../rlm/rlm.tcl
185 source ../rlm/rlm-ns.tcl
186 source ../session/session.tcl
187 source ../webcache/http-server.tcl
188 source ../webcache/http-cache.tcl
189 source ../webcache/http-agent.tcl
190 source ../webcache/http-mcache.tcl
191 source ../webcache/webtraf.tcl
192 source ../webcache/empweb.tcl
193 source ns-namsupp.tcl
194 source ../mobility/dsdv.tcl
195 source ../mobility/dsr.tcl
196 source ../mobility/com.tcl
197
198 source ../plm/plm.tcl
199 source ../plm/plm-ns.tcl
200 source ../plm/plm-topo.tcl
201
202 # MPLS
203 source ../mpls/ns-mpls-simulator.tcl
204 source ../mpls/ns-mpls-node.tcl
205 source ../mpls/ns-mpls-ldpagent.tcl
206 source ../mpls/ns-mpls-classifier.tcl
207
208 source ns-default.tcl
209 source ../emulate/ns-emulate.tcl
210
211 #pushback
212 source ns-pushback.tcl
213
214 # PGM
215 #source ../pgm/ns-pgm.tcl
216
217 #LMS
218 source ../mcast/ns-lms.tcl
219
220 # STL dependent modules get included
221 # ONLY when STL is found
222
223 if {[ns-hasSTL] == 1} {
224 source ns-nix.tcl
225 source ../pgm/ns-pgm.tcl
226 source ../rtglib/ns-rtProtoLS.tcl
227 source ../delaybox/delaybox.tcl
228 source ../packmime/packmime.tcl
229 }
230
231 source ns-qsnode.tcl
232
233 # Obsolete modules
234 #source ns-wireless-mip.tcl
235 #source ns-nam.tcl
236
237 Simulator instproc init args {
238
239 # Debojyoti added this for asim
240
241 $self instvar useasim_
242 $self instvar slinks_
243 $self instvar nconn_
244 $self instvar sflows_
245 $self instvar nsflows_
246
247 set slinks_(0:0) 0
248 set nconn_ 0
249 set conn_ ""
250 # for short flows stuff
251 set sflows_ ""
252 set nsflows_ 0
253 set useasim_ 0
254
255 $self create_packetformat
256 $self use-scheduler Calendar
257 #$self use-scheduler List
258 $self set nullAgent_ [new Agent/Null]
259 $self set-address-format def
260 if {[lindex $args 0] == "-multicast"} {
261 $self multicast $args
262 }
263 eval $self next $args
264 }
265
266 Simulator instproc nullagent {} {
267 $self instvar nullAgent_
268 return $nullAgent_
269 }
270
271 Simulator instproc use-scheduler type {
272 $self instvar scheduler_
273 if [info exists scheduler_] {
274 if { [$scheduler_ info class] == "Scheduler/$type" } {
275 return
276 } else {
277 delete $scheduler_
278 }
279 }
280 set scheduler_ [new Scheduler/$type]
281 $scheduler_ now
282 }
283
284 Simulator instproc delay_parse { spec } {
285 return [time_parse $spec]
286 }
287
288 Simulator instproc bw_parse { spec } {
289 return [bw_parse $spec]
290 }
291
292 #
293 # A simple method to wrap any object around
294 # a trace object that dumps to stdout
295 #
296 Simulator instproc dumper obj {
297 set t [$self alloc-trace hop stdout]
298 $t target $obj
299 return $t
300 }
301
302 # New node structure
303 #
304 # Add APT to support multi-interface: user can specified multiple channels
305 # when config nod. Still need modifications in routing agents to make
306 # multi-interfaces really work. -chen xuan 07/21/00
307 #
308 # Define global node configuration
309 # $ns_ node-config -addressType flat/hierarchical
310 # -adhocRouting DSDV/DSR/TORA
311 # -llType
312 # -macType
313 # -propType
314 # -ifqType
315 # -ifqLen
316 # -phyType
317 # -antType
318 # -channel
319 # -channelType
320 # -topologyInstance
321 # -wiredRouting ON/OFF
322 # -mobileIP ON/OFF
323 # -energyModel "EnergyModel"
324 # -initialEnergy (in Joules)
325 # -rxPower (in W)
326 # -txPower (in W)
327 # -idlePower (in W)
328 #
329 # -sleepPower (in W)
330 # -sleepTime (in sec indicating when the node can start sleeping)
331 # -agentTrace ON
332 # -routerTrace ON
333 # -macTrace OFF
334 # -phyTrace OFF
335 # -toraDebug OFF
336 # -movementTrace OFF
337 # change wrt Mike's code
338 # -eotTrace OFF
339 # -diffusionFilter "GradientFilter/OnePhasePullFilter/GeoRoutingFilter/RmstFilter/SourceRouteFilter/LogFilter/TagFilter"
340
341
342 Simulator instproc addressType {val} { $self set addressType_ $val }
343 Simulator instproc adhocRouting {val} { $self set routingAgent_ $val }
344 Simulator instproc llType {val} { $self set llType_ $val }
345 Simulator instproc macType {val} { $self set macType_ $val }
346 Simulator instproc propType {val} { $self set propType_ $val }
347 Simulator instproc propInstance {val} { $self set propInstance_ $val }
348 Simulator instproc ifqType {val} { $self set ifqType_ $val }
349 Simulator instproc ifqLen {val} { $self set ifqlen_ $val }
350 Simulator instproc phyType {val} { $self set phyType_ $val }
351 Simulator instproc antType {val} { $self set antType_ $val }
352 Simulator instproc channel {val} {$self set channel_ $val}
353 Simulator instproc channelType {val} {$self set channelType_ $val}
354 Simulator instproc topoInstance {val} {$self set topoInstance_ $val}
355 Simulator instproc wiredRouting {val} {$self set wiredRouting_ $val}
356 Simulator instproc mobileIP {val} {$self set mobileIP_ $val}
357 Simulator instproc energyModel {val} { $self set energyModel_ $val }
358 Simulator instproc initialEnergy {val} { $self set initialEnergy_ $val }
359 Simulator instproc txPower {val} { $self set txPower_ $val }
360 Simulator instproc rxPower {val} { $self set rxPower_ $val }
361 Simulator instproc idlePower {val} { $self set idlePower_ $val }
362 #
363 Simulator instproc sleepPower {val} { $self set sleepPower_ $val }
364 Simulator instproc sleepTime {val} { $self set sleepTime_ $val }
365 Simulator instproc transitionPower {val} { $self set transitionPower_ $val }
366 Simulator instproc transitionTime {val} { $self set transitionTime_ $val }
367 #
368 Simulator instproc IncomingErrProc {val} { $self set inerrProc_ $val }
369 Simulator instproc OutgoingErrProc {val} { $self set outerrProc_ $val }
370 Simulator instproc FECProc {val} { $self set FECProc_ $val }
371 Simulator instproc agentTrace {val} { $self set agentTrace_ $val }
372 Simulator instproc routerTrace {val} { $self set routerTrace_ $val }
373 Simulator instproc macTrace {val} { $self set macTrace_ $val }
374 Simulator instproc phyTrace {val} { $self set phyTrace_ $val }
375 Simulator instproc movementTrace {val} { $self set movementTrace_ $val }
376 Simulator instproc toraDebug {val} {$self set toraDebug_ $val }
377 Simulator instproc satNodeType {val} {$self set satNodeType_ $val}
378 Simulator instproc downlinkBW {val} {$self set downlinkBW_ $val}
379 Simulator instproc stopTime {val} {$self set stopTime_ $val}
380
381 # This method is needed so that new Routing Agents can be implemented in a dynamic
382 # library and used without having to modify Simulator::create-wireless-node
383 Simulator instproc rtAgentFunction {val} {$self set rtAgentFunction_ $val}
384
385
386 # change wrt Mike's code
387 Simulator instproc eotTrace {val} { $self set eotTrace_ $val }
388 Simulator instproc diffusionFilter {val} {$self set diffFilter_ $val}
389
390 Simulator instproc MPLS { val } {
391 if { $val == "ON" } {
392 Node enable-module "MPLS"
393 } else {
394 Node disable-module "MPLS"
395 }
396 }
397
398
399 Simulator instproc PGM { val } {
400 if { $val == "ON" } {
401 Node enable-module "PGM"
402 } else {
403 Node disable-module "PGM"
404 }
405 }
406 Simulator instproc LMS { val } {
407 if { $val == "ON" } {
408 Node enable-module "LMS"
409 } else {
410 Node disable-module "LMS"
411 }
412 }
413
414 Simulator instproc get-nodetype {} {
415 $self instvar addressType_ routingAgent_ wiredRouting_
416 set val ""
417
418 if { [info exists addressType_] && $addressType_ == "hierarchical" } {
419 set val Hier
420 }
421 if { [info exists routingAgent_] && $routingAgent_ != "" } {
422 set val Mobile
423 }
424 if { [info exists wiredRouting_] && $wiredRouting_ == "ON" } {
425 set val Base
426 }
427 if { [info exists wiredRouting_] && $wiredRouting_ == "OFF"} {
428 set val Base
429 }
430 if { [Simulator set mobile_ip_] } {
431 if { $val == "Base" && $wiredRouting_ == "ON" } {
432 set val MIPBS
433 }
434 if { $val == "Base" && $wiredRouting_ == "OFF" } {
435 set val MIPMH
436 }
437 }
438 return $val
439 }
440
441 Simulator instproc node-config args {
442 # Object::init-vars{} is defined in ~tclcl/tcl-object.tcl.
443 # It initializes all default variables in the following way:
444 # 1. Look for pairs of {-cmd val} in args
445 # 2. If "$self $cmd $val" is not valid then put it in a list of
446 # arguments to be returned to the caller.
447 #
448 # Since we do not handle undefined {-cmd val} pairs, we ignore
449 # return value from init-vars{}.
450 set args [eval $self init-vars $args]
451
452 $self instvar addressType_ routingAgent_ propType_ macTrace_ \
453 routerTrace_ agentTrace_ movementTrace_ channelType_ channel_ \
454 chan topoInstance_ propInstance_ mobileIP_ \
455 rxPower_ txPower_ idlePower_ sleepPower_ sleepTime_ transitionPower_ \
456 transitionTime_ satNodeType_ eotTrace_ phyTrace_
457
458 if [info exists phyTrace_] {
459 Simulator set PhyTrace_ $phyTrace_
460 }
461
462
463 if [info exists macTrace_] {
464 Simulator set MacTrace_ $macTrace_
465 }
466 if [info exists routerTrace_] {
467 Simulator set RouterTrace_ $routerTrace_
468 }
469 if [info exists agentTrace_] {
470 Simulator set AgentTrace_ $agentTrace_
471 }
472 if [info exists movementTrace_] {
473 Simulator set MovementTrace_ $movementTrace_
474 }
475
476 # change wrt Mike's code
477 if [info exists eotTrace_] {
478 Simulator set EotTrace_ $eotTrace_
479 }
480
481 # hacking for matching old cmu add-interface
482 # not good style, for back-compability ONLY
483 #
484 # Only create 1 instance of prop
485 if {[info exists propInstance_]} {
486 if {[info exists propType_] && [Simulator set propInstCreated_] == 0} {
487 warn "Both propType and propInstance are set. propType is ignored."
488 }
489 } else {
490 if {[info exists propType_]} {
491 set propInstance_ [new $propType_]
492 Simulator set propInstCreated_ 1
493 }
494 }
495
496 # Add multi-interface support:
497 # User can only specify either channelType_ (single_interface as
498 # before) or channel_ (multi_interface)
499 # If both variables are specified, error!
500 if {[info exists channelType_] && [info exists channel_]} {
501 error "Can't specify both channel and channelType, error!"
502 } elseif {[info exists channelType_] && ![info exists satNodeType_]} {
503 # Single channel, single interface
504 warn "Please use -channel as shown in tcl/ex/wireless-mitf.tcl"
505 if {![info exists chan]} {
506 set chan [new $channelType_]
507 }
508 } elseif {[info exists channel_]} {
509 # Multiple channel, multiple interfaces
510 set chan $channel_
511 }
512 if [info exists topoInstance_] {
513 $propInstance_ topography $topoInstance_
514 }
515 # set address type, hierarchical or expanded
516 if {[string compare $addressType_ ""] != 0} {
517 $self set-address-format $addressType_
518 }
519 # set mobileIP flag
520 if { [info exists mobileIP_] && $mobileIP_ == "ON"} {
521 Simulator set mobile_ip_ 1
522 } else {
523 if { [info exists mobileIP_] } {
524 Simulator set mobile_ip_ 0
525 }
526 }
527 }
528
529 # Default behavior is changed: consider nam as not initialized if
530 # no shape OR color parameter is given
531 Simulator instproc node args {
532 $self instvar Node_ routingAgent_ wiredRouting_ satNodeType_
533 if { [Simulator info vars EnableMcast_] != "" } {
534 warn "Flag variable Simulator::EnableMcast_ discontinued.\n\t\
535 Use multicast methods as:\n\t\t\
536 % set ns \[new Simulator -multicast on]\n\t\t\
537 % \$ns multicast"
538 $self multicast
539 Simulator unset EnableMcast_
540 }
541 if { [Simulator info vars NumberInterfaces_] != "" } {
542 warn "Flag variable Simulator::NumberInterfaces_ discontinued.\n\t\
543 Setting this variable will not affect simulations."
544 Simulator unset NumberInterfaces_
545 }
546
547 # Satellite node
548 if { [info exists satNodeType_] } {
549 set node [eval $self create-satnode]
550 #simulator's nodelist in C++ space
551 if {[info exists wiredRouting_] && $wiredRouting_ == "ON"} {
552 # add node to simulator's nodelist in C++ space
553 $self add-node $node [$node id]
554 # Want to keep global state of wiredRouting info
555 SatRouteObject set wiredRouting_ true
556 }
557 return $node
558 }
559
560 # wireless-ready node
561 if { [info exists routingAgent_] && ($routingAgent_ != "") } {
562 set node [eval $self create-wireless-node $args]
563 # for base node
564 if {[info exists wiredRouting_] && $wiredRouting_ == "ON"} {
565 set Node_([$node id]) $node
566 #simulator's nodelist in C++ space
567 $self add-node $node [$node id]
568 }
569 return $node
570 }
571
572
573 # Enable-mcast is now done automatically inside Node::init{}
574 #
575 # XXX node_factory_ is deprecated, HOWEVER, since it's still used by
576 # mobile IP, algorithmic routing, manual routing, and backward
577 # compability tests of hierarchical routing, we should keep it around
578 # before all related code are wiped out.
579 set node [eval new [Simulator set node_factory_] $args]
580 set Node_([$node id]) $node
581
582 #add to simulator's nodelist in C++ space
583 $self add-node $node [$node id]
584
585 #set the nodeid in c++ Node - ratul
586 $node nodeid [$node id]
587
588 $node set ns_ $self
589 $self check-node-num
590 return $node
591 }
592
593 # XXX This is stupid hack. When old code (not using node-config) is used,
594 # create-wireless-node{} will not be called, and IMEPFlag_ will remain empty
595 # (as set in ns-default.tcl), then Node/MobileNode will use global proc
596 # cmu-trace to create trace objects; otherwise mobility-trace{} will be
597 # triggered.
598 Simulator instproc imep-support {} {
599 return [Simulator set IMEPFlag_]
600 }
601
602 # XXX This should be moved into the node initialization procedure instead
603 # of standing here in ns-lib.tcl.
604 Simulator instproc create-wireless-node args {
605 $self instvar routingAgent_ wiredRouting_ propInstance_ llType_ \
606 macType_ ifqType_ ifqlen_ phyType_ chan antType_ \
607 energyModel_ initialEnergy_ txPower_ rxPower_ \
608 idlePower_ sleepPower_ sleepTime_ transitionPower_ transitionTime_ \
609 topoInstance_ level1_ level2_ inerrProc_ outerrProc_ FECProc_ rtAgentFunction_
610
611 Simulator set IMEPFlag_ OFF
612
613 # create node instance
614 set node [eval $self create-node-instance $args]
615
616 # basestation address setting
617 if { [info exist wiredRouting_] && $wiredRouting_ == "ON" } {
618 $node base-station [AddrParams addr2id [$node node-addr]]
619 }
620 if {$rtAgentFunction_ != ""} {
621 set ragent [$self $rtAgentFunction_ $node]
622 } else {
623 puts "switching on $routingAgent_"
624 switch -exact $routingAgent_ {
625 DSDV {
626 set ragent [$self create-dsdv-agent $node]
627 }
628 DSR {
629 $self at 0.0 "$node start-dsr"
630 }
631 AODV {
632 set ragent [$self create-aodv-agent $node]
633 }
634 AOMDV {
635 set ragent [$self create-aomdv-agent $node]
636 }
637 TORA {
638 Simulator set IMEPFlag_ ON
639 set ragent [$self create-tora-agent $node]
640 }
641 ProtolibMK {
642 set ragent [$self create-protolibmk-agent $node]
643 }
644 DIFFUSION/RATE {
645 eval $node addr $args
646 set ragent [$self create-diffusion-rate-agent $node]
647 }
648 DIFFUSION/PROB {
649 eval $node addr $args
650 set ragent [$self create-diffusion-probability-agent $node]
651 }
652 Directed_Diffusion {
653 eval $node addr $args
654 set ragent [$self create-core-diffusion-rtg-agent $node]
655 }
656 FLOODING {
657 eval $node addr $args
658 set ragent [$self create-flooding-agent $node]
659 }
660 OMNIMCAST {
661 eval $node addr $args
662 set ragent [$self create-omnimcast-agent $node]
663 }
664 DumbAgent {
665 set ragent [$self create-dumb-agent $node]
666 }
667 ManualRtg {
668 set ragent [$self create-manual-rtg-agent $node]
669 }
670 default {
671 eval $node addr $args
672 puts "Wrong node routing agent!"
673 exit
674 }
675 }
676 }
677
678 # errProc_ and FECProc_ are an option unlike other
679 # parameters for node interface
680 if ![info exist inerrProc_] {
681 set inerrProc_ ""
682 }
683 if ![info exist outerrProc_] {
684 set outerrProc_ ""
685 }
686 if ![info exist FECProc_] {
687 set FECProc_ ""
688 }
689
690
691
692 # Add main node interface
693 $node add-interface $chan $propInstance_ $llType_ $macType_ \
694 $ifqType_ $ifqlen_ $phyType_ $antType_ $topoInstance_ \
695 $inerrProc_ $outerrProc_ $FECProc_
696 # Attach agent
697 if {$routingAgent_ != "DSR"} {
698 $node attach $ragent [Node set rtagent_port_]
699 }
700 if {$routingAgent_ == "DIFFUSION/RATE" ||
701 $routingAgent_ == "DIFFUSION/PROB" ||
702 $routingAgent_ == "FLOODING" ||
703 $routingAgent_ == "OMNIMCAST" ||
704 $routingAgent_ == "Directed_Diffusion" } {
705 $ragent port-dmux [$node demux]
706 $node instvar ll_
707 $ragent add-ll $ll_(0)
708 }
709 if { $routingAgent_ == "DumbAgent" } {
710 $ragent port-dmux [$node demux]
711 }
712
713
714 # Bind routing agent and mip agent if existing basestation
715 # address setting
716 if { [info exist wiredRouting_] && $wiredRouting_ == "ON" } {
717 if { $routingAgent_ != "DSR" } {
718 $node mip-call $ragent
719 }
720 }
721 #
722 # This Trace Target is used to log changes in direction
723 # and velocity for the mobile node.
724 #
725 set tracefd [$self get-ns-traceall]
726 if {$tracefd != "" } {
727 $node nodetrace $tracefd
728 $node agenttrace $tracefd
729 }
730 set namtracefd [$self get-nam-traceall]
731 if {$namtracefd != "" } {
732 $node namattach $namtracefd
733 }
734 if [info exists energyModel_] {
735 if [info exists level1_] {
736 set l1 $level1_
737 } else {
738 set l1 0.5
739 }
740 if [info exists level2_] {
741 set l2 $level2_
742 } else {
743 set l2 0.2
744 }
745 $node addenergymodel [new $energyModel_ $node \
746 $initialEnergy_ $l1 $l2]
747 }
748 if [info exists txPower_] {
749 $node setPt $txPower_
750 }
751 if [info exists rxPower_] {
752 $node setPr $rxPower_
753 }
754 if [info exists idlePower_] {
755 $node setPidle $idlePower_
756 }
757 #
758 if [info exists sleepPower_] {
759 $node setPsleep $sleepPower_
760 }
761 if [info exists sleepTime_] {
762 $node setTSleep $sleepTime_
763 }
764 if [info exists transitionPower_] {
765 $node setPtransition $transitionPower_
766 }
767 if [info exists transitionTime_] {
768 $node setTtransition $transitionTime_
769 }
770 #
771 $node topography $topoInstance_
772
773 return $node
774 }
775
776 Simulator instproc create-node-instance args {
777 $self instvar routingAgent_
778 # DSR is a special case
779 if {$routingAgent_ == "DSR"} {
780 set nodeclass [$self set-dsr-nodetype]
781 } else {
782 set nodeclass Node/MobileNode
783 }
784 return [eval new $nodeclass $args]
785 }
786
787 Simulator instproc set-dsr-nodetype {} {
788 $self instvar wiredRouting_
789 set nodetype SRNodeNew
790 # MIP mobilenode
791 if [Simulator set mobile_ip_] {
792 set nodetype SRNodeNew/MIPMH
793 }
794 # basestation dsr node
795 if { [info exists wiredRouting_] && $wiredRouting_ == "ON"} {
796 set nodetype Node/MobileNode/BaseStationNode
797 }
798 return $nodetype
799 }
800
801 Simulator instproc create-tora-agent { node } {
802 set ragent [new Agent/TORA [$node id]]
803 $node set ragent_ $ragent
804 return $ragent
805 }
806
807 Simulator instproc create-dsdv-agent { node } {
808 # Create a dsdv routing agent for this node
809 set ragent [new Agent/DSDV]
810 # Setup address (supports hier-addr) for dsdv agent
811 # and mobilenode
812 set addr [$node node-addr]
813 $ragent addr $addr
814 $ragent node $node
815 if [Simulator set mobile_ip_] {
816 $ragent port-dmux [$node demux]
817 }
818 $node addr $addr
819 $node set ragent_ $ragent
820 $self at 0.0 "$ragent start-dsdv" ;# start updates
821 return $ragent
822 }
823
824 Simulator instproc create-protolibmk-agent { node } {
825 # create a dummie wireless agent
826 # it will forward packets up to protolib manet
827 # and just act as a wedge into ns
828 # used by protolib wireless manets
829 set ragent [new Agent/ProtolibMK [$node node-addr]]
830 $node set ragent_ $ragent
831 return $ragent
832 }
833
834 Simulator instproc create-dumb-agent { node } {
835
836 # create a simple wireless agent
837 # that only forwards packets
838 # used for testing single hop brdcast/unicast mode
839 # for wireless macs
840
841 set ragent [new Agent/DumbAgent]
842 $node set ragent_ $ragent
843
844 return $ragent
845 }
846
847 Simulator instproc create-manual-rtg-agent { node } {
848
849 # create a simple wireless agent
850 # that only forwards packets
851 # used for testing single hop brdcast/unicast mode
852 # for wireless macs
853
854 set ragent [new Agent/ManualRtgAgent]
855 $node set ragent_ $ragent
856 $node attach $ragent [Node set rtagent_port_]
857
858 return $ragent
859 }
860
861 Simulator instproc create-aodv-agent { node } {
862 # Create AODV routing agent
863 set ragent [new Agent/AODV [$node node-addr]]
864 $self at 0.0 "$ragent start" ;# start BEACON/HELLO Messages
865 $node set ragent_ $ragent
866 return $ragent
867 }
868
869 # AOMDV patch
870 Simulator instproc create-aomdv-agent { node } {
871 set ragent [new Agent/AOMDV [$node node-addr]]
872 $self at 0.0 "$ragent start"
873 $node set ragent_ $ragent
874 return $ragent
875 }
876
877 Simulator instproc use-newtrace {} {
878 Simulator set WirelessNewTrace_ 1
879 }
880
881 Simulator instproc use-taggedtrace { {tag ON} } {
882 Simulator set TaggedTrace_ $tag
883 }
884
885 Simulator instproc hier-node haddr {
886 error "hier-nodes should be created with [$ns_ node $haddr]"
887 }
888
889 Simulator instproc now {} {
890 $self instvar scheduler_
891 return [$scheduler_ now]
892 }
893
894 Simulator instproc at args {
895 $self instvar scheduler_
896 return [eval $scheduler_ at $args]
897 }
898
899 Simulator instproc at-now args {
900 $self instvar scheduler_
901 return [eval $scheduler_ at-now $args]
902 }
903
904 Simulator instproc cancel args {
905 $self instvar scheduler_
906 return [eval $scheduler_ cancel $args]
907 }
908
909 Simulator instproc after {ival args} {
910 eval $self at [expr [$self now] + $ival] $args
911 }
912
913 #
914 # check if total num of nodes exceed 2 to the power n
915 # where <n=node field size in address>
916 #
917 Simulator instproc check-node-num {} {
918 if {[Node set nn_] > [expr pow(2, [AddrParams nodebits])]} {
919 error "Number of nodes exceeds node-field-size of [AddrParams nodebits] bits"
920 }
921 }
922
923 #
924 # Check if number of items at each hier level (num of nodes, or clusters or
925 # domains) exceed size of that hier level field size (in bits). should be
926 # modified to support n-level of hierarchies
927 #
928 Simulator instproc chk-hier-field-lengths {} {
929 AddrParams instvar domain_num_ cluster_num_ nodes_num_
930 if [info exists domain_num_] {
931 if {[expr $domain_num_ - 1]> [AddrParams NodeMask 1]} {
932 error "\# of domains exceed dom-field-size "
933 }
934 }
935 if [info exists cluster_num_] {
936 set maxval [expr [find-max $cluster_num_] - 1]
937 if {$maxval > [expr pow(2, [AddrParams NodeMask 2])]} {
938 error "\# of clusters exceed clus-field-size "
939 }
940 }
941 if [info exists nodes_num_] {
942 set maxval [expr [find-max $nodes_num_] -1]
943 if {$maxval > [expr pow(2, [AddrParams NodeMask 3])]} {
944 error "\# of nodess exceed node-field-size"
945 }
946 }
947 }
948
949
950 Simulator instproc check-smac {} {
951 $self instvar macType_
952 if { [info exist macType_] && $macType_ == "Mac/SMAC" } {
953 if { [$macType_ set syncFlag_] } {
954 puts "\nNOTE: SMAC is running with sleep-wakeup cycles on. Please make sure to run yr applications AFTER the nodes get sync'ed which is about 40sec for the default settings.\n"
955 }
956 }
957 }
958
959
960 Simulator instproc run {} {
961 # NIXVECTOR?
962 # global runstart
963 # set runstart [clock seconds]
964 $self check-smac ;# print warning if in sleep/wakeup cycle
965 $self check-node-num
966 $self rtmodel-configure ;# in case there are any
967 [$self get-routelogic] configure
968 $self instvar scheduler_ Node_ link_ started_
969
970 set started_ 1
971
972 #
973 # Reset every node, which resets every agent.
974 #
975
976 foreach nn [array names Node_] {
977 $Node_($nn) reset
978 # GFR Additions for NixVector Routing
979 if { [Simulator set nix-routing] } {
980 $Node_($nn) populate-objects
981 }
982 }
983
984 #
985 # Also reset every queue
986 #
987
988 foreach qn [array names link_] {
989 set q [$link_($qn) queue]
990 $q reset
991 }
992
993 # Do all nam-related initialization here
994 $self init-nam
995
996 # NIXVECTOR xxx?
997 # global simstart
998 # set simstart [clock seconds]
999 return [$scheduler_ run]
1000 }
1001
1002 # johnh xxx?
1003 Simulator instproc log-simstart { } {
1004 # GFR Modification to log actual start
1005 global simstart
1006 puts "Starting Actual Simulation"
1007 set simstart [clock seconds]
1008 }
1009
1010 Simulator instproc halt {} {
1011 $self instvar scheduler_
1012 #puts "time: [clock format [clock seconds] -format %X]"
1013 $scheduler_ halt
1014 }
1015
1016 Simulator instproc dumpq {} {
1017 $self instvar scheduler_
1018 $scheduler_ dumpq
1019 }
1020
1021 Simulator instproc is-started {} {
1022 $self instvar started_
1023 return [info exists started_]
1024 }
1025
1026 Simulator instproc clearMemTrace {} {
1027 $self instvar scheduler_
1028 $scheduler_ clearMemTrace
1029 }
1030
1031 Simulator instproc simplex-link { n1 n2 bw delay qtype args } {
1032 $self instvar link_ queueMap_ nullAgent_ useasim_
1033 set sid [$n1 id]
1034 set did [$n2 id]
1035
1036 # Debo
1037 if { $useasim_ == 1 } {
1038 set slink_($sid:$did) $self
1039 }
1040
1041 if [info exists queueMap_($qtype)] {
1042 set qtype $queueMap_($qtype)
1043 }
1044 # construct the queue
1045 set qtypeOrig $qtype
1046 switch -exact $qtype {
1047 ErrorModule {
1048 if { [llength $args] > 0 } {
1049 set q [eval new $qtype $args]
1050 } else {
1051 set q [new $qtype Fid]
1052 }
1053 }
1054 intserv {
1055 set qtype [lindex $args 0]
1056 set q [new Queue/$qtype]
1057 }
1058 default {
1059 if { [llength $args] == 0} {
1060 set q [new Queue/$qtype]
1061 } else {
1062 set q [new Queue/$qtype $args]
1063 }
1064 }
1065 }
1066 # Now create the link
1067 switch -exact $qtypeOrig {
1068 RTM {
1069 set c [lindex $args 1]
1070 set link_($sid:$did) [new CBQLink \
1071 $n1 $n2 $bw $delay $q $c]
1072 }
1073 CBQ -
1074 CBQ/WRR {
1075 # assume we have a string of form "linktype linkarg"
1076 if {[llength $args] == 0} {
1077 # default classifier for cbq is just Fid type
1078 set c [new Classifier/Hash/Fid 33]
1079 } else {
1080 set c [lindex $args 0]
1081 }
1082 set link_($sid:$did) [new CBQLink \
1083 $n1 $n2 $bw $delay $q $c]
1084 }
1085 FQ {
1086 set link_($sid:$did) [new FQLink $n1 $n2 $bw $delay $q]
1087 }
1088 intserv {
1089 #XX need to clean this up
1090 set link_($sid:$did) [new IntServLink \
1091 $n1 $n2 $bw $delay $q \
1092 [concat $qtypeOrig $args]]
1093 }
1094 default {
1095 set link_($sid:$did) [new SimpleLink \
1096 $n1 $n2 $bw $delay $q]
1097 }
1098 }
1099 if {$qtype == "RED/Pushback"} {
1100 set pushback 1
1101 } else {
1102 set pushback 0
1103 }
1104 $n1 add-neighbor $n2 $pushback
1105
1106 #XXX yuck
1107 if {[string first "RED" $qtype] != -1 ||
1108 [string first "PI" $qtype] != -1 ||
1109 [string first "Vq" $qtype] != -1 ||
1110 [string first "REM" $qtype] != -1 ||
1111 [string first "GK" $qtype] != -1 ||
1112 [string first "RIO" $qtype] != -1 ||
1113 [string first "XCP" $qtype] != -1} {
1114 $q link [$link_($sid:$did) set link_]
1115 }
1116
1117 set trace [$self get-ns-traceall]
1118 if {$trace != ""} {
1119 $self trace-queue $n1 $n2 $trace
1120 }
1121 set trace [$self get-nam-traceall]
1122 if {$trace != ""} {
1123 $self namtrace-queue $n1 $n2 $trace
1124 }
1125
1126 # Register this simplex link in nam link list. Treat it as
1127 # a duplex link in nam
1128 $self register-nam-linkconfig $link_($sid:$did)
1129 }
1130
1131 #
1132 # This is used by Link::orient to register/update the order in which links
1133 # should created in nam. This is important because different creation order
1134 # may result in different layout.
1135 #
1136 # A poor hack. :( Any better ideas?
1137 #
1138 Simulator instproc register-nam-linkconfig link {
1139 $self instvar linkConfigList_ link_
1140 if [info exists linkConfigList_] {
1141 # Check whether the reverse simplex link is registered,
1142 # if so, don't register this link again.
1143 # We should have a separate object for duplex link.
1144 set i1 [[$link src] id]
1145 set i2 [[$link dst] id]
1146 if [info exists link_($i2:$i1)] {
1147 set pos [lsearch $linkConfigList_ $link_($i2:$i1)]
1148 if {$pos >= 0} {
1149 set a1 [$link_($i2:$i1) get-attribute \
1150 "ORIENTATION"]
1151 set a2 [$link get-attribute "ORIENTATION"]
1152 if {$a1 == "" && $a2 != ""} {
1153 # If this duplex link has not been
1154 # assigned an orientation, do it.
1155 set linkConfigList_ [lreplace \
1156 $linkConfigList_ $pos $pos]
1157 } else {
1158 return
1159 }
1160 }
1161 }
1162 # Remove $link from list if it's already there
1163 set pos [lsearch $linkConfigList_ $link]
1164 if {$pos >= 0} {
1165 set linkConfigList_ \
1166 [lreplace $linkConfigList_ $pos $pos]
1167 }
1168 }
1169 lappend linkConfigList_ $link
1170 }
1171
1172 #
1173 # GT-ITM may occasionally generate duplicate links, so we need this check
1174 # to ensure duplicated links do not appear in nam trace files.
1175 #
1176 Simulator instproc remove-nam-linkconfig {i1 i2} {
1177 $self instvar linkConfigList_ link_
1178 if ![info exists linkConfigList_] {
1179 return
1180 }
1181 set pos [lsearch $linkConfigList_ $link_($i1:$i2)]
1182 if {$pos >= 0} {
1183 set linkConfigList_ [lreplace $linkConfigList_ $pos $pos]
1184 return
1185 }
1186 set pos [lsearch $linkConfigList_ $link_($i2:$i1)]
1187 if {$pos >= 0} {
1188 set linkConfigList_ [lreplace $linkConfigList_ $pos $pos]
1189 }
1190 }
1191
1192 # Armando L. Caro Jr. <acaro@@cis,udel,edu> 10/22/2001
1193 #
1194 # we create a simplex link (NOT duplex) from the core to the interface. we can
1195 # use arbitrary params (bw, delay, etc) since we'll never actually transmit
1196 # data on these links. they are only used for routing (ie, to determine which
1197 # interface a packet should go out from)
1198 #
1199 Simulator instproc multihome-add-interface { core if } {
1200 $self instvar link_
1201 set coreId [$core id]
1202 set ifId [$if id]
1203
1204 # arbitrary values (doesn't matter since link will NEVER be used!)
1205 set bw 1Mb
1206 set delay 100ms
1207 set type DropTail
1208
1209 if [info exists link_($coreId:$ifId)] {
1210 $self remove-nam-linkconfig $coreId $ifId
1211 }
1212 eval $self simplex-link $core $if $bw $delay $type
1213 # Modified by GFR for nix-vector routing
1214 if { [Simulator set nix-routing] } {
1215 # Inform nodes of neighbors
1216 $n1 set-neighbor [$core id]
1217 $n2 set-neighbor [$if id]
1218 }
1219
1220
1221 $core instvar multihome_interfaces_ num_interfaces_
1222 set interface_ {}
1223
1224 # interface node
1225 lappend interface_ $if
1226
1227 # link from interface node to core node
1228 lappend interface_ [$link_($coreId:$ifId) set head_]
1229
1230 lappend multihome_interfaces_ $interface_
1231 }
1232
1233 Simulator instproc duplex-link { n1 n2 bw delay type args } {
1234 $self instvar link_
1235 set i1 [$n1 id]
1236 set i2 [$n2 id]
1237 if [info exists link_($i1:$i2)] {
1238 $self remove-nam-linkconfig $i1 $i2
1239 }
1240 eval $self simplex-link $n1 $n2 $bw $delay $type $args
1241 eval $self simplex-link $n2 $n1 $bw $delay $type $args
1242 # Modified by GFR for nix-vector routing
1243 if { [Simulator set nix-routing] } {
1244 # Inform nodes of neighbors
1245 $n1 set-neighbor [$n2 id]
1246 $n2 set-neighbor [$n1 id]
1247 }
1248 }
1249
1250 Simulator instproc duplex-intserv-link { n1 n2 bw pd sched signal adc args } {
1251 eval $self duplex-link $n1 $n2 $bw $pd intserv $sched $signal $adc $args
1252 }
1253
1254 Simulator instproc simplex-link-op { n1 n2 op args } {
1255 $self instvar link_
1256 eval $link_([$n1 id]:[$n2 id]) $op $args
1257 }
1258
1259 Simulator instproc duplex-link-op { n1 n2 op args } {
1260 $self instvar link_
1261 eval $link_([$n1 id]:[$n2 id]) $op $args
1262 eval $link_([$n2 id]:[$n1 id]) $op $args
1263 }
1264
1265 Simulator instproc flush-trace {} {
1266 $self instvar alltrace_
1267 if [info exists alltrace_] {
1268 foreach trace $alltrace_ {
1269 $trace flush
1270 }
1271 }
1272 }
1273
1274 Simulator instproc namtrace-all file {
1275 $self instvar namtraceAllFile_
1276 if {$file != ""} {
1277 set namtraceAllFile_ $file
1278 } else {
1279 unset namtraceAllFile_
1280 }
1281 }
1282
1283 Simulator instproc energy-color-change {level1 level2} {
1284 $self instvar level1_ level2_
1285 set level1_ $level1
1286 set level2_ $level2
1287 }
1288
1289 Simulator instproc namtrace-all-wireless {file optx opty} {
1290 $self instvar namtraceAllFile_
1291
1292 # indicate that we need a W event written to the trace
1293 $self set namNeedsW_ 1
1294 if { $optx != "" && $opty != "" } {
1295 $self set namWx_ $optx
1296 $self set namWy_ $opty
1297 }
1298
1299 $self namtrace-all $file
1300 }
1301
1302 Simulator instproc nam-end-wireless {stoptime} {
1303 $self instvar namtraceAllFile_
1304
1305 if {$namtraceAllFile_ != ""} {
1306 $self puts-nam-config "W -t $stoptime"
1307 }
1308 }
1309
1310 Simulator instproc namtrace-some file {
1311 $self instvar namtraceSomeFile_
1312 set namtraceSomeFile_ $file
1313 }
1314
1315 # Support for event-tracing
1316
1317 Simulator instproc eventtrace-all {{file ""}} {
1318 $self instvar eventTraceAll_ eventtraceAllFile_ traceAllFile_
1319 set eventTraceAll_ 1
1320 if {$file != ""} {
1321 set eventtraceAllFile_ $file
1322 } else {
1323 set eventtraceAllFile_ $traceAllFile_
1324 }
1325
1326 }
1327
1328
1329
1330 Simulator instproc initial_node_pos {nodep size} {
1331 $self instvar addressType_
1332 $self instvar energyModel_
1333
1334 if [info exists energyModel_] {
1335 set nodeColor "green"
1336 } else {
1337 set nodeColor "black"
1338 }
1339 if { [info exists addressType_] && $addressType_ == "hierarchical" } {
1340 # Hierarchical addressing
1341 $self puts-nam-config "n -t * -a [$nodep set address_] \
1342 -s [$nodep id] -x [$nodep set X_] -y [$nodep set Y_] -Z [$nodep set Z_] \
1343 -z $size -v circle -c $nodeColor"
1344 } else {
1345 # Flat addressing
1346 $self puts-nam-config "n -t * -s [$nodep id] \
1347 -x [$nodep set X_] -y [$nodep set Y_] -Z [$nodep set Z_] -z $size \
1348 -v circle -c $nodeColor"
1349 }
1350 }
1351
1352 Simulator instproc trace-all file {
1353 $self instvar traceAllFile_
1354 set traceAllFile_ $file
1355 }
1356
1357 Simulator instproc get-nam-traceall {} {
1358 $self instvar namtraceAllFile_
1359 if [info exists namtraceAllFile_] {
1360 return $namtraceAllFile_
1361 } else {
1362 return ""
1363 }
1364 }
1365
1366 Simulator instproc get-ns-traceall {} {
1367 $self instvar traceAllFile_
1368 if [info exists traceAllFile_] {
1369 return $traceAllFile_
1370 } else {
1371 return ""
1372 }
1373 }
1374
1375 # If exists a traceAllFile_, print $str to $traceAllFile_
1376 Simulator instproc puts-ns-traceall { str } {
1377 $self instvar traceAllFile_
1378 if [info exists traceAllFile_] {
1379 puts $traceAllFile_ $str
1380 }
1381 }
1382
1383 # If exists a traceAllFile_, print $str to $traceAllFile_
1384 Simulator instproc puts-nam-traceall { str } {
1385 $self instvar namtraceAllFile_
1386 if [info exists namtraceAllFile_] {
1387 puts $namtraceAllFile_ $str
1388 } elseif [info exists namtraceSomeFile_] {
1389 puts $namtraceSomeFile_ $str
1390 }
1391 }
1392
1393 # namConfigFile is used for writing color/link/node/queue/annotations.
1394 # XXX It cannot co-exist with namtraceAll.
1395 Simulator instproc namtrace-config { f } {
1396 $self instvar namConfigFile_
1397 set namConfigFile_ $f
1398 }
1399
1400 Simulator instproc get-nam-config {} {
1401 $self instvar namConfigFile_
1402 if [info exists namConfigFile_] {
1403 return $namConfigFile_
1404 } else {
1405 return ""
1406 }
1407 }
1408
1409 # Used only for writing nam configurations to trace file(s). This is different
1410 # from puts-nam-traceall because we may want to separate configuration
1411 # informations and actual tracing information
1412 Simulator instproc puts-nam-config { str } {
1413 $self instvar namtraceAllFile_ namConfigFile_
1414
1415 if [info exists namConfigFile_] {
1416 puts $namConfigFile_ $str
1417 } elseif [info exists namtraceAllFile_] {
1418 puts $namtraceAllFile_ $str
1419 } elseif [info exists namtraceSomeFile_] {
1420 puts $namtraceSomeFile_ $str
1421 }
1422 }
1423
1424 Simulator instproc color { id name } {
1425 $self instvar color_
1426 set color_($id) $name
1427 }
1428
1429 Simulator instproc get-color { id } {
1430 $self instvar color_
1431 return $color_($id)
1432 }
1433
1434 # you can pass in {} as a null file
1435 Simulator instproc create-trace { type file src dst {op ""} } {
1436 $self instvar alltrace_
1437 set p [new Trace/$type]
1438 $p tagged [Simulator set TaggedTrace_]
1439 if [catch {$p set src_ [$src id]}] {
1440 $p set src_ $src
1441 }
1442 if [catch {$p set dst_ [$dst id]}] {
1443 $p set dst_ $dst
1444 }
1445 lappend alltrace_ $p
1446 if {$file != ""} {
1447 $p ${op}attach $file
1448 }
1449 return $p
1450 }
1451
1452
1453 Simulator instproc create-eventtrace {type owner } {
1454 $self instvar alltrace_
1455 $self instvar eventTraceAll_ eventtraceAllFile_ namtraceAllFile_
1456
1457 if ![info exists eventTraceAll_] return
1458
1459 if { $eventTraceAll_ == 1 } {
1460
1461 set et [new BaseTrace/$type]
1462 $owner cmd eventtrace $et
1463
1464 lappend alltrace_ $et
1465 $et attach $eventtraceAllFile_
1466 if [info exists namtraceAllFile_] {
1467 $et namattach $namtraceAllFile_
1468 }
1469 }
1470 }
1471
1472
1473 Simulator instproc namtrace-queue { n1 n2 {file ""} } {
1474 $self instvar link_ namtraceAllFile_
1475 if {$file == ""} {
1476 if ![info exists namtraceAllFile_] return
1477 set file $namtraceAllFile_
1478 }
1479 $link_([$n1 id]:[$n2 id]) nam-trace $self $file
1480
1481 # Added later for queue specific tracing events other than enque,
1482 # deque and drop as of now nam does not understand special events.
1483 # Changes will have to be made to nam for it to understand events
1484 # like early drops if they are prefixed differently than "d". - ratul
1485 set queue [$link_([$n1 id]:[$n2 id]) queue]
1486 $queue attach-nam-traces $n1 $n2 $file
1487 }
1488
1489 Simulator instproc trace-queue { n1 n2 {file ""} } {
1490 $self instvar link_ traceAllFile_
1491 if {$file == ""} {
1492 if ![info exists traceAllFile_] return
1493 set file $traceAllFile_
1494 }
1495 $link_([$n1 id]:[$n2 id]) trace $self $file
1496
1497 # Added later for queue specific tracing events other than enque,
1498 # deque and drop - ratul
1499 set queue [$link_([$n1 id]:[$n2 id]) queue]
1500 $queue attach-traces $n1 $n2 $file
1501 }
1502
1503 #
1504 # arrange for queue length of link between nodes n1 and n2
1505 # to be tracked and return object that can be queried
1506 # to learn average q size etc. XXX this API still rough
1507 #
1508 Simulator instproc monitor-queue { n1 n2 qtrace { sampleInterval 0.1 } } {
1509 $self instvar link_
1510 return [$link_([$n1 id]:[$n2 id]) init-monitor $self $qtrace $sampleInterval]
1511 }
1512
1513 Simulator instproc queue-limit { n1 n2 limit } {
1514 $self instvar link_
1515 [$link_([$n1 id]:[$n2 id]) queue] set limit_ $limit
1516 if {[[$link_([$n1 id]:[$n2 id]) queue] info class] == "Queue/XCP"} {
1517 [$link_([$n1 id]:[$n2 id]) queue] queue-limit $limit
1518 }
1519 }
1520
1521 Simulator instproc drop-trace { n1 n2 trace } {
1522 $self instvar link_
1523 [$link_([$n1 id]:[$n2 id]) queue] drop-target $trace
1524 }
1525
1526 Simulator instproc cost {n1 n2 c} {
1527 $self instvar link_
1528 $link_([$n1 id]:[$n2 id]) cost $c
1529 }
1530
1531 # Armando L. Caro Jr. <acaro@@cis,udel,edu> 10/22/2001
1532 Simulator instproc multihome-attach-agent { core agent } {
1533 $agent set-multihome-core [$core entry]
1534
1535 foreach interface [$core set multihome_interfaces_] {
1536 set ifNode [lindex $interface 0]
1537 set coreLink [lindex $interface 1]
1538
1539 # attach agent to the node for each interface
1540 $ifNode attach $agent
1541 set addr [$agent set agent_addr_]
1542 set port [$agent set agent_port_]
1543 set entry [$ifNode entry]
1544
1545 # give the interface info to the agent
1546 $agent add-multihome-interface $addr $port $entry $coreLink
1547
1548 $agent instvar multihome_bindings_
1549 set binding_ {}
1550 lappend binding_ $addr
1551 lappend binding_ $port
1552 lappend multihome_bindings_ $binding_
1553 }
1554 }
1555
1556 Simulator instproc attach-agent { node agent } {
1557 $node attach $agent
1558 # $agent set nodeid_ [$node id]
1559
1560 # Armando L. Caro Jr. <acaro@@cis,udel,edu> 10/22/2001
1561 #
1562 # list of tuples (addr, port)
1563 # This is NEEDED so that single homed agents can play with multihomed
1564 # ones!
1565 # multihoming only for SCTP agents -Padma H.
1566 if {[lindex [split [$agent info class] "/"] 1] == "SCTP"} {
1567 $agent instvar multihome_bindings_
1568 set binding_ {}
1569 set addr [$agent set agent_addr_]
1570 set port [$agent set agent_port_]
1571 lappend binding_ $addr
1572 lappend binding_ $port
1573 lappend multihome_bindings_ $binding_
1574 }
1575 }
1576
1577 Simulator instproc attach-tbf-agent { node agent tbf } {
1578 $node attach $agent
1579 $agent attach-tbf $tbf
1580 }
1581
1582
1583 Simulator instproc detach-agent { node agent } {
1584
1585 # Debo added this
1586 $self instvar conn_ nconn_ sflows_ nsflows_ useasim_
1587
1588 if {$useasim_ == 1} {
1589 set list ""
1590 set s [$node id]
1591 set d [[$self get-node-by-addr [$agent set dst_addr_]] id]
1592 foreach x $conn_ {
1593 set t [split $x ":"]
1594 if {[string compare [lindex $t 0]:[lindex $t 1] $s:$d] != 0} {
1595 lappend list_ $x
1596 }
1597 }
1598 set conn_ list
1599 set nconn_ [expr $nconn_ -1]
1600 # ---------------------------------------
1601 }
1602
1603 $self instvar nullAgent_
1604 $node detach $agent $nullAgent_
1605 }
1606
1607 #
1608 # Helper proc for setting delay on an existing link
1609 #
1610 Simulator instproc delay { n1 n2 delay {type simplex} } {
1611 $self instvar link_
1612 set sid [$n1 id]
1613 set did [$n2 id]
1614 if [info exists link_($sid:$did)] {
1615 set d [$link_($sid:$did) link]
1616 $d set delay_ $delay
1617 }
1618 if {$type == "duplex"} {
1619 if [info exists link_($did:$sid)] {
1620 set d [$link_($did:$sid) link]
1621 $d set delay_ $delay
1622 }
1623 }
1624 }
1625
1626 #
1627 # Helper proc for setting bandwidth on an existing link
1628 #
1629 Simulator instproc bandwidth { n1 n2 bandwidth {type simplex} } {
1630 $self instvar link_
1631 set sid [$n1 id]
1632 set did [$n2 id]
1633 if [info exists link_($sid:$did)] {
1634 set d [$link_($sid:$did) link]
1635 $d set bandwidth_ $bandwidth
1636 }
1637 if {$type == "duplex"} {
1638 if [info exists link_($did:$sid)] {
1639 set d [$link_($did:$sid) link]
1640 $d set bandwidth_ $bandwidth
1641 }
1642 }
1643 }
1644
1645
1646 #XXX need to check that agents are attached to nodes already
1647 Simulator instproc connect {src dst} {
1648
1649 $self instvar conn_ nconn_ sflows_ nsflows_ useasim_
1650
1651 # Armando L. Caro Jr. <acaro@@cis,udel,edu>
1652 # does the agent type support multihoming??
1653 # @@@ do we need to worry about $useasim_ below?? (wasn't in 2.1b8)
1654 if {[lindex [split [$src info class] "/"] 1] == "SCTP"} {
1655 $self multihome-connect $src $dst
1656 }
1657
1658 $self simplex-connect $src $dst
1659 $self simplex-connect $dst $src
1660
1661
1662 # Debo
1663
1664 if {$useasim_ == 1} {
1665 set sid [$src nodeid]
1666 set sport [$src set agent_port_]
1667 set did [$dst nodeid]
1668 set dport [$dst set agent_port_]
1669
1670 if {[lindex [split [$src info class] "/"] 1] == "TCP"} {
1671 lappend conn_ $sid:$did:$sport:$dport
1672 incr nconn_
1673 # set $nconn_ [expr $nconn_ + 1]
1674 # puts "Set a connection with id $nconn_ between $sid and $did"
1675 }
1676 }
1677
1678 return $src
1679 }
1680
1681 # Armando L. Caro Jr. <acaro@@cis,udel,edu> 10/12/2001
1682 Simulator instproc multihome-connect {src dst} {
1683
1684 set destNum 0
1685 foreach binding [$src set multihome_bindings_] {
1686 incr destNum
1687 set addr [lindex $binding 0]
1688 set port [lindex $binding 1]
1689 $dst add-multihome-destination $addr $port
1690 }
1691 if {$destNum == 0} {
1692 # src isn't multihomed, so make sure we do an
1693 # add-multihome-destination
1694 $dst add-multihome-destination \
1695 [$src set agent_addr_] [$src set agent_port_]
1696 }
1697
1698 set destNum 0
1699 foreach binding [$dst set multihome_bindings_] {
1700 incr destNum
1701 set addr [lindex $binding 0]
1702 set port [lindex $binding 1]
1703 $src add-multihome-destination $addr $port
1704 }
1705 if {$destNum == 0} {
1706 # dst isn't multihomed, so make sure we do an
1707 # add-multihome-destination
1708 $src add-multihome-destination \
1709 [$dst set agent_addr_] [$dst set agent_port_]
1710 }
1711 }
1712
1713 Simulator instproc simplex-connect { src dst } {
1714 $src set dst_addr_ [$dst set agent_addr_]
1715 $src set dst_port_ [$dst set agent_port_]
1716
1717
1718 # Polly Huang: to support abstract TCP simulations
1719 if {[lindex [split [$src info class] "/"] 1] == "AbsTCP"} {
1720 $self at [$self now] "$self rtt $src $dst"
1721 $dst set class_ [$src set class_]
1722 }
1723
1724 return $src
1725 }
1726
1727 #
1728 # Here are a bunch of helper methods.
1729 #
1730
1731 Simulator proc instance {} {
1732 set ns [Simulator info instances]
1733 if { $ns != "" } {
1734 return $ns
1735 }
1736 foreach sim [Simulator info subclass] {
1737 set ns [$sim info instances]
1738 if { $ns != "" } {
1739 return $ns
1740 }
1741 }
1742 error "Cannot find instance of simulator"
1743 }
1744
1745 Simulator instproc get-number-of-nodes {} {
1746 return [$self array size Node_]
1747 }
1748
1749 Simulator instproc get-node-by-id id {
1750 $self instvar Node_
1751 return $Node_($id)
1752 }
1753
1754 # Given an node's address, Return the node-id
1755 Simulator instproc get-node-id-by-addr address {
1756 $self instvar Node_
1757 set n [Node set nn_]
1758 for {set q 0} {$q < $n} {incr q} {
1759 set nq $Node_($q)
1760 if {[string compare [$nq node-addr] $address] == 0} {
1761 return $q
1762 }
1763 }
1764 error "get-node-id-by-addr:Cannot find node with given address"
1765 }
1766
1767 # Given an node's address, return the node
1768 Simulator instproc get-node-by-addr address {
1769 return [$self get-node-by-id [$self get-node-id-by-addr $address]]
1770 }
1771
1772 Simulator instproc all-nodes-list {} {
1773 $self instvar Node_
1774 set nodes ""
1775 foreach n [lsort -dictionary [array names Node_]] {
1776 lappend nodes $Node_($n)
1777 }
1778 return $nodes
1779 }
1780
1781 Simulator instproc link { n1 n2 } {
1782 $self instvar Node_ link_
1783 if { ![catch "$n1 info class Node"] } {
1784 set n1 [$n1 id]
1785 }
1786 if { ![catch "$n2 info class Node"] } {
1787 set n2 [$n2 id]
1788 }
1789 if [info exists link_($n1:$n2)] {
1790 return $link_($n1:$n2)
1791 }
1792 return ""
1793 }
1794
1795 # Creates connection. First creates a source agent of type s_type and binds
1796 # it to source. Next creates a destination agent of type d_type and binds
1797 # it to dest. Finally creates bindings for the source and destination agents,
1798 # connects them, and returns the source agent.
1799 Simulator instproc create-connection {s_type source d_type dest pktClass} {
1800 set s_agent [new Agent/$s_type]
1801 set d_agent [new Agent/$d_type]
1802 $s_agent set fid_ $pktClass
1803 $d_agent set fid_ $pktClass
1804 $self attach-agent $source $s_agent
1805 $self attach-agent $dest $d_agent
1806 $self connect $s_agent $d_agent
1807
1808 return $s_agent
1809 }
1810
1811 # Creates a highspeed connection. Similar to create-connection
1812 # above except the sink agent requires additional work -- Sylvia
1813 Simulator instproc create-highspeed-connection {s_type source d_type dest pktClass} {
1814 set s_agent [new Agent/$s_type]
1815 set d_agent [new Agent/$d_type]
1816 $d_agent resize_buffers
1817 $s_agent set fid_ $pktClass
1818 $d_agent set fid_ $pktClass
1819 $self attach-agent $source $s_agent
1820 $self attach-agent $dest $d_agent
1821 $self connect $s_agent $d_agent
1822
1823 return $s_agent
1824 }
1825
1826 # Creates connection. First creates a source agent of type s_type and binds
1827 # it to source. Next creates a destination agent of type d_type and binds
1828 # it to dest. Finally creates bindings for the source and destination agents,
1829 # connects them, and returns a list of source agent and destination agent.
1830 Simulator instproc create-connection-list {s_type source d_type dest pktClass} {
1831 set s_agent [new Agent/$s_type]
1832 set d_agent [new Agent/$d_type]
1833 $s_agent set fid_ $pktClass
1834 $d_agent set fid_ $pktClass
1835 $self attach-agent $source $s_agent
1836 $self attach-agent $dest $d_agent
1837 $self connect $s_agent $d_agent
1838
1839 return [list $s_agent $d_agent]
1840 }
1841
1842 # Creates connection. First creates a source agent of type s_type and binds
1843 # it to source. Next creates a destination agent of type d_type and binds
1844 # it to dest. Finally creates bindings for the source and destination agents,
1845 # connects them, and returns the source agent.
1846 # The destination agent is set to listen, for full-tcp.
1847 Simulator instproc create-connection-listen {s_type source d_type dest pktClass} {
1848 set s_agent [new Agent/$s_type]
1849 set d_agent [new Agent/$d_type]
1850 $s_agent set fid_ $pktClass
1851 $d_agent set fid_ $pktClass
1852 $self attach-agent $source $s_agent
1853 $self attach-agent $dest $d_agent
1854 $self connect $s_agent $d_agent
1855 $d_agent listen
1856
1857 return $s_agent
1858 }
1859
1860 # This seems to be an obsolete procedure.
1861 Simulator instproc create-tcp-connection {s_type source d_type dest pktClass} {
1862 set s_agent [new Agent/$s_type]
1863 set d_agent [new Agent/$d_type]
1864 $s_agent set fid_ $pktClass
1865 $d_agent set fid_ $pktClass
1866 $self attach-agent $source $s_agent
1867 $self attach-agent $dest $d_agent
1868 return "$s_agent $d_agent"
1869 }
1870
1871 #
1872 # Other classifier methods overload the instproc-likes to track
1873 # and return the installed objects.
1874 #
1875 Classifier instproc install {slot val} {
1876 $self set slots_($slot) $val
1877 $self cmd install $slot $val
1878 }
1879
1880 Classifier instproc installNext val {
1881 set slot [$self cmd installNext $val]
1882 $self set slots_($slot) $val
1883 set slot
1884 }
1885
1886 Classifier instproc adjacents {} {
1887 $self array get slots_
1888 }
1889
1890 Classifier instproc in-slot? slot {
1891 $self instvar slots_
1892 set ret ""
1893 if {[info exists slots_($slot)]} {
1894 set ret $slots_($slot)
1895 }
1896 set ret
1897 }
1898
1899 # For debugging
1900 Classifier instproc dump {} {
1901 $self instvar slots_ offset_ shift_ mask_
1902 puts "classifier $self"
1903 puts "\t$offset_ offset"
1904 puts "\t$shift_ shift"
1905 puts "\t$mask_ mask"
1906 puts "\t[array size slots_] slots"
1907 foreach i [lsort -integer [array names slots_]] {
1908 set iv $slots_($i)
1909 puts "\t\tslot $i: $iv ([$iv info class])"
1910 }
1911 }
1912
1913 Classifier instproc no-slot slot {
1914 puts stderr "--- Classfier::no-slot{} default handler (tcl/lib/ns-lib.tcl) ---"
1915 puts stderr "\t$self: no target for slot $slot"
1916 puts stderr "\t$self type: [$self info class]"
1917 puts stderr "content dump:"
1918 $self dump
1919 puts stderr "---------- Finished standard no-slot{} default handler ----------"
1920 # Clear output before we bail out
1921 [Simulator instance] flush-trace
1922 exit 1
1923 }
1924
1925 Classifier/Hash instproc dump args {
1926 eval $self next $args
1927 $self instvar default_
1928 puts "\t$default_ default"
1929 }
1930
1931 Classifier/Hash instproc init nbuck {
1932 # We need to make sure that port shift/mask values are there
1933 # so we set them after they get their default values
1934 $self next $nbuck
1935 $self instvar shift_ mask_
1936 set shift_ [AddrParams NodeShift 1]
1937 set mask_ [AddrParams NodeMask 1]
1938 }
1939
1940 Classifier/Port/Reserve instproc init args {
1941 eval $self next
1942 $self reserve-port 2
1943 }
1944
1945 Simulator instproc makeflowmon { cltype { clslots 29 } } {
1946 set flowmon [new QueueMonitor/ED/Flowmon]
1947 set cl [new Classifier/Hash/$cltype $clslots]
1948
1949 $cl proc unknown-flow { src dst fid } {
1950 set fdesc [new QueueMonitor/ED/Flow]
1951 set dsamp [new Samples]
1952 $fdesc set-delay-samples $dsamp
1953 set slot [$self installNext $fdesc]
1954 $self set-hash auto $src $dst $fid $slot
1955 }
1956
1957 $cl proc no-slot slotnum {
1958 #
1959 # note: we can wind up here when a packet passes
1960 # through either an Out or a Drop Snoop Queue for
1961 # a queue that the flow doesn't belong to anymore.
1962 # Since there is no longer hash state in the
1963 # hash classifier, we get a -1 return value for the
1964 # hash classifier's classify() function, and there
1965 # is no node at slot_[-1]. What to do about this?
1966 # Well, we are talking about flows that have already
1967 # been moved and so should rightly have their stats
1968 # zero'd anyhow, so for now just ignore this case..
1969 # puts "classifier $self, no-slot for slotnum $slotnum"
1970 }
1971 $flowmon classifier $cl
1972 return $flowmon
1973 }
1974
1975 # attach a flow monitor to a link
1976 # 3rd argument dictates whether early drop support is to be used
1977
1978 Simulator instproc attach-fmon {lnk fm { edrop 0 } } {
1979 set isnoop [new SnoopQueue/In]
1980 set osnoop [new SnoopQueue/Out]
1981 set dsnoop [new SnoopQueue/Drop]
1982 $lnk attach-monitors $isnoop $osnoop $dsnoop $fm
1983 if { $edrop != 0 } {
1984 set edsnoop [new SnoopQueue/EDrop]
1985 $edsnoop set-monitor $fm
1986 [$lnk queue] early-drop-target $edsnoop
1987 $edsnoop target [$self set nullAgent_]
1988 }
1989 [$lnk queue] drop-target $dsnoop
1990 }
1991
1992 # Added by Yun Wang
1993
1994 Simulator instproc maketbtagger { cltype { clslots 29 } } {
1995
1996 set tagger [new QueueMonitor/ED/Tagger]
1997 set cl [new Classifier/Hash/$cltype $clslots]
1998
1999 $cl proc unknown-flow { src dst fid } {
2000 set fdesc [new QueueMonitor/ED/Flow/TB]
2001 set dsamp [new Samples]
2002 $fdesc set-delay-samples $dsamp
2003 set slot [$self installNext $fdesc]
2004 $self set-hash auto $src $dst $fid $slot
2005 }
2006
2007 $cl proc set-rate { src dst fid hashbucket rate depth init} {
2008 set fdesc [new QueueMonitor/ED/Flow/TB]
2009 set dsamp [new Samples]
2010 $fdesc set-delay-samples $dsamp
2011 $fdesc set target_rate_ $rate
2012 $fdesc set bucket_depth_ $depth
2013 # Initialize the bucket as full
2014 $fdesc set tbucket_ $init
2015 set slot [$self installNext $fdesc]
2016 $self set-hash $hashbucket $src $dst $fid $slot
2017 }
2018
2019 $cl proc no-slot slotnum {
2020 #
2021 # note: we can wind up here when a packet passes
2022 # through either an Out or a Drop Snoop Queue for
2023 # a queue that the flow doesn't belong to anymore.
2024 # Since there is no longer hash state in the
2025 # hash classifier, we get a -1 return value for the
2026 # hash classifier's classify() function, and there
2027 # is no node at slot_[-1]. What to do about this?
2028 # Well, we are talking about flows that have already
2029 # been moved and so should rightly have their stats
2030 # zero'd anyhow, so for now just ignore this case..
2031 # puts "classifier $self, no-slot for slotnum $slotnum"
2032 }
2033 $tagger classifier $cl
2034 return $tagger
2035 }
2036
2037 # Added by Yun Wang
2038
2039 Simulator instproc maketswtagger { cltype { clslots 29 } } {
2040
2041 set tagger [new QueueMonitor/ED/Tagger]
2042 set cl [new Classifier/Hash/$cltype $clslots]
2043
2044 $cl proc unknown-flow { src dst fid hashbucket } {
2045 set fdesc [new QueueMonitor/ED/Flow/TSW]
2046 set dsamp [new Samples]
2047 $fdesc set-delay-samples $dsamp
2048 set slot [$self installNext $fdesc]
2049 $self set-hash $hashbucket $src $dst $fid $slot
2050 }
2051
2052 $cl proc no-slot slotnum {
2053 #
2054 # note: we can wind up here when a packet passes
2055 # through either an Out or a Drop Snoop Queue for
2056 # a queue that the flow doesn't belong to anymore.
2057 # Since there is no longer hash state in the
2058 # hash classifier, we get a -1 return value for the
2059 # hash classifier's classify() function, and there
2060 # is no node at slot_[-1]. What to do about this?
2061 # Well, we are talking about flows that have already
2062 # been moved and so should rightly have their stats
2063 # zero'd anyhow, so for now just ignore this case..
2064 # puts "classifier $self, no-slot for slotnum $slotnum"
2065 }
2066 $tagger classifier $cl
2067 return $tagger
2068 }
2069
2070 # attach a Tagger to a link
2071 # Added by Yun Wang
2072
2073 Simulator instproc attach-tagger {lnk fm} {
2074 set isnoop [new SnoopQueue/Tagger]
2075 $lnk attach-taggers $isnoop $fm
2076 }
2077
2078 # Imported from session.tcl. It is deleted there.
2079 ### to insert loss module to regular links in detailed Simulator
2080 Simulator instproc lossmodel {lossobj from to} {
2081 set link [$self link $from $to]
2082 $link errormodule $lossobj
2083 }
2084
2085 # This function generates losses that can be visualized by nam.
2086 Simulator instproc link-lossmodel {lossobj from to} {
2087 set link [$self link $from $to]
2088 $link insert-linkloss $lossobj
2089 }
2090
2091
2092 #### Polly Huang: Simulator class instproc to support abstract tcp simulations
2093
2094 Simulator instproc rtt { src dst } {
2095 $self instvar routingTable_ delay_
2096 set srcid [[$src set node_] id]
2097 set dstid [[$dst set node_] id]
2098 set delay 0
2099 set tmpid $srcid
2100 while {$tmpid != $dstid} {
2101 set nextid [$routingTable_ lookup $tmpid $dstid]
2102 set tmpnode [$self get-node-by-id $tmpid]
2103 set nextnode [$self get-node-by-id $nextid]
2104 set tmplink [[$self link $tmpnode $nextnode] link]
2105 set delay [expr $delay + [expr 2 * [$tmplink set delay_]]]
2106 set delay [expr $delay + [expr 8320 / [$tmplink set bandwidth_]]]
2107 set tmpid $nextid
2108 }
2109 $src rtt $delay
2110 return $delay
2111 }
2112
2113 Simulator instproc abstract-tcp {} {
2114 $self instvar TahoeAckfsm_ RenoAckfsm_ TahoeDelAckfsm_ RenoDelAckfsm_ dropper_
2115 $self set TahoeAckfsm_ [new FSM/TahoeAck]
2116 $self set RenoAckfsm_ [new FSM/RenoAck]
2117 $self set TahoeDelAckfsm_ [new FSM/TahoeDelAck]
2118 $self set RenoDelAckfsm_ [new FSM/RenoDelAck]
2119 $self set nullAgent_ [new DropTargetAgent]
2120 }
2121
2122 # Chalermek: For Diffusion, Flooding, and Omnicient Multicast
2123
2124 Simulator instproc create-diffusion-rate-agent {node} {
2125 global opt
2126 set diff [new Agent/Diffusion/RateGradient]
2127
2128 $node set diffagent_ $diff
2129 $node set ragent_ $diff
2130
2131 $diff on-node $node
2132
2133 if [info exist opt(enablePos)] {
2134 if {$opt(enablePos) == "true"} {
2135 $diff enable-pos
2136 } else {
2137 $diff disable-pos
2138 }
2139 }
2140
2141 if [info exist opt(enableNeg)] {
2142 if {$opt(enableNeg) == "true"} {
2143 $diff enable-neg
2144 } else {
2145 $diff disable-neg
2146 }
2147 }
2148
2149 if [info exist opt(suppression)] {
2150 if {$opt(suppression) == "true"} {
2151 $diff enable-suppression
2152 } else {
2153 $diff disable-suppression
2154 }
2155 }
2156
2157 if [info exist opt(subTxType)] {
2158 $diff set-sub-tx-type $opt(subTxType)
2159 }
2160
2161 if [info exist opt(orgTxType)] {
2162 $diff set-org-tx-type $opt(orgTxType)
2163 }
2164
2165 if [info exist opt(posType)] {
2166 $diff set-pos-type $opt(posType)
2167 }
2168
2169 if [info exist opt(posNodeType)] {
2170 $diff set-pos-node-type $opt(posNodeType)
2171 }
2172
2173 if [info exist opt(negWinType)] {
2174 $diff set-neg-win-type $opt(negWinType)
2175 }
2176
2177 if [info exist opt(negThrType)] {
2178 $diff set-neg-thr-type $opt(negThrType)
2179 }
2180
2181 if [info exist opt(negMaxType)] {
2182 $diff set-neg-max-type $opt(negMaxType)
2183 }
2184
2185 $self put-in-list $diff
2186 $self at 0.0 "$diff start"
2187
2188 return $diff
2189 }
2190
2191 Simulator instproc create-diffusion-probability-agent {node} {
2192 global opt
2193 set diff [new Agent/Diffusion/ProbGradient]
2194
2195 $node set diffagent_ $diff
2196 $node set ragent_ $diff
2197
2198 $diff on-node $node
2199
2200 if [info exist opt(enablePos)] {
2201 if {$opt(enablePos) == "true"} {
2202 $diff enable-pos
2203 } else {
2204 $diff disable-pos
2205 }
2206 }
2207 if [info exist opt(enableNeg)] {
2208 if {$opt(enableNeg) == "true"} {
2209 $diff enable-neg
2210 } else {
2211 $diff disable-neg
2212 }
2213 }
2214
2215 $self put-in-list $diff
2216 $self at 0.0 "$diff start"
2217
2218 return $diff
2219 }
2220
2221 # Diffusioncore agent (in diffusion) maps to the wireless routing agent
2222 # in ns
2223 Simulator instproc create-core-diffusion-rtg-agent {node} {
2224 $self instvar stopTime_ diffFilter_
2225 Node instvar ragent_ dmux_
2226 set ragent [new Agent/DiffusionRouting [$node id]]
2227 $node set ragent_ $ragent
2228 # at stop-time core-diffusion dumps stats data
2229 # see diffusion.cc for details
2230 if { [info exists stopTime_] } {
2231 $ragent stop-time $stopTime_
2232 }
2233 if { ![info exists diffFilter_] } {
2234 puts stderr "Error: No filter defined for diffusion!\n"
2235 exit 1
2236 }
2237 $node create-diffusionApp-agent $diffFilter_
2238 return $ragent
2239 }
2240
2241 Simulator instproc create-flooding-agent {node} {
2242 set flood [new Agent/Flooding]
2243
2244 $node set ragent_ $flood
2245
2246 $flood on-node $node
2247
2248 $self put-in-list $flood
2249 $self at 0.0 "$flood start"
2250
2251 return $flood
2252 }
2253
2254 Simulator instproc create-omnimcast-agent {node} {
2255 set omni [new Agent/OmniMcast]
2256
2257 $node set ragent_ $omni
2258
2259 $omni on-node $node
2260
2261 $self put-in-list $omni
2262 $self at 0.0 "$omni start"
2263
2264 return $omni
2265 }
2266
2267 # XXX These are very simulation-specific methods, why should they belong here?
2268 Simulator instproc put-in-list {agent} {
2269 $self instvar lagent
2270 lappend lagent $agent
2271 }
2272
2273 Simulator instproc terminate-all-agents {} {
2274 $self instvar lagent
2275 foreach i $lagent {
2276 $i terminate
2277 }
2278 }
2279
2280 Simulator instproc prepare-to-stop {} {
2281 $self instvar lagent
2282 foreach i $lagent {
2283 $i stop
2284 }
2285 }
2286