Debian Codegraph @

protolib/src/sim/ns/ns233/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: /srv/svn/cvs/protolib/protolib/ns/ns233/ns-lib.tcl,v 1.1 2008-07-07 17:38:46 dean 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 switch -exact $routingAgent_ {
624 DSDV {
625 set ragent [$self create-dsdv-agent $node]
626 }
627 DSR {
628 $self at 0.0 "$node start-dsr"
629 }
630 AODV {
631 set ragent [$self create-aodv-agent $node]
632 }
633 TORA {
634 Simulator set IMEPFlag_ ON
635 set ragent [$self create-tora-agent $node]
636 }
637 ProtolibMK {
638 set ragent [$self create-protolibmk-agent $node]
639 }
640 DIFFUSION/RATE {
641 eval $node addr $args
642 set ragent [$self create-diffusion-rate-agent $node]
643 }
644 DIFFUSION/PROB {
645 eval $node addr $args
646 set ragent [$self create-diffusion-probability-agent $node]
647 }
648 Directed_Diffusion {
649 eval $node addr $args
650 set ragent [$self create-core-diffusion-rtg-agent $node]
651 }
652 FLOODING {
653 eval $node addr $args
654 set ragent [$self create-flooding-agent $node]
655 }
656 OMNIMCAST {
657 eval $node addr $args
658 set ragent [$self create-omnimcast-agent $node]
659 }
660 DumbAgent {
661 set ragent [$self create-dumb-agent $node]
662 }
663 ManualRtg {
664 set ragent [$self create-manual-rtg-agent $node]
665 }
666 default {
667 eval $node addr $args
668 puts "Wrong node routing agent!"
669 exit
670 }
671 }
672 }
673
674 # errProc_ and FECProc_ are an option unlike other
675 # parameters for node interface
676 if ![info exist inerrProc_] {
677 set inerrProc_ ""
678 }
679 if ![info exist outerrProc_] {
680 set outerrProc_ ""
681 }
682 if ![info exist FECProc_] {
683 set FECProc_ ""
684 }
685
686
687
688 # Add main node interface
689 $node add-interface $chan $propInstance_ $llType_ $macType_ \
690 $ifqType_ $ifqlen_ $phyType_ $antType_ $topoInstance_ \
691 $inerrProc_ $outerrProc_ $FECProc_
692 # Attach agent
693 if {$routingAgent_ != "DSR"} {
694 $node attach $ragent [Node set rtagent_port_]
695 }
696 if {$routingAgent_ == "DIFFUSION/RATE" ||
697 $routingAgent_ == "DIFFUSION/PROB" ||
698 $routingAgent_ == "FLOODING" ||
699 $routingAgent_ == "OMNIMCAST" ||
700 $routingAgent_ == "Directed_Diffusion" } {
701 $ragent port-dmux [$node demux]
702 $node instvar ll_
703 $ragent add-ll $ll_(0)
704 }
705 if { $routingAgent_ == "DumbAgent" } {
706 $ragent port-dmux [$node demux]
707 }
708
709
710 # Bind routing agent and mip agent if existing basestation
711 # address setting
712 if { [info exist wiredRouting_] && $wiredRouting_ == "ON" } {
713 if { $routingAgent_ != "DSR" } {
714 $node mip-call $ragent
715 }
716 }
717 #
718 # This Trace Target is used to log changes in direction
719 # and velocity for the mobile node.
720 #
721 set tracefd [$self get-ns-traceall]
722 if {$tracefd != "" } {
723 $node nodetrace $tracefd
724 $node agenttrace $tracefd
725 }
726 set namtracefd [$self get-nam-traceall]
727 if {$namtracefd != "" } {
728 $node namattach $namtracefd
729 }
730 if [info exists energyModel_] {
731 if [info exists level1_] {
732 set l1 $level1_
733 } else {
734 set l1 0.5
735 }
736 if [info exists level2_] {
737 set l2 $level2_
738 } else {
739 set l2 0.2
740 }
741 $node addenergymodel [new $energyModel_ $node \
742 $initialEnergy_ $l1 $l2]
743 }
744 if [info exists txPower_] {
745 $node setPt $txPower_
746 }
747 if [info exists rxPower_] {
748 $node setPr $rxPower_
749 }
750 if [info exists idlePower_] {
751 $node setPidle $idlePower_
752 }
753 #
754 if [info exists sleepPower_] {
755 $node setPsleep $sleepPower_
756 }
757 if [info exists sleepTime_] {
758 $node setTSleep $sleepTime_
759 }
760 if [info exists transitionPower_] {
761 $node setPtransition $transitionPower_
762 }
763 if [info exists transitionTime_] {
764 $node setTtransition $transitionTime_
765 }
766 #
767 $node topography $topoInstance_
768
769 return $node
770 }
771
772 Simulator instproc create-node-instance args {
773 $self instvar routingAgent_
774 # DSR is a special case
775 if {$routingAgent_ == "DSR"} {
776 set nodeclass [$self set-dsr-nodetype]
777 } else {
778 set nodeclass Node/MobileNode
779 }
780 return [eval new $nodeclass $args]
781 }
782
783 Simulator instproc set-dsr-nodetype {} {
784 $self instvar wiredRouting_
785 set nodetype SRNodeNew
786 # MIP mobilenode
787 if [Simulator set mobile_ip_] {
788 set nodetype SRNodeNew/MIPMH
789 }
790 # basestation dsr node
791 if { [info exists wiredRouting_] && $wiredRouting_ == "ON"} {
792 set nodetype Node/MobileNode/BaseStationNode
793 }
794 return $nodetype
795 }
796
797 Simulator instproc create-tora-agent { node } {
798 set ragent [new Agent/TORA [$node id]]
799 $node set ragent_ $ragent
800 return $ragent
801 }
802
803 Simulator instproc create-dsdv-agent { node } {
804 # Create a dsdv routing agent for this node
805 set ragent [new Agent/DSDV]
806 # Setup address (supports hier-addr) for dsdv agent
807 # and mobilenode
808 set addr [$node node-addr]
809 $ragent addr $addr
810 $ragent node $node
811 if [Simulator set mobile_ip_] {
812 $ragent port-dmux [$node demux]
813 }
814 $node addr $addr
815 $node set ragent_ $ragent
816 $self at 0.0 "$ragent start-dsdv" ;# start updates
817 return $ragent
818 }
819
820 Simulator instproc create-protolibmk-agent { node } {
821 # create a dummie wireless agent
822 # it will foward packets up to protolib manet
823 # and just act as a wedge into ns
824 # used by protolib wireless manets
825 set ragent [new Agent/ProtolibMK [$node node-addr]]
826 $node set ragent_ $ragent
827 return $ragent
828 }
829
830 Simulator instproc create-dumb-agent { node } {
831
832 # create a simple wireless agent
833 # that only forwards packets
834 # used for testing single hop brdcast/unicast mode
835 # for wireless macs
836
837 set ragent [new Agent/DumbAgent]
838 $node set ragent_ $ragent
839
840 return $ragent
841 }
842
843 Simulator instproc create-manual-rtg-agent { node } {
844
845 # create a simple wireless agent
846 # that only forwards packets
847 # used for testing single hop brdcast/unicast mode
848 # for wireless macs
849
850 set ragent [new Agent/ManualRtgAgent]
851 $node set ragent_ $ragent
852 $node attach $ragent [Node set rtagent_port_]
853
854 return $ragent
855 }
856
857 Simulator instproc create-aodv-agent { node } {
858 # Create AODV routing agent
859 set ragent [new Agent/AODV [$node node-addr]]
860 $self at 0.0 "$ragent start" ;# start BEACON/HELLO Messages
861 $node set ragent_ $ragent
862 return $ragent
863 }
864
865 Simulator instproc use-newtrace {} {
866 Simulator set WirelessNewTrace_ 1
867 }
868
869 Simulator instproc use-taggedtrace { {tag ON} } {
870 Simulator set TaggedTrace_ $tag
871 }
872
873 Simulator instproc hier-node haddr {
874 error "hier-nodes should be created with [$ns_ node $haddr]"
875 }
876
877 Simulator instproc now {} {
878 $self instvar scheduler_
879 return [$scheduler_ now]
880 }
881
882 Simulator instproc at args {
883 $self instvar scheduler_
884 return [eval $scheduler_ at $args]
885 }
886
887 Simulator instproc at-now args {
888 $self instvar scheduler_
889 return [eval $scheduler_ at-now $args]
890 }
891
892 Simulator instproc cancel args {
893 $self instvar scheduler_
894 return [eval $scheduler_ cancel $args]
895 }
896
897 Simulator instproc after {ival args} {
898 eval $self at [expr [$self now] + $ival] $args
899 }
900
901 #
902 # check if total num of nodes exceed 2 to the power n
903 # where <n=node field size in address>
904 #
905 Simulator instproc check-node-num {} {
906 if {[Node set nn_] > [expr pow(2, [AddrParams nodebits])]} {
907 error "Number of nodes exceeds node-field-size of [AddrParams nodebits] bits"
908 }
909 }
910
911 #
912 # Check if number of items at each hier level (num of nodes, or clusters or
913 # domains) exceed size of that hier level field size (in bits). should be
914 # modified to support n-level of hierarchies
915 #
916 Simulator instproc chk-hier-field-lengths {} {
917 AddrParams instvar domain_num_ cluster_num_ nodes_num_
918 if [info exists domain_num_] {
919 if {[expr $domain_num_ - 1]> [AddrParams NodeMask 1]} {
920 error "\# of domains exceed dom-field-size "
921 }
922 }
923 if [info exists cluster_num_] {
924 set maxval [expr [find-max $cluster_num_] - 1]
925 if {$maxval > [expr pow(2, [AddrParams NodeMask 2])]} {
926 error "\# of clusters exceed clus-field-size "
927 }
928 }
929 if [info exists nodes_num_] {
930 set maxval [expr [find-max $nodes_num_] -1]
931 if {$maxval > [expr pow(2, [AddrParams NodeMask 3])]} {
932 error "\# of nodess exceed node-field-size"
933 }
934 }
935 }
936
937
938 Simulator instproc check-smac {} {
939 $self instvar macType_
940 if { [info exist macType_] && $macType_ == "Mac/SMAC" } {
941 if { [$macType_ set syncFlag_] } {
942 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"
943 }
944 }
945 }
946
947
948 Simulator instproc run {} {
949 # NIXVECTOR?
950 # global runstart
951 # set runstart [clock seconds]
952 $self check-smac ;# print warning if in sleep/wakeup cycle
953 $self check-node-num
954 $self rtmodel-configure ;# in case there are any
955 [$self get-routelogic] configure
956 $self instvar scheduler_ Node_ link_ started_
957
958 set started_ 1
959
960 #
961 # Reset every node, which resets every agent.
962 #
963
964 foreach nn [array names Node_] {
965 $Node_($nn) reset
966 # GFR Additions for NixVector Routing
967 if { [Simulator set nix-routing] } {
968 $Node_($nn) populate-objects
969 }
970 }
971
972 #
973 # Also reset every queue
974 #
975
976 foreach qn [array names link_] {
977 set q [$link_($qn) queue]
978 $q reset
979 }
980
981 # Do all nam-related initialization here
982 $self init-nam
983
984 # NIXVECTOR xxx?
985 # global simstart
986 # set simstart [clock seconds]
987 return [$scheduler_ run]
988 }
989
990 # johnh xxx?
991 Simulator instproc log-simstart { } {
992 # GFR Modification to log actual start
993 global simstart
994 puts "Starting Actual Simulation"
995 set simstart [clock seconds]
996 }
997
998 Simulator instproc halt {} {
999 $self instvar scheduler_
1000 #puts "time: [clock format [clock seconds] -format %X]"
1001 $scheduler_ halt
1002 }
1003
1004 Simulator instproc dumpq {} {
1005 $self instvar scheduler_
1006 $scheduler_ dumpq
1007 }
1008
1009 Simulator instproc is-started {} {
1010 $self instvar started_
1011 return [info exists started_]
1012 }
1013
1014 Simulator instproc clearMemTrace {} {
1015 $self instvar scheduler_
1016 $scheduler_ clearMemTrace
1017 }
1018
1019 Simulator instproc simplex-link { n1 n2 bw delay qtype args } {
1020 $self instvar link_ queueMap_ nullAgent_ useasim_
1021 set sid [$n1 id]
1022 set did [$n2 id]
1023
1024 # Debo
1025 if { $useasim_ == 1 } {
1026 set slink_($sid:$did) $self
1027 }
1028
1029 if [info exists queueMap_($qtype)] {
1030 set qtype $queueMap_($qtype)
1031 }
1032 # construct the queue
1033 set qtypeOrig $qtype
1034 switch -exact $qtype {
1035 ErrorModule {
1036 if { [llength $args] > 0 } {
1037 set q [eval new $qtype $args]
1038 } else {
1039 set q [new $qtype Fid]
1040 }
1041 }
1042 intserv {
1043 set qtype [lindex $args 0]
1044 set q [new Queue/$qtype]
1045 }
1046 default {
1047 if { [llength $args] == 0} {
1048 set q [new Queue/$qtype]
1049 } else {
1050 set q [new Queue/$qtype $args]
1051 }
1052 }
1053 }
1054 # Now create the link
1055 switch -exact $qtypeOrig {
1056 RTM {
1057 set c [lindex $args 1]
1058 set link_($sid:$did) [new CBQLink \
1059 $n1 $n2 $bw $delay $q $c]
1060 }
1061 CBQ -
1062 CBQ/WRR {
1063 # assume we have a string of form "linktype linkarg"
1064 if {[llength $args] == 0} {
1065 # default classifier for cbq is just Fid type
1066 set c [new Classifier/Hash/Fid 33]
1067 } else {
1068 set c [lindex $args 0]
1069 }
1070 set link_($sid:$did) [new CBQLink \
1071 $n1 $n2 $bw $delay $q $c]
1072 }
1073 FQ {
1074 set link_($sid:$did) [new FQLink $n1 $n2 $bw $delay $q]
1075 }
1076 intserv {
1077 #XX need to clean this up
1078 set link_($sid:$did) [new IntServLink \
1079 $n1 $n2 $bw $delay $q \
1080 [concat $qtypeOrig $args]]
1081 }
1082 default {
1083 set link_($sid:$did) [new SimpleLink \
1084 $n1 $n2 $bw $delay $q]
1085 }
1086 }
1087 if {$qtype == "RED/Pushback"} {
1088 set pushback 1
1089 } else {
1090 set pushback 0
1091 }
1092 $n1 add-neighbor $n2 $pushback
1093
1094 #XXX yuck
1095 if {[string first "RED" $qtype] != -1 ||
1096 [string first "PI" $qtype] != -1 ||
1097 [string first "Vq" $qtype] != -1 ||
1098 [string first "REM" $qtype] != -1 ||
1099 [string first "GK" $qtype] != -1 ||
1100 [string first "RIO" $qtype] != -1 ||
1101 [string first "XCP" $qtype] != -1} {
1102 $q link [$link_($sid:$did) set link_]
1103 }
1104
1105 set trace [$self get-ns-traceall]
1106 if {$trace != ""} {
1107 $self trace-queue $n1 $n2 $trace
1108 }
1109 set trace [$self get-nam-traceall]
1110 if {$trace != ""} {
1111 $self namtrace-queue $n1 $n2 $trace
1112 }
1113
1114 # Register this simplex link in nam link list. Treat it as
1115 # a duplex link in nam
1116 $self register-nam-linkconfig $link_($sid:$did)
1117 }
1118
1119 #
1120 # This is used by Link::orient to register/update the order in which links
1121 # should created in nam. This is important because different creation order
1122 # may result in different layout.
1123 #
1124 # A poor hack. :( Any better ideas?
1125 #
1126 Simulator instproc register-nam-linkconfig link {
1127 $self instvar linkConfigList_ link_
1128 if [info exists linkConfigList_] {
1129 # Check whether the reverse simplex link is registered,
1130 # if so, don't register this link again.
1131 # We should have a separate object for duplex link.
1132 set i1 [[$link src] id]
1133 set i2 [[$link dst] id]
1134 if [info exists link_($i2:$i1)] {
1135 set pos [lsearch $linkConfigList_ $link_($i2:$i1)]
1136 if {$pos >= 0} {
1137 set a1 [$link_($i2:$i1) get-attribute \
1138 "ORIENTATION"]
1139 set a2 [$link get-attribute "ORIENTATION"]
1140 if {$a1 == "" && $a2 != ""} {
1141 # If this duplex link has not been
1142 # assigned an orientation, do it.
1143 set linkConfigList_ [lreplace \
1144 $linkConfigList_ $pos $pos]
1145 } else {
1146 return
1147 }
1148 }
1149 }
1150 # Remove $link from list if it's already there
1151 set pos [lsearch $linkConfigList_ $link]
1152 if {$pos >= 0} {
1153 set linkConfigList_ \
1154 [lreplace $linkConfigList_ $pos $pos]
1155 }
1156 }
1157 lappend linkConfigList_ $link
1158 }
1159
1160 #
1161 # GT-ITM may occasionally generate duplicate links, so we need this check
1162 # to ensure duplicated links do not appear in nam trace files.
1163 #
1164 Simulator instproc remove-nam-linkconfig {i1 i2} {
1165 $self instvar linkConfigList_ link_
1166 if ![info exists linkConfigList_] {
1167 return
1168 }
1169 set pos [lsearch $linkConfigList_ $link_($i1:$i2)]
1170 if {$pos >= 0} {
1171 set linkConfigList_ [lreplace $linkConfigList_ $pos $pos]
1172 return
1173 }
1174 set pos [lsearch $linkConfigList_ $link_($i2:$i1)]
1175 if {$pos >= 0} {
1176 set linkConfigList_ [lreplace $linkConfigList_ $pos $pos]
1177 }
1178 }
1179
1180 # Armando L. Caro Jr. <acaro@@cis,udel,edu> 10/22/2001
1181 #
1182 # we create a simplex link (NOT duplex) from the core to the interface. we can
1183 # use arbitrary params (bw, delay, etc) since we'll never actually transmit
1184 # data on these links. they are only used for routing (ie, to determine which
1185 # interface a packet should go out from)
1186 #
1187 Simulator instproc multihome-add-interface { core if } {
1188 $self instvar link_
1189 set coreId [$core id]
1190 set ifId [$if id]
1191
1192 # arbitrary values (doesn't matter since link will NEVER be used!)
1193 set bw 1Mb
1194 set delay 100ms
1195 set type DropTail
1196
1197 if [info exists link_($coreId:$ifId)] {
1198 $self remove-nam-linkconfig $coreId $ifId
1199 }
1200 eval $self simplex-link $core $if $bw $delay $type
1201 # Modified by GFR for nix-vector routing
1202 if { [Simulator set nix-routing] } {
1203 # Inform nodes of neighbors
1204 $n1 set-neighbor [$core id]
1205 $n2 set-neighbor [$if id]
1206 }
1207
1208
1209 $core instvar multihome_interfaces_ num_interfaces_
1210 set interface_ {}
1211
1212 # interface node
1213 lappend interface_ $if
1214
1215 # link from interface node to core node
1216 lappend interface_ [$link_($coreId:$ifId) set head_]
1217
1218 lappend multihome_interfaces_ $interface_
1219 }
1220
1221 Simulator instproc duplex-link { n1 n2 bw delay type args } {
1222 $self instvar link_
1223 set i1 [$n1 id]
1224 set i2 [$n2 id]
1225 if [info exists link_($i1:$i2)] {
1226 $self remove-nam-linkconfig $i1 $i2
1227 }
1228 eval $self simplex-link $n1 $n2 $bw $delay $type $args
1229 eval $self simplex-link $n2 $n1 $bw $delay $type $args
1230 # Modified by GFR for nix-vector routing
1231 if { [Simulator set nix-routing] } {
1232 # Inform nodes of neighbors
1233 $n1 set-neighbor [$n2 id]
1234 $n2 set-neighbor [$n1 id]
1235 }
1236 }
1237
1238 Simulator instproc duplex-intserv-link { n1 n2 bw pd sched signal adc args } {
1239 eval $self duplex-link $n1 $n2 $bw $pd intserv $sched $signal $adc $args
1240 }
1241
1242 Simulator instproc simplex-link-op { n1 n2 op args } {
1243 $self instvar link_
1244 eval $link_([$n1 id]:[$n2 id]) $op $args
1245 }
1246
1247 Simulator instproc duplex-link-op { n1 n2 op args } {
1248 $self instvar link_
1249 eval $link_([$n1 id]:[$n2 id]) $op $args
1250 eval $link_([$n2 id]:[$n1 id]) $op $args
1251 }
1252
1253 Simulator instproc flush-trace {} {
1254 $self instvar alltrace_
1255 if [info exists alltrace_] {
1256 foreach trace $alltrace_ {
1257 $trace flush
1258 }
1259 }
1260 }
1261
1262 Simulator instproc namtrace-all file {
1263 $self instvar namtraceAllFile_
1264 if {$file != ""} {
1265 set namtraceAllFile_ $file
1266 } else {
1267 unset namtraceAllFile_
1268 }
1269 }
1270
1271 Simulator instproc energy-color-change {level1 level2} {
1272 $self instvar level1_ level2_
1273 set level1_ $level1
1274 set level2_ $level2
1275 }
1276
1277 Simulator instproc namtrace-all-wireless {file optx opty} {
1278 $self instvar namtraceAllFile_
1279
1280 # indicate that we need a W event written to the trace
1281 $self set namNeedsW_ 1
1282 if { $optx != "" && $opty != "" } {
1283 $self set namWx_ $optx
1284 $self set namWy_ $opty
1285 }
1286
1287 $self namtrace-all $file
1288 }
1289
1290 Simulator instproc nam-end-wireless {stoptime} {
1291 $self instvar namtraceAllFile_
1292
1293 if {$namtraceAllFile_ != ""} {
1294 $self puts-nam-config "W -t $stoptime"
1295 }
1296 }
1297
1298 Simulator instproc namtrace-some file {
1299 $self instvar namtraceSomeFile_
1300 set namtraceSomeFile_ $file
1301 }
1302
1303 # Support for event-tracing
1304
1305 Simulator instproc eventtrace-all {{file ""}} {
1306 $self instvar eventTraceAll_ eventtraceAllFile_ traceAllFile_
1307 set eventTraceAll_ 1
1308 if {$file != ""} {
1309 set eventtraceAllFile_ $file
1310 } else {
1311 set eventtraceAllFile_ $traceAllFile_
1312 }
1313
1314 }
1315
1316
1317
1318 Simulator instproc initial_node_pos {nodep size} {
1319 $self instvar addressType_
1320 $self instvar energyModel_
1321
1322 if [info exists energyModel_] {
1323 set nodeColor "green"
1324 } else {
1325 set nodeColor "black"
1326 }
1327 if { [info exists addressType_] && $addressType_ == "hierarchical" } {
1328 # Hierarchical addressing
1329 $self puts-nam-config "n -t * -a [$nodep set address_] \
1330 -s [$nodep id] -x [$nodep set X_] -y [$nodep set Y_] -Z [$nodep set Z_] \
1331 -z $size -v circle -c $nodeColor"
1332 } else {
1333 # Flat addressing
1334 $self puts-nam-config "n -t * -s [$nodep id] \
1335 -x [$nodep set X_] -y [$nodep set Y_] -Z [$nodep set Z_] -z $size \
1336 -v circle -c $nodeColor"
1337 }
1338 }
1339
1340 Simulator instproc trace-all file {
1341 $self instvar traceAllFile_
1342 set traceAllFile_ $file
1343 }
1344
1345 Simulator instproc get-nam-traceall {} {
1346 $self instvar namtraceAllFile_
1347 if [info exists namtraceAllFile_] {
1348 return $namtraceAllFile_
1349 } else {
1350 return ""
1351 }
1352 }
1353
1354 Simulator instproc get-ns-traceall {} {
1355 $self instvar traceAllFile_
1356 if [info exists traceAllFile_] {
1357 return $traceAllFile_
1358 } else {
1359 return ""
1360 }
1361 }
1362
1363 # If exists a traceAllFile_, print $str to $traceAllFile_
1364 Simulator instproc puts-ns-traceall { str } {
1365 $self instvar traceAllFile_
1366 if [info exists traceAllFile_] {
1367 puts $traceAllFile_ $str
1368 }
1369 }
1370
1371 # If exists a traceAllFile_, print $str to $traceAllFile_
1372 Simulator instproc puts-nam-traceall { str } {
1373 $self instvar namtraceAllFile_
1374 if [info exists namtraceAllFile_] {
1375 puts $namtraceAllFile_ $str
1376 } elseif [info exists namtraceSomeFile_] {
1377 puts $namtraceSomeFile_ $str
1378 }
1379 }
1380
1381 # namConfigFile is used for writing color/link/node/queue/annotations.
1382 # XXX It cannot co-exist with namtraceAll.
1383 Simulator instproc namtrace-config { f } {
1384 $self instvar namConfigFile_
1385 set namConfigFile_ $f
1386 }
1387
1388 Simulator instproc get-nam-config {} {
1389 $self instvar namConfigFile_
1390 if [info exists namConfigFile_] {
1391 return $namConfigFile_
1392 } else {
1393 return ""
1394 }
1395 }
1396
1397 # Used only for writing nam configurations to trace file(s). This is different
1398 # from puts-nam-traceall because we may want to separate configuration
1399 # informations and actual tracing information
1400 Simulator instproc puts-nam-config { str } {
1401 $self instvar namtraceAllFile_ namConfigFile_
1402
1403 if [info exists namConfigFile_] {
1404 puts $namConfigFile_ $str
1405 } elseif [info exists namtraceAllFile_] {
1406 puts $namtraceAllFile_ $str
1407 } elseif [info exists namtraceSomeFile_] {
1408 puts $namtraceSomeFile_ $str
1409 }
1410 }
1411
1412 Simulator instproc color { id name } {
1413 $self instvar color_
1414 set color_($id) $name
1415 }
1416
1417 Simulator instproc get-color { id } {
1418 $self instvar color_
1419 return $color_($id)
1420 }
1421
1422 # you can pass in {} as a null file
1423 Simulator instproc create-trace { type file src dst {op ""} } {
1424 $self instvar alltrace_
1425 set p [new Trace/$type]
1426 $p tagged [Simulator set TaggedTrace_]
1427 if [catch {$p set src_ [$src id]}] {
1428 $p set src_ $src
1429 }
1430 if [catch {$p set dst_ [$dst id]}] {
1431 $p set dst_ $dst
1432 }
1433 lappend alltrace_ $p
1434 if {$file != ""} {
1435 $p ${op}attach $file
1436 }
1437 return $p
1438 }
1439
1440
1441 Simulator instproc create-eventtrace {type owner } {
1442 $self instvar alltrace_
1443 $self instvar eventTraceAll_ eventtraceAllFile_ namtraceAllFile_
1444
1445 if ![info exists eventTraceAll_] return
1446
1447 if { $eventTraceAll_ == 1 } {
1448
1449 set et [new BaseTrace/$type]
1450 $owner cmd eventtrace $et
1451
1452 lappend alltrace_ $et
1453 $et attach $eventtraceAllFile_
1454 if [info exists namtraceAllFile_] {
1455 $et namattach $namtraceAllFile_
1456 }
1457 }
1458 }
1459
1460
1461 Simulator instproc namtrace-queue { n1 n2 {file ""} } {
1462 $self instvar link_ namtraceAllFile_
1463 if {$file == ""} {
1464 if ![info exists namtraceAllFile_] return
1465 set file $namtraceAllFile_
1466 }
1467 $link_([$n1 id]:[$n2 id]) nam-trace $self $file
1468
1469 # Added later for queue specific tracing events other than enque,
1470 # deque and drop as of now nam does not understand special events.
1471 # Changes will have to be made to nam for it to understand events
1472 # like early drops if they are prefixed differently than "d". - ratul
1473 set queue [$link_([$n1 id]:[$n2 id]) queue]
1474 $queue attach-nam-traces $n1 $n2 $file
1475 }
1476
1477 Simulator instproc trace-queue { n1 n2 {file ""} } {
1478 $self instvar link_ traceAllFile_
1479 if {$file == ""} {
1480 if ![info exists traceAllFile_] return
1481 set file $traceAllFile_
1482 }
1483 $link_([$n1 id]:[$n2 id]) trace $self $file
1484
1485 # Added later for queue specific tracing events other than enque,
1486 # deque and drop - ratul
1487 set queue [$link_([$n1 id]:[$n2 id]) queue]
1488 $queue attach-traces $n1 $n2 $file
1489 }
1490
1491 #
1492 # arrange for queue length of link between nodes n1 and n2
1493 # to be tracked and return object that can be queried
1494 # to learn average q size etc. XXX this API still rough
1495 #
1496 Simulator instproc monitor-queue { n1 n2 qtrace { sampleInterval 0.1 } } {
1497 $self instvar link_
1498 return [$link_([$n1 id]:[$n2 id]) init-monitor $self $qtrace $sampleInterval]
1499 }
1500
1501 Simulator instproc queue-limit { n1 n2 limit } {
1502 $self instvar link_
1503 [$link_([$n1 id]:[$n2 id]) queue] set limit_ $limit
1504 if {[[$link_([$n1 id]:[$n2 id]) queue] info class] == "Queue/XCP"} {
1505 [$link_([$n1 id]:[$n2 id]) queue] queue-limit $limit
1506 }
1507 }
1508
1509 Simulator instproc drop-trace { n1 n2 trace } {
1510 $self instvar link_
1511 [$link_([$n1 id]:[$n2 id]) queue] drop-target $trace
1512 }
1513
1514 Simulator instproc cost {n1 n2 c} {
1515 $self instvar link_
1516 $link_([$n1 id]:[$n2 id]) cost $c
1517 }
1518
1519 # Armando L. Caro Jr. <acaro@@cis,udel,edu> 10/22/2001
1520 Simulator instproc multihome-attach-agent { core agent } {
1521 $agent set-multihome-core [$core entry]
1522
1523 foreach interface [$core set multihome_interfaces_] {
1524 set ifNode [lindex $interface 0]
1525 set coreLink [lindex $interface 1]
1526
1527 # attach agent to the node for each interface
1528 $ifNode attach $agent
1529 set addr [$agent set agent_addr_]
1530 set port [$agent set agent_port_]
1531 set entry [$ifNode entry]
1532
1533 # give the interface info to the agent
1534 $agent add-multihome-interface $addr $port $entry $coreLink
1535
1536 $agent instvar multihome_bindings_
1537 set binding_ {}
1538 lappend binding_ $addr
1539 lappend binding_ $port
1540 lappend multihome_bindings_ $binding_
1541 }
1542 }
1543
1544 Simulator instproc attach-agent { node agent } {
1545 $node attach $agent
1546 # $agent set nodeid_ [$node id]
1547
1548 # Armando L. Caro Jr. <acaro@@cis,udel,edu> 10/22/2001
1549 #
1550 # list of tuples (addr, port)
1551 # This is NEEDED so that single homed agents can play with multihomed
1552 # ones!
1553 # multihoming only for SCTP agents -Padma H.
1554 if {[lindex [split [$agent info class] "/"] 1] == "SCTP"} {
1555 $agent instvar multihome_bindings_
1556 set binding_ {}
1557 set addr [$agent set agent_addr_]
1558 set port [$agent set agent_port_]
1559 lappend binding_ $addr
1560 lappend binding_ $port
1561 lappend multihome_bindings_ $binding_
1562 }
1563 }
1564
1565 Simulator instproc attach-tbf-agent { node agent tbf } {
1566 $node attach $agent
1567 $agent attach-tbf $tbf
1568 }
1569
1570
1571 Simulator instproc detach-agent { node agent } {
1572
1573 # Debo added this
1574 $self instvar conn_ nconn_ sflows_ nsflows_ useasim_
1575
1576 if {$useasim_ == 1} {
1577 set list ""
1578 set s [$node id]
1579 set d [[$self get-node-by-addr [$agent set dst_addr_]] id]
1580 foreach x $conn_ {
1581 set t [split $x ":"]
1582 if {[string compare [lindex $t 0]:[lindex $t 1] $s:$d] != 0} {
1583 lappend list_ $x
1584 }
1585 }
1586 set conn_ list
1587 set nconn_ [expr $nconn_ -1]
1588 # ---------------------------------------
1589 }
1590
1591 $self instvar nullAgent_
1592 $node detach $agent $nullAgent_
1593 }
1594
1595 #
1596 # Helper proc for setting delay on an existing link
1597 #
1598 Simulator instproc delay { n1 n2 delay {type simplex} } {
1599 $self instvar link_
1600 set sid [$n1 id]
1601 set did [$n2 id]
1602 if [info exists link_($sid:$did)] {
1603 set d [$link_($sid:$did) link]
1604 $d set delay_ $delay
1605 }
1606 if {$type == "duplex"} {
1607 if [info exists link_($did:$sid)] {
1608 set d [$link_($did:$sid) link]
1609 $d set delay_ $delay
1610 }
1611 }
1612 }
1613
1614 #
1615 # Helper proc for setting bandwidth on an existing link
1616 #
1617 Simulator instproc bandwidth { n1 n2 bandwidth {type simplex} } {
1618 $self instvar link_
1619 set sid [$n1 id]
1620 set did [$n2 id]
1621 if [info exists link_($sid:$did)] {
1622 set d [$link_($sid:$did) link]
1623 $d set bandwidth_ $bandwidth
1624 }
1625 if {$type == "duplex"} {
1626 if [info exists link_($did:$sid)] {
1627 set d [$link_($did:$sid) link]
1628 $d set bandwidth_ $bandwidth
1629 }
1630 }
1631 }
1632
1633
1634 #XXX need to check that agents are attached to nodes already
1635 Simulator instproc connect {src dst} {
1636
1637 $self instvar conn_ nconn_ sflows_ nsflows_ useasim_
1638
1639 # Armando L. Caro Jr. <acaro@@cis,udel,edu>
1640 # does the agent type support multihoming??
1641 # @@@ do we need to worry about $useasim_ below?? (wasn't in 2.1b8)
1642 if {[lindex [split [$src info class] "/"] 1] == "SCTP"} {
1643 $self multihome-connect $src $dst
1644 }
1645
1646 $self simplex-connect $src $dst
1647 $self simplex-connect $dst $src
1648
1649
1650 # Debo
1651
1652 if {$useasim_ == 1} {
1653 set sid [$src nodeid]
1654 set sport [$src set agent_port_]
1655 set did [$dst nodeid]
1656 set dport [$dst set agent_port_]
1657
1658 if {[lindex [split [$src info class] "/"] 1] == "TCP"} {
1659 lappend conn_ $sid:$did:$sport:$dport
1660 incr nconn_
1661 # set $nconn_ [expr $nconn_ + 1]
1662 # puts "Set a connection with id $nconn_ between $sid and $did"
1663 }
1664 }
1665
1666 return $src
1667 }
1668
1669 # Armando L. Caro Jr. <acaro@@cis,udel,edu> 10/12/2001
1670 Simulator instproc multihome-connect {src dst} {
1671
1672 set destNum 0
1673 foreach binding [$src set multihome_bindings_] {
1674 incr destNum
1675 set addr [lindex $binding 0]
1676 set port [lindex $binding 1]
1677 $dst add-multihome-destination $addr $port
1678 }
1679 if {$destNum == 0} {
1680 # src isn't multihomed, so make sure we do an
1681 # add-multihome-destination
1682 $dst add-multihome-destination \
1683 [$src set agent_addr_] [$src set agent_port_]
1684 }
1685
1686 set destNum 0
1687 foreach binding [$dst set multihome_bindings_] {
1688 incr destNum
1689 set addr [lindex $binding 0]
1690 set port [lindex $binding 1]
1691 $src add-multihome-destination $addr $port
1692 }
1693 if {$destNum == 0} {
1694 # dst isn't multihomed, so make sure we do an
1695 # add-multihome-destination
1696 $src add-multihome-destination \
1697 [$dst set agent_addr_] [$dst set agent_port_]
1698 }
1699 }
1700
1701 Simulator instproc simplex-connect { src dst } {
1702 $src set dst_addr_ [$dst set agent_addr_]
1703 $src set dst_port_ [$dst set agent_port_]
1704
1705
1706 # Polly Huang: to support abstract TCP simulations
1707 if {[lindex [split [$src info class] "/"] 1] == "AbsTCP"} {
1708 $self at [$self now] "$self rtt $src $dst"
1709 $dst set class_ [$src set class_]
1710 }
1711
1712 return $src
1713 }
1714
1715 #
1716 # Here are a bunch of helper methods.
1717 #
1718
1719 Simulator proc instance {} {
1720 set ns [Simulator info instances]
1721 if { $ns != "" } {
1722 return $ns
1723 }
1724 foreach sim [Simulator info subclass] {
1725 set ns [$sim info instances]
1726 if { $ns != "" } {
1727 return $ns
1728 }
1729 }
1730 error "Cannot find instance of simulator"
1731 }
1732
1733 Simulator instproc get-number-of-nodes {} {
1734 return [$self array size Node_]
1735 }
1736
1737 Simulator instproc get-node-by-id id {
1738 $self instvar Node_
1739 return $Node_($id)
1740 }
1741
1742 # Given an node's address, Return the node-id
1743 Simulator instproc get-node-id-by-addr address {
1744 $self instvar Node_
1745 set n [Node set nn_]
1746 for {set q 0} {$q < $n} {incr q} {
1747 set nq $Node_($q)
1748 if {[string compare [$nq node-addr] $address] == 0} {
1749 return $q
1750 }
1751 }
1752 error "get-node-id-by-addr:Cannot find node with given address"
1753 }
1754
1755 # Given an node's address, return the node
1756 Simulator instproc get-node-by-addr address {
1757 return [$self get-node-by-id [$self get-node-id-by-addr $address]]
1758 }
1759
1760 Simulator instproc all-nodes-list {} {
1761 $self instvar Node_
1762 set nodes ""
1763 foreach n [lsort -dictionary [array names Node_]] {
1764 lappend nodes $Node_($n)
1765 }
1766 return $nodes
1767 }
1768
1769 Simulator instproc link { n1 n2 } {
1770 $self instvar Node_ link_
1771 if { ![catch "$n1 info class Node"] } {
1772 set n1 [$n1 id]
1773 }
1774 if { ![catch "$n2 info class Node"] } {
1775 set n2 [$n2 id]
1776 }
1777 if [info exists link_($n1:$n2)] {
1778 return $link_($n1:$n2)
1779 }
1780 return ""
1781 }
1782
1783 # Creates connection. First creates a source agent of type s_type and binds
1784 # it to source. Next creates a destination agent of type d_type and binds
1785 # it to dest. Finally creates bindings for the source and destination agents,
1786 # connects them, and returns the source agent.
1787 Simulator instproc create-connection {s_type source d_type dest pktClass} {
1788 set s_agent [new Agent/$s_type]
1789 set d_agent [new Agent/$d_type]
1790 $s_agent set fid_ $pktClass
1791 $d_agent set fid_ $pktClass
1792 $self attach-agent $source $s_agent
1793 $self attach-agent $dest $d_agent
1794 $self connect $s_agent $d_agent
1795
1796 return $s_agent
1797 }
1798
1799 # Creates a highspeed connection. Similar to create-connection
1800 # above except the sink agent requires additional work -- Sylvia
1801 Simulator instproc create-highspeed-connection {s_type source d_type dest pktClass} {
1802 set s_agent [new Agent/$s_type]
1803 set d_agent [new Agent/$d_type]
1804 $d_agent resize_buffers
1805 $s_agent set fid_ $pktClass
1806 $d_agent set fid_ $pktClass
1807 $self attach-agent $source $s_agent
1808 $self attach-agent $dest $d_agent
1809 $self connect $s_agent $d_agent
1810
1811 return $s_agent
1812 }
1813
1814 # Creates connection. First creates a source agent of type s_type and binds
1815 # it to source. Next creates a destination agent of type d_type and binds
1816 # it to dest. Finally creates bindings for the source and destination agents,
1817 # connects them, and returns a list of source agent and destination agent.
1818 Simulator instproc create-connection-list {s_type source d_type dest pktClass} {
1819 set s_agent [new Agent/$s_type]
1820 set d_agent [new Agent/$d_type]
1821 $s_agent set fid_ $pktClass
1822 $d_agent set fid_ $pktClass
1823 $self attach-agent $source $s_agent
1824 $self attach-agent $dest $d_agent
1825 $self connect $s_agent $d_agent
1826
1827 return [list $s_agent $d_agent]
1828 }
1829
1830 # Creates connection. First creates a source agent of type s_type and binds
1831 # it to source. Next creates a destination agent of type d_type and binds
1832 # it to dest. Finally creates bindings for the source and destination agents,
1833 # connects them, and returns the source agent.
1834 # The destination agent is set to listen, for full-tcp.
1835 Simulator instproc create-connection-listen {s_type source d_type dest pktClass} {
1836 set s_agent [new Agent/$s_type]
1837 set d_agent [new Agent/$d_type]
1838 $s_agent set fid_ $pktClass
1839 $d_agent set fid_ $pktClass
1840 $self attach-agent $source $s_agent
1841 $self attach-agent $dest $d_agent
1842 $self connect $s_agent $d_agent
1843 $d_agent listen
1844
1845 return $s_agent
1846 }
1847
1848 # This seems to be an obsolete procedure.
1849 Simulator instproc create-tcp-connection {s_type source d_type dest pktClass} {
1850 set s_agent [new Agent/$s_type]
1851 set d_agent [new Agent/$d_type]
1852 $s_agent set fid_ $pktClass
1853 $d_agent set fid_ $pktClass
1854 $self attach-agent $source $s_agent
1855 $self attach-agent $dest $d_agent
1856 return "$s_agent $d_agent"
1857 }
1858
1859 #
1860 # Other classifier methods overload the instproc-likes to track
1861 # and return the installed objects.
1862 #
1863 Classifier instproc install {slot val} {
1864 $self set slots_($slot) $val
1865 $self cmd install $slot $val
1866 }
1867
1868 Classifier instproc installNext val {
1869 set slot [$self cmd installNext $val]
1870 $self set slots_($slot) $val
1871 set slot
1872 }
1873
1874 Classifier instproc adjacents {} {
1875 $self array get slots_
1876 }
1877
1878 Classifier instproc in-slot? slot {
1879 $self instvar slots_
1880 set ret ""
1881 if {[info exists slots_($slot)]} {
1882 set ret $slots_($slot)
1883 }
1884 set ret
1885 }
1886
1887 # For debugging
1888 Classifier instproc dump {} {
1889 $self instvar slots_ offset_ shift_ mask_
1890 puts "classifier $self"
1891 puts "\t$offset_ offset"
1892 puts "\t$shift_ shift"
1893 puts "\t$mask_ mask"
1894 puts "\t[array size slots_] slots"
1895 foreach i [lsort -integer [array names slots_]] {
1896 set iv $slots_($i)
1897 puts "\t\tslot $i: $iv ([$iv info class])"
1898 }
1899 }
1900
1901 Classifier instproc no-slot slot {
1902 puts stderr "--- Classfier::no-slot{} default handler (tcl/lib/ns-lib.tcl) ---"
1903 puts stderr "\t$self: no target for slot $slot"
1904 puts stderr "\t$self type: [$self info class]"
1905 puts stderr "content dump:"
1906 $self dump
1907 puts stderr "---------- Finished standard no-slot{} default handler ----------"
1908 # Clear output before we bail out
1909 [Simulator instance] flush-trace
1910 exit 1
1911 }
1912
1913 Classifier/Hash instproc dump args {
1914 eval $self next $args
1915 $self instvar default_
1916 puts "\t$default_ default"
1917 }
1918
1919 Classifier/Hash instproc init nbuck {
1920 # We need to make sure that port shift/mask values are there
1921 # so we set them after they get their default values
1922 $self next $nbuck
1923 $self instvar shift_ mask_
1924 set shift_ [AddrParams NodeShift 1]
1925 set mask_ [AddrParams NodeMask 1]
1926 }
1927
1928 Classifier/Port/Reserve instproc init args {
1929 eval $self next
1930 $self reserve-port 2
1931 }
1932
1933 Simulator instproc makeflowmon { cltype { clslots 29 } } {
1934 set flowmon [new QueueMonitor/ED/Flowmon]
1935 set cl [new Classifier/Hash/$cltype $clslots]
1936
1937 $cl proc unknown-flow { src dst fid } {
1938 set fdesc [new QueueMonitor/ED/Flow]
1939 set dsamp [new Samples]
1940 $fdesc set-delay-samples $dsamp
1941 set slot [$self installNext $fdesc]
1942 $self set-hash auto $src $dst $fid $slot
1943 }
1944
1945 $cl proc no-slot slotnum {
1946 #
1947 # note: we can wind up here when a packet passes
1948 # through either an Out or a Drop Snoop Queue for
1949 # a queue that the flow doesn't belong to anymore.
1950 # Since there is no longer hash state in the
1951 # hash classifier, we get a -1 return value for the
1952 # hash classifier's classify() function, and there
1953 # is no node at slot_[-1]. What to do about this?
1954 # Well, we are talking about flows that have already
1955 # been moved and so should rightly have their stats
1956 # zero'd anyhow, so for now just ignore this case..
1957 # puts "classifier $self, no-slot for slotnum $slotnum"
1958 }
1959 $flowmon classifier $cl
1960 return $flowmon
1961 }
1962
1963 # attach a flow monitor to a link
1964 # 3rd argument dictates whether early drop support is to be used
1965
1966 Simulator instproc attach-fmon {lnk fm { edrop 0 } } {
1967 set isnoop [new SnoopQueue/In]
1968 set osnoop [new SnoopQueue/Out]
1969 set dsnoop [new SnoopQueue/Drop]
1970 $lnk attach-monitors $isnoop $osnoop $dsnoop $fm
1971 if { $edrop != 0 } {
1972 set edsnoop [new SnoopQueue/EDrop]
1973 $edsnoop set-monitor $fm
1974 [$lnk queue] early-drop-target $edsnoop
1975 $edsnoop target [$self set nullAgent_]
1976 }
1977 [$lnk queue] drop-target $dsnoop
1978 }
1979
1980 # Added by Yun Wang
1981
1982 Simulator instproc maketbtagger { cltype { clslots 29 } } {
1983
1984 set tagger [new QueueMonitor/ED/Tagger]
1985 set cl [new Classifier/Hash/$cltype $clslots]
1986
1987 $cl proc unknown-flow { src dst fid } {
1988 set fdesc [new QueueMonitor/ED/Flow/TB]
1989 set dsamp [new Samples]
1990 $fdesc set-delay-samples $dsamp
1991 set slot [$self installNext $fdesc]
1992 $self set-hash auto $src $dst $fid $slot
1993 }
1994
1995 $cl proc set-rate { src dst fid hashbucket rate depth init} {
1996 set fdesc [new QueueMonitor/ED/Flow/TB]
1997 set dsamp [new Samples]
1998 $fdesc set-delay-samples $dsamp
1999 $fdesc set target_rate_ $rate
2000 $fdesc set bucket_depth_ $depth
2001 # Initialize the bucket as full
2002 $fdesc set tbucket_ $init
2003 set slot [$self installNext $fdesc]
2004 $self set-hash $hashbucket $src $dst $fid $slot
2005 }
2006
2007 $cl proc no-slot slotnum {
2008 #
2009 # note: we can wind up here when a packet passes
2010 # through either an Out or a Drop Snoop Queue for
2011 # a queue that the flow doesn't belong to anymore.
2012 # Since there is no longer hash state in the
2013 # hash classifier, we get a -1 return value for the
2014 # hash classifier's classify() function, and there
2015 # is no node at slot_[-1]. What to do about this?
2016 # Well, we are talking about flows that have already
2017 # been moved and so should rightly have their stats
2018 # zero'd anyhow, so for now just ignore this case..
2019 # puts "classifier $self, no-slot for slotnum $slotnum"
2020 }
2021 $tagger classifier $cl
2022 return $tagger
2023 }
2024
2025 # Added by Yun Wang
2026
2027 Simulator instproc maketswtagger { cltype { clslots 29 } } {
2028
2029 set tagger [new QueueMonitor/ED/Tagger]
2030 set cl [new Classifier/Hash/$cltype $clslots]
2031
2032 $cl proc unknown-flow { src dst fid hashbucket } {
2033 set fdesc [new QueueMonitor/ED/Flow/TSW]
2034 set dsamp [new Samples]
2035 $fdesc set-delay-samples $dsamp
2036 set slot [$self installNext $fdesc]
2037 $self set-hash $hashbucket $src $dst $fid $slot
2038 }
2039
2040 $cl proc no-slot slotnum {
2041 #
2042 # note: we can wind up here when a packet passes
2043 # through either an Out or a Drop Snoop Queue for
2044 # a queue that the flow doesn't belong to anymore.
2045 # Since there is no longer hash state in the
2046 # hash classifier, we get a -1 return value for the
2047 # hash classifier's classify() function, and there
2048 # is no node at slot_[-1]. What to do about this?
2049 # Well, we are talking about flows that have already
2050 # been moved and so should rightly have their stats
2051 # zero'd anyhow, so for now just ignore this case..
2052 # puts "classifier $self, no-slot for slotnum $slotnum"
2053 }
2054 $tagger classifier $cl
2055 return $tagger
2056 }
2057
2058 # attach a Tagger to a link
2059 # Added by Yun Wang
2060
2061 Simulator instproc attach-tagger {lnk fm} {
2062 set isnoop [new SnoopQueue/Tagger]
2063 $lnk attach-taggers $isnoop $fm
2064 }
2065
2066 # Imported from session.tcl. It is deleted there.
2067 ### to insert loss module to regular links in detailed Simulator
2068 Simulator instproc lossmodel {lossobj from to} {
2069 set link [$self link $from $to]
2070 $link errormodule $lossobj
2071 }
2072
2073 # This function generates losses that can be visualized by nam.
2074 Simulator instproc link-lossmodel {lossobj from to} {
2075 set link [$self link $from $to]
2076 $link insert-linkloss $lossobj
2077 }
2078
2079
2080 #### Polly Huang: Simulator class instproc to support abstract tcp simulations
2081
2082 Simulator instproc rtt { src dst } {
2083 $self instvar routingTable_ delay_
2084 set srcid [[$src set node_] id]
2085 set dstid [[$dst set node_] id]
2086 set delay 0
2087 set tmpid $srcid
2088 while {$tmpid != $dstid} {
2089 set nextid [$routingTable_ lookup $tmpid $dstid]
2090 set tmpnode [$self get-node-by-id $tmpid]
2091 set nextnode [$self get-node-by-id $nextid]
2092 set tmplink [[$self link $tmpnode $nextnode] link]
2093 set delay [expr $delay + [expr 2 * [$tmplink set delay_]]]
2094 set delay [expr $delay + [expr 8320 / [$tmplink set bandwidth_]]]
2095 set tmpid $nextid
2096 }
2097 $src rtt $delay
2098 return $delay
2099 }
2100
2101 Simulator instproc abstract-tcp {} {
2102 $self instvar TahoeAckfsm_ RenoAckfsm_ TahoeDelAckfsm_ RenoDelAckfsm_ dropper_
2103 $self set TahoeAckfsm_ [new FSM/TahoeAck]
2104 $self set RenoAckfsm_ [new FSM/RenoAck]
2105 $self set TahoeDelAckfsm_ [new FSM/TahoeDelAck]
2106 $self set RenoDelAckfsm_ [new FSM/RenoDelAck]
2107 $self set nullAgent_ [new DropTargetAgent]
2108 }
2109
2110 # Chalermek: For Diffusion, Flooding, and Omnicient Multicast
2111
2112 Simulator instproc create-diffusion-rate-agent {node} {
2113 global opt
2114 set diff [new Agent/Diffusion/RateGradient]
2115
2116 $node set diffagent_ $diff
2117 $node set ragent_ $diff
2118
2119 $diff on-node $node
2120
2121 if [info exist opt(enablePos)] {
2122 if {$opt(enablePos) == "true"} {
2123 $diff enable-pos
2124 } else {
2125 $diff disable-pos
2126 }
2127 }
2128
2129 if [info exist opt(enableNeg)] {
2130 if {$opt(enableNeg) == "true"} {
2131 $diff enable-neg
2132 } else {
2133 $diff disable-neg
2134 }
2135 }
2136
2137 if [info exist opt(suppression)] {
2138 if {$opt(suppression) == "true"} {
2139 $diff enable-suppression
2140 } else {
2141 $diff disable-suppression
2142 }
2143 }
2144
2145 if [info exist opt(subTxType)] {
2146 $diff set-sub-tx-type $opt(subTxType)
2147 }
2148
2149 if [info exist opt(orgTxType)] {
2150 $diff set-org-tx-type $opt(orgTxType)
2151 }
2152
2153 if [info exist opt(posType)] {
2154 $diff set-pos-type $opt(posType)
2155 }
2156
2157 if [info exist opt(posNodeType)] {
2158 $diff set-pos-node-type $opt(posNodeType)
2159 }
2160
2161 if [info exist opt(negWinType)] {
2162 $diff set-neg-win-type $opt(negWinType)
2163 }
2164
2165 if [info exist opt(negThrType)] {
2166 $diff set-neg-thr-type $opt(negThrType)
2167 }
2168
2169 if [info exist opt(negMaxType)] {
2170 $diff set-neg-max-type $opt(negMaxType)
2171 }
2172
2173 $self put-in-list $diff
2174 $self at 0.0 "$diff start"
2175
2176 return $diff
2177 }
2178
2179 Simulator instproc create-diffusion-probability-agent {node} {
2180 global opt
2181 set diff [new Agent/Diffusion/ProbGradient]
2182
2183 $node set diffagent_ $diff
2184 $node set ragent_ $diff
2185
2186 $diff on-node $node
2187
2188 if [info exist opt(enablePos)] {
2189 if {$opt(enablePos) == "true"} {
2190 $diff enable-pos
2191 } else {
2192 $diff disable-pos
2193 }
2194 }
2195 if [info exist opt(enableNeg)] {
2196 if {$opt(enableNeg) == "true"} {
2197 $diff enable-neg
2198 } else {
2199 $diff disable-neg
2200 }
2201 }
2202
2203 $self put-in-list $diff
2204 $self at 0.0 "$diff start"
2205
2206 return $diff
2207 }
2208
2209 # Diffusioncore agent (in diffusion) maps to the wireless routing agent
2210 # in ns
2211 Simulator instproc create-core-diffusion-rtg-agent {node} {
2212 $self instvar stopTime_ diffFilter_
2213 Node instvar ragent_ dmux_
2214 set ragent [new Agent/DiffusionRouting [$node id]]
2215 $node set ragent_ $ragent
2216 # at stop-time core-diffusion dumps stats data
2217 # see diffusion.cc for details
2218 if { [info exists stopTime_] } {
2219 $ragent stop-time $stopTime_
2220 }
2221 if { ![info exists diffFilter_] } {
2222 puts stderr "Error: No filter defined for diffusion!\n"
2223 exit 1
2224 }
2225 $node create-diffusionApp-agent $diffFilter_
2226 return $ragent
2227 }
2228
2229 Simulator instproc create-flooding-agent {node} {
2230 set flood [new Agent/Flooding]
2231
2232 $node set ragent_ $flood
2233
2234 $flood on-node $node
2235
2236 $self put-in-list $flood
2237 $self at 0.0 "$flood start"
2238
2239 return $flood
2240 }
2241
2242 Simulator instproc create-omnimcast-agent {node} {
2243 set omni [new Agent/OmniMcast]
2244
2245 $node set ragent_ $omni
2246
2247 $omni on-node $node
2248
2249 $self put-in-list $omni
2250 $self at 0.0 "$omni start"
2251
2252 return $omni
2253 }
2254
2255 # XXX These are very simulation-specific methods, why should they belong here?
2256 Simulator instproc put-in-list {agent} {
2257 $self instvar lagent
2258 lappend lagent $agent
2259 }
2260
2261 Simulator instproc terminate-all-agents {} {
2262 $self instvar lagent
2263 foreach i $lagent {
2264 $i terminate
2265 }
2266 }
2267
2268 Simulator instproc prepare-to-stop {} {
2269 $self instvar lagent
2270 foreach i $lagent {
2271 $i stop
2272 }
2273 }
2274