Debian Codegraph @

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