ns_tcl.cc

Go to the documentation of this file.
00001 static char code[] = "\n\
00002 \n\
00003 \n\
00004 \n\
00005 \n\
00006 \n\
00007 proc warn {msg} {\n\
00008 global warned_\n\
00009 if {![info exists warned_($msg)]} {\n\
00010 puts stderr \"warning: $msg\"\n\
00011 set warned_($msg) 1\n\
00012 }\n\
00013 }\n\
00014 \n\
00015 if {[info commands debug] == \"\"} {\n\
00016 proc debug args {\n\
00017 warn {Script debugging disabled.  Reconfigure with --with-tcldebug, and recompile.}\n\
00018 }\n\
00019 }\n\
00020 \n\
00021 proc assert args {\n\
00022 if [catch \"expr $args\" ret] {\n\
00023 set ret [eval expr $args]\n\
00024 }\n\
00025 if {! $ret} {\n\
00026 error \"assertion failed: $args\"\n\
00027 }\n\
00028 }\n\
00029 \n\
00030 proc find-max list {\n\
00031 set max 0\n\
00032 foreach val $list {\n\
00033 if {$val > $max} {\n\
00034 set max $val\n\
00035 }\n\
00036 }\n\
00037 return $max\n\
00038 }\n\
00039 \n\
00040 proc bw_parse { bspec } {\n\
00041 if { [scan $bspec \"%f%s\" b unit] == 1 } {\n\
00042 set unit bps\n\
00043 }\n\
00044 regsub {[/p]s(ec)?$} $unit {} unit\n\
00045 if [string match {*B} $unit] {\n\
00046 set b [expr $b*8]\n\
00047 set unit \"[string trimright $unit B]b\"\n\
00048 }\n\
00049 switch $unit {\n\
00050 b { return $b }\n\
00051 kb { return [expr $b*1000] }\n\
00052 Mb { return [expr $b*1000000] }\n\
00053 Gb { return [expr $b*1000000000] }\n\
00054 default { \n\
00055 puts \"error: bw_parse: unknown unit `$unit'\" \n\
00056 exit 1\n\
00057 }\n\
00058 }\n\
00059 }\n\
00060 \n\
00061 proc time_parse { spec } {\n\
00062 if { [scan $spec \"%f%s\" t unit] == 1 } {\n\
00063 set unit s\n\
00064 }\n\
00065 regsub {sec$} $unit {s} unit\n\
00066 switch $unit {\n\
00067 s { return $t }\n\
00068 ms { return [expr $t*1e-3] }\n\
00069 us { return [expr $t*1e-6] }\n\
00070 ns { return [expr $t*1e-9] }\n\
00071 ps { return [expr $t*1e-12] }\n\
00072 default { \n\
00073 puts \"error: time_parse: unknown unit `$unit'\" \n\
00074 exit 1\n\
00075 }\n\
00076 }\n\
00077 }\n\
00078 \n\
00079 proc delay_parse { spec } {\n\
00080 return [time_parse $spec]\n\
00081 }\n\
00082 \n\
00083 \n\
00084 \n\
00085 \n\
00086 \n\
00087 proc checkout_executable {exe_var best alternate text} {\n\
00088 global $exe_var\n\
00089 set $exe_var $best\n\
00090 if {\"$best\" == \"\" || ![file executable $best]} {\n\
00091 puts stderr $text\n\
00092 set $exe_var $alternate\n\
00093 }\n\
00094 }\n\
00095 \n\
00096 checkout_executable PERL \"/usr/bin/perl\" perl \"\\\n\
00097 When configured, ns found the right version of perl in\\\n\
00098 /usr/bin/perl\n\
00099 but it doesn't seem to be there anymore, so\\\n\
00100 ns will fall back on running the first perl in your path.\\\n\
00101 The wrong version of perl may break the test suites.\\\n\
00102 Reconfigure and rebuild ns if this is a problem.\\\n\
00103 \"\n\
00104 checkout_executable TCLSH \"/usr/local/ns/ns-allinone-2.29/bin/tclsh8.4\" tclsh \"\\\n\
00105 When configured, ns found the right version of tclsh in\\\n\
00106 /usr/local/ns/ns-allinone-2.29/bin/tclsh8.4\n\
00107 but it doesn't seem to be there anymore, so\\\n\
00108 ns will fall back on running the first tclsh in your path.\\\n\
00109 The wrong version of tclsh may break the test suites.\\\n\
00110 Reconfigure and rebuild ns if this is a problem.\\\n\
00111 \"\n\
00112 \n\
00113 \n\
00114 \n\
00115 \n\
00116 \n\
00117 \n\
00118 \n\
00119 Class AllocAddrBits\n\
00120 \n\
00121 Simulator proc address-format {} {\n\
00122 return [Simulator set AddressFormat_]\n\
00123 }\n\
00124 \n\
00125 Simulator proc default-addr? {} {\n\
00126 if { [Simulator set AddressFormat_] == \"DEF\" } {\n\
00127 return 1\n\
00128 } else { \n\
00129 return 0\n\
00130 }\n\
00131 }\n\
00132 \n\
00133 Simulator proc hier-addr? {} {\n\
00134 if { [Simulator set AddressFormat_] == \"HIER\" } {\n\
00135 return 1\n\
00136 } else {\n\
00137 return 0\n\
00138 }\n\
00139 }\n\
00140 \n\
00141 Simulator instproc set-address-format {opt args} {\n\
00142 set len [llength $args]\n\
00143 if {[string compare $opt \"def\"] == 0} {\n\
00144 $self set-address 32\n\
00145 set mcastshift [AddrParams McastShift]\n\
00146 Simulator set McastAddr_ [expr 1 << $mcastshift]\n\
00147 mrtObject expandaddr\n\
00148 Simulator set AddressFormat_ DEF\n\
00149 } elseif {[string compare $opt \"expanded\"] == 0} {\n\
00150 puts \"set-address-format expanded is obsoleted by 32-bit addressing.\"\n\
00151 } elseif {[string compare $opt \"hierarchical\"] == 0 && $len == 0} {\n\
00152 if [$self multicast?] {\n\
00153 $self set-hieraddress 3 9 11 11\n\
00154 } else {\n\
00155 $self set-hieraddress 3 10 11 11\n\
00156 }\n\
00157 } elseif {[string compare $opt \"hierarchical\"] == 0 && $len > 0} {\n\
00158 eval $self set-hieraddress [lindex $args 0] \\\n\
00159 [lrange $args 1 [expr $len - 1]]\n\
00160 } else {\n\
00161 error \"ns-address.tcl:set-address-format: Unknown address format $opt\"\n\
00162 }\n\
00163 }\n\
00164 \n\
00165 Simulator instproc set-hieraddress {hlevel args} {\n\
00166 set a [$self get-AllocAddrBits \"new\"]\n\
00167 $a set size_ [AllocAddrBits set MAXADDRSIZE_]\n\
00168 Simulator set AddressFormat_ HIER\n\
00169 Node enable-module \"Hier\"\n\
00170 if [$self multicast?] {\n\
00171 $a set-mcastbits 1\n\
00172 }\n\
00173 eval $a set-idbits $hlevel $args\n\
00174 }\n\
00175 \n\
00176 Simulator instproc set-address {node} {\n\
00177 set a [$self get-AllocAddrBits \"new\"]\n\
00178 $a set size_ [AllocAddrBits set DEFADDRSIZE_]\n\
00179 if {[expr $node] > [$a set size_]} {\n\
00180 $a set size_ [AllocAddrBits set MAXADDRSIZE_]\n\
00181 }\n\
00182 \n\
00183 $a set-mcastbits 1\n\
00184 set lastbit [expr $node - [$a set mcastsize_]]\n\
00185 $a set-idbits 1 $lastbit\n\
00186 }\n\
00187 \n\
00188 Simulator instproc get-AllocAddrBits {prog} {\n\
00189 $self instvar allocAddr_\n\
00190 if ![info exists allocAddr_] {\n\
00191 set allocAddr_ [new AllocAddrBits]\n\
00192 } elseif ![string compare $prog \"new\"] {\n\
00193 set allocAddr_ [new AllocAddrBits]\n\
00194 }\n\
00195 return $allocAddr_\n\
00196 }\n\
00197 \n\
00198 Simulator instproc expand-port-field-bits nbits {\n\
00199 puts \"Warning: Simulator::expand-port-field-bits is obsolete.  Ports are 32 bits wide\"\n\
00200 return\n\
00201 }\n\
00202 \n\
00203 Simulator instproc expand-address {} {\n\
00204 puts \"Warning: Simulator::expand-address is obsolete.  The node address is 32 bits wide\"\n\
00205 return\n\
00206 }\n\
00207 \n\
00208 \n\
00209 AllocAddrBits instproc init {} {\n\
00210 eval $self next\n\
00211 $self instvar size_ portsize_ idsize_ mcastsize_\n\
00212 set size_ 0\n\
00213 set portsize_ 0\n\
00214 set idsize_ 0\n\
00215 set mcastsize_ 0\n\
00216 }\n\
00217 \n\
00218 AllocAddrBits instproc get-AllocAddr {} {\n\
00219 $self instvar addrStruct_\n\
00220 if ![info exists addrStruct_] {\n\
00221 set addrStruct_ [new AllocAddr]\n\
00222 }\n\
00223 return $addrStruct_\n\
00224 }\n\
00225 \n\
00226 AllocAddrBits instproc get-Address {} {\n\
00227 $self instvar address_\n\
00228 if ![info exists address_] {\n\
00229 set address_ [new Address]\n\
00230 }\n\
00231 return $address_\n\
00232 }\n\
00233 \n\
00234 AllocAddrBits instproc chksize {bit_num prog} {\n\
00235 $self instvar size_ portsize_ idsize_ mcastsize_  \n\
00236 if {$bit_num <= 0 } {\n\
00237 error \"$prog : \\# bits less than 1\"\n\
00238 }\n\
00239 set totsize [expr $portsize_ + $idsize_ + $mcastsize_]\n\
00240 if {$totsize > [AllocAddrBits set MAXADDRSIZE_]} {\n\
00241 error \"$prog : Total \\# bits exceed MAXADDRSIZE\"\n\
00242 }\n\
00243 if { $size_ < [AllocAddrBits set MAXADDRSIZE_]} {\n\
00244 if {$totsize > [AllocAddrBits set DEFADDRSIZE_]} {\n\
00245 set size_ [AllocAddrBits set MAXADDRSIZE_]\n\
00246 return 1\n\
00247 } \n\
00248 }\n\
00249 return 0\n\
00250 \n\
00251 }\n\
00252 \n\
00253 AllocAddrBits instproc set-portbits {bit_num} {\n\
00254 puts \"Warning: AllocAddrBits::set-portbits is obsolete.  Ports are 32 bits wide.\"\n\
00255 return\n\
00256 }\n\
00257 \n\
00258 AllocAddrBits instproc expand-portbits nbits {\n\
00259 puts \"Warning: AllocAddrBits::expand-portbits is obsolete.  Ports are 32 bits wide.\"\n\
00260 return\n\
00261 }\n\
00262 \n\
00263 AllocAddrBits instproc set-mcastbits {bit_num} {\n\
00264 $self instvar size_ mcastsize_\n\
00265 if {$bit_num != 1} {\n\
00266 error \"setmcast : mcastbit > 1\"\n\
00267 }\n\
00268 set mcastsize_ $bit_num\n\
00269 \n\
00270 if [$self chksize mcastsize_ \"setmcast\"] {\n\
00271 error \"set-mcastbits: size_ has been changed.\"\n\
00272 }\n\
00273 set a [$self get-AllocAddr] \n\
00274 set v [$a setbit $bit_num $size_]\n\
00275 AddrParams McastMask [lindex $v 0]\n\
00276 AddrParams McastShift [lindex $v 1]\n\
00277 \n\
00278 set ad [$self get-Address]\n\
00279 $ad mcastbits-are [AddrParams McastShift] [AddrParams McastMask]\n\
00280 }\n\
00281 \n\
00282 AllocAddrBits instproc set-idbits {nlevel args} {\n\
00283 $self instvar size_ portsize_ idsize_ hlevel_ hbits_\n\
00284 if {$nlevel != [llength $args]} {\n\
00285 error \"setid: hlevel < 1 OR nlevel and \\# args donot match\"\n\
00286 }\n\
00287 set a [$self get-AllocAddr] \n\
00288 set old 0\n\
00289 set idsize_ 0\n\
00290 set nodebits 0\n\
00291 AddrParams hlevel $nlevel\n\
00292 set hlevel_ $nlevel\n\
00293 for {set i 0} {$i < $nlevel} {incr i} {\n\
00294 set bpl($i) [lindex $args $i]\n\
00295 set idsize_ [expr $idsize_ + $bpl($i)]\n\
00296 \n\
00297 set chk [$self chksize $bpl($i) \"setid\"]\n\
00298 if {$chk > 0} {\n\
00299 error \"set-idbits: size_ has been changed.\"\n\
00300 }\n\
00301 set v [$a setbit $bpl($i) $size_]\n\
00302 AddrParams NodeMask [expr $i+1] [lindex $v 0]\n\
00303 set m([expr $i+1]) [lindex $v 0]\n\
00304 AddrParams NodeShift [expr $i+1] [lindex $v 1]\n\
00305 set s([expr $i+1]) [lindex $v 1]\n\
00306 lappend hbits_ $bpl($i)\n\
00307 \n\
00308 }\n\
00309 AddrParams nodebits $idsize_\n\
00310 set ad [$self get-Address]\n\
00311 eval $ad idsbits-are [array get s]\n\
00312 eval $ad idmbits-are [array get m]\n\
00313 eval $ad bpl-are $hbits_\n\
00314 }\n\
00315 \n\
00316 \n\
00317 AddrParams proc addr2id addrstr {\n\
00318 if [Simulator hier-addr?] {\n\
00319 set addressObj [[[Simulator instance] get-AllocAddrBits \"\"] \\\n\
00320 get-Address]\n\
00321 return [$addressObj str2addr $addrstr]\n\
00322 } else {\n\
00323 return [expr $addrstr & [AddrParams NodeMask 1] << \\\n\
00324 [AddrParams NodeShift 1]]\n\
00325 }\n\
00326 }\n\
00327 \n\
00328 AddrParams proc id2addr addr {\n\
00329 for {set i 1} {$i <= [AddrParams hlevel]} {incr i} {\n\
00330 set a [expr ($addr >> [AddrParams NodeShift $i]) & \\\n\
00331 [AddrParams NodeMask $i]]\n\
00332 lappend str $a\n\
00333 }\n\
00334 return $str\n\
00335 }\n\
00336 \n\
00337 AddrParams proc split-addrstr addrstr {\n\
00338 return [split $addrstr .]\n\
00339 }\n\
00340 \n\
00341 AddrParams proc elements-in-level? {nodeaddr level} {\n\
00342 AddrParams instvar domain_num_ cluster_num_ nodes_num_ \n\
00343 set L [AddrParams split-addrstr $nodeaddr]\n\
00344 set level [expr $level + 1]\n\
00345 \n\
00346 if { $level == 1} {\n\
00347 return $domain_num_\n\
00348 }\n\
00349 if { $level == 2} {\n\
00350 return [lindex $cluster_num_ [lindex $L 0]]\n\
00351 }\n\
00352 if { $level == 3} {\n\
00353 set C 0\n\
00354 set index 0\n\
00355 while {$C < [lindex $L 0]} {\n\
00356 set index [expr $index + [lindex $cluster_num_ $C]]\n\
00357 incr C\n\
00358 }\n\
00359 return [lindex $nodes_num_ [expr $index + [lindex $L 1]]]\n\
00360 }\n\
00361 }\n\
00362 \n\
00363 Node set nn_ 0\n\
00364 Node proc getid {} {\n\
00365 set id [Node set nn_]\n\
00366 Node set nn_ [expr $id + 1]\n\
00367 return $id\n\
00368 }\n\
00369 \n\
00370 Node set module_list_ { Base }\n\
00371 \n\
00372 Node proc enable-module { mod_name } {\n\
00373 Node instvar module_list_\n\
00374 if { [lsearch $module_list_ $mod_name] < 0 } {\n\
00375 lappend module_list_ $mod_name\n\
00376 }\n\
00377 }\n\
00378 \n\
00379 Node proc disable-module { mod_name } {\n\
00380 Node instvar module_list_\n\
00381 set pos [lsearch $module_list_ $mod_name]\n\
00382 if { $pos >= 0 } {\n\
00383 set module_list_ [lreplace $module_list_ $pos $pos]\n\
00384 }\n\
00385 }\n\
00386 \n\
00387 Node instproc init args {\n\
00388 eval $self next $args\n\
00389 \n\
00390 $self instvar id_ agents_ dmux_ neighbor_ rtsize_ address_ \\\n\
00391 nodetype_ multiPath_ ns_ rtnotif_ ptnotif_\n\
00392 \n\
00393 set ns_ [Simulator instance]\n\
00394 set id_ [Node getid]\n\
00395 $self nodeid $id_   ;# Propagate id_ into c++ space\n\
00396 \n\
00397 if {[llength $args] != 0} {\n\
00398 set address_ [lindex $args 0]\n\
00399 } else {\n\
00400 set address_ $id_\n\
00401 }\n\
00402 $self cmd addr $address_; # Propagate address_ into C++ space\n\
00403 set neighbor_ \"\"\n\
00404 set agents_ \"\"\n\
00405 set dmux_ \"\"\n\
00406 set rtsize_ 0\n\
00407 set ptnotif_ {}\n\
00408 set rtnotif_ {}\n\
00409 set nodetype_ [$ns_ get-nodetype]\n\
00410 \n\
00411 $self mk-default-classifier\n\
00412 \n\
00413 set multiPath_ [$class set multiPath_]\n\
00414 }\n\
00415 \n\
00416 Node instproc mk-default-classifier {} {\n\
00417 Node instvar module_list_\n\
00418 foreach modname [Node set module_list_] {\n\
00419 $self register-module [new RtModule/$modname]\n\
00420 }\n\
00421 }\n\
00422 \n\
00423 Node instproc id {} {\n\
00424 return [$self set id_]\n\
00425 }\n\
00426 \n\
00427 Node instproc node-addr {} {\n\
00428 return [$self set address_]\n\
00429 }\n\
00430 \n\
00431 Node instproc node-type {} {\n\
00432 return [$self set nodetype_]\n\
00433 }\n\
00434 \n\
00435 \n\
00436 Node instproc register-module { mod } {\n\
00437 $self instvar reg_module_\n\
00438 $mod register $self\n\
00439 set reg_module_([$mod module-name]) $mod\n\
00440 }\n\
00441 \n\
00442 Node instproc unregister-module { mod } {\n\
00443 $self instvar reg_module_\n\
00444 $mod unregister\n\
00445 unset reg_module_([$mod module-name])\n\
00446 delete $mod\n\
00447 }\n\
00448 \n\
00449 Node instproc list-modules {} {\n\
00450 $self instvar reg_module_\n\
00451 set ret \"\"\n\
00452 foreach n [array names reg_module_] {\n\
00453 lappend ret $reg_module_($n)\n\
00454 }\n\
00455 return $ret\n\
00456 }\n\
00457 \n\
00458 Node instproc get-module { name } {\n\
00459 $self instvar reg_module_\n\
00460 if [info exists reg_module_($name)] {\n\
00461 return $reg_module_($name)\n\
00462 } else {\n\
00463 return \"\"\n\
00464 }\n\
00465 }\n\
00466 \n\
00467 \n\
00468 \n\
00469 Node instproc incr-rtgtable-size {} {\n\
00470 $self instvar rtsize_\n\
00471 incr rtsize_\n\
00472 }\n\
00473 \n\
00474 Node instproc decr-rtgtable-size {} {\n\
00475 $self instvar rtsize_\n\
00476 incr rtsize_ -1\n\
00477 }\n\
00478 \n\
00479 Node instproc entry {} {\n\
00480 return [$self set classifier_]\n\
00481 }\n\
00482 \n\
00483 Node instproc insert-entry { module clsfr {hook \"\"} } {\n\
00484 $self instvar classifier_ mod_assoc_ hook_assoc_\n\
00485 if { $hook != \"\" } {\n\
00486 set hook_assoc_($clsfr) $classifier_\n\
00487 if { $hook == \"target\" } {\n\
00488 $clsfr target $classifier_\n\
00489 } elseif { $hook != \"\" } {\n\
00490 $clsfr install $hook $classifier_\n\
00491 }\n\
00492 }\n\
00493 set mod_assoc_($clsfr) $module\n\
00494 set classifier_ $clsfr\n\
00495 }\n\
00496 \n\
00497 Node instproc install-entry { module clsfr {hook \"\"} } {\n\
00498 $self instvar classifier_ mod_assoc_ hook_assoc_\n\
00499 if [info exists classifier_] {\n\
00500 if [info exists mod_assoc_($classifier_)] {\n\
00501 $self unregister-module $mod_assoc_($classifier_)\n\
00502 unset mod_assoc_($classifier_)\n\
00503 }\n\
00504 if [info exists hook_assoc_($classifier_)] {\n\
00505 if { $hook == \"target\" } {\n\
00506 $clsfr target $hook_assoc($classifier_)\n\
00507 } elseif { $hook != \"\" } {\n\
00508 $clsfr install $hook $hook_assoc_($classifier_)\n\
00509 }\n\
00510 set hook_assoc_($clsfr) $hook_assoc_($classifier_)\n\
00511 unset hook_assoc_($classifier_)\n\
00512 }\n\
00513 }\n\
00514 set mod_assoc_($clsfr) $module\n\
00515 set classifier_ $clsfr\n\
00516 }\n\
00517 \n\
00518 \n\
00519 Node instproc route-notify { module } {\n\
00520 $self instvar rtnotif_\n\
00521 if {$rtnotif_ == \"\"} {\n\
00522 set rtnotif_ $module\n\
00523 } else {\n\
00524 $rtnotif_ route-notify $module\n\
00525 }\n\
00526 \n\
00527 $module cmd route-notify $self\n\
00528 }\n\
00529 \n\
00530 Node instproc unreg-route-notify { module } {\n\
00531 $self instvar rtnotif_\n\
00532 if {$rtnotif_ != \"\"} {\n\
00533 if {$rtnotif_ == $module} {\n\
00534 set rtnotif_ [$rtnotif_ set next_rtm_]\n\
00535 } else {\n\
00536 $rtnotif_ unreg-route-notify $module\n\
00537 }\n\
00538 }\n\
00539 \n\
00540 $module cmd unreg-route-notify $self\n\
00541 }\n\
00542 \n\
00543 Node instproc add-route { dst target } {\n\
00544 $self instvar rtnotif_\n\
00545 \n\
00546 if {$rtnotif_ != \"\"} {\n\
00547 $rtnotif_ add-route $dst $target\n\
00548 }\n\
00549 $self incr-rtgtable-size\n\
00550 }\n\
00551 \n\
00552 Node instproc delete-route args {\n\
00553 $self instvar rtnotif_\n\
00554 if {$rtnotif_ != \"\"} {\n\
00555 eval $rtnotif_ delete-route $args\n\
00556 }\n\
00557 $self decr-rtgtable-size\n\
00558 }\n\
00559 \n\
00560 Node instproc init-routing rtObject {\n\
00561 $self instvar multiPath_ routes_ rtObject_\n\
00562 set nn [$class set nn_]\n\
00563 for {set i 0} {$i < $nn} {incr i} {\n\
00564 set routes_($i) 0\n\
00565 }\n\
00566 if ![info exists rtObject_] {\n\
00567 $self set rtObject_ $rtObject\n\
00568 }\n\
00569 $self set rtObject_\n\
00570 }\n\
00571 \n\
00572 Node instproc rtObject? {} {\n\
00573 $self instvar rtObject_\n\
00574 if ![info exists rtObject_] {\n\
00575 return \"\"\n\
00576 } else {\n\
00577 return $rtObject_\n\
00578 }\n\
00579 }\n\
00580 \n\
00581 Node instproc intf-changed {} {\n\
00582 $self instvar rtObject_\n\
00583 if [info exists rtObject_] {    ;# i.e. detailed dynamic routing\n\
00584 $rtObject_ intf-changed\n\
00585 }\n\
00586 }\n\
00587 \n\
00588 \n\
00589 \n\
00590 \n\
00591 Node instproc add-routes {id ifs} {\n\
00592 $self instvar classifier_ multiPath_ routes_ mpathClsfr_\n\
00593 if !$multiPath_ {\n\
00594 if {[llength $ifs] > 1} {\n\
00595 warn \"$class::$proc cannot install multiple routes\"\n\
00596 set ifs [lindex $ifs 0]\n\
00597 }\n\
00598 $self add-route $id [$ifs head]\n\
00599 set routes_($id) 1\n\
00600 return\n\
00601 }\n\
00602 if {$routes_($id) <= 0 && [llength $ifs] == 1 && \\\n\
00603 ![info exists mpathClsfr_($id)]} {\n\
00604 $self add-route $id [$ifs head]\n\
00605 set routes_($id) 1\n\
00606 } else {\n\
00607 if ![info exists mpathClsfr_($id)] {\n\
00608 set mpathClsfr_($id) [new Classifier/MultiPath]\n\
00609 if {$routes_($id) > 0} {\n\
00610 assert \"$routes_($id) == 1\"\n\
00611 $mpathClsfr_($id) installNext \\\n\
00612 [$classifier_ in-slot? $id]\n\
00613 }\n\
00614 $classifier_ install $id $mpathClsfr_($id)\n\
00615 }\n\
00616 foreach L $ifs {\n\
00617 $mpathClsfr_($id) installNext [$L head]\n\
00618 incr routes_($id)\n\
00619 }\n\
00620 }\n\
00621 }\n\
00622 \n\
00623 Node instproc delete-routes {id ifs nullagent} {\n\
00624 $self instvar mpathClsfr_ routes_\n\
00625 if [info exists mpathClsfr_($id)] {\n\
00626 foreach L $ifs {\n\
00627 set nonLink([$L head]) 1\n\
00628 }\n\
00629 foreach {slot link} [$mpathClsfr_($id) adjacents] {\n\
00630 if [info exists nonLink($link)] {\n\
00631 $mpathClsfr_($id) clear $slot\n\
00632 incr routes_($id) -1\n\
00633 }\n\
00634 }\n\
00635 } else {\n\
00636 $self delete-route $id $nullagent\n\
00637 incr routes_($id) -1\n\
00638 }\n\
00639 }\n\
00640 \n\
00641 Node instproc enable-mcast args {\n\
00642 $self register-module [new RtModule/Mcast]\n\
00643 \n\
00644 }\n\
00645 \n\
00646 \n\
00647 \n\
00648 Node instproc alloc-port { nullagent } {\n\
00649 return [[$self set dmux_] alloc-port $nullagent]\n\
00650 }\n\
00651 \n\
00652 Node instproc agent port {\n\
00653 $self instvar agents_\n\
00654 foreach a $agents_ {\n\
00655 if { [$a set agent_port_] == $port } {\n\
00656 return $a\n\
00657 }\n\
00658 }\n\
00659 return \"\"\n\
00660 }\n\
00661 \n\
00662 Node instproc demux {} {\n\
00663 return [$self set dmux_]\n\
00664 }\n\
00665 \n\
00666 Node instproc install-demux { demux {port \"\"} } {\n\
00667 $self instvar dmux_ address_\n\
00668 if { $dmux_ != \"\" } {\n\
00669 $self delete-route $dmux_\n\
00670 if { $port != \"\" } {\n\
00671 $demux install $port $dmux_\n\
00672 }\n\
00673 }\n\
00674 set dmux_ $demux\n\
00675 $self add-route $address_ $dmux_\n\
00676 }\n\
00677 \n\
00678 Node instproc port-notify { module } {\n\
00679 $self instvar ptnotif_\n\
00680 lappend ptnotif_ $module\n\
00681 }\n\
00682 \n\
00683 Node instproc unreg-port-notify { module } {\n\
00684 $self instvar ptnotif_\n\
00685 set pos [lsearch $ptnotif_ $module]\n\
00686 if { $pos >= 0 } {\n\
00687 set ptnotif_ [lreplace $ptnotif_ $pos $pos]\n\
00688 }\n\
00689 }\n\
00690 \n\
00691 Node instproc attach { agent { port \"\" } } {\n\
00692 $self instvar agents_ address_ dmux_ \n\
00693 lappend agents_ $agent\n\
00694 $agent set node_ $self\n\
00695 $agent set agent_addr_ [AddrParams addr2id $address_]\n\
00696 if { $dmux_ == \"\" } {\n\
00697 set dmux_ [new Classifier/Port]\n\
00698 $self add-route $address_ $dmux_\n\
00699 }\n\
00700 if { $port == \"\" } {\n\
00701 set port [$dmux_ alloc-port [[Simulator instance] nullagent]]\n\
00702 }\n\
00703 $agent set agent_port_ $port\n\
00704 \n\
00705 $self add-target $agent $port\n\
00706 }\n\
00707 \n\
00708 Node instproc add-target { agent port } {\n\
00709 $self instvar ptnotif_\n\
00710 foreach m [$self set ptnotif_] {\n\
00711 $m attach $agent $port\n\
00712 }\n\
00713 }\n\
00714 \n\
00715 Node instproc detach { agent nullagent } {\n\
00716 $self instvar agents_ dmux_\n\
00717 set k [lsearch -exact $agents_ $agent]\n\
00718 if { $k >= 0 } {\n\
00719 set agents_ [lreplace $agents_ $k $k]\n\
00720 }\n\
00721 $agent set node_ \"\"\n\
00722 $agent set agent_addr_ 0\n\
00723 $agent target $nullagent\n\
00724 $dmux_ install [$agent set agent_port_] $nullagent\n\
00725 \n\
00726 foreach m [$self set ptnotif_] {\n\
00727 $m detach $agent $nullagent\n\
00728 }\n\
00729 }\n\
00730 \n\
00731 Node instproc reset {} {\n\
00732 $self instvar agents_\n\
00733 foreach a $agents_ {\n\
00734 $a reset\n\
00735 }\n\
00736 foreach m [$self list-modules] {\n\
00737 $m reset\n\
00738 }\n\
00739 }\n\
00740 \n\
00741 \n\
00742 Node instproc neighbors {} {\n\
00743 $self instvar neighbor_\n\
00744 return [lsort $neighbor_]\n\
00745 }\n\
00746 \n\
00747 Node instproc add-neighbor {p {pushback 0}} {\n\
00748 $self instvar neighbor_\n\
00749 lappend neighbor_ $p\n\
00750 \n\
00751 if { $pushback == 1 } {\n\
00752 $self cmd add-neighbor $p\n\
00753 }\n\
00754 }\n\
00755 \n\
00756 Node instproc is-neighbor { node } {\n\
00757 $self instvar neighbor_\n\
00758 return [expr [lsearch $neighbor_ $node] != -1]\n\
00759 }\n\
00760 \n\
00761 RtModule instproc register { node } {\n\
00762 $self attach-node $node\n\
00763 $node route-notify $self\n\
00764 $node port-notify $self\n\
00765 }\n\
00766 \n\
00767 RtModule instproc init {} {\n\
00768 $self next\n\
00769 $self instvar classifier_ next_rtm_\n\
00770 set next_rtm_ \"\"\n\
00771 set classifier_ \"\"\n\
00772 }\n\
00773 \n\
00774 RtModule instproc unregister {} {\n\
00775 $self instvar classifier_\n\
00776 delete $classifier_\n\
00777 [$self node] unreg-route-notify $self\n\
00778 [$self node] unreg-port-notify $self\n\
00779 }\n\
00780 \n\
00781 RtModule instproc route-notify { module } {\n\
00782 $self instvar next_rtm_\n\
00783 if {$next_rtm_ == \"\"} {\n\
00784 set next_rtm_ $module\n\
00785 } else {\n\
00786 $next_rtm_ route-notify $module\n\
00787 }\n\
00788 }\n\
00789 \n\
00790 RtModule instproc unreg-route-notify { module } {\n\
00791 $self instvar next_rtm_\n\
00792 if {$next_rtm_ != \"\"} {\n\
00793 if {$next_rtm_ == $module} {\n\
00794 set next_rtm_ [$next_rtm_ set next_rtm_]\n\
00795 } else {\n\
00796 $next_rtm_ unreg-route-notify $module\n\
00797 }\n\
00798 }\n\
00799 }\n\
00800 \n\
00801 RtModule instproc add-route { dst target } {\n\
00802 $self instvar next_rtm_\n\
00803 [$self set classifier_] install $dst $target\n\
00804 if {$next_rtm_ != \"\"} {\n\
00805 $next_rtm_ add-route $dst $target\n\
00806 }\n\
00807 }\n\
00808 \n\
00809 RtModule instproc delete-route { dst nullagent} {\n\
00810 $self instvar next_rtm_\n\
00811 [$self set classifier_] install $dst $nullagent\n\
00812 if {$next_rtm_ != \"\"} {\n\
00813 $next_rtm_ delete-route $dst $nullagent\n\
00814 }\n\
00815 }\n\
00816 \n\
00817 RtModule instproc attach { agent port } {\n\
00818 $agent target [[$self node] entry]\n\
00819 [[$self node] demux] install $port $agent\n\
00820 }\n\
00821 \n\
00822 RtModule instproc detach { agent nullagent } {\n\
00823 }\n\
00824 \n\
00825 RtModule instproc reset {} {\n\
00826 }\n\
00827 \n\
00828 \n\
00829 \n\
00830 RtModule/Base instproc register { node } {\n\
00831 $self next $node\n\
00832 \n\
00833 $self instvar classifier_\n\
00834 set classifier_ [new Classifier/Hash/Dest 32]\n\
00835 $classifier_ set mask_ [AddrParams NodeMask 1]\n\
00836 $classifier_ set shift_ [AddrParams NodeShift 1]\n\
00837 \n\
00838 $node install-entry $self $classifier_\n\
00839 }\n\
00840 \n\
00841 \n\
00842 RtModule/Mcast instproc register { node } {\n\
00843 $self next $node\n\
00844 $self instvar classifier_\n\
00845 \n\
00846 $self set classifier_ [$node entry]\n\
00847 \n\
00848 \n\
00849 $node set switch_ [new Classifier/Addr]\n\
00850 \n\
00851 [$node set switch_] set mask_ [AddrParams McastMask]\n\
00852 [$node set switch_] set shift_ [AddrParams McastShift]\n\
00853 \n\
00854 $node set multiclassifier_ [new Classifier/Multicast/Replicator]\n\
00855 [$node set multiclassifier_] set node_ $node\n\
00856 \n\
00857 $node set mrtObject_ [new mrtObject $node]\n\
00858 \n\
00859 $node insert-entry $self [$node set switch_] 0\n\
00860 [$node set switch_] install 1 [$node set multiclassifier_]\n\
00861 }\n\
00862 \n\
00863 RtModule/Hier instproc register { node } {\n\
00864 $self next $node\n\
00865 $self instvar classifier_\n\
00866 set classifier_ [new Classifier/Hier]\n\
00867 $node install-entry $self $classifier_\n\
00868 }\n\
00869 \n\
00870 RtModule/Hier instproc delete-route args {\n\
00871 eval [$self set classifier_] clear $args\n\
00872 }\n\
00873 \n\
00874 Classifier/Hier instproc init {} {\n\
00875 $self next\n\
00876 for {set n 1} {$n <= [AddrParams hlevel]} {incr n} {\n\
00877 set classifier [new Classifier/Addr]\n\
00878 $classifier set mask_ [AddrParams NodeMask $n]\n\
00879 $classifier set shift_ [AddrParams NodeShift $n]\n\
00880 $self cmd add-classifier $n $classifier\n\
00881 }\n\
00882 }\n\
00883 \n\
00884 Classifier/Hier instproc destroy {} {\n\
00885 for {set n 1} {$n <= [AddrParams hlevel]} {incr n} {\n\
00886 delete [$self cmd classifier $n]\n\
00887 }\n\
00888 $self next\n\
00889 }\n\
00890 \n\
00891 Classifier/Hier instproc clear args {\n\
00892 set l [llength $args]\n\
00893 [$self cmd classifier $l] clear [lindex $args [expr $l-1]] \n\
00894 }\n\
00895 \n\
00896 Classifier/Hier instproc install { dst target } {\n\
00897 set al [AddrParams split-addrstr $dst]\n\
00898 set l [llength $al]\n\
00899 for {set i 1} {$i < $l} {incr i} {\n\
00900 set d [lindex $al [expr $i-1]]\n\
00901 [$self cmd classifier $i] install $d \\\n\
00902 [$self cmd classifier [expr $i+1]]\n\
00903 }\n\
00904 [$self cmd classifier $l] install [lindex $al [expr $l-1]] $target\n\
00905 }\n\
00906 \n\
00907 \n\
00908 RtModule/Manual instproc register { node } {\n\
00909 $self next $node\n\
00910 $self instvar classifier_   \n\
00911 set classifier_ [new Classifier/Hash/Dest 2]\n\
00912 $classifier_ set mask_ [AddrParams NodeMask 1]\n\
00913 $classifier_ set shift_ [AddrParams NodeShift 1]\n\
00914 $node install-entry $self $classifier_\n\
00915 }\n\
00916 \n\
00917 RtModule/Manual instproc add-route {dst_address target} {\n\
00918 $self instvar classifier_ \n\
00919 set slot [$classifier_ installNext $target]\n\
00920 if {$dst_address == \"default\"} {\n\
00921 $classifier_ set default_ $slot\n\
00922 } else {\n\
00923 set encoded_dst_address [expr $dst_address << [AddrParams NodeShift 1]]\n\
00924 $classifier_ set-hash auto 0 $encoded_dst_address 0 $slot\n\
00925 }\n\
00926 }\n\
00927 \n\
00928 RtModule/Manual instproc add-route-to-adj-node { args } {\n\
00929 $self instvar classifier_ \n\
00930 \n\
00931 set dst \"\"\n\
00932 if {[lindex $args 0] == \"-default\"} {\n\
00933 set dst default\n\
00934 set args [lrange $args 1 end]\n\
00935 }\n\
00936 if {[llength $args] != 1} {\n\
00937 error \"ManualRtNode::add-route-to-adj-node [-default] node\"\n\
00938 }\n\
00939 set target_node $args\n\
00940 if {$dst == \"\"} {\n\
00941 set dst [$target_node set address_]\n\
00942 }\n\
00943 set ns [Simulator instance]\n\
00944 set link [$ns link [$self node] $target_node]\n\
00945 set target [$link head]\n\
00946 return [$self add-route $dst $target]\n\
00947 }\n\
00948 \n\
00949 RtModule/Source instproc register { node } {\n\
00950 $self next $node\n\
00951 \n\
00952 $self instvar classifier_\n\
00953 $self set classifier_ [$node entry]\n\
00954 \n\
00955 \n\
00956 $node set src_classifier_ [new Classifier/SR]\n\
00957 $node set src_agent_ [new Agent/SRAgent]\n\
00958 $node set switch_ [$node set src_classifier_]\n\
00959 \n\
00960 \n\
00961 \n\
00962 \n\
00963 \n\
00964 $node insert-entry $self [$node set switch_] 1\n\
00965 \n\
00966 [$node set switch_]  install 0 [$node set src_agent_]\n\
00967 $node attach [$node set src_agent_]\n\
00968 \n\
00969 \n\
00970 }\n\
00971 \n\
00972 \n\
00973 RtModule/VC instproc register { node } {\n\
00974 $self instvar classifier_\n\
00975 \n\
00976 $self attach-node $node\n\
00977 $node port-notify $self\n\
00978 \n\
00979 set classifier_ [new Classifier/Virtual]\n\
00980 $classifier_ set node_ $node\n\
00981 $classifier_ set mask_ [AddrParams NodeMask 1]\n\
00982 $classifier_ set shift_ [AddrParams NodeShift 1]\n\
00983 $classifier_ nodeaddr [$node node-addr]\n\
00984 $node install-entry $self $classifier_ \n\
00985 }\n\
00986 \n\
00987 RtModule/VC instproc add-route { dst target } {\n\
00988 }\n\
00989 \n\
00990 Classifier/Virtual instproc find dst {\n\
00991 $self instvar node_\n\
00992 if {[$node_ id] == $dst} {\n\
00993 return [$node_ set dmux_]\n\
00994 } else {\n\
00995 return [[[Simulator instance] link $node_ \\\n\
00996 [[Simulator instance] set Node_($dst)]] head]\n\
00997 }\n\
00998 }\n\
00999 \n\
01000 Classifier/Virtual instproc install {dst target} {\n\
01001 }\n\
01002 \n\
01003 \n\
01004 \n\
01005 \n\
01006 Class HierNode -superclass Node\n\
01007 \n\
01008 HierNode instproc init {args} {\n\
01009 $self instvar address_\n\
01010 set haddress $args\n\
01011 set address_ $args\n\
01012 set args [lreplace $args 0 1]\n\
01013 $self next $args\n\
01014 set address_ $haddress\n\
01015 }\n\
01016 \n\
01017 HierNode instproc mk-default-classifier {} {\n\
01018 $self instvar classifiers_ \n\
01019 $self set classifier_ [new Classifier/Hier]\n\
01020 }\n\
01021 \n\
01022 \n\
01023 \n\
01024 \n\
01025 ARPTable instproc init args {\n\
01026 eval $self next $args       ;# parent class constructor\n\
01027 }\n\
01028 \n\
01029 ARPTable set bandwidth_         0\n\
01030 ARPTable set delay_             5us\n\
01031 \n\
01032 \n\
01033 Node/MobileNode instproc init args {\n\
01034 \n\
01035 eval $self next $args\n\
01036 \n\
01037 $self instvar nifs_ arptable_ X_ Y_ Z_ nodetype_\n\
01038 set X_ 0.0\n\
01039 set Y_ 0.0\n\
01040 set Z_ 0.0\n\
01041 set arptable_ \"\"                ;# no ARP table yet\n\
01042 set nifs_   0       ;# number of network interfaces\n\
01043 $self makemip-New$nodetype_\n\
01044 }\n\
01045 \n\
01046 \n\
01047 \n\
01048 Node/MobileNode instproc makemip-NewMobile {} {\n\
01049 }\n\
01050 \n\
01051 Node/MobileNode instproc makemip-NewBase {} {\n\
01052 }\n\
01053 \n\
01054 Node/MobileNode instproc makemip-New {} {\n\
01055 }\n\
01056 \n\
01057 Node/MobileNode instproc makemip-NewMIPBS {} {\n\
01058 $self instvar regagent_ encap_ decap_ agents_ id_\n\
01059 \n\
01060 set dmux [new Classifier/Port/Reserve]\n\
01061 $dmux set mask_ 0x7fffffff\n\
01062 $dmux set shift_ 0\n\
01063 $self install-demux $dmux\n\
01064 \n\
01065 set regagent_ [new Agent/MIPBS $self]\n\
01066 $self attach $regagent_ [Node/MobileNode set REGAGENT_PORT]\n\
01067 $self attach-encap \n\
01068 $self attach-decap\n\
01069 }\n\
01070 \n\
01071 Node/MobileNode instproc attach-encap {} {\n\
01072 $self instvar encap_ \n\
01073 \n\
01074 set encap_ [new MIPEncapsulator]\n\
01075 \n\
01076 $encap_ set mask_ [AddrParams NodeMask 1]\n\
01077 $encap_ set shift_ [AddrParams NodeShift 1]\n\
01078 set nodeaddr [AddrParams addr2id [$self node-addr]]\n\
01079 $encap_ set addr_ [expr ( ~([AddrParams NodeMask 1] << \\\n\
01080 [AddrParams NodeShift 1]) & $nodeaddr )]\n\
01081 $encap_ set port_ 1\n\
01082 $encap_ target [$self entry]\n\
01083 $encap_ set node_ $self\n\
01084 }\n\
01085 \n\
01086 Node/MobileNode instproc attach-decap {} {\n\
01087 $self instvar decap_ dmux_ agents_\n\
01088 set decap_ [new Classifier/Addr/MIPDecapsulator]\n\
01089 lappend agents_ $decap_\n\
01090 $decap_ set mask_ [AddrParams NodeMask 1]\n\
01091 $decap_ set shift_ [AddrParams NodeShift 1]\n\
01092 $dmux_ install [Node/MobileNode set DECAP_PORT] $decap_\n\
01093 }\n\
01094 \n\
01095 Node/MobileNode instproc makemip-NewMIPMH {} {\n\
01096 $self instvar regagent_\n\
01097 \n\
01098 set dmux [new Classifier/Port/Reserve]\n\
01099 $dmux set mask_ 0x7fffffff\n\
01100 $dmux set shift_ 0\n\
01101 $self install-demux $dmux\n\
01102 \n\
01103 set regagent_ [new Agent/MIPMH $self]\n\
01104 $self attach $regagent_ [Node/MobileNode set REGAGENT_PORT]\n\
01105 $regagent_ set mask_ [AddrParams NodeMask 1]\n\
01106 $regagent_ set shift_ [AddrParams NodeShift 1]\n\
01107 $regagent_ set dst_addr_ [expr (~0) << [AddrParams NodeShift 1]]\n\
01108 $regagent_ set dst_port_ 0\n\
01109 $regagent_ node $self\n\
01110 }\n\
01111 \n\
01112 \n\
01113 Node/MobileNode instproc reset {} {\n\
01114 $self instvar arptable_ nifs_ netif_ mac_ ifq_ ll_ imep_\n\
01115 for {set i 0} {$i < $nifs_} {incr i} {\n\
01116 $netif_($i) reset\n\
01117 $mac_($i) reset\n\
01118 $ll_($i) reset\n\
01119 $ifq_($i) reset\n\
01120 if { [info exists opt(imep)] && $opt(imep) == \"ON\" } { \n\
01121 $imep_($i) reset \n\
01122 }\n\
01123 }\n\
01124 if { $arptable_ != \"\" } {\n\
01125 $arptable_ reset \n\
01126 }\n\
01127 }\n\
01128 \n\
01129 Node/MobileNode instproc add-target { agent port } {\n\
01130 $self instvar dmux_ imep_ toraDebug_ \n\
01131 \n\
01132 set ns [Simulator instance]\n\
01133 set newapi [$ns imep-support]\n\
01134 \n\
01135 $agent set sport_ $port\n\
01136 \n\
01137 set toraonly [string first \"TORA\" [$agent info class]] \n\
01138 if {$toraonly != -1 } {\n\
01139 $agent if-queue [$self set ifq_(0)]  ;# ifq between LL and MAC\n\
01140 $agent imep-agent [$self set imep_(0)]\n\
01141 [$self set imep_(0)] rtagent $agent\n\
01142 }\n\
01143 \n\
01144 set aodvonly [string first \"AODV\" [$agent info class]] \n\
01145 if {$aodvonly != -1 } {\n\
01146 $agent if-queue [$self set ifq_(0)]   ;# ifq between LL and MAC\n\
01147 }\n\
01148 \n\
01149 \n\
01150 if { $port == [Node set rtagent_port_] } {          \n\
01151 $self add-target-rtagent $agent $port\n\
01152 return\n\
01153 }\n\
01154 \n\
01155 set namfp [$ns get-nam-traceall]\n\
01156 if { [Simulator set AgentTrace_] == \"ON\" } {\n\
01157 if {$newapi != \"\"} {\n\
01158 set sndT [$self mobility-trace Send \"AGT\"]\n\
01159 } else {\n\
01160 set sndT [cmu-trace Send AGT $self]\n\
01161 }\n\
01162 if { $namfp != \"\" } {\n\
01163 $sndT namattach $namfp\n\
01164 }\n\
01165 $sndT target [$self entry]\n\
01166 $agent target $sndT\n\
01167 if {$newapi != \"\"} {\n\
01168 set rcvT [$self mobility-trace Recv \"AGT\"]\n\
01169 } else {\n\
01170 set rcvT [cmu-trace Recv AGT $self]\n\
01171 }\n\
01172 if { $namfp != \"\" } {\n\
01173 $rcvT namattach $namfp\n\
01174 }\n\
01175 $rcvT target $agent\n\
01176 $dmux_ install $port $rcvT\n\
01177 } else {\n\
01178 $agent target [$self entry]\n\
01179 $dmux_ install $port $agent\n\
01180 }\n\
01181 }\n\
01182 \n\
01183 Node/MobileNode instproc add-target-rtagent { agent port } {\n\
01184 $self instvar imep_ toraDebug_ \n\
01185 \n\
01186 set ns [Simulator instance]\n\
01187 set newapi [$ns imep-support]\n\
01188 set namfp [$ns get-nam-traceall]\n\
01189 \n\
01190 set dmux_ [$self demux]\n\
01191 set classifier_ [$self entry]\n\
01192 \n\
01193 $agent port-dmux $dmux_\n\
01194 \n\
01195 if { [Simulator set RouterTrace_] == \"ON\" } {\n\
01196 if {$newapi != \"\"} {\n\
01197 set sndT [$self mobility-trace Send \"RTR\"]\n\
01198 } else {\n\
01199 set sndT [cmu-trace Send \"RTR\" $self]\n\
01200 }\n\
01201 if { $namfp != \"\" } {\n\
01202 $sndT namattach $namfp\n\
01203 }\n\
01204 if { $newapi == \"ON\" } {\n\
01205 $agent target $imep_(0)\n\
01206 $imep_(0) sendtarget $sndT\n\
01207 if { [info exists toraDebug_] && $toraDebug_ == \"ON\"} {\n\
01208 set sndT2 [$self mobility-trace Send \"TRP\"]\n\
01209 $sndT2 target $imep_(0)\n\
01210 $agent target $sndT2\n\
01211 }\n\
01212 } else {  ;#  no IMEP\n\
01213 $agent target $sndT\n\
01214 }\n\
01215 $sndT target [$self set ll_(0)]\n\
01216 if {$newapi != \"\"} {\n\
01217 set rcvT [$self mobility-trace Recv \"RTR\"]\n\
01218 } else {\n\
01219 set rcvT [cmu-trace Recv \"RTR\" $self]\n\
01220 }\n\
01221 if { $namfp != \"\" } {\n\
01222 $rcvT namattach $namfp\n\
01223 }\n\
01224 if {$newapi == \"ON\" } {\n\
01225 [$self set ll_(0)] up-target $imep_(0)\n\
01226 $classifier_ defaulttarget $agent\n\
01227 if {[info exists toraDebug_] && $toraDebug_ == \"ON\" } {\n\
01228 set rcvT2 [$self mobility-trace Recv \"TRP\"]\n\
01229 $rcvT2 target $agent\n\
01230 $classifier_ defaulttarget $rcvT2\n\
01231 }\n\
01232 } else {\n\
01233 $rcvT target $agent\n\
01234 $classifier_ defaulttarget $rcvT\n\
01235 $dmux_ install $port $rcvT\n\
01236 }\n\
01237 } else {\n\
01238 if { $newapi == \"ON\" } {\n\
01239 $agent target $imep_(0)\n\
01240 if { [info exists toraDebug_] && $toraDebug_ == \"ON\"} {\n\
01241 set sndT2 [$self mobility-trace Send \"TRP\"]\n\
01242 $sndT2 target $imep_(0)\n\
01243 $agent target $sndT2\n\
01244 }\n\
01245 $imep_(0) sendtarget [$self set ll_(0)]\n\
01246 \n\
01247 } else {  ;#  no IMEP\n\
01248 $agent target [$self set ll_(0)]\n\
01249 }    \n\
01250 if {$newapi == \"ON\" } {\n\
01251 [$self set ll_(0)] up-target $imep_(0)\n\
01252 $classifier_ defaulttarget $agent\n\
01253 if {[info exists toraDebug_] && $toraDebug_ == \"ON\" } {\n\
01254 set rcvT2 [$self mobility-trace Recv \"TRP\"]\n\
01255 $rcvT2 target $agent\n\
01256 [$self set classifier_] defaulttarget $rcvT2\n\
01257 }\n\
01258 } else {\n\
01259 $classifier_ defaulttarget $agent\n\
01260 $dmux_ install $port $agent\n\
01261 }\n\
01262 }\n\
01263 }\n\
01264 \n\
01265 Node/MobileNode instproc add-interface { channel pmodel lltype mactype qtype qlen iftype anttype topo inerrproc outerrproc fecproc } {\n\
01266 $self instvar arptable_ nifs_ netif_ mac_ ifq_ ll_ imep_ inerr_ outerr_ fec_\n\
01267 \n\
01268 set ns [Simulator instance]\n\
01269 set imepflag [$ns imep-support]\n\
01270 set t $nifs_\n\
01271 incr nifs_\n\
01272 \n\
01273 set netif_($t)  [new $iftype]       ;# interface\n\
01274 set mac_($t)    [new $mactype]      ;# mac layer\n\
01275 set ifq_($t)    [new $qtype]        ;# interface queue\n\
01276 set ll_($t) [new $lltype]       ;# link layer\n\
01277 set ant_($t)    [new $anttype]\n\
01278 \n\
01279 $ns mac-type $mactype\n\
01280 set inerr_($t) \"\"\n\
01281 if {$inerrproc != \"\"} {\n\
01282 set inerr_($t) [$inerrproc]\n\
01283 }\n\
01284 set outerr_($t) \"\"\n\
01285 if {$outerrproc != \"\"} {\n\
01286 set outerr_($t) [$outerrproc]\n\
01287 }\n\
01288 set fec_($t) \"\"\n\
01289 if {$fecproc != \"\"} {\n\
01290 set fec_($t) [$fecproc]\n\
01291 }\n\
01292 \n\
01293 set namfp [$ns get-nam-traceall]\n\
01294 if {$imepflag == \"ON\" } {              \n\
01295 set imep_($t) [new Agent/IMEP [$self id]]\n\
01296 set imep $imep_($t)\n\
01297 set drpT [$self mobility-trace Drop \"RTR\"]\n\
01298 if { $namfp != \"\" } {\n\
01299 $drpT namattach $namfp\n\
01300 }\n\
01301 $imep drop-target $drpT\n\
01302 $ns at 0.[$self id] \"$imep_($t) start\"   ;# start beacon timer\n\
01303 }\n\
01304 set nullAgent_ [$ns set nullAgent_]\n\
01305 set netif $netif_($t)\n\
01306 set mac $mac_($t)\n\
01307 set ifq $ifq_($t)\n\
01308 set ll $ll_($t)\n\
01309 \n\
01310 set inerr $inerr_($t)\n\
01311 set outerr $outerr_($t)\n\
01312 set fec $fec_($t)\n\
01313 \n\
01314 if { $arptable_ == \"\" } {\n\
01315 set arptable_ [new ARPTable $self $mac]\n\
01316 if {$imepflag != \"\"} {\n\
01317 set drpT [$self mobility-trace Drop \"IFQ\"]\n\
01318 } else {\n\
01319 set drpT [cmu-trace Drop \"IFQ\" $self]\n\
01320 }\n\
01321 $arptable_ drop-target $drpT\n\
01322 if { $namfp != \"\" } {\n\
01323 $drpT namattach $namfp\n\
01324 }\n\
01325 }\n\
01326 $ll arptable $arptable_\n\
01327 $ll mac $mac\n\
01328 $ll down-target $ifq\n\
01329 \n\
01330 if {$imepflag == \"ON\" } {\n\
01331 $imep recvtarget [$self entry]\n\
01332 $imep sendtarget $ll\n\
01333 $ll up-target $imep\n\
01334 } else {\n\
01335 $ll up-target [$self entry]\n\
01336 }\n\
01337 \n\
01338 $ifq target $mac\n\
01339 $ifq set limit_ $qlen\n\
01340 if {$imepflag != \"\"} {\n\
01341 set drpT [$self mobility-trace Drop \"IFQ\"]\n\
01342 } else {\n\
01343 set drpT [cmu-trace Drop \"IFQ\" $self]\n\
01344 }\n\
01345 $ifq drop-target $drpT\n\
01346 if { $namfp != \"\" } {\n\
01347 $drpT namattach $namfp\n\
01348 }\n\
01349 if {[$ifq info class] == \"Queue/XCP\"} {       \n\
01350 $mac set bandwidth_ [$ll set bandwidth_]\n\
01351 $mac set delay_ [$ll set delay_]\n\
01352 $ifq set-link-capacity [$mac set bandwidth_]\n\
01353 $ifq queue-limit $qlen\n\
01354 $ifq link $ll\n\
01355 $ifq reset\n\
01356 \n\
01357 }\n\
01358 \n\
01359 \n\
01360 $mac netif $netif\n\
01361 $mac up-target $ll\n\
01362 \n\
01363 if {$outerr == \"\" && $fec == \"\"} {\n\
01364 $mac down-target $netif\n\
01365 } elseif {$outerr != \"\" && $fec == \"\"} {\n\
01366 $mac down-target $outerr\n\
01367 $outerr target $netif\n\
01368 } elseif {$outerr == \"\" && $fec != \"\"} {\n\
01369 $mac down-target $fec\n\
01370 $fec down-target $netif\n\
01371 } else {\n\
01372 $mac down-target $fec\n\
01373 $fec down-target $outerr\n\
01374 $err target $netif\n\
01375 }\n\
01376 \n\
01377 set god_ [God instance]\n\
01378 if {$mactype == \"Mac/802_11\"} {\n\
01379 $mac nodes [$god_ num_nodes]\n\
01380 }\n\
01381 \n\
01382 $netif channel $channel\n\
01383 if {$inerr == \"\" && $fec == \"\"} {\n\
01384 $netif up-target $mac\n\
01385 } elseif {$inerr != \"\" && $fec == \"\"} {\n\
01386 $netif up-target $inerr\n\
01387 $inerr target $mac\n\
01388 } elseif {$err == \"\" && $fec != \"\"} {\n\
01389 $netif up-target $fec\n\
01390 $fec up-target $mac\n\
01391 } else {\n\
01392 $netif up-target $inerr\n\
01393 $inerr target $fec\n\
01394 $fec up-target $mac\n\
01395 }\n\
01396 \n\
01397 $netif propagation $pmodel  ;# Propagation Model\n\
01398 $netif node $self       ;# Bind node <---> interface\n\
01399 $netif antenna $ant_($t)\n\
01400 $channel addif $netif\n\
01401 \n\
01402 $channel add-node $self     \n\
01403 \n\
01404 $topo channel $channel\n\
01405 \n\
01406 if { [Simulator set MacTrace_] == \"ON\" } {\n\
01407 if {$imepflag != \"\"} {\n\
01408 set rcvT [$self mobility-trace Recv \"MAC\"]\n\
01409 } else {\n\
01410 set rcvT [cmu-trace Recv \"MAC\" $self]\n\
01411 }\n\
01412 $mac log-target $rcvT\n\
01413 if { $namfp != \"\" } {\n\
01414 $rcvT namattach $namfp\n\
01415 }\n\
01416 if {$imepflag != \"\"} {\n\
01417 set sndT [$self mobility-trace Send \"MAC\"]\n\
01418 } else {\n\
01419 set sndT [cmu-trace Send \"MAC\" $self]\n\
01420 }\n\
01421 $sndT target [$mac down-target]\n\
01422 $mac down-target $sndT\n\
01423 if { $namfp != \"\" } {\n\
01424 $sndT namattach $namfp\n\
01425 }\n\
01426 if {$imepflag != \"\"} {\n\
01427 set rcvT [$self mobility-trace Recv \"MAC\"]\n\
01428 } else {\n\
01429 set rcvT [cmu-trace Recv \"MAC\" $self]\n\
01430 }\n\
01431 $rcvT target [$mac up-target]\n\
01432 $mac up-target $rcvT\n\
01433 if { $namfp != \"\" } {\n\
01434 $rcvT namattach $namfp\n\
01435 }\n\
01436 if {$imepflag != \"\"} {\n\
01437 set drpT [$self mobility-trace Drop \"MAC\"]\n\
01438 } else {\n\
01439 set drpT [cmu-trace Drop \"MAC\" $self]\n\
01440 }\n\
01441 $mac drop-target $drpT\n\
01442 if { $namfp != \"\" } {\n\
01443 $drpT namattach $namfp\n\
01444 }\n\
01445 } else {\n\
01446 $mac log-target [$ns set nullAgent_]\n\
01447 $mac drop-target [$ns set nullAgent_]\n\
01448 }\n\
01449 \n\
01450 if { [Simulator set EotTrace_] == \"ON\" } {\n\
01451 \n\
01452 if {$imepflag != \"\"} {\n\
01453 set eotT [$self mobility-trace EOT \"MAC\"]\n\
01454 } else {\n\
01455 set eoT [cmu-trace EOT \"MAC\" $self]\n\
01456 }\n\
01457 $mac eot-target $eotT\n\
01458 }\n\
01459 \n\
01460 \n\
01461 \n\
01462 \n\
01463 $self addif $netif\n\
01464 }\n\
01465 \n\
01466 Node/MobileNode instproc setPt { val } {\n\
01467 $self instvar netif_\n\
01468 $netif_(0) setTxPower $val\n\
01469 }\n\
01470 \n\
01471 Node/MobileNode instproc setPr { val } {\n\
01472 $self instvar netif_\n\
01473 $netif_(0) setRxPower $val\n\
01474 }\n\
01475 \n\
01476 Node/MobileNode instproc setPidle { val } {\n\
01477 $self instvar netif_\n\
01478 $netif_(0) setIdlePower $val\n\
01479 }\n\
01480 Node/MobileNode instproc setPsleep { val } {\n\
01481 $self instvar netif_\n\
01482 $netif_(0) setSleepPower $val\n\
01483 }\n\
01484 \n\
01485 Node/MobileNode instproc setPtransition { val } {\n\
01486 $self instvar netif_\n\
01487 $netif_(0) setTransitionPower $val\n\
01488 }\n\
01489 \n\
01490 Node/MobileNode instproc setTtransition { val } {\n\
01491 $self instvar netif_\n\
01492 $netif_(0) setTransitionTime $val\n\
01493 }\n\
01494 Node/MobileNode instproc getMac {param0} {\n\
01495 $self instvar mac_\n\
01496 return $mac_($param0)\n\
01497 }\n\
01498 \n\
01499 Node/MobileNode instproc CFP { beacon_period cfp_duration } {\n\
01500 if {$mactype == \"Mac/802_11\"} {\n\
01501 $self instvar mac_\n\
01502 set ns_ [Simulator instance]\n\
01503 set beacon_period [$ns_ delay_parse $beacon_period]\n\
01504 set cfp_duration [$ns_ delay_parse $cfp_duration]\n\
01505 $mac_(0) cfp $beacon_period $cfp_duration\n\
01506 }\n\
01507 }\n\
01508 \n\
01509 \n\
01510 \n\
01511 Node/MobileNode instproc mobility-trace { ttype atype } {\n\
01512 set ns [Simulator instance]\n\
01513 set tracefd [$ns get-ns-traceall]\n\
01514 if { $tracefd == \"\" } {\n\
01515 puts \"Warning: You have not defined you tracefile yet!\"\n\
01516 puts \"Please use trace-all command to define it.\"\n\
01517 return \"\"\n\
01518 }\n\
01519 set T [new CMUTrace/$ttype $atype]\n\
01520 $T newtrace [Simulator set WirelessNewTrace_]\n\
01521 $T tagged [Simulator set TaggedTrace_]\n\
01522 $T target [$ns nullagent]\n\
01523 $T attach $tracefd\n\
01524 $T set src_ [$self id]\n\
01525 $T node $self\n\
01526 return $T\n\
01527 }\n\
01528 \n\
01529 Node/MobileNode instproc nodetrace { tracefd } {\n\
01530 set T [new Trace/Generic]\n\
01531 $T target [[Simulator instance] set nullAgent_]\n\
01532 $T attach $tracefd\n\
01533 $T set src_ [$self id]\n\
01534 $self log-target $T    \n\
01535 }\n\
01536 \n\
01537 Node/MobileNode instproc agenttrace {tracefd} {\n\
01538 set ns [Simulator instance]\n\
01539 set ragent [$self set ragent_]\n\
01540 set drpT [$self mobility-trace Drop \"RTR\"]\n\
01541 set namfp [$ns get-nam-traceall]\n\
01542 if { $namfp != \"\"} {\n\
01543 $drpT namattach $namfp\n\
01544 }\n\
01545 $ragent drop-target $drpT\n\
01546 set T [new Trace/Generic]\n\
01547 $T target [$ns set nullAgent_]\n\
01548 $T attach $tracefd\n\
01549 $T set src_ [$self id]\n\
01550 $ragent tracetarget $T\n\
01551 set imepflag [$ns imep-support]\n\
01552 if {$imepflag == \"ON\"} {\n\
01553 [$self set imep_(0)] log-target $T\n\
01554 }\n\
01555 }\n\
01556 \n\
01557 Node/MobileNode instproc mip-call {ragent} {\n\
01558 $self instvar regagent_\n\
01559 if [info exists regagent_] {\n\
01560 $regagent_ ragent $ragent\n\
01561 }\n\
01562 }\n\
01563 \n\
01564 Node/MobileNode instproc attach-gafpartner {} {\n\
01565 \n\
01566 $self instvar gafpartner_ address_ ll_ \n\
01567 \n\
01568 set gafpartner_ [new GAFPartner]\n\
01569 \n\
01570 $gafpartner_ set mask_ [AddrParams NodeMask 1]\n\
01571 $gafpartner_ set shift_ [AddrParams NodeShift 1]\n\
01572 set nodeaddr [AddrParams addr2id [$self node-addr]]\n\
01573 \n\
01574 \n\
01575 \n\
01576 $gafpartner_ set addr_ $nodeaddr\n\
01577 $gafpartner_ set port_ 254\n\
01578 \n\
01579 \n\
01580 $gafpartner_ target [$self entry]\n\
01581 $ll_(0) up-target $gafpartner_\n\
01582 }\n\
01583 \n\
01584 Node/MobileNode instproc unset-gafpartner {} {\n\
01585 $self instvar gafpartner_\n\
01586 \n\
01587 $gafpartner_ set-gafagent 0\n\
01588 \n\
01589 }\n\
01590 \n\
01591 Node/MobileNode instproc sscs args {\n\
01592 $self instvar mac_\n\
01593 eval $mac_(0) sscs $args\n\
01594 }\n\
01595 \n\
01596 Node/MobileNode instproc NodeClr {arg1} {\n\
01597 $self instvar mac_\n\
01598 $mac_(0) NodeClr $arg1\n\
01599 }\n\
01600 \n\
01601 Node/MobileNode instproc NodeLabel args {\n\
01602 $self instvar mac_\n\
01603 eval $mac_(0) NodeLabel $args\n\
01604 }\n\
01605 \n\
01606 Node/MobileNode instproc node-down {} {\n\
01607 $self instvar mac_\n\
01608 $mac_(0) node-down\n\
01609 }\n\
01610 \n\
01611 Node/MobileNode instproc node-up {} {\n\
01612 $self instvar mac_\n\
01613 $mac_(0) node-up\n\
01614 }\n\
01615 \n\
01616 Node/MobileNode instproc RNType args {\n\
01617 $self instvar ragent_\n\
01618 eval $ragent_ RNType $args\n\
01619 }\n\
01620 \n\
01621 Class SRNodeNew -superclass Node/MobileNode\n\
01622 \n\
01623 SRNodeNew instproc init args {\n\
01624 $self instvar dsr_agent_ dmux_ entry_point_ address_\n\
01625 \n\
01626 set ns [Simulator instance]\n\
01627 \n\
01628 eval $self next $args   ;# parent class constructor\n\
01629 \n\
01630 if {$dmux_ == \"\" } {\n\
01631 set dmux_ [new Classifier/Port]\n\
01632 }\n\
01633 set dsr_agent_ [new Agent/DSRAgent]\n\
01634 \n\
01635 $dsr_agent_ addr $address_\n\
01636 $dsr_agent_ node $self\n\
01637 if [Simulator set mobile_ip_] {\n\
01638 $dsr_agent_ port-dmux [$self set dmux_]\n\
01639 }\n\
01640 $self addr $address_\n\
01641 \n\
01642 if { [Simulator set RouterTrace_] == \"ON\" } {\n\
01643 set rcvT [$self mobility-trace Recv \"RTR\"]\n\
01644 set namfp [$ns get-nam-traceall]\n\
01645 if {  $namfp != \"\" } {\n\
01646 $rcvT namattach $namfp\n\
01647 }\n\
01648 $rcvT target $dsr_agent_\n\
01649 set entry_point_ $rcvT  \n\
01650 } else {\n\
01651 set entry_point_ $dsr_agent_\n\
01652 }\n\
01653 \n\
01654 $self set ragent_ $dsr_agent_\n\
01655 $dsr_agent_ target $dmux_\n\
01656 \n\
01657 set nullAgent_ [$ns set nullAgent_]\n\
01658 $dmux_ install [Node set rtagent_port_] $nullAgent_\n\
01659 \n\
01660 $self instvar classifier_\n\
01661 set classifier_ \"srnode made illegal use of classifier_\"\n\
01662 \n\
01663 return $self\n\
01664 }\n\
01665 \n\
01666 SRNodeNew instproc start-dsr {} {\n\
01667 $self instvar dsr_agent_\n\
01668 $dsr_agent_ startdsr\n\
01669 }\n\
01670 \n\
01671 SRNodeNew instproc entry {} {\n\
01672 $self instvar entry_point_\n\
01673 return $entry_point_\n\
01674 }\n\
01675 \n\
01676 SRNodeNew instproc add-interface args {\n\
01677 eval $self next $args\n\
01678 \n\
01679 $self instvar dsr_agent_ ll_ mac_ ifq_\n\
01680 \n\
01681 set ns [Simulator instance]\n\
01682 $dsr_agent_ mac-addr [$mac_(0) id]\n\
01683 \n\
01684 if { [Simulator set RouterTrace_] == \"ON\" } {\n\
01685 set sndT [$self mobility-trace Send \"RTR\"]\n\
01686 set namfp [$ns get-nam-traceall]\n\
01687 if {$namfp != \"\" } {\n\
01688 $sndT namattach $namfp\n\
01689 }\n\
01690 $sndT target $ll_(0)\n\
01691 $dsr_agent_ add-ll $sndT $ifq_(0)\n\
01692 } else {\n\
01693 $dsr_agent_ add-ll $ll_(0) $ifq_(0)\n\
01694 }\n\
01695 $dsr_agent_ install-tap $mac_(0)\n\
01696 }\n\
01697 \n\
01698 SRNodeNew instproc reset args {\n\
01699 $self instvar dsr_agent_\n\
01700 eval $self next $args\n\
01701 $dsr_agent_ reset\n\
01702 }\n\
01703 \n\
01704 \n\
01705 \n\
01706 Class Node/MobileNode/BaseStationNode -superclass Node/MobileNode\n\
01707 \n\
01708 Node/MobileNode/BaseStationNode instproc init args {\n\
01709 $self next $args\n\
01710 }\n\
01711 \n\
01712 Node/MobileNode/BaseStationNode instproc mk-default-classifier {} {\n\
01713 $self instvar classifiers_ \n\
01714 set levels [AddrParams hlevel]\n\
01715 for {set n 1} {$n <= $levels} {incr n} {\n\
01716 set classifiers_($n) [new Classifier/Hash/Dest/Bcast 32]\n\
01717 $classifiers_($n) set mask_ [AddrParams NodeMask $n]\n\
01718 $classifiers_($n) set shift_ [AddrParams NodeShift $n]\n\
01719 }\n\
01720 }\n\
01721 \n\
01722 \n\
01723 Node/MobileNode/BaseStationNode instproc entry {} {\n\
01724 $self instvar ns_\n\
01725 if ![info exist ns_] {\n\
01726 set ns_ [Simulator instance]\n\
01727 }\n\
01728 if [$ns_ multicast?] { \n\
01729 $self instvar switch_\n\
01730 return $switch_\n\
01731 }\n\
01732 $self instvar classifiers_\n\
01733 return $classifiers_(1)\n\
01734 }\n\
01735 \n\
01736 Node/MobileNode/BaseStationNode instproc add-target {agent port } {\n\
01737 $self instvar dmux_ classifiers_\n\
01738 $agent set sport_ $port\n\
01739 set level [AddrParams hlevel]\n\
01740 \n\
01741 if { $port == [Node set rtagent_port_] } {  \n\
01742 if { [Simulator set RouterTrace_] == \"ON\" } {\n\
01743 set sndT [cmu-trace Send \"RTR\" $self]\n\
01744 $sndT target [$self set ll_(0)]\n\
01745 $agent target $sndT\n\
01746 set rcvT [cmu-trace Recv \"RTR\" $self]\n\
01747 $rcvT target $agent\n\
01748 for {set i 1} {$i <= $level} {incr i} {\n\
01749 $classifiers_($i) defaulttarget $rcvT\n\
01750 $classifiers_($i) bcast-receiver $rcvT\n\
01751 }\n\
01752 $dmux_ install $port $rcvT\n\
01753 } else {\n\
01754 $agent target [$self set ll_(0)]\n\
01755 for {set i 1} {$i <= $level} {incr i} {\n\
01756 $classifiers_($i) bcast-receiver $agent\n\
01757 $classifiers_($i) defaulttarget $agent\n\
01758 }\n\
01759 $dmux_ install $port $agent\n\
01760 }\n\
01761 } else {\n\
01762 if { [Simulator set AgentTrace_] == \"ON\" } {\n\
01763 set sndT [cmu-trace Send AGT $self]\n\
01764 $sndT target [$self entry]\n\
01765 $agent target $sndT\n\
01766 set rcvT [cmu-trace Recv AGT $self]\n\
01767 $rcvT target $agent\n\
01768 $dmux_ install $port $rcvT\n\
01769 } else {\n\
01770 $agent target [$self entry]\n\
01771 $dmux_ install $port $agent\n\
01772 }\n\
01773 }\n\
01774 }\n\
01775 \n\
01776 Class Link\n\
01777 \n\
01778 Link set nl_ 0\n\
01779 \n\
01780 Link instproc init { src dst } {\n\
01781 $self next\n\
01782 \n\
01783 $self instvar id_\n\
01784 set id_ [Link set nl_]\n\
01785 Link set nl_ [expr $id_ + 1]\n\
01786 \n\
01787 \n\
01788 $self instvar trace_ fromNode_ toNode_ color_ oldColor_\n\
01789 set fromNode_ $src\n\
01790 set toNode_   $dst\n\
01791 set color_ \"black\"\n\
01792 set oldColor_ \"black\"\n\
01793 \n\
01794 set trace_ \"\"\n\
01795 }\n\
01796 \n\
01797 Link instproc head {} {\n\
01798 $self instvar head_\n\
01799 return $head_\n\
01800 }\n\
01801 \n\
01802 Link instproc add-to-head { connector } {\n\
01803 $self instvar head_\n\
01804 $connector target [$head_ target]\n\
01805 $head_ target $connector\n\
01806 }\n\
01807 \n\
01808 Link instproc queue {} {\n\
01809 $self instvar queue_\n\
01810 return $queue_\n\
01811 }\n\
01812 \n\
01813 Link instproc link {} {\n\
01814 $self instvar link_\n\
01815 return $link_\n\
01816 }\n\
01817 \n\
01818 Link instproc src {}    { $self set fromNode_   }\n\
01819 Link instproc dst {}    { $self set toNode_ }\n\
01820 Link instproc cost c    { $self set cost_ $c    }\n\
01821 \n\
01822 Link instproc cost? {} {\n\
01823 $self instvar cost_\n\
01824 if ![info exists cost_] {\n\
01825 set cost_ 1\n\
01826 }\n\
01827 set cost_\n\
01828 }\n\
01829 \n\
01830 Link instproc id {}     { $self set id_ }\n\
01831 Link instproc setid { x } { $self set id_ $x }\n\
01832 Link instproc bw {} { $self set bandwidth_ }\n\
01833 \n\
01834 Link instproc if-label? {} {\n\
01835 $self instvar iif_\n\
01836 $iif_ label\n\
01837 }\n\
01838 \n\
01839 Link instproc up { } {\n\
01840 $self instvar dynamics_ dynT_\n\
01841 if ![info exists dynamics_] return\n\
01842 $dynamics_ set status_ 1\n\
01843 if [info exists dynT_] {\n\
01844 foreach tr $dynT_ {\n\
01845 $tr format link-up {$src_} {$dst_}\n\
01846 set ns [Simulator instance]\n\
01847 $self instvar fromNode_ toNode_\n\
01848 $tr ntrace \"l -t [$ns now] -s [$fromNode_ id] -d [$toNode_ id] -S UP\"\n\
01849 $tr ntrace \"v -t [$ns now] link-up [$ns now] [$fromNode_ id] [$toNode_ id]\"\n\
01850 }\n\
01851 }\n\
01852 }\n\
01853 \n\
01854 Link instproc down { } {\n\
01855 $self instvar dynamics_ dynT_\n\
01856 if ![info exists dynamics_] {\n\
01857 puts stderr \"$class::$proc Link $self was not declared dynamic, and cannot be taken down.  ignored\"\n\
01858 return\n\
01859 }\n\
01860 $dynamics_ set status_ 0\n\
01861 $self all-connectors reset\n\
01862 if [info exists dynT_] {\n\
01863 foreach tr $dynT_ {\n\
01864 $tr format link-down {$src_} {$dst_}\n\
01865 set ns [Simulator instance]\n\
01866 $self instvar fromNode_ toNode_\n\
01867 $tr ntrace \"l -t [$ns now] -s [$fromNode_ id] -d [$toNode_ id] -S DOWN\"\n\
01868 $tr ntrace \"v -t [$ns now] link-down [$ns now] [$fromNode_ id] [$toNode_ id]\"\n\
01869 }\n\
01870 }\n\
01871 }\n\
01872 \n\
01873 Link instproc up? {} {\n\
01874 $self instvar dynamics_\n\
01875 if [info exists dynamics_] {\n\
01876 return [$dynamics_ status?]\n\
01877 } else {\n\
01878 return \"up\"\n\
01879 }\n\
01880 }\n\
01881 \n\
01882 Link instproc all-connectors op {\n\
01883 foreach c [$self info vars] {\n\
01884 $self instvar $c\n\
01885 if ![info exists $c] continue\n\
01886 if [array size $c] continue\n\
01887 foreach var [$self set $c] {\n\
01888 if [catch \"$var info class\"] {\n\
01889 continue\n\
01890 }\n\
01891 if ![$var info class Node] { ;# $op on most everything\n\
01892 catch \"$var $op\";# in case var isn't a connector\n\
01893 }\n\
01894 }\n\
01895 }\n\
01896 }\n\
01897 \n\
01898 Link instproc install-error {em} {\n\
01899 $self instvar link_\n\
01900 $em target [$link_ target]\n\
01901 $link_ target $em\n\
01902 }\n\
01903 \n\
01904 Class SimpleLink -superclass Link\n\
01905 \n\
01906 SimpleLink instproc init { src dst bw delay q {lltype \"DelayLink\"} } {\n\
01907 $self next $src $dst\n\
01908 $self instvar link_ queue_ head_ toNode_ ttl_\n\
01909 $self instvar drophead_\n\
01910 \n\
01911 set ns [Simulator instance]\n\
01912 set drophead_ [new Connector]\n\
01913 $drophead_ target [$ns set nullAgent_]\n\
01914 \n\
01915 set head_ [new Connector]\n\
01916 $head_ set link_ $self\n\
01917 \n\
01918 if { [[$q info class] info heritage ErrModule] == \"ErrorModule\" } {\n\
01919 $head_ target [$q classifier]\n\
01920 } else {\n\
01921 $head_ target $q\n\
01922 }\n\
01923 \n\
01924 set queue_ $q\n\
01925 set link_ [new $lltype]\n\
01926 $link_ set bandwidth_ $bw\n\
01927 $link_ set delay_ $delay\n\
01928 $queue_ target $link_\n\
01929 $link_ target [$dst entry]\n\
01930 $queue_ drop-target $drophead_\n\
01931 \n\
01932 set ttl_ [new TTLChecker]\n\
01933 $ttl_ target [$link_ target]\n\
01934 $self ttl-drop-trace\n\
01935 $link_ target $ttl_\n\
01936 \n\
01937 if { [$ns multicast?] } {\n\
01938 $self enable-mcast $src $dst\n\
01939 }\n\
01940 $ns instvar srcRt_\n\
01941 if [info exists srcRt_] {\n\
01942 if { $srcRt_ == 1 } {\n\
01943 $self enable-src-rt $src $dst $head_\n\
01944 }\n\
01945 }\n\
01946 \n\
01947 }\n\
01948 \n\
01949 SimpleLink instproc enable-src-rt {src dst head} {\n\
01950 $self instvar ttl_\n\
01951 $src instvar src_agent_\n\
01952 $ttl_ target [$dst entry]\n\
01953 $src_agent_ install_slot $head [$dst id]\n\
01954 }\n\
01955 \n\
01956 \n\
01957 SimpleLink instproc enable-mcast {src dst} {\n\
01958 $self instvar iif_ ttl_\n\
01959 set iif_ [new NetworkInterface]\n\
01960 $iif_ target [$ttl_ target]\n\
01961 $ttl_ target $iif_\n\
01962 \n\
01963 $src add-oif [$self head]  $self\n\
01964 $dst add-iif [$iif_ label] $self\n\
01965 }\n\
01966 \n\
01967 \n\
01968 SimpleLink instproc bw {} { \n\
01969 $self instvar link_\n\
01970 $link_ set bandwidth_ \n\
01971 \n\
01972 }\n\
01973 \n\
01974 SimpleLink instproc delay {} {\n\
01975 $self instvar link_\n\
01976 $link_ set delay_\n\
01977 }\n\
01978 \n\
01979 SimpleLink instproc qsize {} {\n\
01980 [$self queue] set limit_\n\
01981 }\n\
01982 \n\
01983 SimpleLink instproc nam-trace { ns f } {\n\
01984 $self instvar enqT_ deqT_ drpT_ rcvT_ dynT_\n\
01985 \n\
01986 if [info exists enqT_] {\n\
01987 $enqT_ namattach $f\n\
01988 if [info exists deqT_] {\n\
01989 $deqT_ namattach $f\n\
01990 }\n\
01991 if [info exists drpT_] {\n\
01992 $drpT_ namattach $f\n\
01993 }\n\
01994 if [info exists rcvT_] {\n\
01995 $rcvT_ namattach $f\n\
01996 }\n\
01997 if [info exists dynT_] {\n\
01998 foreach tr $dynT_ {\n\
01999 $tr namattach $f\n\
02000 }\n\
02001 }\n\
02002 } else {\n\
02003 $self trace $ns $f \"nam\"\n\
02004 }\n\
02005 }\n\
02006 \n\
02007 SimpleLink instproc trace { ns f {op \"\"} } {\n\
02008 \n\
02009 $self instvar enqT_ deqT_ drpT_ queue_ link_ fromNode_ toNode_\n\
02010 $self instvar rcvT_ ttl_ trace_\n\
02011 $self instvar drophead_     ;# idea stolen from CBQ and Kevin\n\
02012 \n\
02013 set trace_ $f\n\
02014 set enqT_ [$ns create-trace Enque $f $fromNode_ $toNode_ $op]\n\
02015 set deqT_ [$ns create-trace Deque $f $fromNode_ $toNode_ $op]\n\
02016 set drpT_ [$ns create-trace Drop $f $fromNode_ $toNode_ $op]\n\
02017 set rcvT_ [$ns create-trace Recv $f $fromNode_ $toNode_ $op]\n\
02018 \n\
02019 $self instvar drpT_ drophead_\n\
02020 set nxt [$drophead_ target]\n\
02021 $drophead_ target $drpT_\n\
02022 $drpT_ target $nxt\n\
02023 \n\
02024 $queue_ drop-target $drophead_\n\
02025 \n\
02026 \n\
02027 $deqT_ target [$queue_ target]\n\
02028 $queue_ target $deqT_\n\
02029 \n\
02030 $self add-to-head $enqT_\n\
02031 \n\
02032 $rcvT_ target [$ttl_ target]\n\
02033 $ttl_ target $rcvT_\n\
02034 \n\
02035 $self instvar dynamics_\n\
02036 if [info exists dynamics_] {\n\
02037 $self trace-dynamics $ns $f $op\n\
02038 }\n\
02039 }\n\
02040 \n\
02041 SimpleLink instproc trace-dynamics { ns f {op \"\"}} {\n\
02042 $self instvar dynT_ fromNode_ toNode_\n\
02043 lappend dynT_ [$ns create-trace Generic $f $fromNode_ $toNode_ $op]\n\
02044 $self transit-drop-trace\n\
02045 $self linkfail-drop-trace\n\
02046 }\n\
02047 \n\
02048 SimpleLink instproc ttl-drop-trace args {\n\
02049 $self instvar ttl_\n\
02050 if ![info exists ttl_] return\n\
02051 if {[llength $args] != 0} {\n\
02052 $ttl_ drop-target [lindex $args 0]\n\
02053 } else {\n\
02054 $self instvar drophead_\n\
02055 $ttl_ drop-target $drophead_\n\
02056 }\n\
02057 }\n\
02058 \n\
02059 SimpleLink instproc transit-drop-trace args {\n\
02060 $self instvar link_\n\
02061 if {[llength $args] != 0} {\n\
02062 $link_ drop-target [lindex $args 0]\n\
02063 } else {\n\
02064 $self instvar drophead_\n\
02065 $link_ drop-target $drophead_\n\
02066 }\n\
02067 }\n\
02068 \n\
02069 SimpleLink instproc linkfail-drop-trace args {\n\
02070 $self instvar dynamics_\n\
02071 if ![info exists dynamics_] return\n\
02072 if {[llength $args] != 0} {\n\
02073 $dynamics_ drop-target [lindex $args 0]\n\
02074 } else {\n\
02075 $self instvar drophead_\n\
02076 $dynamics_ drop-target $drophead_\n\
02077 }\n\
02078 }\n\
02079 \n\
02080 SimpleLink instproc trace-callback {ns cmd} {\n\
02081 $self trace $ns {}\n\
02082 foreach part {enqT_ deqT_ drpT_ rcvT_} {\n\
02083 $self instvar $part\n\
02084 set to [$self set $part]\n\
02085 $to set callback_ 1\n\
02086 $to proc handle a \"$cmd \\$a\"\n\
02087 }\n\
02088 }\n\
02089 \n\
02090 SimpleLink instproc attach-monitors { insnoop outsnoop dropsnoop qmon } {\n\
02091 $self instvar drpT_ queue_ snoopIn_ snoopOut_ snoopDrop_\n\
02092 $self instvar qMonitor_ drophead_\n\
02093 \n\
02094 set snoopIn_ $insnoop\n\
02095 set snoopOut_ $outsnoop\n\
02096 set snoopDrop_ $dropsnoop\n\
02097 \n\
02098 $self add-to-head $snoopIn_\n\
02099 \n\
02100 $snoopOut_ target [$queue_ target]\n\
02101 $queue_ target $snoopOut_\n\
02102 \n\
02103 set nxt [$drophead_ target]\n\
02104 $drophead_ target $snoopDrop_\n\
02105 $snoopDrop_ target $nxt\n\
02106 \n\
02107 \n\
02108 $snoopIn_ set-monitor $qmon\n\
02109 $snoopOut_ set-monitor $qmon\n\
02110 $snoopDrop_ set-monitor $qmon\n\
02111 set qMonitor_ $qmon\n\
02112 }\n\
02113 \n\
02114 SimpleLink instproc attach-taggers { insnoop qmon } {\n\
02115 $self instvar drpT_ queue_ head_ snoopIn_ snoopOut_ snoopDrop_\n\
02116 $self instvar qMonitor_ drophead_\n\
02117 \n\
02118 set snoopIn_ $insnoop\n\
02119 \n\
02120 $snoopIn_ target $head_\n\
02121 set head_ $snoopIn_\n\
02122 \n\
02123 $snoopIn_ set-monitor $qmon\n\
02124 \n\
02125 \n\
02126 set qMonitor_ $qmon\n\
02127 \n\
02128 }\n\
02129 \n\
02130 SimpleLink instproc init-monitor { ns qtrace sampleInterval} {\n\
02131 $self instvar qMonitor_ ns_ qtrace_ sampleInterval_\n\
02132 \n\
02133 set ns_ $ns\n\
02134 set qtrace_ $qtrace\n\
02135 set sampleInterval_ $sampleInterval\n\
02136 set qMonitor_ [new QueueMonitor]\n\
02137 \n\
02138 $self attach-monitors [new SnoopQueue/In] \\\n\
02139 [new SnoopQueue/Out] [new SnoopQueue/Drop] $qMonitor_\n\
02140 \n\
02141 set bytesInt_ [new Integrator]\n\
02142 $qMonitor_ set-bytes-integrator $bytesInt_\n\
02143 set pktsInt_ [new Integrator]\n\
02144 $qMonitor_ set-pkts-integrator $pktsInt_\n\
02145 return $qMonitor_\n\
02146 }\n\
02147 \n\
02148 SimpleLink instproc start-tracing { } {\n\
02149 $self instvar qMonitor_ ns_ qtrace_ sampleInterval_\n\
02150 $self instvar fromNode_ toNode_\n\
02151 \n\
02152 if {$qtrace_ != 0} {\n\
02153 $qMonitor_ trace $qtrace_\n\
02154 }\n\
02155 $qMonitor_ set-src-dst [$fromNode_ id] [$toNode_ id]\n\
02156 } \n\
02157 \n\
02158 SimpleLink instproc queue-sample-timeout { } {\n\
02159 $self instvar qMonitor_ ns_ qtrace_ sampleInterval_\n\
02160 $self instvar fromNode_ toNode_\n\
02161 \n\
02162 set qavg [$self sample-queue-size]\n\
02163 if {$qtrace_ != 0} {\n\
02164 puts $qtrace_ \"[$ns_ now] [$fromNode_ id] [$toNode_ id] $qavg\"\n\
02165 }\n\
02166 $ns_ at [expr [$ns_ now] + $sampleInterval_] \"$self queue-sample-timeout\"\n\
02167 }\n\
02168 \n\
02169 SimpleLink instproc sample-queue-size { } {\n\
02170 $self instvar qMonitor_ ns_ qtrace_ sampleInterval_ lastSample_\n\
02171 \n\
02172 set now [$ns_ now]\n\
02173 set qBytesMonitor_ [$qMonitor_ get-bytes-integrator]\n\
02174 set qPktsMonitor_ [$qMonitor_ get-pkts-integrator]\n\
02175 \n\
02176 $qBytesMonitor_ newpoint $now [$qBytesMonitor_ set lasty_]\n\
02177 set bsum [$qBytesMonitor_ set sum_]\n\
02178 \n\
02179 $qPktsMonitor_ newpoint $now [$qPktsMonitor_ set lasty_]\n\
02180 set psum [$qPktsMonitor_ set sum_]\n\
02181 \n\
02182 if ![info exists lastSample_] {\n\
02183 set lastSample_ 0\n\
02184 }\n\
02185 set dur [expr $now - $lastSample_]\n\
02186 if { $dur != 0 } {\n\
02187 set meanBytesQ [expr $bsum / $dur]\n\
02188 set meanPktsQ [expr $psum / $dur]\n\
02189 } else {\n\
02190 set meanBytesQ 0\n\
02191 set meanPktsQ 0\n\
02192 }\n\
02193 $qBytesMonitor_ set sum_ 0.0\n\
02194 $qPktsMonitor_ set sum_ 0.0\n\
02195 set lastSample_ $now\n\
02196 \n\
02197 \n\
02198 $qMonitor_ instvar pdrops_ pdepartures_ parrivals_ bdrops_ bdepartures_ barrivals_\n\
02199 \n\
02200 return \"$meanBytesQ $meanPktsQ $parrivals_ $pdepartures_ $pdrops_ $barrivals_ $bdepartures_ $bdrops_\" \n\
02201 \n\
02202 }   \n\
02203 \n\
02204 \n\
02205 SimpleLink instproc dynamic {} {\n\
02206 $self instvar dynamics_\n\
02207 \n\
02208 if [info exists dynamics_] return\n\
02209 \n\
02210 set dynamics_ [new DynamicLink]\n\
02211 $self add-to-head $dynamics_\n\
02212 \n\
02213 $self transit-drop-trace\n\
02214 $self all-connectors isDynamic\n\
02215 }\n\
02216 \n\
02217 SimpleLink instproc errormodule args {\n\
02218 $self instvar errmodule_ queue_ drophead_\n\
02219 if { $args == \"\" } {\n\
02220 return $errmodule_\n\
02221 }\n\
02222 \n\
02223 set em [lindex $args 0]\n\
02224 set errmodule_ $em\n\
02225 \n\
02226 $self add-to-head $em\n\
02227 \n\
02228 $em drop-target $drophead_\n\
02229 }\n\
02230 \n\
02231 SimpleLink instproc insert-linkloss args { \n\
02232 $self instvar link_errmodule_ queue_ drophead_ deqT_ \n\
02233 if { $args == \"\" } {\n\
02234 return $link_errmodule_\n\
02235 }\n\
02236 \n\
02237 set em [lindex $args 0]\n\
02238 if [info exists link_errmodule_] {\n\
02239 delete link_errmodule_\n\
02240 }\n\
02241 set link_errmodule_ $em\n\
02242 \n\
02243 if [info exists deqT_] {\n\
02244 $em target [$deqT_ target]\n\
02245 $deqT_ target $em\n\
02246 } else {\n\
02247 $em target [$queue_ target]\n\
02248 $queue_ target $em\n\
02249 }\n\
02250 \n\
02251 $em drop-target $drophead_\n\
02252 }\n\
02253 \n\
02254 \n\
02255 \n\
02256 \n\
02257 \n\
02258 Class Application/FTP -superclass Application\n\
02259 \n\
02260 Application/FTP instproc init {} {\n\
02261 $self next\n\
02262 }\n\
02263 \n\
02264 Application/FTP instproc start {} {\n\
02265 [$self agent] send -1\n\
02266 }\n\
02267 \n\
02268 Application/FTP instproc stop {} {\n\
02269 [$self agent] advance 0\n\
02270 [$self agent] close\n\
02271 }\n\
02272 \n\
02273 Application/FTP instproc send {nbytes} {\n\
02274 [$self agent] send $nbytes\n\
02275 }\n\
02276 \n\
02277 Application/FTP instproc produce { pktcnt } {\n\
02278 [$self agent] advance $pktcnt\n\
02279 }\n\
02280 \n\
02281 Application/FTP instproc producemore { pktcnt } {\n\
02282 [$self agent] advanceby $pktcnt\n\
02283 }\n\
02284 \n\
02285 Application/Traffic instproc set args {\n\
02286 $self instvar packetSize_ rate_\n\
02287 if { [lindex $args 0] == \"packet_size_\" } {\n\
02288 if { [llength $args] == 2 } {\n\
02289 set packetSize_ [lindex $args 1]\n\
02290 return\n\
02291 } elseif { [llength $args] == 1 } {\n\
02292 return $packetSize_\n\
02293 }\n\
02294 }\n\
02295 eval $self next $args\n\
02296 }\n\
02297 Application/Traffic/CBR instproc set args {\n\
02298 $self instvar packetSize_ rate_\n\
02299 if { [lindex $args 0] == \"interval_\" } {\n\
02300 if { [llength $args] == 2 } {\n\
02301 set ns_ [Simulator instance]\n\
02302 set interval_ [$ns_ delay_parse [lindex $args 1]]\n\
02303 $self set rate_ [expr $packetSize_ * 8.0/$interval_]\n\
02304 return\n\
02305 } elseif { [llength $args] == 1 } {\n\
02306 return [expr $packetSize_ * 8.0/$rate_]\n\
02307 }\n\
02308 }\n\
02309 eval $self next $args\n\
02310 }\n\
02311 \n\
02312 \n\
02313 Class Agent/CBR -superclass Agent/UDP\n\
02314 Class Agent/CBR/UDP -superclass Agent/UDP\n\
02315 Class Agent/CBR/RTP -superclass Agent/RTP\n\
02316 Class Agent/CBR/UDP/SA -superclass Agent/SA\n\
02317 \n\
02318 Agent/SA instproc attach-traffic tg {\n\
02319 $tg attach-agent $self\n\
02320 eval $self cmd attach-traffic $tg\n\
02321 }\n\
02322 \n\
02323 Agent/CBR/UDP instproc attach-traffic tg {\n\
02324 $self instvar trafgen_\n\
02325 $tg attach-agent $self\n\
02326 set trafgen_ $tg\n\
02327 }\n\
02328 \n\
02329 Agent/CBR/UDP instproc done {} { }\n\
02330 \n\
02331 Agent/CBR/UDP instproc start {} {\n\
02332 $self instvar trafgen_\n\
02333 $trafgen_ start\n\
02334 }\n\
02335 \n\
02336 Agent/CBR/UDP instproc stop {} {\n\
02337 $self instvar trafgen_\n\
02338 $trafgen_ stop\n\
02339 }\n\
02340 \n\
02341 Agent/CBR/UDP instproc advance args {\n\
02342 $self instvar trafgen_\n\
02343 eval $trafgen_ advance $args\n\
02344 }\n\
02345 \n\
02346 Agent/CBR/UDP instproc advanceby args {\n\
02347 $self instvar trafgen_\n\
02348 eval $trafgen_ advanceby $args\n\
02349 }\n\
02350 \n\
02351 Agent/CBR instproc init {} {\n\
02352 $self next\n\
02353 $self instvar trafgen_ interval_ random_ packetSize_ maxpkts_\n\
02354 set packetSize_ 210\n\
02355 set random_ 0\n\
02356 set maxpkts_ 268435456  \n\
02357 set interval_ 0.00375\n\
02358 set trafgen_ [new Application/Traffic/CBR]\n\
02359 $trafgen_ attach-agent $self\n\
02360 $trafgen_ set rate_ [expr $packetSize_ * 8.0/ $interval_]\n\
02361 $trafgen_ set random_ [$self set random_]\n\
02362 $trafgen_ set maxpkts_ [$self set maxpkts_]\n\
02363 $trafgen_ set packetSize_ [$self set packetSize_]\n\
02364 if {[Simulator set nsv1flag] == 0} { \n\
02365 \n\
02366 puts \"using backward compatible Agent/CBR; use Application/Traffic/CBR instead\"\n\
02367 }    \n\
02368 }\n\
02369 \n\
02370 \n\
02371 \n\
02372 Agent/CBR instproc done {} { }\n\
02373 \n\
02374 Agent/CBR instproc start {} {\n\
02375 $self instvar trafgen_\n\
02376 $trafgen_ start\n\
02377 }\n\
02378 \n\
02379 Agent/CBR instproc stop {} {\n\
02380 $self instvar trafgen_\n\
02381 $trafgen_ stop\n\
02382 }\n\
02383 \n\
02384 Agent/CBR instproc advance args {\n\
02385 $self instvar trafgen_\n\
02386 eval $trafgen_ advance $args\n\
02387 }\n\
02388 \n\
02389 Agent/CBR instproc advanceby args {\n\
02390 $self instvar trafgen_\n\
02391 eval $trafgen_ advanceby $args\n\
02392 }\n\
02393 \n\
02394 Agent/CBR instproc set args {\n\
02395 $self instvar interval_ random_ packetSize_ maxpkts_ trafgen_\n\
02396 if { [info exists trafgen_] } {\n\
02397 if { [lindex $args 0] == \"packetSize_\" } {\n\
02398 if { [llength $args] == 2 } {\n\
02399 $trafgen_ set packetSize_ [lindex $args 1]\n\
02400 set packetSize_ [lindex $args 1]\n\
02401 $trafgen_ set rate_ [expr $packetSize_ * 8.0/ $interval_]\n\
02402 return \n\
02403 } elseif { [llength $args] == 1 } {\n\
02404 return $packetSize_\n\
02405 }\n\
02406 } elseif { [lindex $args 0] == \"random_\" } {\n\
02407 if { [llength $args] == 2 } {\n\
02408 $trafgen_ set random_ [lindex $args 1]\n\
02409 set random_ [lindex $args 1]\n\
02410 return\n\
02411 } elseif { [llength $args] == 1 } {\n\
02412 return $random_\n\
02413 }\n\
02414 } elseif { [lindex $args 0] == \"maxpkts_\" } {\n\
02415 if { [llength $args] == 2 } {\n\
02416 $trafgen_ set maxpkts_ [lindex $args 1]\n\
02417 set maxpkts_ [lindex $args 1]\n\
02418 return\n\
02419 } elseif { [llength $args] == 1 } {\n\
02420 return $maxpkts_\n\
02421 }\n\
02422 } elseif { [lindex $args 0] == \"interval_\" } {\n\
02423 if { [llength $args] == 2 } {\n\
02424 set ns_ [Simulator instance]\n\
02425 set interval_ [$ns_ delay_parse [lindex $args 1]]\n\
02426 $trafgen_ set rate_ [expr $packetSize_ * 8.0/ $interval_]\n\
02427 return\n\
02428 } elseif { [llength $args] == 1 } {\n\
02429 return $interval_\n\
02430 }\n\
02431 }\n\
02432 }\n\
02433 eval $self next $args\n\
02434 }\n\
02435 \n\
02436 Class Traffic/Expoo -superclass Application/Traffic/Exponential\n\
02437 Class Traffic/Pareto -superclass Application/Traffic/Pareto\n\
02438 Class Traffic/RealAudio -superclass Application/Traffic/RealAudio\n\
02439 Class Traffic/Trace -superclass Application/Traffic/Trace\n\
02440 \n\
02441 Traffic/Expoo instproc set args {\n\
02442 $self instvar packetSize_ burst_time_ idle_time_ rate_ \n\
02443 if { [lindex $args 0] == \"packet-size\" } {\n\
02444 if { [llength $args] == 2 } {\n\
02445 $self set packetSize_ [lindex $args 1]\n\
02446 return \n\
02447 } elseif { [llength $args] == 1 } {\n\
02448 return $packetSize_\n\
02449 }\n\
02450 } elseif { [lindex $args 0] == \"burst-time\" } {\n\
02451 if { [llength $args] == 2 } {\n\
02452 $self set burst_time_ [lindex $args 1]\n\
02453 return \n\
02454 } elseif { [llength $args] == 1 } {\n\
02455 return $burst_time_\n\
02456 }\n\
02457 } elseif { [lindex $args 0] == \"idle-time\" } {\n\
02458 if { [llength $args] == 2 } {\n\
02459 $self set idle_time_ [lindex $args 1]\n\
02460 return \n\
02461 } elseif { [llength $args] == 1 } {\n\
02462 return $idle_time_\n\
02463 }\n\
02464 } elseif { [lindex $args 0] == \"rate\" } {\n\
02465 if { [llength $args] == 2 } {\n\
02466 $self set rate_ [lindex $args 1]\n\
02467 return \n\
02468 } elseif { [llength $args] == 1 } {\n\
02469 return $rate_\n\
02470 }\n\
02471 }\n\
02472 eval $self next $args\n\
02473 }\n\
02474 \n\
02475 Traffic/Pareto instproc set args {\n\
02476 $self instvar packetSize_ burst_time_ idle_time_ rate_ shape_\n\
02477 if { [lindex $args 0] == \"packet-size\" } {\n\
02478 if { [llength $args] == 2 } {\n\
02479 $self set packetSize_ [lindex $args 1]\n\
02480 return \n\
02481 } elseif { [llength $args] == 1 } {\n\
02482 return $packetSize_\n\
02483 }\n\
02484 } elseif { [lindex $args 0] == \"burst-time\" } {\n\
02485 if { [llength $args] == 2 } {\n\
02486 $self set burst_time_ [lindex $args 1]\n\
02487 return \n\
02488 } elseif { [llength $args] == 1 } {\n\
02489 return $burst_time_\n\
02490 }\n\
02491 } elseif { [lindex $args 0] == \"idle-time\" } {\n\
02492 if { [llength $args] == 2 } {\n\
02493 $self set idle_time_ [lindex $args 1]\n\
02494 return \n\
02495 } elseif { [llength $args] == 1 } {\n\
02496 return $idle_time_\n\
02497 }\n\
02498 } elseif { [lindex $args 0] == \"rate\" } {\n\
02499 if { [llength $args] == 2 } {\n\
02500 $self set rate_ [lindex $args 1]\n\
02501 return \n\
02502 } elseif { [llength $args] == 1 } {\n\
02503 return $rate_\n\
02504 }\n\
02505 } elseif { [lindex $args 0] == \"shape\" } {\n\
02506 if { [llength $args] == 2 } {\n\
02507 $self set shape_ [lindex $args 1]\n\
02508 return \n\
02509 } elseif { [llength $args] == 1 } {\n\
02510 return $shape_\n\
02511 }\n\
02512 }\n\
02513 eval $self next $args\n\
02514 }\n\
02515 \n\
02516 Traffic/RealAudio instproc set args {\n\
02517 $self instvar packetSize_ burst_time_ idle_time_ rate_ \n\
02518 if { [lindex $args 0] == \"packet-size\" } {\n\
02519 if { [llength $args] == 2 } {\n\
02520 $self set packetSize_ [lindex $args 1]\n\
02521 return \n\
02522 } elseif { [llength $args] == 1 } {\n\
02523 return $packetSize_\n\
02524 }\n\
02525 } elseif { [lindex $args 0] == \"burst-time\" } {\n\
02526 if { [llength $args] == 2 } {\n\
02527 $self set burst_time_ [lindex $args 1]\n\
02528 return \n\
02529 } elseif { [llength $args] == 1 } {\n\
02530 return $burst_time_\n\
02531 }\n\
02532 } elseif { [lindex $args 0] == \"idle-time\" } {\n\
02533 if { [llength $args] == 2 } {\n\
02534 $self set idle_time_ [lindex $args 1]\n\
02535 return \n\
02536 } elseif { [llength $args] == 1 } {\n\
02537 return $idle_time_\n\
02538 }\n\
02539 } elseif { [lindex $args 0] == \"rate\" } {\n\
02540 if { [llength $args] == 2 } {\n\
02541 $self set rate_ [lindex $args 1]\n\
02542 return \n\
02543 } elseif { [llength $args] == 1 } {\n\
02544 return $rate_\n\
02545 }\n\
02546 }\n\
02547 eval $self next $args\n\
02548 }\n\
02549 \n\
02550 Class Source/FTP -superclass Application\n\
02551 Source/FTP set maxpkts_ 268435456\n\
02552 \n\
02553 Source/FTP instproc attach o {\n\
02554 $self instvar agent_\n\
02555 set agent_ $o\n\
02556 $self attach-agent $o\n\
02557 }\n\
02558 \n\
02559 Source/FTP instproc init {} {\n\
02560 $self next\n\
02561 $self instvar maxpkts_ agent_\n\
02562 set maxpkts_ 268435456\n\
02563 }\n\
02564 \n\
02565 Source/FTP instproc start {} {\n\
02566 $self instvar agent_ maxpkts_\n\
02567 $agent_ advance $maxpkts_\n\
02568 }\n\
02569 \n\
02570 Source/FTP instproc stop {} {\n\
02571 $self instvar agent_\n\
02572 $agent_ advance 0\n\
02573 }\n\
02574 \n\
02575 Source/FTP instproc produce { pktcnt } {\n\
02576 $self instvar agent_ \n\
02577 $agent_ advance $pktcnt\n\
02578 }\n\
02579 \n\
02580 Source/FTP instproc producemore { pktcnt } {\n\
02581 $self instvar agent_\n\
02582 $agent_ advanceby $pktcnt\n\
02583 }\n\
02584 \n\
02585 \n\
02586 Class Source/Telnet -superclass Application/Telnet\n\
02587 \n\
02588 Source/Telnet set maxpkts_ 268435456\n\
02589 \n\
02590 Source/Telnet instproc attach o {\n\
02591 $self instvar agent_\n\
02592 set agent_ $o\n\
02593 $self attach-agent $o\n\
02594 }\n\
02595 \n\
02596 \n\
02597 Class OldSim -superclass Simulator\n\
02598 \n\
02599 proc ns args {\n\
02600 OldSim ns\n\
02601 eval ns $args\n\
02602 }\n\
02603 \n\
02604 OldSim instproc default_catch { varName index op } {\n\
02605 if { $index == \"\" } {\n\
02606 error \"ns-1 compat: default change caught, but not a default! (varName: $varName)\"\n\
02607 exit 1\n\
02608 }\n\
02609 \n\
02610 if { $op == \"r\" || $op == \"u\" } {\n\
02611 error \"ns-1 compat: default change caught a $op operation\"\n\
02612 exit 1\n\
02613 }\n\
02614 set vname ${varName}($index)\n\
02615 upvar $vname var\n\
02616 $self default_assign $varName $index $var\n\
02617 }\n\
02618 \n\
02619 \n\
02620 OldSim instproc default_assign {aname index newval} {\n\
02621 $self instvar classMap_ queueMap_\n\
02622 if { $index == \"\" } {\n\
02623 puts \"something funny with default traces\"\n\
02624 exit 1\n\
02625 }\n\
02626 set obj [string trimleft $aname ns_]\n\
02627 if { $obj == \"link\" } {\n\
02628 if { $index == \"queue-limit\" } {\n\
02629 Queue set limit_ $newval\n\
02630 return\n\
02631 }\n\
02632 set ivar \"$index\\_\"\n\
02633 if { [lsearch [DelayLink info vars] $ivar] >= 0 } {\n\
02634 DelayLink set $ivar $newval\n\
02635 return\n\
02636 }\n\
02637 error \"warning: ns-1 compatibility library cannot set link default ${aname}($index)\"\n\
02638 return\n\
02639 }\n\
02640 \n\
02641 if ![info exists classMap_($obj)] {\n\
02642 if ![info exists queueMap_($obj)] {\n\
02643 puts \"error: ns-2 compatibility library cannot set ns-v1 default ${aname}($index)\"\n\
02644 exit 1\n\
02645 } else {\n\
02646 set ns2obj \"Queue/$queueMap_($obj)\"\n\
02647 }\n\
02648 } else {\n\
02649 set ns2obj $classMap_($obj)\n\
02650 }\n\
02651 SplitObject instvar varMap_ \n\
02652 if ![info exists varMap_($index)] {\n\
02653 puts \"error: ns-2 compatibility library cannot map instvar $index in class $ns2obj\"\n\
02654 exit 1\n\
02655 }\n\
02656 $ns2obj set $varMap_($index) $newval\n\
02657 \n\
02658 }\n\
02659 \n\
02660 OldSim instproc map_ns_defaults old_arr {\n\
02661 global $old_arr ; # these were all globals in ns-1\n\
02662 SplitObject instvar varMap_\n\
02663 \n\
02664 foreach el [array names $old_arr] {\n\
02665 set val [expr \"$${old_arr}($el)\"]\n\
02666 $self default_assign $old_arr $el $val\n\
02667 }\n\
02668 \n\
02669 trace variable $old_arr rwu \"$self default_catch\"\n\
02670 }\n\
02671 \n\
02672 OldSim instproc trace_old_defaults {} {\n\
02673 $self map_ns_defaults ns_tcp\n\
02674 $self map_ns_defaults ns_tcpnewreno\n\
02675 $self map_ns_defaults ns_trace\n\
02676 $self map_ns_defaults ns_fulltcp\n\
02677 $self map_ns_defaults ns_red\n\
02678 $self map_ns_defaults ns_cbq\n\
02679 $self map_ns_defaults ns_class\n\
02680 $self map_ns_defaults ns_sink\n\
02681 $self map_ns_defaults ns_delsink\n\
02682 $self map_ns_defaults ns_sacksink\n\
02683 $self map_ns_defaults ns_cbr\n\
02684 $self map_ns_defaults ns_rlm\n\
02685 $self map_ns_defaults ns_ivs\n\
02686 $self map_ns_defaults ns_source\n\
02687 $self map_ns_defaults ns_telnet\n\
02688 $self map_ns_defaults ns_bursty\n\
02689 $self map_ns_defaults ns_message\n\
02690 $self map_ns_defaults ns_facktcp\n\
02691 $self map_ns_defaults ns_link\n\
02692 $self map_ns_defaults ns_lossy_uniform\n\
02693 $self map_ns_defaults ns_lossy_patt\n\
02694 $self map_ns_defaults ns_queue\n\
02695 $self map_ns_defaults ns_srm\n\
02696 }\n\
02697 \n\
02698 OldSim instproc init args {\n\
02699 eval $self next $args\n\
02700 puts stderr \"warning: using backward compatibility mode\"\n\
02701 $self instvar classMap_\n\
02702 \n\
02703 Simulator set nsv1flag 1\n\
02704 \n\
02705 $self instvar scheduler_\n\
02706 set scheduler_ [new Scheduler/List]\n\
02707 \n\
02708 Queue/CBQ instproc set args {\n\
02709 $self instvar compat_qlim_\n\
02710 if { [lindex $args 0] == \"queue-limit\" || \\\n\
02711 [lindex $args 0] == \"limit_\" } { \n\
02712 if { [llength $args] == 2 } {\n\
02713 set val [lindex $args 1]\n\
02714 set compat_qlim_ $val\n\
02715 return $val\n\
02716 }\n\
02717 return $compat_qlim_\n\
02718 } elseif { [lindex $args 0] == \"algorithm_\" } {\n\
02719 $self algorithm [lindex $args 1]\n\
02720 }\n\
02721 eval $self next $args\n\
02722 }\n\
02723 Queue/DropTail instproc set args {\n\
02724 if { [llength $args] == 2 &&\n\
02725 [lindex $args 0] == \"queue-limit\" } {\n\
02726 $self set limit_ [lindex $args 1]\n\
02727 return\n\
02728 }\n\
02729 eval $self next $args\n\
02730 }\n\
02731 Queue/RED instproc set args {\n\
02732 if { [llength $args] == 2 &&\n\
02733 [lindex $args 0] == \"queue-limit\" } {\n\
02734 $self set limit_ [lindex $args 1]\n\
02735 return\n\
02736 }\n\
02737 eval $self next $args\n\
02738 }\n\
02739 Queue/RED instproc enable-vartrace file {\n\
02740 $self trace ave_\n\
02741 $self trace prob_\n\
02742 $self trace curq_\n\
02743 $self attach $file\n\
02744 }\n\
02745 Source/FTP instproc set args {\n\
02746 if { [llength $args] == 2 &&\n\
02747 [lindex $args 0] == \"maxpkts\" } {\n\
02748 $self set maxpkts_ [lindex $args 1]\n\
02749 return\n\
02750 }\n\
02751 eval $self next $args\n\
02752 }\n\
02753 Source/Telnet instproc set args {\n\
02754 if { [llength $args] == 2 &&\n\
02755 [lindex $args 0] == \"interval\" } {\n\
02756 $self set interval_ [lindex $args 1]\n\
02757 return\n\
02758 }\n\
02759 eval $self next $args\n\
02760 }\n\
02761 Agent/TCP instproc source type {\n\
02762 if { $type == \"ftp\" } {\n\
02763 set type FTP\n\
02764 }\n\
02765 if { $type == \"telnet\" } {\n\
02766 set type Telnet\n\
02767 }\n\
02768 set src [new Source/$type]\n\
02769 $src attach $self\n\
02770 return $src\n\
02771 }\n\
02772 Agent/TCP set restart_bugfix_ false\n\
02773 SplitObject instproc set args {\n\
02774 SplitObject instvar varMap_\n\
02775 set var [lindex $args 0] \n\
02776 if [info exists varMap_($var)] {\n\
02777 set var $varMap_($var)\n\
02778 set args \"$var [lrange $args 1 end]\"\n\
02779 }\n\
02780 $self instvar -parse-part1 $var\n\
02781 if {[llength $args] == 1} {\n\
02782 return [subst $[subst $var]]\n\
02783 } else {\n\
02784 return [set $var [lrange $args 1 end]]\n\
02785 }\n\
02786 }\n\
02787 SplitObject instproc get {var} {\n\
02788 SplitObject instvar varMap_\n\
02789 if [info exists varMap_($var)] {\n\
02790 return [$self set $varMap_($var)]\n\
02791 } else {\n\
02792 return [$self next $var]\n\
02793 }\n\
02794 }\n\
02795 TclObject set varMap_(addr) addr_\n\
02796 TclObject set varMap_(dst) dst_\n\
02797 TclObject set varMap_(cls) fid_\n\
02798 \n\
02799 TclObject set varMap_(src) src_\n\
02800 TclObject set varMap_(show_tcphdr) show_tcphdr_\n\
02801 \n\
02802 TclObject set varMap_(window) window_\n\
02803 TclObject set varMap_(window-init) windowInit_\n\
02804 TclObject set varMap_(window-option) windowOption_\n\
02805 TclObject set varMap_(window-constant) windowConstant_\n\
02806 TclObject set varMap_(window-thresh) windowThresh_\n\
02807 TclObject set varMap_(overhead) overhead_\n\
02808 TclObject set varMap_(tcp-tick) tcpTick_\n\
02809 TclObject set varMap_(ecn) ecn_\n\
02810 TclObject set varMap_(bug-fix) bugFix_\n\
02811 TclObject set varMap_(maxburst) maxburst_\n\
02812 TclObject set varMap_(maxcwnd) maxcwnd_\n\
02813 TclObject set varMap_(dupacks) dupacks_\n\
02814 TclObject set varMap_(seqno) seqno_\n\
02815 TclObject set varMap_(ack) ack_\n\
02816 TclObject set varMap_(cwnd) cwnd_\n\
02817 TclObject set varMap_(awnd) awnd_\n\
02818 TclObject set varMap_(ssthresh) ssthresh_\n\
02819 TclObject set varMap_(rtt) rtt_\n\
02820 TclObject set varMap_(srtt) srtt_\n\
02821 TclObject set varMap_(rttvar) rttvar_\n\
02822 TclObject set varMap_(backoff) backoff_\n\
02823 TclObject set varMap_(v-alpha) v_alpha_\n\
02824 TclObject set varMap_(v-beta) v_beta_\n\
02825 TclObject set varMap_(v-gamma) v_gamma_\n\
02826 \n\
02827 TclObject set varMap_(changes) newreno_changes_\n\
02828 \n\
02829 TclObject set varMap_(rampdown) rampdown_ \n\
02830 TclObject set varMap_(ss-div4) ss-div4_\n\
02831 \n\
02832 TclObject set varMap_(limit) limit_\n\
02833 \n\
02834 TclObject set varMap_(limit) maxqueue_\n\
02835 TclObject set varMap_(buckets) buckets_\n\
02836 \n\
02837 TclObject set varMap_(bytes) bytes_\n\
02838 TclObject set varMap_(thresh) thresh_\n\
02839 TclObject set varMap_(maxthresh) maxthresh_\n\
02840 TclObject set varMap_(mean_pktsize) meanPacketSize_\n\
02841 TclObject set varMap_(q_weight) queueWeight_\n\
02842 TclObject set varMap_(wait) wait_\n\
02843 TclObject set varMap_(linterm) linterm_\n\
02844 TclObject set varMap_(setbit) setbit_\n\
02845 TclObject set varMap_(drop-tail) dropTail_\n\
02846 TclObject set varMap_(doubleq) doubleq_\n\
02847 TclObject set varMap_(dqthresh) dqthresh_\n\
02848 TclObject set varMap_(subclasses) subclasses_\n\
02849 TclObject set varMap_(algorithm) algorithm_\n\
02850 TclObject set varMap_(max-pktsize) maxpkt_\n\
02851 TclObject set varMap_(priority) priority_\n\
02852 TclObject set varMap_(maxidle) maxidle_\n\
02853 TclObject set varMap_(extradelay) extradelay_\n\
02854 \n\
02855 TclObject set varMap_(packet-size) packetSize_\n\
02856 TclObject set varMap_(interval) interval_\n\
02857 \n\
02858 TclObject set varMap_(random) random_\n\
02859 \n\
02860 TclObject set varMap_(S) S_\n\
02861 TclObject set varMap_(R) R_\n\
02862 TclObject set varMap_(state) state_\n\
02863 TclObject set varMap_(rttShift) rttShift_\n\
02864 TclObject set varMap_(keyShift) keyShift_\n\
02865 TclObject set varMap_(key) key_\n\
02866 TclObject set varMap_(maxrtt) maxrtt_\n\
02867 \n\
02868 Class traceHelper\n\
02869 traceHelper instproc attach f {\n\
02870 $self instvar file_\n\
02871 set file_ $f\n\
02872 }\n\
02873 \n\
02874 Class linkHelper\n\
02875 linkHelper instproc init args {\n\
02876 $self instvar node1_ node2_ linkref_ queue_\n\
02877 set node1_ [lindex $args 0]\n\
02878 set node2_ [lindex $args 1]\n\
02879 set lid [$node1_ id]:[$node2_ id]       \n\
02880 set linkref_ [ns set link_($lid)]\n\
02881 set queue_ [$linkref_ queue]\n\
02882 set sqi [new SnoopQueue/In]\n\
02883 set sqo [new SnoopQueue/Out]\n\
02884 set sqd [new SnoopQueue/Drop]\n\
02885 set dsamples [new Samples]\n\
02886 set qmon [new QueueMonitor/Compat]\n\
02887 $qmon set-delay-samples $dsamples\n\
02888 $linkref_ attach-monitors $sqi $sqo $sqd $qmon\n\
02889 $linkref_ set bytesInt_ [new Integrator]\n\
02890 $linkref_ set pktsInt_ [new Integrator]\n\
02891 $qmon set-bytes-integrator [$linkref_ set bytesInt_]\n\
02892 $qmon set-pkts-integrator [$linkref_ set pktsInt_]\n\
02893 }\n\
02894 linkHelper instproc trace traceObj {\n\
02895 $self instvar node1_ node2_\n\
02896 $self instvar queue_\n\
02897 set tfile [$traceObj set file_]\n\
02898 ns trace-queue $node1_ $node2_ $tfile\n\
02899 if { [string first Queue/RED [$queue_ info class]] == 0 } {\n\
02900 $queue_ enable-vartrace $tfile\n\
02901 }\n\
02902 }\n\
02903 linkHelper instproc callback {fn} {\n\
02904 $self instvar linkref_\n\
02905 foreach part {enqT_ deqT_ drpT_} {\n\
02906 set to [$linkref_ set $part]\n\
02907 $to set callback_ 1\n\
02908 $to proc handle {args} \"$fn \\$args\"\n\
02909 }\n\
02910 }\n\
02911 linkHelper instproc set { var val } {\n\
02912 \n\
02913 $self instvar linkref_ queue_\n\
02914 set qvars [$queue_ info vars]\n\
02915 set linkvars [$linkref_ info vars]\n\
02916 set linkdelayvars [[$linkref_ link] info vars]\n\
02917 if { [string last _ $var] != ( [string length $var] - 1) } {\n\
02918 set var ${var}_\n\
02919 }\n\
02920 if { $var == \"queue-limit_\" } {\n\
02921 set var \"limit_\"\n\
02922 }\n\
02923 if { [lsearch $qvars $var] >= 0 } {\n\
02924 $queue_ set $var $val\n\
02925 } elseif { [lsearch $linkvars $var] >= 0 } {\n\
02926 $linkref_ set $var $val\n\
02927 } elseif { [lsearch $linkdelayvars $var] >= 0 } {\n\
02928 [$linkref_ link] set $var $val\n\
02929 } else {\n\
02930 puts stderr \"linkHelper warning: couldn't set unknown variable $var\"\n\
02931 }\n\
02932 }\n\
02933 \n\
02934 linkHelper instproc get var {\n\
02935 \n\
02936 $self instvar linkref_ queue_\n\
02937 set qvars [$queue_ info vars]\n\
02938 set linkvars [$linkref_ info vars]\n\
02939 set linkdelayvars [[$linkref_ link] info vars]\n\
02940 if { [string last _ $var] != ( [string length $var] - 1) } {\n\
02941 set var ${var}_\n\
02942 }\n\
02943 if { $var == \"queue-limit_\" } {\n\
02944 set var \"limit_\"\n\
02945 }\n\
02946 if { [lsearch $qvars $var] >= 0 } {\n\
02947 return [$queue_ set $var]\n\
02948 } elseif { [lsearch $linkvars $var] >= 0 } {\n\
02949 return [$linkref_ set $var]\n\
02950 } elseif { [lsearch $linkdelayvars $var] >= 0 } {\n\
02951 return [[$linkref_ link] set $var]\n\
02952 } else {\n\
02953 puts stderr \"linkHelper warning: couldn't set unknown variable $var\"\n\
02954 return \"\"\n\
02955 }\n\
02956 return \"\"\n\
02957 }\n\
02958 \n\
02959 linkHelper instproc try { obj operation argv } {\n\
02960 set op [eval list $obj $operation $argv]\n\
02961 set ocl [$obj info class]\n\
02962 set iprocs [$ocl info instcommands]\n\
02963 set oprocs [$obj info commands]\n\
02964 if { $operation != \"cmd\" } {\n\
02965 if { [lsearch $iprocs $operation] >= 0 } {\n\
02966 return [eval $op]\n\
02967 }\n\
02968 if { [lsearch $oprocs $operation] >= 0 } {\n\
02969 return [eval $op]\n\
02970 }\n\
02971 }\n\
02972 if [catch $op ret] {\n\
02973 return -1\n\
02974 }\n\
02975 return $ret\n\
02976 }\n\
02977 linkHelper instproc unknown { m args } {\n\
02978 $self instvar linkref_ queue_\n\
02979 set oldbody [TclObject info instbody unknown]\n\
02980 TclObject instproc unknown args {\n\
02981 if { [lindex $args 0] == \"cmd\" } {\n\
02982 puts stderr \"Can't dispatch $args\"\n\
02983 exit 1\n\
02984 }\n\
02985 eval $self cmd $args\n\
02986 }\n\
02987 \n\
02988 set rval [$self try $queue_ $m $args]\n\
02989 if { $rval != -1 } {\n\
02990 TclObject instproc unknown args $oldbody\n\
02991 return $rval\n\
02992 }\n\
02993 set rval [$self try $queue_ cmd [list $m $args]]\n\
02994 if { $rval != -1 } {\n\
02995 TclObject instproc unknown args $oldbody\n\
02996 return $rval\n\
02997 }\n\
02998 set rval [$self try $linkref_ $m $args]\n\
02999 if { $rval != -1 } {\n\
03000 TclObject instproc unknown args $oldbody\n\
03001 return $rval\n\
03002 }\n\
03003 set rval [$self try $linkref_ cmd [list $m $args]]\n\
03004 if { $rval != -1 } {\n\
03005 TclObject instproc unknown args $oldbody\n\
03006 return $rval\n\
03007 }\n\
03008 set dlink [$linkref_ link]\n\
03009 set rval [$self try $dlink $m $args]\n\
03010 if { $rval != -1 } {\n\
03011 TclObject instproc unknown args $oldbody\n\
03012 return $rval\n\
03013 }\n\
03014 set rval [$self try $dlink cmd [list $m $args]]\n\
03015 if { $rval != -1 } {\n\
03016 TclObject instproc unknown args $oldbody\n\
03017 return $rval\n\
03018 }\n\
03019 TclObject instproc unknown args $oldbody\n\
03020 puts stderr \"Unknown operation $m or subbordinate operation failed\"\n\
03021 exit 1\n\
03022 }\n\
03023 linkHelper instproc stat { classid item } {\n\
03024 $self instvar linkref_\n\
03025 set qmon [$linkref_ set qMonitor_]\n\
03026 if { $item == \"packets\" } {\n\
03027 return [$qmon pkts $classid]\n\
03028 } elseif { $item == \"bytes\" } {\n\
03029 return [$qmon bytes $classid]\n\
03030 } elseif { $item == \"drops\"} {\n\
03031 return [$qmon drops $classid]\n\
03032 } elseif { $item == \"mean-qdelay\" } {\n\
03033 set dsamp [$qmon get-class-delay-samples $classid]\n\
03034 if { [$dsamp cnt] > 0 } {\n\
03035 return [$dsamp mean]\n\
03036 } else {\n\
03037 return NaN\n\
03038 }\n\
03039 } else {\n\
03040 puts stderr \"linkHelper: unknown stat op $item\"\n\
03041 exit 1\n\
03042 }\n\
03043 }\n\
03044 linkHelper instproc integral { itype } {\n\
03045 $self instvar linkref_\n\
03046 if { $itype == \"qsize\" } {\n\
03047 set integ [$linkref_ set bytesInt_]\n\
03048 } elseif { $itype == \"qlen\" } {\n\
03049 set integ [$linkref_ set pktsInt_]\n\
03050 }\n\
03051 \n\
03052 return [$integ set sum_]\n\
03053 }\n\
03054 \n\
03055 \n\
03056 set classMap_(tcp) Agent/TCP\n\
03057 set classMap_(tcp-reno) Agent/TCP/Reno\n\
03058 set classMap_(tcp-vegas) Agent/TCP/Vegas\n\
03059 set classMap_(tcp-full) Agent/TCP/FullTcp\n\
03060 set classMap_(fulltcp) Agent/TCP/FullTcp\n\
03061 set classMap_(tcp-fack) Agent/TCP/Fack\n\
03062 set classMap_(facktcp) Agent/TCP/Fack\n\
03063 set classMap_(tcp-newreno) Agent/TCP/Newreno\n\
03064 set classMap_(tcpnewreno) Agent/TCP/Newreno\n\
03065 set classMap_(cbr) Agent/CBR\n\
03066 set classMap_(tcp-sink) Agent/TCPSink\n\
03067 set classMap_(tcp-sack1) Agent/TCP/Sack1\n\
03068 set classMap_(sack1-tcp-sink) Agent/TCPSink/Sack1\n\
03069 set classMap_(tcp-sink-da) Agent/TCPSink/DelAck\n\
03070 set classMap_(sack1-tcp-sink-da) Agent/TCPSink/Sack1/DelAck\n\
03071 set classMap_(sink) Agent/TCPSink\n\
03072 set classMap_(delsink) Agent/TCPSink/DelAck\n\
03073 set classMap_(sacksink) Agent/TCPSink ; # sacksink becomes TCPSink here\n\
03074 set classMap_(loss-monitor) Agent/LossMonitor\n\
03075 set classMap_(class) CBQClass\n\
03076 set classMap_(ivs) Agent/IVS/Source\n\
03077 set classMap_(trace) Trace\n\
03078 set classMap_(srm) Agent/SRM\n\
03079 \n\
03080 $self instvar queueMap_\n\
03081 set queueMap_(drop-tail) DropTail\n\
03082 set queueMap_(sfq) SFQ\n\
03083 set queueMap_(red) RED\n\
03084 set queueMap_(cbq) CBQ\n\
03085 set queueMap_(wrr-cbq) CBQ/WRR\n\
03086 \n\
03087 $self trace_old_defaults\n\
03088 \n\
03089 global tcl_version\n\
03090 if {$tcl_version < 8} {\n\
03091 set class_name \"class\"\n\
03092 } else {\n\
03093 set class_name \"::class\"\n\
03094 }\n\
03095 proc $class_name args {\n\
03096 set arglen [llength $args]\n\
03097 if { $arglen < 2 } {\n\
03098 return\n\
03099 }\n\
03100 set op [lindex $args 0]\n\
03101 set id [lindex $args 1]\n\
03102 if { $op != \"create\" } {\n\
03103 error \"ns-v1 compat: malformed class operation: op $op\"\n\
03104 return\n\
03105 }\n\
03106 eval CBQClass create $id [lrange $args 2 [expr $arglen - 1]]\n\
03107 }\n\
03108 }\n\
03109 \n\
03110 OldSim instproc simplex-link-compat { n1 n2 bw delay qtype } {\n\
03111 $self simplex-link $n1 $n2 $bw $delay $qtype\n\
03112 $self link-twoargs $n1 $n2 ;#maybe this is not needed, whatever...\n\
03113 }\n\
03114 \n\
03115 OldSim instproc duplex-link-compat { n1 n2 bw delay type } {\n\
03116 ns simplex-link-compat $n1 $n2 $bw $delay $type\n\
03117 ns simplex-link-compat $n2 $n1 $bw $delay $type\n\
03118 }\n\
03119 \n\
03120 OldSim instproc get-queues { n1 n2 } {\n\
03121 $self instvar link_\n\
03122 set n1 [$n1 id]\n\
03123 set n2 [$n2 id]\n\
03124 return \"[$link_($n1:$n2) queue] [$link_($n2:$n1) queue]\"\n\
03125 }\n\
03126 \n\
03127 OldSim instproc create-agent { node type pktClass } {\n\
03128 \n\
03129 $self instvar classMap_\n\
03130 if ![info exists classMap_($type)] {\n\
03131 puts stderr \\\n\
03132 \"backward compat bug: need to update classMap for $type\"\n\
03133 exit 1\n\
03134 }\n\
03135 set agent [new $classMap_($type)]\n\
03136 $agent set fid_ $pktClass\n\
03137 $self attach-agent $node $agent\n\
03138 \n\
03139 \n\
03140 return $agent\n\
03141 }\n\
03142 \n\
03143 OldSim instproc agent { type node } {\n\
03144 return [$self create-agent $node $type 0]\n\
03145 }\n\
03146 \n\
03147 OldSim instproc create-connection \\\n\
03148 { srcType srcNode sinkType sinkNode pktClass } {\n\
03149 \n\
03150 set src [$self create-agent $srcNode $srcType $pktClass]\n\
03151 set sink [$self create-agent $sinkNode $sinkType $pktClass]\n\
03152 $self connect $src $sink\n\
03153 \n\
03154 return $src\n\
03155 }\n\
03156 \n\
03157 proc ns_connect { src sink } {\n\
03158 return [ns connect $src $sink]\n\
03159 }\n\
03160 \n\
03161 OldSim instproc link args {\n\
03162 set nargs [llength $args]\n\
03163 set arg0 [lindex $args 0]\n\
03164 set arg1 [lindex $args 1]\n\
03165 if { $nargs == 2 } {\n\
03166 return [$self link-twoargs $arg0 $arg1]\n\
03167 } elseif { $nargs == 3 } {\n\
03168 return [$self link-threeargs $arg0 $arg1 [lindex $args 2]]\n\
03169 }\n\
03170 }\n\
03171 OldSim instproc link-twoargs { n1 n2 } {\n\
03172 $self instvar LH_\n\
03173 if ![info exists LH_($n1:$n2)] {\n\
03174 set LH_($n1:$n2) 1\n\
03175 linkHelper LH_:$n1:$n2 $n1 $n2\n\
03176 }\n\
03177 return LH_:$n1:$n2\n\
03178 }\n\
03179 \n\
03180 OldSim instproc link-threeargs { n1 n2 qtype } {\n\
03181 $self simplex-link $n1 $n2 0 0 $qtype\n\
03182 return [$self link-twoargs $n1 $n2]\n\
03183 }\n\
03184 \n\
03185 OldSim instproc trace {} {\n\
03186 return [new traceHelper]\n\
03187 }\n\
03188 \n\
03189 OldSim instproc random { seed } {\n\
03190 return [ns-random $seed]\n\
03191 }\n\
03192 \n\
03193 proc ns_simplex { n1 n2 bw delay type } {\n\
03194 puts stderr \"ns_simplex: no backward compat\"\n\
03195 exit 1\n\
03196 }\n\
03197 \n\
03198 proc ns_duplex { n1 n2 bw delay type } {\n\
03199 ns duplex-link-compat $n1 $n2 $bw $delay $type\n\
03200 return [ns get-queues $n1 $n2]\n\
03201 }\n\
03202 \n\
03203 proc ns_create_connection { srcType srcNode sinkType sinkNode pktClass } {\n\
03204 ns create-connection $srcType $srcNode $sinkType \\\n\
03205 $sinkNode $pktClass\n\
03206 }\n\
03207 \n\
03208 proc ns_create_cbr { srcNode sinkNode pktSize interval fid } {\n\
03209 set s [ns create-connection cbr $srcNode loss-monitor \\\n\
03210 $sinkNode $fid]\n\
03211 $s set interval_ $interval\n\
03212 $s set packetSize_ $pktSize\n\
03213 return $s\n\
03214 }\n\
03215 \n\
03216 proc ns_create_class { parent borrow allot maxidle notused prio depth xdelay } {\n\
03217 set cl [new CBQClass]\n\
03218 if { $prio < 8 } {\n\
03219 set qtype [CBQClass set def_qtype_]\n\
03220 set q [new Queue/$qtype]\n\
03221 $cl install-queue $q\n\
03222 }\n\
03223 set depth [expr $depth + 1]\n\
03224 if { $borrow == \"none\" } {\n\
03225 set borrowok false\n\
03226 } elseif { $borrow == $parent } {\n\
03227 set borrowok true\n\
03228 } else {\n\
03229 puts stderr \"CBQ: borrowing from non-parent not supported\"\n\
03230 exit 1\n\
03231 }\n\
03232 \n\
03233 $cl setparams $parent $borrowok $allot $maxidle $prio $depth $xdelay\n\
03234 return $cl\n\
03235 }\n\
03236 \n\
03237 proc ns_create_class1 { parent borrow allot maxidle notused prio depth xdelay Mb } {\n\
03238 set cl [ns_create_class $parent $borrow $allot $maxidle $notused $prio $depth $xdelay]\n\
03239 ns_class_maxIdle $cl $allot $maxidle $prio $Mb\n\
03240 return $cl\n\
03241 }\n\
03242 \n\
03243 proc ns_class_params { cl parent borrow allot maxidle notused prio depth xdelay Mb } {\n\
03244 set depth [expr $depth + 1]\n\
03245 if { $borrow == \"none\" } {\n\
03246 set borrowok false\n\
03247 } elseif { $borrow == $parent } {\n\
03248 set borrowok true\n\
03249 } else {\n\
03250 puts stderr \"CBQ: borrowing from non-parent not supported\"\n\
03251 exit 1\n\
03252 }\n\
03253 $cl setparams $parent $borrowok $allot $maxidle $prio $depth $xdelay\n\
03254 ns_class_maxIdle $cl $allot $maxidle $prio $Mb\n\
03255 return $cl\n\
03256 }\n\
03257 \n\
03258 proc ns_class_maxIdle { cl allot maxIdle priority Mbps } {\n\
03259 if { $maxIdle == \"auto\" } {\n\
03260 set g 0.9375\n\
03261 set n [expr 8 * $priority]\n\
03262 set gTOn [expr pow($g, $n)]\n\
03263 set first [expr ((1/$allot) - 1) * (1-$gTOn) / $gTOn ]\n\
03264 set second [expr (1 - $g)]\n\
03265 set packetsize 1000\n\
03266 set t [expr ($packetsize * 8)/($Mbps * 1000000) ]\n\
03267 if { $first > $second } {\n\
03268 $cl set maxidle_ [expr $t * $first]\n\
03269 } else {\n\
03270 $cl set maxidle_ [expr $t * $second]\n\
03271 }\n\
03272 } else {\n\
03273 $cl set maxidle_ $maxIdle\n\
03274 }\n\
03275 return $cl\n\
03276 }\n\
03277 Agent instproc connect d {\n\
03278 $self set dst_ $d\n\
03279 }\n\
03280 \n\
03281 Agent/Message instproc recv msg {\n\
03282 $self handle $msg\n\
03283 }\n\
03284 \n\
03285 Queue/RED proc set { var {arg \"\"} } {\n\
03286 if { $var == \"queue-in-bytes_\" } {\n\
03287 warn \"Warning: use `queue_in_bytes_' rather than `queue-in-bytes_'\"\n\
03288 set var \"queue_in_bytes_\"\n\
03289 } elseif { $var == \"drop-tail_\" } {\n\
03290 warn \"Warning: use `drop_tail_' rather than `drop-tail_'\"\n\
03291 set var \"drop_tail_\"\n\
03292 } elseif { $var == \"drop-front_\" } {\n\
03293 warn \"Warning: use `drop_front_' rather than `drop-front_'\"\n\
03294 set var \"drop_front_\"\n\
03295 } elseif { $var == \"drop-rand_\" } {\n\
03296 warn \"Warning: use `drop_rand_' rather than `drop-rand_'\"\n\
03297 set var \"drop_rand_\"\n\
03298 } elseif { $var == \"ns1-compat_\" } {\n\
03299 warn \"Warning: use `ns1_compat_' rather than `ns1-compat_'\"\n\
03300 set var \"ns1_compat_\"\n\
03301 }\n\
03302 eval $self next $var $arg\n\
03303 }\n\
03304 \n\
03305 Queue/DropTail proc set { var {arg \"\"} } {\n\
03306 if { $var == \"drop-front_\" } {\n\
03307 warn \"Warning: use `drop_front_' rather than `drop-front_'\"\n\
03308 set var \"drop_front_\"\n\
03309 }\n\
03310 eval $self next $var $arg\n\
03311 }\n\
03312 \n\
03313 \n\
03314 PacketHeaderManager set hdrlen_ 0\n\
03315 \n\
03316 PacketHeaderManager set tab_(Common) 1\n\
03317 \n\
03318 proc add-packet-header args {\n\
03319 foreach cl $args {\n\
03320 PacketHeaderManager set tab_(PacketHeader/$cl) 1\n\
03321 }\n\
03322 }\n\
03323 \n\
03324 proc add-all-packet-headers {} {\n\
03325 PacketHeaderManager instvar tab_\n\
03326 foreach cl [PacketHeader info subclass] {\n\
03327 if [info exists tab_($cl)] { \n\
03328 PacketHeaderManager set tab_($cl) 1\n\
03329 }\n\
03330 }\n\
03331 }\n\
03332 \n\
03333 proc remove-packet-header args {\n\
03334 foreach cl $args {\n\
03335 if { $cl == \"Common\" } {\n\
03336 warn \"Cannot exclude common packet header.\"\n\
03337 continue\n\
03338 }\n\
03339 PacketHeaderManager unset tab_(PacketHeader/$cl)\n\
03340 }\n\
03341 }\n\
03342 \n\
03343 proc remove-all-packet-headers {} {\n\
03344 PacketHeaderManager instvar tab_\n\
03345 foreach cl [PacketHeader info subclass] {\n\
03346 if { $cl != \"PacketHeader/Common\" } {\n\
03347 if [info exists tab_($cl)] { \n\
03348 PacketHeaderManager unset tab_($cl)\n\
03349 }\n\
03350 }\n\
03351 }\n\
03352 }\n\
03353 \n\
03354 foreach prot {\n\
03355 Common \n\
03356 Flags\n\
03357 IP  # IP\n\
03358 NV  # NixVector classifier for stateless routing \n\
03359 rtProtoDV   # distance vector routing protocol\n\
03360 rtProtoLS   # link state routing protocol\n\
03361 SR  # source routing, dsr/hdr_sr.cc\n\
03362 Src_rt  # source routing, src_rtg/hdr_src.cc\n\
03363 LDP     # mpls/ldp.cc\n\
03364 MPLS    # MPLS, MultiProtocol Label Switching\n\
03365 Resv    # Token buckets, for reservations.\n\
03366 UMP     # Admission control, adc/ump.cc\n\
03367 Pushback    # Pushback, router-to-router\n\
03368 aSRM    # mcast/srm.cc\n\
03369 CtrMcast    # Centralized Multicast routing\n\
03370 mcastCtrl   # mcast/mcast_ctrl.cc\n\
03371 MFTP    # Multicast File Transfer Protocol\n\
03372 PGM     # PGM multicast\n\
03373 PGM_SPM # PGM multicast\n\
03374 PGM_NAK # PGM multicast\n\
03375 SRM     # SRM, multicast\n\
03376 SRMEXT  # SRM, multicast\n\
03377 HttpInval   # HTTP\n\
03378 IVS     # Inria video conferencing system \n\
03379 QS  # Quick-Start\n\
03380 RAP     # Rate Adaption Protocol, transport protocol.\n\
03381 RTP     # RTP.  Also used for UPD traffic.\n\
03382 SCTP    # SCTP, transport protocol\n\
03383 Snoop   # tcp/snoop.cc\n\
03384 TCP     # TCP, transport protocol\n\
03385 TCPA    # Asymmetric TCP, transport protocol\n\
03386 TFRC    # TFRC, transport protocol\n\
03387 TFRC_ACK    # TFRC, transport protocol\n\
03388 XCP     # XCP, transport protocol\n\
03389 Message # a protocol to carry text messages\n\
03390 Ping    # Ping\n\
03391 ARP     # Address Resolution Protocol, network wireless stack\n\
03392 GAF     # Geographic Adaptive Delity, for ad-hoc networks\n\
03393 LL  # network wireless stack\n\
03394 LRWPAN  # zheng, wpan/p802_15_4mac.cc\n\
03395 Mac     # network wireless stack\n\
03396 AODV    # routing protocol for ad-hoc networks\n\
03397 Diffusion   # diffusion/diffusion.cc\n\
03398 IMEP    # Internet MANET Encapsulation Protocol, for ad-hoc networks\n\
03399 MIP     # Mobile IP, mobile/mip-reg.cc\n\
03400 Smac    # Sensor-MAC\n\
03401 TORA    # routing protocol for ad-hoc networks\n\
03402 Encap   # common/encap.cc\n\
03403 IPinIP  # IP encapsulation \n\
03404 HDLC    # High Level Data Link Control\n\
03405 } {\n\
03406 add-packet-header $prot\n\
03407 }\n\
03408 \n\
03409 proc PktHdr_offset { hdrName {field \"\"} } {\n\
03410 set offset [$hdrName offset]\n\
03411 if { $field != \"\" } {\n\
03412 incr offset [$hdrName set offset_($field)]\n\
03413 }\n\
03414 return $offset\n\
03415 }\n\
03416 \n\
03417 Simulator instproc create_packetformat { } {\n\
03418 PacketHeaderManager instvar tab_\n\
03419 set pm [new PacketHeaderManager]\n\
03420 foreach cl [PacketHeader info subclass] {\n\
03421 if [info exists tab_($cl)] {\n\
03422 set off [$pm allochdr $cl]\n\
03423 $cl offset $off\n\
03424 }\n\
03425 }\n\
03426 $self set packetManager_ $pm\n\
03427 }\n\
03428 \n\
03429 PacketHeaderManager instproc allochdr cl {\n\
03430 set size [$cl set hdrlen_]\n\
03431 \n\
03432 $self instvar hdrlen_\n\
03433 set NS_ALIGN 8\n\
03434 set incr [expr ($size + ($NS_ALIGN-1)) & ~($NS_ALIGN-1)]\n\
03435 set base $hdrlen_\n\
03436 incr hdrlen_ $incr\n\
03437 \n\
03438 return $base\n\
03439 }\n\
03440 \n\
03441 \n\
03442 \n\
03443 \n\
03444 \n\
03445 \n\
03446 \n\
03447 \n\
03448 \n\
03449 \n\
03450 Class CBQLink -superclass SimpleLink\n\
03451 CBQLink instproc init { src dst bw delay q cl {lltype \"DelayLink\"} } {\n\
03452 $self next $src $dst $bw $delay $q $lltype ; # SimpleLink ctor\n\
03453 $self instvar head_ queue_ link_\n\
03454 $self instvar  classifier_  ; # not found in a SimpleLink\n\
03455 \n\
03456 $queue_ link $link_ ; # queue_ set by SimpleLink ctor, CBQ needs $link_\n\
03457 set classifier_ $cl\n\
03458 $head_ target $classifier_\n\
03459 \n\
03460 set defalg [Queue/CBQ set algorithm_]\n\
03461 $queue_ set algorithm_ $defalg\n\
03462 $queue_ algorithm $defalg\n\
03463 }\n\
03464 \n\
03465 \n\
03466 \n\
03467 \n\
03468 CBQLink instproc classifier {} {\n\
03469 $self instvar classifier_\n\
03470 return $classifier_\n\
03471 }\n\
03472 \n\
03473 CBQLink instproc bind args {\n\
03474 \n\
03475 $self instvar classifier_\n\
03476 set nargs [llength $args]\n\
03477 set cbqcl [lindex $args 0]\n\
03478 set a [lindex $args 1]\n\
03479 if { $nargs == 3 } {\n\
03480 set b [lindex $args 2]\n\
03481 } else {\n\
03482 set b $a\n\
03483 }\n\
03484 while { $a <= $b } {\n\
03485 set slot [$classifier_ installNext $cbqcl]\n\
03486 $classifier_ set-hash auto 0 0 $a $slot\n\
03487 incr a\n\
03488 }\n\
03489 }\n\
03490 \n\
03491 CBQLink instproc insert args {\n\
03492 $self instvar queue_ drophead_ link_\n\
03493 set nargs [llength $args]\n\
03494 set cbqcl [lindex $args 0]\n\
03495 set qdisc [$cbqcl qdisc]\n\
03496 if { $nargs == 1 } {\n\
03497 set qmon [new QueueMonitor]\n\
03498 } else {\n\
03499 set qmon [lindex $args 1]\n\
03500 }\n\
03501 \n\
03502 \n\
03503 if { $qmon == \"\" } {\n\
03504 error \"CBQ requires a q-monitor for class $cbqcl\"\n\
03505 }\n\
03506 if { $qdisc != \"\" } {\n\
03507 set in [new SnoopQueue/In]\n\
03508 set out [new SnoopQueue/Out]\n\
03509 set drop [new SnoopQueue/Drop]\n\
03510 $in set-monitor $qmon\n\
03511 $out set-monitor $qmon\n\
03512 $drop set-monitor $qmon\n\
03513 \n\
03514 $in target $qdisc\n\
03515 $cbqcl target $in\n\
03516 \n\
03517 $qdisc drop-target $drop\n\
03518 $drop target $drophead_\n\
03519 \n\
03520 $qdisc target $out\n\
03521 $out target $queue_\n\
03522 $cbqcl qmon $qmon\n\
03523 }\n\
03524 \n\
03525 \n\
03526 $cbqcl instvar maxidle_\n\
03527 \n\
03528 if { $maxidle_ == \"auto\" } {\n\
03529 $cbqcl automaxidle [$link_ set bandwidth_] \\\n\
03530 [$queue_ set maxpkt_]\n\
03531 set maxidle_ [$cbqcl set maxidle_]\n\
03532 }\n\
03533 $cbqcl maxidle $maxidle_\n\
03534 \n\
03535 $queue_ insert-class $cbqcl\n\
03536 }\n\
03537 \n\
03538 CBQClass instproc init {} {\n\
03539 $self next\n\
03540 $self instvar automaxidle_gain_\n\
03541 set automaxidle_gain_ [$class set automaxidle_gain_]\n\
03542 }\n\
03543 \n\
03544 CBQClass instproc automaxidle { linkbw maxpkt } {\n\
03545 $self instvar automaxidle_gain_ maxidle_\n\
03546 $self instvar priority_\n\
03547 \n\
03548 \n\
03549 set allot [$self allot]\n\
03550 \n\
03551 \n\
03552 set g $automaxidle_gain_\n\
03553 set n [expr 8 * $priority_]\n\
03554 \n\
03555 if { $g == 0 || $allot == 0 || $linkbw == 0 } {\n\
03556 set maxidle_ 0.0\n\
03557 return\n\
03558 }\n\
03559 set gTOn [expr pow($g, $n)]\n\
03560 set first [expr ((1/$allot) - 1) * (1-$gTOn) / $gTOn ]\n\
03561 set second [expr (1 - $g)]\n\
03562 set t [expr ($maxpkt * 8.0)/$linkbw]\n\
03563 if { $first > $second } {\n\
03564 set maxidle_ [expr $t * $first]\n\
03565 } else {\n\
03566 set maxidle_ [expr $t * $second]\n\
03567 }\n\
03568 return $maxidle_\n\
03569 }\n\
03570 \n\
03571 \n\
03572 CBQClass instproc setparams { parent okborrow allot maxidle prio level xdelay } {\n\
03573 \n\
03574 $self allot $allot\n\
03575 $self parent $parent\n\
03576 \n\
03577 $self set okborrow_ $okborrow\n\
03578 $self set maxidle_ $maxidle\n\
03579 $self set priority_ $prio\n\
03580 $self set level_ $level\n\
03581 $self set extradelay_ $xdelay\n\
03582 \n\
03583 return $self\n\
03584 }\n\
03585 \n\
03586 \n\
03587 CBQClass instproc install-queue q {\n\
03588 $q set blocked_ true\n\
03589 $q set unblock_on_resume_ false\n\
03590 $self qdisc $q\n\
03591 }\n\
03592 \n\
03593 \n\
03594 QueueMonitor instproc reset {} {\n\
03595 $self instvar size_ pkts_\n\
03596 $self instvar parrivals_ barrivals_\n\
03597 $self instvar pdepartures_ bdepartures_\n\
03598 $self instvar pdrops_ bdrops_\n\
03599 \n\
03600 set parrivals_ 0\n\
03601 set barrivals_ 0\n\
03602 set pdepartures_ 0\n\
03603 set bdepartures_ 0\n\
03604 set pdrops_ 0\n\
03605 set bdrops_ 0\n\
03606 \n\
03607 set bint [$self get-bytes-integrator]\n\
03608 if { $bint != \"\" } {\n\
03609 $bint reset\n\
03610 }\n\
03611 \n\
03612 set pint [$self get-pkts-integrator]\n\
03613 if { $pint != \"\" } {\n\
03614 $pint reset\n\
03615 }\n\
03616 \n\
03617 set samp [$self get-delay-samples]\n\
03618 if { $samp != \"\" } {\n\
03619 $samp reset\n\
03620 }\n\
03621 }\n\
03622 \n\
03623 QueueMonitor/ED instproc reset {} {\n\
03624 $self next\n\
03625 $self instvar epdrops_ ebdrops_ mon_epdrops_ mon_ebdrops_\n\
03626 set epdrops_ 0\n\
03627 set ebdrops_ 0\n\
03628 set mon_epdrops_ 0\n\
03629 set mon_ebdrops_ 0\n\
03630 }\n\
03631 \n\
03632 Class AckReconsClass -superclass Agent\n\
03633 \n\
03634 AckReconsControllerClass instproc demux { src dst } {\n\
03635 $self instvar reconslist_ queue_\n\
03636 set addr $src:$dst\n\
03637 if { ![info exists reconslist_($addr)] } {\n\
03638 set recons [new Agent/AckReconsClass $src $dst]\n\
03639 $recons target $queue_\n\
03640 set reconslist_($addr) $recons\n\
03641 }\n\
03642 return $reconslist_($addr)\n\
03643 }\n\
03644 \n\
03645 \n\
03646 \n\
03647 Agent/AckReconsClass instproc spacing { ack } {\n\
03648 $self instvar ackInterArr_ ackSpacing_ delack_ \\\n\
03649 lastAck_ lastRealAck_ lastRealTime_ adaptive_ size_\n\
03650 global ns\n\
03651 \n\
03652 set deltaTime [expr [$ns now] - $lastRealTime_]\n\
03653 set deltaAck [expr $ack - $lastAck_]\n\
03654 if {$adaptive_} {\n\
03655 set bw [expr $deltaAck*$size_/$deltaTime]\n\
03656 set ackSpacing_ $ackInterArr_\n\
03657 if { $deltaAck > 0 } {\n\
03658 }\n\
03659 } else {\n\
03660 set deltaT [expr $deltaTime / ($deltaAck/$delack_ +1)]\n\
03661 set ackSpacing_ $deltaT\n\
03662 }\n\
03663 }\n\
03664 \n\
03665 Agent/AckReconsClass instproc ackbw {ack time} {\n\
03666 $self instvar ackInterArr_ lastRealTime_ lastRealAck_ alpha_\n\
03667 \n\
03668 set sample [expr $time - $lastRealTime_]\n\
03669 set ackInterArr_ [expr $alpha_*$sample + (1-$alpha_)*$ackInterArr_]\n\
03670 }\n\
03671 \n\
03672 Class Classifier/Hash/Fid/FQ -superclass Classifier/Hash/Fid\n\
03673 \n\
03674 Classifier/Hash/Fid/FQ instproc unknown-flow { src dst fid } {\n\
03675 $self instvar fq_\n\
03676 $fq_ new-flow $src $dst $fid\n\
03677 }\n\
03678 \n\
03679 Class FQLink -superclass SimpleLink\n\
03680 \n\
03681 FQLink instproc init { src dst bw delay q } {\n\
03682 $self next $src $dst $bw $delay $q\n\
03683 $self instvar link_ queue_ head_ toNode_ ttl_ classifier_ \\\n\
03684 nactive_ \n\
03685 $self instvar drophead_     ;# idea stolen from CBQ and Kevin\n\
03686 \n\
03687 set nactive_ 0\n\
03688 \n\
03689 set classifier_ [new Classifier/Hash/Fid/FQ 33]\n\
03690 $classifier_ set fq_ $self\n\
03691 \n\
03692 $head_ target $classifier_\n\
03693 \n\
03694 \n\
03695 $queue_ set secsPerByte_ [expr 8.0 / [$link_ set bandwidth_]]\n\
03696 }\n\
03697 FQLink instproc new-flow { src dst fid } {\n\
03698 $self instvar classifier_ nactive_ queue_ link_ drpT_\n\
03699 incr nactive_\n\
03700 \n\
03701 set type [$class set queueManagement_]\n\
03702 set q [new Queue/$type]\n\
03703 \n\
03704 if { $type == \"RED\" } {\n\
03705 set bw [$link_ set bandwidth_]\n\
03706 $q set ptc_ [expr $bw / (8. * [$q set mean_pktsize_])]\n\
03707 }\n\
03708 $q drop-target $drpT_\n\
03709 \n\
03710 set slot [$classifier_ installNext $q]\n\
03711 $classifier_ set-hash auto $src $dst $fid $slot\n\
03712 $q target $queue_\n\
03713 $queue_ install $fid $q\n\
03714 }\n\
03715 FQLink instproc up? { } {\n\
03716 return up\n\
03717 }\n\
03718 \n\
03719 Queue/RED/PD instproc makeflowmon { link {cltype \"SrcDestFid\"} {cslots 29}} {\n\
03720 \n\
03721 set flowmon [new QueueMonitor/ED/Flowmon]\n\
03722 set cl [new Classifier/Hash/$cltype $cslots]\n\
03723 \n\
03724 $cl proc unknown-flow { src dst fid } {\n\
03725 set nflow [new QueueMonitor/ED/Flow/RedPD]\n\
03726 set slot [$self installNext $nflow]\n\
03727 $self set-hash auto $src $dst $fid $slot\n\
03728 }\n\
03729 \n\
03730 $cl proc no-slot slotnum {\n\
03731 puts stderr \"classifier $self, no-slot for slotnum $slotnum\"\n\
03732 }\n\
03733 \n\
03734 $flowmon classifier $cl\n\
03735 $self attach-flowmon $flowmon\n\
03736 \n\
03737 set isnoop [new SnoopQueue/In]\n\
03738 set osnoop [new SnoopQueue/Out]\n\
03739 set dsnoop [new SnoopQueue/Drop]\n\
03740 set edsnoop [new SnoopQueue/EDrop]\n\
03741 \n\
03742 $link attach-monitors $isnoop $osnoop $dsnoop $flowmon\n\
03743 $edsnoop set-monitor $flowmon\n\
03744 $self early-drop-target $edsnoop \n\
03745 set ns [Simulator instance]\n\
03746 $edsnoop target [$ns set nullAgent_]\n\
03747 \n\
03748 \n\
03749 $self drop-target $dsnoop\n\
03750 \n\
03751 return $flowmon\n\
03752 \n\
03753 }   \n\
03754 \n\
03755 \n\
03756 Queue instproc attach-nam-traces {src dst file} {\n\
03757 \n\
03758 \n\
03759 $self attach-traces $src $dst $file \"nam\"\n\
03760 }\n\
03761 \n\
03762 Queue instproc attach-traces {src dst file {op \"\"}} {\n\
03763 }\n\
03764 \n\
03765 Queue/RED instproc attach-traces {src dst file {op \"\"}} {\n\
03766 \n\
03767 set ns [Simulator instance]\n\
03768 set type [$self trace-type]\n\
03769 \n\
03770 if {$op == \"nam\"} {\n\
03771 set type \"Drop\"\n\
03772 }\n\
03773 \n\
03774 \n\
03775 set newtrace [$ns create-trace $type $file $src $dst $op]\n\
03776 set oldTrace [$self edrop-trace]\n\
03777 \n\
03778 if {$oldTrace!=0} {\n\
03779 $newtrace target $oldTrace\n\
03780 } else {\n\
03781 $newtrace target [$ns set nullAgent_]\n\
03782 }\n\
03783 \n\
03784 $self edrop-trace $newtrace\n\
03785 }\n\
03786 \n\
03787 Queue/RED/PD instproc attach-traces {src dst file {op \"\"}} {\n\
03788 \n\
03789 $self next $src $dst $file $op\n\
03790 \n\
03791 set ns [Simulator instance]\n\
03792 set type [$self mon-trace-type]\n\
03793 \n\
03794 if {$op == \"nam\"} {\n\
03795 set type \"Drop\"\n\
03796 }\n\
03797 \n\
03798 set medtrace [$ns create-trace $type $file $src $dst $op]\n\
03799 \n\
03800 set oldTrace [$self mon-edrop-trace]\n\
03801 if {$oldTrace!=0} {\n\
03802 puts \"exists\"\n\
03803 $medtrace target $oldTrace\n\
03804 } else {\n\
03805 $medtrace target [$ns set nullAgent_]\n\
03806 }\n\
03807 \n\
03808 $self mon-edrop-trace $medtrace\n\
03809 \n\
03810 }\n\
03811 \n\
03812 Delayer instproc init {} {\n\
03813 $self next\n\
03814 }\n\
03815 \n\
03816 Simulator instproc insert-delayer {src dst delayer} {\n\
03817 set link [$self link $src $dst]\n\
03818 $link insert-delayer $delayer\n\
03819 }\n\
03820 \n\
03821 SimpleLink instproc insert-delayer args  {\n\
03822 $self instvar delayer_ queue_\n\
03823 if {[info exists delayer_]} {\n\
03824 puts stderr \"Delayer already inserted\"\n\
03825 } else {\n\
03826 set delayer_ [lindex $args 0]\n\
03827 $delayer_ target [$queue_ target]\n\
03828 $queue_ target $delayer_\n\
03829 }\n\
03830 }\n\
03831 \n\
03832 Queue/XCP instproc init {} {\n\
03833 $self next\n\
03834 $self create-vqueues\n\
03835 }\n\
03836 \n\
03837 Queue/XCP instproc create-vqueues {} {\n\
03838 $self instvar vq_ limit_\n\
03839 \n\
03840 $self set-xcpQ [set vq_(0) [new Queue/DropTail/XCPQ]]\n\
03841 $self set-tcpQ [set vq_(1) [new Queue/RED]]\n\
03842 $self set-otherQ [set vq_(2) [new Queue/RED]]\n\
03843 }\n\
03844 \n\
03845 Queue/XCP instproc link {del} {\n\
03846 $self instvar vq_ \n\
03847 \n\
03848 $vq_(1) link $del\n\
03849 $vq_(2) link $del\n\
03850 \n\
03851 }\n\
03852 \n\
03853 Queue/XCP instproc queue-limit { limit } {\n\
03854 $self instvar vq_\n\
03855 \n\
03856 $vq_(0) set limit_ $limit\n\
03857 $vq_(1) set limit_ $limit\n\
03858 $vq_(2) set limit_ $limit\n\
03859 }\n\
03860 \n\
03861 Queue/XCP instproc reset {} {\n\
03862 $self instvar vq_\n\
03863 \n\
03864 $vq_(0) reset\n\
03865 $vq_(1) reset\n\
03866 $vq_(2) reset\n\
03867 }\n\
03868 \n\
03869 Trace instproc init type {\n\
03870 $self next $type\n\
03871 $self instvar type_\n\
03872 set type_ $type\n\
03873 }\n\
03874 \n\
03875 Trace instproc format args {\n\
03876 \n\
03877 $self instvar type_ fp_ src_ dst_\n\
03878 \n\
03879 if [info exists fp_] {\n\
03880 set ns [Simulator instance]\n\
03881 puts $fp_ [eval list $type_ [$ns now] [eval concat $args]]\n\
03882 }\n\
03883 }\n\
03884 \n\
03885 Trace instproc attach fp {\n\
03886 $self instvar fp_\n\
03887 \n\
03888 set fp_ $fp\n\
03889 $self cmd attach $fp_\n\
03890 }\n\
03891 \n\
03892 \n\
03893 BaseTrace instproc attach fp {\n\
03894 $self instvar fp_\n\
03895 \n\
03896 set fp_ $fp\n\
03897 $self cmd attach $fp_\n\
03898 }\n\
03899 \n\
03900 Class Trace/Hop -superclass Trace\n\
03901 Trace/Hop instproc init {} {\n\
03902 $self next \"h\"\n\
03903 }\n\
03904 \n\
03905 Class Trace/Enque -superclass Trace\n\
03906 Trace/Enque instproc init {} {\n\
03907 $self next \"+\"\n\
03908 }\n\
03909 \n\
03910 Trace/Deque instproc init {} {\n\
03911 $self next \"-\"\n\
03912 }\n\
03913 \n\
03914 Class Trace/EDrop -superclass Trace\n\
03915 Trace/EDrop instproc init {} {\n\
03916 $self next \"e\"\n\
03917 }\n\
03918 \n\
03919 Class Trace/MEDrop -superclass Trace\n\
03920 Trace/MEDrop instproc init {} {\n\
03921 $self next \"m\"\n\
03922 }\n\
03923 \n\
03924 \n\
03925 Class Trace/SessEnque -superclass Trace\n\
03926 Trace/SessEnque instproc init {} {\n\
03927 $self next \"E\"    ;# Should use '='? :)\n\
03928 }\n\
03929 \n\
03930 Class Trace/SessDeque -superclass Trace\n\
03931 Trace/SessDeque instproc init {} {\n\
03932 $self next \"D\"    ;# Should use '_'?\n\
03933 }\n\
03934 \n\
03935 Class Trace/Recv -superclass Trace \n\
03936 Trace/Recv instproc init {} {\n\
03937 $self next \"r\"\n\
03938 }\n\
03939 \n\
03940 Class Trace/Drop -superclass Trace\n\
03941 Trace/Drop instproc init {} {\n\
03942 $self next \"d\"\n\
03943 }\n\
03944 \n\
03945 Class Trace/Generic -superclass Trace\n\
03946 Trace/Generic instproc init {} {\n\
03947 $self next \"v\"\n\
03948 }\n\
03949 \n\
03950 Class Trace/Collision -superclass Trace\n\
03951 Trace/Collision instproc init {} {\n\
03952 $self next \"c\"\n\
03953 }\n\
03954 \n\
03955 Class Trace/Var -superclass Trace\n\
03956 Trace/Var instproc init {} {\n\
03957 $self next \"f\"\n\
03958 }\n\
03959 \n\
03960 proc f-time t {\n\
03961 format \"%7.4f\" $t\n\
03962 }\n\
03963 \n\
03964 proc f-node n {\n\
03965 set node [expr $n >> 8]\n\
03966 set port [expr $n & 0xff]\n\
03967 return \"$node.$port\"\n\
03968 }\n\
03969 \n\
03970 proc gc o {\n\
03971 set ret \"NULL_OBJECT\"\n\
03972 if { $o != \"\" } {\n\
03973 set ret \"\"\n\
03974 foreach i $o {\n\
03975 if ![catch \"$i info class\" val] {\n\
03976 lappend ret $val\n\
03977 }\n\
03978 }\n\
03979 }\n\
03980 set ret\n\
03981 }\n\
03982 \n\
03983 Node instproc tn {} {\n\
03984 $self instvar id_\n\
03985 return \"${self}(id $id_)\"\n\
03986 }\n\
03987 \n\
03988 Simulator instproc gen-map {} {\n\
03989 \n\
03990 $self instvar Node_ link_ MobileNode_\n\
03991 \n\
03992 set nn [Node set nn_]\n\
03993 for {set i 0} {$i < $nn} {incr i} {\n\
03994 if ![info exists Node_($i)] {\n\
03995 continue\n\
03996 }\n\
03997 set n $Node_($i)\n\
03998 puts \"Node [$n tn]\"\n\
03999 foreach nc [$n info vars] {\n\
04000 switch $nc {\n\
04001 ns_     continue\n\
04002 id_     continue\n\
04003 neighbor_   continue\n\
04004 agents_     continue\n\
04005 routes_     continue\n\
04006 np_     continue\n\
04007 default {\n\
04008 if [$n array exists $nc] {\n\
04009 puts \"\\t\\t$nc\\t[$n array get $nc]\"\n\
04010 } else {\n\
04011 set v [$n set $nc]\n\
04012 puts \"\\t\\t$nc${v}([gc $v])\"\n\
04013 }\n\
04014 }\n\
04015 }\n\
04016 }\n\
04017 if {[llength [$n set agents_]] > 0} {\n\
04018 puts \"\\n\\tAgents at node (possibly in order of creation):\"\n\
04019 foreach a [$n set agents_] {\n\
04020 puts \"\\t\\t$a\\t[gc $a]\\t\\tdst-addr/port: [$a set dst_addr_]/[$a set dst_port_]\"\n\
04021 }\n\
04022 }\n\
04023 puts \"\"\n\
04024 foreach li [array names link_ [$n id]:*] {\n\
04025 set L [split $li :]\n\
04026 set nbr [[$self get-node-by-id [lindex $L 1]] entry]\n\
04027 set ln $link_($li)\n\
04028 puts \"\\tLink $ln, fromNode_ [[$ln set fromNode_] tn] -> toNode_ [[$ln set toNode_] tn]\"\n\
04029 puts \"\\tComponents (in order) head first\"\n\
04030 for {set c [$ln head]} {$c != $nbr} {set c [$c target]} {\n\
04031 puts \"\\t\\t$c\\t[gc $c]\"\n\
04032 }\n\
04033 }\n\
04034 puts \"---\"\n\
04035 }\n\
04036 }\n\
04037 \n\
04038 \n\
04039 \n\
04040 Simulator instproc maybeEnableTraceAll {obj args} {\n\
04041 foreach {file tag} {\n\
04042 traceAllFile_           {}\n\
04043 namtraceAllFile_        nam\n\
04044 } {\n\
04045 $self instvar $file\n\
04046 if [info exists $file] {\n\
04047 $obj trace [set $file] $args $tag\n\
04048 }\n\
04049 }\n\
04050 }\n\
04051 \n\
04052 proc exponential {args} {\n\
04053 global defaultRNG\n\
04054 eval [list $defaultRNG exponential] $args\n\
04055 }\n\
04056 \n\
04057 proc uniform {args} {\n\
04058 global defaultRNG\n\
04059 eval [list $defaultRNG uniform] $args\n\
04060 }\n\
04061 \n\
04062 proc integer {args} {\n\
04063 global defaultRNG\n\
04064 eval [list $defaultRNG integer] $args\n\
04065 }\n\
04066 \n\
04067 RNG instproc init {} {\n\
04068 $self next\n\
04069 $self instvar z2\n\
04070 set z2 0\n\
04071 }\n\
04072 \n\
04073 RNG instproc uniform {a b} {\n\
04074 expr $a + (($b - $a) * ([$self next-random] * 1.0 / 0x7fffffff))\n\
04075 }\n\
04076 \n\
04077 RNG instproc integer k {\n\
04078 expr [$self next-random] % abs($k)\n\
04079 }\n\
04080 \n\
04081 RNG instproc exponential {{mu 1.0}} {\n\
04082 expr - $mu * log(([$self next-random] + 1.0) / (0x7fffffff + 1.0))\n\
04083 }\n\
04084 \n\
04085 \n\
04086 \n\
04087 RandomVariable instproc test count {\n\
04088 for {set i 0} {$i < $count} {incr i} {\n\
04089 puts stdout [$self value]\n\
04090 }\n\
04091 }\n\
04092 \n\
04093 \n\
04094 set defaultRNG [new RNG]\n\
04095 $defaultRNG seed 1\n\
04096 $defaultRNG default\n\
04097 trace variable defaultRNG w { abort \"cannot update defaultRNG once assigned\"; }\n\
04098 \n\
04099 \n\
04100 Class RandomVariable/TraceDriven -superclass RandomVariable\n\
04101 \n\
04102 RandomVariable/TraceDriven instproc init {} {\n\
04103 $self instvar filename_ file_\n\
04104 }\n\
04105 \n\
04106 RandomVariable/TraceDriven instproc value {} {\n\
04107 $self instvar file_ filename_\n\
04108 \n\
04109 if ![info exist file_] {\n\
04110 if [info exist filename_] {\n\
04111 set file_ [open $filename_ r]\n\
04112 } else {\n\
04113 puts \"RandomVariable/TraceDriven: Filename is not given\"\n\
04114 exit 0\n\
04115 }\n\
04116 }\n\
04117 \n\
04118 if ![eof $file_] {\n\
04119 gets $file_ tmp\n\
04120 return $tmp\n\
04121 } else {\n\
04122 close $file_\n\
04123 puts \"Error: RandomVariable/TraceDriven: Reached the end of the trace fi\n\
04124 le \"\n\
04125 exit 0\n\
04126 }\n\
04127 }\n\
04128 \n\
04129 \n\
04130 Agent instproc set args {\n\
04131 if { [lindex $args 0] == \"dst_\" } {\n\
04132 puts \"Warning dst_ is no longer being supported in NS. $args\"\n\
04133 puts \"Use dst_addr_ and dst_port_ instead\"\n\
04134 $self instvar dst_addr_ dst_port_\n\
04135 set addr [lindex $args 1]\n\
04136 set baseAddr [Simulator set McastBaseAddr_]\n\
04137 if { $addr >= $baseAddr } {\n\
04138 $self set dst_addr_ $addr\n\
04139 $self set dst_port_ 0\n\
04140 } else {\n\
04141 $self set dst_addr_ [expr ($addr >> 8) ]\n\
04142 $self set dst_port_ [expr ($addr % 256) ]\n\
04143 exit\n\
04144 }\n\
04145 return\n\
04146 }\n\
04147 eval $self next $args\n\
04148 }\n\
04149 \n\
04150 \n\
04151 Agent instproc init {} {\n\
04152 }\n\
04153 \n\
04154 Agent instproc nodeid {} { \n\
04155 [$self set node_] id\n\
04156 }\n\
04157 \n\
04158 Agent instproc port {} {\n\
04159 $self instvar agent_port_\n\
04160 return $agent_port_\n\
04161 }\n\
04162 \n\
04163 Agent instproc dst-port {} {\n\
04164 $self instvar dst_port_\n\
04165 return [expr $dst_port_]\n\
04166 }\n\
04167 \n\
04168 Agent instproc attach-source {s_type} {\n\
04169 set source [new Source/$s_type]\n\
04170 $source attach $self\n\
04171 $self set type_ $s_type\n\
04172 return $source\n\
04173 }\n\
04174 \n\
04175 Agent instproc attach-app {s_type} {\n\
04176 set app_ [new Application/$s_type]\n\
04177 $app_ attach-agent $self\n\
04178 $self set type_ $s_type\n\
04179 return $app_\n\
04180 }\n\
04181 \n\
04182 Agent instproc attach-tbf { tbf } {\n\
04183 $tbf target [$self target]\n\
04184 $self target $tbf\n\
04185 \n\
04186 }\n\
04187 \n\
04188 Class Agent/Null -superclass Agent\n\
04189 \n\
04190 Agent/Null instproc init args {\n\
04191 eval $self next $args\n\
04192 }\n\
04193 \n\
04194 Agent/LossMonitor instproc log-loss {} {\n\
04195 }\n\
04196 \n\
04197 Agent/CBR/UDP/SA instproc attach-tbf { tbf } {\n\
04198 $tbf target [$self target]\n\
04199 $self target $tbf\n\
04200 $self ctrl-target [$tbf target]\n\
04201 }\n\
04202 \n\
04203 Agent proc set-maxttl {objectOrClass var} {\n\
04204 if { [catch \"$objectOrClass set $var\" value] ||   \\\n\
04205 ($value < [Agent set ttl_]) } {\n\
04206 $objectOrClass set $var [Agent set ttl_]\n\
04207 }\n\
04208 $objectOrClass set $var\n\
04209 }\n\
04210 \n\
04211 \n\
04212 \n\
04213 Agent/TCP instproc init {} {\n\
04214 eval $self next\n\
04215 set ns [Simulator instance]\n\
04216 $ns create-eventtrace Event $self\n\
04217 }\n\
04218 \n\
04219 \n\
04220 Agent/TORA instproc init args {\n\
04221 \n\
04222 $self next $args\n\
04223 }       \n\
04224 \n\
04225 Agent/TORA set sport_   0\n\
04226 Agent/TORA set dport_   0\n\
04227 \n\
04228 Agent/AODV instproc init args {\n\
04229 \n\
04230 $self next $args\n\
04231 }\n\
04232 \n\
04233 Agent/AODV set sport_   0\n\
04234 Agent/AODV set dport_   0\n\
04235 \n\
04236 \n\
04237 RouteLogic instproc register {proto args} {\n\
04238 $self instvar rtprotos_ node_rtprotos_ default_node_rtprotos_\n\
04239 if [info exists rtprotos_($proto)] {\n\
04240 eval lappend rtprotos_($proto) $args\n\
04241 } else {\n\
04242 set rtprotos_($proto) $args\n\
04243 }\n\
04244 if { [Agent/rtProto/$proto info procs pre-init-all] != \"\" } {\n\
04245 Agent/rtProto/$proto pre-init-all $args\n\
04246 }\n\
04247 }\n\
04248 \n\
04249 RouteLogic instproc configure {} {\n\
04250 $self instvar rtprotos_\n\
04251 if [info exists rtprotos_] {\n\
04252 foreach proto [array names rtprotos_] {\n\
04253 eval Agent/rtProto/$proto init-all $rtprotos_($proto)\n\
04254 }\n\
04255 } else {\n\
04256 Agent/rtProto/Static init-all\n\
04257 }\n\
04258 }\n\
04259 \n\
04260 RouteLogic instproc lookup { nodeid destid } {\n\
04261 if { $nodeid == $destid } {\n\
04262 return $nodeid\n\
04263 }\n\
04264 \n\
04265 set ns [Simulator instance]\n\
04266 set node [$ns get-node-by-id $nodeid]\n\
04267 \n\
04268 if [Simulator hier-addr?] {\n\
04269 set dest [$ns get-node-by-id $destid]\n\
04270 set nh [$self hier-lookup [$node node-addr] [$dest node-addr]]\n\
04271 return [$ns get-node-id-by-addr $nh]\n\
04272 }\n\
04273 set rtobj [$node rtObject?]\n\
04274 if { $rtobj != \"\" } {\n\
04275 $rtobj lookup [$ns get-node-by-id $destid]\n\
04276 } else {\n\
04277 $self cmd lookup $nodeid $destid\n\
04278 } \n\
04279 }\n\
04280 \n\
04281 RouteLogic instproc notify {} {\n\
04282 $self instvar rtprotos_\n\
04283 foreach i [array names rtprotos_] {\n\
04284 Agent/rtProto/$i compute-all\n\
04285 }\n\
04286 \n\
04287 foreach i [CtrMcastComp info instances] {\n\
04288 $i notify\n\
04289 }\n\
04290 if { [rtObject info instances] == \"\"} {\n\
04291 foreach node [[Simulator instance] all-nodes-list] {\n\
04292 $node notify-mcast 0\n\
04293 }\n\
04294 }\n\
04295 }\n\
04296 \n\
04297 RouteLogic instproc append-addr {level addrstr} {\n\
04298 if {$level != 0} {\n\
04299 set str [lindex $addrstr 0]\n\
04300 for {set i 1} {$i < $level} {incr i} {\n\
04301 append str . [lindex $addrstr [expr $i]]\n\
04302 }\n\
04303 return $str\n\
04304 }\n\
04305 }\n\
04306 \n\
04307 RouteLogic instproc dump nn {\n\
04308 set i 0\n\
04309 while { $i < $nn } {\n\
04310 set j 0\n\
04311 while { $j < $nn } {\n\
04312 puts \"$i -> $j via [$self lookup $i $j]\"\n\
04313 incr j\n\
04314 }\n\
04315 incr i\n\
04316 }\n\
04317 }\n\
04318 \n\
04319 Simulator instproc rtproto {proto args} {\n\
04320 $self instvar routingTable_\n\
04321 if {$proto == \"Algorithmic\"} {\n\
04322 set routingTable_ [new RouteLogic/Algorithmic]\n\
04323 }\n\
04324 eval [$self get-routelogic] register $proto $args\n\
04325 }\n\
04326 \n\
04327 Simulator instproc get-routelogic {} {\n\
04328 $self instvar routingTable_\n\
04329 if ![info exists routingTable_] {\n\
04330 set routingTable_ [new RouteLogic]\n\
04331 }\n\
04332 return $routingTable_\n\
04333 }\n\
04334 \n\
04335 Simulator instproc dump-approx-sim-data {} {\n\
04336 \n\
04337 $self instvar routingTable_ Node_ link_\n\
04338 \n\
04339 \n\
04340 set r [$self get-routelogic]    \n\
04341 $self cmd get-routelogic $r  ;# propagate rl in C++\n\
04342 foreach ln [array names link_] {\n\
04343 set L [split $ln :]\n\
04344 set srcID [lindex $L 0]\n\
04345 set dstID [lindex $L 1]\n\
04346 if { [$link_($ln) up?] == \"up\" } {\n\
04347 $r insert $srcID $dstID [$link_($ln) cost?]\n\
04348 } else {\n\
04349 $r reset $srcID $dstID\n\
04350 }\n\
04351 }\n\
04352 $r compute\n\
04353 \n\
04354 puts \"# Dumping Approx-Sim Data\"  \n\
04355 \n\
04356 set n [Node set nn_]\n\
04357 puts \"m [Link set nl_] \"\n\
04358 foreach qn [array names link_] {\n\
04359 set l $link_($qn)\n\
04360 set q [$l queue]\n\
04361 set t [$q info class]\n\
04362 if {[lindex [split $t \"/\"] 1] == \"DropTail\"} {\n\
04363 puts \"link [expr [$l set id_] + 1] [expr [$l bw] / 8000] [expr [$l bw] / 8000] [$l delay] [$l qsize] $t\"\n\
04364 }\n\
04365 if {[lindex [split $t \"/\"] 1] == \"RED\"} {\n\
04366 puts \"link [expr [$l set id_] + 1] [expr [$l bw] / 8000] [expr [$l bw] / 8000] [$l delay] [$l qsize] RED [$q set thresh_] 0 [$q set maxthresh_] [expr 1.0 / [$q set linterm_] ]\"\n\
04367 }\n\
04368 }\n\
04369 \n\
04370 puts \"\"\n\
04371 puts \"n $nconn_\"\n\
04372 \n\
04373 for { set i 0 } { $i < $nconn_ } { incr i } {\n\
04374 \n\
04375 set len 0\n\
04376 set str \"\"\n\
04377 \n\
04378 set list [split $conn_($i) \":\"] \n\
04379 set srcid [lindex $list 0]\n\
04380 set dstid [lindex $list 1]\n\
04381 \n\
04382 while { $srcid != $dstid } {\n\
04383 incr len\n\
04384 set nh [$r lookup $srcid $dstid]\n\
04385 append str \" \" [expr [$link_($srcid:$nh) id] + 1] \n\
04386 set srcid  $nh\n\
04387 }\n\
04388 \n\
04389 puts \"route [expr $i + 1] $len $str\"\n\
04390 \n\
04391 }\n\
04392 }\n\
04393 \n\
04394 Simulator instproc dump-routelogic-nh {} {\n\
04395 $self instvar routingTable_ Node_ link_\n\
04396 if ![info exists routingTable_] {\n\
04397 puts \"error: routing table is not computed yet!\"\n\
04398 return 0\n\
04399 }\n\
04400 \n\
04401 puts \"Dumping Routing Table: Next Hop Information\"\n\
04402 set n [Node set nn_]\n\
04403 set i 0\n\
04404 puts -nonewline \"\\t\"\n\
04405 while { $i < $n } {\n\
04406 if ![info exists Node_($i)] {\n\
04407 incr i\n\
04408 continue\n\
04409 }\n\
04410 puts -nonewline \"$i\\t\"\n\
04411 incr i\n\
04412 }\n\
04413 set i 0\n\
04414 while { $i < $n } {\n\
04415 if ![info exists Node_($i)] {\n\
04416 incr i\n\
04417 continue\n\
04418 }\n\
04419 puts -nonewline \"\\n$i\\t\"\n\
04420 set n1 $Node_($i)\n\
04421 set j 0\n\
04422 while { $j < $n } {\n\
04423 if { $i != $j } {\n\
04424 set nh [$routingTable_ lookup $i $j]\n\
04425 if { $nh >= 0 } {\n\
04426 puts -nonewline \"$nh\\t\"\n\
04427 }\n\
04428 } else {\n\
04429 puts -nonewline \"--\\t\"\n\
04430 }\n\
04431 incr j\n\
04432 }\n\
04433 incr i\n\
04434 }\n\
04435 puts \"\"\n\
04436 }\n\
04437 \n\
04438 Simulator instproc dump-routelogic-distance {} {\n\
04439 $self instvar routingTable_ Node_ link_\n\
04440 if ![info exists routingTable_] {\n\
04441 puts \"error: routing table is not computed yet!\"\n\
04442 return 0\n\
04443 }\n\
04444 \n\
04445 set n [Node set nn_]\n\
04446 set i 0\n\
04447 puts -nonewline \"\\t\"\n\
04448 while { $i < $n } {\n\
04449 if ![info exists Node_($i)] {\n\
04450 incr i\n\
04451 continue\n\
04452 }\n\
04453 puts -nonewline \"$i\\t\"\n\
04454 incr i\n\
04455 }\n\
04456 \n\
04457 for {set i 0} {$i < $n} {incr i} {\n\
04458 if ![info exists Node_($i)] {\n\
04459 continue\n\
04460 }\n\
04461 puts -nonewline \"\\n$i\\t\"\n\
04462 set n1 $Node_($i)\n\
04463 for {set j 0} {$j < $n} {incr j} {\n\
04464 if { $i == $j } {\n\
04465 puts -nonewline \"0\\t\"\n\
04466 continue\n\
04467 }\n\
04468 set nh [$routingTable_ lookup $i $j]\n\
04469 if { $nh < 0 } {\n\
04470 puts -nonewline \"0\\t\"\n\
04471 continue\n\
04472 }\n\
04473 set distance 0\n\
04474 set tmpfrom $i\n\
04475 set tmpto $j\n\
04476 while {$tmpfrom != $tmpto} {\n\
04477 set tmpnext [$routingTable_ lookup \\\n\
04478 $tmpfrom $tmpto]\n\
04479 set distance [expr $distance + \\\n\
04480 [$link_($tmpfrom:$tmpnext) cost?]]\n\
04481 set tmpfrom $tmpnext\n\
04482 }\n\
04483 puts -nonewline \"$distance\\t\"\n\
04484 }\n\
04485 }\n\
04486 puts \"\"\n\
04487 }\n\
04488 \n\
04489 Simulator instproc compute-routes {} {\n\
04490 if [Simulator hier-addr?] {\n\
04491 $self compute-hier-routes \n\
04492 } else {\n\
04493 $self compute-flat-routes\n\
04494 }\n\
04495 }\n\
04496 \n\
04497 Simulator instproc compute-flat-routes {} {\n\
04498 $self instvar Node_ link_\n\
04499 if { [ Simulator set nix-routing] } {\n\
04500 puts \"Using NixVector routing, skipping route computations\"\n\
04501 return\n\
04502 }\n\
04503 \n\
04504 set r [$self get-routelogic]\n\
04505 $self cmd get-routelogic $r  ;# propagate rl in C++\n\
04506 \n\
04507 foreach ln [array names link_] {\n\
04508 set L [split $ln :]\n\
04509 set srcID [lindex $L 0]\n\
04510 set dstID [lindex $L 1]\n\
04511 if { [$link_($ln) up?] == \"up\" } {\n\
04512 $r insert $srcID $dstID [$link_($ln) cost?]\n\
04513 } else {\n\
04514 $r reset $srcID $dstID\n\
04515 }\n\
04516 }\n\
04517 \n\
04518 $r compute\n\
04519 \n\
04520 set n [Node set nn_]\n\
04521 \n\
04522 \n\
04523 $self populate-flat-classifiers $n\n\
04524 \n\
04525 \n\
04526 \n\
04527 }\n\
04528 \n\
04529 Simulator instproc get-link-head { n1 n2 } {\n\
04530 $self instvar link_\n\
04531 return [$link_($n1:$n2) head]\n\
04532 }\n\
04533 \n\
04534 \n\
04535 \n\
04536 Simulator instproc hier-topo {rl} {\n\
04537 AddrParams instvar domain_num_ cluster_num_ nodes_num_ \n\
04538 \n\
04539 if ![info exists cluster_num_] {\n\
04540 if {[AddrParams hlevel] > 1} {\n\
04541 set def [AddrParams set def_clusters]\n\
04542 puts \"Default value for cluster_num set to $def\\n\"\n\
04543 for {set i 0} {$i < $domain_num_} {incr i} {\n\
04544 lappend clusters $def\n\
04545 }\n\
04546 } else {\n\
04547 puts stderr \"hierarchy level = 1; should use flat-rtg instead of hier-rtg\" \n\
04548 exit 1\n\
04549 }\n\
04550 AddrParams set cluster_num_ $clusters\n\
04551 }\n\
04552 \n\
04553 if ![info exists nodes_num_ ] {\n\
04554 set total_node 0\n\
04555 set def [AddrParams set def_nodes]\n\
04556 puts \"Default value for nodes_num set to $def\\n\"\n\
04557 for {set i 0} {$i < $domain_num_} {incr i} {\n\
04558 set total_node [expr $total_node + \\\n\
04559 [lindex $clusters $i]]\n\
04560 }\n\
04561 for {set i 0} {$i < $total_node} {incr i} {\n\
04562 lappend nodes $def\n\
04563 }\n\
04564 AddrParams set nodes_num_ $nodes\n\
04565 }\n\
04566 eval $rl send-num-of-domains $domain_num_\n\
04567 eval $rl send-num-of-clusters $cluster_num_\n\
04568 eval $rl send-num-of-nodes $nodes_num_\n\
04569 }\n\
04570 \n\
04571 Simulator instproc compute-hier-routes {} {\n\
04572 $self instvar Node_ link_\n\
04573 set r [$self get-routelogic]\n\
04574 $self cmd get-routelogic $r ;# propagate rl in C++    \n\
04575 \n\
04576 if ![info exists link_] {\n\
04577 return\n\
04578 }\n\
04579 set level [AddrParams hlevel]\n\
04580 $r hlevel-is $level\n\
04581 $self hier-topo $r\n\
04582 foreach ln [array names link_] {\n\
04583 set L [split $ln :]\n\
04584 set srcID [[$self get-node-by-id [lindex $L 0]] node-addr]\n\
04585 set dstID [[$self get-node-by-id [lindex $L 1]] node-addr]\n\
04586 if { [$link_($ln) up?] == \"up\" } {\n\
04587 $r hier-insert $srcID $dstID [$link_($ln) cost?]\n\
04588 } else {\n\
04589 $r hier-reset $srcID $dstID\n\
04590 }\n\
04591 }\n\
04592 \n\
04593 $r hier-compute\n\
04594 \n\
04595 \n\
04596 \n\
04597 set n [Node set nn_]\n\
04598 $self populate-hier-classifiers $n\n\
04599 \n\
04600 \n\
04601 \n\
04602 }\n\
04603 \n\
04604 \n\
04605 \n\
04606 \n\
04607 set rtglibRNG [new RNG]\n\
04608 $rtglibRNG seed 1\n\
04609 \n\
04610 Class rtObject\n\
04611 \n\
04612 rtObject set unreach_ -1\n\
04613 rtObject set maxpref_   255\n\
04614 \n\
04615 rtObject proc init-all args {\n\
04616 foreach node $args {\n\
04617 if { [$node rtObject?] == \"\" } {\n\
04618 set rtobj($node) [new rtObject $node]\n\
04619 }\n\
04620 }\n\
04621 foreach node $args {    ;# XXX\n\
04622 $rtobj($node) compute-routes\n\
04623 }\n\
04624 }\n\
04625 \n\
04626 rtObject instproc init node {\n\
04627 $self next\n\
04628 $self instvar ns_ nullAgent_\n\
04629 $self instvar nextHop_ rtpref_ metric_ node_ rtVia_ rtProtos_\n\
04630 \n\
04631 set ns_ [Simulator instance]\n\
04632 set nullAgent_ [$ns_ set nullAgent_]\n\
04633 \n\
04634 $node init-routing $self\n\
04635 set node_ $node\n\
04636 foreach dest [$ns_ all-nodes-list] {\n\
04637 set nextHop_($dest) \"\"\n\
04638 if {$node == $dest} {\n\
04639 set rtpref_($dest) 0\n\
04640 set metric_($dest) 0\n\
04641 set rtVia_($dest) \"Agent/rtProto/Local\" ;# make dump happy\n\
04642 } else {\n\
04643 set rtpref_($dest) [$class set maxpref_]\n\
04644 set metric_($dest) [$class set unreach_]\n\
04645 set rtVia_($dest)    \"\"\n\
04646 $node add-route [$dest id] $nullAgent_\n\
04647 }\n\
04648 }\n\
04649 $self add-proto Direct $node\n\
04650 $rtProtos_(Direct) compute-routes\n\
04651 }\n\
04652 \n\
04653 rtObject instproc add-proto {proto node} {\n\
04654 $self instvar ns_ rtProtos_\n\
04655 set rtProtos_($proto) [new Agent/rtProto/$proto $node]\n\
04656 $ns_ attach-agent $node $rtProtos_($proto)\n\
04657 set rtProtos_($proto)\n\
04658 }\n\
04659 \n\
04660 rtObject instproc lookup dest {\n\
04661 $self instvar nextHop_ node_\n\
04662 if {![info exists nextHop_($dest)] || $nextHop_($dest) == \"\"} {\n\
04663 return -1\n\
04664 } else {\n\
04665 return [[$nextHop_($dest) set toNode_] id]\n\
04666 }\n\
04667 }\n\
04668 \n\
04669 rtObject instproc compute-routes {} {\n\
04670 $self instvar ns_ node_ rtProtos_ nullAgent_\n\
04671 $self instvar nextHop_ rtpref_ metric_ rtVia_\n\
04672 set protos \"\"\n\
04673 set changes 0\n\
04674 foreach p [array names rtProtos_] {\n\
04675 if [$rtProtos_($p) set rtsChanged_] {\n\
04676 incr changes\n\
04677 $rtProtos_($p) set rtsChanged_ 0\n\
04678 }\n\
04679 lappend protos $rtProtos_($p)\n\
04680 }\n\
04681 if !$changes return\n\
04682 \n\
04683 set changes 0\n\
04684 foreach dst [$ns_ all-nodes-list] {\n\
04685 if {$dst == $node_} continue\n\
04686 set nh \"\"\n\
04687 set pf [$class set maxpref_]\n\
04688 set mt [$class set unreach_]\n\
04689 set rv \"\"\n\
04690 foreach p $protos {\n\
04691 set pnh [$p set nextHop_($dst)]\n\
04692 if { $pnh == \"\" } continue\n\
04693 \n\
04694 set ppf [$p set rtpref_($dst)]\n\
04695 set pmt [$p set metric_($dst)]\n\
04696 if {$ppf < $pf || ($ppf == $pf && $pmt < $mt) || $mt < 0} {\n\
04697 set nh  $pnh\n\
04698 set pf  $ppf\n\
04699 set mt  $pmt\n\
04700 set rv  $p\n\
04701 }\n\
04702 }\n\
04703 if { $nh == \"\" } {\n\
04704 if { $nextHop_($dst) != \"\" } {\n\
04705 $node_ delete-routes [$dst id] $nextHop_($dst) $nullAgent_\n\
04706 set nextHop_($dst) $nh\n\
04707 set rtpref_($dst)  $pf\n\
04708 set metric_($dst)  $mt\n\
04709 set rtVia_($dst)   $rv\n\
04710 incr changes\n\
04711 }\n\
04712 } else {\n\
04713 if { $rv == $rtVia_($dst) } {\n\
04714 if { $nh != $nextHop_($dst) } {\n\
04715 $node_ delete-routes [$dst id] $nextHop_($dst) $nullAgent_\n\
04716 set nextHop_($dst) $nh\n\
04717 $node_ add-routes [$dst id] $nextHop_($dst)\n\
04718 incr changes\n\
04719 }\n\
04720 if { $mt != $metric_($dst) } {\n\
04721 set metric_($dst) $mt\n\
04722 incr changes\n\
04723 }\n\
04724 if { $pf != $rtpref_($dst) } {\n\
04725 set rtpref_($dst) $pf\n\
04726 }\n\
04727 } else {\n\
04728 if { $rtVia_($dst) != \"\" } {\n\
04729 set nextHop_($dst) [$rtVia_($dst) set nextHop_($dst)]\n\
04730 set rtpref_($dst)  [$rtVia_($dst) set rtpref_($dst)]\n\
04731 set metric_($dst)  [$rtVia_($dst) set metric_($dst)]\n\
04732 }\n\
04733 if {$rtpref_($dst) != $pf || $metric_($dst) != $mt} {\n\
04734 $node_ delete-routes [$dst id] $nextHop_($dst) $nullAgent_\n\
04735 set nextHop_($dst) $nh\n\
04736 set rtpref_($dst)  $pf\n\
04737 set metric_($dst)  $mt\n\
04738 set rtVia_($dst)   $rv\n\
04739 $node_ add-routes [$dst id] $nextHop_($dst)\n\
04740 incr changes\n\
04741 }\n\
04742 }\n\
04743 }\n\
04744 }\n\
04745 foreach proto [array names rtProtos_] {\n\
04746 $rtProtos_($proto) send-updates $changes\n\
04747 }\n\
04748 $self flag-multicast $changes\n\
04749 }\n\
04750 \n\
04751 rtObject instproc flag-multicast changes {\n\
04752 $self instvar node_\n\
04753 $node_ notify-mcast $changes\n\
04754 }\n\
04755 \n\
04756 rtObject instproc intf-changed {} {\n\
04757 $self instvar ns_ node_ rtProtos_ rtVia_ nextHop_ rtpref_ metric_\n\
04758 foreach p [array names rtProtos_] {\n\
04759 $rtProtos_($p) intf-changed\n\
04760 $rtProtos_($p) compute-routes\n\
04761 }\n\
04762 $self compute-routes\n\
04763 }\n\
04764 \n\
04765 rtObject instproc dump-routes chan {\n\
04766 $self instvar ns_ node_ nextHop_ rtpref_ metric_ rtVia_\n\
04767 \n\
04768 if {$ns_ != \"\"} {\n\
04769 set time [$ns_ now]\n\
04770 } else {\n\
04771 set time 0.0\n\
04772 }\n\
04773 puts $chan [concat \"Node:\\t${node_}([$node_ id])\\tat t =\"       \\\n\
04774 [format \"%4.2f\" $time]]\n\
04775 puts $chan \"  Dest\\t\\t nextHop\\tPref\\tMetric\\tProto\"\n\
04776 foreach dest [$ns_ all-nodes-list] {\n\
04777 if {[llength $nextHop_($dest)] > 1} {\n\
04778 set p [split [$rtVia_($dest) info class] /]\n\
04779 set proto [lindex $p [expr [llength $p] - 1]]\n\
04780 foreach rt $nextHop_($dest) {\n\
04781 puts $chan [format \"%-5s(%d)\\t%-5s(%d)\\t%3d\\t%4d\\t %s\"     \\\n\
04782 $dest [$dest id] $rt [[$rt set toNode_] id]  \\\n\
04783 $rtpref_($dest) $metric_($dest) $proto]\n\
04784 }\n\
04785 } elseif {$nextHop_($dest) != \"\"} {\n\
04786 set p [split [$rtVia_($dest) info class] /]\n\
04787 set proto [lindex $p [expr [llength $p] - 1]]\n\
04788 puts $chan [format \"%-5s(%d)\\t%-5s(%d)\\t%3d\\t%4d\\t %s\"     \\\n\
04789 $dest [$dest id]                     \\\n\
04790 $nextHop_($dest) [[$nextHop_($dest) set toNode_] id] \\\n\
04791 $rtpref_($dest) $metric_($dest) $proto]\n\
04792 } elseif {$dest == $node_} {\n\
04793 puts $chan [format \"%-5s(%d)\\t%-5s(%d)\\t%03d\\t%4d\\t %s\"   \\\n\
04794 $dest [$dest id] $dest [$dest id] 0 0 \"Local\"]\n\
04795 } else {\n\
04796 puts $chan [format \"%-5s(%d)\\t%-5s(%s)\\t%03d\\t%4d\\t %s\"   \\\n\
04797 $dest [$dest id] \"\" \"-\" 255 32 \"Unknown\"]\n\
04798 }\n\
04799 }\n\
04800 }\n\
04801 \n\
04802 rtObject instproc rtProto? proto {\n\
04803 $self instvar rtProtos_\n\
04804 if [info exists rtProtos_($proto)] {\n\
04805 return $rtProtos_($proto)\n\
04806 } else {\n\
04807 return \"\"\n\
04808 }\n\
04809 }\n\
04810 \n\
04811 rtObject instproc nextHop? dest {\n\
04812 $self instvar nextHop_\n\
04813 $self set nextHop_($dest)\n\
04814 }\n\
04815 \n\
04816 rtObject instproc rtpref? dest {\n\
04817 $self instvar rtpref_\n\
04818 $self set rtpref_($dest)\n\
04819 }\n\
04820 \n\
04821 rtObject instproc metric? dest {\n\
04822 $self instvar metric_\n\
04823 $self set metric_($dest)\n\
04824 }\n\
04825 \n\
04826 Class rtPeer\n\
04827 \n\
04828 rtPeer instproc init {addr port cls} {\n\
04829 $self next\n\
04830 $self instvar addr_ port_ metric_ rtpref_\n\
04831 set addr_ $addr\n\
04832 set port_ $port\n\
04833 foreach dest [[Simulator instance] all-nodes-list] {\n\
04834 set metric_($dest) [$cls set INFINITY]\n\
04835 set rtpref_($dest) [$cls set preference_]\n\
04836 }\n\
04837 }\n\
04838 \n\
04839 rtPeer instproc addr? {} {\n\
04840 $self instvar addr_\n\
04841 return $addr_\n\
04842 }\n\
04843 \n\
04844 rtPeer instproc port? {} {\n\
04845 $self instvar port_\n\
04846 return $port_\n\
04847 }\n\
04848 \n\
04849 rtPeer instproc metric {dest val} {\n\
04850 $self instvar metric_\n\
04851 set metric_($dest) $val\n\
04852 }\n\
04853 \n\
04854 rtPeer instproc metric? dest {\n\
04855 $self instvar metric_\n\
04856 return $metric_($dest)\n\
04857 }\n\
04858 \n\
04859 rtPeer instproc preference {dest val} {\n\
04860 $self instvar rtpref_\n\
04861 set rtpref_($dest) $val\n\
04862 }\n\
04863 \n\
04864 rtPeer instproc preference? dest {\n\
04865 $self instvar rtpref_\n\
04866 return $rtpref_($dest)\n\
04867 }\n\
04868 \n\
04869 \n\
04870 Agent/rtProto proc pre-init-all args {\n\
04871 }\n\
04872 \n\
04873 Agent/rtProto proc init-all args {\n\
04874 error \"No initialization defined\"\n\
04875 }\n\
04876 \n\
04877 Agent/rtProto instproc init node {\n\
04878 $self next\n\
04879 \n\
04880 $self instvar ns_ node_ rtObject_ preference_ ifs_ ifstat_\n\
04881 set ns_ [Simulator instance]\n\
04882 \n\
04883 catch \"set preference_ [[$self info class] set preference_]\" ret\n\
04884 if { $ret == \"\" } {\n\
04885 set preference_ [$class set preference_]\n\
04886 }\n\
04887 foreach nbr [$node set neighbor_] {\n\
04888 set link [$ns_ link $node $nbr]\n\
04889 set ifs_($nbr) $link\n\
04890 set ifstat_($nbr) [$link up?]\n\
04891 }\n\
04892 set rtObject_ [$node rtObject?]\n\
04893 }\n\
04894 \n\
04895 Agent/rtProto instproc compute-routes {} {\n\
04896 error \"No route computation defined\"\n\
04897 }\n\
04898 \n\
04899 Agent/rtProto instproc intf-changed {} {\n\
04900 }\n\
04901 \n\
04902 Agent/rtProto instproc send-updates args {\n\
04903 }\n\
04904 \n\
04905 Agent/rtProto proc compute-all {} {\n\
04906 }\n\
04907 \n\
04908 Class Agent/rtProto/Static -superclass Agent/rtProto\n\
04909 \n\
04910 Agent/rtProto/Static proc init-all args {\n\
04911 [Simulator instance] compute-routes\n\
04912 }\n\
04913 \n\
04914 Class Agent/rtProto/Session -superclass Agent/rtProto\n\
04915 \n\
04916 Agent/rtProto/Session proc init-all args {\n\
04917 [Simulator instance] compute-routes\n\
04918 }\n\
04919 \n\
04920 Agent/rtProto/Session proc compute-all {} {\n\
04921 [Simulator instance] compute-routes\n\
04922 }\n\
04923 \n\
04924 Class Agent/rtProto/Direct -superclass Agent/rtProto\n\
04925 Agent/rtProto/Direct instproc init node {\n\
04926 $self next $node\n\
04927 $self instvar ns_ rtpref_ nextHop_ metric_ ifs_\n\
04928 \n\
04929 foreach node [$ns_ all-nodes-list] {\n\
04930 set rtpref_($node) 255\n\
04931 set nextHop_($node) \"\"\n\
04932 set metric_($node) -1\n\
04933 }\n\
04934 foreach node [array names ifs_] {\n\
04935 set rtpref_($node) [$class set preference_]\n\
04936 }\n\
04937 }\n\
04938 \n\
04939 Agent/rtProto/Direct instproc compute-routes {} {\n\
04940 $self instvar ifs_ ifstat_ nextHop_ metric_ rtsChanged_\n\
04941 set rtsChanged_ 0\n\
04942 foreach nbr [array names ifs_] {\n\
04943 if {$nextHop_($nbr) == \"\" && [$ifs_($nbr) up?] == \"up\"} {\n\
04944 set ifstat_($nbr) 1\n\
04945 set nextHop_($nbr) $ifs_($nbr)\n\
04946 set metric_($nbr) [$ifs_($nbr) cost?]\n\
04947 incr rtsChanged_\n\
04948 } elseif {$nextHop_($nbr) != \"\" && [$ifs_($nbr) up?] != \"up\"} {\n\
04949 set ifstat_($nbr) 0\n\
04950 set nextHop_($nbr) \"\"\n\
04951 set metric_($nbr) -1\n\
04952 incr rtsChanged_\n\
04953 }\n\
04954 }\n\
04955 }\n\
04956 \n\
04957 Agent/rtProto/DV set UNREACHABLE    [rtObject set unreach_]\n\
04958 Agent/rtProto/DV set mid_         0\n\
04959 \n\
04960 Agent/rtProto/DV proc init-all args {\n\
04961 if { [llength $args] == 0 } {\n\
04962 set nodeslist [[Simulator instance] all-nodes-list]\n\
04963 } else {\n\
04964 eval \"set nodeslist $args\"\n\
04965 }\n\
04966 Agent set-maxttl Agent/rtProto/DV INFINITY\n\
04967 eval rtObject init-all $nodeslist\n\
04968 foreach node $nodeslist {\n\
04969 set proto($node) [[$node rtObject?] add-proto DV $node]\n\
04970 }\n\
04971 foreach node $nodeslist {\n\
04972 foreach nbr [$node neighbors] {\n\
04973 set rtobj [$nbr rtObject?]\n\
04974 if { $rtobj != \"\" } {\n\
04975 set rtproto [$rtobj rtProto? DV]\n\
04976 if { $rtproto != \"\" } {\n\
04977 $proto($node) add-peer $nbr [$rtproto set agent_addr_] [$rtproto set agent_port_]\n\
04978 }\n\
04979 }\n\
04980 }\n\
04981 }\n\
04982 }\n\
04983 \n\
04984 Agent/rtProto/DV instproc init node {\n\
04985 global rtglibRNG\n\
04986 \n\
04987 $self next $node\n\
04988 $self instvar ns_ rtObject_ ifsUp_\n\
04989 $self instvar preference_ rtpref_ nextHop_ nextHopPeer_ metric_ multiPath_\n\
04990 \n\
04991 set UNREACHABLE [$class set UNREACHABLE]\n\
04992 foreach dest [$ns_ all-nodes-list] {\n\
04993 set rtpref_($dest) $preference_\n\
04994 set nextHop_($dest) \"\"\n\
04995 set nextHopPeer_($dest) \"\"\n\
04996 set metric_($dest)  $UNREACHABLE\n\
04997 }\n\
04998 set ifsUp_ \"\"\n\
04999 set multiPath_ [[$rtObject_ set node_] set multiPath_]\n\
05000 set updateTime [$rtglibRNG uniform 0.0 0.5]\n\
05001 $ns_ at $updateTime \"$self send-periodic-update\"\n\
05002 }\n\
05003 \n\
05004 Agent/rtProto/DV instproc add-peer {nbr agentAddr agentPort} {\n\
05005 $self instvar peers_\n\
05006 $self set peers_($nbr) [new rtPeer $agentAddr $agentPort $class]\n\
05007 }\n\
05008 \n\
05009 Agent/rtProto/DV instproc send-periodic-update {} {\n\
05010 global rtglibRNG\n\
05011 \n\
05012 $self instvar ns_\n\
05013 $self send-updates 1    ;# Anything but 0\n\
05014 set updateTime [expr [$ns_ now] + \\\n\
05015 ([$class set advertInterval] * [$rtglibRNG uniform 0.9 1.1])]\n\
05016 $ns_ at $updateTime \"$self send-periodic-update\"\n\
05017 }\n\
05018 \n\
05019 Agent/rtProto/DV instproc compute-routes {} {\n\
05020 $self instvar ns_ ifs_ rtpref_ metric_ nextHop_ nextHopPeer_\n\
05021 $self instvar peers_ rtsChanged_ multiPath_\n\
05022 \n\
05023 set INFINITY [$class set INFINITY]\n\
05024 set MAXPREF  [rtObject set maxpref_]\n\
05025 set UNREACH  [rtObject set unreach_]\n\
05026 set rtsChanged_ 0\n\
05027 foreach dst [$ns_ all-nodes-list] {\n\
05028 set p [lindex $nextHopPeer_($dst) 0]\n\
05029 if {$p != \"\"} {\n\
05030 set metric_($dst) [$p metric? $dst]\n\
05031 set rtpref_($dst) [$p preference? $dst]\n\
05032 }\n\
05033 \n\
05034 set pf $MAXPREF\n\
05035 set mt $INFINITY\n\
05036 set nh(0) 0\n\
05037 foreach nbr [lsort -dictionary [array names peers_]] {\n\
05038 set pmt [$peers_($nbr) metric? $dst]\n\
05039 set ppf [$peers_($nbr) preference? $dst]\n\
05040 \n\
05041 \n\
05042 if { $pmt < 0 || $pmt >= $INFINITY || $ppf > $pf || $pmt > $mt } \\\n\
05043 continue\n\
05044 if { $ppf < $pf || $pmt < $mt } {\n\
05045 set pf $ppf\n\
05046 set mt $pmt\n\
05047 unset nh    ;# because we must compute *new* next hops\n\
05048 }\n\
05049 set nh($ifs_($nbr)) $peers_($nbr)\n\
05050 }\n\
05051 catch \"unset nh(0)\"\n\
05052 if { $pf == $MAXPREF && $mt == $INFINITY } continue\n\
05053 if { $pf > $rtpref_($dst) ||                \\\n\
05054 ($metric_($dst) >= 0 && $mt > $metric_($dst)) } \\\n\
05055 continue\n\
05056 if {$mt >= $INFINITY} {\n\
05057 set mt $UNREACH\n\
05058 }\n\
05059 \n\
05060 incr rtsChanged_\n\
05061 if { $pf < $rtpref_($dst) || $mt < $metric_($dst) } {\n\
05062 set rtpref_($dst) $pf\n\
05063 set metric_($dst) $mt\n\
05064 set nextHop_($dst) \"\"\n\
05065 set nextHopPeer_($dst) \"\"\n\
05066 foreach n [array names nh] {\n\
05067 lappend nextHop_($dst) $n\n\
05068 lappend nextHopPeer_($dst) $nh($n)\n\
05069 if !$multiPath_ break;\n\
05070 }\n\
05071 continue\n\
05072 }\n\
05073 \n\
05074 set rtpref_($dst) $pf\n\
05075 set metric_($dst) $mt\n\
05076 set newNextHop \"\"\n\
05077 set newNextHopPeer \"\"\n\
05078 foreach rt $nextHop_($dst) {\n\
05079 if [info exists nh($rt)] {\n\
05080 lappend newNextHop $rt\n\
05081 lappend newNextHopPeer $nh($rt)\n\
05082 unset nh($rt)\n\
05083 }\n\
05084 }\n\
05085 set nextHop_($dst) $newNextHop\n\
05086 set nextHopPeer_($dst) $newNextHopPeer\n\
05087 if { $multiPath_ || $nextHop_($dst) == \"\" } {\n\
05088 foreach rt [array names nh] {\n\
05089 lappend nextHop_($dst) $rt\n\
05090 lappend nextHopPeer_($dst) $nh($rt)\n\
05091 if !$multiPath_ break\n\
05092 }\n\
05093 }\n\
05094 }\n\
05095 set rtsChanged_\n\
05096 }\n\
05097 \n\
05098 Agent/rtProto/DV instproc intf-changed {} {\n\
05099 $self instvar ns_ peers_ ifs_ ifstat_ ifsUp_ nextHop_ nextHopPeer_ metric_\n\
05100 set INFINITY [$class set INFINITY]\n\
05101 set ifsUp_ \"\"\n\
05102 foreach nbr [lsort -dictionary [array names peers_]] {\n\
05103 set state [$ifs_($nbr) up?]\n\
05104 if {$state != $ifstat_($nbr)} {\n\
05105 set ifstat_($nbr) $state\n\
05106 if {$state != \"up\"} {\n\
05107 if ![info exists all-nodes] {\n\
05108 set all-nodes [$ns_ all-nodes-list]\n\
05109 }\n\
05110 foreach dest ${all-nodes} {\n\
05111 $peers_($nbr) metric $dest $INFINITY\n\
05112 }\n\
05113 } else {\n\
05114 lappend ifsUp_ $nbr\n\
05115 }\n\
05116 }\n\
05117 }\n\
05118 }\n\
05119 \n\
05120 Agent/rtProto/DV proc get-next-mid {} {\n\
05121 set ret [Agent/rtProto/DV set mid_]\n\
05122 Agent/rtProto/DV set mid_ [expr $ret + 1]\n\
05123 set ret\n\
05124 }\n\
05125 \n\
05126 Agent/rtProto/DV proc retrieve-msg id {\n\
05127 set ret [Agent/rtProto/DV set msg_($id)]\n\
05128 Agent/rtProto/DV unset msg_($id)\n\
05129 set ret\n\
05130 }\n\
05131 \n\
05132 Agent/rtProto/DV instproc send-updates changes {\n\
05133 $self instvar peers_ ifs_ ifsUp_\n\
05134 \n\
05135 if $changes {\n\
05136 set to-send-to [lsort -dictionary [array names peers_]]\n\
05137 } else {\n\
05138 set to-send-to $ifsUp_\n\
05139 }\n\
05140 set ifsUp_ \"\"\n\
05141 foreach nbr ${to-send-to} {\n\
05142 if { [$ifs_($nbr) up?] == \"up\" } {\n\
05143 $self send-to-peer $nbr\n\
05144 }\n\
05145 }\n\
05146 }\n\
05147 \n\
05148 Agent/rtProto/DV instproc send-to-peer nbr {\n\
05149 $self instvar ns_ rtObject_ ifs_ peers_\n\
05150 set INFINITY [$class set INFINITY]\n\
05151 foreach dest [$ns_ all-nodes-list] {\n\
05152 set metric [$rtObject_ metric? $dest]\n\
05153 if {$metric < 0} {\n\
05154 set update($dest) $INFINITY\n\
05155 } else {\n\
05156 set update($dest) [$rtObject_ metric? $dest]\n\
05157 foreach nh [$rtObject_ nextHop? $dest] {\n\
05158 if {$nh == $ifs_($nbr)} {\n\
05159 set update($dest) $INFINITY\n\
05160 }\n\
05161 }\n\
05162 }\n\
05163 }\n\
05164 \n\
05165 if { $peers_($nbr) == \"\" } {\n\
05166 return\n\
05167 }\n\
05168 \n\
05169 set id [$class get-next-mid]\n\
05170 $class set msg_($id) [array get update]\n\
05171 \n\
05172 $self send-update [$peers_($nbr) addr?] [$peers_($nbr) port?] $id [array size update]\n\
05173 }\n\
05174 \n\
05175 Agent/rtProto/DV instproc recv-update {peerAddr id} {\n\
05176 $self instvar peers_ ifs_ nextHopPeer_ metric_\n\
05177 $self instvar rtsChanged_ rtObject_\n\
05178 \n\
05179 set INFINITY [$class set INFINITY]\n\
05180 set UNREACHABLE  [$class set UNREACHABLE]\n\
05181 set msg [$class retrieve-msg $id]\n\
05182 array set metrics $msg\n\
05183 foreach nbr [lsort -dictionary [array names peers_]] {\n\
05184 if {[$peers_($nbr) addr?] == $peerAddr} {\n\
05185 set peer $peers_($nbr)\n\
05186 if { [array size metrics] > [Node set nn_] } {\n\
05187 error \"$class::$proc update $peerAddr:$msg:$count is larger than the simulation topology\"\n\
05188 }\n\
05189 set metricsChanged 0\n\
05190 foreach dest [array names metrics] {\n\
05191 set metric [expr $metrics($dest) + [$ifs_($nbr) cost?]]\n\
05192 if {$metric > $INFINITY} {\n\
05193 set metric $INFINITY\n\
05194 }\n\
05195 if {$metric != [$peer metric? $dest]} {\n\
05196 $peer metric $dest $metric\n\
05197 incr metricsChanged\n\
05198 }\n\
05199 }\n\
05200 if $metricsChanged {\n\
05201 $self compute-routes\n\
05202 incr rtsChanged_ $metricsChanged\n\
05203 $rtObject_ compute-routes\n\
05204 } else {\n\
05205 $rtObject_ flag-multicast -1\n\
05206 }\n\
05207 return\n\
05208 }\n\
05209 }\n\
05210 error \"$class::$proc update $peerAddr:$msg:$count from unknown peer\"\n\
05211 }\n\
05212 \n\
05213 Agent/rtProto/DV proc compute-all {} {\n\
05214 }\n\
05215 \n\
05216 Class Agent/rtProto/Manual -superclass Agent/rtProto\n\
05217 \n\
05218 Agent/rtProto/Manual proc pre-init-all args {\n\
05219 Node enable-module Manual\n\
05220 }\n\
05221 \n\
05222 Agent/rtProto/Manual proc init-all args {\n\
05223 }\n\
05224 \n\
05225 \n\
05226 \n\
05227 \n\
05228 Class rtQueue\n\
05229 \n\
05230 Simulator instproc rtmodel { dist parms args } {\n\
05231 set ret \"\"\n\
05232 if { [rtModel info subclass rtModel/$dist] != \"\" } {\n\
05233 $self instvar  rtModel_\n\
05234 set ret [eval new rtModel/$dist $self]\n\
05235 eval $ret set-elements $args\n\
05236 eval $ret set-parms $parms\n\
05237 set trace [$self get-ns-traceall]\n\
05238 if {$trace != \"\"} {\n\
05239 $ret trace $self $trace\n\
05240 }\n\
05241 set trace [$self get-nam-traceall]\n\
05242 if {$trace != \"\"} {\n\
05243 $ret trace $self $trace \"nam\"\n\
05244 }\n\
05245 if [info exists rtModel_] {\n\
05246 lappend rtModel_ $ret\n\
05247 } else {\n\
05248 set rtModel_ $ret\n\
05249 }\n\
05250 }\n\
05251 return $ret\n\
05252 }\n\
05253 \n\
05254 Simulator instproc rtmodel-configure {} {\n\
05255 $self instvar rtq_ rtModel_\n\
05256 if [info exists rtModel_] {\n\
05257 set rtq_ [new rtQueue $self]\n\
05258 foreach m $rtModel_ {\n\
05259 $m configure\n\
05260 }\n\
05261 }\n\
05262 }\n\
05263 \n\
05264 Simulator instproc rtmodel-at {at op args} {\n\
05265 set parms [list $op $at]\n\
05266 eval $self rtmodel Manual [list $parms] $args\n\
05267 }\n\
05268 \n\
05269 Simulator instproc rtmodel-delete model {\n\
05270 $self instvar rtModel_\n\
05271 set idx [lsearch -exact $rtModel_ $model]\n\
05272 if { $idx != -1 } {\n\
05273 delete $model\n\
05274 set rtModel_ [lreplace $rtModel_ $idx $idx]\n\
05275 }\n\
05276 }\n\
05277 \n\
05278 rtQueue instproc init ns {\n\
05279 $self next\n\
05280 $self instvar ns_\n\
05281 set ns_ $ns\n\
05282 }\n\
05283 \n\
05284 rtQueue instproc insq-i { interval obj iproc args } {\n\
05285 $self instvar rtq_ ns_\n\
05286 set time [expr $interval + [$ns_ now]]\n\
05287 if ![info exists rtq_($time)] {\n\
05288 $ns_ at $time \"$self runq $time\"\n\
05289 }\n\
05290 lappend rtq_($time) \"$obj $iproc $args\"\n\
05291 return $time\n\
05292 }\n\
05293 \n\
05294 rtQueue instproc insq { at obj iproc args } {\n\
05295 $self instvar rtq_ ns_\n\
05296 if {[$ns_ now] >= $at} {\n\
05297 puts stderr \"$proc: Cannot set event in the past\"\n\
05298 set at \"\"\n\
05299 } else {\n\
05300 if ![info exists rtq_($at)] {\n\
05301 $ns_ at $at \"$self runq $at\"\n\
05302 }\n\
05303 lappend rtq_($at) \"$obj $iproc $args\"\n\
05304 }\n\
05305 return $at\n\
05306 }\n\
05307 \n\
05308 rtQueue instproc delq { time obj } {\n\
05309 $self instvar rtq_\n\
05310 set ret \"\"\n\
05311 set nevent \"\"\n\
05312 if [info exists rtq_($time)] {\n\
05313 foreach event $rtq_($time) {\n\
05314 if {[lindex $event 0] != $obj} {\n\
05315 lappend nevent $event\n\
05316 } else {\n\
05317 set ret $event\n\
05318 }\n\
05319 }\n\
05320 set rtq_($time) $nevent     ;# XXX\n\
05321 }\n\
05322 return ret\n\
05323 }\n\
05324 \n\
05325 rtQueue instproc runq { time } {\n\
05326 $self instvar rtq_\n\
05327 set objects \"\"\n\
05328 foreach event $rtq_($time) {\n\
05329 set obj   [lindex $event 0]\n\
05330 set iproc [lindex $event 1]\n\
05331 set args  [lrange $event 2 end]\n\
05332 eval $obj $iproc $args\n\
05333 lappend objects $obj\n\
05334 }\n\
05335 foreach obj $objects {\n\
05336 $obj notify\n\
05337 }\n\
05338 unset rtq_($time)\n\
05339 }\n\
05340 \n\
05341 Class rtModel\n\
05342 \n\
05343 rtModel set rtq_ \"\"\n\
05344 \n\
05345 rtModel instproc init ns {\n\
05346 $self next\n\
05347 $self instvar ns_ startTime_ finishTime_\n\
05348 set ns_ $ns\n\
05349 set startTime_ [$class set startTime_]\n\
05350 set finishTime_ [$class set finishTime_]\n\
05351 }\n\
05352 \n\
05353 rtModel instproc set-elements args {\n\
05354 $self instvar ns_ links_ nodes_\n\
05355 if { [llength $args] == 2 } {\n\
05356 set n0 [lindex $args 0]\n\
05357 set n1 [lindex $args 1]\n\
05358 set n0id [$n0 id]\n\
05359 set n1id [$n1 id]\n\
05360 \n\
05361 set nodes_($n0id) $n0\n\
05362 set nodes_($n1id) $n1\n\
05363 set links_($n0id:$n1id) [$ns_ link $n0 $n1]\n\
05364 set links_($n1id:$n0id) [$ns_ link $n1 $n0]\n\
05365 } else {\n\
05366 set n0 [lindex $args 0]\n\
05367 set n0id [$n0 id]\n\
05368 set nodes_($n0id) $n0\n\
05369 foreach nbr [$n0 set neighbor_] {\n\
05370 set n1 $nbr\n\
05371 set n1id [$n1 id]\n\
05372 \n\
05373 set nodes_($n1id) $n1\n\
05374 set links_($n0id:$n1id) [$ns_ link $n0 $n1]\n\
05375 set links_($n1id:$n0id) [$ns_ link $n1 $n0]\n\
05376 }\n\
05377 }\n\
05378 }\n\
05379 \n\
05380 rtModel instproc set-parms args {\n\
05381 $self instvar startTime_ upInterval_ downInterval_ finishTime_\n\
05382 \n\
05383 set cls [$self info class]\n\
05384 foreach i {startTime_ upInterval_ downInterval_ finishTime_} {\n\
05385 if [catch \"$cls set $i\" $i] {\n\
05386 set $i [$class set $i]\n\
05387 }\n\
05388 }\n\
05389 \n\
05390 set off \"-\"\n\
05391 set up  \"-\"\n\
05392 set dn  \"-\"\n\
05393 set fin \"-\"\n\
05394 \n\
05395 switch [llength $args] {\n\
05396 4 {\n\
05397 set off [lindex $args 0]\n\
05398 set up  [lindex $args 1]\n\
05399 set dn  [lindex $args 2]\n\
05400 set fin [lindex $args 3]\n\
05401 }\n\
05402 3 {\n\
05403 set off [lindex $args 0]\n\
05404 set up  [lindex $args 1]\n\
05405 set dn  [lindex $args 2]\n\
05406 }\n\
05407 2 {\n\
05408 set up [lindex $args 0]\n\
05409 set dn [lindex $args 1]\n\
05410 }\n\
05411 }\n\
05412 if {$off != \"-\" && $off != \"\"} {\n\
05413 set startTime_ $off\n\
05414 }\n\
05415 if {$up != \"-\" && $up != \"\"} {\n\
05416 set upInterval_ $up\n\
05417 }\n\
05418 if {$dn != \"-\" && $dn != \"\"} {\n\
05419 set downInterval_ $dn\n\
05420 }\n\
05421 if {$fin != \"-\" && $fin != \"\"} {\n\
05422 set finishTime_ $fin\n\
05423 }\n\
05424 }\n\
05425 \n\
05426 rtModel instproc configure {} {\n\
05427 $self instvar ns_ links_\n\
05428 if { [rtModel set rtq_] == \"\" } {\n\
05429 rtModel set rtq_ [$ns_ set rtq_]\n\
05430 }\n\
05431 \n\
05432 foreach l [array names links_] {\n\
05433 $links_($l) dynamic\n\
05434 }\n\
05435 $self set-first-event\n\
05436 }\n\
05437 \n\
05438 rtModel instproc set-event-exact {fireTime op} {\n\
05439 $self instvar ns_ finishTime_\n\
05440 if {$finishTime_ != \"-\" && $fireTime > $finishTime_} {\n\
05441 if {$op == \"up\"} {\n\
05442 [rtModel set rtq_] insq $finishTime_ $self $op\n\
05443 }\n\
05444 } else {\n\
05445 [rtModel set rtq_] insq $fireTime $self $op\n\
05446 }\n\
05447 }\n\
05448 \n\
05449 rtModel instproc set-event {interval op} {\n\
05450 $self instvar ns_\n\
05451 $self set-event-exact [expr [$ns_ now] + $interval] $op\n\
05452 }\n\
05453 \n\
05454 rtModel instproc set-first-event {} {\n\
05455 $self instvar startTime_ upInterval_\n\
05456 $self set-event [expr $startTime_ + $upInterval_] down\n\
05457 }\n\
05458 \n\
05459 rtModel instproc up {} {\n\
05460 $self instvar links_\n\
05461 foreach l [array names links_] {\n\
05462 $links_($l) up\n\
05463 }\n\
05464 }\n\
05465 \n\
05466 rtModel instproc down {} {\n\
05467 $self instvar links_\n\
05468 foreach l [array names links_] {\n\
05469 $links_($l) down\n\
05470 }\n\
05471 }\n\
05472 \n\
05473 rtModel instproc notify {} {\n\
05474 $self instvar nodes_ ns_\n\
05475 foreach n [array names nodes_] {\n\
05476 $nodes_($n) intf-changed\n\
05477 }\n\
05478 [$ns_ get-routelogic] notify\n\
05479 }\n\
05480 \n\
05481 rtModel instproc trace { ns f {op \"\"} } {\n\
05482 $self instvar links_\n\
05483 foreach l [array names links_] {\n\
05484 $links_($l) trace-dynamics $ns $f $op\n\
05485 }\n\
05486 }\n\
05487 \n\
05488 \n\
05489 Class rtModel/Exponential -superclass rtModel\n\
05490 \n\
05491 rtModel/Exponential instproc set-first-event {} {\n\
05492 global rtglibRNG\n\
05493 \n\
05494 $self instvar startTime_ upInterval_\n\
05495 $self set-event [expr $startTime_ + [$rtglibRNG exponential] * $upInterval_] down\n\
05496 }\n\
05497 \n\
05498 rtModel/Exponential instproc up { } {\n\
05499 global rtglibRNG\n\
05500 \n\
05501 $self next\n\
05502 $self instvar upInterval_\n\
05503 $self set-event [expr [$rtglibRNG exponential] * $upInterval_] down\n\
05504 }\n\
05505 \n\
05506 rtModel/Exponential instproc down { } {\n\
05507 global rtglibRNG\n\
05508 \n\
05509 $self next\n\
05510 $self instvar downInterval_\n\
05511 $self set-event [expr [$rtglibRNG exponential] * $downInterval_] up\n\
05512 }\n\
05513 \n\
05514 \n\
05515 Class rtModel/Deterministic -superclass rtModel\n\
05516 \n\
05517 rtModel/Deterministic instproc up { } {\n\
05518 $self next\n\
05519 $self instvar upInterval_\n\
05520 $self set-event $upInterval_ down\n\
05521 }\n\
05522 \n\
05523 rtModel/Deterministic instproc down { } {\n\
05524 $self next\n\
05525 $self instvar downInterval_\n\
05526 $self set-event $downInterval_ up\n\
05527 }\n\
05528 \n\
05529 \n\
05530 Class rtModel/Trace -superclass rtModel\n\
05531 \n\
05532 rtModel/Trace instproc get-next-event {} {\n\
05533 $self instvar tracef_ links_\n\
05534 while {[gets $tracef_ event] >= 0} {\n\
05535 set toks [split $event]\n\
05536 if [info exists links_([lindex $toks 3]:[lindex $toks 4])] {\n\
05537 return $toks\n\
05538 }\n\
05539 }\n\
05540 return \"\"\n\
05541 }\n\
05542 \n\
05543 rtModel/Trace instproc set-trace-events {} {\n\
05544 $self instvar ns_ nextEvent_ evq_\n\
05545 \n\
05546 set time [lindex $nextEvent_ 1]\n\
05547 while {$nextEvent_ != \"\"} {\n\
05548 set nextTime [lindex $nextEvent_ 1]\n\
05549 if {$nextTime < $time} {\n\
05550 puts stderr \"event $nextEvent_  is before current time $time. ignored.\"\n\
05551 continue\n\
05552 }\n\
05553 if {$nextTime > $time} break\n\
05554 if ![info exists evq_($time)] {\n\
05555 set op [string range [lindex $nextEvent_ 2] 5 end]\n\
05556 $self set-event-exact $time $op\n\
05557 set evq_($time) 1\n\
05558 }\n\
05559 set nextEvent_ [$self get-next-event]\n\
05560 }\n\
05561 }\n\
05562 \n\
05563 \n\
05564 rtModel/Trace instproc set-parms traceFile {\n\
05565 $self instvar tracef_ nextEvent_\n\
05566 if [catch \"open $traceFile r\" tracef_] {\n\
05567 puts stderr \"cannot open $traceFile\"\n\
05568 } else {\n\
05569 set nextEvent_ [$self get-next-event]\n\
05570 if {$nextEvent_ == \"\"} {\n\
05571 puts stderr \"no relevant events in $traceFile\"\n\
05572 }\n\
05573 }\n\
05574 }\n\
05575 \n\
05576 rtModel/Trace instproc set-first-event {} {\n\
05577 $self set-trace-events\n\
05578 }\n\
05579 \n\
05580 rtModel/Trace instproc up {} {\n\
05581 $self next\n\
05582 $self set-trace-events\n\
05583 }\n\
05584 \n\
05585 rtModel/Trace instproc down {} {\n\
05586 $self next\n\
05587 $self set-trace-events\n\
05588 }\n\
05589 \n\
05590 Class rtModel/Manual -superclass rtModel\n\
05591 \n\
05592 rtModel/Manual instproc set-first-event {} {\n\
05593 $self instvar op_ at_\n\
05594 $self set-event-exact $at_ $op_ ;# you could concievably set a finishTime_?\n\
05595 }\n\
05596 \n\
05597 rtModel/Manual instproc set-parms {op at} {\n\
05598 $self instvar op_ at_\n\
05599 set op_ $op\n\
05600 set at_ $at\n\
05601 }\n\
05602 \n\
05603 rtModel/Manual instproc notify {} {\n\
05604 $self next\n\
05605 delete $self        ;# XXX wierd code alert.\n\
05606 }\n\
05607 Class Agent/rtProto/Algorithmic -superclass Agent/rtProto\n\
05608 \n\
05609 Agent/rtProto/Algorithmic proc init-all args {\n\
05610 [Simulator instance] compute-algo-routes\n\
05611 }\n\
05612 \n\
05613 Agent/rtProto/Algorithmic proc compute-all {} {\n\
05614 [Simulator instance] compute-algo-routes\n\
05615 }\n\
05616 \n\
05617 RouteLogic/Algorithmic instproc BFS {} {\n\
05618 $self instvar ns_ children_ root_ rank_\n\
05619 \n\
05620 set ns_ [Simulator instance]\n\
05621 if {[$ns_ info class] == \"Simulator\"} {\n\
05622 $ns_ instvar link_\n\
05623 foreach ln [array names link_] {\n\
05624 set L [split $ln :]\n\
05625 set srcID [lindex $L 0]\n\
05626 set dstID [lindex $L 1]\n\
05627 if ![info exist adj($srcID)] {\n\
05628 set adj($srcID) \"\"\n\
05629 }\n\
05630 if ![info exist adj($dstID)] {\n\
05631 set adj($dstID) \"\"\n\
05632 }\n\
05633 if {[lsearch $adj($srcID) $dstID] < 0} {\n\
05634 lappend adj($srcID) $dstID\n\
05635 }\n\
05636 if {[lsearch $adj($dstID) $srcID] < 0} {\n\
05637 lappend adj($dstID) $srcID\n\
05638 }\n\
05639 }\n\
05640 } elseif {[$ns_ info class] == \"SessionSim\"} {\n\
05641 $ns_ instvar delay_\n\
05642 foreach ln [array names delay_] {\n\
05643 set L [split $ln :]\n\
05644 set srcID [lindex $L 0]\n\
05645 set dstID [lindex $L 1]\n\
05646 if ![info exist adj($srcID)] {\n\
05647 set adj($srcID) \"\"\n\
05648 }\n\
05649 if ![info exist adj($dstID)] {\n\
05650 set adj($dstID) \"\"\n\
05651 }\n\
05652 if {[lsearch $adj($srcID) $dstID] < 0} {\n\
05653 lappend adj($srcID) $dstID\n\
05654 }\n\
05655 if {[lsearch $adj($dstID) $srcID] < 0} {\n\
05656 lappend adj($dstID) $srcID\n\
05657 }\n\
05658 }\n\
05659 }\n\
05660 \n\
05661 \n\
05662 set rank_ 0\n\
05663 set root_ 0\n\
05664 set traversed($root_) 1\n\
05665 set queue \"$root_\"\n\
05666 \n\
05667 while {[llength $queue] > 0} {\n\
05668 set parent [lindex $queue 0]\n\
05669 set queue [lreplace $queue 0 0]\n\
05670 if ![info exist children_($parent)] {\n\
05671 set children_($parent) \"\"\n\
05672 }\n\
05673 \n\
05674 foreach nd $adj($parent) {\n\
05675 if ![info exist traversed($nd)] {\n\
05676 set traversed($nd) 0\n\
05677 }\n\
05678 if !$traversed($nd) {\n\
05679 set traversed($nd) 1\n\
05680 lappend children_($parent) $nd\n\
05681 lappend queue $nd\n\
05682 }\n\
05683 }\n\
05684 set num_children [llength $children_($parent)]\n\
05685 if {$rank_ < $num_children} {\n\
05686 set rank_ $num_children\n\
05687 }\n\
05688 }\n\
05689 }\n\
05690 \n\
05691 RouteLogic/Algorithmic instproc compute {} {\n\
05692 $self instvar root_ children_ rank_ id_ algoAdd_\n\
05693 \n\
05694 \n\
05695 set queue [list [list $root_ 0]]\n\
05696 \n\
05697 while {[llength $queue] > 0} {\n\
05698 set parent [lindex $queue 0]\n\
05699 set queue [lreplace $queue 0 0]\n\
05700 set id [lindex $parent 0]\n\
05701 set algoAdd [lindex $parent 1]\n\
05702 set id_($algoAdd) $id\n\
05703 set algoAdd_($id) $algoAdd\n\
05704 \n\
05705 set i 0\n\
05706 foreach child $children_($id) {\n\
05707 incr i\n\
05708 lappend queue [list $child [expr [expr $algoAdd * $rank_] + $i]]\n\
05709 }\n\
05710 }\n\
05711 }\n\
05712 \n\
05713 RouteLogic/Algorithmic instproc lookup {src dst} {\n\
05714 $self instvar id_ algoAdd_\n\
05715 set algosrc $algoAdd_($src)\n\
05716 set algodst $algoAdd_($dst)\n\
05717 set algonxt [$self algo-lookup $algosrc $algodst]\n\
05718 return $id_($algonxt)\n\
05719 }\n\
05720 \n\
05721 \n\
05722 RouteLogic/Algorithmic instproc algo-lookup {src dst} {\n\
05723 $self instvar rank_\n\
05724 \n\
05725 if {$src == $dst} {\n\
05726 return $src\n\
05727 }\n\
05728 set a $src\n\
05729 set b $dst\n\
05730 set offset 0\n\
05731 \n\
05732 while {$b > $a} {\n\
05733 set offset [expr $b % $rank_]\n\
05734 set b [expr $b / $rank_]\n\
05735 if {$offset == 0} {\n\
05736 set offset $rank_\n\
05737 set b [expr $b - 1]\n\
05738 }\n\
05739 }\n\
05740 \n\
05741 if {$b == $a} {\n\
05742 return [expr [expr $a * $rank_] + $offset]\n\
05743 } else {\n\
05744 return [expr [expr $a - 1] / $rank_]\n\
05745 }\n\
05746 }\n\
05747 \n\
05748 \n\
05749 Simulator instproc compute-algo-routes {} {\n\
05750 $self instvar Node_ link_\n\
05751 set r [$self get-routelogic]\n\
05752 \n\
05753 $r BFS\n\
05754 $r compute\n\
05755 \n\
05756 set i 0\n\
05757 set n [Node set nn_]\n\
05758 while { $i < $n } {\n\
05759 if ![info exists Node_($i)] {\n\
05760 incr i\n\
05761 continue\n\
05762 }\n\
05763 set n1 $Node_($i)\n\
05764 $n1 set rtsize_ 1 \n\
05765 set j 0\n\
05766 while { $j < $n } {\n\
05767 if { $i != $j } {\n\
05768 set nh [$r lookup $i $j]\n\
05769 if { $nh >= 0 } {\n\
05770 $n1 add-route $j [$link_($i:$nh) head]\n\
05771 }\n\
05772 } \n\
05773 incr j\n\
05774 }\n\
05775 incr i\n\
05776 }\n\
05777 }\n\
05778 \n\
05779 \n\
05780 \n\
05781 \n\
05782 \n\
05783 \n\
05784 Simulator instproc asim-run { } {\n\
05785 \n\
05786 $self instvar asim_\n\
05787 set asim_ [new Asim]\n\
05788 $self asim-dump ddt\n\
05789 $asim_ readinput ddt\n\
05790 $asim_ run\n\
05791 \n\
05792 }\n\
05793 \n\
05794 Simulator instproc asim-dump { file } {\n\
05795 \n\
05796 $self instvar routingTable_ Node_ link_\n\
05797 $self instvar nconn_ conn_ sflows_ nsflows_\n\
05798 \n\
05799 set tf_ [open \"$file\" w]\n\
05800 \n\
05801 set r [$self get-routelogic]    \n\
05802 $self cmd get-routelogic $r  ;# propagate rl in C++\n\
05803 foreach ln [array names link_] {\n\
05804 set L [split $ln :]\n\
05805 set srcID [lindex $L 0]\n\
05806 set dstID [lindex $L 1]\n\
05807 if { [$link_($ln) up?] == \"up\" } {\n\
05808 $r insert $srcID $dstID [$link_($ln) cost?]\n\
05809 } else {\n\
05810 $r reset $srcID $dstID\n\
05811 }\n\
05812 }\n\
05813 $r compute\n\
05814 \n\
05815 puts $tf_ \"# Dumping Approx-Sim Data\"  \n\
05816 \n\
05817 set n [Node set nn_]\n\
05818 puts $tf_ \"m [Link set nl_] \"\n\
05819 foreach qn [array names link_] {\n\
05820 set l $link_($qn)\n\
05821 set q [$l queue]\n\
05822 set t [$q info class]\n\
05823 if {[lindex [split $t \"/\"] 1] == \"DropTail\"} {\n\
05824 puts $tf_ \"link [expr [$l set id_] + 1] [$l delay] [expr [$l bw] / 8000] [expr [$l bw] / 8000]  [$l qsize] $t\"\n\
05825 }\n\
05826 if {[lindex [split $t \"/\"] 1] == \"RED\"} {\n\
05827 puts $tf_ \"link [expr [$l set id_] + 1] [$l delay] [expr [$l bw] / 8000] [expr [$l bw] / 8000] [$l qsize] red [$q set thresh_] 0 [$q set maxthresh_] [expr 1.0 / [$q set linterm_] ]\"\n\
05828 }\n\
05829 }\n\
05830 \n\
05831 puts $tf_ \"\"\n\
05832 puts $tf_ \"n [expr $nconn_ + $nsflows_]\"\n\
05833 \n\
05834 set i 0\n\
05835 foreach x $conn_ {\n\
05836 \n\
05837 set len 0\n\
05838 set str \"\"\n\
05839 \n\
05840 set list [split $x \":\"] \n\
05841 set srcid [lindex $list 0]\n\
05842 set dstid [lindex $list 1]\n\
05843 \n\
05844 while { $srcid != $dstid } {\n\
05845 incr len\n\
05846 set nh [$r lookup $srcid $dstid]\n\
05847 append str \" \" [expr [$link_($srcid:$nh) id] + 1] \n\
05848 set srcid  $nh\n\
05849 }\n\
05850 \n\
05851 puts $tf_ \"route [expr $i + 1] $len $str\"\n\
05852 incr i\n\
05853 \n\
05854 }\n\
05855 \n\
05856 foreach x $sflows_ {\n\
05857 \n\
05858 set len 0\n\
05859 set str \"\"\n\
05860 \n\
05861 set list [split $x \":\"] \n\
05862 set srcid [lindex $list 0]\n\
05863 set dstid [lindex $list 1]\n\
05864 set lambda [lindex $list 2]\n\
05865 set mu [lindex $list 3]\n\
05866 \n\
05867 while { $srcid != $dstid } {\n\
05868 incr len\n\
05869 set nh [$r lookup $srcid $dstid]\n\
05870 append str \" \" [expr [$link_($srcid:$nh) id] + 1] \n\
05871 set srcid  $nh\n\
05872 }\n\
05873 \n\
05874 puts $tf_ \"route [expr $i + 1] $len $str sh $lambda $mu\"\n\
05875 incr i\n\
05876 \n\
05877 }\n\
05878 \n\
05879 close $tf_\n\
05880 }\n\
05881 \n\
05882 Simulator instproc asim-getLinkDelay { link } {\n\
05883 \n\
05884 $self instvar asim_\n\
05885 set t [$asim_ get-link-delay [$link set id_] ]\n\
05886 return $t\n\
05887 \n\
05888 }\n\
05889 \n\
05890 Simulator instproc asim-getLinkDrop { link } {\n\
05891 \n\
05892 $self instvar asim_\n\
05893 set t [$asim_ get-link-drop [$link set id_] ]\n\
05894 return $t\n\
05895 \n\
05896 }\n\
05897 \n\
05898 Simulator instproc asim-getLinkTput { link } {\n\
05899 \n\
05900 $self instvar asim_\n\
05901 set t [$asim_ get-link-tput [$link set id_] ]\n\
05902 return $t\n\
05903 \n\
05904 }\n\
05905 \n\
05906 Simulator instproc asim-getAggrTput { srcnode dstnode } {\n\
05907 \n\
05908 $self instvar conn_\n\
05909 $self instvar asim_ \n\
05910 set src [$srcnode id]\n\
05911 set dst [$dstnode id]\n\
05912 set tt [lsearch -exact $conn_ $src:$dst]\n\
05913 set t [$asim_ get-flow-tput $tt ]\n\
05914 return $t\n\
05915 \n\
05916 }\n\
05917 \n\
05918 Simulator instproc asim-getFlowTput { agent } {\n\
05919 \n\
05920 $self instvar conn_\n\
05921 $self instvar asim_\n\
05922 \n\
05923 set srcnode [$self get-node-by-addr [$agent set agent_addr_]]\n\
05924 set dstnode [$self get-node-by-addr [$agent set dst_addr_]]\n\
05925 \n\
05926 set src [$srcnode id]\n\
05927 set dst [$dstnode id]\n\
05928 set sport [$agent set agent_port_]\n\
05929 set dport [$agent set dst_port_]\n\
05930 set tt [lsearch -exact $conn_ $src:$dst:$sport:$dport]\n\
05931 set t [$asim_ get-flow-tput $tt ]\n\
05932 return $t\n\
05933 \n\
05934 }\n\
05935 \n\
05936 \n\
05937 Simulator instproc asim-getFlowDrop { agent } {\n\
05938 \n\
05939 $self instvar conn_\n\
05940 $self instvar asim_\n\
05941 \n\
05942 set srcnode [$self get-node-by-addr [$agent set agent_addr_]]\n\
05943 set dstnode [$self get-node-by-addr [$agent set dst_addr_]]\n\
05944 \n\
05945 set src [$srcnode id]\n\
05946 set dst [$dstnode id]\n\
05947 set sport [$agent set agent_port_]\n\
05948 set dport [$agent set dst_port_]\n\
05949 set tt [lsearch -exact $conn_ $src:$dst:$sport:$dport]\n\
05950 set t [$asim_ get-flow-drop $tt ]\n\
05951 return $t\n\
05952 \n\
05953 }\n\
05954 \n\
05955 \n\
05956 \n\
05957 \n\
05958 ErrorModel instproc init {} {\n\
05959 eval $self next\n\
05960 set ns [Simulator instance]\n\
05961 $ns create-eventtrace Event $self\n\
05962 }\n\
05963 \n\
05964 ErrorModel/Trace instproc init {{filename \"\"}} {\n\
05965 $self instvar file_\n\
05966 $self next\n\
05967 set file_ \"\"\n\
05968 if {$filename != \"\"} {\n\
05969 $self open $filename\n\
05970 }\n\
05971 }\n\
05972 \n\
05973 ErrorModel/Trace instproc open {filename} {\n\
05974 $self instvar file_\n\
05975 if {! [file readable $filename]} {\n\
05976 puts \"$class: cannot open $filename\"\n\
05977 return\n\
05978 }\n\
05979 if {$file_ != \"\"} {\n\
05980 close $file_\n\
05981 }\n\
05982 set file_ [open $filename]\n\
05983 $self read\n\
05984 }\n\
05985 \n\
05986 ErrorModel/Trace instproc read {} {\n\
05987 $self instvar file_ good_ loss_\n\
05988 if {$file_ != \"\"} {\n\
05989 set line [gets $file_]\n\
05990 set good_ [lindex $line 0]\n\
05991 set loss_ [lindex $line 1]\n\
05992 } else {\n\
05993 set good_ 123456789\n\
05994 set loss_ 0\n\
05995 }\n\
05996 }\n\
05997 \n\
05998 \n\
05999 ErrorModel/TwoState instproc init {rv0 rv1 {unit \"pkt\"}} {\n\
06000 $self next\n\
06001 $self unit $unit\n\
06002 $self ranvar 0 $rv0\n\
06003 $self ranvar 1 $rv1\n\
06004 }\n\
06005 \n\
06006 \n\
06007 Class ErrorModel/Uniform -superclass ErrorModel\n\
06008 Class ErrorModel/Expo -superclass ErrorModel/TwoState\n\
06009 Class ErrorModel/Empirical -superclass ErrorModel/TwoState\n\
06010 \n\
06011 ErrorModel/Uniform instproc init {rate {unit \"pkt\"}} {\n\
06012 $self next\n\
06013 $self unit $unit\n\
06014 $self set rate_ $rate\n\
06015 }\n\
06016 \n\
06017 ErrorModel/Expo instproc init {avgList {unit \"pkt\"}} {\n\
06018 set rv0 [new RandomVariable/Exponential]\n\
06019 set rv1 [new RandomVariable/Exponential]\n\
06020 $rv0 set avg_ [lindex $avgList 0]\n\
06021 $rv1 set avg_ [lindex $avgList 1]\n\
06022 $self next $rv0 $rv1 $unit\n\
06023 }\n\
06024 \n\
06025 ErrorModel/Empirical instproc init {fileList {unit \"pkt\"}} {\n\
06026 set rv0 [new RandomVariable/Empirical]\n\
06027 set rv1 [new RandomVariable/Empirical]\n\
06028 $rv0 loadCDF [lindex $fileList 0]\n\
06029 $rv1 loadCDF [lindex $fileList 1]\n\
06030 $self next $rv0 $rv1 $unit\n\
06031 }\n\
06032 \n\
06033 ErrorModel/MultiState instproc init {states periods trans transunit sttype nstates start} {\n\
06034 \n\
06035 $self instvar states_ transmatrix_ transunit_ nstates_ curstate_ eu_ periods_\n\
06036 \n\
06037 $self next\n\
06038 set states_ $states\n\
06039 set periods_ $periods\n\
06040 set transmatrix_ $trans\n\
06041 set transunit_ $transunit\n\
06042 $self sttype $sttype\n\
06043 set nstates_ $nstates\n\
06044 set curstate_ $start\n\
06045 set eu_ $transunit\n\
06046 $self error-model $start\n\
06047 \n\
06048 if { [$self sttype] == \"time\" } {\n\
06049 for { set i 0 } { $i < $nstates_ } {incr i} {\n\
06050 if { [lindex $states_ $i] == $curstate_ } {\n\
06051 break\n\
06052 }\n\
06053 }\n\
06054 $self set curperiod_ [lindex $periods_ $i]\n\
06055 }\n\
06056 }\n\
06057 \n\
06058 ErrorModel/MultiState instproc corrupt { } {\n\
06059 $self instvar states_ transmatrix_ transunit_ curstate_\n\
06060 \n\
06061 set cur $curstate_\n\
06062 if { [$self sttype] == \"time\" } {\n\
06063 set curstate_ [$self time-transition]\n\
06064 } else {\n\
06065 set curstate_ [$self transition]\n\
06066 }\n\
06067 \n\
06068 if { $cur != $curstate_ } {\n\
06069 $cur reset\n\
06070 $self reset\n\
06071 $self error-model $curstate_\n\
06072 }\n\
06073 return [$curstate_ next]\n\
06074 }\n\
06075 \n\
06076 \n\
06077 ErrorModel/MultiState instproc time-transition { } {\n\
06078 $self instvar states_ transmatrix_ transunit_ curstate_ nstates_ periods_\n\
06079 \n\
06080 if {[$self set texpired_] != 1} {\n\
06081 return $curstate_\n\
06082 }\n\
06083 \n\
06084 for { set i 0 } { $i < $nstates_ } {incr i} {\n\
06085 if { [lindex $states_ $i] == $curstate_ } {\n\
06086 break\n\
06087 }\n\
06088 }\n\
06089 \n\
06090 set trans [lindex $transmatrix_ $i]\n\
06091 set p [uniform 0 1]\n\
06092 set total 0\n\
06093 for { set i 0 } { $i < $nstates_ } {incr i } {\n\
06094 set total [expr $total + [lindex $trans $i]]\n\
06095 if { $p <= $total } {\n\
06096 $self set curperiod_ [lindex $periods_ $i]\n\
06097 return [lindex $states_ $i]\n\
06098 }\n\
06099 }\n\
06100 puts \"Misconfigured state transition: prob $p total $total $nstates_\"\n\
06101 return $curstate_\n\
06102 }\n\
06103 \n\
06104 ErrorModel/MultiState instproc transition { } {\n\
06105 $self instvar states_ transmatrix_ transunit_ curstate_ nstates_\n\
06106 \n\
06107 for { set i 0 } { $i < $nstates_ } {incr i} {\n\
06108 if { [lindex $states_ $i] == $curstate_ } {\n\
06109 break\n\
06110 }\n\
06111 }\n\
06112 set trans [lindex $transmatrix_ $i]\n\
06113 set p [uniform 0 1]\n\
06114 set total 0\n\
06115 for { set i 0 } { $i < $nstates_ } {incr i } {\n\
06116 set total [expr $total + [lindex $trans $i]]\n\
06117 if { $p <= $total } {\n\
06118 return [lindex $states_ $i]\n\
06119 }\n\
06120 }\n\
06121 puts \"Misconfigured state transition: prob $p total $total $nstates_\"\n\
06122 return $curstate_\n\
06123 }\n\
06124 \n\
06125 \n\
06126 Class ErrorModel/TwoStateMarkov -superclass ErrorModel/Expo\n\
06127 \n\
06128 ErrorModel/TwoStateMarkov instproc init {rate {unit \"time\"}} {\n\
06129 \n\
06130 $self next $rate $unit\n\
06131 }\n\
06132 \n\
06133 ErrorModel/ComplexTwoStateMarkov instproc init {avgList {unit \"time\"} {rng \"\"}} {\n\
06134 $self next\n\
06135 $self unit $unit\n\
06136 \n\
06137 set rv0 [new RandomVariable/Exponential]\n\
06138 set rv1 [new RandomVariable/Exponential]\n\
06139 set rv2 [new RandomVariable/Exponential]\n\
06140 set rv3 [new RandomVariable/Exponential]\n\
06141 \n\
06142 if {$rng != \"\"} {\n\
06143 $rv0 use-rng $rng\n\
06144 $rv1 use-rng $rng\n\
06145 $rv2 use-rng $rng\n\
06146 $rv3 use-rng $rng\n\
06147 }\n\
06148 $rv0 set avg_ [lindex $avgList 0]\n\
06149 $rv1 set avg_ [lindex $avgList 1]\n\
06150 $rv2 set avg_ [lindex $avgList 2]\n\
06151 $rv3 set avg_ [lindex $avgList 3]\n\
06152 $self ranvar 0 0 $rv0 \n\
06153 $self ranvar 0 1 $rv1 \n\
06154 $self ranvar 1 0 $rv2 \n\
06155 $self ranvar 1 1 $rv3\n\
06156 }\n\
06157 \n\
06158 \n\
06159 ErrorModule instproc init { cltype { clslots 29 } } {\n\
06160 \n\
06161 $self next\n\
06162 set nullagent [[Simulator instance] set nullAgent_]\n\
06163 \n\
06164 set classifier [new Classifier/Hash/$cltype $clslots]\n\
06165 $self cmd classifier $classifier\n\
06166 $self cmd target [new Connector]\n\
06167 $self cmd drop-target [new Connector]\n\
06168 $classifier proc unknown-flow { src dst fid } {\n\
06169 puts \"warning: classifier $self unknown flow s:$src, d:$dst, fid:$fid\"\n\
06170 }\n\
06171 }\n\
06172 \n\
06173 ErrorModule instproc default errmodel {\n\
06174 set cl [$self cmd classifier]\n\
06175 if { $errmodel == \"pass\" } {\n\
06176 set target [$self cmd target]\n\
06177 set pslot [$cl installNext $target]\n\
06178 $cl set default_ $pslot\n\
06179 return\n\
06180 }\n\
06181 \n\
06182 set emslot [$cl findslot $errmodel]\n\
06183 if { $emslot == -1 } {\n\
06184 puts \"ErrorModule: couldn't find classifier entry for error model $errmodel\"\n\
06185 return\n\
06186 }\n\
06187 $cl set default_ $emslot\n\
06188 }\n\
06189 \n\
06190 ErrorModule instproc insert errmodel {\n\
06191 $self instvar models_\n\
06192 $errmodel target [$self cmd target]\n\
06193 $errmodel drop-target [$self cmd drop-target]\n\
06194 if { [info exists models_] } {\n\
06195 set models_ [concat $models_ $errmodel]\n\
06196 } else {\n\
06197 set models_ $errmodel\n\
06198 }\n\
06199 }\n\
06200 \n\
06201 ErrorModule instproc errormodels {} {\n\
06202 $self instvar models_\n\
06203 return $models_\n\
06204 }\n\
06205 \n\
06206 ErrorModule instproc bind args {\n\
06207 \n\
06208 set nargs [llength $args]\n\
06209 set errmod [lindex $args 0]\n\
06210 set a [lindex $args 1]\n\
06211 if { $nargs == 3 } {\n\
06212 set b [lindex $args 2]\n\
06213 } else {\n\
06214 set b $a\n\
06215 }       \n\
06216 set cls [$self cmd classifier]\n\
06217 while { $a <= $b } {\n\
06218 set slot [$cls installNext $errmod] \n\
06219 $cls set-hash auto 0 0 $a $slot\n\
06220 incr a  \n\
06221 }\n\
06222 }\n\
06223 \n\
06224 ErrorModule instproc target args {\n\
06225 if { $args == \"\" } {\n\
06226 return [[$self cmd target] target]\n\
06227 }\n\
06228 set obj [lindex $args 0]\n\
06229 \n\
06230 [$self cmd target] target $obj\n\
06231 [$self cmd target] drop-target $obj\n\
06232 }\n\
06233 \n\
06234 ErrorModule instproc drop-target args {\n\
06235 if { $args == \"\" } {\n\
06236 return [[$self cmd drop-target] target]\n\
06237 }\n\
06238 \n\
06239 set obj [lindex $args 0]\n\
06240 \n\
06241 [$self cmd drop-target] drop-target $obj\n\
06242 [$self cmd drop-target] target $obj\n\
06243 }\n\
06244 \n\
06245 Queue/SimpleIntServ set qlimit1_ 50\n\
06246 Queue/SimpleIntServ set qlimit0_ 50\n\
06247 \n\
06248 Agent/SA set rate_ 0\n\
06249 Agent/SA set bucket_ 0\n\
06250 Agent/SA set packetSize_ 210\n\
06251 \n\
06252 ADC set backoff_ true\n\
06253 ADC set dobump_ true\n\
06254 ADC/MS set backoff_ false\n\
06255 \n\
06256 ADC set src_ -1\n\
06257 ADC set dst_ -1\n\
06258 ADC/MS set utilization_ 0.95\n\
06259 ADC/MSPK set utilization_ 0.95\n\
06260 ADC/Param set utilization_ 1.0\n\
06261 ADC/HB set epsilon_ 0.7\n\
06262 ADC/ACTO set s_ 0.002\n\
06263 ADC/ACTO set dobump_ false\n\
06264 ADC/ACTP set s_ 0.002\n\
06265 ADC/ACTP set dobump_ false\n\
06266 \n\
06267 \n\
06268 Est/TimeWindow set T_ 3\n\
06269 Est/ExpAvg set w_ 0.125\n\
06270 Est set period_ 0.5\n\
06271 \n\
06272 ADC set bandwidth_ 0\n\
06273 \n\
06274 SALink set src_ -1\n\
06275 SALink set dst_ -1\n\
06276 \n\
06277 Est set src_ -1\n\
06278 Est set dst_ -1\n\
06279 \n\
06280 \n\
06281 Class IntServLink -superclass  SimpleLink\n\
06282 IntServLink instproc init { src dst bw delay q arg {lltype \"DelayLink\"} } {\n\
06283 \n\
06284 $self next $src $dst $bw $delay $q $lltype ; # SimpleLink ctor\n\
06285 $self instvar queue_ link_\n\
06286 \n\
06287 $self instvar measclassifier_ signalmod_ adc_ est_ measmod_\n\
06288 \n\
06289 set ns_ [Simulator instance]\n\
06290 \n\
06291 set adctype [lindex $arg 3]\n\
06292 set adc_ [new ADC/$adctype]\n\
06293 $adc_ set bandwidth_ $bw\n\
06294 $adc_ set src_ [$src id]\n\
06295 $adc_ set dst_ [$dst id]\n\
06296 \n\
06297 if { [lindex $arg 5] == \"CL\" } {\n\
06298 set esttype [lindex $arg 4]\n\
06299 set est_ [new Est/$esttype]\n\
06300 $est_ set src_ [$src id]\n\
06301 $est_ set dst_ [$dst id]\n\
06302 $adc_ attach-est $est_ 1\n\
06303 \n\
06304 set measmod_ [new MeasureMod]\n\
06305 $measmod_ target $queue_\n\
06306 $adc_ attach-measmod $measmod_ 1\n\
06307 }\n\
06308 \n\
06309 set signaltype [lindex $arg 2]\n\
06310 set signalmod_ [new $signaltype]\n\
06311 $signalmod_ set src_ [$src id]\n\
06312 $signalmod_ set dst_ [$dst id]\n\
06313 $signalmod_ attach-adc $adc_\n\
06314 $self add-to-head $signalmod_\n\
06315 \n\
06316 \n\
06317 $self create-meas-classifier\n\
06318 $signalmod_ target $measclassifier_\n\
06319 \n\
06320 $ns_ at 0.0 \"$adc_ start\"\n\
06321 }\n\
06322 IntServLink instproc buffersize { b } {\n\
06323 $self instvar est_ adc_\n\
06324 $est_ setbuf [set b]\n\
06325 $adc_ setbuf [set b]\n\
06326 }\n\
06327 \n\
06328 \n\
06329 \n\
06330 IntServLink instproc create-meas-classifier {} {\n\
06331 $self instvar measclassifier_ measmod_ link_ queue_\n\
06332 \n\
06333 set measclassifier_ [new Classifier/Hash/Fid 1 ]\n\
06334 set slot [$measclassifier_ installNext $queue_]\n\
06335 $measclassifier_ set-hash auto 0 0 0 $slot \n\
06336 \n\
06337 set slot [$measclassifier_ installNext $measmod_]\n\
06338 $measclassifier_ set default_ 1\n\
06339 }\n\
06340 \n\
06341 IntServLink instproc trace-sig { f } {\n\
06342 $self instvar signalmod_ est_ adc_\n\
06343 $signalmod_ attach $f\n\
06344 $est_ attach $f\n\
06345 $adc_ attach $f\n\
06346 set ns [Simulator instance]\n\
06347 $ns at 0.0 \"$signalmod_ add-trace\"\n\
06348 }\n\
06349 \n\
06350 IntServLink instproc trace-util { interval {f \"\"}} {\n\
06351 $self instvar est_\n\
06352 set ns [Simulator instance]\n\
06353 if { $f != \"\" } {\n\
06354 puts $f \"[$ns now] [$est_ load-est] [$est_ link-utlzn]\" \n\
06355 }\n\
06356 $ns at [expr [$ns now]+$interval] \"$self trace-util $interval $f\" \n\
06357 }\n\
06358 \n\
06359 CMUTrace instproc init { tname type } {\n\
06360 $self next $tname $type\n\
06361 $self instvar type_ src_ dst_ callback_ show_tcphdr_\n\
06362 \n\
06363 set type_ $type\n\
06364 set src_ 0\n\
06365 set dst_ 0\n\
06366 set callback_ 0\n\
06367 set show_tcphdr_ 0\n\
06368 }\n\
06369 \n\
06370 CMUTrace instproc attach fp {\n\
06371 $self instvar fp_\n\
06372 set fp_ $fp\n\
06373 $self cmd attach $fp_\n\
06374 }\n\
06375 \n\
06376 Class CMUTrace/Send -superclass CMUTrace\n\
06377 CMUTrace/Send instproc init { tname } {\n\
06378 $self next $tname \"s\"\n\
06379 }\n\
06380 \n\
06381 Class CMUTrace/Recv -superclass CMUTrace\n\
06382 CMUTrace/Recv instproc init { tname } {\n\
06383 $self next $tname \"r\"\n\
06384 }\n\
06385 \n\
06386 Class CMUTrace/Drop -superclass CMUTrace\n\
06387 CMUTrace/Drop instproc init { tname } {\n\
06388 $self next $tname \"D\"\n\
06389 }\n\
06390 \n\
06391 Class CMUTrace/EOT -superclass CMUTrace\n\
06392 CMUTrace/EOT instproc init { tname } {\n\
06393 $self next $tname \"x\"\n\
06394 }\n\
06395 \n\
06396 \n\
06397 CMUTrace/Recv set src_ 0\n\
06398 CMUTrace/Recv set dst_ 0\n\
06399 CMUTrace/Recv set callback_ 0\n\
06400 CMUTrace/Recv set show_tcphdr_ 0\n\
06401 \n\
06402 CMUTrace/Send set src_ 0\n\
06403 CMUTrace/Send set dst_ 0\n\
06404 CMUTrace/Send set callback_ 0\n\
06405 CMUTrace/Send set show_tcphdr_ 0\n\
06406 \n\
06407 CMUTrace/Drop set src_ 0\n\
06408 CMUTrace/Drop set dst_ 0\n\
06409 CMUTrace/Drop set callback_ 0\n\
06410 CMUTrace/Drop set show_tcphdr_ 0\n\
06411 \n\
06412 CMUTrace/EOT set src_ 0\n\
06413 CMUTrace/EOT set dst_ 0\n\
06414 CMUTrace/EOT set callback_ 0\n\
06415 CMUTrace/EOT set show_tcphdr_ 0\n\
06416 \n\
06417 \n\
06418 \n\
06419 \n\
06420 Node/Broadcast instproc init {} {\n\
06421 $self next\n\
06422 $self instvar address_ classifier_ id_ dmux_\n\
06423 \n\
06424 [Simulator instance] add-broadcast-node $self $id_\n\
06425 \n\
06426 set classifier_ [new Classifier/Hash/Dest/Bcast 32]\n\
06427 $classifier_ set mask_ [AddrParams NodeMask 1]\n\
06428 $classifier_ set shift_ [AddrParams NodeShift 1]\n\
06429 set address_ $id_\n\
06430 if { $dmux_ == \"\" } {\n\
06431 set dmux_ [new Classifier/Port/Reserve]\n\
06432 $dmux_ set mask_ [AddrParams set ALL_BITS_SET]\n\
06433 $dmux_ set shift_ 0\n\
06434 $self add-route $address_ $dmux_\n\
06435 \n\
06436 }\n\
06437 $classifier_ bcast-receiver $dmux_\n\
06438 \n\
06439 $self attach-classifier $classifier_\n\
06440 }\n\
06441 \n\
06442 Node/Broadcast instproc mk-default-classifier {} { }\n\
06443 \n\
06444 \n\
06445 \n\
06446 \n\
06447 Node/Broadcast instproc add-route { dst target } {\n\
06448 [$self set classifier_] install $dst $target\n\
06449 }\n\
06450 \n\
06451 Node/Broadcast instproc delete-route { dst nullagent } {\n\
06452 [$self set classifier_] install $dst $nullagent\n\
06453 }\n\
06454 \n\
06455 Node/Broadcast instproc add-target { agent port } {\n\
06456 $agent target [$self entry]\n\
06457 [$self demux] install $port $agent\n\
06458 }\n\
06459 \n\
06460 MIPEncapsulator instproc tunnel-exit mhaddr {\n\
06461 $self instvar node_\n\
06462 return [[$node_ set regagent_] set TunnelExit_($mhaddr)]\n\
06463 }\n\
06464 \n\
06465 Class Node/MIPBS -superclass Node/Broadcast\n\
06466 \n\
06467 Node/MIPBS instproc init { args } {\n\
06468 eval $self next $args\n\
06469 $self instvar regagent_ encap_ decap_ agents_ address_ dmux_ id_\n\
06470 \n\
06471 if { $dmux_ == \"\" } {\n\
06472 error \"serious internal error at Node/MIPBS\\n\"\n\
06473 }\n\
06474 set regagent_ [new Agent/MIPBS $self]\n\
06475 $self attach $regagent_ 0\n\
06476 $regagent_ set mask_ [AddrParams NodeMask 1]\n\
06477 $regagent_ set shift_ [AddrParams NodeShift 1]\n\
06478 $regagent_ set dst_addr_ [expr (~0) << [AddrParams NodeShift 1]]\n\
06479 $regagent_ set dst_port_ 0\n\
06480 \n\
06481 set encap_ [new MIPEncapsulator]\n\
06482 set decap_ [new Classifier/Addr/MIPDecapsulator]\n\
06483 \n\
06484 lappend agents_ $decap_\n\
06485 \n\
06486 set nodeaddr [AddrParams addr2id $address_]\n\
06487 $encap_ set addr_ $nodeaddr\n\
06488 $encap_ set port_ 1\n\
06489 $encap_ target [$self entry]\n\
06490 $encap_ set node_ $self\n\
06491 \n\
06492 $dmux_ install 1 $decap_\n\
06493 \n\
06494 $encap_ set mask_ [AddrParams NodeMask 1]\n\
06495 $encap_ set shift_ [AddrParams NodeShift 1]\n\
06496 $decap_ set mask_ [AddrParams NodeMask 1]\n\
06497 $decap_ set shift_ [AddrParams NodeShift 1]\n\
06498 }\n\
06499 \n\
06500 Class Node/MIPMH -superclass Node/Broadcast\n\
06501 \n\
06502 Node/MIPMH instproc init { args } {\n\
06503 eval $self next $args\n\
06504 $self instvar regagent_\n\
06505 set regagent_ [new Agent/MIPMH $self]\n\
06506 $self attach $regagent_ 0\n\
06507 $regagent_ set mask_ [AddrParams NodeMask 1]\n\
06508 $regagent_ set shift_ [AddrParams NodeShift 1]\n\
06509 $regagent_ set dst_addr_ [expr (~0) << [AddrParams NodeShift 1]]\n\
06510 $regagent_ set dst_port_ 0\n\
06511 }\n\
06512 \n\
06513 \n\
06514 Agent/MIPBS instproc init { node args } {\n\
06515 eval $self next $args\n\
06516 \n\
06517 if {[$node info class] != \"MobileNode/MIPBS\" && \\\n\
06518 [$node info class] != \"Node/MobileNode\"} {\n\
06519 $self instvar BcastTarget_\n\
06520 set BcastTarget_ [new Classifier/Replicator]\n\
06521 $self bcast-target $BcastTarget_\n\
06522 }\n\
06523 $self beacon-period 1.0 ;# default value\n\
06524 }\n\
06525 \n\
06526 Agent/MIPBS instproc clear-reg mhaddr {\n\
06527 $self instvar node_ OldRoute_ RegTimer_\n\
06528 if [info exists OldRoute_($mhaddr)] {\n\
06529 $node_ add-route $mhaddr $OldRoute_($mhaddr)\n\
06530 }\n\
06531 if {[$node_ info class] == \"MobileNode/MIPBS\" || [$node_ info class] ==\"Node/MobileNode\" } {\n\
06532 eval $node_ delete-route [AddrParams id2addr $mhaddr]\n\
06533 }\n\
06534 if { [info exists RegTimer_($mhaddr)] && $RegTimer_($mhaddr) != \"\" } {\n\
06535 [Simulator instance] cancel $RegTimer_($mhaddr)\n\
06536 set RegTimer_($mhaddr) \"\"\n\
06537 }\n\
06538 }\n\
06539 \n\
06540 Agent/MIPBS instproc encap-route { mhaddr coa lifetime } {\n\
06541 $self instvar node_ TunnelExit_ OldRoute_ RegTimer_\n\
06542 set ns [Simulator instance]\n\
06543 set encap [$node_ set encap_]\n\
06544 \n\
06545 if {[$node_ info class] == \"MobileNode/MIPBS\" || [$node_ info class] == \"Node/MobileNode\"} {\n\
06546 set addr [AddrParams id2addr $mhaddr]\n\
06547 set a [split $addr]\n\
06548 set b [join $a .]\n\
06549 $node_ add-route $b $encap\n\
06550 } else {\n\
06551 set or [[$node_ entry] slot $mhaddr]\n\
06552 if { $or != $encap } {\n\
06553 set OldRoute_($mhaddr) $or\n\
06554 $node_ add-route $mhaddr $encap\n\
06555 }\n\
06556 }\n\
06557 set TunnelExit_($mhaddr) $coa\n\
06558 if { [info exists RegTimer_($mhaddr)] && $RegTimer_($mhaddr) != \"\" } {\n\
06559 $ns cancel $RegTimer_($mhaddr)\n\
06560 }\n\
06561 set RegTimer_($mhaddr) [$ns at [expr [$ns now] + $lifetime] \\\n\
06562 \"$self clear-reg $mhaddr\"]\n\
06563 }\n\
06564 \n\
06565 Agent/MIPBS instproc decap-route { mhaddr target lifetime } {\n\
06566 $self instvar node_ RegTimer_\n\
06567 \n\
06568 if {[$node_ info class] != \"MobileNode/MIPBS\" && \\\n\
06569 [$node_ info class] != \"Node/MobileNode\" } {\n\
06570 set ns [Simulator instance]\n\
06571 [$node_ set decap_] install $mhaddr $target\n\
06572 \n\
06573 if { [info exists RegTimer_($mhaddr)] && \\\n\
06574 $RegTimer_($mhaddr) != \"\" } {\n\
06575 $ns cancel $RegTimer_($mhaddr)\n\
06576 }\n\
06577 set RegTimer_($mhaddr) [$ns at [expr [$ns now] + $lifetime] \\\n\
06578 \"$self clear-decap $mhaddr\"]\n\
06579 } else {\n\
06580 [$node_ set decap_] defaulttarget [$node_ set ragent_]\n\
06581 }\n\
06582 }\n\
06583 \n\
06584 Agent/MIPBS instproc clear-decap mhaddr {\n\
06585 $self instvar node_ RegTimer_\n\
06586 if { [info exists RegTimer_($mhaddr)] && $RegTimer_($mhaddr) != \"\" } {\n\
06587 [Simulator instance] cancel $RegTimer_($mhaddr)\n\
06588 set RegTimer_($mhaddr) \"\"\n\
06589 }\n\
06590 [$node_ set decap_] clear $mhaddr\n\
06591 }\n\
06592 \n\
06593 Agent/MIPBS instproc get-link { src dst } {\n\
06594 $self instvar node_\n\
06595 if {[$node_ info class] != \"MobileNode/MIPBS\" && \\\n\
06596 [$node_ info class] != \"Node/MobileNode\"} {\n\
06597 set ns [Simulator instance]\n\
06598 return [[$ns link [$ns get-node-by-addr $src] \\\n\
06599 [$ns get-node-by-addr $dst]] head]\n\
06600 } else { \n\
06601 return \"\"\n\
06602 }\n\
06603 }\n\
06604 \n\
06605 Agent/MIPBS instproc add-ads-bcast-link { ll } {\n\
06606 $self instvar BcastTarget_\n\
06607 $BcastTarget_ installNext [$ll head]\n\
06608 }\n\
06609 \n\
06610 Agent/MIPMH instproc init { node args } {\n\
06611 eval $self next $args\n\
06612 if {[$node info class] != \"MobileNode/MIPMH\" && \\\n\
06613 [$node info class] != \"SRNode/MIPMH\" && \\\n\
06614 [$node info class] != \"Node/MobileNode\" } {\n\
06615 $self instvar BcastTarget_\n\
06616 set BcastTarget_ [new Classifier/Replicator]\n\
06617 $self bcast-target $BcastTarget_\n\
06618 }\n\
06619 $self beacon-period 1.0 ;# default value\n\
06620 }\n\
06621 \n\
06622 Agent/MIPMH instproc update-reg coa {\n\
06623 $self instvar node_\n\
06624 if {[$node_ info class] != \"MobileNode/MIPMH\" && \\\n\
06625 [$node_ info class] != \"SRNode/MIPMH\" && \\\n\
06626 [$node_ info class] != \"Node/MobileNode\" } {\n\
06627 set n [Node set nn_]\n\
06628 set ns [Simulator instance]\n\
06629 set id [$node_ id]\n\
06630 set l [[$ns link $node_ [$ns get-node-by-addr $coa]] head]\n\
06631 for { set i 0 } { $i < $n } { incr i } {\n\
06632 if { $i != $id } {\n\
06633 $node_ add-route $i $l\n\
06634 }\n\
06635 }\n\
06636 }\n\
06637 }\n\
06638 \n\
06639 Agent/MIPMH instproc get-link { src dst } {\n\
06640 $self instvar node_\n\
06641 if {[$node_ info class] != \"MobileNode/MIPMH\" && \\\n\
06642 [$node_ info class] != \"SRNode/MIPMH\" && \\\n\
06643 [$node_ info class] != \"Node/MobileNode\" } {\n\
06644 set ns [Simulator instance]\n\
06645 return [[$ns link [$ns get-node-by-addr $src] \\\n\
06646 [$ns get-node-by-addr $dst]] head]\n\
06647 } else {\n\
06648 return \"\"\n\
06649 }\n\
06650 }\n\
06651 \n\
06652 Agent/MIPMH instproc add-sol-bcast-link { ll } {\n\
06653 $self instvar BcastTarget_\n\
06654 $BcastTarget_ installNext [$ll head]\n\
06655 }\n\
06656 \n\
06657 \n\
06658 \n\
06659 \n\
06660 \n\
06661 \n\
06662 \n\
06663 \n\
06664 \n\
06665 \n\
06666 \n\
06667 Node/SatNode instproc init args {\n\
06668 eval $self next $args       ;# parent class constructor\n\
06669 \n\
06670 $self instvar nifs_ \n\
06671 $self instvar phy_tx_ phy_rx_ mac_ ifq_ ll_ pos_ hm_ id_\n\
06672 \n\
06673 set nifs_   0       ;# number of network interfaces\n\
06674 set ns_ [Simulator instance]\n\
06675 set trace_ [$ns_ get-ns-traceall]\n\
06676 if {$trace_ != \"\"} {\n\
06677 set dropT_ [$ns_ create-trace Sat/Drop $trace_ $self $self \"\"]\n\
06678 $self set_trace $dropT_\n\
06679 }\n\
06680 $self cmd set_address $id_ ; # Used to indicate satellite node in array\n\
06681 }\n\
06682 \n\
06683 Node/SatNode instproc reset {} {\n\
06684 eval $self next \n\
06685 $self instvar hm_ instvar nifs_ phy_tx_ phy_rx_ mac_ ifq_ ll_\n\
06686 set ns [Simulator instance]\n\
06687 set now_ [$ns now]\n\
06688 for {set i 0} {$i < $nifs_} {incr i} {\n\
06689 $phy_tx_($i) reset\n\
06690 $phy_rx_($i) reset\n\
06691 if {[info exists mac_($i)]} {\n\
06692 $mac_($i) reset\n\
06693 }\n\
06694 if {[info exists ll_($i)]} {\n\
06695 $ll_($i) reset\n\
06696 }\n\
06697 if {[info exists ifq_($i)]} {\n\
06698 $ifq_($i) reset\n\
06699 }\n\
06700 }\n\
06701 if {$now_ == 0} {\n\
06702 if {[info exists hm_]} {\n\
06703 $ns at 0.0 \"$self start_handoff\"\n\
06704 }\n\
06705 }\n\
06706 }\n\
06707 \n\
06708 Node/SatNode instproc set_next {node_} {\n\
06709 $self instvar pos_\n\
06710 $pos_ set_next [$node_ set pos_]\n\
06711 }\n\
06712 \n\
06713 Node/SatNode instproc add-target {agent port } {\n\
06714 \n\
06715 $self instvar dmux_ \n\
06716 \n\
06717 if { $port == [Node set rtagent_port_] } {          \n\
06718 [$self set classifier_] defaulttarget $agent\n\
06719 $dmux_ install $port $agent\n\
06720 } else {\n\
06721 $agent target [$self entry]\n\
06722 \n\
06723 $dmux_ install $port $agent\n\
06724 }\n\
06725 }\n\
06726 \n\
06727 \n\
06728 Simulator instproc create-satnode {} {\n\
06729 $self instvar satNodeType_ llType_ ifqType_ ifqlen_ macType_ \\\n\
06730 downlinkBW_ phyType_ channelType_\n\
06731 if {![info exists satNodeType_]} {\n\
06732 puts \"Error: create-satnode called, but no satNodeType_; exiting\"\n\
06733 exit 1\n\
06734 }\n\
06735 if {$satNodeType_ == \"Polar\"} {set satNodeType_ \"polar\"}\n\
06736 if {$satNodeType_ == \"Geo\"} {set satNodeType_ \"geo\"}\n\
06737 if {$satNodeType_ == \"Terminal\"} {set satNodeType_ \"terminal\"}\n\
06738 if {$satNodeType_ == \"Geo-repeater\"} {set satNodeType_ \"geo-repeater\"}\n\
06739 if {[lsearch {polar geo terminal geo-repeater} $satNodeType_] < 0} {\n\
06740 puts \"Error: undefined satNodeType: $satNodeType_; exiting\"\n\
06741 exit 1\n\
06742 }\n\
06743 set tmp [$self newsatnode]\n\
06744 if {$satNodeType_ == \"polar\" || $satNodeType_ == \"geo\"} {\n\
06745 set linkargs \"$llType_ $ifqType_ $ifqlen_ $macType_ \\\n\
06746 $downlinkBW_ $phyType_\"\n\
06747 $self add-first-links $tmp gsl $linkargs $channelType_\n\
06748 } elseif {$satNodeType_ == \"geo-repeater\"} {\n\
06749 $self add-first-links $tmp gsl-repeater \"\" $channelType_\n\
06750 }\n\
06751 return $tmp\n\
06752 }\n\
06753 \n\
06754 Simulator instproc newsatnode {} {\n\
06755 $self instvar Node_ satNodeType_\n\
06756 if ![info exists satNodeType_] {\n\
06757 puts \"Error: satNodeType_ does not exist in newsatnode; exiting\"\n\
06758 exit 1\n\
06759 }\n\
06760 set node [new Node/SatNode]\n\
06761 if {$satNodeType_ == \"polar\" || $satNodeType_ == \"geo\" || \\\n\
06762 $satNodeType_ == \"terminal\"} {\n\
06763 $node create-ragent\n\
06764 }\n\
06765 set Node_([$node id]) $node\n\
06766 $node set ns_ $self\n\
06767 if [$self multicast?] {\n\
06768 $node enable-mcast $self\n\
06769 }\n\
06770 $self check-node-num\n\
06771 return $node\n\
06772 }\n\
06773 \n\
06774 Node/SatNode instproc set-position args {\n\
06775 set ns_ [Simulator instance]\n\
06776 set nodetype_ [$ns_ set satNodeType_]\n\
06777 if {$nodetype_ == \"polar\"} {\n\
06778 if {[llength $args] != 5 } {\n\
06779 puts \"Error:  satNodeType_ is polar, but number\\\n\
06780 of position arguments incorrect: $args; exiting\"\n\
06781 exit 1\n\
06782 }\n\
06783 $self set pos_ [new Position/Sat/Polar $args]\n\
06784 $self cmd set_position [$self set pos_]\n\
06785 [$self set pos_] setnode $self\n\
06786 $self set hm_ [new HandoffManager/Sat]\n\
06787 $self cmd set_handoff_mgr [$self set hm_]\n\
06788 [$self set hm_] setnode $self\n\
06789 } elseif {$nodetype_ == \"geo\" || $nodetype_ == \"geo-repeater\"} {\n\
06790 if {[llength $args] != 1 } {\n\
06791 puts \"Error:  satNodeType_ is geo, but number\\\n\
06792 of position arguments incorrect: $args; exiting\"\n\
06793 exit 1\n\
06794 }\n\
06795 $self set pos_ [new Position/Sat/Geo $args]\n\
06796 $self cmd set_position [$self set pos_]\n\
06797 [$self set pos_] setnode $self\n\
06798 } elseif {$nodetype_ == \"terminal\"} {\n\
06799 if {[llength $args] != 2 } {\n\
06800 puts \"Error:  satNodeType_ is terminal, but number\\\n\
06801 of position arguments incorrect: $args; exiting\"\n\
06802 exit 1\n\
06803 }\n\
06804 $self set pos_ [new Position/Sat/Term $args]\n\
06805 $self cmd set_position [$self set pos_]\n\
06806 [$self set pos_] setnode $self\n\
06807 $self set hm_ [new HandoffManager/Term]\n\
06808 $self cmd set_handoff_mgr [$self set hm_]\n\
06809 [$self set hm_] setnode $self\n\
06810 } else {\n\
06811 puts \"Error:  satNodeType_ not set appropriately:\\\n\
06812 $satNodeType_ exiting\"\n\
06813 exit 1\n\
06814 }\n\
06815 }\n\
06816 \n\
06817 \n\
06818 Simulator instproc satnode-polar {alt inc lon alpha plane linkargs chan} {\n\
06819 set tmp [$self satnode polar $alt $inc $lon $alpha $plane]\n\
06820 $self add-first-links $tmp gsl $linkargs $chan\n\
06821 return $tmp\n\
06822 }\n\
06823 \n\
06824 Simulator instproc satnode-geo {lon linkargs chan} {\n\
06825 set tmp [$self satnode geo $lon]\n\
06826 $self add-first-links $tmp gsl $linkargs $chan\n\
06827 return $tmp\n\
06828 }\n\
06829 \n\
06830 Simulator instproc satnode-geo-repeater {lon chan} {\n\
06831 set tmp [$self satnode geo $lon]\n\
06832 $self add-first-links $tmp gsl-repeater \"\" $chan\n\
06833 return $tmp\n\
06834 }\n\
06835 \n\
06836 Simulator instproc satnode-terminal {lat lon} {\n\
06837 $self satnode terminal $lat $lon\n\
06838 }\n\
06839 \n\
06840 Simulator instproc satnode args {\n\
06841 $self instvar Node_\n\
06842 set node [new Node/SatNode]\n\
06843 if {[lindex $args 0] == \"polar\" || [lindex $args 0] == \"Polar\"} {\n\
06844 set args [lreplace $args 0 0]\n\
06845 $node set pos_ [new Position/Sat/Polar $args]\n\
06846 $node cmd set_position [$node set pos_]\n\
06847 [$node set pos_] setnode $node\n\
06848 $node set hm_ [new HandoffManager/Sat]\n\
06849 $node cmd set_handoff_mgr [$node set hm_]\n\
06850 [$node set hm_] setnode $node\n\
06851 $node create-ragent \n\
06852 } elseif {[lindex $args 0] == \"geo\" || [lindex $args 0] == \"Geo\"} {  \n\
06853 set args [lreplace $args 0 0]\n\
06854 $node set pos_ [new Position/Sat/Geo $args]\n\
06855 $node cmd set_position [$node set pos_]\n\
06856 [$node set pos_] setnode $node\n\
06857 $node create-ragent\n\
06858 } elseif {[lindex $args 0] == \"geo-repeater\" || [lindex $args 0] == \"Geo-repeater\"} {  \n\
06859 set args [lreplace $args 0 0]\n\
06860 $node set pos_ [new Position/Sat/Geo $args]\n\
06861 $node cmd set_position [$node set pos_]\n\
06862 [$node set pos_] setnode $node\n\
06863 } elseif {[lindex $args 0] == \"terminal\" || [lindex $args 0] == \"Terminal\"} {  \n\
06864 set args [lreplace $args 0 0]\n\
06865 $node set pos_ [new Position/Sat/Term $args]\n\
06866 $node cmd set_position [$node set pos_]\n\
06867 [$node set pos_] setnode $node\n\
06868 $node set hm_ [new HandoffManager/Term]\n\
06869 $node cmd set_handoff_mgr [$node set hm_]\n\
06870 [$node set hm_] setnode $node\n\
06871 $node create-ragent\n\
06872 } else {\n\
06873 puts \"Otcl error; satnode specified incorrectly: $args\"\n\
06874 }\n\
06875 set Node_([$node id]) $node\n\
06876 $node set ns_ $self\n\
06877 if [$self multicast?] {\n\
06878 $node enable-mcast $self\n\
06879 }\n\
06880 $self check-node-num\n\
06881 return $node\n\
06882 }\n\
06883 \n\
06884 \n\
06885 \n\
06886 Simulator instproc add-first-links {node_ linktype linkargs chan} {\n\
06887 $node_ set_downlink $chan\n\
06888 $node_ set_uplink $chan\n\
06889 if {$linktype == \"gsl-repeater\"} {\n\
06890 $node_ add-repeater $chan\n\
06891 } else {\n\
06892 eval $node_ add-interface $linktype $linkargs\n\
06893 }\n\
06894 $node_ attach-to-outlink [$node_ set downlink_]\n\
06895 $node_ attach-to-inlink [$node_ set uplink_]\n\
06896 }\n\
06897 \n\
06898 Node/SatNode instproc add-gsl {ltype opt_ll opt_ifq opt_qlim opt_mac \\\n\
06899 opt_bw opt_phy opt_inlink opt_outlink} {\n\
06900 $self add-interface $ltype $opt_ll $opt_ifq $opt_qlim $opt_mac $opt_bw \\\n\
06901 $opt_phy \n\
06902 $self attach-to-inlink $opt_inlink\n\
06903 $self attach-to-outlink $opt_outlink\n\
06904 }\n\
06905 \n\
06906 Simulator instproc add-isl {ltype node1 node2 bw qtype qlim} {\n\
06907 set opt_ll LL/Sat\n\
06908 set opt_mac Mac/Sat\n\
06909 set opt_phy Phy/Sat\n\
06910 set opt_chan Channel/Sat\n\
06911 set chan1 [new $opt_chan]\n\
06912 set chan2 [new $opt_chan]\n\
06913 $node1 add-interface $ltype $opt_ll $qtype $qlim $opt_mac $bw $opt_phy $chan1 $chan2\n\
06914 $node2 add-interface $ltype $opt_ll $qtype $qlim $opt_mac $bw $opt_phy $chan2 $chan1\n\
06915 if {$ltype == \"crossseam\"} {\n\
06916 $node1 add-interface $ltype $opt_ll $qtype $qlim $opt_mac $bw $opt_phy \n\
06917 $node2 add-interface $ltype $opt_ll $qtype $qlim $opt_mac $bw $opt_phy \n\
06918 \n\
06919 }\n\
06920 }\n\
06921 \n\
06922 Node/SatNode instproc add-repeater chan { \n\
06923 $self instvar nifs_ phy_tx_ phy_rx_ linkhead_ \n\
06924 \n\
06925 set t $nifs_\n\
06926 incr nifs_\n\
06927 \n\
06928 set linkhead_($t) [new Connector/LinkHead/Sat]\n\
06929 set phy_tx_($t) [new Phy/Repeater]      ;# interface\n\
06930 set phy_rx_($t) [new Phy/Repeater]\n\
06931 \n\
06932 $linkhead_($t) setnode $self\n\
06933 $linkhead_($t) setphytx $phy_tx_($t)\n\
06934 $linkhead_($t) setphyrx $phy_rx_($t)\n\
06935 $linkhead_($t) set_type \"gsl-repeater\"\n\
06936 $linkhead_($t) set type_ \"gsl-repeater\"\n\
06937 \n\
06938 $phy_rx_($t) up-target $phy_tx_($t)\n\
06939 $phy_tx_($t) linkhead $linkhead_($t)\n\
06940 $phy_rx_($t) linkhead $linkhead_($t)\n\
06941 $phy_tx_($t) node $self     ;# Bind node <---> interface\n\
06942 $phy_rx_($t) node $self     ;# Bind node <---> interface\n\
06943 }\n\
06944 \n\
06945 Node/SatNode instproc add-interface args { \n\
06946 \n\
06947 $self instvar nifs_ phy_tx_ phy_rx_ mac_ ifq_ ll_ drophead_ linkhead_\n\
06948 \n\
06949 global ns_ MacTrace opt\n\
06950 \n\
06951 set t $nifs_\n\
06952 incr nifs_\n\
06953 \n\
06954 set linkhead_($t) [new Connector/LinkHead/Sat]\n\
06955 \n\
06956 set linktype    [lindex $args 0]\n\
06957 set ll_($t) [new [lindex $args 1]]      ;# link layer\n\
06958 set ifq_($t)    [new [lindex $args 2]]      ;# interface queue\n\
06959 set qlen    [lindex $args 3]\n\
06960 set mac_($t)    [new [lindex $args 4]]      ;# mac layer\n\
06961 set mac_bw  [lindex $args 5]\n\
06962 set phy_tx_($t) [new [lindex $args 6]]      ;# interface\n\
06963 set phy_rx_($t) [new [lindex $args 6]]      ;# interface\n\
06964 set inchan  [lindex $args 7]\n\
06965 set outchan     [lindex $args 8]\n\
06966 set drophead_($t) [new Connector]   ;# drop target for queue\n\
06967 set iif_($t) [new NetworkInterface]\n\
06968 \n\
06969 \n\
06970 set linkhead $linkhead_($t)\n\
06971 set phy_tx $phy_tx_($t)\n\
06972 set phy_rx $phy_rx_($t)\n\
06973 set mac $mac_($t)\n\
06974 set ifq $ifq_($t)\n\
06975 set ll $ll_($t)\n\
06976 set drophead $drophead_($t)\n\
06977 set iif $iif_($t)\n\
06978 \n\
06979 $linkhead setnode $self\n\
06980 $linkhead setll $ll\n\
06981 $linkhead setmac $mac\n\
06982 $linkhead setqueue $ifq\n\
06983 $linkhead setphytx $phy_tx\n\
06984 $linkhead setphyrx $phy_rx\n\
06985 $linkhead setnetinf $iif\n\
06986 $self addlinkhead $linkhead; # Add NetworkInterface to node's list\n\
06987 $linkhead target $ll; \n\
06988 $linkhead set_type $linktype\n\
06989 $linkhead set type_ $linktype\n\
06990 \n\
06991 $iif target [$self entry]\n\
06992 \n\
06993 $ll mac $mac; # XXX is this needed?\n\
06994 $ll up-target $iif\n\
06995 $ll down-target $ifq\n\
06996 $ll set delay_ 0ms; # processing delay between ll and ifq\n\
06997 $ll setnode $self\n\
06998 \n\
06999 $ifq target $mac\n\
07000 $ifq set limit_ $qlen\n\
07001 $drophead target [[Simulator instance] set nullAgent_]\n\
07002 $ifq drop-target $drophead\n\
07003 \n\
07004 \n\
07005 $mac netif $phy_tx; # Not used by satellite code at this time\n\
07006 $mac up-target $ll\n\
07007 $mac down-target $phy_tx\n\
07008 $mac set bandwidth_ $mac_bw; \n\
07009 \n\
07010 $phy_rx up-target $mac\n\
07011 $phy_tx linkhead $linkhead\n\
07012 $phy_rx linkhead $linkhead\n\
07013 $phy_tx node $self      ;# Bind node <---> interface\n\
07014 $phy_rx node $self      ;# Bind node <---> interface\n\
07015 \n\
07016 if {$outchan != \"\" && $inchan != \"\"} {\n\
07017 $phy_tx channel $outchan\n\
07018 $phy_rx channel $inchan\n\
07019 $inchan addif $phy_rx\n\
07020 }\n\
07021 return $t\n\
07022 }\n\
07023 \n\
07024 Node/SatNode instproc set_uplink {chan} {\n\
07025 $self instvar uplink_\n\
07026 set uplink_ [new $chan]\n\
07027 $self cmd set_uplink $uplink_\n\
07028 }\n\
07029 \n\
07030 Node/SatNode instproc set_downlink {chan} {\n\
07031 $self instvar downlink_\n\
07032 set downlink_ [new $chan]\n\
07033 $self cmd set_downlink $downlink_\n\
07034 }\n\
07035 \n\
07036 Node/SatNode instproc attach-to-outlink {chan {index 0} } {\n\
07037 $self instvar phy_tx_ mac_\n\
07038 $phy_tx_($index) channel $chan\n\
07039 }\n\
07040 \n\
07041 Node/SatNode instproc attach-to-inlink { chan {index 0}} {\n\
07042 $self instvar phy_rx_ \n\
07043 $phy_rx_($index) channel $chan\n\
07044 $chan addif $phy_rx_($index)\n\
07045 }\n\
07046 \n\
07047 Node/SatNode instproc interface-errormodel { em { index 0 } } {\n\
07048 $self instvar mac_ ll_ em_ linkhead_\n\
07049 $mac_($index) up-target $em\n\
07050 $em target $ll_($index)\n\
07051 $em drop-target [new Agent/Null]; # otherwise, packet is only marked\n\
07052 set em_($index) $em\n\
07053 $linkhead_($index) seterrmodel $em\n\
07054 } \n\
07055 \n\
07056 \n\
07057 Mac/Sat instproc init args {\n\
07058 eval $self next $args           ;# parent class constructor\n\
07059 \n\
07060 set ns_ [Simulator instance]\n\
07061 set trace_ [$ns_ get-ns-traceall]\n\
07062 if {$trace_ != \"\"} {\n\
07063 set dropT_ [$ns_ create-trace Sat/Drop $trace_ $self $self \"\"]\n\
07064 $self set_drop_trace $dropT_\n\
07065 set collT_ [$ns_ create-trace Sat/Collision $trace_ $self $self \"\"]\n\
07066 $self set_coll_trace $collT_\n\
07067 }\n\
07068 }\n\
07069 \n\
07070 \n\
07071 Node/SatNode instproc create-ragent {} {\n\
07072 set ragent [new Agent/SatRoute]\n\
07073 $self attach $ragent 255; # attaches to default target of classifier  \n\
07074 $ragent set myaddr_ [$self set id_]\n\
07075 $self set_ragent $ragent; # sets pointer at C++ level\n\
07076 $ragent set_node $self; # sets back pointer in ragent to node\n\
07077 }\n\
07078 \n\
07079 Class Agent/rtProto/Dummy -superclass Agent/rtProto\n\
07080 \n\
07081 Agent/rtProto/Dummy proc init-all args {\n\
07082 }\n\
07083 \n\
07084 \n\
07085 \n\
07086 \n\
07087 Class Connector/RoutingHelper -superclass Connector\n\
07088 \n\
07089 Simulator instproc sat_link_up {src dst cost handle queue_handle} {\n\
07090 $self instvar link_\n\
07091 \n\
07092 global slink_\n\
07093 set slink_($src:$dst) $self; # what is this?\n\
07094 \n\
07095 if {![info exists link_($src:$dst)]} {\n\
07096 set link_($src:$dst) [new Connector/RoutingHelper]\n\
07097 }\n\
07098 if {[$link_($src:$dst) info class] == \"Connector/RoutingHelper\"} {\n\
07099 $link_($src:$dst) set cost_ $cost\n\
07100 $link_($src:$dst) set up_ \"up\"\n\
07101 $link_($src:$dst) set queue_ $queue_handle\n\
07102 $link_($src:$dst) target $handle\n\
07103 $link_($src:$dst) set head_ $handle\n\
07104 } else {\n\
07105 puts -nonewline \"link_(${src}:${dst}) have non-connector \"\n\
07106 puts \"[$link_($src:$dst) info class]\"\n\
07107 exit 1\n\
07108 }\n\
07109 }\n\
07110 \n\
07111 \n\
07112 Simulator instproc sat_link_destroy {src dst} {\n\
07113 $self instvar link_\n\
07114 \n\
07115 global slink_\n\
07116 if {[info exists slink_($src:$dst)]} {\n\
07117 unset slink_($src:$dst)\n\
07118 }\n\
07119 \n\
07120 if {[info exists link_($src:$dst)]} {\n\
07121 delete $link_($src:$dst)\n\
07122 unset link_($src:$dst)\n\
07123 } else {\n\
07124 puts -nonewline \"Warning: trying to delete a link_ \"\n\
07125 puts \"link_(${src}:${dst}) that doesn't exist at [$self now]\"\n\
07126 }\n\
07127 }\n\
07128 \n\
07129 Connector/RoutingHelper instproc up? {} {\n\
07130 $self instvar up_\n\
07131 return $up_\n\
07132 }\n\
07133 \n\
07134 Connector/RoutingHelper instproc queue {} {\n\
07135 $self instvar queue_\n\
07136 return $queue_\n\
07137 }\n\
07138 \n\
07139 Connector/RoutingHelper instproc head {} {\n\
07140 $self instvar head_\n\
07141 return $head_\n\
07142 }\n\
07143 \n\
07144 Connector/RoutingHelper instproc cost? {} {\n\
07145 $self instvar cost_\n\
07146 return $cost_\n\
07147 }                                                     \n\
07148 Connector/RoutingHelper instproc dump-nam-queueconfig {} { return 0}\n\
07149 \n\
07150 \n\
07151 Simulator instproc trace-all-satlinks {f} {\n\
07152 $self instvar Node_\n\
07153 foreach nn [array names Node_] {\n\
07154 if {![$Node_($nn) info class Node/SatNode]} {\n\
07155 continue; # Not a SatNode\n\
07156 }\n\
07157 $Node_($nn) trace-all-satlinks $f\n\
07158 }\n\
07159 }\n\
07160 \n\
07161 Node/SatNode instproc trace-all-satlinks {f} {\n\
07162 $self instvar nifs_ enqT_ rcvT_ linkhead_\n\
07163 for {set i 0} {$i < $nifs_} {incr i} {\n\
07164 if {[$linkhead_($i) set type_] == \"gsl-repeater\"} {\n\
07165 continue;\n\
07166 }\n\
07167 if {[info exists enqT_($i)]} {\n\
07168 puts \"Tracing already exists on node [$self id]\"\n\
07169 } else {\n\
07170 $self trace-outlink-queue $f $i\n\
07171 }\n\
07172 if {[info exists rcvT_($i)]} {\n\
07173 puts \"Tracing already exists on node [$self id]\"\n\
07174 } else {\n\
07175 $self trace-inlink-queue $f $i\n\
07176 }\n\
07177 }\n\
07178 }\n\
07179 \n\
07180 Node/SatNode instproc trace-outlink-queue {f {index_ 0} } {\n\
07181 $self instvar id_ enqT_ deqT_ drpT_ mac_ ll_ ifq_ drophead_ \n\
07182 \n\
07183 set ns [Simulator instance]\n\
07184 set fromNode_ $id_\n\
07185 set toNode_ -1\n\
07186 \n\
07187 set enqT_($index_) [$ns create-trace Sat/Enque $f $fromNode_ $toNode_]\n\
07188 $enqT_($index_) target $ifq_($index_)\n\
07189 $ll_($index_) down-target $enqT_($index_)\n\
07190 \n\
07191 set deqT_($index_) [$ns create-trace Sat/Deque $f $fromNode_ $toNode_]\n\
07192 $deqT_($index_) target $mac_($index_)\n\
07193 $ifq_($index_) target $deqT_($index_)\n\
07194 \n\
07195 set drpT_($index_) [$ns create-trace Sat/Drop $f $fromNode_ $toNode_]\n\
07196 $drpT_($index_) target [$drophead_($index_) target]\n\
07197 $drophead_($index_) target $drpT_($index_)\n\
07198 $ifq_($index_) drop-target $drpT_($index_)\n\
07199 }\n\
07200 \n\
07201 Node/SatNode instproc trace-inlink-queue {f {index_ 0} } {\n\
07202 $self instvar id_ rcvT_ mac_ ll_ phy_rx_ em_ errT_    \n\
07203 \n\
07204 set ns [Simulator instance]\n\
07205 set toNode_ $id_\n\
07206 set fromNode_ -1\n\
07207 \n\
07208 if {[info exists em_($index_)]} {\n\
07209 set errT_($index_) [$ns create-trace Sat/Error $f $fromNode_ $toNode_]\n\
07210 $errT_($index_) target [$em_($index_) drop-target]\n\
07211 $em_($index_) drop-target $errT_($index_)\n\
07212 set rcvT_($index_) [$ns create-trace Sat/Recv $f $fromNode_ $toNode_]\n\
07213 $rcvT_($index_) target [$em_($index_) target]\n\
07214 $em_($index_) target $rcvT_($index_)\n\
07215 } else {\n\
07216 set rcvT_($index_) [$ns create-trace Sat/Recv $f $fromNode_ $toNode_]\n\
07217 $rcvT_($index_) target [$mac_($index_) up-target]\n\
07218 $mac_($index_) up-target $rcvT_($index_)\n\
07219 }\n\
07220 \n\
07221 }\n\
07222 \n\
07223 \n\
07224 \n\
07225 \n\
07226 Class Trace/Sat/Hop -superclass Trace/Sat\n\
07227 Trace/Sat/Hop instproc init {} {\n\
07228 $self next \"h\"\n\
07229 }\n\
07230 \n\
07231 Class Trace/Sat/Enque -superclass Trace/Sat\n\
07232 Trace/Sat/Enque instproc init {} {\n\
07233 $self next \"+\"\n\
07234 }\n\
07235 \n\
07236 Trace/Sat/Deque instproc init {} {\n\
07237 $self next \"-\"\n\
07238 }\n\
07239 \n\
07240 Class Trace/Sat/Recv -superclass Trace/Sat\n\
07241 Trace/Sat/Recv instproc init {} {\n\
07242 $self next \"r\"\n\
07243 }\n\
07244 \n\
07245 Class Trace/Sat/Drop -superclass Trace/Sat\n\
07246 Trace/Sat/Drop instproc init {} {\n\
07247 $self next \"d\"\n\
07248 }\n\
07249 \n\
07250 Class Trace/Sat/Error -superclass Trace/Sat\n\
07251 Trace/Sat/Error instproc init {} {\n\
07252 $self next \"e\"\n\
07253 }\n\
07254 \n\
07255 Class Trace/Sat/Collision -superclass Trace/Sat\n\
07256 Trace/Sat/Collision instproc init {} {\n\
07257 $self next \"c\"\n\
07258 }\n\
07259 \n\
07260 Class Trace/Sat/Generic -superclass Trace/Sat\n\
07261 Trace/Sat/Generic instproc init {} {\n\
07262 $self next \"v\"\n\
07263 }\n\
07264 \n\
07265 \n\
07266 \n\
07267 Node/SatNode set dist_routing_ false; # distributed routing not yet supported\n\
07268 Position/Sat set time_advance_ 0; # time offset to start of simulation \n\
07269 Position/Sat/Polar set plane_ 0\n\
07270 HandoffManager/Term set elevation_mask_ 0\n\
07271 HandoffManager/Term set term_handoff_int_ 10\n\
07272 HandoffManager/Sat set sat_handoff_int_ 10\n\
07273 HandoffManager/Sat set latitude_threshold_ 70\n\
07274 HandoffManager/Sat set longitude_threshold_ 0\n\
07275 HandoffManager set handoff_randomization_ false \n\
07276 SatRouteObject set metric_delay_ true\n\
07277 SatRouteObject set data_driven_computation_ false\n\
07278 SatRouteObject set wiredRouting_ false\n\
07279 Mac/Sat set trace_drops_ true\n\
07280 Mac/Sat set trace_collisions_ true\n\
07281 Mac/Sat/UnslottedAloha set mean_backoff_ 1s; # mean backoff time upon collision\n\
07282 Mac/Sat/UnslottedAloha set rtx_limit_ 3; # Retransmission limit \n\
07283 Mac/Sat/UnslottedAloha set send_timeout_ 270ms; # Timer interval for new sends\n\
07284 \n\
07285 Agent/SatRoute set myaddr_       0        ;# My address\n\
07286 Mac/Sat set bandwidth_ 2Mb \n\
07287 \n\
07288 \n\
07289 Simulator instproc attach-diffapp { node diffapp } {\n\
07290 $diffapp dr [$node get-dr]\n\
07291 }\n\
07292 \n\
07293 Node instproc get-dr {} {\n\
07294 $self instvar diffAppAgent_\n\
07295 if [info exists diffAppAgent_] {\n\
07296 return $diffAppAgent_\n\
07297 } else {\n\
07298 puts \"Error: No DiffusionApp agent created for this node!\\n\" \n\
07299 exit 1\n\
07300 }\n\
07301 }\n\
07302 \n\
07303 \n\
07304 Node instproc create-diffusionApp-agent { diffFilters } {\n\
07305 $self instvar gradient_ diffAppAgent_\n\
07306 \n\
07307 \n\
07308 if [info exists diffAppAgent_] {\n\
07309 puts \"diffAppAgent_ exists: $diffAppAgent_\"\n\
07310 return $diffAppAgent_\n\
07311 }\n\
07312 \n\
07313 $self set diffAppAgent_ [new Agent/DiffusionApp]\n\
07314 set da $diffAppAgent_\n\
07315 set port [get-da-port $da $self]\n\
07316 $da agent-id $port\n\
07317 $da node $self\n\
07318 \n\
07319 if {$diffFilters == \"\"} {\n\
07320 puts \"Error: No filter defined for diffusion!\\n\"\n\
07321 exit 1\n\
07322 }\n\
07323 set n 0\n\
07324 foreach filtertype [split $diffFilters \"/\"] {\n\
07325 if {$filtertype == \"GeoRoutingFilter\" } continue\n\
07326 set filter($n) [new Application/DiffApp/$filtertype $da]\n\
07327 $filter($n) start         ;# starts filter\n\
07328 incr n\n\
07329 }\n\
07330 \n\
07331 }\n\
07332 \n\
07333 \n\
07334 proc get-da-port {da node} {\n\
07335 \n\
07336 set port [Node set DIFFUSION_APP_PORT]\n\
07337 $node attach $da $port\n\
07338 return $port\n\
07339 }\n\
07340 \n\
07341 proc mvar args {\n\
07342 upvar self _s\n\
07343 uplevel $_s instvar $args\n\
07344 }\n\
07345 \n\
07346 Session/RTP set uniq_srcid 0\n\
07347 Session/RTP proc alloc_srcid {} {\n\
07348 set id [Session/RTP set uniq_srcid]\n\
07349 Session/RTP set uniq_srcid [expr $id+1]\n\
07350 return $id\n\
07351 }\n\
07352 \n\
07353 Session/RTP instproc init {} {\n\
07354 $self next \n\
07355 mvar dchan_ cchan_\n\
07356 set cchan_ [new Agent/RTCP]\n\
07357 set dchan_ [new Agent/CBR/RTP]\n\
07358 $dchan_ set packetSize_ 512\n\
07359 \n\
07360 $dchan_ session $self\n\
07361 $cchan_ session $self\n\
07362 \n\
07363 $self set rtcp_timer_ [new RTCPTimer $self]\n\
07364 \n\
07365 mvar srcid_ localsrc_\n\
07366 set srcid_ [Session/RTP alloc_srcid]\n\
07367 set localsrc_ [new RTPSource $srcid_]\n\
07368 $self localsrc $localsrc_\n\
07369 \n\
07370 $self set srctab_ $localsrc_\n\
07371 $self set stopped_ 1\n\
07372 }\n\
07373 \n\
07374 Session/RTP instproc start {} {\n\
07375 mvar group_\n\
07376 if ![info exists group_] {\n\
07377 puts \"error: can't transmit before joining group!\"\n\
07378 exit 1\n\
07379 }\n\
07380 \n\
07381 mvar cchan_ \n\
07382 $cchan_ start \n\
07383 }\n\
07384 \n\
07385 Session/RTP instproc stop {} {\n\
07386 $self instvar cchan_ dchan_\n\
07387 $dchan_ stop\n\
07388 $cchan_ stop\n\
07389 $self set stopped_ 1\n\
07390 }\n\
07391 \n\
07392 Session/RTP instproc report-interval { i } {\n\
07393 mvar cchan_\n\
07394 $cchan_ set interval_ $i\n\
07395 }\n\
07396 \n\
07397 Session/RTP instproc bye {} {\n\
07398 mvar cchan_ dchan_\n\
07399 $dchan_ stop\n\
07400 $cchan_ bye\n\
07401 }\n\
07402 \n\
07403 Session/RTP instproc attach-node { node } {\n\
07404 mvar dchan_ cchan_\n\
07405 global ns\n\
07406 $ns attach-agent $node $dchan_\n\
07407 $ns attach-agent $node $cchan_\n\
07408 \n\
07409 $self set node_ $node\n\
07410 }\n\
07411 \n\
07412 Session/RTP instproc detach-node { node } {\n\
07413 mvar dchan_ cchan_\n\
07414 global ns\n\
07415 $ns detach-agent $node $dchan_\n\
07416 $ns detach-agent $node $cchan_\n\
07417 \n\
07418 $self unset node_\n\
07419 }\n\
07420 \n\
07421 Session/RTP instproc rtcp_timeout {} {\n\
07422 mvar rtcp_timeout_callback_\n\
07423 \n\
07424 if [info exists rtcp_timeout_callback_] {\n\
07425 eval $rtcp_timeout_callback_\n\
07426 }\n\
07427 }\n\
07428 \n\
07429 Session/RTP instproc join-group { g } {\n\
07430 set g [expr $g]\n\
07431 \n\
07432 $self set group_ $g\n\
07433 \n\
07434 mvar node_ dchan_ cchan_ \n\
07435 \n\
07436 $dchan_ set dst_ $g\n\
07437 $node_ join-group $dchan_ $g\n\
07438 \n\
07439 incr g\n\
07440 \n\
07441 $cchan_ set dst_ $g\n\
07442 $node_ join-group $cchan_ $g\n\
07443 }\n\
07444 \n\
07445 Session/RTP instproc leave-group { } {\n\
07446 mvar group_ node_ cchan_ dchan_\n\
07447 $node_ leave-group $dchan_ $group_\n\
07448 $node_ leave-group $cchan_ [expr $group_+1]\n\
07449 \n\
07450 $self unset group_\n\
07451 }\n\
07452 \n\
07453 Session/RTP instproc session_bw { bspec } {\n\
07454 set b [bw_parse $bspec]\n\
07455 \n\
07456 $self set session_bw_ $b\n\
07457 \n\
07458 mvar rtcp_timer_\n\
07459 $rtcp_timer_ session-bw $b\n\
07460 }\n\
07461 \n\
07462 Session/RTP instproc transmit { bspec } {\n\
07463 set b [bw_parse $bspec]\n\
07464 \n\
07465 \n\
07466 $self set txBW_ $b\n\
07467 \n\
07468 $self instvar dchan_ stopped_\n\
07469 if { $b == 0 } {\n\
07470 $dchan_ stop\n\
07471 set stopped_ 1\n\
07472 }\n\
07473 \n\
07474 set ps [$dchan_ set packetSize_]\n\
07475 $dchan_ set interval_  [expr 8.*$ps/$b]\n\
07476 if { $stopped_ == 1 } {\n\
07477 $dchan_ start\n\
07478 set stopped_ 0\n\
07479 } else {\n\
07480 $dchan_ rate-change\n\
07481 }\n\
07482 }\n\
07483 \n\
07484 \n\
07485 Session/RTP instproc sample-size { cc } {\n\
07486 mvar rtcp_timer_\n\
07487 $rtcp_timer_ sample-size $cc\n\
07488 }\n\
07489 \n\
07490 Session/RTP instproc adapt-timer { nsrc nrr we_sent } {\n\
07491 mvar rtcp_timer_\n\
07492 $rtcp_timer_ adapt $nsrc $nrr $we_sent\n\
07493 }\n\
07494 \n\
07495 Session/RTP instproc new-source { srcid } {\n\
07496 set src [new RTPSource $srcid]\n\
07497 $self enter $src\n\
07498 \n\
07499 mvar srctab_\n\
07500 lappend srctab_ $src\n\
07501 \n\
07502 return $src\n\
07503 }\n\
07504 \n\
07505 Class RTCPTimer \n\
07506 \n\
07507 RTCPTimer instproc init { session } {\n\
07508 $self next\n\
07509 \n\
07510 \n\
07511 mvar session_bw_fraction_ min_rpt_time_ inv_sender_bw_fraction_\n\
07512 mvar inv_rcvr_bw_fraction_ size_gain_ avg_size_ inv_bw_\n\
07513 \n\
07514 set session_bw_fraction_ 0.05\n\
07515 \n\
07516 set min_rpt_time_ 1.   \n\
07517 \n\
07518 set sender_bw_fraction 0.25\n\
07519 set rcvr_bw_fraction [expr 1. - $sender_bw_fraction]\n\
07520 \n\
07521 set inv_sender_bw_fraction_ [expr 1. / $sender_bw_fraction]\n\
07522 set inv_rcvr_bw_fraction_ [expr 1. / $rcvr_bw_fraction]\n\
07523 \n\
07524 set size_gain_ 0.125    \n\
07525 \n\
07526 set avg_size_ 128.\n\
07527 set inv_bw_ 0.\n\
07528 \n\
07529 mvar session_\n\
07530 set session_ $session\n\
07531 \n\
07532 \n\
07533 mvar min_rtp_time_ avg_size_ inv_bw_\n\
07534 set rint [expr 8*$avg_size_ * $inv_bw_]\n\
07535 \n\
07536 set t [expr $min_rpt_time_ / 2.]\n\
07537 \n\
07538 if { $rint < $t } {\n\
07539 set rint $t\n\
07540 }\n\
07541 \n\
07542 $session_ report-interval $rint\n\
07543 }\n\
07544 \n\
07545 RTCPTimer instproc sample-size { cc } {\n\
07546 mvar avg_size_ size_gain_\n\
07547 \n\
07548 set avg_size_ [expr $avg_size_ + $size_gain_ * ($cc + 28 - $avg_size_)]\n\
07549 }\n\
07550 \n\
07551 RTCPTimer instproc adapt { nsrc nrr we_sent } {\n\
07552 mvar inv_bw_ avg_size_ min_rpt_time_\n\
07553 mvar inv_sender_bw_fraction_ inv_rcvr_bw_fraction_\n\
07554 \n\
07555 \n\
07556 set ibw $inv_bw_\n\
07557 if { $nrr > 0 } {\n\
07558 if { $we_sent } {\n\
07559 set ibw [expr $ibw * $inv_sender_bw_fraction_]\n\
07560 set nsrc $nrr\n\
07561 } else {\n\
07562 set ibw [expr $ibw * $inv_rcvr_bw_fraction_]\n\
07563 incr nsrc -$nrr\n\
07564 }\n\
07565 }\n\
07566 \n\
07567 set rint [expr 8*$avg_size_ * $nsrc * $ibw] \n\
07568 if { $rint < $min_rpt_time_ } {\n\
07569 set rint $min_rpt_time_\n\
07570 }\n\
07571 \n\
07572 mvar session_\n\
07573 $session_ report-interval $rint\n\
07574 }\n\
07575 \n\
07576 RTCPTimer instproc session-bw { b } {\n\
07577 $self set inv_bw_ [expr 1. / $b ]\n\
07578 }\n\
07579 \n\
07580 Agent/RTCP set interval_ 0.\n\
07581 Agent/RTCP set random_ 0\n\
07582 Agent/RTCP set class_ 32\n\
07583 \n\
07584 RTPSource set srcid_ -1\n\
07585 NetworkInterface set ifacenum_ 0\n\
07586 NetworkInterface proc getid {} {\n\
07587 $self instvar ifacenum_\n\
07588 return [incr ifacenum_]\n\
07589 }\n\
07590 \n\
07591 NetworkInterface instproc init {} {\n\
07592 $self next\n\
07593 $self cmd label [NetworkInterface getid]\n\
07594 }\n\
07595 \n\
07596 Channel set delay_ 4us\n\
07597 \n\
07598 Classifier/Mac set bcast_ 0\n\
07599 \n\
07600 Mac set bandwidth_ 2Mb\n\
07601 Mac set delay_ 0us\n\
07602 \n\
07603 Mac/Simple set fullduplex_mode_ 0\n\
07604 \n\
07605 if [TclObject is-class Mac/802_11] {\n\
07606 Mac/802_11 set delay_ 64us\n\
07607 Mac/802_11 set ifs_ 16us\n\
07608 Mac/802_11 set slotTime_ 16us\n\
07609 Mac/802_11 set cwmin_ 16\n\
07610 Mac/802_11 set cwmax_ 1024\n\
07611 Mac/802_11 set rtxLimit_ 16\n\
07612 Mac/802_11 set bssId_ -1\n\
07613 Mac/802_11 set sifs_ 8us\n\
07614 Mac/802_11 set pifs_ 12us\n\
07615 Mac/802_11 set difs_ 16us\n\
07616 Mac/802_11 set rtxAckLimit_ 1\n\
07617 Mac/802_11 set rtxRtsLimit_ 3\n\
07618 Mac/802_11 set basicRate_ 1Mb  ;# set this to 0 if want to use bandwidth_ for \n\
07619 Mac/802_11 set dataRate_ 1Mb   ;# both control and data pkts\n\
07620 }\n\
07621 \n\
07622 if [TclObject is-class Mac/Mcns] {\n\
07623 Mac/Mcns set bandwidth_ 10Mb\n\
07624 Mac/Mcns set hlen_ 6\n\
07625 Mac/Mcns set bssId_ -1\n\
07626 Mac/Mcns set slotTime_ 10us\n\
07627 }\n\
07628 \n\
07629 if [TclObject is-class Mac/Multihop] {\n\
07630 Mac/Multihop set bandwidth_ 100Kb\n\
07631 Mac/Multihop set delay_ 10ms\n\
07632 Mac/Multihop set tx_rx_ 11.125ms\n\
07633 Mac/Multihop set rx_tx_ 13.25ms\n\
07634 Mac/Multihop set rx_rx_ 10.5625\n\
07635 Mac/Multihop set backoffBase_ 20ms\n\
07636 Mac/Multihop set hlen_ 16\n\
07637 }\n\
07638 \n\
07639 Mac instproc classify-macs {peerinfo} {\n\
07640 set peerlabel [lindex $peerinfo 0]\n\
07641 set peerll [lindex $peerinfo 1]\n\
07642 $self instvar mclass_\n\
07643 set mclass_ [new Classifier/Mac]\n\
07644 $mclass_ install $peerlabel $peerll\n\
07645 $self target $mclass_\n\
07646 }\n\
07647 \n\
07648 Node instproc addmac {mac} { \n\
07649 $self instvar machead_ mactail_\n\
07650 \n\
07651 if ![info exists mactail_] {\n\
07652 set mactail_ [set machead_ $mac]\n\
07653 $mac maclist $mactail_\n\
07654 } else {\n\
07655 $mactail_ maclist $mac\n\
07656 $mac maclist $machead_\n\
07657 set mactail_ $mac\n\
07658 }\n\
07659 }\n\
07660 \n\
07661 \n\
07662 Mac/Simple set debug_ false\n\
07663 Mac/Simple instproc init {} {\n\
07664 eval $self next\n\
07665 set ns [Simulator instance]\n\
07666 $ns create-eventtrace Event $self\n\
07667 }\n\
07668 \n\
07669 Mac/802_11 set debug_ false\n\
07670 Mac/802_11 instproc init {} {\n\
07671 eval $self next\n\
07672 set ns [Simulator instance]\n\
07673 $ns create-eventtrace Event $self\n\
07674 }\n\
07675 \n\
07676 LL set bandwidth_ 0      ;# not used\n\
07677 LL set delay_ 1ms\n\
07678 LL set macDA_ 0\n\
07679 \n\
07680 LL/Sat/HDLC set window_size_ 8\n\
07681 LL/Sat/HDLC set queue_size_ 1000\n\
07682 LL/Sat/HDLC set timeout_ 0.26\n\
07683 LL/Sat/HDLC set max_timeouts_ 2 ;# set to a very high value to ensure HDLC ARQ connection\n\
07684 LL/Sat/HDLC set delAck_   false  ;# ack maybe delayed to allow piggybacking\n\
07685 LL/Sat/HDLC set delAckVal_  0.1  ;# value chosen based on a link delay of 100ms\n\
07686 LL/Sat/HDLC set selRepeat_ false ;# set to GoBackN by default\n\
07687 \n\
07688 if [TclObject is-class LL/Arq] {\n\
07689 LL/Arq set mode_ 2\n\
07690 LL/Arq set hlen_ 16\n\
07691 LL/Arq set slen_ 1400\n\
07692 LL/Arq set limit_ 8\n\
07693 LL/Arq set timeout_ 100ms\n\
07694 \n\
07695 Class LL/Rlp -superclass LL/Arq\n\
07696 LL/Rlp set mode_ 1\n\
07697 LL/Rlp set hlen_ 6\n\
07698 LL/Rlp set slen_ 30\n\
07699 LL/Rlp set limit_ 63\n\
07700 LL/Rlp set timeout_ 500ms\n\
07701 LL/Rlp set delay_ 70ms\n\
07702 }\n\
07703 \n\
07704 \n\
07705 if [TclObject is-class Snoop] {\n\
07706 Snoop set snoopTick_ 0.1\n\
07707 Snoop set snoopDisable_ 0\n\
07708 Snoop set srtt_ 0.1\n\
07709 Snoop set rttvar_ 0.25\n\
07710 Snoop set g_ 0.125\n\
07711 Snoop set tailTime_ 0\n\
07712 Snoop set rxmitStatus_ 0\n\
07713 Snoop set lru_ 0\n\
07714 Snoop set maxbufs_ 0\n\
07715 }\n\
07716 \n\
07717 if [TclObject is-class LL/LLSnoop] {\n\
07718 LL/LLSnoop set integrate_ 0\n\
07719 LL/LLSnoop set delay_ 0ms\n\
07720 Snoop set srtt_ 0.1\n\
07721 Snoop set rttvar_ 0.25\n\
07722 Snoop set g_ 0.125\n\
07723 LL/LLSnoop set snoopTick_ 0.1\n\
07724 }\n\
07725 \n\
07726 LL/LLSnoop instproc get-snoop { src dst } {\n\
07727 $self instvar snoops_ off_ll_ delay_\n\
07728 \n\
07729 if { ![info exists snoops_($src:$dst)] } {\n\
07730 set snoops_($src:$dst) [new Snoop]\n\
07731 }\n\
07732 $snoops_($src:$dst) llsnoop $self\n\
07733 $snoops_($src:$dst) set delay_ $delay_\n\
07734 return $snoops_($src:$dst)\n\
07735 }\n\
07736 \n\
07737 LL/LLSnoop instproc integrate { src dst } {\n\
07738 $self instvar snoops_\n\
07739 \n\
07740 set conn $src:$dst\n\
07741 if {![info exists snoops_($conn)]} {\n\
07742 return\n\
07743 }\n\
07744 \n\
07745 set snoop $snoops_($conn)\n\
07746 set threshtime [$snoop set tailTime_]\n\
07747 \n\
07748 foreach a [array names snoops_] {\n\
07749 if { $a != $conn } {\n\
07750 $snoops_($a) check-rxmit $threshtime\n\
07751 if { [$snoops_($a) set rxmitStatus_] == 2 } {\n\
07752 break;\n\
07753 }\n\
07754 }\n\
07755 }\n\
07756 }\n\
07757 \n\
07758 \n\
07759 \n\
07760 \n\
07761 \n\
07762 \n\
07763 \n\
07764 \n\
07765 \n\
07766 \n\
07767 LanNode set ifqType_   Queue/DropTail\n\
07768 LanNode set ifqLen_    \"\"\n\
07769 LanNode set llType_    LL\n\
07770 LanNode set macType_   Mac\n\
07771 LanNode set chanType_  Channel\n\
07772 LanNode set phyType_   Phy/WiredPhy\n\
07773 LanNode set address_   \"\"\n\
07774 LanNode set mactrace_   false\n\
07775 \n\
07776 LanNode instproc address  {val} { $self set address_  $val }\n\
07777 LanNode instproc bw       {val} { $self set bw_       $val }\n\
07778 LanNode instproc delay    {val} { $self set delay_    $val }\n\
07779 LanNode instproc ifqType  {val} { $self set ifqType_  $val }\n\
07780 LanNode instproc ifqLen   {val} { $self set ifqLen_   $val }\n\
07781 LanNode instproc llType   {val} { $self set llType_   $val }\n\
07782 LanNode instproc macType  {val} { $self set macType_  $val }\n\
07783 LanNode instproc chanType {val} { $self set chanType_ $val }\n\
07784 LanNode instproc phyType  {val} { $self set phyType_  $val }\n\
07785 LanNode instproc mactrace    {val} { $self set mactrace_    $val }\n\
07786 \n\
07787 LanNode instproc init {ns args} {\n\
07788 set args [eval $self init-vars $args]\n\
07789 $self instvar bw_ delay_ llType_ macType_ chanType_\n\
07790 $self instvar phyType_ mactrace_\n\
07791 $self instvar ns_ nodelist_ defRouter_ cost_\n\
07792 $self instvar id_ address_ channel_ mcl_ varp_\n\
07793 $ns instvar Node_\n\
07794 \n\
07795 $self next\n\
07796 set ns_ $ns\n\
07797 set nodelist_ \"\"\n\
07798 set cost_ 1\n\
07799 \n\
07800 set id_ [Node getid]\n\
07801 $self nodeid $id_\n\
07802 $ns_ add-lannode $self $id_\n\
07803 set Node_($id_) $self\n\
07804 if [Simulator hier-addr?] {\n\
07805 if {$address_ == \"\"} {\n\
07806 error \"LanNode: use \\\"-address\\\" option \\\n\
07807 with hierarchical routing\"\n\
07808 }\n\
07809 } else {\n\
07810 set address_ $id_\n\
07811 }\n\
07812 $self addr $address_\n\
07813 set defRouter_ [new LanRouter $ns $self]\n\
07814 if [$ns multicast?] {\n\
07815 set switch_ [new Classifier/Hash/Dest 32]\n\
07816 $switch_ set mask_ [AddrParams McastMask]\n\
07817 $switch_ set shift_ [AddrParams McastShift]\n\
07818 \n\
07819 $defRouter_ switch $switch_\n\
07820 }\n\
07821 set channel_ [new $chanType_]\n\
07822 set varp_ [new VARPTable]\n\
07823 }\n\
07824 \n\
07825 LanNode instproc addNode {nodes bw delay {llType \"\"} {ifqType \"\"} \\\n\
07826 {macType \"\"} {phyType \"\"} {mactrace \"\"} {ifqLen \"\"}} {\n\
07827 $self instvar ifqType_ ifqLen_ llType_ macType_ chanType_ phyType_ \n\
07828 $self instvar mactrace_\n\
07829 $self instvar id_ channel_ mcl_ lanIface_\n\
07830 $self instvar ns_ nodelist_ cost_ varp_\n\
07831 $ns_ instvar link_ Node_ \n\
07832 \n\
07833 if {$ifqType == \"\"} { set ifqType $ifqType_ }\n\
07834 if {$ifqLen == \"\"} { set ifqLen $ifqLen_ }\n\
07835 if {$macType == \"\"} { set macType $macType_ }\n\
07836 if {$llType  == \"\"} { set llType $llType_ }\n\
07837 if {$phyType  == \"\"} { set phyType $phyType_ }\n\
07838 if {$mactrace == \"\"}  { set mactrace $mactrace_ }\n\
07839 \n\
07840 set vlinkcost [expr $cost_ / 2.0]\n\
07841 foreach src $nodes {\n\
07842 set nif [new LanIface $src $self \\\n\
07843 -ifqType $ifqType \\\n\
07844 -ifqLen $ifqLen \\\n\
07845 -llType  $llType \\\n\
07846 -macType $macType \\\n\
07847 -phyType $phyType \\\n\
07848 -mactrace $mactrace ]\n\
07849 \n\
07850 set tr [$ns_ get-ns-traceall]\n\
07851 if {$tr != \"\"} {\n\
07852 $nif trace $ns_ $tr\n\
07853 }\n\
07854 set tr [$ns_ get-nam-traceall]\n\
07855 if {$tr != \"\"} {\n\
07856 $nif nam-trace $ns_ $tr\n\
07857 }\n\
07858 \n\
07859 \n\
07860 set ll [$nif set ll_]\n\
07861 $ll set delay_ $delay\n\
07862 $ll varp $varp_\n\
07863 \n\
07864 $varp_ mac-addr [[$nif set node_] id] \\\n\
07865 [[$nif set mac_] id]\n\
07866 \n\
07867 set phy [$nif set phy_]\n\
07868 $phy node $src\n\
07869 $phy channel $channel_\n\
07870 $channel_ addif $phy\n\
07871 $phy set bandwidth_ $bw\n\
07872 \n\
07873 set lanIface_($src) $nif\n\
07874 \n\
07875 $src add-neighbor $self\n\
07876 \n\
07877 set sid [$src id]\n\
07878 set link_($sid:$id_) [new Vlink $ns_ $self $src  $self $bw 0]\n\
07879 set link_($id_:$sid) [new Vlink $ns_ $self $self $src  $bw 0]\n\
07880 \n\
07881 $src add-oif [$link_($sid:$id_) head]  $link_($sid:$id_)\n\
07882 $src add-iif [[$nif set iface_] label] $link_($id_:$sid)\n\
07883 [$link_($sid:$id_) head] set link_ $link_($sid:$id_)\n\
07884 \n\
07885 $link_($sid:$id_) queue [$nif set ifq_]\n\
07886 $link_($id_:$sid) queue [$nif set ifq_]\n\
07887 \n\
07888 $link_($sid:$id_) set iif_ [$nif set iface_]\n\
07889 $link_($id_:$sid) set iif_ [$nif set iface_]\n\
07890 \n\
07891 $link_($sid:$id_) cost $vlinkcost\n\
07892 $link_($id_:$sid) cost $vlinkcost\n\
07893 }\n\
07894 set nodelist_ [concat $nodelist_ $nodes]\n\
07895 }\n\
07896 \n\
07897 LanNode instproc assign-mac {ip} {\n\
07898 return $ip ;# use ip addresses at MAC layer\n\
07899 }\n\
07900 \n\
07901 LanNode instproc cost c {\n\
07902 $self instvar ns_ nodelist_ id_ cost_\n\
07903 $ns_ instvar link_\n\
07904 set cost_ $c\n\
07905 set vlinkcost [expr $c / 2.0]\n\
07906 foreach node $nodelist_ {\n\
07907 set nid [$node id]\n\
07908 $link_($id_:$nid) cost $vlinkcost\n\
07909 $link_($nid:$id_) cost $vlinkcost\n\
07910 }\n\
07911 }\n\
07912 \n\
07913 LanNode instproc cost? {} {\n\
07914 $self instvar cost_\n\
07915 return $cost_\n\
07916 }\n\
07917 \n\
07918 LanNode instproc rtObject? {} {\n\
07919 }\n\
07920 \n\
07921 LanNode instproc id {} { $self set id_ }\n\
07922 \n\
07923 LanNode instproc node-addr {{addr \"\"}} { \n\
07924 eval $self set address_ $addr\n\
07925 }\n\
07926 \n\
07927 LanNode instproc reset {} {\n\
07928 }\n\
07929 \n\
07930 LanNode instproc is-lan? {} { return 1 }\n\
07931 \n\
07932 LanNode instproc dump-namconfig {} {\n\
07933 $self instvar ns_ bw_ delay_ nodelist_ id_\n\
07934 $ns_ puts-nam-config \\\n\
07935 \"X -t * -n $id_ -r $bw_ -D $delay_ -o left\"\n\
07936 set cnt 0\n\
07937 set LanOrient(0) \"up\"\n\
07938 set LanOrient(1) \"down\"\n\
07939 \n\
07940 foreach n $nodelist_ {\n\
07941 $ns_ puts-nam-config \\\n\
07942 \"L -t * -s $id_ -d [$n id] -o $LanOrient($cnt)\"\n\
07943 set cnt [expr 1 - $cnt]\n\
07944 }\n\
07945 }\n\
07946 \n\
07947 LanNode instproc init-outLink {} { \n\
07948 }\n\
07949 \n\
07950 LanNode instproc start-mcast {} { \n\
07951 }\n\
07952 \n\
07953 LanNode instproc getArbiter {} {\n\
07954 }\n\
07955 \n\
07956 LanNode instproc attach {agent} {\n\
07957 }\n\
07958 \n\
07959 LanNode instproc sp-add-route {args} {\n\
07960 }\n\
07961 \n\
07962 LanNode instproc add-route {args} {\n\
07963 }\n\
07964 \n\
07965 LanNode instproc add-hroute {args} {\n\
07966 }\n\
07967 \n\
07968 Class LanIface \n\
07969 LanIface set ifqType_ Queue/DropTail\n\
07970 LanIface set macType_ Mac\n\
07971 LanIface set llType_  LL\n\
07972 LanIface set phyType_  Phy/WiredPhy\n\
07973 LanIface set mactrace_ false\n\
07974 \n\
07975 LanIface instproc llType {val} { $self set llType_ $val }\n\
07976 LanIface instproc ifqType {val} { $self set ifqType_ $val }\n\
07977 LanIface instproc ifqLen {val} { $self set ifqLen_ $val }\n\
07978 LanIface instproc macType {val} { $self set macType_ $val }\n\
07979 LanIface instproc phyType {val} { $self set phyType_ $val }\n\
07980 LanIface instproc mactrace {val} { $self set mactrace_ $val }\n\
07981 \n\
07982 LanIface instproc entry {} { $self set entry_ }\n\
07983 LanIface instproc init {node lan args} {\n\
07984 set args [eval $self init-vars $args]\n\
07985 eval $self next $args\n\
07986 \n\
07987 $self instvar llType_ ifqType_ macType_ phyType_ mactrace_\n\
07988 $self instvar node_ lan_ ifq_ ifqLen_ mac_ ll_ phy_\n\
07989 $self instvar iface_ entry_ drophead_\n\
07990 \n\
07991 set node_ $node\n\
07992 set lan_ $lan\n\
07993 \n\
07994 set ll_ [new $llType_]\n\
07995 set ifq_ [new $ifqType_]\n\
07996 if {$ifqLen_ != \"\"} { $ifq_ set limit_ $ifqLen_ }\n\
07997 set mac_ [new $macType_]\n\
07998 if {[string compare $macType_ \"Mac/802_3\"] == 0} {\n\
07999 $mac_ set trace_ $mactrace_\n\
08000 }\n\
08001 set iface_ [new NetworkInterface]\n\
08002 set phy_ [new $phyType_]\n\
08003 \n\
08004 set entry_ [new Connector]\n\
08005 set drophead_ [new Connector]\n\
08006 \n\
08007 $ll_ set macDA_ -1  ;# bcast address if there is no LAN router\n\
08008 $ll_ lanrouter [$lan set defRouter_]\n\
08009 $ll_ up-target $iface_\n\
08010 $ll_ down-target $ifq_\n\
08011 $ll_ mac $mac_\n\
08012 $ll_ ifq $ifq_\n\
08013 \n\
08014 $ifq_ target $mac_\n\
08015 \n\
08016 $mac_ up-target $ll_\n\
08017 $mac_ down-target $phy_\n\
08018 $mac_ netif $phy_\n\
08019 \n\
08020 $phy_ up-target $mac_\n\
08021 \n\
08022 $iface_ target [$node entry]\n\
08023 $entry_ target $ll_\n\
08024 \n\
08025 set ns [Simulator instance]\n\
08026 \n\
08027 $drophead_ target [$ns set nullAgent_]\n\
08028 \n\
08029 $ifq_ drop-target $drophead_ \n\
08030 $mac_ drop-target $drophead_ \n\
08031 $ll_ drop-target $drophead_\n\
08032 }\n\
08033 \n\
08034 LanIface instproc trace {ns f {op \"\"}} {\n\
08035 $self instvar hopT_ rcvT_ enqT_ deqT_ drpT_ \n\
08036 $self instvar iface_ entry_ node_ lan_ drophead_ \n\
08037 $self instvar ll_ ifq_ mac_ mactrace_\n\
08038 \n\
08039 set hopT_ [$ns create-trace Hop   $f $node_ $lan_  $op]\n\
08040 set rcvT_ [$ns create-trace Recv  $f $lan_  $node_ $op]\n\
08041 set enqT_ [$ns create-trace Enque $f $node_ $lan_  $op]\n\
08042 set deqT_ [$ns create-trace Deque $f $node_ $lan_  $op]\n\
08043 set drpT_ [$ns create-trace Drop  $f $node_ $lan_  $op]\n\
08044 if {[string compare $mactrace_ \"true\"] == 0} {\n\
08045 set macdrpT_ [$ns create-trace Collision $f $node_ $lan_ $op]\n\
08046 set macdrophead_ [new Connector]\n\
08047 $mac_ drop-target $macdrophead_\n\
08048 $macdrophead_ target $macdrpT_\n\
08049 }\n\
08050 \n\
08051 $hopT_ target [$entry_ target]\n\
08052 $entry_ target $hopT_\n\
08053 \n\
08054 $rcvT_ target [$iface_ target]\n\
08055 $iface_ target $rcvT_\n\
08056 \n\
08057 $enqT_ target [$ll_ down-target]\n\
08058 $ll_ down-target $enqT_\n\
08059 \n\
08060 $deqT_ target [$ifq_ target]\n\
08061 $ifq_ target $deqT_\n\
08062 \n\
08063 $drpT_ target [$drophead_ target]\n\
08064 $drophead_ target $drpT_\n\
08065 }\n\
08066 LanIface instproc nam-trace {ns f} {\n\
08067 $self instvar hopT_ rcvT_ enqT_ deqT_ drpT_ \n\
08068 if [info exists hopT_] {\n\
08069 $hopT_ namattach $f\n\
08070 } else {\n\
08071 $self trace $ns $f \"nam\"\n\
08072 }\n\
08073 $rcvT_ namattach $f\n\
08074 $enqT_ namattach $f\n\
08075 $deqT_ namattach $f\n\
08076 $drpT_ namattach $f\n\
08077 }\n\
08078 LanIface instproc add-receive-filter filter {\n\
08079 $self instvar mac_\n\
08080 $filter target [$mac_ target]\n\
08081 $mac_ target $filter\n\
08082 }\n\
08083 \n\
08084 \n\
08085 Class Vlink\n\
08086 Vlink instproc up? {} {\n\
08087 return \"up\"\n\
08088 }\n\
08089 Vlink instproc queue {{q \"\"}} {\n\
08090 eval $self set queue_ $q\n\
08091 }\n\
08092 Vlink instproc init {ns lan src dst b d} {\n\
08093 $self instvar ns_ lan_ src_ dst_ bw_ delay_\n\
08094 \n\
08095 set ns_ $ns\n\
08096 set lan_ $lan\n\
08097 set src_ $src\n\
08098 set dst_ $dst\n\
08099 set bw_ $b\n\
08100 set delay_ $d\n\
08101 }\n\
08102 Vlink instproc src {}   { $self set src_    }\n\
08103 Vlink instproc dst {}   { $self set dst_    }\n\
08104 Vlink instproc dump-nam-queueconfig {} {\n\
08105 }\n\
08106 Vlink instproc head {} {\n\
08107 $self instvar lan_ dst_ src_\n\
08108 if {$src_ == $lan_ } {\n\
08109 return \"\"\n\
08110 } else {\n\
08111 set src_lif [$lan_ set lanIface_($src_)]\n\
08112 return [$src_lif entry]\n\
08113 }\n\
08114 }\n\
08115 Vlink instproc cost c { $self set cost_ $c} \n\
08116 Vlink instproc cost? {} {\n\
08117 $self instvar cost_\n\
08118 if ![info exists cost_] {\n\
08119 return 1\n\
08120 }\n\
08121 return $cost_\n\
08122 }\n\
08123 \n\
08124 \n\
08125 LanRouter instproc init {ns lan} {\n\
08126 $self next\n\
08127 if [Simulator hier-addr?] {\n\
08128 $self routing hier\n\
08129 } else {\n\
08130 $self routing flat\n\
08131 }\n\
08132 $self lanaddr [$lan node-addr]\n\
08133 $self routelogic [$ns get-routelogic]\n\
08134 }\n\
08135 \n\
08136 \n\
08137 Node instproc is-lan? {} { return 0 }\n\
08138 \n\
08139 Simulator instproc newLan {nodelist bw delay args} {\n\
08140 set lan [eval new LanNode $self -bw $bw -delay $delay $args]\n\
08141 $lan addNode $nodelist $bw $delay\n\
08142 return $lan\n\
08143 }\n\
08144 \n\
08145 \n\
08146 Simulator instproc make-lan { args } {\n\
08147 \n\
08148 set t [lindex $args 0]\n\
08149 set mactrace \"false\"\n\
08150 if { $t == \"-trace\" } {\n\
08151 set mactrace [lindex $args 1]\n\
08152 if {$mactrace == \"on\" } {\n\
08153 set mactrace \"true\"\n\
08154 }\n\
08155 \n\
08156 }\n\
08157 \n\
08158 if { $t == \"-trace\" } {\n\
08159 set nodelist [lindex $args 2]\n\
08160 set bw [lindex $args 3]\n\
08161 set delay [lindex $args 4]\n\
08162 set llType [lindex $args 5]\n\
08163 set ifqType [lindex $args 6]\n\
08164 set macType [lindex $args 7]\n\
08165 set chanType [lindex $args 8]\n\
08166 set phyType [lindex $args 9]\n\
08167 set ifqLen [lindex $args 10]\n\
08168 } else {\n\
08169 set nodelist [lindex $args 0]\n\
08170 set bw [lindex $args 1]\n\
08171 set delay [lindex $args 2]\n\
08172 set llType [lindex $args 3]\n\
08173 set ifqType [lindex $args 4]\n\
08174 set macType [lindex $args 5]\n\
08175 set chanType [lindex $args 6]\n\
08176 set phyType [lindex $args 7]\n\
08177 set ifqLen [lindex $args 8]\n\
08178 }\n\
08179 \n\
08180 if { $llType == \"\" } {\n\
08181 set llType \"LL\"\n\
08182 }\n\
08183 if { $ifqType == \"\" } {\n\
08184 set ifqtype \"Queue/DropTail\"\n\
08185 }\n\
08186 if { $macType == \"\" } {\n\
08187 set macType \"Mac\"\n\
08188 }\n\
08189 if { $chanType == \"\" } {\n\
08190 set chanType \"Channel\"\n\
08191 }\n\
08192 if { $phyType == \"\"} {\n\
08193 set phyType \"Phy/WiredPhy\"\n\
08194 }\n\
08195 \n\
08196 if {[string compare $macType \"Mac/Csma/Cd\"] == 0} {\n\
08197 puts \"Warning: Mac/Csma/Cd is out of date\"\n\
08198 puts \"Warning: Please use Mac/802_3 to replace Mac/Csma/Cd\"\n\
08199 set macType \"Mac/802_3\"\n\
08200 }\n\
08201 \n\
08202 set lan [new LanNode $self \\\n\
08203 -bw $bw \\\n\
08204 -delay $delay \\\n\
08205 -llType $llType \\\n\
08206 -ifqType $ifqType \\\n\
08207 -ifqLen $ifqLen \\\n\
08208 -macType $macType \\\n\
08209 -chanType $chanType \\\n\
08210 -phyType $phyType \\\n\
08211 -mactrace $mactrace]\n\
08212 $lan addNode $nodelist $bw $delay $llType $ifqType $macType \\\n\
08213 $phyType $mactrace $ifqLen\n\
08214 \n\
08215 return $lan\n\
08216 }\n\
08217 \n\
08218 \n\
08219 \n\
08220 \n\
08221 \n\
08222 \n\
08223 \n\
08224 \n\
08225 \n\
08226 \n\
08227 \n\
08228 \n\
08229 AbsLanNode set address_   \"\"\n\
08230 \n\
08231 AbsLanNode instproc address  {val} { $self set address_  $val }\n\
08232 AbsLanNode instproc bw       {val} { $self set bw_       $val }\n\
08233 AbsLanNode instproc delay    {val} { $self set delay_    $val }\n\
08234 AbsLanNode instproc qlen     {val} { $self set qlen_     $val }\n\
08235 \n\
08236 AbsLanNode instproc init {ns args} {\n\
08237 set args [eval $self init-vars $args]\n\
08238 $self instvar bw_ delay_ qlen_\n\
08239 $self instvar ns_ nodelist_ defRouter_ cost_\n\
08240 $self instvar id_ address_ q_ dlink_ mcl_ varp_\n\
08241 $ns instvar Node_\n\
08242 \n\
08243 $self next\n\
08244 set ns_ $ns\n\
08245 set nodelist_ \"\"\n\
08246 set cost_ 1\n\
08247 \n\
08248 set id_ [Node getid]\n\
08249 $ns_ add-abslan-node $self $id_\n\
08250 $self nodeid $id_   ;# Propagate id_ into c++ space\n\
08251 set Node_($id_) $self\n\
08252 set address_ $id_       ;# won't work for hier rtg!\n\
08253 set defRouter_ [new LanRouter $ns $self]\n\
08254 if [$ns multicast?] {\n\
08255 set switch_ [new Classifier/Hash/Dest 32]\n\
08256 $switch_ set mask_ [AddrParams set McastMask_]\n\
08257 $switch_ set shift_ [AddrParams set McastShift_]\n\
08258 \n\
08259 $defRouter_ switch $switch_\n\
08260 }\n\
08261 \n\
08262 set varp_ [new VARPTable]\n\
08263 \n\
08264 set q_ [new Queue/DropTail]\n\
08265 set dlink_ [new DelayLink]\n\
08266 $dlink_ set bandwidth_ $bw_\n\
08267 $dlink_ set delay_ $delay_\n\
08268 set mcl_ [new Classifier/Replicator]\n\
08269 $mcl_ set offset_ [PktHdr_offset PacketHeader/Mac macDA_]\n\
08270 $mcl_ set direction_ true\n\
08271 $q_ target $dlink_\n\
08272 $q_ set limit_ $qlen_\n\
08273 $dlink_ target $mcl_\n\
08274 \n\
08275 }\n\
08276 \n\
08277 AbsLanNode instproc addNode {nodes} {\n\
08278 $self instvar id_ lanIface_\n\
08279 $self instvar q_ ns_ nodelist_ cost_ varp_ \n\
08280 $self instvar dlink_ mcl_ bw_\n\
08281 $self instvar deqT_\n\
08282 $ns_ instvar link_ Node_ \n\
08283 \n\
08284 \n\
08285 set vlinkcost [expr $cost_ / 2.0]\n\
08286 foreach src $nodes {\n\
08287 set nif [new AbsLanIface $src $self]\n\
08288 \n\
08289 set tr [$ns_ get-ns-traceall]\n\
08290 if {$tr != \"\"} {\n\
08291 $nif trace $ns_ $tr\n\
08292 }\n\
08293 \n\
08294 set tr [$ns_ get-nam-traceall]\n\
08295 if {$tr != \"\"} {\n\
08296 $nif nam-trace $ns_ $tr\n\
08297 }\n\
08298 \n\
08299 \n\
08300 $mcl_ installNext [$nif set mac_]\n\
08301 $varp_ mac-addr [[$nif set node_] id] \\\n\
08302 [[$nif set mac_] id] \n\
08303 \n\
08304 $q_ drop-target [$nif set drophead_]\n\
08305 set lanIface_($src) $nif\n\
08306 \n\
08307 $src add-neighbor $self\n\
08308 \n\
08309 set sid [$src id]\n\
08310 \n\
08311 set link_($sid:$id_) [new Vlink $ns_ $self $src  $self $bw_ 0]\n\
08312 set link_($id_:$sid) [new Vlink $ns_ $self $self $src  $bw_ 0]\n\
08313 \n\
08314 [$link_($sid:$id_) head] set link_ $link_($sid:$id_)\n\
08315 \n\
08316 $link_($sid:$id_) queue [$self set q_ ]\n\
08317 $link_($id_:$sid) queue [$self set q_ ]\n\
08318 \n\
08319 \n\
08320 $link_($sid:$id_) cost $vlinkcost\n\
08321 $link_($id_:$sid) cost $vlinkcost\n\
08322 }\n\
08323 \n\
08324 set nodelist_ [concat $nodelist_ $nodes]\n\
08325 \n\
08326 set f [$ns_ get-ns-traceall]\n\
08327 set deqT_ [$ns_ create-trace Deque  $f $src $self ]\n\
08328 \n\
08329 $deqT_ target $dlink_\n\
08330 $q_ target $deqT_\n\
08331 \n\
08332 }\n\
08333 \n\
08334 AbsLanNode instproc assign-mac {ip} {\n\
08335 return $ip ;# use ip addresses at MAC layer\n\
08336 }\n\
08337 \n\
08338 AbsLanNode instproc cost c {\n\
08339 $self instvar ns_ nodelist_ id_ cost_\n\
08340 $ns_ instvar link_\n\
08341 set cost_ $c\n\
08342 set vlinkcost [expr $c / 2.0]\n\
08343 foreach node $nodelist_ {\n\
08344 set nid [$node id]\n\
08345 $link_($id_:$nid) cost $vlinkcost\n\
08346 $link_($nid:$id_) cost $vlinkcost\n\
08347 }\n\
08348 }\n\
08349 \n\
08350 AbsLanNode instproc cost? {} {\n\
08351 $self instvar cost_\n\
08352 return $cost_\n\
08353 }\n\
08354 \n\
08355 AbsLanNode instproc rtObject? {} {\n\
08356 }\n\
08357 \n\
08358 AbsLanNode instproc id {} { $self set id_ }\n\
08359 \n\
08360 AbsLanNode instproc node-addr {{addr \"\"}} { \n\
08361 eval $self set address_ $addr\n\
08362 }\n\
08363 \n\
08364 AbsLanNode instproc reset {} {\n\
08365 }\n\
08366 \n\
08367 AbsLanNode instproc is-lan? {} { return 1 }\n\
08368 \n\
08369 AbsLanNode instproc dump-namconfig {} {\n\
08370 $self instvar ns_ bw_ delay_ nodelist_ id_\n\
08371 $ns_ puts-nam-config \\\n\
08372 \"X -t * -n $id_ -r $bw_ -D $delay_ -o left\"\n\
08373 set cnt 0\n\
08374 set LanOrient(0) \"up\"\n\
08375 set LanOrient(1) \"down\"\n\
08376 \n\
08377 foreach n $nodelist_ {\n\
08378 $ns_ puts-nam-config \\\n\
08379 \"L -t * -s $id_ -d [$n id] -o $LanOrient($cnt)\"\n\
08380 set cnt [expr 1 - $cnt]\n\
08381 }\n\
08382 }\n\
08383 \n\
08384 AbsLanNode instproc init-outLink {} { \n\
08385 }\n\
08386 \n\
08387 AbsLanNode instproc start-mcast {} { \n\
08388 }\n\
08389 \n\
08390 AbsLanNode instproc getArbiter {} {\n\
08391 }\n\
08392 \n\
08393 AbsLanNode instproc attach {agent} {\n\
08394 }\n\
08395 \n\
08396 AbsLanNode instproc sp-add-route {args} {\n\
08397 }\n\
08398 \n\
08399 AbsLanNode instproc add-route {args} {\n\
08400 }\n\
08401 \n\
08402 AbsLanNode instproc add-hroute {args} {\n\
08403 }\n\
08404 \n\
08405 AbsLanNode instproc split-addrstr addrstr {\n\
08406 set L [split $addrstr .]\n\
08407 return $L\n\
08408 }\n\
08409 \n\
08410 \n\
08411 \n\
08412 Class AbsLanIface \n\
08413 \n\
08414 AbsLanIface instproc entry {} { $self set entry_ }\n\
08415 \n\
08416 AbsLanIface instproc init {node lan } {\n\
08417 \n\
08418 $self next \n\
08419 \n\
08420 $self instvar node_ lan_ \n\
08421 $self instvar entry_ mac_ ll_ \n\
08422 $self instvar drophead_\n\
08423 \n\
08424 set node_ $node\n\
08425 set lan_ $lan\n\
08426 \n\
08427 set entry_ [new Connector]\n\
08428 set ll_ [new LL]\n\
08429 set mac_ [new Mac]\n\
08430 $mac_ set abstract_ true\n\
08431 \n\
08432 $entry_ target $ll_\n\
08433 \n\
08434 $ll_ mac $mac_\n\
08435 $ll_ up-target [$node entry]\n\
08436 $ll_ down-target $mac_\n\
08437 $ll_ set macDA_ -1\n\
08438 $ll_ set delay_ 0\n\
08439 $ll_ lanrouter [$lan set defRouter_]\n\
08440 $ll_ varp [$lan set varp_]\n\
08441 \n\
08442 $mac_ up-target $ll_\n\
08443 $mac_ down-target [$lan set q_]\n\
08444 $mac_ set delay_ 0\n\
08445 \n\
08446 set ns [Simulator instance]\n\
08447 set drophead_ [new Connector]\n\
08448 $drophead_ target [$ns set nullAgent_]\n\
08449 \n\
08450 $mac_ drop-target $drophead_\n\
08451 $ll_ drop-target $drophead_\n\
08452 }\n\
08453 \n\
08454 AbsLanIface instproc trace {ns f {op \"\"}} {\n\
08455 $self instvar hopT_ rcvT_ enqT_ drpT_ deqT_ \n\
08456 $self instvar iface_ entry_ node_ lan_ drophead_ \n\
08457 $self instvar ll_ mac_ \n\
08458 \n\
08459 set hopT_ [$ns create-trace Hop   $f $node_ $lan_  $op]\n\
08460 set rcvT_ [$ns create-trace Recv  $f $lan_  $node_ $op]\n\
08461 set enqT_ [$ns create-trace Enque $f $node_ $lan_  $op]\n\
08462 set drpT_ [$ns create-trace Drop  $f $node_ $lan_  $op]\n\
08463 \n\
08464 $hopT_ target [$entry_ target]\n\
08465 $entry_ target $hopT_\n\
08466 \n\
08467 $rcvT_ target [$ll_ up-target]\n\
08468 $ll_ up-target $rcvT_\n\
08469 \n\
08470 $enqT_ target [$mac_ down-target]\n\
08471 $mac_ down-target $enqT_\n\
08472 \n\
08473 \n\
08474 $drpT_ target [$drophead_ target]\n\
08475 $drophead_ target $drpT_\n\
08476 }\n\
08477 \n\
08478 AbsLanIface instproc nam-trace {ns f} {\n\
08479 $self instvar hopT_ rcvT_ enqT_  drpT_ deqT_\n\
08480 if [info exists hopT_] {\n\
08481 $hopT_ namattach $f\n\
08482 } else {\n\
08483 $self trace $ns $f \"nam\"\n\
08484 }\n\
08485 $rcvT_ namattach $f\n\
08486 $enqT_ namattach $f\n\
08487 $drpT_ namattach $f\n\
08488 }\n\
08489 \n\
08490 Simulator instproc make-abslan {nodelist bw delay {qlen 50}} {\n\
08491 set lan [new AbsLanNode $self \\\n\
08492 -bw $bw \\\n\
08493 -delay $delay \\\n\
08494 -qlen $qlen]\n\
08495 $lan addNode $nodelist \n\
08496 return $lan\n\
08497 }\n\
08498 \n\
08499 \n\
08500 \n\
08501 \n\
08502 \n\
08503 \n\
08504 \n\
08505 \n\
08506 \n\
08507 Class Timer\n\
08508 \n\
08509 Timer instproc init { ns } {\n\
08510 $self set ns_ $ns\n\
08511 }\n\
08512 \n\
08513 Timer instproc sched delay {\n\
08514 $self instvar ns_\n\
08515 $self instvar id_\n\
08516 $self cancel\n\
08517 set id_ [$ns_ after $delay \"$self timeout\"]\n\
08518 }\n\
08519 \n\
08520 Timer instproc destroy {} {\n\
08521 $self cancel\n\
08522 }\n\
08523 \n\
08524 Timer instproc cancel {} {\n\
08525 $self instvar ns_\n\
08526 $self instvar id_\n\
08527 if [info exists id_] {\n\
08528 $ns_ cancel $id_\n\
08529 unset id_\n\
08530 }\n\
08531 }\n\
08532 \n\
08533 Timer instproc resched delay {\n\
08534 $self sched $delay \n\
08535 }\n\
08536 \n\
08537 Timer instproc expire {} {\n\
08538 $self timeout\n\
08539 }\n\
08540 \n\
08541 \n\
08542 Class Timer/Iface -superclass Timer\n\
08543 \n\
08544 Timer/Iface instproc init { protocol source group oiface sim} {\n\
08545 $self instvar proto_ src_ grp_ oif_\n\
08546 $self next $sim\n\
08547 set proto_ $protocol\n\
08548 set src_ $source\n\
08549 set grp_ $group\n\
08550 set oif_ $oiface\n\
08551 }\n\
08552 \n\
08553 Timer/Iface instproc schedule {} {\n\
08554 $self sched [[$self info class] set timeout]\n\
08555 }\n\
08556 \n\
08557 \n\
08558 Class MultiSim -superclass Simulator\n\
08559 \n\
08560 MultiSim instproc init args {\n\
08561 eval $self next $args\n\
08562 $self multicast on\n\
08563 }\n\
08564 \n\
08565 Simulator instproc multicast args {\n\
08566 $self set multiSim_ 1\n\
08567 Node enable-module Mcast\n\
08568 }\n\
08569 \n\
08570 Simulator instproc multicast? {} {\n\
08571 $self instvar multiSim_\n\
08572 if { ![info exists multiSim_] } {\n\
08573 set multiSim_ 0\n\
08574 }\n\
08575 set multiSim_\n\
08576 }\n\
08577 \n\
08578 Simulator instproc run-mcast {} {\n\
08579 $self instvar Node_\n\
08580 foreach n [array names Node_] {\n\
08581 set node $Node_($n)\n\
08582 $node start-mcast\n\
08583 }\n\
08584 $self next\n\
08585 }\n\
08586 \n\
08587 Simulator instproc clear-mcast {} {\n\
08588 $self instvar Node_\n\
08589 foreach n [array names Node_] {\n\
08590 $Node_($n) stop-mcast\n\
08591 }\n\
08592 }\n\
08593 \n\
08594 Simulator instproc mrtproto { mproto { nodelist \"\" } } {\n\
08595 $self instvar Node_ MrtHandle_\n\
08596 \n\
08597 set MrtHandle_ \"\"\n\
08598 if { $mproto == \"CtrMcast\" } {\n\
08599 set MrtHandle_ [new CtrMcastComp $self]\n\
08600 $MrtHandle_ set ctrrpcomp [new CtrRPComp $self]\n\
08601 }\n\
08602 \n\
08603 if { $mproto == \"BST\" } {\n\
08604 foreach n [array names Node_] {\n\
08605 if ![$Node_($n) is-lan?] {\n\
08606 $Node_($n) instvar multiclassifier_ switch_\n\
08607 set multiclassifier_ [new Classifier/Multicast/Replicator/BST]\n\
08608 $multiclassifier_ set node_ $Node_($n)\n\
08609 $switch_ install 1 $multiclassifier_\n\
08610 }\n\
08611 }\n\
08612 }\n\
08613 \n\
08614 if { $nodelist == \"\" } {\n\
08615 foreach n [array names Node_] {\n\
08616 $self mrtproto-iifs $mproto $Node_($n) \"\"\n\
08617 }\n\
08618 } else {\n\
08619 foreach node $nodelist {\n\
08620 $self mrtproto-iifs $mproto $node \"\"\n\
08621 }\n\
08622 }\n\
08623 $self at 0.0 \"$self run-mcast\"\n\
08624 \n\
08625 return $MrtHandle_\n\
08626 }\n\
08627 Simulator instproc mrtproto-iifs {mproto node iiflist } {\n\
08628 set mh [new $mproto $self $node]\n\
08629 set arbiter [$node getArbiter]\n\
08630 if { $arbiter != \"\" } {\n\
08631 $arbiter addproto $mh $iiflist\n\
08632 }\n\
08633 }\n\
08634 \n\
08635 Node proc allocaddr {} {\n\
08636 set addr [Simulator set McastAddr_]\n\
08637 Simulator set McastAddr_ [expr $addr + 1]\n\
08638 return $addr\n\
08639 }\n\
08640 \n\
08641 Node proc expandaddr {} {\n\
08642 [Simulator instance] set-address-format expanded\n\
08643 puts \"Backward compatibility: Use \\\"set-address-format expanded\\\" instead of \\\"Node expandaddr\\\";\" \n\
08644 }\n\
08645 \n\
08646 Node instproc start-mcast {} {\n\
08647 $self instvar mrtObject_\n\
08648 $mrtObject_ start\n\
08649 }\n\
08650 \n\
08651 Node instproc getArbiter {} {\n\
08652 $self instvar mrtObject_\n\
08653 if [info exists mrtObject_] {\n\
08654 return $mrtObject_\n\
08655 }\n\
08656 return \"\"\n\
08657 }\n\
08658 \n\
08659 Node instproc notify-mcast changes {\n\
08660 $self instvar mrtObject_\n\
08661 if [info exists mrtObject_] {\n\
08662 $mrtObject_ notify $changes\n\
08663 }\n\
08664 }\n\
08665 \n\
08666 Node instproc stop-mcast {} {\n\
08667 $self instvar mrtObject_\n\
08668 $self clear-caches\n\
08669 $mrtObject_ stop\n\
08670 }\n\
08671 \n\
08672 Node instproc clear-caches {} {\n\
08673 $self instvar Agents_  multiclassifier_ replicator_\n\
08674 \n\
08675 $multiclassifier_ clearAll\n\
08676 $multiclassifier_ set nrep_ 0\n\
08677 \n\
08678 foreach var {Agents_ replicator_} {\n\
08679 $self instvar $var\n\
08680 if { [info exists $var] } {\n\
08681 delete $var\n\
08682 unset $var\n\
08683 }\n\
08684 }\n\
08685 }\n\
08686 \n\
08687 Node instproc dump-routes args {\n\
08688 $self instvar mrtObject_\n\
08689 if { [info exists mrtObject_] } {\n\
08690 eval $mrtObject_ dump-routes $args\n\
08691 }\n\
08692 }\n\
08693 \n\
08694 Node instproc check-local { group } {\n\
08695 $self instvar Agents_\n\
08696 if [info exists Agents_($group)] {\n\
08697 return [llength $Agents_($group)]\n\
08698 }\n\
08699 return 0\n\
08700 }\n\
08701 \n\
08702 Node instproc new-group { src group iface code } {\n\
08703 $self instvar mrtObject_\n\
08704 $mrtObject_ upcall $code $src $group $iface\n\
08705 }\n\
08706 \n\
08707 Node instproc join-group { agent group { src \"\" } } {\n\
08708 $self instvar replicator_ Agents_ mrtObject_\n\
08709 set group [expr $group] ;# use expr to convert to decimal\n\
08710 \n\
08711 $mrtObject_ join-group $group $src\n\
08712 \n\
08713 lappend Agents_($group) $agent\n\
08714 if { $src == \"\" } {\n\
08715 set reps [$self getReps \"*\" $group]\n\
08716 } else {\n\
08717 set reps [$self getReps $src $group]\n\
08718 }\n\
08719 foreach rep $reps {\n\
08720 $rep insert $agent\n\
08721 }\n\
08722 }\n\
08723 \n\
08724 Node instproc leave-group { agent group { src \"\" } } {\n\
08725 $self instvar replicator_ Agents_ mrtObject_\n\
08726 set group [expr $group] ;# use expr to get rid of possible leading 0x\n\
08727 if { $src == \"\" } {\n\
08728 set reps [$self getReps \"*\" $group]\n\
08729 } else {\n\
08730 set reps [$self getReps $src $group]\n\
08731 }\n\
08732 foreach rep $reps  {\n\
08733 $rep disable $agent\n\
08734 }\n\
08735 if [info exists Agents_($group)] {\n\
08736 set k [lsearch -exact $Agents_($group) $agent]\n\
08737 set Agents_($group) [lreplace $Agents_($group) $k $k]\n\
08738 \n\
08739 $mrtObject_ leave-group $group $src\n\
08740 } else {\n\
08741 warn \"cannot leave a group without joining it\"\n\
08742 }\n\
08743 }\n\
08744 \n\
08745 Node instproc add-mfc { src group iif oiflist } {\n\
08746 $self instvar multiclassifier_ \\\n\
08747 replicator_ Agents_ \n\
08748 \n\
08749 if [info exists replicator_($src:$group)] {\n\
08750 set r $replicator_($src:$group)\n\
08751 } else {\n\
08752 set r [new Classifier/Replicator/Demuxer]\n\
08753 $r set srcID_ $src\n\
08754 $r set grp_ $group\n\
08755 set replicator_($src:$group) $r\n\
08756 $r set node_ $self\n\
08757 if [info exists Agents_($group)] {\n\
08758 foreach a $Agents_($group) {\n\
08759 $r insert $a\n\
08760 }\n\
08761 }\n\
08762 if [info exists Agents_($src:$group)] {\n\
08763 foreach a $Agents_($src:$group) {\n\
08764 $r insert $a\n\
08765 }\n\
08766 }\n\
08767 $multiclassifier_ add-rep $r $src $group $iif\n\
08768 }\n\
08769 \n\
08770 foreach oif [lsort $oiflist] {\n\
08771 $r insert $oif\n\
08772 }\n\
08773 }\n\
08774 \n\
08775 Node instproc del-mfc { srcID group oiflist } {\n\
08776 $self instvar replicator_ multiclassifier_\n\
08777 if [info exists replicator_($srcID:$group)] {\n\
08778 set r $replicator_($srcID:$group)  \n\
08779 foreach oif $oiflist {\n\
08780 $r disable $oif\n\
08781 }\n\
08782 return 1\n\
08783 } \n\
08784 return 0\n\
08785 }\n\
08786 \n\
08787 Class Classifier/Multicast/Replicator -superclass Classifier/Multicast\n\
08788 \n\
08789 Classifier/Multicast instproc new-group { src group iface code} {\n\
08790 $self instvar node_\n\
08791 $node_ new-group $src $group $iface $code\n\
08792 }\n\
08793 \n\
08794 Classifier/Multicast instproc no-slot slot {\n\
08795 }\n\
08796 \n\
08797 Classifier/Multicast/Replicator instproc init args {\n\
08798 $self next\n\
08799 $self instvar nrep_\n\
08800 set nrep_ 0\n\
08801 }\n\
08802 \n\
08803 Classifier/Multicast/Replicator instproc add-rep { rep src group iif } {\n\
08804 $self instvar nrep_\n\
08805 $self set-hash $src $group $nrep_ $iif\n\
08806 $self install $nrep_ $rep\n\
08807 incr nrep_\n\
08808 }\n\
08809 \n\
08810 Class Classifier/Replicator/Demuxer -superclass Classifier/Replicator\n\
08811 Classifier/Replicator/Demuxer set ignore_ 0\n\
08812 Classifier/Replicator/Demuxer instproc init args {\n\
08813 eval $self next $args\n\
08814 $self instvar nslot_ nactive_\n\
08815 set nactive_ 0\n\
08816 }\n\
08817 \n\
08818 Classifier/Replicator/Demuxer instproc is-active {} {\n\
08819 $self instvar nactive_\n\
08820 expr $nactive_ > 0\n\
08821 }\n\
08822 \n\
08823 Classifier/Replicator/Demuxer instproc insert target {\n\
08824 $self instvar nactive_ active_ \n\
08825 \n\
08826 if ![info exists active_($target)] {\n\
08827 set active_($target) -1\n\
08828 }\n\
08829 if {$active_($target) < 0} {\n\
08830 $self enable $target\n\
08831 }\n\
08832 }\n\
08833 \n\
08834 Classifier/Replicator/Demuxer instproc dump-oifs {} {\n\
08835 set oifs \"\"\n\
08836 if [$self is-active] {\n\
08837 $self instvar active_\n\
08838 foreach target [array names active_] {\n\
08839 if { $active_($target) >= 0 } {\n\
08840 lappend oifs [$self slot $active_($target)]\n\
08841 }\n\
08842 }\n\
08843 }\n\
08844 return [lsort $oifs]\n\
08845 }\n\
08846 \n\
08847 Classifier/Replicator/Demuxer instproc disable target {\n\
08848 $self instvar nactive_ active_\n\
08849 if {[info exists active_($target)] && $active_($target) >= 0} {\n\
08850 $self clear $active_($target)\n\
08851 set active_($target) -1\n\
08852 incr nactive_ -1\n\
08853 }\n\
08854 }\n\
08855 \n\
08856 Classifier/Replicator/Demuxer instproc enable target {\n\
08857 $self instvar nactive_ active_ ignore_\n\
08858 if {$active_($target) < 0} {\n\
08859 set active_($target) [$self installNext $target]\n\
08860 incr nactive_\n\
08861 set ignore_ 0\n\
08862 }\n\
08863 }\n\
08864 \n\
08865 Classifier/Replicator/Demuxer instproc exists target {\n\
08866 $self instvar active_\n\
08867 info exists active_($target)\n\
08868 }\n\
08869 \n\
08870 Classifier/Replicator/Demuxer instproc is-active-target target {\n\
08871 $self instvar active_\n\
08872 if { [info exists active_($target)] && $active_($target) >= 0 } {\n\
08873 return 1\n\
08874 } else {\n\
08875 return 0\n\
08876 }\n\
08877 }\n\
08878 \n\
08879 Classifier/Replicator/Demuxer instproc drop { src dst {iface -1} } {\n\
08880 $self instvar node_\n\
08881 [$node_ getArbiter] drop $self $src $dst $iface\n\
08882 }\n\
08883 \n\
08884 Node instproc change-iface { src dst oldiface newiface} {\n\
08885 $self instvar multiclassifier_\n\
08886 $multiclassifier_ change-iface $src $dst $oldiface $newiface\n\
08887 }\n\
08888 \n\
08889 Node instproc lookup-iface { src dst } {\n\
08890 $self instvar multiclassifier_\n\
08891 $multiclassifier_ lookup-iface $src $dst\n\
08892 }\n\
08893 \n\
08894 Classifier/Replicator/Demuxer instproc reset {} {\n\
08895 $self instvar nactive_ active_\n\
08896 foreach { target slot } [array get active_] {\n\
08897 $self clear $slot\n\
08898 }\n\
08899 set nactive_ 0\n\
08900 unset active_\n\
08901 }\n\
08902 \n\
08903 Agent/Mcast/Control instproc init { protocol } {\n\
08904 $self next\n\
08905 $self instvar proto_\n\
08906 set proto_ $protocol\n\
08907 }\n\
08908 \n\
08909 Agent/Mcast/Control array set messages {}\n\
08910 Agent/Mcast/Control set mcounter 0\n\
08911 \n\
08912 Agent/Mcast/Control instproc send {type from src group args} {\n\
08913 Agent/Mcast/Control instvar mcounter messages\n\
08914 set messages($mcounter) [concat [list $from $src $group] $args]\n\
08915 $self cmd send $type $mcounter\n\
08916 incr mcounter\n\
08917 }\n\
08918 \n\
08919 Agent/Mcast/Control instproc recv {type iface m} {\n\
08920 Agent/Mcast/Control instvar messages\n\
08921 eval $self recv2 $type $iface $messages($m)\n\
08922 }\n\
08923 \n\
08924 Agent/Mcast/Control instproc recv2 {type iface from src group args} {\n\
08925 $self instvar proto_\n\
08926 eval $proto_ recv-$type $from $src $group $iface $args\n\
08927 }\n\
08928 \n\
08929 Node instproc rpf-nbr src {\n\
08930 $self instvar ns_ id_\n\
08931 if [catch \"$src id\" srcID] {  \n\
08932 set srcID $src\n\
08933 }\n\
08934 $ns_ get-node-by-id [[$ns_ get-routelogic] lookup $id_ $srcID]\n\
08935 }\n\
08936 \n\
08937 LanNode instproc rpf-nbr src {\n\
08938 $self instvar ns_ id_\n\
08939 if [catch \"$src id\" srcID] {  \n\
08940 set srcID $src\n\
08941 }\n\
08942 $ns_ get-node-by-id [[$ns_ get-routelogic] lookup $id_ $srcID]\n\
08943 }\n\
08944 \n\
08945 Node instproc getReps { src group } {\n\
08946 $self instvar replicator_\n\
08947 set reps \"\"\n\
08948 foreach key [array names replicator_ \"$src:$group\"] { \n\
08949 lappend reps $replicator_($key)\n\
08950 }\n\
08951 return [lsort $reps]\n\
08952 }\n\
08953 \n\
08954 Node instproc getReps-raw { src group } {\n\
08955 $self array get replicator_ \"$src:$group\"\n\
08956 }\n\
08957 \n\
08958 Node instproc clearReps { src group } {\n\
08959 $self instvar multiclassifier_\n\
08960 foreach {key rep} [$self getReps-raw $src $group] {\n\
08961 $rep reset\n\
08962 delete $rep\n\
08963 \n\
08964 foreach {slot val} [$multiclassifier_ adjacents] {\n\
08965 if { $val == $rep } {\n\
08966 $multiclassifier_ clear $slot\n\
08967 }\n\
08968 }\n\
08969 \n\
08970 $self unset replicator_($key)\n\
08971 }\n\
08972 }\n\
08973 \n\
08974 Node instproc add-oif {head link} {\n\
08975 $self instvar outLink_\n\
08976 set outLink_($head) $link\n\
08977 }\n\
08978 \n\
08979 Node instproc add-iif {iflbl link} {\n\
08980 $self set inLink_($iflbl) $link\n\
08981 }\n\
08982 \n\
08983 Node instproc get-all-oifs {} {\n\
08984 $self instvar outLink_\n\
08985 return [lsort [array names outLink_]]\n\
08986 }\n\
08987 \n\
08988 Node instproc get-all-iifs {} {\n\
08989 $self instvar inLink_\n\
08990 return [array names inLink_]\n\
08991 }\n\
08992 \n\
08993 Node instproc iif2oif ifid {\n\
08994 $self instvar ns_\n\
08995 set link [$self iif2link $ifid]\n\
08996 set outlink [$ns_ link $self [$link src]]\n\
08997 return [$self link2oif $outlink]\n\
08998 }\n\
08999 \n\
09000 Node instproc iif2link ifid {\n\
09001 $self set inLink_($ifid)\n\
09002 }\n\
09003 \n\
09004 Node instproc link2iif link {\n\
09005 return [[$link set iif_] label]\n\
09006 }\n\
09007 \n\
09008 Node instproc link2oif link {\n\
09009 $link head\n\
09010 }\n\
09011 \n\
09012 Node instproc oif2link oif {\n\
09013 $oif set link_\n\
09014 }\n\
09015 \n\
09016 Node instproc from-node-iface { node } {\n\
09017 $self instvar ns_\n\
09018 catch {\n\
09019 set node [$ns_ get-node-by-id $node]\n\
09020 }\n\
09021 set rpfnbr [$self rpf-nbr $node]\n\
09022 set rpflink [$ns_ link $rpfnbr $self]\n\
09023 if { $rpflink != \"\" } {\n\
09024 return [$rpflink if-label?]\n\
09025 }\n\
09026 return \"?\" ;#unknown iface\n\
09027 }\n\
09028 \n\
09029 Vlink instproc if-label? {} {\n\
09030 $self instvar iif_\n\
09031 $iif_ label\n\
09032 }\n\
09033 \n\
09034 \n\
09035 Simulator instproc src_rting args {\n\
09036 $self set srcRt_ 1\n\
09037 add-packet-header Src_rt\n\
09038 Node enable-module Source\n\
09039 }\n\
09040 \n\
09041 Simulator instproc src_rting? {} {\n\
09042 $self instvar srcRt_\n\
09043 if { ![info exists srcRt_] } {\n\
09044 set srcRt_ 0\n\
09045 }\n\
09046 set srcRt_\n\
09047 }  \n\
09048 Class McastProtocol\n\
09049 \n\
09050 McastProtocol instproc init {sim node} {\n\
09051 $self next\n\
09052 $self instvar ns_ node_ status_ type_ id_\n\
09053 set ns_   $sim\n\
09054 set node_ $node\n\
09055 set status_ \"down\"\n\
09056 set type_   [$self info class]\n\
09057 set id_ [$node id]\n\
09058 \n\
09059 $ns_ maybeEnableTraceAll $self $node_\n\
09060 }\n\
09061 \n\
09062 McastProtocol instproc getType {} { $self set type_ }\n\
09063 \n\
09064 McastProtocol instproc start {}     { $self set status_ \"up\"   }\n\
09065 McastProtocol instproc stop {}      { $self set status_ \"down\" }\n\
09066 McastProtocol instproc getStatus {} { $self set status_    }\n\
09067 \n\
09068 McastProtocol instproc upcall {code args} {\n\
09069 eval $self handle-$code $args\n\
09070 }\n\
09071 \n\
09072 McastProtocol instproc handle-wrong-iif { srcID group iface } {\n\
09073 return 0\n\
09074 }\n\
09075 \n\
09076 McastProtocol instproc handle-cache-miss { srcID group iface } {\n\
09077 return 0\n\
09078 }\n\
09079 \n\
09080 McastProtocol instproc annotate args {\n\
09081 $self instvar dynT_ node_ ns_\n\
09082 set s \"[$ns_ now] [$node_ id] $args\" ;#nam wants uinique first arg???\n\
09083 if [info exists dynT_] {\n\
09084 foreach tr $dynT_ {\n\
09085 $tr annotate $s\n\
09086 }\n\
09087 }\n\
09088 }\n\
09089 \n\
09090 McastProtocol instproc join-group arg   { \n\
09091 $self annotate $proc $arg \n\
09092 }\n\
09093 McastProtocol instproc leave-group arg  { \n\
09094 $self annotate $proc $arg\n\
09095 }\n\
09096 \n\
09097 McastProtocol instproc trace { f src {op \"\"} } {\n\
09098 $self instvar ns_ dynT_\n\
09099 if {$op == \"nam\" && [info exists dynT_] > 0} {\n\
09100 foreach tr $dynT_ {\n\
09101 $tr namattach $f\n\
09102 }\n\
09103 } else {\n\
09104 lappend dynT_ [$ns_ create-trace Generic $f $src $src $op]\n\
09105 }\n\
09106 }\n\
09107 McastProtocol instproc notify { dummy } {\n\
09108 $self instvar ns_ node_ PruneTimer_\n\
09109 \n\
09110 foreach r [$node_ getReps \"*\" \"*\"] {\n\
09111 set src_id [$r set srcID_]\n\
09112 set sources($src_id) 1\n\
09113 }\n\
09114 set sourceIDs [array names sources]\n\
09115 foreach src_id $sourceIDs {\n\
09116 set src [$ns_ get-node-by-id $src_id]\n\
09117 if {$src != $node_} {\n\
09118 set upstream [$node_ rpf-nbr $src]\n\
09119 if { $upstream != \"\"} {\n\
09120 set inlink [$ns_ link $upstream $node_]\n\
09121 set newiif [$node_ link2iif $inlink]\n\
09122 set reps [$node_ getReps $src_id \"*\"]\n\
09123 foreach r $reps {\n\
09124 set oldiif [$node_ lookup-iface $src_id [$r set grp_]]\n\
09125 if { $oldiif != $newiif } {\n\
09126 $node_ change-iface $src_id [$r set grp_] $oldiif $newiif\n\
09127 }\n\
09128 }\n\
09129 }\n\
09130 }\n\
09131 set oiflist \"\"\n\
09132 foreach nbr [$node_ neighbors] {\n\
09133 set nbr_id [$nbr id]\n\
09134 set nh [$nbr rpf-nbr $src] \n\
09135 if { $nh != $node_ } {\n\
09136 continue\n\
09137 }\n\
09138 set oif [$node_ link2oif [$ns_ link $node_ $nbr]]\n\
09139 set oifs($oif) 1\n\
09140 }\n\
09141 set oiflist [array names oifs]\n\
09142 \n\
09143 set reps [$node_ getReps $src_id \"*\"]\n\
09144 foreach r $reps {\n\
09145 set grp [$r set grp_]\n\
09146 set oldoifs [$r dump-oifs]\n\
09147 set newoifs $oiflist\n\
09148 foreach old $oldoifs {\n\
09149 if [catch \"$node_ oif2link $old\" ] {\n\
09150 continue\n\
09151 }\n\
09152 set idx [lsearch $newoifs $old]\n\
09153 if { $idx < 0} {\n\
09154 $r disable $old\n\
09155 if [info exists PruneTimer_($src_id:$grp:$old)] {\n\
09156 delete $PruneTimer_($src_id:$grp:$old)\n\
09157 unset PruneTimer_($src_id:$grp:$old)\n\
09158 }\n\
09159 } else {\n\
09160 set newoifs [lreplace $newoifs $idx $idx]\n\
09161 }\n\
09162 }\n\
09163 foreach new $newoifs {\n\
09164 foreach r $reps {\n\
09165 $r insert $new\n\
09166 }\n\
09167 }\n\
09168 }\n\
09169 }\n\
09170 }\n\
09171 \n\
09172 McastProtocol instproc dump-routes {chan {grp \"\"} {src \"\"}} {\n\
09173 $self instvar ns_ node_\n\
09174 if { $grp == \"\" } {\n\
09175 array set reps [$node_ getReps-raw * *]\n\
09176 } elseif { $src == \"\" } {\n\
09177 array set reps [$node_ getReps-raw * $grp]  ;# actually, more than *,g\n\
09178 } else {\n\
09179 array set reps [$node_ getReps-raw $src $grp]\n\
09180 }\n\
09181 puts $chan [concat \"Node:\\t${node_}([$node_ id])\\tat t =\"   \\\n\
09182 [format \"%4.2f\" [$ns_ now]]]\n\
09183 puts $chan \"\\trepTag\\tActive\\t\\tsrc\\tgroup\\tiifNode\\t\\tdest_nodes\"\n\
09184 foreach ent [lsort [array names reps]] {\n\
09185 set sg [split $ent \":\"]\n\
09186 if { [$reps($ent) is-active] } {\n\
09187 set active Y\n\
09188 } else {\n\
09189 set active N\n\
09190 }\n\
09191 set dest \"\"\n\
09192 foreach oif [$reps($ent) dump-oifs] {\n\
09193 if ![catch { set nbr [[$node_ oif2link $oif] dst] } ] {\n\
09194 set nbrid [$nbr id]\n\
09195 if [$nbr is-lan?] {\n\
09196 set nbrid ${nbrid}(L)\n\
09197 }\n\
09198 lappend dest $nbrid\n\
09199 }\n\
09200 }\n\
09201 set s [lindex $sg 0]\n\
09202 set g [lindex $sg 1]\n\
09203 set iif [$node_ lookup-iface $s $g]\n\
09204 \n\
09205 set iif_node_id $iif\n\
09206 catch {\n\
09207 set iif_node [[$node_ iif2link $iif] src]\n\
09208 if [$iif_node is-lan?] {\n\
09209 set iif_node_id [$iif_node id](L)\n\
09210 } else {\n\
09211 set iif_node_id [$iif_node id]\n\
09212 }\n\
09213 }\n\
09214 \n\
09215 puts $chan [format \"\\t%5s\\t  %s\\t\\t%d\\t0x%x\\t%s\\t\\t%s\"    \\\n\
09216 $reps($ent) $active $s $g $iif_node_id $dest]\n\
09217 }\n\
09218 }\n\
09219 \n\
09220 \n\
09221 Class mrtObject\n\
09222 \n\
09223 mrtObject set mask-wkgroups 0xfff0\n\
09224 mrtObject set wkgroups(Allocd)  [mrtObject set mask-wkgroups]\n\
09225 \n\
09226 mrtObject proc registerWellKnownGroups name {\n\
09227 set newGroup [mrtObject set wkgroups(Allocd)]\n\
09228 mrtObject set wkgroups(Allocd) [expr $newGroup + 1]\n\
09229 mrtObject set wkgroups($name)  $newGroup\n\
09230 }\n\
09231 \n\
09232 mrtObject proc getWellKnownGroup name {\n\
09233 assert \"\\\"$name\\\" != \\\"Allocd\\\"\"\n\
09234 mrtObject set wkgroups($name)\n\
09235 }\n\
09236 \n\
09237 mrtObject registerWellKnownGroups ALL_ROUTERS\n\
09238 mrtObject registerWellKnownGroups ALL_PIM_ROUTERS\n\
09239 \n\
09240 mrtObject proc expandaddr {} {\n\
09241 mrtObject set mask-wkgroups 0x7fffffff\n\
09242 \n\
09243 foreach {name group} [mrtObject array get wkgroups] {\n\
09244 mrtObject set wkgroups($name) [expr $group | 0x7fffffff]\n\
09245 }\n\
09246 }\n\
09247 \n\
09248 mrtObject instproc init { node } {\n\
09249 $self next\n\
09250 $self set node_      $node\n\
09251 }\n\
09252 \n\
09253 mrtObject instproc addproto { proto { iiflist \"\" } } {\n\
09254 $self instvar node_ protocols_\n\
09255 if { $iiflist == \"\" } {\n\
09256 set iiflist [$node_ get-all-iifs]\n\
09257 lappend iiflist -1 ;#for local packets\n\
09258 }\n\
09259 foreach iif $iiflist {\n\
09260 set protocols_($iif) $proto\n\
09261 }\n\
09262 }\n\
09263 \n\
09264 mrtObject instproc getType { protocolType } {\n\
09265 $self instvar protocols_\n\
09266 foreach iif [array names protocols_] {\n\
09267 if { [$protocols_($iif) getType] == $protocolType } {\n\
09268 return $protocols_($iif)\n\
09269 }\n\
09270 }\n\
09271 return \"\"\n\
09272 }\n\
09273 \n\
09274 mrtObject instproc all-mprotos {op args} {\n\
09275 $self instvar protocols_\n\
09276 foreach iif [array names protocols_] {\n\
09277 set p $protocols_($iif)\n\
09278 if ![info exists protos($p)] {\n\
09279 set protos($p) 1\n\
09280 eval $p $op $args\n\
09281 }\n\
09282 }\n\
09283 }\n\
09284 \n\
09285 mrtObject instproc start {} { $self all-mprotos start   }\n\
09286 mrtObject instproc stop {}  { $self all-mprotos stop    }\n\
09287 mrtObject instproc notify dummy { $self all-mprotos notify $dummy }\n\
09288 mrtObject instproc dump-routes args {\n\
09289 $self all-mprotos dump-routes $args\n\
09290 }\n\
09291 \n\
09292 mrtObject instproc join-group { grp src } {\n\
09293 eval $self all-mprotos join-group $grp $src\n\
09294 }\n\
09295 \n\
09296 mrtObject instproc leave-group { grp src } {\n\
09297 eval $self all-mprotos leave-group $grp $src\n\
09298 }\n\
09299 \n\
09300 mrtObject instproc upcall { code source group iface } {\n\
09301 set wkgroup [expr [$class set mask-wkgroups]]\n\
09302 if { [expr ( $group & $wkgroup ) == $wkgroup] } {\n\
09303 $self instvar node_\n\
09304 $node_ add-mfc $source $group -1 {}\n\
09305 return 1\n\
09306 } else {\n\
09307 $self instvar protocols_\n\
09308 $protocols_($iface) upcall $code $source $group $iface\n\
09309 }\n\
09310 }\n\
09311 \n\
09312 mrtObject instproc drop { replicator src dst {iface -1} } {\n\
09313 $self instvar protocols_\n\
09314 $protocols_($iface) drop $replicator $src $dst $iface\n\
09315 }\n\
09316 \n\
09317 Class DM -superclass McastProtocol\n\
09318 \n\
09319 DM set PruneTimeout  0.5\n\
09320 DM set CacheMissMode pimdm ;#or dvmrp (lowercase)\n\
09321 \n\
09322 DM instproc init { sim node } {\n\
09323 $self instvar mctrl_\n\
09324 set mctrl_ [new Agent/Mcast/Control $self]\n\
09325 $node attach $mctrl_\n\
09326 Timer/Iface/Prune set timeout [[$self info class] set PruneTimeout]\n\
09327 $self next $sim $node\n\
09328 }\n\
09329 \n\
09330 DM instproc join-group  { group } {\n\
09331 $self instvar node_\n\
09332 $self next $group\n\
09333 set listOfReps [$node_ getReps * $group]\n\
09334 foreach r $listOfReps {\n\
09335 if ![$r is-active] {\n\
09336 $self send-ctrl \"graft\" [$r set srcID_] $group\n\
09337 set nbr [$node_ rpf-nbr [$r set srcID_]]\n\
09338 set nbrs($nbr) 1\n\
09339 }\n\
09340 }\n\
09341 foreach nbr [array names nbrs] {\n\
09342 if [$nbr is-lan?] {\n\
09343 $nbr instvar receivers_\n\
09344 if [info exists receivers_($group)] {\n\
09345 incr receivers_($group)\n\
09346 } else {\n\
09347 set receivers_($group) 1\n\
09348 }\n\
09349 }\n\
09350 }\n\
09351 }\n\
09352 \n\
09353 DM instproc leave-group { group } {\n\
09354 $self next $group\n\
09355 \n\
09356 $self instvar node_\n\
09357 set listOfReps [$node_ getReps * $group]\n\
09358 foreach r $listOfReps {\n\
09359 set nbr [$node_ rpf-nbr [$r set srcID_]]\n\
09360 set nbrs($nbr) 1\n\
09361 }\n\
09362 foreach nbr [array names nbrs] {\n\
09363 if [$nbr is-lan?] {\n\
09364 $nbr instvar receivers_\n\
09365 if { [info exists receivers_($group)] && \\\n\
09366 $receivers_($group) > 0 } {\n\
09367 incr receivers_($group) -1\n\
09368 }\n\
09369 }\n\
09370 }\n\
09371 }\n\
09372 \n\
09373 DM instproc handle-wrong-iif { srcID group iface } {\n\
09374 $self instvar node_ ns_\n\
09375 set inlink  [$node_ iif2link $iface]\n\
09376 set from [$inlink src]\n\
09377 $self send-ctrl \"prune\" $srcID $group [$from id]\n\
09378 return 0 ;# don't call this method two times\n\
09379 }\n\
09380 \n\
09381 DM instproc handle-cache-miss  { srcID group iface } {\n\
09382 DM instvar CacheMissMode\n\
09383 $self handle-cache-miss-$CacheMissMode $srcID $group $iface\n\
09384 return 1 ;#call again\n\
09385 }\n\
09386 \n\
09387 DM instproc handle-cache-miss-pimdm { srcID group iface } {\n\
09388 $self instvar node_ ns_\n\
09389 \n\
09390 if { $iface >= 0 } {\n\
09391 set rpf_nbr [$node_ rpf-nbr $srcID]\n\
09392 set inlink  [$node_ iif2link $iface]\n\
09393 set rpflink [$ns_ link $rpf_nbr $node_]\n\
09394 \n\
09395 if { $inlink != $rpflink } {\n\
09396 set from [$inlink src]\n\
09397 $self send-ctrl \"prune\" $srcID $group [$from id]\n\
09398 return 0; #drop this packet\n\
09399 }\n\
09400 set rpfoif [$node_ iif2oif $iface]\n\
09401 } else {\n\
09402 set rpfoif \"\"\n\
09403 }\n\
09404 set alloifs [$node_ get-all-oifs]\n\
09405 set oiflist \"\"\n\
09406 foreach oif $alloifs {\n\
09407 if {$oif == $rpfoif} {\n\
09408 continue ;#exclude incoming iface\n\
09409 }\n\
09410 set dst [[$node_ oif2link $oif] dst]\n\
09411 if { [$dst is-lan?] && [$dst rpf-nbr $srcID] != $node_  } {\n\
09412 continue \n\
09413 }\n\
09414 lappend oiflist $oif\n\
09415 }\n\
09416 \n\
09417 $node_ add-mfc $srcID $group $iface $oiflist\n\
09418 }\n\
09419 \n\
09420 DM instproc handle-cache-miss-dvmrp { srcID group iface } {\n\
09421 $self instvar node_ ns_\n\
09422 \n\
09423 set oiflist \"\"\n\
09424 foreach nbr [$node_ neighbors] {\n\
09425 set rpfnbr [$nbr rpf-nbr $srcID]\n\
09426 if { $rpfnbr == $node_ } {\n\
09427 set link [$ns_ link $node_ $nbr]\n\
09428 lappend oiflist [$node_ link2oif $link]\n\
09429 }\n\
09430 \n\
09431 }\n\
09432 $node_ add-mfc $srcID $group $iface $oiflist\n\
09433 }\n\
09434 \n\
09435 DM instproc drop { replicator src dst iface} {\n\
09436 $self instvar node_ ns_\n\
09437 \n\
09438 if { $iface < 0 } {\n\
09439 $replicator set ignore_ 1\n\
09440 } else {\n\
09441 set from [[$node_ iif2link $iface] src]\n\
09442 if [$from is-lan?] {\n\
09443 $self send-ctrl \"prune\" $src $dst\n\
09444 } else {\n\
09445 $self send-ctrl \"prune\" $src $dst [$from id]\n\
09446 }\n\
09447 }\n\
09448 }\n\
09449 \n\
09450 DM instproc recv-prune { from src group iface} {\n\
09451 $self instvar node_ PruneTimer_ ns_\n\
09452 \n\
09453 set r [$node_ getReps $src $group]\n\
09454 if { $r == \"\" } { \n\
09455 return 0\n\
09456 }\n\
09457 set id [$node_ id]\n\
09458 set tmpoif [$node_ iif2oif $iface]\n\
09459 \n\
09460 if { [$r is-active-target $tmpoif] } {\n\
09461 $r disable $tmpoif\n\
09462 if ![$r is-active] {\n\
09463 if { $src != $id } {\n\
09464 $self send-ctrl prune $src $group\n\
09465 }\n\
09466 }\n\
09467 }\n\
09468 if ![info exists PruneTimer_($src:$group:$tmpoif)] {\n\
09469 set PruneTimer_($src:$group:$tmpoif) \\\n\
09470 [new Timer/Iface/Prune $self $src $group $tmpoif $ns_]\n\
09471 }\n\
09472 $PruneTimer_($src:$group:$tmpoif) schedule\n\
09473 \n\
09474 }\n\
09475 \n\
09476 DM instproc recv-graft { from src group iface} {\n\
09477 $self instvar node_ PruneTimer_ ns_\n\
09478 \n\
09479 set id [$node_ id]\n\
09480 set r [$node_ getReps $src $group]\n\
09481 if { $r == \"\" } {\n\
09482 if { $id == $src } {\n\
09483 set iif \"?\"\n\
09484 } else {\n\
09485 set rpfnbr [$node_ rpf_nbr $src]\n\
09486 set rpflnk [$ns_ link $src $id]\n\
09487 set iif [$node_ link2iif $rpflnk]\n\
09488 }\n\
09489 $node_ add-mfc $src $group $iif \"\"\n\
09490 set r [$node_ getReps $src $group]\n\
09491 } \n\
09492 if { ![$r is-active] && $src != $id } {\n\
09493 $self send-ctrl graft $src $group\n\
09494 }\n\
09495 set tmpoif [$node_ iif2oif $iface]\n\
09496 $r enable $tmpoif\n\
09497 if [info exists PruneTimer_($src:$group:$tmpoif)] {\n\
09498 delete $PruneTimer_($src:$group:$tmpoif)\n\
09499 unset  PruneTimer_($src:$group:$tmpoif)\n\
09500 }\n\
09501 }\n\
09502 \n\
09503 DM instproc send-ctrl { which src group { to \"\" } } {\n\
09504 $self instvar mctrl_ ns_ node_\n\
09505 if { $to != \"\" } {\n\
09506 set n [$ns_ get-node-by-id $to]\n\
09507 if [$n is-lan?] return\n\
09508 set toid $to\n\
09509 } else {\n\
09510 set toid $src\n\
09511 }\n\
09512 set nbr [$node_ rpf-nbr $toid]\n\
09513 if [$nbr is-lan?] {\n\
09514 $nbr instvar receivers_\n\
09515 if { [info exists receivers_($group)] && \\\n\
09516 $receivers_($group) > 0 } return \n\
09517 set nbr [$nbr rpf-nbr $toid]\n\
09518 }\n\
09519 $ns_ simplex-connect $mctrl_ \\\n\
09520 [[[$nbr getArbiter] getType [$self info class]] set mctrl_]\n\
09521 if { $which == \"prune\" } {\n\
09522 $mctrl_ set class_ 30\n\
09523 } else {\n\
09524 $mctrl_ set class_ 31\n\
09525 }        \n\
09526 $mctrl_ send $which [$node_ id] $src $group\n\
09527 }\n\
09528 \n\
09529 DM instproc timeoutPrune { oif src grp } {\n\
09530 $self instvar node_ PruneTimer_ ns_\n\
09531 set r [$node_ getReps $src $grp]\n\
09532 \n\
09533 $r insert $oif\n\
09534 if [info exists PruneTimer_($src:$grp:$oif)] {\n\
09535 delete $PruneTimer_($src:$grp:$oif)\n\
09536 unset PruneTimer_($src:$grp:$oif)\n\
09537 }\n\
09538 return\n\
09539 }\n\
09540 \n\
09541 \n\
09542 Class Timer/Iface/Prune -superclass Timer/Iface\n\
09543 Timer/Iface/Prune set timeout 0.5\n\
09544 \n\
09545 Timer/Iface/Prune instproc timeout {} {\n\
09546 $self instvar proto_ src_ grp_ oif_\n\
09547 $proto_ timeoutPrune $oif_ $src_ $grp_\n\
09548 }\n\
09549 \n\
09550 \n\
09551 \n\
09552 Class CtrMcast -superclass McastProtocol\n\
09553 \n\
09554 CtrMcast instproc init { sim node } {\n\
09555 $self next $sim $node\n\
09556 $self instvar ns_ node_\n\
09557 $self instvar agent_ defaultTree_ decapagent_\n\
09558 $self instvar c_rp_ c_bsr_ priority_\n\
09559 \n\
09560 set agent_ [$ns_ set MrtHandle_]\n\
09561 \n\
09562 set defaultTree_ \"RPT\"\n\
09563 \n\
09564 set decapagent_ [new Agent/Decapsulator]\n\
09565 $ns_ attach-agent $node_ $decapagent_\n\
09566 \n\
09567 set c_rp_      1\n\
09568 set c_bsr_     1\n\
09569 set priority_  0\n\
09570 }\n\
09571 \n\
09572 CtrMcast instproc join-group  { group } {\n\
09573 $self next $group\n\
09574 $self instvar node_ ns_ agent_\n\
09575 $self instvar defaultTree_\n\
09576 \n\
09577 if { [$agent_ treetype? $group] == \"\" } {\n\
09578 $agent_ treetype $group $defaultTree_\n\
09579 $agent_ add-new-group $group\n\
09580 }\n\
09581 \n\
09582 $agent_ add-new-member $group $node_\n\
09583 \n\
09584 foreach src [$agent_ sources? $group] {\n\
09585 $agent_ compute-branch $src $group $node_\n\
09586 }\n\
09587 }\n\
09588 \n\
09589 CtrMcast instproc leave-group  { group } {\n\
09590 $self next $group\n\
09591 $self instvar node_ ns_ agent_ defaultTree_\n\
09592 \n\
09593 $agent_ remove-member $group $node_\n\
09594 foreach src [$agent_ sources? $group] {\n\
09595 $agent_ prune-branch $src $group $node_\n\
09596 }\n\
09597 }\n\
09598 \n\
09599 CtrMcast instproc handle-cache-miss { srcID group iface } {\n\
09600 $self instvar ns_ agent_ node_\n\
09601 $self instvar defaultTree_\n\
09602 \n\
09603 if { [$agent_ treetype? $group] == \"\" } {\n\
09604 $agent_ treetype $group $defaultTree_\n\
09605 }\n\
09606 if { [$node_ id] == $srcID } {\n\
09607 set RP [$self get_rp $group]\n\
09608 if {[$agent_ treetype? $group] == \"RPT\" && $srcID != [$RP id]} {\n\
09609 set encapagent [new Agent/Encapsulator]\n\
09610 $ns_ attach-agent $node_ $encapagent\n\
09611 \n\
09612 set ctrmcast [[$RP getArbiter] getType \"CtrMcast\"]\n\
09613 $ns_ connect $encapagent [$ctrmcast set decapagent_]\n\
09614 \n\
09615 $node_ add-mfc-reg $srcID $group -1 $encapagent\n\
09616 }\n\
09617 \n\
09618 if [$agent_ new-source? $group $node_] {\n\
09619 $agent_ compute-tree $node_ $group\n\
09620 }\n\
09621 } elseif [SessionSim set MixMode_] {\n\
09622 set srcnode [$ns_ get-node-by-id $srcID]\n\
09623 if [$agent_ new-source? $group $srcnode] {\n\
09624 $agent_ compute-tree $srcnode $group\n\
09625 }\n\
09626 }\n\
09627 return 1 ;#call again\n\
09628 }\n\
09629 \n\
09630 CtrMcast instproc drop  { replicator src group iface } {\n\
09631 }\n\
09632 \n\
09633 CtrMcast instproc handle-wrong-iif { srcID group iface } {\n\
09634 warn \"$self: $proc for <S: $srcID, G: $group, if: $iface>?\"\n\
09635 return 0 ;#call once\n\
09636 }\n\
09637 \n\
09638 CtrMcast instproc notify { dummy } {\n\
09639 }\n\
09640 CtrMcast instproc get_rp group {\n\
09641 $self instvar rpset_ agent_\n\
09642 \n\
09643 if ![info exists rpset_] {\n\
09644 [$agent_ set ctrrpcomp] compute-rpset\n\
09645 assert [info exists rpset_]\n\
09646 }\n\
09647 set returnrp -1\n\
09648 set hashval -1\n\
09649 foreach rp $rpset_ {\n\
09650 if {[$self hash $rp $group] > $hashval} {\n\
09651 set hashval [$self hash $rp $group]\n\
09652 set returnrp $rp\n\
09653 }\n\
09654 }\n\
09655 set returnrp        ;# return\n\
09656 }\n\
09657 \n\
09658 CtrMcast instproc hash {rp group} {\n\
09659 $rp id\n\
09660 }\n\
09661 \n\
09662 CtrMcast instproc set-rpset args {\n\
09663 eval $self set rpset_ \"$args\"\n\
09664 }\n\
09665 \n\
09666 CtrMcast instproc get_bsr {} {\n\
09667 warn \"$self: CtrMcast doesn't require a BSR\"\n\
09668 }\n\
09669 \n\
09670 CtrMcast instproc set_c_bsr { prior } {\n\
09671 $self instvar c_bsr_ priority_\n\
09672 set c_bsr_ 1\n\
09673 set priority_ $prior\n\
09674 }\n\
09675 \n\
09676 CtrMcast instproc set_c_rp {} {\n\
09677 $self instvar c_rp_\n\
09678 set c_rp_ 1\n\
09679 }\n\
09680 \n\
09681 CtrMcast instproc unset_c_rp {} {\n\
09682 $self instvar c_rp_\n\
09683 set c_rp_ 0\n\
09684 }\n\
09685 \n\
09686 \n\
09687 Node instproc add-mfc-reg { src group iif oiflist } {\n\
09688 $self instvar multiclassifier_ Regreplicator_\n\
09689 \n\
09690 \n\
09691 if [info exists Regreplicator_($group)] {\n\
09692 foreach oif $oiflist {\n\
09693 $Regreplicator_($group) insert $oif\n\
09694 }\n\
09695 return 1\n\
09696 }\n\
09697 set r [new Classifier/Replicator/Demuxer]\n\
09698 $r set node_ $self\n\
09699 $r set srcID_ $src\n\
09700 set Regreplicator_($group) $r\n\
09701 \n\
09702 foreach oif $oiflist {\n\
09703 $r insert $oif\n\
09704 }\n\
09705 \n\
09706 $multiclassifier_ add-rep $r $src $group $iif\n\
09707 }\n\
09708 \n\
09709 Node instproc getRegreplicator group {\n\
09710 $self instvar Regreplicator_\n\
09711 if [info exists Regreplicator_($group)] {\n\
09712 return $Regreplicator_($group)\n\
09713 } else {\n\
09714 return -1\n\
09715 }\n\
09716 }\n\
09717 \n\
09718 Class CtrMcastComp\n\
09719 \n\
09720 CtrMcastComp instproc init sim {\n\
09721 $self instvar ns_\n\
09722 \n\
09723 set ns_ $sim\n\
09724 $self init-groups\n\
09725 $ns_ maybeEnableTraceAll $self {}\n\
09726 }\n\
09727 \n\
09728 CtrMcastComp instproc id {} {\n\
09729 return 0\n\
09730 }\n\
09731 \n\
09732 CtrMcastComp instproc trace { f nop {op \"\"} } {\n\
09733 $self instvar ns_ dynT_\n\
09734 if {$op == \"nam\" && [info exists dynT_]} {\n\
09735 foreach tr $dynT_ {\n\
09736 $tr namattach $f\n\
09737 }\n\
09738 } else {\n\
09739 lappend dynT_ [$ns_ create-trace Generic $f $self $self $op]\n\
09740 }\n\
09741 }\n\
09742 \n\
09743 CtrMcastComp instproc reset-mroutes {} {\n\
09744 $self instvar ns_\n\
09745 \n\
09746 foreach node [$ns_ all-nodes-list] {\n\
09747 foreach group [$self groups?] {\n\
09748 set class_info [$node info class]\n\
09749 if {$class_info != \"LanNode\"} {\n\
09750 $node clearReps * $group\n\
09751 }\n\
09752 }\n\
09753 }\n\
09754 }\n\
09755 \n\
09756 CtrMcastComp instproc compute-mroutes {} {\n\
09757 $self reset-mroutes\n\
09758 foreach group [$self groups?] {\n\
09759 foreach src [$self sources? $group] {\n\
09760 $self compute-tree $src $group\n\
09761 }\n\
09762 }\n\
09763 }\n\
09764 \n\
09765 CtrMcastComp instproc compute-tree { src group } {\n\
09766 foreach mem [$self members? $group] {\n\
09767 $self compute-branch $src $group $mem\n\
09768 }\n\
09769 }\n\
09770 \n\
09771 \n\
09772 CtrMcastComp instproc compute-branch { src group nodeh } {\n\
09773 $self instvar ns_\n\
09774 \n\
09775 set tt [$self treetype? $group]\n\
09776 if { $tt == \"SPT\" } {\n\
09777 set target $src\n\
09778 } elseif { $tt == \"RPT\" } {\n\
09779 set target [$self get_rp $nodeh $group]\n\
09780 }\n\
09781 \n\
09782 for {\n\
09783 set downstreamtmp \"\"\n\
09784 set tmp $nodeh\n\
09785 } { $downstreamtmp != $target } {\n\
09786 set downstreamtmp $tmp\n\
09787 set tmp [$tmp rpf-nbr $target]\n\
09788 } {\n\
09789 \n\
09790 if {[SessionSim set MixMode_] && $downstreamtmp != \"\" && ![$ns_ detailed-link? [$tmp id] [$downstreamtmp id]]} {\n\
09791 break\n\
09792 }\n\
09793 \n\
09794 \n\
09795 if {$tmp == $target} {\n\
09796 set iif -1\n\
09797 } else {\n\
09798 set rpfl [$ns_ link [$tmp rpf-nbr $target] $tmp]\n\
09799 \n\
09800 if {[SessionSim set MixMode_] && $rpfl == \"\"} {\n\
09801 set iif -1\n\
09802 set ttmp $tmp\n\
09803 while {$ttmp != $target} {\n\
09804 set rpfl [$ns_ link [$ttmp rpf-nbr $target] $ttmp]\n\
09805 if {$rpfl != \"\"} {\n\
09806 set iif [$rpfl if-label?]\n\
09807 break\n\
09808 }\n\
09809 set ttmp [$ttmp rpf-nbr $target]\n\
09810 }\n\
09811 } else {\n\
09812 set iif [$rpfl if-label?]\n\
09813 }\n\
09814 }\n\
09815 \n\
09816 set oiflist \"\"\n\
09817 if { $downstreamtmp != \"\" } {\n\
09818 set rpfnbr [$downstreamtmp rpf-nbr $target]\n\
09819 if { $rpfnbr == $tmp } {\n\
09820 set rpflink [$ns_ link $tmp $downstreamtmp]\n\
09821 if {$rpflink != \"\"} {\n\
09822 set oiflist [$tmp link2oif $rpflink]\n\
09823 } \n\
09824 }\n\
09825 }\n\
09826 \n\
09827 if { [set r [$tmp getReps [$src id] $group]] != \"\" } {\n\
09828 if [$r is-active] {\n\
09829 if { $oiflist != \"\" } {\n\
09830 $r insert [lindex $oiflist 0]\n\
09831 }\n\
09832 break\n\
09833 } else {\n\
09834 if { $oiflist != \"\" } {\n\
09835 $r insert [lindex $oiflist 0]\n\
09836 }\n\
09837 }\n\
09838 } else {\n\
09839 $tmp add-mfc [$src id] $group $iif $oiflist\n\
09840 }\n\
09841 }\n\
09842 }\n\
09843 \n\
09844 \n\
09845 CtrMcastComp instproc prune-branch { src group nodeh } {\n\
09846 $self instvar ns_\n\
09847 \n\
09848 set tt [$self treetype? $group]\n\
09849 if { $tt == \"SPT\" } {\n\
09850 set target $src\n\
09851 } elseif { $tt == \"RPT\" } {\n\
09852 set target [$self get_rp $nodeh $group]\n\
09853 }\n\
09854 \n\
09855 for {\n\
09856 set downstreamtmp \"\"\n\
09857 set tmp $nodeh\n\
09858 } { $downstreamtmp != $target } {\n\
09859 set downstreamtmp $tmp\n\
09860 set tmp [$tmp rpf-nbr $target]\n\
09861 } {\n\
09862 set iif -1\n\
09863 set oif \"\"\n\
09864 if { $downstreamtmp != \"\" } {\n\
09865 set rpfnbr [$downstreamtmp rpf-nbr $target]\n\
09866 if { $rpfnbr == $tmp } {\n\
09867 set oif [$tmp link2oif [$ns_ link $tmp $downstreamtmp]]\n\
09868 }\n\
09869 }\n\
09870 \n\
09871 if { [set r [$tmp getReps [$src id] $group]] != \"\" } {\n\
09872 if { $oif != \"\" } {\n\
09873 $r disable $oif\n\
09874 }\n\
09875 \n\
09876 if [$r is-active] {\n\
09877 break\n\
09878 }\n\
09879 } else {\n\
09880 break\n\
09881 }\n\
09882 }\n\
09883 \n\
09884 }\n\
09885 \n\
09886 CtrMcastComp instproc notify {} {\n\
09887 $self instvar ctrrpcomp\n\
09888 \n\
09889 $ctrrpcomp compute-rpset\n\
09890 $self compute-mroutes\n\
09891 }\n\
09892 \n\
09893 CtrMcastComp instproc init-groups {} {\n\
09894 $self set Glist_ \"\"\n\
09895 }\n\
09896 \n\
09897 CtrMcastComp instproc add-new-group group {\n\
09898 $self instvar Glist_ \n\
09899 set group [expr $group]\n\
09900 \n\
09901 if ![info exist Glist_] {\n\
09902 set Glist_ \"\"\n\
09903 }\n\
09904 if {[lsearch $Glist_ $group] < 0} {\n\
09905 lappend Glist_ $group\n\
09906 }\n\
09907 }\n\
09908 \n\
09909 CtrMcastComp instproc add-new-member {group node} {\n\
09910 $self instvar Mlist_ \n\
09911 set group [expr $group]\n\
09912 \n\
09913 $self add-new-group $group\n\
09914 if ![info exist Mlist_($group)] {\n\
09915 set Mlist_($group) \"\"\n\
09916 }\n\
09917 \n\
09918 if {[lsearch $Mlist_($group) $node] < 0} {\n\
09919 lappend Mlist_($group) $node\n\
09920 }\n\
09921 }\n\
09922 \n\
09923 CtrMcastComp instproc new-source? {group node} {\n\
09924 $self instvar Slist_ \n\
09925 set group [expr $group]\n\
09926 \n\
09927 $self add-new-group $group\n\
09928 if ![info exist Slist_($group)] {\n\
09929 set Slist_($group) \"\"\n\
09930 }\n\
09931 \n\
09932 if {[lsearch $Slist_($group) $node] < 0} {\n\
09933 lappend Slist_($group) $node\n\
09934 return 1\n\
09935 } else {\n\
09936 return 0\n\
09937 }\n\
09938 }\n\
09939 \n\
09940 CtrMcastComp instproc groups? {} {\n\
09941 $self set Glist_\n\
09942 }\n\
09943 \n\
09944 CtrMcastComp instproc members? group {\n\
09945 $self instvar Mlist_\n\
09946 set group [expr $group]\n\
09947 if ![info exists Mlist_($group)] {\n\
09948 set Mlist_($group) \"\"\n\
09949 }\n\
09950 set Mlist_($group)\n\
09951 }\n\
09952 \n\
09953 CtrMcastComp instproc sources? group {\n\
09954 $self instvar Slist_\n\
09955 set group [expr $group]\n\
09956 if ![info exists Slist_($group)] {\n\
09957 set Slist_($group) \"\"\n\
09958 }\n\
09959 set Slist_($group)\n\
09960 }\n\
09961 \n\
09962 CtrMcastComp instproc remove-member {group node} {\n\
09963 $self instvar Mlist_ Glist_\n\
09964 set group [expr $group]\n\
09965 \n\
09966 set k [lsearch $Mlist_($group) $node]\n\
09967 if {$k < 0} {\n\
09968 puts \"warning: removing non-member\"\n\
09969 } else {\n\
09970 set Mlist_($group) [lreplace $Mlist_($group) $k $k]\n\
09971 }\n\
09972 \n\
09973 if { $Mlist_($group) == \"\" } {\n\
09974 set k [lsearch $Glist_ $group]\n\
09975 if {$k < 0} {\n\
09976 puts \"warning: removing non-existing group\"\n\
09977 } else {\n\
09978 set Glist_ [lreplace $Glist_ $k $k]\n\
09979 }\n\
09980 }\n\
09981 }\n\
09982 \n\
09983 CtrMcastComp instproc treetype? group {\n\
09984 $self instvar treetype_\n\
09985 set group [expr $group]\n\
09986 if [info exists treetype_($group)] {\n\
09987 return $treetype_($group)\n\
09988 } else {\n\
09989 return \"\"\n\
09990 }\n\
09991 }\n\
09992 \n\
09993 CtrMcastComp instproc treetype {group tree} {\n\
09994 $self set treetype_([expr $group]) $tree\n\
09995 }\n\
09996 \n\
09997 CtrMcastComp instproc switch-treetype group {\n\
09998 $self instvar treetype_ dynT_\n\
09999 set group [expr $group]\n\
10000 \n\
10001 if [info exists dynT_] {\n\
10002 foreach tr $dynT_ {\n\
10003 $tr annotate \"$group switch tree type\"\n\
10004 }\n\
10005 }\n\
10006 set treetype_($group) \"SPT\"\n\
10007 $self add-new-group $group\n\
10008 $self compute-mroutes\n\
10009 }\n\
10010 \n\
10011 CtrMcastComp instproc set_c_rp args {\n\
10012 $self instvar ns_\n\
10013 \n\
10014 \n\
10015 foreach n [$ns_ all-nodes-list] {\n\
10016 set arbiter [$n getArbiter]\n\
10017 if {$arbiter != \"\"} {\n\
10018 set ctrmcast [$arbiter getType \"CtrMcast\"]\n\
10019 $ctrmcast instvar c_rp_\n\
10020 $ctrmcast unset_c_rp\n\
10021 }\n\
10022 }\n\
10023 \n\
10024 foreach node $args {\n\
10025 set arbiter [$node getArbiter]     \n\
10026 set ctrmcast [$arbiter getType \"CtrMcast\"]\n\
10027 $ctrmcast set_c_rp\n\
10028 }\n\
10029 }\n\
10030 \n\
10031 CtrMcastComp instproc set_c_bsr args {\n\
10032 foreach node $args {\n\
10033 set tmp [split $node :]\n\
10034 set node [lindex $tmp 0]\n\
10035 set prior [lindex $tmp 1]\n\
10036 set arbiter [$node getArbiter]\n\
10037 set ctrmcast [$arbiter getType \"CtrMcast\"]\n\
10038 $ctrmcast set_c_bsr $prior\n\
10039 }\n\
10040 }\n\
10041 \n\
10042 CtrMcastComp instproc get_rp { node group } {\n\
10043 set ctrmcast [[$node getArbiter] getType \"CtrMcast\"]\n\
10044 $ctrmcast get_rp $group\n\
10045 }\n\
10046 \n\
10047 CtrMcastComp instproc get_bsr { node } {\n\
10048 set arbiter [$node getArbiter]\n\
10049 set ctrmcast [$arbiter getType \"CtrMcast\"]\n\
10050 $ctrmcast get_bsr\n\
10051 }\n\
10052 \n\
10053 Class CtrRPComp\n\
10054 CtrRPComp instproc init sim {\n\
10055 $self set ns_ $sim\n\
10056 $self next\n\
10057 }\n\
10058 \n\
10059 CtrRPComp instproc compute-rpset {} {\n\
10060 $self instvar ns_\n\
10061 \n\
10062 foreach node [$ns_ all-nodes-list] {\n\
10063 set connected($node) 0\n\
10064 }\n\
10065 set urtl [$ns_ get-routelogic]\n\
10066 \n\
10067 foreach node [$ns_ all-nodes-list] {\n\
10068 foreach {vertix lvertix} [array get ldomain] {\n\
10069 if {[$urtl lookup [$node id] [$vertix id]] >= 0} {\n\
10070 lappend ldomain($vertix) $node\n\
10071 set connected($node) 1\n\
10072 break\n\
10073 }\n\
10074 }\n\
10075 \n\
10076 if {!$connected($node)} {\n\
10077 set ldomain($node) $node\n\
10078 set connected($node) 1\n\
10079 }\n\
10080 }\n\
10081 \n\
10082 foreach {vnode lvertix} [array get ldomain] {\n\
10083 set hasbsr 0\n\
10084 set rpset \"\"\n\
10085 \n\
10086 foreach vertix $lvertix {\n\
10087 set class_info [$vertix info class]\n\
10088 if {$class_info != \"LanNode\"} {\n\
10089 set ctrdm [[$vertix getArbiter] getType \"CtrMcast\"]\n\
10090 if [$ctrdm set c_bsr_] {set hasbsr 1}\n\
10091 if [$ctrdm set c_rp_] {\n\
10092 lappend rpset $vertix\n\
10093 }\n\
10094 }\n\
10095 }\n\
10096 \n\
10097 foreach vertix $lvertix {\n\
10098 set class_info [$vertix info class]\n\
10099 if {$class_info != \"LanNode\"} {\n\
10100 set ctrdm [[$vertix getArbiter] getType \"CtrMcast\"]\n\
10101 if $hasbsr {\n\
10102 $ctrdm set-rpset $rpset\n\
10103 } else {\n\
10104 $ctrdm set-rpset \"\"\n\
10105 puts \"no c_bsr\"\n\
10106 }\n\
10107 }\n\
10108 }\n\
10109 }\n\
10110 }\n\
10111 \n\
10112 Class BST -superclass McastProtocol\n\
10113 \n\
10114 BST instproc init { sim node } {\n\
10115 $self instvar mctrl_ oiflist_\n\
10116 BST instvar RP_\n\
10117 \n\
10118 set mctrl_ [new Agent/Mcast/Control $self]\n\
10119 $node attach $mctrl_\n\
10120 $self next $sim $node\n\
10121 }\n\
10122 \n\
10123 BST instproc start {} {\n\
10124 $self instvar node_ oiflist_\n\
10125 BST instvar RP_\n\
10126 \n\
10127 foreach grpx [array names RP_] {\n\
10128 set grp [expr $grpx]\n\
10129 if { [string compare $grp $grpx] } {\n\
10130 set RP_($grp) $RP_(grpx)\n\
10131 unset RP_($grpx)\n\
10132 }\n\
10133 set rpfiif [$node_ from-node-iface $RP_($grp)]\n\
10134 if { $rpfiif != \"?\" } {\n\
10135 set rpfoif [$node_ iif2oif $rpfiif]\n\
10136 } else {\n\
10137 set rpfoif \"\"\n\
10138 }\n\
10139 \n\
10140 set oiflist_($grp) $rpfoif\n\
10141 set neighbors [$node_ set neighbor_]\n\
10142 if [info exists neighbors] {\n\
10143 for {set i 0} {$i < [llength $neighbors]} {incr i} {\n\
10144 set neighbor [lindex $neighbors $i]\n\
10145 set class_info [$neighbor info class]\n\
10146 if {$class_info == \"LanNode\"} {\n\
10147 $neighbor designate-ump-router $grp \\\n\
10148 $RP_($grp)\n\
10149 }\n\
10150 }\n\
10151 }\n\
10152 }\n\
10153 \n\
10154 }\n\
10155 \n\
10156 BST instproc join-group  { group {src \"x\"} } {\n\
10157 $self instvar node_ ns_ oiflist_\n\
10158 BST instvar RP_\n\
10159 \n\
10160 set nbr [$node_ rpf-nbr $RP_($group)]\n\
10161 set nbrs($nbr) 1\n\
10162 $node_ add-mark m1 blue \"[$node_ get-shape]\"\n\
10163 foreach nbr [array names nbrs] {\n\
10164 if [$nbr is-lan?] {\n\
10165 $nbr instvar receivers_\n\
10166 if [info exists receivers_($group)] {\n\
10167 incr receivers_($group)\n\
10168 } else {\n\
10169 $self send-ctrl \"graft\" $RP_($group) $group\n\
10170 set receivers_($group) 1\n\
10171 }\n\
10172 }\n\
10173 $self next $group ; #annotate\n\
10174 }\n\
10175 \n\
10176 if { ![$node_ check-local $group] || [$node_ getReps \"x\" \\\n\
10177 $group] == \"\"} { \n\
10178 $self send-ctrl \"graft\" $RP_($group) $group\n\
10179 }\n\
10180 \n\
10181 }\n\
10182 \n\
10183 BST instproc leave-group { group {src \"x\"} } {\n\
10184 BST instvar RP_ \n\
10185 \n\
10186 $self next $group ;#annotate\n\
10187 $self instvar node_ oiflist_\n\
10188 \n\
10189 set nbr [$node_ rpf-nbr $RP_($group)]\n\
10190 if  [$nbr is-lan?] {\n\
10191 $nbr instvar receivers_\n\
10192 if [info exists receivers_($group)] {\n\
10193 if {$receivers_($group) > 0} {\n\
10194 incr receivers_($group) -1\n\
10195 if {$receivers_($group) == 0} {\n\
10196 $node_ delete-mark m1\n\
10197 $self send-ctrl \"prune\" $RP_($group) $group\n\
10198 }\n\
10199 }\n\
10200 } else {\n\
10201 return\n\
10202 }\n\
10203 } else {\n\
10204 set rpfiif [$node_ from-node-iface $RP_($group)]\n\
10205 if { $rpfiif != \"?\" } {\n\
10206 set rpfoif [$node_ iif2oif $rpfiif]\n\
10207 } else {\n\
10208 set rpfoif \"\"\n\
10209 }\n\
10210 if { $oiflist_($group) == \\\n\
10211 $rpfoif && ![$node_ check-local $group] } {\n\
10212 $self send-ctrl \"prune\" $RP_($group) $group\n\
10213 $node_ delete-mark m1\n\
10214 } else {\n\
10215 $node_ delete-mark m1\n\
10216 $node_ add-mark m2 red circle\n\
10217 }\n\
10218 }\n\
10219 \n\
10220 }\n\
10221 \n\
10222 BST instproc handle-wrong-iif { srcID group iface } {\n\
10223 $self instvar node_ oiflist_\n\
10224 BST instvar RP_\n\
10225 \n\
10226 \n\
10227 set rep [$node_ getReps \"x\" $group]\n\
10228 \n\
10229 $node_ add-mfc \"x\" $group $iface $oiflist_($group)\n\
10230 set iif [$node_ lookup-iface \"x\" $group]\n\
10231 if { $iface >= 0 } {\n\
10232 set oif [$node_ iif2oif $iface]\n\
10233 set rpfiif [$node_ from-node-iface $RP_($group)]\n\
10234 if { $iface == $rpfiif } {\n\
10235 $rep disable [$node_ iif2oif $rpfiif]\n\
10236 } else {\n\
10237 $rep disable $oif\n\
10238 if { $node_ != $RP_($group) } {\n\
10239 $rep insert [$node_ iif2oif $rpfiif]\n\
10240 }\n\
10241 }\n\
10242 }\n\
10243 $node_ change-iface \"x\" $group $iif $iface\n\
10244 return 1 ;#classify packet again\n\
10245 }\n\
10246 \n\
10247 BST instproc handle-cache-miss { srcID group iface } {\n\
10248 $self instvar node_  ns_ oiflist_\n\
10249 BST instvar RP_\n\
10250 \n\
10251 if { [$node_ getReps \"x\" $group] != \"\" } {\n\
10252 error\n\
10253 }\n\
10254 \n\
10255 \n\
10256 \n\
10257 \n\
10258 if {$iface != -1} {\n\
10259 set neighbors [$node_ set neighbor_]\n\
10260 if [info exists neighbors] {\n\
10261 for {set i 0} {$i < [llength $neighbors]} {incr i} {\n\
10262 set neighbor [lindex $neighbors $i]\n\
10263 set nbr [$node_ rpf-nbr $RP_($group)]\n\
10264 if {[$neighbor is-lan?] && \\\n\
10265 [$nbr info class] != \"LanNode\"} {\n\
10266 $neighbor instvar up_\n\
10267 set up [$neighbor set up_($group)]\n\
10268 if {$node_ != $up} {\n\
10269 if [$self link2lan? $neighbor \\\n\
10270 $iface] {\n\
10271 return 0\n\
10272 }\n\
10273 }\n\
10274 }\n\
10275 }\n\
10276 }\n\
10277 }\n\
10278 \n\
10279 $node_ add-mfc \"x\" $group $iface $oiflist_($group)\n\
10280 \n\
10281 if { $iface > 0 } {\n\
10282 set rep [$node_ getReps \"x\" $group]\n\
10283 $rep disable [$node_ iif2oif $iface]\n\
10284 }\n\
10285 return 1 ;# classify the packet again.\n\
10286 }\n\
10287 \n\
10288 BST instproc drop { replicator src dst iface} {\n\
10289 $self instvar node_ ns_\n\
10290 BST instvar RP_\n\
10291 \n\
10292 \n\
10293 if {$iface >= 0} {\n\
10294 }\n\
10295 }\n\
10296 \n\
10297 BST instproc recv-prune { from src group iface} {\n\
10298 $self instvar node_ ns_ oiflist_ \n\
10299 BST instvar RP_ \n\
10300 \n\
10301 set rep [$node_ getReps \"x\" $group]\n\
10302 if {$rep != \"\"} {\n\
10303 set oif [$node_ iif2oif $iface]\n\
10304 set idx [lsearch $oiflist_($group) $oif]\n\
10305 if { $idx >= 0 } {\n\
10306 set oiflist_($group) [lreplace $oiflist_($group) $idx $idx]\n\
10307 $rep disable $oif\n\
10308 set rpfiif [$node_ from-node-iface $RP_($group)]\n\
10309 if { $rpfiif != \"?\" } {\n\
10310 set rpfoif [$node_ iif2oif $rpfiif]\n\
10311 } else {\n\
10312 set rpfoif \"\"\n\
10313 }\n\
10314 if { $oiflist_($group) == $rpfoif && ![$node_ check-local $group] } {\n\
10315 $node_ delete-mark m2\n\
10316 $self send-ctrl \"prune\" $RP_($group) $group\n\
10317 }\n\
10318 }\n\
10319 }\n\
10320 }\n\
10321 \n\
10322 BST instproc recv-graft { from to group iface } {\n\
10323 $self instvar node_ ns_ oiflist_\n\
10324 BST instvar RP_\n\
10325 \n\
10326 set oif [$node_ iif2oif $iface]\n\
10327 set rpfiif [$node_ from-node-iface $RP_($group)]\n\
10328 if { $rpfiif != \"?\" } {\n\
10329 set rpfoif [$node_ iif2oif $rpfiif]\n\
10330 } else {\n\
10331 set rpfoif \"\"\n\
10332 }\n\
10333 \n\
10334 if { $oiflist_($group) == $rpfoif && ![$node_ check-local $group] } {\n\
10335 $node_ add-mark m2 red circle\n\
10336 $self send-ctrl \"graft\" $RP_($group) $group\n\
10337 }\n\
10338 if { [lsearch $oiflist_($group) $oif] < 0 } {\n\
10339 lappend oiflist_($group) $oif\n\
10340 if { [$node_ lookup-iface \"x\" $group] != $iface } {\n\
10341 set rep [$node_ getReps \"x\" $group]\n\
10342 if { $rep != \"\" } {\n\
10343 $rep insert $oif\n\
10344 }\n\
10345 }\n\
10346 }\n\
10347 }\n\
10348 \n\
10349 BST instproc send-ctrl { which dst group } {\n\
10350 $self instvar mctrl_ ns_ node_\n\
10351 \n\
10352 if {$node_ != $dst} {\n\
10353 set nbr [$node_ rpf-nbr $dst]\n\
10354 if [$nbr is-lan?] {\n\
10355 $nbr instvar receivers_\n\
10356 if { [info exists receivers_($group)] && \\\n\
10357 $receivers_($group) > 0 } return\n\
10358 \n\
10359 set nbr [$nbr rpf-nbr $dst]\n\
10360 }\n\
10361 \n\
10362 \n\
10363 $ns_ simplex-connect $mctrl_ \\\n\
10364 [[[$nbr getArbiter] getType [$self info class]] set mctrl_]\n\
10365 if { $which == \"prune\" } {\n\
10366 $mctrl_ set fid_ 2\n\
10367 } else {\n\
10368 $mctrl_ set fid_ 3\n\
10369 }\n\
10370 $mctrl_ send $which [$node_ id] $dst $group\n\
10371 }\n\
10372 }\n\
10373 \n\
10374 \n\
10375 BST instproc dbg arg {\n\
10376 $self instvar ns_ node_\n\
10377 puts [format \"At %.4f : node [$node_ id] $arg\" [$ns_ now]]\n\
10378 }\n\
10379 \n\
10380 \n\
10381 \n\
10382 LanNode instproc designate-ump-router {group dst} {\n\
10383 $self instvar nodelist_\n\
10384 $self instvar up_\n\
10385 \n\
10386 set nbr [$self rpf-nbr $dst]\n\
10387 set up_($group) $nbr\n\
10388 return\n\
10389 }\n\
10390 \n\
10391 \n\
10392 BST instproc next-hop-router {node group} {\n\
10393 BST instvar RP_\n\
10394 \n\
10395 set nbr [$node rpf-nbr $RP_($group)]\n\
10396 if [$nbr is-lan?] {\n\
10397 set nbr [$nbr rpf-nbr $RP_($group)]\n\
10398 }\n\
10399 return $nbr\n\
10400 }\n\
10401 \n\
10402 BST instproc is-group-bidir? {group} {\n\
10403 BST instvar RP_\n\
10404 \n\
10405 foreach grp [array names RP_] {\n\
10406 if {$grp == $group} {\n\
10407 return 1\n\
10408 }\n\
10409 }\n\
10410 return 0\n\
10411 }\n\
10412 \n\
10413 BST instproc match-oif {group link} {\n\
10414 $self instvar oiflist_\n\
10415 \n\
10416 set oiflist $oiflist_($group)\n\
10417 if {$oiflist != \"\"} {\n\
10418 foreach oif $oiflist {\n\
10419 set oiflink [$oif set link_]\n\
10420 if {$oiflink == $link} {\n\
10421 return $oiflink\n\
10422 }\n\
10423 }\n\
10424 }\n\
10425 return\n\
10426 }\n\
10427 \n\
10428 BST instproc find-oif {dst group} {\n\
10429 $self instvar node_ ns_\n\
10430 \n\
10431 if {$node_ != $dst} {\n\
10432 set ns [$self set ns_]\n\
10433 $ns instvar link_\n\
10434 set link [$ns set link_([$node_ id]:[$dst id])]\n\
10435 return [$self match-oif $group $link]\n\
10436 } else {\n\
10437 return \"\"\n\
10438 }\n\
10439 }\n\
10440 \n\
10441 BST instproc link2lan? {neighbor iface} {\n\
10442 $self instvar node_ ns_\n\
10443 \n\
10444 set link1 [[[$node_ iif2oif $iface] set link_] set iif_]\n\
10445 set link2 [[$ns_ link $node_ $neighbor] set iif_]\n\
10446 if {$link1 == $link2} {\n\
10447 return 1\n\
10448 } else {\n\
10449 return 0\n\
10450 }\n\
10451 }\n\
10452 \n\
10453 Class Classifier/Multicast/Replicator/BST -superclass Classifier/Multicast/BST\n\
10454 \n\
10455 Classifier/Multicast/BST instproc new-group { src group iface code} {\n\
10456 $self instvar node_\n\
10457 $node_ new-group $src $group $iface $code\n\
10458 }\n\
10459 \n\
10460 Classifier/Multicast/BST instproc no-slot slot {\n\
10461 }\n\
10462 \n\
10463 Classifier/Multicast/Replicator/BST instproc init args {\n\
10464 $self next\n\
10465 $self instvar nrep_\n\
10466 set nrep_ 0\n\
10467 }\n\
10468 \n\
10469 Classifier/Multicast/Replicator/BST instproc add-rep { rep src group iif } {\n\
10470 $self instvar nrep_\n\
10471 $self set-hash $src $group $nrep_ $iif\n\
10472 $self install $nrep_ $rep\n\
10473 incr nrep_\n\
10474 }\n\
10475 \n\
10476 Classifier/Multicast/Replicator/BST instproc match-BST-iif {iface group} {\n\
10477 $self instvar node_\n\
10478 \n\
10479 list retval_\n\
10480 set agents [$node_ set agents_]\n\
10481 for {set i 0} {$i < [llength $agents]} {incr i} {\n\
10482 set agent [lindex $agents $i]\n\
10483 $agent instvar proto_\n\
10484 if [info exists proto_] {\n\
10485 set protocol [$agent set proto_]\n\
10486 if {[$protocol info class] == \"BST\"} {\n\
10487 BST instvar RP_\n\
10488 $protocol instvar oiflist_\n\
10489 set bidir [$protocol is-group-bidir? $group]\n\
10490 if {$bidir == 1} {\n\
10491 if {$node_ == $RP_($group)} {\n\
10492 return 1\n\
10493 }\n\
10494 \n\
10495 set iif [$node_ from-node-iface \\\n\
10496 $RP_($group)]\n\
10497 if {$iif == $iface} {\n\
10498 return 1\n\
10499 } else {\n\
10500 return 0\n\
10501 }\n\
10502 }\n\
10503 }\n\
10504 }\n\
10505 }\n\
10506 return -1\n\
10507 }\n\
10508 \n\
10509 Classifier/Multicast/Replicator/BST instproc upstream-link {group} {\n\
10510 $self instvar node_\n\
10511 \n\
10512 list retval_\n\
10513 set agents [$node_ set agents_]\n\
10514 for {set i 0} {$i < [llength $agents]} {incr i} {\n\
10515 set agent [lindex $agents $i]\n\
10516 $agent instvar proto_\n\
10517 if [info exists proto_] {\n\
10518 set protocol [$agent set proto_]\n\
10519 if {[$protocol info class] == \"BST\"} {\n\
10520 BST instvar RP_\n\
10521 $protocol instvar oiflist_\n\
10522 set bidir [$protocol is-group-bidir? $group]\n\
10523 if {$bidir == 1} {\n\
10524 set nbr [$node_ rpf-nbr $RP_($group)]\n\
10525 \n\
10526 set oif [$protocol find-oif $nbr \\\n\
10527 $group]\n\
10528 \n\
10529 if {$oif == \"\"} {\n\
10530 set oif \"self\"\n\
10531 } \n\
10532 lappend retval_ $oif\n\
10533 \n\
10534 if [$nbr is-lan?] {\n\
10535 set nbr [$nbr rpf-nbr $RP_($group)]\n\
10536 }\n\
10537 lappend retval_ [$nbr id]\n\
10538 return $retval_\n\
10539 \n\
10540 }\n\
10541 }\n\
10542 }\n\
10543 }\n\
10544 return {}\n\
10545 }\n\
10546 \n\
10547 Classifier/Multicast/Replicator/BST instproc check-rpf-link {node group} {\n\
10548 $self instvar node_\n\
10549 \n\
10550 set agents [$node_ set agents_]\n\
10551 for {set i 0} {$i < [llength $agents]} {incr i} {\n\
10552 set agent [lindex $agents $i]\n\
10553 $agent instvar proto_\n\
10554 if [info exists proto_] {\n\
10555 set protocol [$agent set proto_]\n\
10556 set classInfo [$protocol info class]\n\
10557 if {$classInfo == \"BST\"} {\n\
10558 BST instvar RP_\n\
10559 set rpfiif [$node_ from-node-iface \\\n\
10560 $RP_($group)]\n\
10561 return $rpfiif\n\
10562 }\n\
10563 }\n\
10564 }\n\
10565 return -1\n\
10566 }\n\
10567 \n\
10568 \n\
10569 \n\
10570 Agent instproc traffic-source agent {\n\
10571 $self instvar tg_\n\
10572 set tg_ $agent\n\
10573 $tg_ target $self\n\
10574 $tg_ set agent_addr_ [$self set agent_addr_]\n\
10575 $tg_ set agent_port_ [$self set agent_port_]\n\
10576 }\n\
10577 \n\
10578 Agent/SRM set packetSize_  1024 ;# assume default message size for repair is 1K\n\
10579 Agent/SRM set groupSize_   0\n\
10580 Agent/SRM set app_fid_ 0\n\
10581 \n\
10582 Agent/SRM set distanceCompute_  ewma\n\
10583 \n\
10584 Agent/SRM set C1_   2.0\n\
10585 Agent/SRM set C2_   2.0\n\
10586 Agent/SRM set requestFunction_  \"SRM/request\"\n\
10587 Agent/SRM set requestBackoffLimit_  5\n\
10588 \n\
10589 Agent/SRM set D1_   1.0\n\
10590 Agent/SRM set D2_   1.0\n\
10591 Agent/SRM set repairFunction_   \"SRM/repair\"\n\
10592 \n\
10593 Agent/SRM set sessionDelay_ 1.0\n\
10594 Agent/SRM set sessionFunction_  \"SRM/session\"\n\
10595 \n\
10596 Class Agent/SRM/Deterministic -superclass Agent/SRM\n\
10597 Agent/SRM/Deterministic set C2_ 0.0\n\
10598 Agent/SRM/Deterministic set D2_ 0.0\n\
10599 \n\
10600 Class Agent/SRM/Probabilistic -superclass Agent/SRM\n\
10601 Agent/SRM/Probabilistic set C1_ 0.0\n\
10602 Agent/SRM/Probabilistic set D1_ 0.0\n\
10603 \n\
10604 Class Agent/SRM/Fixed -superclass Agent/SRM\n\
10605 \n\
10606 Class SRM\n\
10607 Class SRM/request -superclass SRM\n\
10608 Class SRM/repair -superclass SRM\n\
10609 Class SRM/session -superclass SRM\n\
10610 \n\
10611 \n\
10612 Agent/SRM/Adaptive set pdistance_   0.0 ;# bound instance variables\n\
10613 Agent/SRM/Adaptive set requestor_ 0\n\
10614 \n\
10615 Agent/SRM/Adaptive set C1_  2.0\n\
10616 Agent/SRM/Adaptive set MinC1_   0.5\n\
10617 Agent/SRM/Adaptive set MaxC1_   2.0\n\
10618 Agent/SRM/Adaptive set C2_  2.0\n\
10619 Agent/SRM/Adaptive set MinC2_   1.0\n\
10620 Agent/SRM/Adaptive set MaxC2_   1.0 ;# G\n\
10621 \n\
10622 Agent/SRM/Adaptive set D1_  -1  ;# log10 G\n\
10623 Agent/SRM/Adaptive set MinD1_   0.5\n\
10624 Agent/SRM/Adaptive set MaxD1_   0.0 ;# log10 G\n\
10625 Agent/SRM/Adaptive set D2_  -1  ;# log10 G  XXX\n\
10626 Agent/SRM/Adaptive set MinD2_   1.0\n\
10627 Agent/SRM/Adaptive set MaxD2_   1.0 ;# G\n\
10628 \n\
10629 Agent/SRM/Adaptive set requestFunction_ \"SRM/request/Adaptive\"\n\
10630 Agent/SRM/Adaptive set repairFunction_  \"SRM/repair/Adaptive\"\n\
10631 \n\
10632 Agent/SRM/Adaptive set AveDups_ 1.0\n\
10633 Agent/SRM/Adaptive set AveDelay_    1.0\n\
10634 \n\
10635 Agent/SRM/Adaptive set eps_ 0.10\n\
10636 \n\
10637 Agent/SRM/Adaptive instproc init args {\n\
10638 \n\
10639 eval $self next $args\n\
10640 $self array set closest_ \"requestor 0 repairor 0\"\n\
10641 \n\
10642 $self set AveDups_  [$class set AveDups_]\n\
10643 $self set AveDelay_ [$class set AveDelay_]\n\
10644 \n\
10645 foreach i [list MinC1_ MaxC1_ MinC2_ MaxC2_         \\\n\
10646 MinD1_ MaxD1_ MinD2_ MaxD2_] {\n\
10647 $self instvar $i\n\
10648 set $i [$class set $i]\n\
10649 }\n\
10650 \n\
10651 $self set eps_  [$class set eps_]\n\
10652 }\n\
10653 \n\
10654 Agent/SRM/Adaptive instproc check-bounds args {\n\
10655 set G [$self set groupSize_]\n\
10656 $self set MaxC2_ $G\n\
10657 $self set MaxD1_ [expr log10($G)]\n\
10658 $self set MaxD2_ $G\n\
10659 if {[llength $args] <= 0} {\n\
10660 set args \"C1_ C2_ D1_ D2_\"\n\
10661 }\n\
10662 foreach i $args {\n\
10663 $self instvar $i\n\
10664 set val [$self set $i]        ;# We do this for notational convenience\n\
10665 set min [$self set Min$i]\n\
10666 set max [$self set Max$i]\n\
10667 if { $val < $min } {\n\
10668 set $i $min\n\
10669 } elseif { $val > $max } {\n\
10670 set $i $max\n\
10671 }\n\
10672 }\n\
10673 }\n\
10674 \n\
10675 Agent/SRM/Adaptive instproc recompute-request-params {} {\n\
10676 $self instvar closest_ C1_ C2_ stats_ AveDups_ AveDelay_ eps_\n\
10677 if {$stats_(ave-req-delay) < 0} {\n\
10678 $self check-bounds C1_ C2_  ;# adjust bounds to estimated size of G\n\
10679 return\n\
10680 }\n\
10681 \n\
10682 $self compute-ave dup-req\n\
10683 if $closest_(requestor) {\n\
10684 set C2_ [expr $C2_ - 0.1]\n\
10685 set closest_(requestor) 0\n\
10686 } elseif {$stats_(ave-dup-req) >= $AveDups_} {\n\
10687 set C1_ [expr $C1_ + 0.1]\n\
10688 set C2_ [expr $C2_ + 0.5]\n\
10689 } elseif {$stats_(ave-dup-req) < [expr $AveDups_ - $eps_]} {\n\
10690 if {$stats_(ave-req-delay) > $AveDelay_} {\n\
10691 set C2_ [expr $C2_ - 0.1]\n\
10692 }\n\
10693 if {$stats_(ave-dup-req) < 0.25} {\n\
10694 set C1_ [expr $C1_ - 0.05]\n\
10695 }\n\
10696 } else {\n\
10697 set C1_ [expr $C1_ + 0.05]\n\
10698 }\n\
10699 $self check-bounds C1_ C2_\n\
10700 }\n\
10701 \n\
10702 Agent/SRM/Adaptive instproc sending-request {} {\n\
10703 $self set C1_ [expr [$self set C1_] - 0.1]  ;# XXX SF's code uses other\n\
10704 $self set closest_(requestor) 1\n\
10705 $self check-bounds C1_\n\
10706 }\n\
10707 \n\
10708 Agent/SRM/Adaptive instproc recv-request {r d s m} {\n\
10709 $self instvar pending_ closest_\n\
10710 if { [info exists pending_($s:$m)]  && $d == 1 } {\n\
10711 set closeness [$pending_($s:$m) closest-requestor?]\n\
10712 if {$closeness >= 0} {\n\
10713 set closest_(requestor) $closeness\n\
10714 }\n\
10715 }\n\
10716 $self next $r $d $s $m\n\
10717 }\n\
10718 \n\
10719 Agent/SRM/Adaptive instproc recompute-repair-params {} {\n\
10720 $self instvar closest_ D1_ D2_ stats_ AveDups_ AveDelay_ eps_\n\
10721 if {$stats_(ave-rep-delay) < 0} {\n\
10722 set logG [expr log10([$self set groupSize_])]\n\
10723 set D1_  $logG\n\
10724 set D2_  $logG\n\
10725 $self check-bounds D1_ D2_  ;# adjust bounds to estimated size of G\n\
10726 return\n\
10727 }\n\
10728 \n\
10729 $self compute-ave dup-rep\n\
10730 if $closest_(repairor) {\n\
10731 set D2_ [expr $D2_ - 0.1]\n\
10732 set closest_(repairor) 0\n\
10733 } elseif {$stats_(ave-dup-rep) >= $AveDups_} {\n\
10734 set D1_ [expr $D1_ + 0.1]\n\
10735 set D2_ [expr $D2_ + 0.5]\n\
10736 } elseif {$stats_(ave-dup-rep) < [expr $AveDups_ - $eps_]} {\n\
10737 if {$stats_(ave-rep-delay) > $AveDelay_} {\n\
10738 set D2_ [expr $D2_ - 0.1]\n\
10739 }\n\
10740 if {$stats_(ave-dup-rep) < 0.25} {\n\
10741 set D1_ [expr $D1_ - 0.05]\n\
10742 }\n\
10743 } else {\n\
10744 set D1_ [expr $D1_ + 0.05]\n\
10745 }\n\
10746 $self check-bounds D1_ D2_\n\
10747 }\n\
10748 \n\
10749 Agent/SRM/Adaptive instproc sending-repair {} {\n\
10750 $self set D1_ [expr [$self set D1_] - 0.1]  ;# XXX SF's code uses other\n\
10751 $self set closest_(repairor) 1\n\
10752 $self check-bounds D1_\n\
10753 }\n\
10754 \n\
10755 Agent/SRM/Adaptive instproc recv-repair {d s m} {\n\
10756 $self instvar pending_ closest_\n\
10757 if { [info exists pending_($s:$m)] && $d == 1 } {\n\
10758 set closeness [$pending_($s:$m) closest-repairor?]\n\
10759 if {$closeness >= 0} {\n\
10760 set closest_(repairor) $closeness\n\
10761 }\n\
10762 }\n\
10763 $self next $d $s $m\n\
10764 }\n\
10765 \n\
10766 Class SRM/request/Adaptive -superclass SRM/request\n\
10767 SRM/request/Adaptive instproc set-params args {\n\
10768 $self instvar agent_\n\
10769 $agent_ recompute-request-params\n\
10770 eval $self next $args\n\
10771 }\n\
10772 \n\
10773 SRM/request/Adaptive instproc backoff? {} {\n\
10774 $self instvar backoff_ backoffCtr_ backoffLimit_\n\
10775 set retval $backoff_\n\
10776 if {[incr backoffCtr_] <= $backoffLimit_} {\n\
10777 set backoff_ [expr $backoff_ * 3]\n\
10778 }\n\
10779 set retval\n\
10780 }\n\
10781 \n\
10782 SRM/request/Adaptive instproc schedule {} {\n\
10783 $self next\n\
10784 }\n\
10785 \n\
10786 SRM/request/Adaptive instproc send-request {} {\n\
10787 $self instvar agent_ round_\n\
10788 if { $round_ == 1 } {\n\
10789 $agent_ sending-request\n\
10790 }\n\
10791 $self next\n\
10792 }\n\
10793 \n\
10794 SRM/request/Adaptive instproc closest-requestor? {} {\n\
10795 $self instvar agent_ sender_ sent_ round_\n\
10796 if {$sent_ == 1 && $round_ == 1} {  ;# since repairs aren't rescheduled.\n\
10797 if {[$agent_ set pdistance_] >          \\\n\
10798 [expr 1.5 * [$self distance? $sender_]]} {\n\
10799 return 1\n\
10800 } else {\n\
10801 return 0\n\
10802 }\n\
10803 } else {\n\
10804 return -1\n\
10805 }\n\
10806 }\n\
10807 \n\
10808 SRM/request/Adaptive instproc closest-repairor? {} {\n\
10809 return -1\n\
10810 }\n\
10811 \n\
10812 Class SRM/repair/Adaptive -superclass SRM/repair\n\
10813 SRM/repair/Adaptive instproc set-params args {\n\
10814 $self instvar agent_\n\
10815 $agent_ recompute-repair-params\n\
10816 eval $self next $args\n\
10817 }\n\
10818 \n\
10819 SRM/repair/Adaptive instproc schedule {} {\n\
10820 $self next\n\
10821 }\n\
10822 \n\
10823 SRM/repair/Adaptive instproc send-repair {} {\n\
10824 $self instvar round_ agent_\n\
10825 if { $round_ == 1 } {\n\
10826 $agent_ sending-repair\n\
10827 }\n\
10828 $self next\n\
10829 }\n\
10830 \n\
10831 SRM/repair/Adaptive instproc closest-requestor? {} {\n\
10832 return -1\n\
10833 }\n\
10834 \n\
10835 SRM/repair/Adaptive instproc closest-repairor? {} {\n\
10836 $self instvar agent_ requestor_ sent_ round_\n\
10837 if {$sent_ == 1 && $round_ == 1} {\n\
10838 if {[$agent_ set pdistance_] >          \\\n\
10839 [expr 1.5 * [$self distance? $requestor_]]} {\n\
10840 return 1\n\
10841 } else {\n\
10842 return 0\n\
10843 }\n\
10844 } else {\n\
10845 return -1\n\
10846 }\n\
10847 }\n\
10848 \n\
10849 Agent/SRM instproc init {} {\n\
10850 $self next\n\
10851 $self instvar ns_ requestFunction_ repairFunction_\n\
10852 set ns_ [Simulator instance]\n\
10853 \n\
10854 $ns_ create-eventtrace Event $self  \n\
10855 \n\
10856 $self init-instvar sessionDelay_\n\
10857 foreach var {C1_ C2_ D1_ D2_} {\n\
10858 $self init-instvar $var\n\
10859 }\n\
10860 $self init-instvar requestFunction_\n\
10861 $self init-instvar repairFunction_\n\
10862 $self init-instvar sessionFunction_\n\
10863 $self init-instvar requestBackoffLimit_\n\
10864 $self init-instvar distanceCompute_\n\
10865 \n\
10866 $self array set stats_ [list        \\\n\
10867 dup-req     -1  ave-dup-req -1  \\\n\
10868 dup-rep     -1  ave-dup-rep -1  \\\n\
10869 req-delay   0.0 ave-req-delay   -1  \\\n\
10870 rep-delay   0.0 ave-rep-delay   -1  \\\n\
10871 ]\n\
10872 }\n\
10873 \n\
10874 Agent/SRM instproc delete {} {\n\
10875 $self instvar ns_ pending_ done_ session_ tg_\n\
10876 foreach i [array names pending_] {\n\
10877 $pending_($i) cancel DELETE\n\
10878 delete $pending_($i)\n\
10879 }\n\
10880 $self cleanup\n\
10881 delete $session_\n\
10882 if [info exists tg_] {\n\
10883 delete $tg_\n\
10884 }\n\
10885 }\n\
10886 \n\
10887 Agent/SRM instproc start {} {\n\
10888 $self instvar node_ dst_addr_   ;# defined in Agent base class\n\
10889 set dst_addr_ [expr $dst_addr_] ; # get rid of possibly leading 0x etc.\n\
10890 $self cmd start\n\
10891 \n\
10892 $node_ join-group $self $dst_addr_\n\
10893 \n\
10894 $self instvar ns_ session_ sessionFunction_\n\
10895 set session_ [new $sessionFunction_ $ns_ $self]\n\
10896 $session_ schedule\n\
10897 }\n\
10898 \n\
10899 Agent/SRM instproc start-source {} {\n\
10900 $self instvar tg_\n\
10901 if ![info exists tg_] {\n\
10902 error \"No source defined for agent $self\"\n\
10903 }\n\
10904 $tg_ start\n\
10905 }\n\
10906 \n\
10907 Agent/SRM instproc sessionFunction f {\n\
10908 $self instvar sessionFunction_\n\
10909 set sessionFunction_ $f\n\
10910 }\n\
10911 \n\
10912 Agent/SRM instproc requestFunction f {\n\
10913 $self instvar requestFunction_\n\
10914 set requestFunction_ $f\n\
10915 }\n\
10916 \n\
10917 Agent/SRM instproc repairFunction f {\n\
10918 $self instvar repairFunction_\n\
10919 set repairFunction_ $f\n\
10920 }\n\
10921 \n\
10922 Agent/SRM instproc groupSize? {} {\n\
10923 $self set groupSize_\n\
10924 }\n\
10925 \n\
10926 global alpha\n\
10927 if ![info exists alpha] {\n\
10928 set alpha   0.25\n\
10929 }\n\
10930 \n\
10931 proc ewma {ave cur} {\n\
10932 if {$ave < 0} {\n\
10933 return $cur\n\
10934 } else {\n\
10935 global alpha\n\
10936 return [expr (1 - $alpha) * $ave + $alpha * $cur]\n\
10937 }\n\
10938 }\n\
10939 \n\
10940 proc instantaneous {ave cur} {\n\
10941 set cur\n\
10942 }\n\
10943 \n\
10944 Agent/SRM instproc compute-ave var {\n\
10945 $self instvar stats_\n\
10946 set stats_(ave-$var) [ewma $stats_(ave-$var) $stats_($var)]\n\
10947 }\n\
10948 \n\
10949 \n\
10950 Agent/SRM instproc recv {type args} {\n\
10951 eval $self recv-$type $args\n\
10952 }\n\
10953 \n\
10954 Agent/SRM instproc recv-data {sender msgid} {\n\
10955 $self instvar pending_\n\
10956 if ![info exists pending_($sender:$msgid)] {\n\
10957 error \"Oy vey!  How did we get here?\"\n\
10958 }\n\
10959 if {[$pending_($sender:$msgid) set round_] == 1} {\n\
10960 $pending_($sender:$msgid) cancel DATA\n\
10961 $pending_($sender:$msgid) evTrace Q DATA\n\
10962 delete $pending_($sender:$msgid)\n\
10963 unset pending_($sender:$msgid)\n\
10964 } else {\n\
10965 $pending_($sender:$msgid) recv-repair\n\
10966 }\n\
10967 }\n\
10968 \n\
10969 Agent/SRM instproc mark-period period {\n\
10970 $self compute-ave $period\n\
10971 $self set stats_($period) 0\n\
10972 }\n\
10973 \n\
10974 Agent/SRM instproc request {sender args} {\n\
10975 $self instvar pending_ ns_ requestFunction_\n\
10976 set newReq 0\n\
10977 foreach msgid $args {\n\
10978 if [info exists pending_($sender:$msgid)] {\n\
10979 error \"duplicate loss detection in agent\"\n\
10980 }\n\
10981 set pending_($sender:$msgid) [new $requestFunction_ $ns_ $self]\n\
10982 $pending_($sender:$msgid) set-params $sender $msgid\n\
10983 $pending_($sender:$msgid) schedule\n\
10984 \n\
10985 if ![info exists old_($sender:$msgid)] {\n\
10986 incr newReq\n\
10987 }\n\
10988 }\n\
10989 if $newReq {\n\
10990 $self mark-period dup-req\n\
10991 }\n\
10992 }\n\
10993 \n\
10994 Agent/SRM instproc update-ave {type delay} {\n\
10995 $self instvar stats_\n\
10996 set stats_(${type}-delay) $delay\n\
10997 $self compute-ave ${type}-delay\n\
10998 }\n\
10999 \n\
11000 Agent/SRM instproc recv-request {requestor round sender msgid} {\n\
11001 $self instvar pending_ stats_\n\
11002 if [info exists pending_($sender:$msgid)] {\n\
11003 if { $round == 1 } {\n\
11004 incr stats_(dup-req) [$pending_($sender:$msgid) \\\n\
11005 dup-request?]\n\
11006 }\n\
11007 $pending_($sender:$msgid) recv-request\n\
11008 } else {\n\
11009 $self repair $requestor $sender $msgid\n\
11010 }\n\
11011 }\n\
11012 \n\
11013 Agent/SRM instproc repair {requestor sender msgid} {\n\
11014 $self instvar pending_ ns_ repairFunction_\n\
11015 if [info exists pending_($sender:$msgid)] {\n\
11016 error \"duplicate repair detection in agent??  really??\"\n\
11017 }\n\
11018 set pending_($sender:$msgid) [new $repairFunction_ $ns_ $self]\n\
11019 $pending_($sender:$msgid) set requestor_ $requestor\n\
11020 $pending_($sender:$msgid) set-params $sender $msgid\n\
11021 $pending_($sender:$msgid) schedule\n\
11022 $self mark-period dup-rep\n\
11023 }\n\
11024 \n\
11025 Agent/SRM instproc recv-repair {round sender msgid} {\n\
11026 $self instvar pending_ stats_\n\
11027 if ![info exists pending_($sender:$msgid)] {\n\
11028 $self instvar trace_ ns_ node_ \n\
11029 if [info exists trace_] {\n\
11030 }\n\
11031 } else {\n\
11032 if { $round == 1 } {\n\
11033 incr stats_(dup-rep) [$pending_($sender:$msgid) \\\n\
11034 dup-repair?]\n\
11035 }\n\
11036 $pending_($sender:$msgid) recv-repair\n\
11037 }\n\
11038 }\n\
11039 \n\
11040 Agent/SRM/Fixed instproc repair args {\n\
11041 $self set D1_ [expr log10([$self set groupSize_])]\n\
11042 $self set D2_ [expr log10([$self set groupSize_])]\n\
11043 eval $self next $args\n\
11044 }\n\
11045 \n\
11046 \n\
11047 Agent/SRM instproc clear {obj s m} {\n\
11048 $self instvar pending_ done_ old_ logfile_\n\
11049 set done_($s:$m) $obj\n\
11050 set old_($s:$m) [$obj set round_]\n\
11051 if [info exists logfile_] {\n\
11052 $obj dump-stats $logfile_\n\
11053 }\n\
11054 unset pending_($s:$m)\n\
11055 if {[array size done_] > 32} {\n\
11056 $self instvar ns_\n\
11057 $ns_ at [expr [$ns_ now] + 0.01] \"$self cleanup\"\n\
11058 }\n\
11059 }\n\
11060 \n\
11061 Agent/SRM instproc round? {s m} {\n\
11062 $self instvar old_\n\
11063 if [info exists old_($s:$m)] {\n\
11064 return $old_($s:$m)\n\
11065 } else {\n\
11066 return 0\n\
11067 }\n\
11068 }\n\
11069 \n\
11070 Agent/SRM instproc cleanup {} {\n\
11071 $self instvar done_\n\
11072 if [info exists done_] {\n\
11073 foreach i [array names done_] {\n\
11074 delete $done_($i)\n\
11075 }\n\
11076 unset done_\n\
11077 }\n\
11078 }\n\
11079 \n\
11080 Agent/SRM instproc trace file {\n\
11081 $self set trace_ $file\n\
11082 }\n\
11083 \n\
11084 Agent/SRM instproc log file {\n\
11085 $self set logfile_ $file\n\
11086 }\n\
11087 \n\
11088 SRM instproc init {ns agent} {\n\
11089 $self next\n\
11090 $self instvar ns_ agent_ nid_ distf_\n\
11091 set ns_ $ns\n\
11092 set agent_ $agent\n\
11093 set nid_ [[$agent_ set node_] id]\n\
11094 set distf_ [$agent_ set distanceCompute_]\n\
11095 if ![catch \"$agent_ set trace_\" traceVar] {\n\
11096 $self set trace_ $traceVar\n\
11097 }\n\
11098 $self array set times_ [list        \\\n\
11099 startTime [$ns_ now] serviceTime -1 distance -1]\n\
11100 }\n\
11101 \n\
11102 SRM instproc set-params {sender msgid} {\n\
11103 $self next\n\
11104 $self instvar agent_ sender_ msgid_ round_ sent_\n\
11105 set sender_ $sender\n\
11106 set msgid_  $msgid\n\
11107 set round_  [$agent_ round? $sender_ $msgid_]\n\
11108 set sent_   0\n\
11109 }\n\
11110 \n\
11111 SRM instproc cancel {} {\n\
11112 $self instvar ns_ eventID_\n\
11113 if [info exists eventID_] {\n\
11114 $ns_ cancel $eventID_\n\
11115 unset eventID_\n\
11116 }\n\
11117 }\n\
11118 \n\
11119 SRM instproc schedule {} {\n\
11120 $self instvar round_\n\
11121 incr round_\n\
11122 }\n\
11123 \n\
11124 SRM instproc distance? node {\n\
11125 $self instvar agent_ times_ distf_\n\
11126 set times_(distance) [$distf_ $times_(distance) \\\n\
11127 [$agent_ distance? $node]]\n\
11128 }\n\
11129 \n\
11130 SRM instproc serviceTime {} {\n\
11131 $self instvar ns_ times_\n\
11132 set times_(serviceTime) [expr ([$ns_ now] - $times_(startTime)) / \\\n\
11133 ( 2 * $times_(distance))]\n\
11134 }\n\
11135 \n\
11136 SRM instproc logpfx fp {\n\
11137 $self instvar ns_ nid_ sender_ msgid_ round_\n\
11138 puts -nonewline $fp [format \"%7.4f\" [$ns_ now]]\n\
11139 puts -nonewline $fp \" n $nid_ m <$sender_:$msgid_> r $round_ \"\n\
11140 }\n\
11141 \n\
11142 SRM instproc nam-event-pfx fp {\n\
11143 $self instvar ns_ nid_ sender_ msgid_ round_\n\
11144 puts -nonewline $fp \"E \"\n\
11145 puts -nonewline $fp [format \"%8.6f\" [$ns_ now]]\n\
11146 puts -nonewline $fp \" n $nid_ m <$sender_:$msgid_> r $round_ \"\n\
11147 }\n\
11148 \n\
11149 SRM instproc ns-event-pfx fp {\n\
11150 $self instvar ns_ nid_ sender_ msgid_ round_\n\
11151 puts -nonewline $fp \"E \"\n\
11152 puts -nonewline $fp [format \"%8.6f\" [$ns_ now]]\n\
11153 puts -nonewline $fp \" n $nid_ m <$sender_:$msgid_> r $round_ \"\n\
11154 }\n\
11155 \n\
11156 SRM instproc dump-stats fp {\n\
11157 $self instvar times_ statistics_\n\
11158 $self logpfx $fp\n\
11159 puts -nonewline $fp \"type [string range [$self info class] 4 end] \"\n\
11160 puts $fp \"[array get times_] [array get statistics_]\"\n\
11161 }\n\
11162 \n\
11163 SRM instproc evTrace {tag type args} {\n\
11164 $self instvar trace_ ns_\n\
11165 $ns_ instvar eventTraceAll_ traceAllFile_ namtraceAllFile_\n\
11166 \n\
11167 if [info exists eventTraceAll_] {\n\
11168 if {$eventTraceAll_ == 1} {\n\
11169 if [info exists traceAllFile_] {\n\
11170 $self ns-event-pfx $traceAllFile_\n\
11171 puts -nonewline $traceAllFile_ \"$tag $type\"\n\
11172 foreach elem $args {\n\
11173 puts -nonewline $traceAllFile_ \" $elem\"\n\
11174 }\n\
11175 puts $traceAllFile_ {}\n\
11176 }\n\
11177 \n\
11178 }\n\
11179 }\n\
11180 \n\
11181 if [info exists trace_] {\n\
11182 $self logpfx $trace_\n\
11183 puts -nonewline $trace_ \"$tag $type\"\n\
11184 foreach elem $args {\n\
11185 puts -nonewline $trace_ \" $elem\"\n\
11186 }\n\
11187 puts $trace_ {}\n\
11188 }\n\
11189 }\n\
11190 \n\
11191 \n\
11192 SRM/request instproc init args {\n\
11193 eval $self next $args\n\
11194 $self array set statistics_ \"dupRQST 0 dupREPR 0 #sent 0 backoff 0\"\n\
11195 }\n\
11196 \n\
11197 SRM/request instproc set-params args {\n\
11198 eval $self next $args\n\
11199 $self instvar agent_ sender_\n\
11200 foreach var {C1_ C2_} {\n\
11201 if ![catch \"$agent_ set $var\" val] {\n\
11202 $self instvar $var\n\
11203 set $var $val\n\
11204 }\n\
11205 }\n\
11206 $self distance? $sender_\n\
11207 $self instvar backoff_ backoffCtr_ backoffLimit_\n\
11208 set backoff_ 1\n\
11209 set backoffCtr_ 0\n\
11210 set backoffLimit_ [$agent_ set requestBackoffLimit_]\n\
11211 \n\
11212 $self evTrace Q DETECT\n\
11213 }\n\
11214 \n\
11215 SRM/request instproc dup-request? {} {\n\
11216 $self instvar ns_ round_ ignore_\n\
11217 if {$round_ == 2 && [$ns_ now] <= $ignore_} {\n\
11218 return 1\n\
11219 } else {\n\
11220 return 0\n\
11221 }\n\
11222 }\n\
11223 \n\
11224 SRM/request instproc dup-repair? {} {\n\
11225 return 0\n\
11226 }\n\
11227 \n\
11228 SRM/request instproc backoff? {} {\n\
11229 $self instvar backoff_ backoffCtr_ backoffLimit_\n\
11230 set retval $backoff_\n\
11231 if {[incr backoffCtr_] <= $backoffLimit_} {\n\
11232 incr backoff_ $backoff_\n\
11233 }\n\
11234 set retval\n\
11235 }\n\
11236 \n\
11237 SRM/request instproc compute-delay {} {\n\
11238 $self instvar C1_ C2_\n\
11239 set rancomp [expr $C1_ + $C2_ * [uniform 0 1]]\n\
11240 \n\
11241 $self instvar sender_ backoff_\n\
11242 set dist [$self distance? $sender_]\n\
11243 $self evTrace Q INTERVALS C1 $C1_ C2 $C2_ d $dist i $backoff_\n\
11244 set delay [expr $rancomp * $dist]\n\
11245 }\n\
11246 \n\
11247 SRM/request instproc schedule {} {\n\
11248 $self instvar ns_ eventID_ delay_\n\
11249 $self next\n\
11250 set now [$ns_ now]\n\
11251 set delay_ [expr [$self compute-delay] * [$self backoff?]]\n\
11252 set fireTime [expr $now + $delay_]\n\
11253 \n\
11254 $self evTrace Q NTIMER at $fireTime\n\
11255 \n\
11256 set eventID_ [$ns_ at $fireTime \"$self send-request\"]\n\
11257 }\n\
11258 \n\
11259 SRM/request instproc cancel type {\n\
11260 $self next\n\
11261 if {$type == \"REQUEST\" || $type == \"REPAIR\"} {\n\
11262 $self instvar agent_ round_\n\
11263 if {$round_ == 1} {\n\
11264 $agent_ update-ave req [$self serviceTime]\n\
11265 }\n\
11266 }\n\
11267 }\n\
11268 \n\
11269 SRM/request instproc send-request {} {\n\
11270 $self instvar agent_ round_ sender_ msgid_ sent_ round_\n\
11271 $self evTrace Q SENDNACK\n\
11272 \n\
11273 $agent_ send request $round_ $sender_ $msgid_\n\
11274 \n\
11275 $self instvar statistics_\n\
11276 incr statistics_(#sent)\n\
11277 set sent_ $round_\n\
11278 }\n\
11279 \n\
11280 SRM/request instproc recv-request {} {\n\
11281 $self instvar ns_ agent_ round_ delay_ ignore_ statistics_\n\
11282 if {[info exists ignore_] && [$ns_ now] < $ignore_} {\n\
11283 incr statistics_(dupRQST)\n\
11284 } else {\n\
11285 $self cancel REQUEST\n\
11286 $self schedule          ;# or rather, reschedule-rqst \n\
11287 set ignore_ [expr [$ns_ now] + ($delay_ / 2)]\n\
11288 incr statistics_(backoff)\n\
11289 $self evTrace Q NACK IGNORE-BACKOFF $ignore_\n\
11290 }\n\
11291 }\n\
11292 \n\
11293 SRM/request instproc recv-repair {} {\n\
11294 $self instvar ns_ agent_ sender_ msgid_ ignore_ eventID_\n\
11295 if [info exists eventID_] {\n\
11296 $self serviceTime\n\
11297 set ignore_ [expr [$ns_ now] + 3 * [$self distance? $sender_]]\n\
11298 $ns_ at $ignore_ \"$agent_ clear $self $sender_ $msgid_\"\n\
11299 $self cancel REPAIR\n\
11300 $self evTrace Q REPAIR IGNORES $ignore_\n\
11301 } else {        ;# we must be in the 3dS,B holdDown interval\n\
11302 $self instvar statistics_\n\
11303 incr statistics_(dupREPR)\n\
11304 }\n\
11305 }\n\
11306 \n\
11307 SRM/repair instproc init args {\n\
11308 eval $self next $args\n\
11309 $self array set statistics_ \"dupRQST 0 dupREPR 0 #sent 0\"\n\
11310 }\n\
11311 \n\
11312 SRM/repair instproc set-params args {\n\
11313 eval $self next $args\n\
11314 $self instvar agent_ requestor_\n\
11315 foreach var {D1_ D2_} {\n\
11316 if ![catch \"$agent_ set $var\" val] {\n\
11317 $self instvar $var\n\
11318 set $var $val\n\
11319 }\n\
11320 }\n\
11321 $self distance? $requestor_\n\
11322 $self evTrace P NACK from $requestor_\n\
11323 }\n\
11324 \n\
11325 SRM/repair instproc dup-request? {} {\n\
11326 return 0\n\
11327 }\n\
11328 \n\
11329 SRM/repair instproc dup-repair? {} {\n\
11330 $self instvar ns_ round_\n\
11331 if {$round_ == 1} {     ;# because repairs do not reschedule\n\
11332 return 1\n\
11333 } else {\n\
11334 return 0\n\
11335 }\n\
11336 }\n\
11337 SRM/repair instproc compute-delay {} {\n\
11338 $self instvar D1_ D2_\n\
11339 set rancomp [expr $D1_ + $D2_ * [uniform 0 1]]\n\
11340 \n\
11341 $self instvar requestor_\n\
11342 set dist [$self distance? $requestor_]\n\
11343 $self evTrace P INTERVALS D1 $D1_ D2 $D2_ d $dist\n\
11344 set delay [expr $rancomp * $dist]\n\
11345 }\n\
11346 \n\
11347 SRM/repair instproc schedule {} {\n\
11348 $self instvar ns_ eventID_\n\
11349 $self next\n\
11350 set fireTime [expr [$ns_ now] + [$self compute-delay]]\n\
11351 \n\
11352 $self evTrace P RTIMER at $fireTime\n\
11353 \n\
11354 set eventID_ [$ns_ at $fireTime \"$self send-repair\"]\n\
11355 }\n\
11356 \n\
11357 SRM/repair instproc cancel type {\n\
11358 $self next\n\
11359 if {$type == \"REQUEST\" || $type == \"REPAIR\"} {\n\
11360 $self instvar agent_ round_\n\
11361 if {$round_ == 1} {\n\
11362 $agent_ update-ave rep [$self serviceTime]\n\
11363 }\n\
11364 }\n\
11365 }\n\
11366 \n\
11367 SRM/repair instproc send-repair {} {\n\
11368 $self instvar ns_ agent_ round_ sender_ msgid_ requestor_ sent_ round_\n\
11369 $self evTrace P SENDREP\n\
11370 \n\
11371 $agent_ set requestor_ $requestor_\n\
11372 $agent_ send repair $round_ $sender_ $msgid_\n\
11373 \n\
11374 $self instvar statistics_\n\
11375 incr statistics_(#sent)\n\
11376 set sent_ $round_\n\
11377 }\n\
11378 \n\
11379 SRM/repair instproc recv-request {} {\n\
11380 $self instvar statistics_\n\
11381 incr statistics_(dupRQST)\n\
11382 }\n\
11383 \n\
11384 SRM/repair instproc recv-repair {} {\n\
11385 $self instvar ns_ agent_ round_ sender_ msgid_ eventID_ requestor_\n\
11386 if [info exists eventID_] {\n\
11387 set holdDown [expr [$ns_ now] +     \\\n\
11388 3 * [$self distance? $requestor_]]\n\
11389 $ns_ at $holdDown \"$agent_ clear $self $sender_ $msgid_\"\n\
11390 $self cancel REPAIR\n\
11391 $self evTrace P REPAIR IGNORES $holdDown\n\
11392 } else {        ;# we must in the 3dS,B holdDown interval\n\
11393 $self instvar statistics_\n\
11394 incr statistics_(dupREPR)\n\
11395 }\n\
11396 }\n\
11397 \n\
11398 SRM/session instproc init args {\n\
11399 eval $self next $args\n\
11400 $self instvar agent_ sessionDelay_ round_\n\
11401 set sessionDelay_ [$agent_ set sessionDelay_]\n\
11402 set round_ 1\n\
11403 $self array set statistics_ \"#sent 0\"\n\
11404 \n\
11405 $self set sender_ 0\n\
11406 $self set msgid_  0\n\
11407 }\n\
11408 \n\
11409 SRM/session instproc delete {} {\n\
11410 $self instvar $ns_ eventID_\n\
11411 $ns_ cancel $eventID_\n\
11412 $self next\n\
11413 }\n\
11414 \n\
11415 SRM/session instproc schedule {} {\n\
11416 $self instvar ns_ agent_ sessionDelay_ eventID_\n\
11417 \n\
11418 $self next\n\
11419 \n\
11420 \n\
11421 set sessionDelay_ [$agent_ set sessionDelay_]\n\
11422 set fireTime [expr $sessionDelay_ * [uniform 0.9 1.1]]\n\
11423 \n\
11424 set eventID_ [$ns_ at [expr [$ns_ now] + $fireTime]     \\\n\
11425 \"$self send-session\"]\n\
11426 }\n\
11427 \n\
11428 SRM/session instproc send-session {} {\n\
11429 $self instvar agent_ statistics_\n\
11430 $agent_ send session\n\
11431 $self evTrace S SESSION\n\
11432 incr statistics_(#sent)\n\
11433 $self schedule\n\
11434 }\n\
11435 \n\
11436 SRM/session instproc evTrace args {}    ;# because I don't want to trace\n\
11437 \n\
11438 Class SRM/session/log-scaled -superclass SRM/session\n\
11439 SRM/session/log-scaled instproc schedule {} {\n\
11440 $self instvar ns_ agent_ sessionDelay_ eventID_\n\
11441 \n\
11442 set fireTime [expr $sessionDelay_ * [uniform 0.9 1.1] * \\\n\
11443 (1 + log([$agent_ set groupSize_])) ]\n\
11444 \n\
11445 set eventID_ [$ns_ at [expr [$ns_ now] + $fireTime]     \\\n\
11446 \"$self send-session\"]\n\
11447 }\n\
11448 Agent/SRM/SSM set group_scope_ 32\n\
11449 Agent/SRM/SSM set local_scope_ 2\n\
11450 Agent/SRM/SSM set scope_flag_  2\n\
11451 Agent/SRM/SSM set rep_id_ 0\n\
11452 Agent/SRM/SSM set numrep_ 0\n\
11453 Agent/SRM/SSM set repthresh_up_ 100\n\
11454 Agent/SRM/SSM set repthresh_low_ 7\n\
11455 Agent/SRM/SSM set Z1_ 1.5\n\
11456 Agent/SRM/SSM set S1_ 0.0\n\
11457 Agent/SRM/SSM set S2_ 3.0\n\
11458 \n\
11459 Agent/SRM/SSM instproc init {} {\n\
11460 $self next\n\
11461 $self instvar numrep_ numloc_ repthresh_up_ repthresh_low_ Z1_ \\\n\
11462 S1_ S2_\n\
11463 set numrep_ 0\n\
11464 set numloc_ 0\n\
11465 set repthresh_up_ [$class set repthresh_up_]\n\
11466 set repthresh_low_ [$class set repthresh_low_]\n\
11467 set Z1_ [$class set Z1_]\n\
11468 set S1_ [$class set S1_]\n\
11469 set S2_ [$class set S2_]\n\
11470 }\n\
11471 \n\
11472 Agent/SRM/SSM instproc start {} {\n\
11473 $self next \n\
11474 $self instvar deactivateID_ sessionDelay_ ns_\n\
11475 set now [expr [$ns_ now]]\n\
11476 set deactivateID_ [$ns_ at [expr $now + 3 * $sessionDelay_] \\\n\
11477 \"$self deactivate-reps $now\"]\n\
11478 }\n\
11479 \n\
11480 \n\
11481 Agent/SRM/SSM instproc repid { rep} {\n\
11482 \n\
11483 $self instvar rep_id_\n\
11484 $self set rep_id_ [$rep set addr_]\n\
11485 $self ch-rep \n\
11486 \n\
11487 }\n\
11488 \n\
11489 Agent/SRM/SSM instproc member-scope {scope } {\n\
11490 $self instvar scope_flag_\n\
11491 $self set scope_flag_ $scope\n\
11492 \n\
11493 }\n\
11494 \n\
11495 Agent/SRM/SSM instproc local-member? {} {\n\
11496 $self instvar scope_flag_\n\
11497 if {$scope_flag_ == 1 } {\n\
11498 return 1\n\
11499 } else {\n\
11500 return 0\n\
11501 }\n\
11502 }\n\
11503 \n\
11504 Agent/SRM/SSM instproc global-member? {} {\n\
11505 $self instvar scope_flag_\n\
11506 if {$scope_flag_ == 2 } {\n\
11507 return 1\n\
11508 } else {\n\
11509 return 0\n\
11510 }\n\
11511 }\n\
11512 \n\
11513 Agent/SRM/SSM instproc local-member {} {\n\
11514 $self member-scope 1    \n\
11515 }\n\
11516 \n\
11517 Agent/SRM/SSM instproc global-rep {} {\n\
11518 $self member-scope 2\n\
11519 set rep_id_ [$self set addr_]\n\
11520 $self ch-rep\n\
11521 }\n\
11522 \n\
11523 Agent/SRM/SSM instproc set-local-scope {scope} {\n\
11524 $self instvar local_scope_\n\
11525 $self set local_scope_ $scope\n\
11526 }\n\
11527 \n\
11528 Agent/SRM/SSM instproc set-global-scope {scope} {\n\
11529 $self instvar global-scope\n\
11530 $self set global-scope $scope\n\
11531 }\n\
11532 \n\
11533 Agent/SRM/SSM instproc set-repid {rep} {\n\
11534 $self instvar rep_id_\n\
11535 $self set rep_id_ [$rep set addr_]\n\
11536 $self ch-rep \n\
11537 }\n\
11538 \n\
11539 Agent/SRM/SSM instproc dump-reps {} {\n\
11540 $self instvar ns_ activerep_ numrep_\n\
11541 puts \"[ft $ns_ $self] numreps: $numrep_\"\n\
11542 if [info exists activerep_] {\n\
11543 foreach i [array names activerep_] {\n\
11544 set rtime [$activerep_($i) set recvTime_]\n\
11545 set ttl [$activerep_($i) set ttl_]\n\
11546 puts \"rep: $i recvtime: [ftime $rtime] ttl: $ttl\"\n\
11547 }\n\
11548 \n\
11549 }\n\
11550 }\n\
11551 \n\
11552 Agent/SRM/SSM instproc dump-locs {} {\n\
11553 $self instvar ns_ activeloc_ numloc_\n\
11554 puts \"[ft $ns_ $self] numlocs: $numloc_\"\n\
11555 if [info exists activeloc_] {\n\
11556 foreach i [array names activeloc_] {\n\
11557 set rtime [$activeloc_($i) set recvTime_]\n\
11558 set ttl [$activeloc_($i) set ttl_]\n\
11559 set repid [$activeloc_($i) set repid_]\n\
11560 puts \"loc: $i recvtime: [ftime $rtime] ttl: \\\n\
11561 $ttl repid: $repid\"\n\
11562 }\n\
11563 \n\
11564 }\n\
11565 }\n\
11566 \n\
11567 \n\
11568 Agent/SRM/SSM instproc send-session {} {\n\
11569 $self instvar session_\n\
11570 $session_ send-session\n\
11571 }\n\
11572 \n\
11573 \n\
11574 \n\
11575 \n\
11576 Agent/SRM/SSM instproc repchange-action {} {\n\
11577 $self instvar rep_id_ tentativerep_ tentativettl_\n\
11578 $self instvar ns_\n\
11579 $self cur-num-reps\n\
11580 set rep_id_ $tentativerep_\n\
11581 puts \"[ft $ns_ $self] chrep rep : $tentativerep_\\\n\
11582 ttl : $tentativettl_\"\n\
11583 $self set-local-scope $tentativettl_\n\
11584 $self local-member\n\
11585 $self ch-rep\n\
11586 $self send-session\n\
11587 }\n\
11588 \n\
11589 \n\
11590 Agent/SRM/SSM instproc recv-lsess {sender repid ttl} {\n\
11591 \n\
11592 $self instvar activeloc_ ns_ numloc_ sessionDelay_ deactivatelocID_\n\
11593 $self instvar activerep_ numrep_\n\
11594 $self instvar ch_localID_ tentativerep_ addr_ rep_id_ tentativettl_\n\
11595 \n\
11596 if [info exists activeloc_($sender)] {\n\
11597 $activeloc_($sender) recv-lsess $repid $ttl\n\
11598 } else {\n\
11599 set activeloc_($sender) [new SRMinfo/loc $sender]\n\
11600 incr numloc_\n\
11601 $activeloc_($sender) set-params $ns_ $self\n\
11602 $activeloc_($sender) recv-lsess $repid $ttl\n\
11603 }\n\
11604 \n\
11605 \n\
11606 if [info exists activerep_($sender)] {\n\
11607 delete $activerep_($sender)\n\
11608 unset activerep_($sender)\n\
11609 incr numrep_ -1\n\
11610 if [info exists ch_localID_] {\n\
11611 if {[info exists tentativerep_] && $tentativerep_ == $sender } {\n\
11612 $self cur-num-reps\n\
11613 }\n\
11614 if { $repid == $addr_} {\n\
11615 $ns_ cancel $ch_localID_\n\
11616 $self unset ch_localID_\n\
11617 $self check-status\n\
11618 }\n\
11619 }\n\
11620 if { [$self local-member?]} {\n\
11621 if { $sender == $rep_id_} {\n\
11622 $self repchange-action\n\
11623 }\n\
11624 } else {\n\
11625 if { $sender == $rep_id_} {\n\
11626 puts \"[ft $ns_ $self] error\"\n\
11627 \n\
11628 }\n\
11629 }           \n\
11630 }\n\
11631 \n\
11632 set time [expr [$ns_ now] - 3 * $sessionDelay_]\n\
11633 if [info exists deactivatelocID_] {\n\
11634 $ns_ cancel $deactivatelocID_\n\
11635 unset deactivatelocID_\n\
11636 }\n\
11637 $self deactivate-locs $time\n\
11638 }\n\
11639 \n\
11640 \n\
11641 Agent/SRM/SSM instproc recv-gsess {sender ttl} {\n\
11642 $self instvar activerep_ ns_ numrep_ sessionDelay_\n\
11643 $self instvar deactivateID_ local_scope_\n\
11644 \n\
11645 $self instvar activeloc_ numloc_\n\
11646 if [info exists activerep_($sender)] {\n\
11647 $activerep_($sender) recv-gsess $ttl\n\
11648 } else {\n\
11649 set activerep_($sender) [new SRMinfo/rep $sender]\n\
11650 incr numrep_\n\
11651 $activerep_($sender) set-params $ns_ $self\n\
11652 $activerep_($sender) recv-gsess $ttl\n\
11653 }\n\
11654 set time [expr [$ns_ now] - 3 * $sessionDelay_]\n\
11655 if [info exists deactivateID_] {\n\
11656 $ns_ cancel $deactivateID_\n\
11657 unset deactivateID_\n\
11658 }\n\
11659 if [info exists activeloc_($sender)] {\n\
11660 delete $activeloc_($sender)\n\
11661 unset activeloc_($sender)\n\
11662 incr numloc_ -1\n\
11663 }\n\
11664 if { [$self local-member?]} {\n\
11665 if {$ttl < $local_scope_} {\n\
11666 set rep_id_ $sender\n\
11667 puts \"[ft $ns_ $self] closerrep rep : $sender \\\n\
11668 ttl : $ttl\"\n\
11669 $self set-local-scope $ttl\n\
11670 $self local-member\n\
11671 $self ch-rep\n\
11672 $self send-session\n\
11673 }           \n\
11674 }\n\
11675 $self deactivate-reps $time\n\
11676 $self check-status\n\
11677 }\n\
11678 \n\
11679 Agent/SRM/SSM instproc bias {} {\n\
11680 $self instvar activerep_  ns_ sessionDelay_\n\
11681 set now [expr [$ns_ now]]\n\
11682 set biasfactor 0\n\
11683 set time [expr $now - 1.5 * $sessionDelay_]\n\
11684 if [info exists activerep_] {\n\
11685 foreach i [array names activerep_] {\n\
11686 set rtime [$activerep_($i) set recvTime_]\n\
11687 if { $rtime >= $time} {\n\
11688 incr biasfactor \n\
11689 }\n\
11690 }\n\
11691 }\n\
11692 return $biasfactor\n\
11693 }\n\
11694 \n\
11695 Agent/SRM/SSM instproc my-loc {} {\n\
11696 $self instvar activeloc_\n\
11697 set num 0\n\
11698 if [info exists activeloc_] {\n\
11699 foreach i [array names activeloc_] {\n\
11700 set repid [$activeloc_($i) set repid_]\n\
11701 if { $repid == [$self set addr_]} {\n\
11702 incr num\n\
11703 }\n\
11704 }\n\
11705 }\n\
11706 return $num\n\
11707 }\n\
11708 \n\
11709 Agent/SRM/SSM instproc cur-num-reps {} {\n\
11710 $self instvar activerep_  ns_ sessionDelay_ tentativerep_ tentativettl_ \n\
11711 $self instvar Z1_\n\
11712 set now [expr [$ns_ now]]\n\
11713 set num 0\n\
11714 set min_ttl 32\n\
11715 set time [expr $now - $Z1_ * $sessionDelay_]\n\
11716 if [info exists activerep_] {\n\
11717 foreach i [array names activerep_] {\n\
11718 set rtime [$activerep_($i) set recvTime_]\n\
11719 set ttl [$activerep_($i) set ttl_]\n\
11720 if { $rtime >= $time} {\n\
11721 if {$min_ttl > $ttl} {\n\
11722 set tentativerep_ $i\n\
11723 set min_ttl $ttl\n\
11724 }\n\
11725 incr num\n\
11726 }\n\
11727 }\n\
11728 }\n\
11729 set tentativettl_ $min_ttl\n\
11730 return $num\n\
11731 }\n\
11732 \n\
11733 Agent/SRM/SSM instproc compute-localdelay {} {\n\
11734 $self instvar S1_ S2_ sessionDelay_\n\
11735 set num [$self my-loc]\n\
11736 if {$num > 0} {\n\
11737 set rancomp [expr $S1_+ 1 + $S2_ * [uniform 0 1]]\n\
11738 } else {\n\
11739 set rancomp [expr $S1_+ $S2_ * [uniform 0 1]]\n\
11740 }\n\
11741 set delay [expr $rancomp * $sessionDelay_]\n\
11742 return $delay\n\
11743 }\n\
11744 \n\
11745 Agent/SRM/SSM instproc compute-globaldelay {} {\n\
11746 $self instvar S1_ S2_ sessionDelay_\n\
11747 set rancomp [expr $S1_ + $S2_ * [uniform 0 1]]\n\
11748 set delay [expr $rancomp * $sessionDelay_]\n\
11749 return $delay\n\
11750 }\n\
11751 \n\
11752 \n\
11753 \n\
11754 Agent/SRM/SSM instproc schedule-ch-local {} {\n\
11755 $self instvar ns_ ch_localID_\n\
11756 set now [$ns_ now]\n\
11757 set delay [$self compute-localdelay]\n\
11758 set fireTime [expr $now + $delay]\n\
11759 if [info exists ch_localID_] {\n\
11760 puts \"[new_ft $ns_ $self] scheduled called without cancel\"\n\
11761 $ns_ cancel $ch_localID_\n\
11762 unset ch_localID_\n\
11763 }\n\
11764 \n\
11765 set ch_localID_ [$ns_ at $fireTime \"$self ch-local\"]\n\
11766 puts \"[ft $ns_ $self] schlocal [ftime $fireTime] evid : $ch_localID_\"\n\
11767 \n\
11768 }\n\
11769 \n\
11770 Agent/SRM/SSM instproc schedule-ch-global {} {\n\
11771 $self instvar ns_ ch_globalID_\n\
11772 set now [$ns_ now]\n\
11773 set delay [$self compute-globaldelay]\n\
11774 set fireTime [expr $now + $delay]\n\
11775 if [info exists ch_globalID_] {\n\
11776 puts \"[ft $ns_ $self] glbscheduled called without cancel\"\n\
11777 $ns_ cancel $ch_globalID_\n\
11778 unset ch_globalID_\n\
11779 }\n\
11780 \n\
11781 set ch_globalID_ [$ns_ at $fireTime \"$self ch-global\"]\n\
11782 puts \"[ft $ns_ $self] schglobal [ftime $fireTime] evid : $ch_globalID_\"\n\
11783 \n\
11784 }\n\
11785 \n\
11786 \n\
11787 \n\
11788 \n\
11789 Agent/SRM/SSM instproc check-status {} {\n\
11790 $self instvar ns_ numrep_ repthresh_up_ ch_localID_\n\
11791 $self instvar ch_globalID_ repthresh_low_\n\
11792 if { $numrep_ > $repthresh_up_ }  {\n\
11793 if [info exists ch_localID_] {\n\
11794 return;\n\
11795 }\n\
11796 if { [$self local-member?]} {\n\
11797 if [info exists ch_globalID_] {\n\
11798 $ns_ cancel $ch_globalID_\n\
11799 unset ch_globalID_\n\
11800 }\n\
11801 return;\n\
11802 }\n\
11803 $self schedule-ch-local\n\
11804 return;\n\
11805 }\n\
11806 if {$numrep_ < $repthresh_low_} {\n\
11807 if [info exists ch_globalID_] {\n\
11808 return;\n\
11809 }\n\
11810 if { [$self global-member?]} {\n\
11811 if [info exists ch_localID_] {\n\
11812 $ns_ cancel $ch_localID_\n\
11813 unset ch_localID_\n\
11814 }\n\
11815 return;\n\
11816 }\n\
11817 $self schedule-ch-global\n\
11818 return;\n\
11819 }\n\
11820 if [info exists ch_localID_] {\n\
11821 $ns_ cancel $ch_localID_\n\
11822 unset ch_localID_\n\
11823 }\n\
11824 if [info exists ch_globalID_] {\n\
11825 $ns_ cancel $ch_globalID_\n\
11826 unset ch_globalID_\n\
11827 }\n\
11828 \n\
11829 }\n\
11830 \n\
11831 \n\
11832 \n\
11833 Agent/SRM/SSM instproc ch-local {} {\n\
11834 $self instvar repthresh_up_ tentativerep_ tentativettl_ ns_ rep_id_\n\
11835 if {[$self cur-num-reps] > $repthresh_up_} {\n\
11836 set rep_id_ $tentativerep_\n\
11837 puts \"[ft $ns_ $self] chlocal rep : $tentativerep_\\\n\
11838 ttl : $tentativettl_\"\n\
11839 $self local-member\n\
11840 $self ch-rep\n\
11841 $self send-session\n\
11842 $self set-local-scope $tentativettl_\n\
11843 }\n\
11844 if [info exists ch_localID_] {  \n\
11845 $ns_ cancel ch_localID_\n\
11846 unset ch_localID_\n\
11847 }\n\
11848 }\n\
11849 \n\
11850 Agent/SRM/SSM instproc ch-global {} {\n\
11851 $self instvar repthresh_low_ tentativerep_ tentativettl_ ns_ rep_id_\n\
11852 if {[$self cur-num-reps] < $repthresh_low_} {\n\
11853 set rep_id_ [$self set addr_]\n\
11854 puts \"[ft $ns_ $self] chglobal rep : $rep_id_\\\n\
11855 ttl : $tentativettl_\"\n\
11856 $self set-local-scope 0\n\
11857 $self global-rep\n\
11858 $self ch-rep\n\
11859 $self send-session\n\
11860 }\n\
11861 if [info exists ch_globalID_] { \n\
11862 $ns_ cancel ch_globalID_\n\
11863 unset ch_globalID_\n\
11864 }\n\
11865 }\n\
11866 \n\
11867 \n\
11868 Agent/SRM/SSM instproc deactivate-reps {time} {\n\
11869 $self instvar numrep_ activerep_ deactivateID_ ns_\n\
11870 $self instvar sessionDelay_ rep_id_\n\
11871 if [info exists activerep_] {\n\
11872 foreach i [array names activerep_] {\n\
11873 set rtime [$activerep_($i) set recvTime_]\n\
11874 if { $rtime < $time} {\n\
11875 delete $activerep_($i)\n\
11876 unset activerep_($i)\n\
11877 incr numrep_ -1\n\
11878 if { $i == $rep_id_ } {\n\
11879 puts \"[ft $ns_ $self] $i == $rep_id_\" \n\
11880 $self repchange-action\n\
11881 }\n\
11882 }\n\
11883 }\n\
11884 if {$numrep_ <= 0} {\n\
11885 unset activerep_\n\
11886 }\n\
11887 }\n\
11888 set now [expr [$ns_ now]]\n\
11889 set deactivateID_ [$ns_ at [expr $now + 3 * $sessionDelay_] \\\n\
11890 \"$self deactivate-reps $now\"]\n\
11891 }\n\
11892 \n\
11893 Agent/SRM/SSM instproc deactivate-locs {time} {\n\
11894 $self instvar numloc_ activeloc_ deactivatelocID_ ns_\n\
11895 $self instvar sessionDelay_ local_scope_\n\
11896 set maxttl 0\n\
11897 if [info exists activeloc_] {\n\
11898 foreach i [array names activeloc_] {\n\
11899 set rtime [$activeloc_($i) set recvTime_]\n\
11900 if { $rtime < $time} {\n\
11901 delete $activeloc_($i)\n\
11902 unset activeloc_($i)\n\
11903 incr numloc_ -1\n\
11904 } else {\n\
11905 if { [$self global-member?] } {\n\
11906 set ttl [$activeloc_($i) set ttl_]\n\
11907 if {$maxttl < $ttl} {\n\
11908 set maxttl $ttl\n\
11909 }\n\
11910 set local_scope_ $maxttl\n\
11911 }\n\
11912 }\n\
11913 }\n\
11914 if {$numloc_ <= 0} {\n\
11915 unset activeloc_\n\
11916 }\n\
11917 }\n\
11918 set now [expr [$ns_ now]]\n\
11919 set deactivatelocID_ [$ns_ at [expr $now + 3 * $sessionDelay_] \\\n\
11920 \"$self deactivate-locs $now\"]\n\
11921 }\n\
11922 \n\
11923 \n\
11924 \n\
11925 \n\
11926 Class SRMinfo\n\
11927 \n\
11928 SRMinfo set recvTime_ 0\n\
11929 \n\
11930 SRMinfo instproc init {sender} {\n\
11931 $self next\n\
11932 $self instvar sender_ \n\
11933 set sender_ $sender\n\
11934 }\n\
11935 \n\
11936 SRMinfo instproc set-params {ns agent} {\n\
11937 $self instvar ns_ agent_\n\
11938 set ns_ $ns\n\
11939 set agent_ $agent\n\
11940 }\n\
11941 \n\
11942 Class SRMinfo/rep -superclass SRMinfo\n\
11943 \n\
11944 SRMinfo/rep instproc recv-gsess {ttl} {\n\
11945 $self instvar recvTime_ ns_ ttl_\n\
11946 set now [$ns_ now]\n\
11947 set recvTime_ [expr $now]\n\
11948 set ttl_ [expr $ttl]\n\
11949 }\n\
11950 \n\
11951 Class SRMinfo/loc -superclass SRMinfo\n\
11952 \n\
11953 \n\
11954 SRMinfo/loc instproc recv-lsess {repid ttl} {\n\
11955 $self instvar recvTime_ ns_ ttl_ repid_\n\
11956 set now [$ns_ now]\n\
11957 set recvTime_ [expr $now]\n\
11958 set ttl_ [expr $ttl]\n\
11959 set repid_ [expr $repid]\n\
11960 }\n\
11961 Class McastMonitor\n\
11962 \n\
11963 McastMonitor instproc init {} {\n\
11964 $self instvar period_ ns_\n\
11965 \n\
11966 set ns_ [Simulator instance]\n\
11967 set period_ 0.03\n\
11968 }\n\
11969 \n\
11970 McastMonitor instproc trace-topo {} {\n\
11971 $self instvar ns_ period_\n\
11972 \n\
11973 $self trace-links [$ns_ all-links-list]\n\
11974 }\n\
11975 \n\
11976 McastMonitor instproc trace-links links {\n\
11977 $self instvar pktmon_\n\
11978 \n\
11979 foreach l $links {\n\
11980 set pktmon_($l) [new PktInTranMonitor]\n\
11981 $pktmon_($l) attach-link $l\n\
11982 $l add-pktmon $pktmon_($l)\n\
11983 }\n\
11984 }\n\
11985 \n\
11986 McastMonitor instproc filter {header field value} {\n\
11987 $self instvar pktmon_\n\
11988 \n\
11989 foreach index [array name pktmon_] {\n\
11990 $pktmon_($index) filter $header $field $value\n\
11991 }\n\
11992 }\n\
11993 \n\
11994 McastMonitor instproc pktintran {} {\n\
11995 $self instvar ns_ pktmon_\n\
11996 \n\
11997 set total 0\n\
11998 foreach index [array name pktmon_] {\n\
11999 if {[$index up?] == \"up\"} {\n\
12000 incr total [$pktmon_($index) pktintran]\n\
12001 }\n\
12002 }\n\
12003 return $total\n\
12004 }\n\
12005 \n\
12006 McastMonitor instproc print-trace {} {\n\
12007 $self instvar ns_ period_ file_\n\
12008 \n\
12009 if [info exists file_] {\n\
12010 puts $file_ \"[$ns_ now] [$self pktintran]\"\n\
12011 } else {\n\
12012 puts \"[$ns_ now] [$self pktintran]\"\n\
12013 }\n\
12014 $ns_ at [expr [$ns_ now] + $period_] \"$self print-trace\"\n\
12015 }\n\
12016 \n\
12017 McastMonitor instproc attach file {\n\
12018 $self instvar file_\n\
12019 set file_ $file\n\
12020 }\n\
12021 \n\
12022 \n\
12023 Class PktInTranMonitor\n\
12024 \n\
12025 PktInTranMonitor instproc init {} {\n\
12026 $self instvar period_ ns_ front_counter_ rear_counter_ front_filter_ rear_filter_ \n\
12027 set ns_ [Simulator instance]\n\
12028 set period_ 0.03\n\
12029 set front_counter_ [new PktCounter]\n\
12030 $front_counter_ set pktInTranMonitor_ $self\n\
12031 set front_filter_ [new Filter/MultiField]\n\
12032 $front_filter_ filter-target $front_counter_\n\
12033 \n\
12034 \n\
12035 set rear_counter_ [new PktCounter]\n\
12036 $rear_counter_ set pktInTranMonitor_ $self\n\
12037 set rear_filter_ [new Filter/MultiField]\n\
12038 $rear_filter_ filter-target $rear_counter_\n\
12039 }\n\
12040 \n\
12041 PktInTranMonitor instproc reset {} {\n\
12042 $self instvar front_counter_ rear_counter_  ns_ next_\n\
12043 $front_counter_ reset\n\
12044 $rear_counter_ reset\n\
12045 if {[info exist next_] && $next_ != 0} {\n\
12046 $next_ reset\n\
12047 }\n\
12048 }\n\
12049 \n\
12050 PktInTranMonitor instproc filter {header field value} {\n\
12051 $self instvar front_filter_ rear_filter_\n\
12052 $front_filter_ filter-field [PktHdr_offset PacketHeader/$header $field] $value\n\
12053 $rear_filter_ filter-field [PktHdr_offset PacketHeader/$header $field] $value\n\
12054 }\n\
12055 \n\
12056 PktInTranMonitor instproc attach-link link {\n\
12057 $self instvar front_filter_ rear_filter_ front_counter_ rear_counter_\n\
12058 \n\
12059 set tmp [$link head]\n\
12060 while {[$tmp target] != [$link link]} {\n\
12061 set tmp [$tmp target]\n\
12062 }\n\
12063 \n\
12064 $tmp target $front_filter_\n\
12065 $front_filter_ target [$link link]\n\
12066 $front_counter_ target [$link link]\n\
12067 \n\
12068 $rear_filter_ target [[$link link] target]\n\
12069 $rear_counter_ target [[$link link] target]\n\
12070 [$link link] target $rear_filter_\n\
12071 }\n\
12072 \n\
12073 PktInTranMonitor instproc attach file {\n\
12074 $self instvar file_\n\
12075 set file_ $file\n\
12076 }\n\
12077 \n\
12078 PktInTranMonitor instproc pktintran {} {\n\
12079 $self instvar front_counter_ rear_counter_ \n\
12080 return [expr [$front_counter_ value] - [$rear_counter_ value]]\n\
12081 }\n\
12082 \n\
12083 PktInTranMonitor instproc output {} {\n\
12084 $self instvar front_counter_ rear_counter_ ns_ file_ \n\
12085 \n\
12086 puts $file_ \"[$ns_ now] [expr [$front_counter_ value] - [$rear_counter_ value]]\"\n\
12087 }\n\
12088 \n\
12089 \n\
12090 PktInTranMonitor instproc periodical-output {} {\n\
12091 $self instvar period_ ns_\n\
12092 \n\
12093 $self output\n\
12094 $ns_ at [expr [$ns_ now] + $period_] \"$self periodical-output\"\n\
12095 }\n\
12096 \n\
12097 Simulator instproc all-links-list {} {\n\
12098 $self instvar link_\n\
12099 set links \"\"\n\
12100 foreach n [array names link_] {\n\
12101 lappend links $link_($n)\n\
12102 }\n\
12103 set links\n\
12104 }\n\
12105 \n\
12106 Link instproc add-pktmon pktmon {\n\
12107 $self instvar pktmon_\n\
12108 \n\
12109 if [info exists pktmon_] {\n\
12110 $pktmon set next_ $pktmon_\n\
12111 } else {\n\
12112 $pktmon set next_ 0\n\
12113 }\n\
12114 set pktmon_ $pktmon\n\
12115 }\n\
12116 \n\
12117 \n\
12118 set rlm_param(alpha) 4\n\
12119 set rlm_param(alpha) 2\n\
12120 set rlm_param(beta) 0.75\n\
12121 set rlm_param(init-tj) 1.5\n\
12122 set rlm_param(init-tj) 10\n\
12123 set rlm_param(init-tj) 5\n\
12124 set rlm_param(init-td) 5\n\
12125 set rlm_param(init-td-var) 2\n\
12126 set rlm_param(max) 600\n\
12127 set rlm_param(max) 60\n\
12128 set rlm_param(g1) 0.25\n\
12129 set rlm_param(g2) 0.25\n\
12130 \n\
12131 \n\
12132 \n\
12133 Class MMG\n\
12134 \n\
12135 MMG instproc init { levels } {\n\
12136 $self next\n\
12137 \n\
12138 $self instvar debug_ env_ maxlevel_\n\
12139 set debug_ 0\n\
12140 set env_ [lindex [split [$self info class] /] 1]\n\
12141 set maxlevel_ $levels\n\
12142 \n\
12143 global rlm_debug_flag\n\
12144 if [info exists rlm_debug_flag] {\n\
12145 set debug_ $rlm_debug_flag\n\
12146 }\n\
12147 \n\
12148 $self instvar TD TDVAR state_ subscription_\n\
12149 global rlm_param\n\
12150 set TD $rlm_param(init-td)\n\
12151 set TDVAR $rlm_param(init-td-var)\n\
12152 set state_ /S\n\
12153 \n\
12154 $self instvar layer_ layers_\n\
12155 set i 1\n\
12156 while { $i <= $maxlevel_ } {\n\
12157 set layer_($i) [$self create-layer [expr $i - 1]]\n\
12158 lappend layers_ $layer_($i)\n\
12159 incr i\n\
12160 }\n\
12161 \n\
12162 set subscription_ 0\n\
12163 $self add-layer\n\
12164 \n\
12165 set state_ /S\n\
12166 \n\
12167 $self set_TJ_timer\n\
12168 }\n\
12169 \n\
12170 MMG instproc set-state s {\n\
12171 $self instvar state_\n\
12172 set old $state_\n\
12173 set state_ $s\n\
12174 $self debug \"FSM: $old -> $s\"\n\
12175 }\n\
12176 \n\
12177 MMG instproc drop-layer {} {\n\
12178 $self dumpLevel\n\
12179 $self instvar subscription_ layer_\n\
12180 set n $subscription_\n\
12181 \n\
12182 if { $n > 0 } {\n\
12183 $self debug \"DRP-LAYER $n\"\n\
12184 $layer_($n) leave-group \n\
12185 incr n -1\n\
12186 set subscription_ $n\n\
12187 }\n\
12188 $self dumpLevel\n\
12189 }\n\
12190 \n\
12191 MMG instproc add-layer {} {\n\
12192 $self dumpLevel\n\
12193 $self instvar maxlevel_ subscription_ layer_\n\
12194 set n $subscription_\n\
12195 if { $n < $maxlevel_ } {\n\
12196 $self debug \"ADD-LAYER\"\n\
12197 incr n\n\
12198 set subscription_ $n\n\
12199 $layer_($n) join-group\n\
12200 }\n\
12201 $self dumpLevel\n\
12202 }\n\
12203 \n\
12204 MMG instproc current_layer_getting_packets {} {\n\
12205 $self instvar subscription_ layer_ TD\n\
12206 set n $subscription_\n\
12207 if { $n == 0 } {\n\
12208 return 0\n\
12209 }\n\
12210 \n\
12211 set l $layer_($subscription_)\n\
12212 $self debug \"npkts [$l npkts]\"\n\
12213 if [$l getting-pkts] {\n\
12214 return 1\n\
12215 }\n\
12216 \n\
12217 set delta [expr [$self now] - [$l last-add]]\n\
12218 if { $delta > $TD } {\n\
12219 set TD [expr 1.2 * $delta]\n\
12220 }\n\
12221 return 0\n\
12222 }\n\
12223 \n\
12224 MMG instproc mmg_loss {} {\n\
12225 $self instvar layers_\n\
12226 set loss 0\n\
12227 foreach l $layers_ {\n\
12228 incr loss [$l nlost]\n\
12229 }\n\
12230 return $loss\n\
12231 }\n\
12232 \n\
12233 MMG instproc mmg_pkts {} {\n\
12234 $self instvar layers_\n\
12235 set npkts 0\n\
12236 foreach l $layers_ {\n\
12237 incr npkts [$l npkts]\n\
12238 }\n\
12239 return $npkts\n\
12240 }\n\
12241 \n\
12242 MMG instproc check-equilibrium {} {\n\
12243 global rlm_param\n\
12244 $self instvar subscription_ maxlevel_ layer_\n\
12245 \n\
12246 set n [expr $subscription_ + 1]\n\
12247 if { $n >= $maxlevel_ || [$layer_($n) timer] >= $rlm_param(max) } {\n\
12248 set eq 1\n\
12249 } else {\n\
12250 set eq 0\n\
12251 }\n\
12252 \n\
12253 $self debug \"EQ $eq\"\n\
12254 }\n\
12255 \n\
12256 MMG instproc backoff-one { n alpha } {\n\
12257 $self debug \"BACKOFF $n by $alpha\"\n\
12258 $self instvar layer_\n\
12259 $layer_($n) backoff $alpha\n\
12260 }\n\
12261 \n\
12262 MMG instproc backoff n {\n\
12263 $self debug \"BACKOFF $n\"\n\
12264 global rlm_param\n\
12265 $self instvar maxlevel_ layer_\n\
12266 set alpha $rlm_param(alpha)\n\
12267 set L $layer_($n)\n\
12268 $L backoff $alpha\n\
12269 incr n\n\
12270 while { $n <= $maxlevel_ } {\n\
12271 $layer_($n) peg-backoff $L\n\
12272 incr n\n\
12273 }\n\
12274 $self check-equilibrium\n\
12275 }\n\
12276 \n\
12277 MMG instproc highest_level_pending {} {\n\
12278 $self instvar maxlevel_\n\
12279 set m \"\"\n\
12280 set n 0\n\
12281 incr n\n\
12282 while { $n <= $maxlevel_ } {\n\
12283 if [$self level_pending $n] {\n\
12284 set m $n\n\
12285 }\n\
12286 incr n\n\
12287 }\n\
12288 return $m\n\
12289 }\n\
12290 \n\
12291 MMG instproc rlm_update_D  D {\n\
12292 global rlm_param\n\
12293 $self instvar TD TDVAR\n\
12294 \n\
12295 set v [expr abs($D - $TD)]\n\
12296 set TD [expr $TD * (1 - $rlm_param(g1)) \\\n\
12297 + $rlm_param(g1) * $D]\n\
12298 set TDVAR [expr $TDVAR * (1 - $rlm_param(g2)) \\\n\
12299 + $rlm_param(g2) * $v]\n\
12300 }\n\
12301 \n\
12302 MMG instproc exceed_loss_thresh {} {\n\
12303 $self instvar h_npkts h_nlost\n\
12304 set npkts [expr [$self mmg_pkts] - $h_npkts]\n\
12305 if { $npkts >= 10 } {\n\
12306 set nloss [expr [$self mmg_loss] - $h_nlost]\n\
12307 set loss [expr double($nloss) / ($nloss + $npkts)]\n\
12308 $self debug \"H-THRESH $nloss $npkts $loss\"\n\
12309 if { $loss > 0.25 } {\n\
12310 return 1\n\
12311 }\n\
12312 }\n\
12313 return 0\n\
12314 }\n\
12315 \n\
12316 MMG instproc enter_M {} {\n\
12317 $self set-state /M\n\
12318 $self set_TD_timer_wait\n\
12319 $self instvar h_npkts h_nlost\n\
12320 set h_npkts [$self mmg_pkts]\n\
12321 set h_nlost [$self mmg_loss]\n\
12322 }\n\
12323 \n\
12324 MMG instproc enter_D {} {\n\
12325 $self set-state /D\n\
12326 $self set_TD_timer_conservative\n\
12327 }\n\
12328 \n\
12329 MMG instproc enter_H {} {\n\
12330 $self set_TD_timer_conservative\n\
12331 $self set-state /H\n\
12332 }\n\
12333 \n\
12334 MMG instproc log-loss {} {\n\
12335 $self debug \"LOSS [$self mmg_loss]\"\n\
12336 \n\
12337 $self instvar state_ subscription_ pending_ts_\n\
12338 if { $state_ == \"/M\" } {\n\
12339 if [$self exceed_loss_thresh] {\n\
12340 $self cancel_timer TD\n\
12341 $self drop-layer\n\
12342 $self check-equilibrium\n\
12343 $self enter_D\n\
12344 }\n\
12345 return\n\
12346 }\n\
12347 if { $state_ == \"/S\" } {\n\
12348 $self cancel_timer TD\n\
12349 set n [$self highest_level_pending]\n\
12350 if { $n != \"\" } {\n\
12351 $self backoff $n\n\
12352 if { $n == $subscription_ } {\n\
12353 set ts $pending_ts_($subscription_)\n\
12354 $self rlm_update_D [expr [$self now] - $ts]\n\
12355 $self drop-layer\n\
12356 $self check-equilibrium\n\
12357 $self enter_D\n\
12358 return\n\
12359 }\n\
12360 if { $n == [expr $subscription_ + 1] } {\n\
12361 $self cancel_timer TJ\n\
12362 $self set_TJ_timer\n\
12363 }\n\
12364 }\n\
12365 if [$self our_level_recently_added] {\n\
12366 $self enter_M\n\
12367 return\n\
12368 }\n\
12369 $self enter_H\n\
12370 return\n\
12371 }\n\
12372 if { $state_ == \"/H\" || $state_ == \"/D\" } {\n\
12373 return\n\
12374 }\n\
12375 puts stderr \"rlm state machine botched\"\n\
12376 exit -1\n\
12377 }\n\
12378 \n\
12379 MMG instproc relax_TJ {} {\n\
12380 $self instvar subscription_ layer_\n\
12381 if { $subscription_ > 0 } {\n\
12382 $layer_($subscription_) relax\n\
12383 $self check-equilibrium\n\
12384 }\n\
12385 }\n\
12386 \n\
12387 MMG instproc trigger_TD {} {\n\
12388 $self instvar state_\n\
12389 if { $state_ == \"/H\" } {\n\
12390 $self enter_M\n\
12391 return\n\
12392 }\n\
12393 if { $state_ == \"/D\" || $state_ == \"/M\" } {\n\
12394 $self set-state /S\n\
12395 $self set_TD_timer_conservative\n\
12396 return\n\
12397 }\n\
12398 if { $state_ == \"/S\" } {\n\
12399 $self relax_TJ\n\
12400 $self set_TD_timer_conservative\n\
12401 return\n\
12402 }\n\
12403 puts stderr \"trigger_TD: rlm state machine botched $state)\"\n\
12404 exit -1\n\
12405 }\n\
12406 \n\
12407 MMG instproc set_TJ_timer {} {\n\
12408 global rlm_param\n\
12409 $self instvar subscription_ layer_\n\
12410 set n [expr $subscription_ + 1]\n\
12411 if ![info exists layer_($n)] {\n\
12412 return\n\
12413 }\n\
12414 set I [$layer_($n) timer]\n\
12415 set d [expr $I / 2.0 + [trunc_exponential $I]]\n\
12416 $self debug \"TJ $d\"\n\
12417 $self set_timer TJ $d\n\
12418 }\n\
12419 \n\
12420 MMG instproc set_TD_timer_conservative {} {\n\
12421 $self instvar TD TDVAR\n\
12422 set delay [expr $TD + 1.5 * $TDVAR]\n\
12423 $self set_timer TD $delay\n\
12424 }\n\
12425 \n\
12426 MMG instproc set_TD_timer_wait {} {\n\
12427 $self instvar TD TDVAR\n\
12428 $self instvar subscription_\n\
12429 set k [expr $subscription_ / 2. + 1.5]\n\
12430 $self set_timer TD [expr $TD + $k * $TDVAR]\n\
12431 }\n\
12432 \n\
12433 MMG instproc is-recent { ts } {\n\
12434 $self instvar TD TDVAR\n\
12435 set ts [expr $ts + ($TD + 2 * $TDVAR)]\n\
12436 if { $ts > [$self now] } {\n\
12437 return 1\n\
12438 }\n\
12439 return 0\n\
12440 }\n\
12441 \n\
12442 MMG instproc level_pending n {\n\
12443 $self instvar pending_ts_\n\
12444 if { [info exists pending_ts_($n)] && \\\n\
12445 [$self is-recent $pending_ts_($n)] } {\n\
12446 return 1\n\
12447 }\n\
12448 return 0\n\
12449 }\n\
12450 \n\
12451 MMG instproc level_recently_joined n {\n\
12452 $self instvar join_ts_\n\
12453 if { [info exists join_ts_($n)] && \\\n\
12454 [$self is-recent $join_ts_($n)] } {\n\
12455 return 1\n\
12456 }\n\
12457 return 0\n\
12458 }\n\
12459 \n\
12460 MMG instproc pending_inferior_jexps {} {\n\
12461 set n 0\n\
12462 $self instvar subscription_\n\
12463 while { $n <= $subscription_ } { \n\
12464 if [$self level_recently_joined $n] {\n\
12465 return 1\n\
12466 }\n\
12467 incr n\n\
12468 }\n\
12469 $self debug \"NO-PEND-INF\"\n\
12470 return 0\n\
12471 }\n\
12472 \n\
12473 MMG instproc trigger_TJ {} {\n\
12474 $self debug \"trigger-TJ\"\n\
12475 $self instvar state_ ctrl_ subscription_\n\
12476 if { ($state_ == \"/S\" && ![$self pending_inferior_jexps] && \\\n\
12477 [$self current_layer_getting_packets])  } {\n\
12478 $self add-layer\n\
12479 $self check-equilibrium\n\
12480 set msg \"add $subscription_\"\n\
12481 $ctrl_ send $msg\n\
12482 $self local-join\n\
12483 }\n\
12484 $self set_TJ_timer\n\
12485 }\n\
12486 \n\
12487 MMG instproc our_level_recently_added {} {\n\
12488 $self instvar subscription_ layer_\n\
12489 return [$self is-recent [$layer_($subscription_) last-add]]\n\
12490 }\n\
12491 \n\
12492 \n\
12493 MMG instproc recv-ctrl msg {\n\
12494 $self instvar join_ts_ pending_ts_ subscription_\n\
12495 $self debug \"X-JOIN $msg\"\n\
12496 set what [lindex $msg 0]\n\
12497 if { $what != \"add\" } {\n\
12498 return\n\
12499 }\n\
12500 set level [lindex $msg 1]\n\
12501 set join_ts_($level) [$self now]\n\
12502 if { $level > $subscription_ } {\n\
12503 set pending_ts_($level) [$self now]\n\
12504 }\n\
12505 }\n\
12506 \n\
12507 MMG instproc local-join {} {\n\
12508 $self instvar subscription_ pending_ts_ join_ts_\n\
12509 set join_ts_($subscription_) [$self now]\n\
12510 set pending_ts_($subscription_) [$self now]\n\
12511 }\n\
12512 \n\
12513 MMG instproc debug { msg } {\n\
12514 $self instvar debug_ subscription_ state_\n\
12515 if {$debug_} {\n\
12516 puts stderr \"[gettimeofday] layer $subscription_ $state_ $msg\"\n\
12517 }\n\
12518 }\n\
12519 \n\
12520 MMG instproc dumpLevel {} {\n\
12521 }\n\
12522 \n\
12523 \n\
12524 \n\
12525 Class Layer\n\
12526 \n\
12527 Layer instproc init { mmg } {\n\
12528 $self next\n\
12529 \n\
12530 $self instvar mmg_ TJ npkts_\n\
12531 global rlm_param\n\
12532 set mmg_ $mmg\n\
12533 set TJ $rlm_param(init-tj)\n\
12534 set npkts_ 0\n\
12535 }\n\
12536 \n\
12537 Layer instproc relax {} {\n\
12538 global rlm_param\n\
12539 $self instvar TJ\n\
12540 set TJ [expr $TJ * $rlm_param(beta)]\n\
12541 if { $TJ <= $rlm_param(init-tj) } {\n\
12542 set TJ $rlm_param(init-tj)\n\
12543 }\n\
12544 }\n\
12545 \n\
12546 Layer instproc backoff alpha {\n\
12547 global rlm_param\n\
12548 $self instvar TJ\n\
12549 set TJ [expr $TJ * $alpha]\n\
12550 if { $TJ >= $rlm_param(max) } {\n\
12551 set TJ $rlm_param(max)\n\
12552 }\n\
12553 }\n\
12554 \n\
12555 Layer instproc peg-backoff L {\n\
12556 $self instvar TJ\n\
12557 set t [$L set TJ]    \n\
12558 if { $t >= $TJ } {\n\
12559 set TJ $t\n\
12560 }\n\
12561 }\n\
12562 \n\
12563 Layer instproc timer {} {\n\
12564 $self instvar TJ\n\
12565 return $TJ\n\
12566 }\n\
12567 \n\
12568 Layer instproc last-add {} {\n\
12569 $self instvar add_time_\n\
12570 return $add_time_\n\
12571 }\n\
12572 \n\
12573 Layer instproc join-group {} {\n\
12574 $self instvar npkts_ add_time_ mmg_\n\
12575 set npkts_ [$self npkts]\n\
12576 set add_time_ [$mmg_ now]\n\
12577 }\n\
12578 \n\
12579 Layer instproc leave-group {} {\n\
12580 }\n\
12581 \n\
12582 Layer instproc getting-pkts {} {\n\
12583 $self instvar npkts_\n\
12584 return [expr [$self npkts] != $npkts_]\n\
12585 }\n\
12586 \n\
12587 Agent/LossMonitor set npkts_ 0\n\
12588 Agent/LossMonitor set bytes_ 0\n\
12589 Agent/LossMonitor set nlost_ 0\n\
12590 Agent/LossMonitor set lastPktTime_ 0\n\
12591 \n\
12592 Class LossTrace -superclass Agent/LossMonitor\n\
12593 LossTrace set expected_ -1\n\
12594 \n\
12595 LossTrace instproc init {} {\n\
12596 $self next\n\
12597 $self instvar lastTime\n\
12598 set lastTime 0\n\
12599 }\n\
12600 \n\
12601 LossTrace instproc log-loss {} {\n\
12602 $self instvar mmg_\n\
12603 $mmg_ log-loss\n\
12604 \n\
12605 global lossTraceFile lossNode\n\
12606 if [info exists lossTraceFile] {\n\
12607 set id [[$mmg_ node] id]\n\
12608 if { [info exists lossNode] && $lossNode != $id } {\n\
12609 return\n\
12610 }\n\
12611 set f $lossTraceFile\n\
12612 $self instvar layerNo seqno_ expected_ lastPktTime_ \\\n\
12613 lastSeqno lastTime\n\
12614 if [info exists lastSeqno] {\n\
12615 set npkt [expr $expected_ - $lastSeqno]\n\
12616 puts $f \"p $id $layerNo $lastTime $lastPktTime_ $npkt\"\n\
12617 set lastTime $lastPktTime_\n\
12618 }\n\
12619 set lost [expr $seqno_ - $expected_]\n\
12620 set t [ns-now]\n\
12621 puts $f \"d $id $layerNo $lastPktTime_ $t $lost\"\n\
12622 set lastSeqno $seqno_\n\
12623 set lastTime $t\n\
12624 }\n\
12625 }\n\
12626 \n\
12627 LossTrace instproc flush {} {\n\
12628 global lossTraceFile\n\
12629 $self instvar lastSeqno expected_ layerNo lastTime \\\n\
12630 lastPktTime_ mmg_ seqno_\n\
12631 if [info exists lastSeqno] {\n\
12632 set id [[$mmg_ node] id]\n\
12633 set npkt [expr $seqno_ - $lastSeqno]\n\
12634 if { $npkt != 0 } {\n\
12635 puts $lossTraceFile \\\n\
12636 \"p $id $layerNo $lastTime $lastPktTime_ $npkt\"\n\
12637 }\n\
12638 unset lastSeqno\n\
12639 }\n\
12640 }\n\
12641 \n\
12642 \n\
12643 \n\
12644 Class Layer/ns -superclass Layer\n\
12645 \n\
12646 Layer/ns instproc init {ns mmg addr layerNo} {\n\
12647 $self next $mmg\n\
12648 \n\
12649 $self instvar ns_ addr_ mon_\n\
12650 set ns_ $ns\n\
12651 set addr_ $addr\n\
12652 set mon_ [$ns_ create-agent [$mmg node] LossTrace 0]\n\
12653 $mon_ set layerNo $layerNo\n\
12654 $mon_ set mmg_ $mmg\n\
12655 $mon_ set dst_ $addr\n\
12656 }\n\
12657 \n\
12658 Layer/ns instproc join-group {} {\n\
12659 $self instvar mon_ mmg_ addr_\n\
12660 $mon_ clear\n\
12661 [$mmg_ node] join-group $mon_ $addr_\n\
12662 $self next\n\
12663 }\n\
12664 \n\
12665 Layer/ns instproc leave-group {} {\n\
12666 $self instvar mon_ mmg_ addr_\n\
12667 [$mmg_ node] leave-group $mon_ $addr_\n\
12668 $self next\n\
12669 }\n\
12670 \n\
12671 Layer/ns instproc npkts {} {\n\
12672 $self instvar mon_\n\
12673 return [$mon_ set npkts_]\n\
12674 }\n\
12675 \n\
12676 Layer/ns instproc nlost {} {\n\
12677 $self instvar mon_\n\
12678 return [$mon_ set nlost_]\n\
12679 }\n\
12680 \n\
12681 Layer/ns instproc mon {} {\n\
12682 $self instvar mon_\n\
12683 return $mon_\n\
12684 }\n\
12685 \n\
12686 Class MMG/ns -superclass MMG\n\
12687 \n\
12688 MMG/ns instproc init {ns localNode caddr addrs} {\n\
12689 $self instvar ns_ node_ addrs_\n\
12690 set ns_ $ns\n\
12691 set node_ $localNode\n\
12692 set addrs_ $addrs\n\
12693 \n\
12694 $self next [llength $addrs]\n\
12695 \n\
12696 $self instvar ctrl_\n\
12697 set ctrl_ [$ns create-agent $node_ Agent/Message 0]\n\
12698 $ctrl_ set dst_ $caddr\n\
12699 $ctrl_ proc handle msg \"$self recv-ctrl \\$msg\"\n\
12700 $node_ join-group $ctrl_ $caddr\n\
12701 }\n\
12702 \n\
12703 MMG/ns instproc create-layer {layerNo} {\n\
12704 $self instvar ns_ addrs_\n\
12705 return [new Layer/ns $ns_ $self [lindex $addrs_ $layerNo] $layerNo]\n\
12706 }\n\
12707 \n\
12708 MMG/ns instproc now {} {\n\
12709 $self instvar ns_\n\
12710 return [$ns_ now]\n\
12711 }\n\
12712 \n\
12713 MMG/ns instproc set_timer {which delay} {\n\
12714 $self instvar ns_ timers_\n\
12715 if [info exists timers_($which)] {\n\
12716 puts \"timer botched ($which)\"\n\
12717 exit 1\n\
12718 }\n\
12719 set time [expr [$ns_ now] + $delay]\n\
12720 set timers_($which) [$ns_ at $time \"$self trigger_timer $which\"]\n\
12721 }\n\
12722 \n\
12723 MMG/ns instproc trigger_timer {which} {\n\
12724 $self instvar timers_\n\
12725 unset timers_($which)\n\
12726 $self trigger_$which\n\
12727 }\n\
12728 \n\
12729 MMG/ns instproc cancel_timer {which} {\n\
12730 $self instvar ns_ timers_\n\
12731 if [info exists timers_($which)] {\n\
12732 $ns_ at $timers_($which)\n\
12733 unset timers_($which)\n\
12734 }\n\
12735 }\n\
12736 \n\
12737 \n\
12738 \n\
12739 \n\
12740 MMG/ns instproc node {} {\n\
12741 $self instvar node_\n\
12742 return $node_\n\
12743 }\n\
12744 \n\
12745 MMG/ns instproc debug { msg } {\n\
12746 $self instvar debug_\n\
12747 if {!$debug_} { return }\n\
12748 \n\
12749 $self instvar subscription_ state_ node_\n\
12750 set time [format %.05f [ns-now]]\n\
12751 puts stderr \"$time node [$node_ id] layer $subscription_ $state_ $msg\"\n\
12752 }\n\
12753 \n\
12754 MMG/ns instproc trace { trace } {\n\
12755 $self instvar layers_\n\
12756 foreach s $layers_ {\n\
12757 [$s mon] trace $trace\n\
12758 }\n\
12759 }\n\
12760 \n\
12761 \n\
12762 MMG/ns instproc total_bytes_delivered {} {\n\
12763 $self instvar layers_\n\
12764 set v 0\n\
12765 foreach s $layers_ {\n\
12766 incr v [[$s mon] set bytes]\n\
12767 }\n\
12768 return $v\n\
12769 }\n\
12770 \n\
12771 Class SessionSim -superclass Simulator\n\
12772 SessionSim set MixMode_ 0\n\
12773 SessionSim set rc_ 0\n\
12774 \n\
12775 SessionSim instproc create-session { srcNode srcAgent } {\n\
12776 $self instvar session_\n\
12777 \n\
12778 set nid [$srcNode id]\n\
12779 set dst [$srcAgent set dst_addr_]\n\
12780 set session_($nid:$dst:$nid) [new SessionHelper]\n\
12781 $session_($nid:$dst:$nid) set-node $nid\n\
12782 if {[SessionSim set rc_]} {\n\
12783 $session_($nid:$dst:$nid) set rc_ 1\n\
12784 }\n\
12785 \n\
12786 set trace [$self get-nam-traceall]\n\
12787 if {$trace != \"\"} {\n\
12788 set p [$self create-trace SessEnque $trace $nid $dst \"nam\"]\n\
12789 $srcAgent target $p\n\
12790 $p target $session_($nid:$dst:$nid)\n\
12791 } else {\n\
12792 $srcAgent target $session_($nid:$dst:$nid)\n\
12793 }\n\
12794 \n\
12795 return $session_($nid:$dst:$nid)\n\
12796 }\n\
12797 \n\
12798 SessionSim instproc update-loss-dependency { src dst owner agent group } {\n\
12799 $self instvar session_ routingTable_ loss_\n\
12800 \n\
12801 set loss_rcv 1\n\
12802 set tmp $dst\n\
12803 while {$tmp != $owner} {\n\
12804 set next [$routingTable_ lookup $tmp $owner]\n\
12805 if {[info exists loss_($next:$tmp)] && $loss_($next:$tmp) != 0} {\n\
12806 if {$loss_rcv} {\n\
12807 set dep_loss [$session_($src:$group:$owner) update-loss-rcv $loss_($next:$tmp) $agent]\n\
12808 } else {\n\
12809 set dep_loss [$session_($src:$group:$owner) update-loss-loss $loss_($next:$tmp) $dep_loss]\n\
12810 }\n\
12811 \n\
12812 if {$dep_loss == 0} { \n\
12813 return \n\
12814 }\n\
12815 set loss_rcv 0\n\
12816 }\n\
12817 set tmp $next\n\
12818 }\n\
12819 \n\
12820 if [info exists dep_loss] {\n\
12821 $session_($src:$group:$owner) update-loss-top $dep_loss\n\
12822 }\n\
12823 }\n\
12824 \n\
12825 SessionSim instproc join-group { rcvAgent group } {\n\
12826 $self instvar session_ routingTable_ delay_ bw_\n\
12827 \n\
12828 foreach index [array names session_] {\n\
12829 set tri [split $index :]\n\
12830 if {[lindex $tri 1] == $group} {\n\
12831 set src [lindex $tri 0]\n\
12832 set dst [[$rcvAgent set node_] id]\n\
12833 set delay 0\n\
12834 set accu_bw 0\n\
12835 set ttl 0\n\
12836 set tmp $dst\n\
12837 while {$tmp != $src} {\n\
12838 set next [$routingTable_ lookup $tmp $src]\n\
12839 set delay [expr $delay + $delay_($tmp:$next)]\n\
12840 if {$accu_bw} {\n\
12841 set accu_bw [expr 1 / (1 / $accu_bw + 1 / $bw_($tmp:$next))]\n\
12842 } else {\n\
12843 set accu_bw $bw_($tmp:$next)\n\
12844 }\n\
12845 incr ttl\n\
12846 set tmp $next\n\
12847 }\n\
12848 \n\
12849 $self puts-nam-config \"G -t [$self now] -i $group -a $dst\"\n\
12850 \n\
12851 set f [$self get-nam-traceall]\n\
12852 if {$f != \"\"} { \n\
12853 set p [$self create-trace SessDeque $f $src $dst \"nam\"]\n\
12854 $p target $rcvAgent\n\
12855 $session_($index) add-dst $accu_bw $delay $ttl $dst $p\n\
12856 $self update-loss-dependency $src $dst $src $p $group\n\
12857 } else {\n\
12858 $session_($index) add-dst $accu_bw $delay $ttl $dst $rcvAgent\n\
12859 $self update-loss-dependency $src $dst $src $rcvAgent $group\n\
12860 }\n\
12861 }\n\
12862 }\n\
12863 }\n\
12864 \n\
12865 SessionSim instproc leave-group { rcvAgent group } {\n\
12866 $self instvar session_\n\
12867 \n\
12868 foreach index [array names session_] {\n\
12869 set tri [split $index :]\n\
12870 if {[lindex $tri 1] == $group} {\n\
12871 set dst [[$rcvAgent set node_] id]\n\
12872 $self puts-nam-traceall \\\n\
12873 \"G -t [$self now] -i $group -x $dst\"\n\
12874 }\n\
12875 }\n\
12876 }\n\
12877 \n\
12878 SessionSim instproc insert-loss { lossmodule from to } {\n\
12879 $self instvar loss_ bw_ Node_\n\
12880 \n\
12881 if {[SessionSim set MixMode_] && [$self detailed-link? [$from id] [$to id]]} {\n\
12882 $self lossmodel $lossmodule $from $to\n\
12883 } elseif [info exists bw_([$from id]:[$to id])] {\n\
12884 set loss_([$from id]:[$to id]) $lossmodule\n\
12885 }\n\
12886 }\n\
12887 \n\
12888 SessionSim instproc get-delay { src dst } {\n\
12889 $self instvar routingTable_ delay_\n\
12890 set delay 0\n\
12891 set tmp $src\n\
12892 while {$tmp != $dst} {\n\
12893 set next [$routingTable_ lookup $tmp $dst]\n\
12894 set delay [expr $delay + $delay_($tmp:$next)]\n\
12895 set tmp $next\n\
12896 }\n\
12897 return $delay\n\
12898 }\n\
12899 \n\
12900 SessionSim instproc get-bw { src dst } {\n\
12901 $self instvar routingTable_ bw_\n\
12902 set accu_bw 0\n\
12903 set tmp $src\n\
12904 while {$tmp != $dst} {\n\
12905 set next [$routingTable_ lookup $tmp $dst]\n\
12906 if {$accu_bw} {\n\
12907 set accu_bw [expr 1 / (1 / $accu_bw + 1 / $bw_($tmp:$next))]\n\
12908 } else {\n\
12909 set accu_bw $bw_($tmp:$next)\n\
12910 }\n\
12911 set tmp $next\n\
12912 }\n\
12913 return $accu_bw\n\
12914 }\n\
12915 \n\
12916 SessionSim instproc node args {\n\
12917 $self instvar sessionNode_\n\
12918 if {[llength $args] == 0} {\n\
12919 set node [new SessionNode]\n\
12920 } else {\n\
12921 set node [new SessionNode $args]\n\
12922 }\n\
12923 set sessionNode_([$node id]) $node\n\
12924 $node set ns_ $self\n\
12925 return $node\n\
12926 }\n\
12927 \n\
12928 SessionSim instproc simplex-link { n1 n2 bw delay type } {\n\
12929 $self instvar bw_ delay_ linkAttr_\n\
12930 set sid [$n1 id]\n\
12931 set did [$n2 id]\n\
12932 \n\
12933 set bw_($sid:$did) [bw_parse $bw]\n\
12934 set delay_($sid:$did) [delay_parse $delay]\n\
12935 \n\
12936 set linkAttr_($sid:$did:ORIENT) \"\"\n\
12937 set linkAttr_($sid:$did:COLOR) \"black\"\n\
12938 }\n\
12939 \n\
12940 SessionSim instproc duplex-link { n1 n2 bw delay type } {\n\
12941 $self simplex-link $n1 $n2 $bw $delay $type\n\
12942 $self simplex-link $n2 $n1 $bw $delay $type\n\
12943 \n\
12944 $self session-register-nam-linkconfig [$n1 id]:[$n2 id]\n\
12945 }\n\
12946 \n\
12947 SessionSim instproc simplex-link-of-interfaces { n1 n2 bw delay type } {\n\
12948 $self simplex-link $n1 $n2 $bw $delay $type\n\
12949 }\n\
12950 \n\
12951 SessionSim instproc duplex-link-of-interfaces { n1 n2 bw delay type } {\n\
12952 $self simplex-link $n1 $n2 $bw $delay $type\n\
12953 $self simplex-link $n2 $n1 $bw $delay $type\n\
12954 \n\
12955 $self session-register-nam-linkconfig [$n1 id]:[$n2 id]\n\
12956 }\n\
12957 \n\
12958 SessionSim instproc detailed-node { id address } {\n\
12959 $self instvar Node_\n\
12960 \n\
12961 if { [Simulator info vars EnableMcast_] != \"\" } {\n\
12962 warn \"Flag variable Simulator::EnableMcast_ discontinued.\\n\\t\\\n\
12963 Use multicast methods as:\\n\\t\\t\\\n\
12964 % set ns \\[new Simulator -multicast on]\\n\\t\\t\\\n\
12965 % \\$ns multicast\"\n\
12966 $self multicast\n\
12967 Simulator unset EnableMcast_\n\
12968 }\n\
12969 if ![info exist Node_($id)] {\n\
12970 set node [new [Simulator set node_factory_] $address]\n\
12971 Node set nn_ [expr [Node set nn_] - 1]\n\
12972 $node set id_ $id\n\
12973 set Node_($id) $node\n\
12974 return $node\n\
12975 } else {\n\
12976 return $Node_($id)\n\
12977 }\n\
12978 }\n\
12979 \n\
12980 SessionSim instproc detailed-duplex-link { from to } {\n\
12981 $self instvar bw_ delay_\n\
12982 \n\
12983 SessionSim set MixMode_ 1\n\
12984 set fromNode [$self detailed-node [$from id] [$from set address_]]\n\
12985 set toNode [$self detailed-node [$to id] [$from set address_]]\n\
12986 \n\
12987 $self simulator-duplex-link $fromNode $toNode $bw_([$from id]:[$to id]) $delay_([$from id]:[$to id]) DropTail\n\
12988 }\n\
12989 \n\
12990 SessionSim instproc simulator-duplex-link { n1 n2 bw delay type args } {\n\
12991 $self instvar link_\n\
12992 set i1 [$n1 id]\n\
12993 set i2 [$n2 id]\n\
12994 if [info exists link_($i1:$i2)] {\n\
12995 $self remove-nam-linkconfig $i1 $i2\n\
12996 }\n\
12997 \n\
12998 eval $self simulator-simplex-link $n1 $n2 $bw $delay $type $args\n\
12999 eval $self simulator-simplex-link $n2 $n1 $bw $delay $type $args\n\
13000 }\n\
13001 \n\
13002 SessionSim instproc simulator-simplex-link { n1 n2 bw delay qtype args } {\n\
13003 $self instvar link_ queueMap_ nullAgent_\n\
13004 set sid [$n1 id]\n\
13005 set did [$n2 id]\n\
13006 \n\
13007 if [info exists queueMap_($qtype)] {\n\
13008 set qtype $queueMap_($qtype)\n\
13009 }\n\
13010 set qtypeOrig $qtype\n\
13011 switch -exact $qtype {\n\
13012 ErrorModule {\n\
13013 if { [llength $args] > 0 } {\n\
13014 set q [eval new $qtype $args]\n\
13015 } else {\n\
13016 set q [new $qtype Fid]\n\
13017 }\n\
13018 }\n\
13019 intserv {\n\
13020 set qtype [lindex $args 0]\n\
13021 set q [new Queue/$qtype]\n\
13022 }\n\
13023 default {\n\
13024 set q [new Queue/$qtype]\n\
13025 }\n\
13026 }\n\
13027 \n\
13028 switch -exact $qtypeOrig {\n\
13029 RTM {\n\
13030 set c [lindex $args 1]\n\
13031 set link_($sid:$did) [new CBQLink       \\\n\
13032 $n1 $n2 $bw $delay $q $c]\n\
13033 }\n\
13034 CBQ -\n\
13035 CBQ/WRR {\n\
13036 if {[llength $args] == 0} {\n\
13037 set c [new Classifier/Hash/Fid 33]\n\
13038 } else {\n\
13039 set c [lindex $args 1]\n\
13040 }\n\
13041 set link_($sid:$did) [new CBQLink       \\\n\
13042 $n1 $n2 $bw $delay $q $c]\n\
13043 }\n\
13044 intserv {\n\
13045 set link_($sid:$did) [new IntServLink   \\\n\
13046 $n1 $n2 $bw $delay $q   \\\n\
13047 [concat $qtypeOrig $args]]\n\
13048 }\n\
13049 default {\n\
13050 set link_($sid:$did) [new SimpleLink    \\\n\
13051 $n1 $n2 $bw $delay $q]\n\
13052 }\n\
13053 }\n\
13054 $n1 add-neighbor $n2\n\
13055 \n\
13056 if {[string first \"RED\" $qtype] != -1} {\n\
13057 $q link [$link_($sid:$did) set link_]\n\
13058 }\n\
13059 \n\
13060 set trace [$self get-ns-traceall]\n\
13061 if {$trace != \"\"} {\n\
13062 $self trace-queue $n1 $n2 $trace\n\
13063 }\n\
13064 set trace [$self get-nam-traceall]\n\
13065 if {$trace != \"\"} {\n\
13066 $self namtrace-queue $n1 $n2 $trace\n\
13067 }\n\
13068 \n\
13069 $self register-nam-linkconfig $link_($sid:$did)\n\
13070 }\n\
13071 \n\
13072 SessionSim instproc duplex-link-op { n1 n2 op args } {\n\
13073 $self instvar linkAttr_ bw_\n\
13074 \n\
13075 set sid [$n1 id]\n\
13076 set did [$n2 id]\n\
13077 \n\
13078 if ![info exists bw_($sid:$did)] {\n\
13079 error \"Non-existent link [$n1 id]:[$n2 id]\"\n\
13080 }\n\
13081 \n\
13082 switch $op {\n\
13083 \"orient\" {\n\
13084 set linkAttr_($sid:$did:ORIENT) $args\n\
13085 set linkAttr_($did:$sid:ORIENT) $args\n\
13086 }\n\
13087 \"color\" {\n\
13088 set ns [Simulator instance]\n\
13089 $ns puts-nam-traceall \\\n\
13090 [eval list \"l -t [$self now] -s $sid -d $did \\\n\
13091 -S COLOR -c $args -o $linkAttr_($sid:$did:COLOR)\"]\n\
13092 $ns puts-nam-traceall \\\n\
13093 [eval list \"l -t [$self now] -s $did -d $sid \\\n\
13094 -S COLOR -c $args -o $linkAttr_($sid:$did:COLOR)\"]\n\
13095 eval set attr_($sid:$did:COLOR) $args\n\
13096 eval set attr_($did:$sid:COLOR) $args\n\
13097 }\n\
13098 default {\n\
13099 eval puts \"Duplex link option $args not implemented \\\n\
13100 in SessionSim\"\n\
13101 }\n\
13102 } \n\
13103 }\n\
13104 \n\
13105 SessionSim instproc session-register-nam-linkconfig link {\n\
13106 $self instvar sessionLinkConfigList_ bw_ linkAttr_\n\
13107 if [info exists sessionLinkConfigList_] {\n\
13108 set tmp [split $link :]\n\
13109 set i1 [lindex $tmp 0]\n\
13110 set i2 [lindex $tmp 1]\n\
13111 if [info exists bw_($i2:$i1)] {\n\
13112 set pos [lsearch $sessionLinkConfigList_ $i2:$i1]\n\
13113 if {$pos >= 0} {\n\
13114 set a1 $linkAttr_($i2:$i1:ORIENT)\n\
13115 set a2 $linkAttr_($link:ORIENT)\n\
13116 if {$a1 == \"\" && $a2 != \"\"} {\n\
13117 set sessionLinkConfigList_ [lreplace $sessionLinkConfigList_ $pos $pos]\n\
13118 } else {\n\
13119 return\n\
13120 }\n\
13121 }\n\
13122 }\n\
13123 \n\
13124 set pos [lsearch $sessionLinkConfigList_ $link]\n\
13125 if {$pos >= 0} {\n\
13126 set sessionLinkConfigList_ \\\n\
13127 [lreplace $sessionLinkConfigList_ $pos $pos]\n\
13128 }\n\
13129 }\n\
13130 lappend sessionLinkConfigList_ $link\n\
13131 }\n\
13132 \n\
13133 SessionSim instproc dump-namlinks {} {\n\
13134 $self instvar bw_ delay_ sessionLinkConfigList_ linkAttr_\n\
13135 \n\
13136 set ns [Simulator instance]\n\
13137 foreach lnk $sessionLinkConfigList_ {\n\
13138 set tmp [split $lnk :]\n\
13139 set i1 [lindex $tmp 0]\n\
13140 set i2 [lindex $tmp 1]\n\
13141 $ns puts-nam-traceall \\\n\
13142 \"l -t * -s $i1 -d $i2 -S UP -r $bw_($lnk) -D \\\n\
13143 $delay_($lnk) -o $linkAttr_($lnk:ORIENT)\"\n\
13144 }\n\
13145 }\n\
13146 \n\
13147 SessionSim instproc dump-namnodes {} {\n\
13148 $self instvar sessionNode_\n\
13149 if ![$self is-started] {\n\
13150 return\n\
13151 }\n\
13152 foreach nn [array names sessionNode_] {\n\
13153 if ![$sessionNode_($nn) is-lan?] {\n\
13154 $sessionNode_($nn) dump-namconfig\n\
13155 }\n\
13156 }\n\
13157 }     \n\
13158 \n\
13159 SessionSim instproc compute-routes {} {\n\
13160 if [Simulator hier-addr?] {\n\
13161 $self compute-hier-routes \n\
13162 } else {\n\
13163 $self compute-flat-routes\n\
13164 }\n\
13165 }\n\
13166 \n\
13167 SessionSim instproc compute-flat-routes {} {\n\
13168 $self instvar bw_\n\
13169 set r [$self get-routelogic]\n\
13170 foreach ln [array names bw_] {\n\
13171 set L [split $ln :]\n\
13172 set srcID [lindex $L 0]\n\
13173 set dstID [lindex $L 1]\n\
13174 if {$bw_($ln) != 0} {\n\
13175 $r insert $srcID $dstID\n\
13176 } else {\n\
13177 $r reset $srcID $dstID\n\
13178 }\n\
13179 }\n\
13180 $r compute\n\
13181 }\n\
13182 \n\
13183 SessionSim instproc compute-hier-routes {} {\n\
13184 $self instvar bw_\n\
13185 set r [$self get-routelogic]\n\
13186 set level [AddrParams hlevel]\n\
13187 $r hlevel-is $level\n\
13188 $self hier-topo $r\n\
13189 \n\
13190 foreach ln [array names bw_] {\n\
13191 set L [split $ln :]\n\
13192 set srcID [[$self get-node-by-id [lindex $L 0]] node-addr]\n\
13193 set dstID [[$self get-node-by-id [lindex $L 1]] node-addr]\n\
13194 if { $bw_($ln) != 0 } {\n\
13195 $r hier-insert $srcID $dstID\n\
13196 } else {\n\
13197 $r hier-reset $srcID $dstID\n\
13198 }\n\
13199 }       \n\
13200 $r hier-compute\n\
13201 }\n\
13202 \n\
13203 SessionSim instproc compute-algo-routes {} {\n\
13204 set r [$self get-routelogic]\n\
13205 \n\
13206 \n\
13207 $r BFS\n\
13208 $r compute\n\
13209 }\n\
13210 \n\
13211 SessionSim instproc dump-routelogic-distance {} {\n\
13212 $self instvar routingTable_ sessionNode_ bw_\n\
13213 if ![info exists routingTable_] {\n\
13214 puts \"error: routing table is not computed yet!\"\n\
13215 return 0\n\
13216 }\n\
13217 \n\
13218 set n [Node set nn_]\n\
13219 set i 0\n\
13220 puts -nonewline \"\\t\"\n\
13221 while { $i < $n } {\n\
13222 if ![info exists sessionNode_($i)] {\n\
13223 incr i\n\
13224 continue\n\
13225 }\n\
13226 puts -nonewline \"$i\\t\"\n\
13227 incr i\n\
13228 }\n\
13229 \n\
13230 set i 0\n\
13231 while { $i < $n } {\n\
13232 if ![info exists sessionNode_($i)] {\n\
13233 incr i\n\
13234 continue\n\
13235 }\n\
13236 puts -nonewline \"\\n$i\\t\"\n\
13237 set n1 $sessionNode_($i)\n\
13238 set j 0\n\
13239 while { $j < $n } {\n\
13240 if { $i != $j } {\n\
13241 set nh [$routingTable_ lookup $i $j]\n\
13242 if { $nh >= 0 } {\n\
13243 set distance 0\n\
13244 set tmpfrom $i\n\
13245 set tmpto $j\n\
13246 while {$tmpfrom != $tmpto} {\n\
13247 set tmpnext [$routingTable_ lookup $tmpfrom $tmpto]\n\
13248 set distance [expr $distance + 1]\n\
13249 set tmpfrom $tmpnext\n\
13250 }\n\
13251 puts -nonewline \"$distance\\t\"\n\
13252 } else {\n\
13253 puts -nonewline \"0\\t\"\n\
13254 }\n\
13255 } else {\n\
13256 puts -nonewline \"0\\t\"\n\
13257 }\n\
13258 incr j\n\
13259 }\n\
13260 incr i\n\
13261 }\n\
13262 puts \"\"\n\
13263 }\n\
13264 \n\
13265 SessionSim instproc run args {\n\
13266 $self rtmodel-configure                 ;# in case there are any\n\
13267 [$self get-routelogic] configure\n\
13268 $self instvar scheduler_ sessionNode_ started_\n\
13269 \n\
13270 set started_ 1\n\
13271 \n\
13272 foreach nn [array names sessionNode_] {\n\
13273 $sessionNode_($nn) reset\n\
13274 }\n\
13275 \n\
13276 if {[SessionSim set MixMode_]} {\n\
13277 foreach nn [array names Node_] {\n\
13278 $Node_($nn) reset\n\
13279 }\n\
13280 }\n\
13281 \n\
13282 $self dump-namcolors\n\
13283 $self dump-namnodes\n\
13284 $self dump-namlinks\n\
13285 $self dump-namagents\n\
13286 \n\
13287 return [$scheduler_ run]\n\
13288 }\n\
13289 \n\
13290 SessionSim instproc get-mcast-tree { src grp } {\n\
13291 $self instvar treeLinks_ session_\n\
13292 \n\
13293 if [info exists treeLinks_] {\n\
13294 unset treeLinks_\n\
13295 }\n\
13296 \n\
13297 set sid [$src id] \n\
13298 \n\
13299 foreach idx [array names session_] {\n\
13300 set tri [split $idx :]\n\
13301 if {[lindex $tri 0] == $sid && [lindex $tri 1] == $grp} {\n\
13302 set mbrs [$session_($idx) list-mbr]\n\
13303 break\n\
13304 }\n\
13305 }       \n\
13306 \n\
13307 foreach mbr $mbrs {\n\
13308 while {![string match \"Agent*\" [$mbr info class]]} {\n\
13309 set mbr [$mbr target]\n\
13310 }\n\
13311 set mid [[$mbr set node_] id]\n\
13312 if {$sid == $mid} {\n\
13313 continue\n\
13314 }\n\
13315 $self merge-path $sid $mid\n\
13316 }\n\
13317 \n\
13318 foreach lnk [array names treeLinks_] {\n\
13319 lappend res $lnk $treeLinks_($lnk)\n\
13320 }\n\
13321 return $res\n\
13322 }\n\
13323 \n\
13324 SessionSim instproc merge-path { src mbr } {\n\
13325 $self instvar routingTable_ treeLinks_ bw_\n\
13326 \n\
13327 set tmp $mbr\n\
13328 while {$tmp != $src} {\n\
13329 set nxt [$routingTable_ lookup $tmp $src]\n\
13330 if ![info exists treeLinks_($nxt:$tmp)] {\n\
13331 set treeLinks_($nxt:$tmp) $bw_($nxt:$tmp)\n\
13332 }\n\
13333 if [info exists treeLinks_($tmp:$nxt)] {\n\
13334 error \"Reverse links in a SPT!\"\n\
13335 }\n\
13336 set tmp $nxt\n\
13337 }\n\
13338 }\n\
13339 \n\
13340 SessionSim instproc get-node-by-id id {\n\
13341 $self instvar sessionNode_ Node_\n\
13342 if [info exists Node_($id)] {\n\
13343 set Node_($id)\n\
13344 } else {\n\
13345 set sessionNode_($id)\n\
13346 }\n\
13347 }\n\
13348 \n\
13349 SessionSim instproc get-node-id-by-addr address {\n\
13350 $self instvar sessionNode_\n\
13351 set n [Node set nn_]\n\
13352 for {set q 0} {$q < $n} {incr q} {\n\
13353 set nq $sessionNode_($q)\n\
13354 if {[string compare [$nq node-addr] $address] == 0} {\n\
13355 return $q\n\
13356 }\n\
13357 }\n\
13358 error \"get-node-id-by-addr:Cannot find node with given address\"\n\
13359 }\n\
13360 \n\
13361 Class SessionNode -superclass Node\n\
13362 SessionNode instproc init args {\n\
13363 $self instvar id_ np_ address_\n\
13364 set id_ [Node getid]\n\
13365 set np_ 0\n\
13366 if {[llength $args] > 0} {\n\
13367 set address_ $args\n\
13368 } else {\n\
13369 set address_ $id_\n\
13370 }\n\
13371 }\n\
13372 \n\
13373 SessionNode instproc id {} {\n\
13374 $self instvar id_\n\
13375 return $id_\n\
13376 }\n\
13377 \n\
13378 SessionNode instproc reset {} {\n\
13379 }\n\
13380 \n\
13381 SessionNode instproc alloc-port {} {\n\
13382 $self instvar np_\n\
13383 set p $np_\n\
13384 incr np_\n\
13385 return $p\n\
13386 }\n\
13387 \n\
13388 SessionNode instproc attach agent {\n\
13389 $self instvar id_ address_\n\
13390 $agent set node_ $self\n\
13391 set port [$self alloc-port]\n\
13392 $agent set agent_addr_ [AddrParams addr2id $address_]\n\
13393 $agent set agent_port_ $port\n\
13394 }\n\
13395 \n\
13396 SessionNode instproc join-group { rcvAgent group } {\n\
13397 set group [expr $group]\n\
13398 if {[SessionSim set MixMode_]} {\n\
13399 [Simulator instance] join-intermediate-session $rcvAgent $group\n\
13400 } else {\n\
13401 [Simulator instance] join-group $rcvAgent $group\n\
13402 }\n\
13403 }\n\
13404 \n\
13405 SessionNode instproc leave-group { rcvAgent group } {\n\
13406 set group [expr $group]\n\
13407 [Simulator instance] leave-group $rcvAgent $group\n\
13408 }\n\
13409 \n\
13410 \n\
13411 Agent/LossMonitor instproc show-delay { seqno delay } {\n\
13412 $self instvar node_\n\
13413 \n\
13414 puts \"[$node_ id] $seqno $delay\"\n\
13415 }\n\
13416 \n\
13417 \n\
13418 \n\
13419 SessionSim instproc RPF-link { src from to } {\n\
13420 $self instvar routingTable_ link_\n\
13421 if [info exists routingTable_] {\n\
13422 set tmp $to\n\
13423 while {$tmp != $src} {\n\
13424 set reverse [$routingTable_ lookup $tmp $src]\n\
13425 if [info exists link_($reverse:$tmp)] {\n\
13426 return $link_($reverse:$tmp)\n\
13427 }\n\
13428 set tmp $reverse\n\
13429 }\n\
13430 }\n\
13431 return \"\"\n\
13432 }\n\
13433 \n\
13434 SessionSim instproc detailed-link? { from to } {\n\
13435 $self instvar link_\n\
13436 \n\
13437 return [info exist link_($from:$to)]\n\
13438 }\n\
13439 \n\
13440 SessionSim instproc create-intermediate-session { src group nid } {\n\
13441 $self instvar session_\n\
13442 \n\
13443 set session_($src:$group:$nid) [new SessionHelper]\n\
13444 $session_($src:$group:$nid) set-node $nid\n\
13445 \n\
13446 if {[SessionSim set rc_]} {\n\
13447 $session_($src:$group:$nid) set rc_ 1\n\
13448 }\n\
13449 \n\
13450 set trace [$self get-nam-traceall]\n\
13451 if {$trace != \"\"} {\n\
13452 set p [$self create-trace SessEnque $trace $nid $dst \"nam\"]\n\
13453 $p target $session_($src:$group:$nid)\n\
13454 return $p\n\
13455 } else {\n\
13456 return $session_($src:$group:$nid)\n\
13457 }\n\
13458 \n\
13459 }\n\
13460 \n\
13461 SessionSim instproc join-intermediate-session { rcvAgent group } {\n\
13462 $self instvar session_ routingTable_ delay_ bw_ link_ Node_ dlist_\n\
13463 \n\
13464 foreach index [array names session_] {\n\
13465 set tri [split $index :]\n\
13466 set src [lindex $tri 0]\n\
13467 set grp [lindex $tri 1]\n\
13468 set owner [lindex $tri 2]\n\
13469 if {$grp == $group && $src == $owner} {\n\
13470 set session_area 1\n\
13471 set dst [[$rcvAgent set node_] id]\n\
13472 set delay 0\n\
13473 set accu_bw 0\n\
13474 set ttl 0\n\
13475 set tmp $dst\n\
13476 while {$tmp != $src} {\n\
13477 set next [$routingTable_ lookup $tmp $src]\n\
13478 \n\
13479 if {$session_area} {\n\
13480 if [info exist link_($tmp:$next)] {\n\
13481 \n\
13482 set session_area 0\n\
13483 if ![info exist session_($src:$grp:$tmp)] {\n\
13484 set inter_session [$self create-intermediate-session $src $grp $tmp]\n\
13485 } else {\n\
13486 set inter_session $session_($src:$grp:$tmp)\n\
13487 }\n\
13488 if {![info exist dlist_($src:$grp:$tmp)] || [lsearch $dlist_($src:$grp:$tmp) $rcvAgent] < 0 } {\n\
13489 $inter_session add-dst $accu_bw $delay $ttl $dst $rcvAgent\n\
13490 $self update-loss-dependency $src $dst $tmp $rcvAgent $group\n\
13491 lappend dlist_($src:$grp:$tmp) $rcvAgent\n\
13492 }\n\
13493 $Node_($tmp) join-group $inter_session $group\n\
13494 \n\
13495 } else {\n\
13496 \n\
13497 set delay [expr $delay + $delay_($tmp:$next)]\n\
13498 if {$accu_bw} {\n\
13499 set accu_bw [expr 1 / (1 / $accu_bw + 1 / $bw_($tmp:$next))]\n\
13500 } else {\n\
13501 set accu_bw $bw_($tmp:$next)\n\
13502 }\n\
13503 incr ttl\n\
13504 }\n\
13505 } else {\n\
13506 if [info exist link_($tmp:$next)] {\n\
13507 \n\
13508 } else {\n\
13509 \n\
13510 set session_area 1\n\
13511 set accu_bw $bw_($tmp:$next)\n\
13512 set delay $delay_($tmp:$next)\n\
13513 set ttl 1\n\
13514 set dst $tmp\n\
13515 set rcvAgent [$Node_($tmp) entry]\n\
13516 }\n\
13517 }\n\
13518 set tmp $next\n\
13519 }\n\
13520 \n\
13521 $self puts-nam-config \"G -t [$self now] -i $group -a $dst\"\n\
13522 \n\
13523 set f [$self get-nam-traceall]\n\
13524 \n\
13525 if {$session_area} {\n\
13526 if {$f != \"\"} { \n\
13527 set p [$self create-trace SessDeque $f $src $dst \"nam\"]\n\
13528 $p target $rcvAgent\n\
13529 if {![info exist dlist_($index)] || [lsearch $dlist_($index) $rcvAgent] < 0 } {\n\
13530 $session_($index) add-dst $accu_bw $delay $ttl $dst $p\n\
13531 $self update-loss-dependency $src $dst $src $p $group\n\
13532 lappend dlist_($index) $rcvAgent\n\
13533 }\n\
13534 } else {\n\
13535 if {![info exist dlist_($index)] || [lsearch $dlist_($index) $rcvAgent] < 0 } {\n\
13536 $session_($index) add-dst $accu_bw $delay $ttl $dst $rcvAgent\n\
13537 $self update-loss-dependency $src $dst $src $rcvAgent $group\n\
13538 lappend dlist_($index) $rcvAgent\n\
13539 }\n\
13540 }\n\
13541 } else {\n\
13542 if {$f != \"\"} { \n\
13543 set p [$self create-trace SessDeque $f $src $src \"nam\"]\n\
13544 $p target [$Node_($tmp) entry]\n\
13545 if {![info exist dlist_($index)] || [lsearch $dlist_($index) [$Node_($tmp) entry]] < 0 } {\n\
13546 $session_($index) add-dst 0 0 0 $src $p\n\
13547 $self update-loss-dependency $src $src $src $p $group\n\
13548 lappend dlist_($index) [$Node_($tmp) entry]\n\
13549 }\n\
13550 } else {\n\
13551 if {![info exist dlist_($index)] || [lsearch $dlist_($index) [$Node_($tmp) entry]] < 0 } {\n\
13552 $session_($index) add-dst 0 0 0 $src [$Node_($tmp) entry]\n\
13553 $self update-loss-dependency $src $src $src [$Node_($tmp) entry] $group\n\
13554 lappend dlist_($index) [$Node_($tmp) entry]\n\
13555 }\n\
13556 }\n\
13557 }\n\
13558 }\n\
13559 }\n\
13560 }\n\
13561 \n\
13562 \n\
13563 \n\
13564 PagePool instproc gen-page { pageid thismod } {\n\
13565 set size [$self gen-size $pageid]\n\
13566 if {$thismod >= 0} {\n\
13567 set age [expr [$self gen-modtime $pageid $thismod] - $thismod]\n\
13568 } else {\n\
13569 set age -1\n\
13570 }\n\
13571 return \"size $size age $age modtime $thismod\"\n\
13572 }\n\
13573 \n\
13574 Class PagePool/CompMath/noc -superclass PagePool/CompMath\n\
13575 \n\
13576 PagePool/CompMath/noc instproc gen-page { pageid thismod } {\n\
13577 set res [eval $self next $pageid $thismod]\n\
13578 if {$pageid == 0} {\n\
13579 return \"$res noc 1\"\n\
13580 } else {\n\
13581 return $res\n\
13582 }\n\
13583 }\n\
13584 \n\
13585 \n\
13586 Http/Server instproc init args {\n\
13587 eval $self next $args\n\
13588 $self instvar node_ stat_\n\
13589 $node_ color \"HotPink\"\n\
13590 array set stat_ [list hit-num 0 mod-num 0 barrival 0]\n\
13591 }\n\
13592 \n\
13593 Http/Server instproc set-page-generator { pagepool } {\n\
13594 $self instvar pgtr_\n\
13595 set pgtr_ $pagepool\n\
13596 }\n\
13597 \n\
13598 Http/Server instproc gen-init-modtime { id } {\n\
13599 $self instvar pgtr_ ns_\n\
13600 if [info exists pgtr_] {\n\
13601 return [$pgtr_ gen-init-modtime $id]\n\
13602 } else {\n\
13603 return [$ns_ now]\n\
13604 }\n\
13605 }\n\
13606 \n\
13607 Http/Server instproc stale-time { pageid modtime } {\n\
13608 $self instvar modseq_ modtimes_ ns_\n\
13609 for {set i $modseq_($pageid)} {$i >= 0} {incr i -1} {\n\
13610 if {$modtimes_($pageid:$i) <= $modtime} {\n\
13611 break\n\
13612 }\n\
13613 }\n\
13614 if {$i < 0} {\n\
13615 error \"Non-existent modtime $modtime for page $pageid\"\n\
13616 }\n\
13617 set ii [expr $i + 1]\n\
13618 set t1 [expr abs($modtimes_($pageid:$i) - $modtime)]\n\
13619 set t2 [expr abs($modtimes_($pageid:$ii) - $modtime)]\n\
13620 if {$t1 > $t2} {\n\
13621 incr ii\n\
13622 }\n\
13623 return [expr [$ns_ now] - $modtimes_($pageid:$ii)]\n\
13624 }\n\
13625 \n\
13626 Http/Server instproc modify-page { pageid } {\n\
13627 $self instvar ns_ id_ stat_ pgtr_\n\
13628 \n\
13629 incr stat_(mod-num)\n\
13630 set id [lindex [split $pageid :] end]\n\
13631 \n\
13632 set modtime [$ns_ now]\n\
13633 if [info exists pgtr_] {\n\
13634 set pginfo [$pgtr_ gen-page $id $modtime]\n\
13635 } else {\n\
13636 set pginfo \"size 2000 age 50 modtime $modtime\"\n\
13637 }\n\
13638 array set data $pginfo\n\
13639 set age $data(age)\n\
13640 $self schedule-nextmod [expr [$ns_ now] + $age] $pageid\n\
13641 eval $self enter-page $pageid $pginfo\n\
13642 \n\
13643 $ns_ trace-annotate \"S $id_ INV $pageid\"\n\
13644 $self evTrace S MOD p $pageid m [$ns_ now] n [expr [$ns_ now] + $age]\n\
13645 \n\
13646 $self instvar modtimes_ modseq_\n\
13647 incr modseq_($pageid)\n\
13648 set modtimes_($pageid:$modseq_($pageid)) $modtime\n\
13649 }\n\
13650 \n\
13651 Http/Server instproc schedule-nextmod { time pageid } {\n\
13652 $self instvar ns_\n\
13653 $ns_ at $time \"$self modify-page $pageid\"\n\
13654 }\n\
13655 \n\
13656 Http/Server instproc gen-page { pageid } {\n\
13657 set pginfo [$self gen-pageinfo $pageid]\n\
13658 eval $self enter-page $pageid $pginfo\n\
13659 return $pginfo\n\
13660 }\n\
13661 \n\
13662 Http/Server instproc gen-pageinfo { pageid } {\n\
13663 $self instvar ns_ pgtr_ \n\
13664 \n\
13665 if [$self exist-page $pageid] {\n\
13666 error \"$self: shouldn't use gen-page for existing pages\"\n\
13667 }\n\
13668 \n\
13669 set id [lindex [split $pageid :] end]\n\
13670 \n\
13671 set modtime [$self gen-init-modtime $id]\n\
13672 if [info exists pgtr_] {\n\
13673 set pginfo [$pgtr_ gen-page $id $modtime]\n\
13674 } else {\n\
13675 set pginfo \"size 2000 age 50 modtime $modtime\"\n\
13676 }\n\
13677 array set data $pginfo\n\
13678 set age $data(age)\n\
13679 if {$modtime >= 0} {\n\
13680 $self schedule-nextmod [expr [$ns_ now] + $age] $pageid\n\
13681 }\n\
13682 $self evTrace S MOD p $pageid m [$ns_ now] n [expr [$ns_ now] + $age]\n\
13683 \n\
13684 $self instvar modtimes_ modseq_\n\
13685 set modseq_($pageid) 0\n\
13686 set modtimes_($pageid:0) $modtime\n\
13687 \n\
13688 return [join $pginfo]\n\
13689 }\n\
13690 \n\
13691 Http/Server instproc disconnect { client } {\n\
13692 $self instvar ns_ clist_ node_\n\
13693 set pos [lsearch $clist_ $client]\n\
13694 if {$pos >= 0} {\n\
13695 lreplace $clist_ $pos $pos\n\
13696 } else { \n\
13697 error \"Http/Server::disconnect: not connected to $server\"\n\
13698 }\n\
13699 set tcp [[$self get-cnc $client] agent]\n\
13700 $self cmd disconnect $client\n\
13701 $tcp proc done {} \"$ns_ detach-agent $node_ $tcp; delete $tcp\"\n\
13702 $tcp close\n\
13703 }\n\
13704 \n\
13705 Http/Server instproc alloc-connection { client fid } {\n\
13706 Http instvar TRANSPORT_\n\
13707 $self instvar ns_ clist_ node_ fid_\n\
13708 \n\
13709 lappend clist_ $client\n\
13710 set snk [new Agent/TCP/$TRANSPORT_]\n\
13711 $snk set fid_ $fid\n\
13712 $ns_ attach-agent $node_ $snk\n\
13713 $snk listen\n\
13714 set wrapper [new Application/TcpApp $snk]\n\
13715 $self cmd connect $client $wrapper\n\
13716 return $wrapper\n\
13717 }\n\
13718 \n\
13719 Http/Server instproc handle-request-GET { pageid args } {\n\
13720 $self instvar ns_\n\
13721 \n\
13722 if [$self exist-page $pageid] {\n\
13723 set pageinfo [$self get-page $pageid]\n\
13724 } else {\n\
13725 set pageinfo [$self gen-page $pageid]\n\
13726 }\n\
13727 \n\
13728 lappend res [$self get-size $pageid]\n\
13729 eval lappend res $pageinfo\n\
13730 }\n\
13731 \n\
13732 Http/Server instproc handle-request-IMS { pageid args } {\n\
13733 array set data $args\n\
13734 set mt [$self get-modtime $pageid]\n\
13735 if {$mt <= $data(modtime)} {\n\
13736 set size [$self get-invsize]\n\
13737 set pageinfo \\\n\
13738 \"size $size modtime $mt time [$self get-cachetime $pageid]\"\n\
13739 $self evTrace S SND p $pageid m $mt z $size t IMS-NM\n\
13740 } else {\n\
13741 set size [$self get-size $pageid]\n\
13742 set pageinfo [$self get-page $pageid]\n\
13743 $self evTrace S SND p $pageid m $mt z $size t IMS-M\n\
13744 }\n\
13745 \n\
13746 lappend res $size\n\
13747 eval lappend res $pageinfo\n\
13748 return $res\n\
13749 }\n\
13750 \n\
13751 Http/Server instproc get-request { client type pageid args } {\n\
13752 $self instvar ns_ id_ stat_\n\
13753 \n\
13754 incr stat_(hit-num)\n\
13755 array set data $args\n\
13756 incr stat_(barrival) $data(size)\n\
13757 unset data\n\
13758 \n\
13759 \n\
13760 set res [eval $self handle-request-$type $pageid $args]\n\
13761 set size [lindex $res 0]\n\
13762 set pageinfo [lrange $res 1 end]\n\
13763 \n\
13764 $self send $client $size \\\n\
13765 \"$client get-response-$type $self $pageid $pageinfo\"\n\
13766 }\n\
13767 \n\
13768 Http/Server instproc set-parent-cache { cache } {\n\
13769 }\n\
13770 \n\
13771 \n\
13772 \n\
13773 Class Http/Server/epa -superclass Http/Server\n\
13774 \n\
13775 Http/Server/epa instproc start-update { interval } {\n\
13776 $self instvar pm_itv_ ns_\n\
13777 set pm_itv_ $interval\n\
13778 $ns_ at [expr [$ns_ now] + $pm_itv_] \"$self modify-page\"\n\
13779 }\n\
13780 \n\
13781 Http/Server/epa instproc schedule-nextmod { time pageid } {\n\
13782 $self instvar ns_ pm_itv_\n\
13783 $ns_ at [expr [$ns_ now]+$pm_itv_] \"$self modify-page $pageid\"\n\
13784 }\n\
13785 \n\
13786 Http/Server/epa instproc modify-page args {\n\
13787 $self instvar pgtr_\n\
13788 set pageid $self:[$pgtr_ pick-pagemod]\n\
13789 eval $self next $pageid\n\
13790 }\n\
13791 \n\
13792 Http/Server/epa instproc gen-pageinfo { pageid } {\n\
13793 $self instvar ns_ pgtr_ \n\
13794 \n\
13795 if [$self exist-page $pageid] {\n\
13796 error \"$self: shouldn't use gen-page for existing pages\"\n\
13797 }\n\
13798 \n\
13799 set id [lindex [split $pageid :] end]\n\
13800 \n\
13801 set modtime [$self gen-init-modtime $id]\n\
13802 if [info exists pgtr_] {\n\
13803 set pginfo [$pgtr_ gen-page $id $modtime]\n\
13804 } else {\n\
13805 set pginfo \"size 2000 age 50 modtime $modtime\"\n\
13806 }\n\
13807 array set data $pginfo\n\
13808 set age $data(age)\n\
13809 \n\
13810 $self instvar modtimes_ modseq_\n\
13811 set modseq_($pageid) 0\n\
13812 set modtimes_($pageid:0) $modtime\n\
13813 \n\
13814 return [join $pginfo]\n\
13815 }\n\
13816 \n\
13817 \n\
13818 Http/Server/Inval instproc modify-page { pageid } {\n\
13819 $self next $pageid\n\
13820 $self instvar ns_ id_\n\
13821 $self invalidate $pageid [$ns_ now]\n\
13822 }\n\
13823 \n\
13824 Http/Server/Inval instproc handle-request-REF { pageid args } {\n\
13825 return [eval $self handle-request-GET $pageid $args]\n\
13826 }\n\
13827 \n\
13828 \n\
13829 Class Http/Server/Inval/Ucast -superclass Http/Server/Inval\n\
13830 \n\
13831 Http/Server/Inval/Ucast instproc get-request { client type pageid args } {\n\
13832 eval $self next $client $type $pageid $args\n\
13833 \n\
13834 $self instvar cacheList_\n\
13835 if [info exists cacheList_($pageid)] {\n\
13836 set pos [lsearch $cacheList_($pageid) $client]\n\
13837 } else {\n\
13838 set pos -1\n\
13839 }\n\
13840 \n\
13841 if {$pos < 0 && [regexp \"Cache\" [$client info class]]} {\n\
13842 lappend cacheList_($pageid) $client\n\
13843 }\n\
13844 }\n\
13845 \n\
13846 Http/Server/Inval/Ucast instproc invalidate { pageid modtime } {\n\
13847 $self instvar cacheList_ \n\
13848 \n\
13849 if ![info exists cacheList_($pageid)] {\n\
13850 return\n\
13851 }\n\
13852 foreach c $cacheList_($pageid) {\n\
13853 set size [$self get-invsize]\n\
13854 \n\
13855 set agent [[$self get-cnc $c] agent]\n\
13856 set fid [$agent set fid_]\n\
13857 $agent_ set fid_ [Http set PINV_FID_]\n\
13858 $self send $c $size \\\n\
13859 \"$c invalidate $pageid $modtime\"\n\
13860 $agent_ set fid_ $fid\n\
13861 $self evTrace S INV p $pageid m $modtime z $size\n\
13862 }\n\
13863 }\n\
13864 \n\
13865 \n\
13866 Http/Server/Inval/Yuc instproc set-tlc { tlc } {\n\
13867 $self instvar tlc_\n\
13868 set tlc_ $tlc\n\
13869 }\n\
13870 \n\
13871 Http/Server/Inval/Yuc instproc get-tlc { tlc } {\n\
13872 $self instvar tlc_\n\
13873 return $tlc_\n\
13874 }\n\
13875 \n\
13876 Http/Server/Inval/Yuc instproc next-hb {} {\n\
13877 Http/Server/Inval/Yuc instvar hb_interval_ \n\
13878 return [expr $hb_interval_ * [uniform 0.9 1.1]]\n\
13879 }\n\
13880 \n\
13881 Http/Server/Inval/Yuc instproc set-parent-cache { cache } {\n\
13882 $self instvar pcache_\n\
13883 set pcache_ $cache\n\
13884 \n\
13885 $self send $pcache_ [$self get-joinsize] \\\n\
13886 \"$pcache_ server-join $self $self\"\n\
13887 \n\
13888 Http instvar TRANSPORT_\n\
13889 $self instvar ns_ node_\n\
13890 \n\
13891 set tcp [new Agent/TCP/$TRANSPORT_]\n\
13892 $tcp set fid_ [Http set HB_FID_]\n\
13893 $ns_ attach-agent $node_ $tcp\n\
13894 set dst [$pcache_ setup-unicast-hb]\n\
13895 set snk [$dst agent]\n\
13896 $ns_ connect $tcp $snk\n\
13897 $tcp set window_ 100\n\
13898 \n\
13899 set wrapper [new Application/TcpApp/HttpInval $tcp]\n\
13900 $wrapper connect $dst\n\
13901 $wrapper set-app $self\n\
13902 \n\
13903 $self add-inval-sender $wrapper\n\
13904 \n\
13905 $self instvar ns_\n\
13906 $ns_ at [expr [$ns_ now] + [$self next-hb]] \"$self heartbeat\"\n\
13907 }\n\
13908 \n\
13909 Http/Server/Inval/Yuc instproc heartbeat {} {\n\
13910 $self instvar pcache_ ns_\n\
13911 \n\
13912 $self cmd send-hb\n\
13913 $ns_ at [expr [$ns_ now] + [$self next-hb]] \\\n\
13914 \"$self heartbeat\"\n\
13915 }\n\
13916 \n\
13917 Http/Server/Inval/Yuc instproc get-request { cl type pageid args } {\n\
13918 eval $self next $cl $type $pageid $args\n\
13919 if {($type == \"GET\") || ($type == \"REF\")} {\n\
13920 $self count-request $pageid\n\
13921 }\n\
13922 }\n\
13923 \n\
13924 Http/Server/Inval/Yuc instproc invalidate { pageid modtime } {\n\
13925 $self instvar pcache_ id_ enable_upd_\n\
13926 \n\
13927 if ![info exists pcache_] {\n\
13928 error \"Server $id_ doesn't have a parent cache!\"\n\
13929 }\n\
13930 \n\
13931 $self count-inval $pageid\n\
13932 \n\
13933 if [$self is-pushable $pageid] {\n\
13934 $self push-page $pageid $modtime\n\
13935 return\n\
13936 }\n\
13937 \n\
13938 \n\
13939 $self cmd add-inv $pageid $modtime\n\
13940 $self evTrace S INV p $pageid m $modtime \n\
13941 }\n\
13942 \n\
13943 Http/Server/Inval/Yuc instproc push-page { pageid modtime } {\n\
13944 $self instvar pcache_ id_\n\
13945 \n\
13946 if ![info exists pcache_] {\n\
13947 error \"Server $id_ doesn't have a parent cache!\"\n\
13948 }\n\
13949 set size [$self get-size $pageid]\n\
13950 set pageinfo [$self get-page $pageid]\n\
13951 \n\
13952 set agent [[$self get-cnc $pcache_] agent]\n\
13953 set fid [$agent set fid_]\n\
13954 $agent set fid_ [Http set PINV_FID_]\n\
13955 $self send $pcache_ $size \\\n\
13956 \"$pcache_ push-update $pageid $pageinfo\"\n\
13957 $agent set fid_ $fid\n\
13958 $self evTrace S UPD p $pageid m $modtime z $size\n\
13959 }\n\
13960 \n\
13961 Http/Server/Inval/Yuc instproc get-req-notify { pageid } {\n\
13962 $self count-request $pageid\n\
13963 }\n\
13964 \n\
13965 Http/Server/Inval/Yuc instproc handle-request-TLC { pageid args } {\n\
13966 $self instvar tlc_\n\
13967 array set data $args\n\
13968 lappend res $data(size) ;# Same size of queries\n\
13969 lappend res $tlc_\n\
13970 return $res\n\
13971 }\n\
13972 \n\
13973 \n\
13974 Class Http/Server/Compound -superclass Http/Server\n\
13975 \n\
13976 Class Http/Server/Inval/MYuc -superclass \\\n\
13977 { Http/Server/Inval/Yuc Http/Server/Compound}\n\
13978 \n\
13979 \n\
13980 Http/Cache instproc init args {\n\
13981 eval $self next $args\n\
13982 \n\
13983 $self instvar node_ stat_\n\
13984 $node_ color \"yellow\" ;# no page\n\
13985 array set stat_ [list hit-num 0 barrival 0 ims-num 0]\n\
13986 }\n\
13987 \n\
13988 Http instproc set-cachesize { size } {\n\
13989 $self instvar pool_\n\
13990 $pool_ set max_size_ $size\n\
13991 }\n\
13992 \n\
13993 Http instproc get-cachesize {} {\n\
13994 $self instvar pool_\n\
13995 return [$pool_ set max_size_]\n\
13996 }\n\
13997 \n\
13998 Http/Cache instproc connect { server } {\n\
13999 $self next $server\n\
14000 }\n\
14001 \n\
14002 Http/Cache instproc disconnect { http } {\n\
14003 $self instvar slist_ clist_\n\
14004 \n\
14005 if [$http info class Http/Cache] {\n\
14006 error \"Cannot disconnect a cache from another cache\"\n\
14007 }\n\
14008 \n\
14009 if {[lsearch $slist_ $http] >= 0} {\n\
14010 $self disconnect-server $http\n\
14011 } else {\n\
14012 $self disconnect-client $http\n\
14013 }\n\
14014 }\n\
14015 \n\
14016 Http/Cache instproc disconnect-server { server } {\n\
14017 $self instvar ns_ slist_ node_\n\
14018 set pos [lsearch $slist_ $server]\n\
14019 if {$pos >= 0} {\n\
14020 lreplace $slist_ $pos $pos\n\
14021 } else { \n\
14022 error \"Http::disconnect: not connected to $server\"\n\
14023 }\n\
14024 set tcp [[$self get-cnc $server] agent]\n\
14025 $self cmd disconnect $server\n\
14026 $server disconnect $self\n\
14027 $tcp proc done {} \"$ns_ detach-agent $node_ $tcp; delete $tcp\"\n\
14028 $tcp close\n\
14029 \n\
14030 $self instvar pending_\n\
14031 foreach p [array names pending_] {\n\
14032 if {$server == [lindex [split $p :] 0]} {\n\
14033 unset pending_($p)\n\
14034 }\n\
14035 }\n\
14036 }\n\
14037 \n\
14038 Http/Cache instproc disconnect-client { client } {\n\
14039 $self instvar ns_ clist_ node_\n\
14040 set pos [lsearch $clist_ $client]\n\
14041 if {$pos >= 0} {\n\
14042 lreplace $clist_ $pos $pos\n\
14043 } else { \n\
14044 error \"Http/Cache::disconnect: not connected to $server\"\n\
14045 }\n\
14046 set tcp [[$self get-cnc $client] agent]\n\
14047 $self cmd disconnect $client\n\
14048 $tcp proc done {} \"$ns_ detach-agent $node_ $tcp; delete $tcp\"\n\
14049 $tcp close\n\
14050 \n\
14051 $self instvar creq_\n\
14052 foreach p [array names creq_] {\n\
14053 set res {}\n\
14054 for {set i 0} {$i < [llength $creq_($p)]} {incr i} {\n\
14055 set clt [lindex $creq_($p) $i]\n\
14056 if {$client != [lindex [split clt /] 0]} {\n\
14057 lappend res $clt\n\
14058 }\n\
14059 }\n\
14060 if {[llength $res] == 0} {\n\
14061 unset creq_($p)\n\
14062 } else {\n\
14063 set creq_($p) $res\n\
14064 }\n\
14065 }\n\
14066 }\n\
14067 \n\
14068 Http/Cache instproc set-parent { server } {\n\
14069 $self instvar parent_\n\
14070 set parent_ $server\n\
14071 }\n\
14072 \n\
14073 \n\
14074 Http/Cache instproc alloc-connection { client fid } {\n\
14075 Http instvar TRANSPORT_\n\
14076 $self instvar ns_ clist_ node_ id_ fid_\n\
14077 \n\
14078 lappend clist_ $client\n\
14079 set snk [new Agent/TCP/$TRANSPORT_]\n\
14080 $snk set fid_ $fid\n\
14081 $ns_ attach-agent $node_ $snk\n\
14082 $snk listen\n\
14083 set wrapper [new Application/TcpApp $snk]\n\
14084 $self cmd connect $client $wrapper\n\
14085 return $wrapper\n\
14086 }\n\
14087 \n\
14088 Http/Cache instproc send-request { server type pageid size args } {\n\
14089 $self instvar ns_ pending_  ;# pending requests, includes those \n\
14090 ;# from itself\n\
14091 \n\
14092 if ![$self is-connected $server] {\n\
14093 return\n\
14094 }\n\
14095 set pending_($pageid) [$ns_ now]\n\
14096 $self send $server $size \\\n\
14097 \"$server get-request $self $type $pageid size $size [join $args]\"\n\
14098 }\n\
14099 \n\
14100 Http/Cache instproc get-request { cl type pageid args } {\n\
14101 $self instvar slist_ clist_ ns_ id_ pending_ stat_\n\
14102 \n\
14103 incr stat_(hit-num)\n\
14104 array set data $args\n\
14105 if ![info exists data(size)] {\n\
14106 error \"Http/Cache $id_: client [$cl id] must include request size in its request\"\n\
14107 }\n\
14108 \n\
14109 if [$self exist-page $pageid] {\n\
14110 $self cache-hit $cl $type $pageid \n\
14111 } else {\n\
14112 $self cache-miss $cl $type $pageid\n\
14113 }\n\
14114 }\n\
14115 \n\
14116 Http/Cache instproc cache-miss { cl type pageid } {\n\
14117 $self instvar parent_ pending_ \\\n\
14118 creq_ ;# pending client requests\n\
14119 \n\
14120 lappend creq_($pageid) $cl/$type\n\
14121 \n\
14122 if [info exists pending_($pageid)] {\n\
14123 return\n\
14124 }\n\
14125 \n\
14126 set server [lindex [split $pageid :] 0]\n\
14127 if [info exists parent_] {\n\
14128 set server $parent_\n\
14129 }\n\
14130 \n\
14131 set size [$self get-reqsize]\n\
14132 $self evTrace E MISS p $pageid c [$cl id] s [$server id] z $size\n\
14133 $self send-request $server $type $pageid $size\n\
14134 }\n\
14135 \n\
14136 Http/Cache instproc is-consistent { cl type pageid } {\n\
14137 return 1\n\
14138 }\n\
14139 \n\
14140 Http/Cache instproc refetch-pending { cl type pageid } {\n\
14141 return 0\n\
14142 }\n\
14143 \n\
14144 Http/Cache instproc refetch args {\n\
14145 }\n\
14146 \n\
14147 Http/Cache instproc cache-hit { cl type pageid } {\n\
14148 if ![$self is-consistent $cl $type $pageid] {\n\
14149 if ![$self refetch-pending $cl $type $pageid] {\n\
14150 $self refetch $cl $type $pageid\n\
14151 }\n\
14152 return\n\
14153 }\n\
14154 set server [lindex [split $pageid :] 0]\n\
14155 $self evTrace E HIT p $pageid c [$cl id] s [$server id]\n\
14156 \n\
14157 eval $self answer-request-$type $cl $pageid [$self get-page $pageid]\n\
14158 }\n\
14159 \n\
14160 Http/Cache instproc get-response-GET { server pageid args } {\n\
14161 array set data $args\n\
14162 \n\
14163 if ![info exists data(noc)] {\n\
14164 if ![$self exist-page $pageid] {\n\
14165 eval $self enter-page $pageid $args\n\
14166 $self evTrace E ENT p $pageid m $data(modtime) \\\n\
14167 z $data(size) s [$server id]\n\
14168 } else {\n\
14169 $self instvar id_ ns_\n\
14170 puts stderr \"At [$ns_ now], cache $id_ has requested a page which it already has.\"\n\
14171 }\n\
14172 }\n\
14173 eval $self answer-pending-requests $pageid $args\n\
14174 \n\
14175 $self instvar stat_\n\
14176 incr stat_(barrival) $data(size)\n\
14177 \n\
14178 $self instvar node_\n\
14179 $node_ color \"blue\"   ;# valid page\n\
14180 }\n\
14181 \n\
14182 Http/Cache instproc answer-pending-requests { pageid args } {\n\
14183 $self instvar creq_ pending_\n\
14184 \n\
14185 array set data $args\n\
14186 if [info exists creq_($pageid)] {\n\
14187 foreach clt $creq_($pageid) {\n\
14188 set tmp [split $clt /]\n\
14189 set cl [lindex $tmp 0]\n\
14190 set type [lindex $tmp 1]\n\
14191 eval $self answer-request-$type $cl $pageid $args\n\
14192 }\n\
14193 unset creq_($pageid)\n\
14194 unset pending_($pageid)\n\
14195 } else {\n\
14196 unset pending_($pageid)\n\
14197 }\n\
14198 }\n\
14199 \n\
14200 Http/Cache instproc answer-request-GET { cl pageid args } {\n\
14201 array set data $args\n\
14202 $self send $cl $data(size) \\\n\
14203 \"$cl get-response-GET $self $pageid $args\"\n\
14204 $self evTrace E SND c [$cl id] p $pageid z $data(size)\n\
14205 }\n\
14206 \n\
14207 \n\
14208 Class Http/Cache/TTL -superclass Http/Cache\n\
14209 \n\
14210 Http/Cache/TTL set updateThreshold_ 0.1\n\
14211 \n\
14212 Http/Cache/TTL instproc init args {\n\
14213 eval $self next $args\n\
14214 \n\
14215 $self instvar thresh_\n\
14216 set thresh_ [Http/Cache/TTL set updateThreshold_]\n\
14217 }\n\
14218 \n\
14219 Http/Cache/TTL instproc set-thresh { th } {\n\
14220 $self instvar thresh_\n\
14221 set thresh_ $th\n\
14222 }\n\
14223 \n\
14224 Http/Cache/TTL instproc answer-request-IMS { client pageid args } {\n\
14225 if ![$self exist-page $pageid] {\n\
14226 error \"At [$ns_ now], cache [$self id] gets an IMS of a non-cacheable page.\"\n\
14227 }\n\
14228 \n\
14229 set mt [$self get-modtime $pageid]\n\
14230 if ![$client exist-page $pageid] {\n\
14231 error \"client [$client id] IMS a page which it doesn't have\"\n\
14232 }\n\
14233 if {$mt < [$client get-modtime $pageid]} {\n\
14234 error \"client [$client id] IMS a newer page\"\n\
14235 }\n\
14236 \n\
14237 if {$mt > [$client get-modtime $pageid]} {\n\
14238 set pginfo [$self get-page $pageid]\n\
14239 set size [$self get-size $pageid]\n\
14240 } else {\n\
14241 set size [$self get-invsize]\n\
14242 set pginfo \"size $size modtime $mt time [$self get-cachetime $pageid]\"\n\
14243 }\n\
14244 $self evTrace E SND c [$client id] t IMS z $size\n\
14245 $self send $client $size \\\n\
14246 \"$client get-response-IMS $self $pageid $pginfo\"\n\
14247 }\n\
14248 \n\
14249 Http/Cache/TTL instproc get-response-IMS { server pageid args } {\n\
14250 $self instvar ns_\n\
14251 \n\
14252 array set data $args\n\
14253 if {$data(modtime) > [$self get-modtime $pageid]} {\n\
14254 eval $self enter-page $pageid $args\n\
14255 $self evTrace E ENT p $pageid m [$self get-modtime $pageid] \\\n\
14256 z [$self get-size $pageid] s [$server id]\n\
14257 $self set-cachetime $pageid $data(time)\n\
14258 } else {\n\
14259 $self set-cachetime $pageid [$ns_ now]\n\
14260 }\n\
14261 eval $self answer-pending-requests $pageid [$self get-page $pageid]\n\
14262 \n\
14263 $self instvar stat_\n\
14264 incr stat_(barrival) $data(size)\n\
14265 }\n\
14266 \n\
14267 \n\
14268 Http/Cache/TTL instproc is-expired { pageid } {\n\
14269 $self instvar thresh_ ns_\n\
14270 set cktime [expr [$ns_ now] - [$self get-cachetime $pageid]]\n\
14271 set age [expr ([$ns_ now] - [$self get-modtime $pageid]) * $thresh_]\n\
14272 if {$cktime <= $age} {\n\
14273 return 0\n\
14274 }\n\
14275 return 1\n\
14276 }\n\
14277 \n\
14278 Http/Cache/TTL instproc is-consistent { cl type pageid } { \n\
14279 return ![$self is-expired $pageid]\n\
14280 }\n\
14281 \n\
14282 Http/Cache/TTL instproc refetch-pending { cl type pageid } {\n\
14283 $self instvar creq_ \n\
14284 if [info exists creq_($pageid)] {\n\
14285 if [regexp $cl:* $creq_($pageid)] {\n\
14286 return 1\n\
14287 }\n\
14288 lappend creq_($pageid) $cl/$type\n\
14289 return 1\n\
14290 }\n\
14291 lappend creq_($pageid) $cl/$type\n\
14292 return 0\n\
14293 }\n\
14294 \n\
14295 Http/Cache/TTL instproc refetch { cl type pageid } {\n\
14296 $self instvar parent_\n\
14297 \n\
14298 set server [lindex [split $pageid :] 0]\n\
14299 set size [$self get-imssize]\n\
14300 if [info exists parent_] {\n\
14301 set server $parent_\n\
14302 }\n\
14303 \n\
14304 $self instvar stat_\n\
14305 incr stat_(ims-num)\n\
14306 \n\
14307 $self evTrace E IMS p $pageid c [$cl id] s [$server id] z $size \\\n\
14308 t [$self get-cachetime $pageid] m [$self get-modtime $pageid]\n\
14309 $self send-request $server IMS $pageid $size \\\n\
14310 modtime [$self get-modtime $pageid]\n\
14311 return 0\n\
14312 }\n\
14313 \n\
14314 \n\
14315 Class Http/Cache/TTL/Plain -superclass Http/Cache/TTL\n\
14316 \n\
14317 Http/Cache/TTL/Plain set updateThreshold_ 100\n\
14318 \n\
14319 Http/Cache/TTL/Plain instproc init { args } {\n\
14320 eval $self next $args\n\
14321 $self instvar thresh_\n\
14322 set thresh_ [[$self info class] set updateThreshold_]\n\
14323 }\n\
14324 \n\
14325 Http/Cache/TTL/Plain instproc is-expired { pageid } {\n\
14326 $self instvar ns_ thresh_\n\
14327 set cktime [expr [$ns_ now] - [$self get-cachetime $pageid]]\n\
14328 if {$cktime < $thresh_} {\n\
14329 return 0\n\
14330 }\n\
14331 return 1\n\
14332 }\n\
14333 \n\
14334 \n\
14335 Class Http/Cache/TTL/Omniscient -superclass Http/Cache/TTL\n\
14336 \n\
14337 Http/Cache/TTL/Omniscient instproc is-expired { pageid } {\n\
14338 $self instvar ns_ \n\
14339 \n\
14340 set nmt [expr [$self get-modtime $pageid] + [$self get-age $pageid]]\n\
14341 if {[$ns_ now] >= $nmt} {\n\
14342 return 1\n\
14343 } \n\
14344 return 0\n\
14345 }\n\
14346 \n\
14347 \n\
14348 \n\
14349 Http/Cache/Inval instproc mark-invalid {} {\n\
14350 $self instvar node_\n\
14351 $node_ color \"red\"\n\
14352 }\n\
14353 \n\
14354 Http/Cache/Inval instproc mark-valid {} {\n\
14355 $self instvar node_ \n\
14356 $node_ color \"blue\"\n\
14357 }\n\
14358 \n\
14359 Http/Cache/Inval instproc mark-leave {} {\n\
14360 $self instvar node_ \n\
14361 $node_ add-mark down \"cyan\"\n\
14362 }\n\
14363 \n\
14364 Http/Cache/Inval instproc mark-rejoin {} {\n\
14365 $self instvar node_ \n\
14366 $node_ delete-mark down\n\
14367 }\n\
14368 \n\
14369 Http/Cache/Inval instproc answer-request-REF { cl pageid args } {\n\
14370 if ![$self exist-page $pageid] {\n\
14371 error \"At [$ns_ now], cache [$self id] gets a REF of a non-cacheable page.\"\n\
14372 }\n\
14373 \n\
14374 set pginfo [$self get-page $pageid]\n\
14375 set size [$self get-size $pageid]\n\
14376 $self evTrace E SND c [$cl id] t REF p $pageid z $size\n\
14377 $self send $cl $size \\\n\
14378 \"$cl get-response-REF $self $pageid $pginfo\"\n\
14379 }\n\
14380 \n\
14381 Http/Cache/Inval instproc get-response-GET { server pageid args } {\n\
14382 set sid [[lindex [split $pageid :] 0] id]\n\
14383 set cid [$server id]\n\
14384 $self check-sstate $sid $cid\n\
14385 eval $self next $server $pageid $args\n\
14386 }\n\
14387 \n\
14388 Http/Cache/Inval instproc get-response-REF { server pageid args } {\n\
14389 $self instvar creq_ id_ \n\
14390 \n\
14391 set sid [[lindex [split $pageid :] 0] id]\n\
14392 set cid [$server id]\n\
14393 $self check-sstate $sid $cid\n\
14394 \n\
14395 array set data $args\n\
14396 if {[$self get-modtime $pageid] > $data(modtime)} {\n\
14397 puts stderr \"At [$ns_ now], cache $self ($id_) refetched an old page\\\n\
14398 $pageid ($data(modtime), new time [$self get-modtime $pageid])\\\n\
14399 from [$server id]\"\n\
14400 } else {\n\
14401 eval $self enter-page $pageid $args\n\
14402 $self evTrace E UPD p $pageid m [$self get-modtime $pageid] \\\n\
14403 z [$self get-size $pageid] s [$server id]\n\
14404 }\n\
14405 eval $self answer-pending-requests $pageid [$self get-page $pageid]\n\
14406 \n\
14407 $self instvar node_ marks_ ns_\n\
14408 set mk [lindex $marks_($pageid) 0]\n\
14409 $node_ delete-mark $mk\n\
14410 set marks_($pageid) [lreplace $marks_($pageid) 0 0]\n\
14411 $node_ color \"blue\"\n\
14412 }\n\
14413 \n\
14414 Http/Cache/Inval instproc is-consistent { cl type pageid } {\n\
14415 return [$self is-valid $pageid]\n\
14416 }\n\
14417 \n\
14418 Http/Cache/Inval instproc refetch-pending { cl type pageid } {\n\
14419 $self instvar creq_ \n\
14420 if [info exists creq_($pageid)] {\n\
14421 if [regexp $cl:* $creq_($pageid)] {\n\
14422 return 1\n\
14423 }\n\
14424 lappend creq_($pageid) $cl/$type\n\
14425 return 1\n\
14426 }\n\
14427 lappend creq_($pageid) $cl/$type\n\
14428 return 0\n\
14429 }\n\
14430 \n\
14431 Http/Cache/Inval instproc refetch { cl type pageid } {\n\
14432 $self instvar parent_\n\
14433 \n\
14434 set size [$self get-refsize]\n\
14435 set server [lindex [split $pageid :] 0]\n\
14436 \n\
14437 if [info exists parent_] {\n\
14438 set par $parent_\n\
14439 } else {\n\
14440 set par $server\n\
14441 }\n\
14442 \n\
14443 $self evTrace E REF p $pageid s [$server id] z $size\n\
14444 $self send-request $par REF $pageid $size\n\
14445 \n\
14446 $self instvar node_ marks_ ns_\n\
14447 lappend marks_($pageid) $pageid:[$ns_ now]\n\
14448 $node_ add-mark $pageid:[$ns_ now] \"brown\"\n\
14449 }\n\
14450 \n\
14451 \n\
14452 \n\
14453 Http/Cache/Inval/Mcast instproc init args {\n\
14454 eval $self next $args\n\
14455 $self add-to-map\n\
14456 }\n\
14457 \n\
14458 Http/Cache/Inval/Mcast instproc get-response-GET { server pageid args } {\n\
14459 eval $self next $server $pageid $args\n\
14460 \n\
14461 set sid [[lindex [split $pageid :] 0] id]\n\
14462 set cid [$server id]\n\
14463 $self register-server $cid $sid\n\
14464 }\n\
14465 \n\
14466 Http/Cache/Inval/Mcast instproc set-parent { parent } {\n\
14467 $self next $parent\n\
14468 $self cmd set-parent $parent\n\
14469 }\n\
14470 \n\
14471 Http/Cache/Inval/Mcast instproc join-inval-group { group } {\n\
14472 $self instvar invalListener_ invListenGroup_ ns_ node_\n\
14473 \n\
14474 if [info exists invalListener_] {\n\
14475 return\n\
14476 }\n\
14477 set invalListener_ [new Agent/HttpInval]\n\
14478 set invListenGroup_ $group\n\
14479 $invalListener_ set dst_addr_ $group\n\
14480 $invalListener_ set dst_port_ 0\n\
14481 \n\
14482 $self add-inval-listener $invalListener_\n\
14483 $ns_ attach-agent $node_ $invalListener_\n\
14484 \n\
14485 $node_ join-group $invalListener_ $group\n\
14486 }\n\
14487 \n\
14488 Http/Cache/Inval/Mcast instproc init-inval-group { group } {\n\
14489 $self instvar invalSender_ invSndGroup_ ns_ node_\n\
14490 if [info exists invalSender_] {\n\
14491 return\n\
14492 }\n\
14493 set invalSender_ [new Agent/HttpInval]\n\
14494 set invSndGroup_ $group\n\
14495 $invalSender_ set dst_addr_ $group\n\
14496 $invalSender_ set dst_port_ 0\n\
14497 \n\
14498 $self add-inval-sender $invalSender_\n\
14499 $ns_ attach-agent $node_ $invalSender_\n\
14500 $node_ join-group $invalSender_ $group\n\
14501 \n\
14502 $self start-hbtimer\n\
14503 }\n\
14504 \n\
14505 Http/Cache/Inval/Mcast instproc parent-cache { server } {\n\
14506 $self instvar parent_\n\
14507 \n\
14508 set par [$self cmd parent-cache [$server id]]\n\
14509 if {$par == \"\"} {\n\
14510 if [info exists parent_] {\n\
14511 set par $parent_\n\
14512 } else {\n\
14513 set par $server\n\
14514 }\n\
14515 }\n\
14516 return $par\n\
14517 }\n\
14518 \n\
14519 Http/Cache/Inval/Mcast instproc refetch { cl type pageid } {\n\
14520 set size [$self get-refsize]\n\
14521 set server [lindex [split $pageid :] 0]\n\
14522 set par [$self parent-cache $server]\n\
14523 \n\
14524 $self evTrace E REF p $pageid s [$server id] z $size\n\
14525 $self send-request $par REF $pageid $size\n\
14526 \n\
14527 $self instvar node_ marks_ ns_\n\
14528 lappend marks_($pageid) $pageid:[$ns_ now]\n\
14529 $node_ add-mark $pageid:[$ns_ now] \"brown\"\n\
14530 }\n\
14531 \n\
14532 Http/Cache/Inval/Mcast instproc cache-miss { cl type pageid } {\n\
14533 $self instvar parent_ pending_ creq_ ;# pending client requests\n\
14534 \n\
14535 lappend creq_($pageid) $cl/$type\n\
14536 \n\
14537 if [info exists pending_($pageid)] {\n\
14538 return\n\
14539 }\n\
14540 \n\
14541 set size [$self get-reqsize]\n\
14542 set server [lindex [split $pageid :] 0]\n\
14543 $self evTrace E MISS p $pageid c [$cl id] s [$server id] z $size\n\
14544 \n\
14545 set par [$self cmd parent-cache [$server id]]\n\
14546 if {$par == \"\"} {\n\
14547 if [info exists parent_] {\n\
14548 set par $parent_\n\
14549 } else {\n\
14550 $self instvar ns_ id_\n\
14551 $self send-request $server TLC $pageid $size\n\
14552 return\n\
14553 }\n\
14554 }\n\
14555 $self send-request $par $type $pageid $size\n\
14556 }\n\
14557 \n\
14558 Http/Cache/Inval/Mcast instproc invalidate { pageid modtime } {\n\
14559 if [$self recv-inv $pageid $modtime] {\n\
14560 $self instvar parent_ \n\
14561 if ![info exists parent_] {\n\
14562 return\n\
14563 }\n\
14564 set size [$self get-invsize]\n\
14565 $self evTrace E SND t INV c [$parent_ id] p $pageid z $size\n\
14566 \n\
14567 set agent [[$self get-cnc $parent_] agent]\n\
14568 set fid [$agent set fid_]\n\
14569 $agent set fid_ [Http set PINV_FID_]\n\
14570 $self send $parent_ $size \\\n\
14571 \"$parent_ invalidate $pageid $modtime\"\n\
14572 $agent set fid_ $fid\n\
14573 }\n\
14574 }\n\
14575 \n\
14576 Http/Cache/Inval/Mcast instproc get-request { cl type pageid args } {\n\
14577 eval $self next $cl $type $pageid $args\n\
14578 if {(($type == \"GET\") || ($type == \"REF\")) && \\\n\
14579 [$self exist-page $pageid]} {\n\
14580 $self count-request $pageid\n\
14581 if [$self is-unread $pageid] {\n\
14582 $self send-req-notify $pageid\n\
14583 $self set-read $pageid\n\
14584 }\n\
14585 }\n\
14586 }\n\
14587 \n\
14588 Http/Cache/Inval/Mcast instproc get-req-notify { pageid } {\n\
14589 $self count-request $pageid\n\
14590 if [$self is-unread $pageid] {\n\
14591 $self set-read $pageid\n\
14592 $self send-req-notify $pageid\n\
14593 }\n\
14594 }\n\
14595 \n\
14596 Http/Cache/Inval/Mcast instproc send-req-notify { pageid } {\n\
14597 set server [lindex [split $pageid :] 0]\n\
14598 set par [$self parent-cache $server]\n\
14599 $self send $par [$self get-ntfsize] \"$par get-req-notify $pageid\"\n\
14600 }\n\
14601 \n\
14602 Http/Cache/Inval/Mcast instproc push-update { pageid args } {\n\
14603 if [eval $self recv-push $pageid $args] {\n\
14604 \n\
14605 $self instvar parent_ \n\
14606 if [info exists parent_] {\n\
14607 set pginfo [$self get-page $pageid]\n\
14608 set size [$self get-size $pageid]\n\
14609 $self evTrace E UPD c [$parent_ id] p $pageid z $size\n\
14610 $self send $parent_ $size \\\n\
14611 \"$parent_ push-update $pageid $pginfo\"\n\
14612 }\n\
14613 $self push-children $pageid\n\
14614 }\n\
14615 }\n\
14616 \n\
14617 Http/Cache/Inval/Mcast instproc init-update-group { group } {\n\
14618 $self instvar ns_ node_ updSender_ updSendGroup_\n\
14619 \n\
14620 set snd [new Agent/HttpInval]\n\
14621 $snd set dst_addr_ $group\n\
14622 $snd set dst_port_ 0\n\
14623 $self add-upd-sender $snd\n\
14624 $ns_ attach-agent $node_ $snd\n\
14625 $node_ join-group $snd $group\n\
14626 }\n\
14627 \n\
14628 Http/Cache/Inval/Mcast instproc join-update-group { group }  {\n\
14629 $self instvar updListener_ updListenGroup_ ns_ node_\n\
14630 \n\
14631 set updListenGroup_ $group\n\
14632 if ![info exists updListener_] {\n\
14633 set updListener_ [new Agent/HttpInval]\n\
14634 $self add-upd-listener $updListener_\n\
14635 $updListener_ set dst_addr_ $updListenGroup_\n\
14636 $updListener_ set dst_port_ 0\n\
14637 $ns_ attach-agent $node_ $updListener_\n\
14638 }\n\
14639 $node_ join-group $updListener_ $updListenGroup_\n\
14640 }\n\
14641 \n\
14642 Http/Cache/Inval/Mcast instproc leave-update-group {} {\n\
14643 $self instvar updListener_ updListenGroup_ ns_ node_\n\
14644 if ![info exists updListener_] {\n\
14645 return\n\
14646 }\n\
14647 $node_ leave-group $updListener_ $updListenGroup_\n\
14648 $node_ delete-mark \"Updating\"\n\
14649 }\n\
14650 \n\
14651 Http/Cache/Inval/Mcast instproc setup-unicast-hb {} {\n\
14652 Http instvar TRANSPORT_\n\
14653 $self instvar node_ ns_\n\
14654 \n\
14655 set snk [new Agent/TCP/$TRANSPORT_]\n\
14656 $snk set fid_ [Http set HB_FID_]\n\
14657 $ns_ attach-agent $node_ $snk\n\
14658 $snk listen\n\
14659 set wrapper [new Application/TcpApp/HttpInval $snk]\n\
14660 $wrapper set-app $self\n\
14661 return $wrapper\n\
14662 }\n\
14663 \n\
14664 Http/Cache/Inval/Mcast instproc server-join { server cache } {\n\
14665 $self cmd join [$server id] $cache\n\
14666 \n\
14667 \n\
14668 $self instvar parent_\n\
14669 if ![info exists parent_] {\n\
14670 return\n\
14671 }\n\
14672 \n\
14673 $self send $parent_ [$self get-joinsize] \\\n\
14674 \"$parent_ server-join $server $self\"\n\
14675 \n\
14676 Http instvar TRANSPORT_\n\
14677 $self instvar ns_ node_\n\
14678 \n\
14679 set tcp [new Agent/TCP/$TRANSPORT_]\n\
14680 $tcp set fid_ [Http set HB_FID_]\n\
14681 $ns_ attach-agent $node_ $tcp\n\
14682 set dst [$parent_ setup-unicast-hb]\n\
14683 set snk [$dst agent]\n\
14684 $ns_ connect $tcp $snk\n\
14685 $tcp set window_ 100\n\
14686 \n\
14687 set wrapper [new Application/TcpApp/HttpInval $tcp]\n\
14688 $wrapper connect $dst\n\
14689 $wrapper set-app $self\n\
14690 \n\
14691 $self set-pinv-agent $wrapper\n\
14692 \n\
14693 $self start-hbtimer\n\
14694 }\n\
14695 \n\
14696 Http/Cache/Inval/Mcast instproc request-mpush { page } {\n\
14697 $self instvar mpush_refresh_ ns_ hb_interval_\n\
14698 if [info exists mpush_refresh_($page)] {\n\
14699 return\n\
14700 }\n\
14701 $self set-mandatory-push $page\n\
14702 \n\
14703 set server [lindex [split $page :] 0]\n\
14704 set cache [$self parent-cache $server]\n\
14705 \n\
14706 set mpush_refresh_($page) [$ns_ at [expr [$ns_ now] + $hb_interval_] \\\n\
14707 \"$self send-refresh-mpush $cache $page\"]\n\
14708 $self send $cache [$self get-mpusize] \"$cache request-mpush $page\"\n\
14709 }\n\
14710 \n\
14711 Http/Cache/Inval/Mcast instproc refresh-mpush { page } {\n\
14712 $self cmd set-mandatory-push $page\n\
14713 }\n\
14714 \n\
14715 Http/Cache/Inval/Mcast instproc send-refresh-mpush { cache page } {\n\
14716 $self instvar mpush_refresh_ ns_ hb_interval_\n\
14717 $self send $cache [$self get-mpusize] \"$cache refresh-mpush $page\"\n\
14718 set mpush_refresh_($page) [$ns_ at [expr [$ns_ now] + $hb_interval_] \\\n\
14719 \"$self send-refresh-mpush $cache $page\"]\n\
14720 }\n\
14721 \n\
14722 Http/Cache/Inval/Mcast instproc cancel-mpush-refresh { page } {\n\
14723 $self instvar mpush_refresh_ ns_ \n\
14724 if [info exists mpush_refresh_($page)] {\n\
14725 $ns_ cancel $mpush_refresh_($page)\n\
14726 } else {\n\
14727 error \"Cache [$self id]: No mpush to stop!\"\n\
14728 }\n\
14729 }\n\
14730 \n\
14731 Http/Cache/Inval/Mcast instproc stop-mpush { page } {\n\
14732 $self cancel-mpush-refresh $page\n\
14733 \n\
14734 $self cmd stop-mpush $page\n\
14735 \n\
14736 set server [lindex [split $page :] 0]\n\
14737 set cache [$self parent-cache $server]\n\
14738 $self send $cache [$self get-mpusize] \"$cache stop-mpush $page\"\n\
14739 }\n\
14740 \n\
14741 Http/Cache/Inval/Mcast instproc join-tlc-group { group } {\n\
14742 $self instvar tlcAgent_ tlcGroup_ ns_ node_\n\
14743 \n\
14744 if [info exists tlcAgent_] {\n\
14745 return \n\
14746 }\n\
14747 set tlcAgent_ [new Agent/HttpInval]\n\
14748 set tlcGroup_ $group\n\
14749 $tlcAgent_ set dst_addr_ $group\n\
14750 $tlcAgent_ set dst_port_ 0\n\
14751 \n\
14752 $self add-inval-sender $tlcAgent_\n\
14753 $self add-inval-listener $tlcAgent_\n\
14754 $ns_ attach-agent $node_ $tlcAgent_\n\
14755 $node_ join-group $tlcAgent_ $group\n\
14756 }\n\
14757 \n\
14758 Http/Cache/Inval/Mcast instproc get-response-TLC { server pageid tlc } {\n\
14759 $self register-server [$tlc id] [$server id]\n\
14760 $self instvar ns_ id_\n\
14761 $self send-request $tlc GET $pageid [$self get-reqsize]\n\
14762 }\n\
14763 \n\
14764 \n\
14765 \n\
14766 Http/Cache/Inval/Mcast/Perc instproc check-sstate {sid cid} {\n\
14767 $self instvar direct_request_\n\
14768 if !$direct_request_ {\n\
14769 $self cmd check-sstate $sid $cid\n\
14770 }\n\
14771 }\n\
14772 \n\
14773 Http/Cache/Inval/Mcast/Perc instproc register-server {cid sid} {\n\
14774 $self instvar parent_ direct_request_\n\
14775 if {$direct_request_ && [info exists parent_]} {\n\
14776 $self cmd register-server [$parent_ id] $sid\n\
14777 } \n\
14778 }\n\
14779 \n\
14780 Http/Cache/Inval/Mcast/Perc instproc cache-miss { cl type pageid } {\n\
14781 $self instvar direct_request_\n\
14782 \n\
14783 if !$direct_request_ {\n\
14784 $self next $cl $type $pageid\n\
14785 return\n\
14786 }\n\
14787 \n\
14788 \n\
14789 $self instvar parent_ pending_ creq_ ;# pending client requests\n\
14790 $self instvar dreq_ ;# pending direct requests\n\
14791 \n\
14792 lappend creq_($pageid) $cl/$type\n\
14793 \n\
14794 if [info exists pending_($pageid)] {\n\
14795 return\n\
14796 }\n\
14797 \n\
14798 $self instvar dreq_\n\
14799 set dreq_($pageid) 1\n\
14800 \n\
14801 set server [lindex [split $pageid :] 0]\n\
14802 set size [$self get-reqsize]\n\
14803 $self evTrace E MISS p $pageid c [$cl id] s [$server id] z $size\n\
14804 $self send-request $server $type $pageid $size\n\
14805 }\n\
14806 \n\
14807 Http/Cache/Inval/Mcast/Perc instproc refetch { cl type pageid } {\n\
14808 $self instvar direct_request_\n\
14809 \n\
14810 if !$direct_request_ {\n\
14811 $self next $cl $type $pageid\n\
14812 return\n\
14813 }\n\
14814 \n\
14815 $self instvar dreq_\n\
14816 set dreq_($pageid) 1\n\
14817 \n\
14818 set size [$self get-refsize]\n\
14819 set server [lindex [split $pageid :] 0]\n\
14820 $self evTrace E REF p $pageid s [$server id] z $size \n\
14821 $self send-request $server REF $pageid $size\n\
14822 \n\
14823 $self instvar node_ marks_ ns_\n\
14824 lappend marks_($pageid) $pageid:[$ns_ now]\n\
14825 $node_ add-mark $pageid:[$ns_ now] \"brown\"\n\
14826 }\n\
14827 \n\
14828 Http/Cache/Inval/Mcast/Perc instproc get-response-GET { server pageid args } {\n\
14829 eval $self next $server $pageid $args\n\
14830 \n\
14831 $self instvar dreq_ \n\
14832 if [info exists dreq_($pageid)] {\n\
14833 eval $self send-proforma $pageid $args\n\
14834 unset dreq_($pageid)\n\
14835 }\n\
14836 }\n\
14837 \n\
14838 Http/Cache/Inval/Mcast/Perc instproc get-response-REF { server pageid args } {\n\
14839 eval $self next $server $pageid $args\n\
14840 $self instvar dreq_\n\
14841 if [info exists dreq_($pageid)] {\n\
14842 eval $self send-proforma $pageid $args\n\
14843 unset dreq_($pageid)\n\
14844 }\n\
14845 }\n\
14846 \n\
14847 Http/Cache/Inval/Mcast/Perc instproc send-proforma { pageid args } {\n\
14848 set server [lindex [split $pageid :] 0]\n\
14849 set par [$self parent-cache $server]\n\
14850 if {$par == $server} {\n\
14851 return\n\
14852 } elseif {$par == \"\"} {\n\
14853 set par [$server get-tlc]\n\
14854 }\n\
14855 $self send $par [$self get-pfsize] \\\n\
14856 \"$par recv-proforma $self $pageid [join $args]\"\n\
14857 $self evTrace E SPF p $pageid c [$par id]\n\
14858 }\n\
14859 \n\
14860 Http/Cache/Inval/Mcast/Perc instproc get-response-IMS { server pageid args } {\n\
14861 $self instvar ns_ \n\
14862 \n\
14863 array set data $args\n\
14864 if {$data(modtime) <= [$self get-modtime $pageid]} {\n\
14865 return\n\
14866 }\n\
14867 $self invalidate $pageid \n\
14868 eval $self enter-page $pageid $args\n\
14869 $self mark-valid\n\
14870 }\n\
14871 \n\
14872 Http/Cache/Inval/Mcast/Perc instproc mark-valid-hdr {} {\n\
14873 $self instvar node_\n\
14874 $node_ color \"orange\"\n\
14875 }\n\
14876 \n\
14877 Http/Cache/Inval/Mcast/Perc instproc recv-proforma { cache pageid args } {\n\
14878 $self instvar stat_\n\
14879 incr stat_(hit-num)\n\
14880 \n\
14881 $self evTrace E RPF p $pageid c [$cache id]\n\
14882 \n\
14883 array set data $args\n\
14884 if ![$self exist-page $pageid] {\n\
14885 eval $self enter-metadata $pageid $args\n\
14886 $self mark-valid-hdr\n\
14887 \n\
14888 set server [lindex [split $pageid :] 0]\n\
14889 set par [$self parent-cache $server]\n\
14890 if {$par == $server} {\n\
14891 $self send-request $par IMS $pageid \\\n\
14892 [$self get-imssize] modtime $data(modtime)\n\
14893 } else {\n\
14894 eval $self send-proforma $pageid $args\n\
14895 }\n\
14896 } elseif [$self is-valid $pageid] {\n\
14897 set mt [$self get-modtime $pageid]\n\
14898 if {$data(modtime) < $mt} {\n\
14899 $self recv-inv $pageid $data(modtime)\n\
14900 return\n\
14901 } elseif {$data(modtime) > $mt} {\n\
14902 $self recv-inv $pageid $data(modtime)\n\
14903 eval $self enter-metadata $pageid $args\n\
14904 $self mark-valid-hdr\n\
14905 eval $self send-proforma $pageid $args\n\
14906 }\n\
14907 $self count-request $pageid\n\
14908 if [$self is-unread $pageid] {\n\
14909 $self set-read $pageid\n\
14910 }\n\
14911 } else {\n\
14912 array set data $args\n\
14913 set mt [$self get-modtime $pageid]\n\
14914 if {$data(modtime) < $mt} {\n\
14915 return\n\
14916 } \n\
14917 eval $self enter-metadata $pageid $args\n\
14918 $self mark-valid-hdr\n\
14919 \n\
14920 eval $self send-proforma $pageid $args\n\
14921 }\n\
14922 }\n\
14923 \n\
14924 \n\
14925 Http set id_ 0  ;# required by TclCL\n\
14926 Http set TRANSPORT_ FullTcp\n\
14927 Http set HB_FID_ 40\n\
14928 Http set PINV_FID_ 41\n\
14929 \n\
14930 Http set INVSize_ 43    ;# unicast invalidation\n\
14931 Http set REQSize_ 43    ;# Request\n\
14932 Http set REFSize_ 50    ;# Refetch request\n\
14933 Http set IMSSize_ 50    ;# If-Modified-Since\n\
14934 Http set JOINSize_ 10   ;# Server join/leave\n\
14935 Http set HBSize_ 1  ;# Used by Http/Server/Inval only\n\
14936 Http set PFSize_ 1  ;# Pro forma\n\
14937 Http set NTFSize_ 10    ;# Request Notification\n\
14938 Http set MPUSize_ 10    ;# Mandatory push request\n\
14939 \n\
14940 Http/Server set id_ 0\n\
14941 Http/Server/Inval set id_ 0\n\
14942 Http/Server/Inval/Yuc set hb_interval_ 60\n\
14943 Http/Server/Inval/Yuc set enable_upd_ 0\n\
14944 Http/Server/Inval/Yuc set Ca_ 1\n\
14945 Http/Server/Inval/Yuc set Cb_ 4\n\
14946 Http/Server/Inval/Yuc set push_thresh_ 4\n\
14947 Http/Server/Inval/Yuc set push_low_bound_ 0\n\
14948 Http/Server/Inval/Yuc set push_high_bound_ 8\n\
14949 \n\
14950 Http/Cache set id_ 0\n\
14951 Http/Cache/Inval set id_ 0\n\
14952 Http/Cache/Inval/Mcast set hb_interval_ 60\n\
14953 Http/Cache/Inval/Mcast set upd_interval_ 5\n\
14954 Http/Cache/Inval/Mcast set enable_upd_ 0\n\
14955 Http/Cache/Inval/Mcast set Ca_ 1\n\
14956 Http/Cache/Inval/Mcast set Cb_ 4\n\
14957 Http/Cache/Inval/Mcast set push_thresh_ 4\n\
14958 Http/Cache/Inval/Mcast set push_low_bound_ 0\n\
14959 Http/Cache/Inval/Mcast set push_high_bound_ 8\n\
14960 Http/Cache/Inval/Mcast/Perc set direct_request_ 0\n\
14961 \n\
14962 PagePool/CompMath set num_pages_ 1\n\
14963 PagePool/CompMath set main_size_ 1024\n\
14964 PagePool/CompMath set comp_size_ 10240\n\
14965 \n\
14966 Http set MEDIA_TRANSPORT_ RAP\n\
14967 Http set MEDIA_APP_ MediaApp\n\
14968 Application/MediaApp set segmentSize_ 1024\n\
14969 Application/MediaApp set MAX_LAYER_ 10\n\
14970 Application/MediaApp/QA set LAYERBW_ 2500 ;# Byte per-second\n\
14971 Application/MediaApp/QA set MAXACTIVELAYERS_ 10\n\
14972 Application/MediaApp/QA set SRTTWEIGHT_ 0.95\n\
14973 Application/MediaApp/QA set SMOOTHFACTOR_ 4\n\
14974 Application/MediaApp/QA set MAXBKOFF_ 100\n\
14975 Application/MediaApp/QA set debug_output_ 0\n\
14976 Application/MediaApp/QA set pref_srtt_ 0.6\n\
14977 PagePool/Client/Media set max_size_ 104857600 \n\
14978 \n\
14979 \n\
14980 Http instproc init { ns node } {\n\
14981 $self next\n\
14982 $self instvar ns_ node_ id_ pool_\n\
14983 set ns_ $ns\n\
14984 set node_ $node\n\
14985 $self set id_ [$node_ id]\n\
14986 set pool_ [$self create-pagepool]\n\
14987 }\n\
14988 \n\
14989 Http instproc create-pagepool {} {\n\
14990 set pool [new PagePool/Client]\n\
14991 $self set-pagepool $pool\n\
14992 return $pool\n\
14993 }\n\
14994 \n\
14995 Http instproc addr {} {\n\
14996 $self instvar node_ \n\
14997 return [$node_ node-addr]\n\
14998 }\n\
14999 \n\
15000 Http set fid_ -1\n\
15001 Http instproc getfid {} {\n\
15002 $self instvar fid_\n\
15003 set fid_ [Http set fid_]\n\
15004 Http set fid_ [incr fid_]\n\
15005 }\n\
15006 \n\
15007 Http instproc get-mpusize {} {\n\
15008 return [Http set MPUSize_]\n\
15009 }\n\
15010 \n\
15011 Http instproc get-ntfsize {} {\n\
15012 return [Http set NTFSize_]\n\
15013 }\n\
15014 \n\
15015 Http instproc get-pfsize {} {\n\
15016 return [Http set PFSize_]\n\
15017 }\n\
15018 \n\
15019 Http instproc get-hbsize {} {\n\
15020 return [Http set HBSize_]\n\
15021 }\n\
15022 \n\
15023 Http instproc get-imssize {} {\n\
15024 return [Http set IMSSize_]\n\
15025 }\n\
15026 \n\
15027 Http instproc get-invsize {} {\n\
15028 return [Http set INVSize_]\n\
15029 }\n\
15030 \n\
15031 Http instproc get-reqsize {} {\n\
15032 return [Http set REQSize_]\n\
15033 }\n\
15034 \n\
15035 Http instproc get-refsize {} {\n\
15036 return [Http set REFSize_]\n\
15037 }\n\
15038 \n\
15039 Http instproc get-joinsize {} {\n\
15040 return [Http set JOINSize_]\n\
15041 }\n\
15042 \n\
15043 Http instproc connect { server } {\n\
15044 Http instvar TRANSPORT_\n\
15045 $self instvar ns_ slist_ node_ fid_ id_\n\
15046 \n\
15047 lappend slist_ $server\n\
15048 set tcp [new Agent/TCP/$TRANSPORT_]\n\
15049 $tcp set fid_ [$self getfid]\n\
15050 $ns_ attach-agent $node_ $tcp\n\
15051 \n\
15052 set ret [$server alloc-connection $self $fid_]\n\
15053 set snk [$ret agent]\n\
15054 $ns_ connect $tcp $snk\n\
15055 $tcp set window_ 100\n\
15056 \n\
15057 set wrapper [new Application/TcpApp $tcp]\n\
15058 $self cmd connect $server $wrapper\n\
15059 $wrapper connect $ret\n\
15060 }\n\
15061 \n\
15062 Http instproc stat { name } {\n\
15063 $self instvar stat_\n\
15064 return $stat_($name)\n\
15065 }\n\
15066 \n\
15067 \n\
15068 Http/Client set hb_interval_ 60\n\
15069 \n\
15070 Http/Client instproc init args {\n\
15071 eval $self next $args\n\
15072 $self instvar node_ stat_\n\
15073 $node_ color \"SteelBlue\"\n\
15074 array set stat_ [list req-num 0 stale-num 0 stale-time 0 rep-time 0 \\\n\
15075 rt-min 987654321 rt-max 0 st-min 987654321 st-max 0]\n\
15076 }\n\
15077 \n\
15078 Http/Client instproc disconnect { server } {\n\
15079 $self instvar ns_ slist_ \n\
15080 set pos [lsearch $slist_ $server]\n\
15081 if {$pos >= 0} {\n\
15082 lreplace $slist_ $pos $pos\n\
15083 } else { \n\
15084 error \"Http::disconnect: not connected to $server\"\n\
15085 }\n\
15086 \n\
15087 $self instvar ns_ node_ cache_\n\
15088 $self stop-session $server\n\
15089 \n\
15090 set tcp [[$self get-cnc $server] agent]\n\
15091 $self cmd disconnect $server\n\
15092 $server disconnect $self\n\
15093 $tcp proc done {} \"$ns_ detach-agent $node_ $tcp; delete $tcp\"\n\
15094 $tcp close\n\
15095 }\n\
15096 \n\
15097 Http/Client instproc send-request { server type pageid args } {\n\
15098 $self instvar ns_ pending_  ;# unansewered requests\n\
15099 \n\
15100 if ![$self cmd is-connected $server] {\n\
15101 return\n\
15102 }\n\
15103 \n\
15104 if ![info exists pending_($pageid)] { \n\
15105 lappend pending_($pageid) [$ns_ now]\n\
15106 } else {\n\
15107 return\n\
15108 }\n\
15109 \n\
15110 set size [$self get-reqsize]\n\
15111 $self send $server $size \\\n\
15112 \"$server get-request $self $type $pageid size $size [join $args]\"\n\
15113 $self evTrace C GET p $pageid s [$server id] z $size\n\
15114 $self instvar stat_ simStartTime_\n\
15115 if [info exists simStartTime_] {\n\
15116 incr stat_(req-num)\n\
15117 }\n\
15118 \n\
15119 $self mark-request $pageid\n\
15120 }\n\
15121 \n\
15122 Http/Client instproc mark-request { pageid } {\n\
15123 $self instvar node_ marks_ ns_\n\
15124 $node_ add-mark $pageid:[$ns_ now] \"purple\"\n\
15125 lappend marks_($pageid) $pageid:[$ns_ now]\n\
15126 }\n\
15127 \n\
15128 Http/Client instproc get-response-GET { server pageid args } {\n\
15129 $self instvar pending_ id_ ns_ stat_ simStartTime_\n\
15130 \n\
15131 if ![info exists pending_($pageid)] {\n\
15132 error \"Client $id_: Unrequested response page $pageid from server [$server id]\"\n\
15133 }\n\
15134 \n\
15135 array set data $args\n\
15136 \n\
15137 set origsvr [lindex [split $pageid :] 0]\n\
15138 set modtime [$origsvr get-modtime $pageid]\n\
15139 set reqtime [lindex $pending_($pageid) 0]\n\
15140 set reqrtt [expr [$ns_ now] - $reqtime]\n\
15141 \n\
15142 if {$modtime > $data(modtime)} {\n\
15143 set tmp [$origsvr stale-time $pageid $data(modtime)]\n\
15144 if {$tmp > $reqrtt/2} {\n\
15145 $self evTrace C STA p $pageid s [$origsvr id] l $tmp\n\
15146 if [info exists simStartTime_] {\n\
15147 incr stat_(stale-num)\n\
15148 set stat_(stale-time) [expr \\\n\
15149 $stat_(stale-time) + $tmp]\n\
15150 if {$stat_(st-min) > $tmp} {\n\
15151 set stat_(st-min) $tmp\n\
15152 }\n\
15153 if {$stat_(st-max) < $tmp} {\n\
15154 set stat_(st-max) $tmp\n\
15155 }\n\
15156 }\n\
15157 }\n\
15158 }\n\
15159 \n\
15160 $self evTrace C RCV p $pageid s [$server id] l $reqrtt z $data(size)\n\
15161 if [info exists simStartTime_] {\n\
15162 set stat_(rep-time) [expr $stat_(rep-time) + $reqrtt]\n\
15163 if {$stat_(rt-min) > $reqrtt} {\n\
15164 set stat_(rt-min) $reqrtt\n\
15165 }\n\
15166 if {$stat_(rt-max) < $reqrtt} {\n\
15167 set stat_(rt-max) $reqrtt\n\
15168 }\n\
15169 }\n\
15170 \n\
15171 set pending_($pageid) [lreplace $pending_($pageid) 0 0]\n\
15172 if {[llength $pending_($pageid)] == 0} {\n\
15173 unset pending_($pageid)\n\
15174 }\n\
15175 $self mark-response $pageid\n\
15176 }\n\
15177 \n\
15178 Http/Client instproc mark-response { pageid } {\n\
15179 $self instvar node_ marks_ ns_\n\
15180 set mk [lindex $marks_($pageid) 0]\n\
15181 $node_ delete-mark $mk\n\
15182 set marks_($pageid) [lreplace $marks_($pageid) 0 0]\n\
15183 }\n\
15184 \n\
15185 Http/Client instproc get-response-REF { server pageid args } {\n\
15186 eval $self get-response-GET $server $pageid $args\n\
15187 }\n\
15188 \n\
15189 Http/Client instproc get-response-IMS { server pageid args } {\n\
15190 eval $self get-response-GET $server $pageid $args\n\
15191 }\n\
15192 \n\
15193 Http/Client instproc set-page-generator { pagepool } {\n\
15194 $self instvar pgtr_     ;# Page generator\n\
15195 set pgtr_ $pagepool\n\
15196 }\n\
15197 \n\
15198 Http/Client instproc set-interval-generator { ranvar } {\n\
15199 $self instvar rvInterPage_\n\
15200 set rvInterPage_ $ranvar\n\
15201 }\n\
15202 \n\
15203 Http/Client instproc gen-request {} {\n\
15204 $self instvar pgtr_ rvInterPage_ id_\n\
15205 \n\
15206 if ![info exists pgtr_] {\n\
15207 error \"Http/Client requires a page generator (pgtr_)!\"\n\
15208 }\n\
15209 \n\
15210 if [info exists rvInterPage_] {\n\
15211 return [list [$rvInterPage_ value] [$pgtr_ gen-pageid $id_]]\n\
15212 } else {\n\
15213 return [$pgtr_ gen-request $id_]\n\
15214 }\n\
15215 }\n\
15216 \n\
15217 Http/Client instproc next-request { server pageid } {\n\
15218 $self instvar ns_ cache_ nextreq_\n\
15219 \n\
15220 if [info exists cache_] {\n\
15221 $self send-request $cache_ GET $pageid\n\
15222 } else {\n\
15223 $self send-request $server GET $pageid\n\
15224 }\n\
15225 \n\
15226 set req [$self gen-request]\n\
15227 set pageid $server:[lindex $req 1]\n\
15228 set itvl [lindex $req 0]\n\
15229 if {$itvl >= 0} {\n\
15230 set nextreq_([$server id]) [$ns_ at [expr [$ns_ now] + $itvl] \\\n\
15231 \"$self next-request $server $pageid\"]\n\
15232 } ;# otherwise it's the end of the request stream \n\
15233 }\n\
15234 \n\
15235 Http/Client instproc set-cache { cache } {\n\
15236 $self instvar cache_\n\
15237 set cache_ $cache\n\
15238 }\n\
15239 \n\
15240 Http/Client instproc start-session { cache server } {\n\
15241 $self instvar ns_ cache_ simStartTime_\n\
15242 \n\
15243 $self instvar simStartTime_ pgtr_\n\
15244 set simStartTime_ [$ns_ now]\n\
15245 if [info exists pgtr_] {\n\
15246 if {[$pgtr_ get-start-time] > $simStartTime_} {\n\
15247 $pgtr_ set-start-time $simStartTime_\n\
15248 }\n\
15249 }\n\
15250 \n\
15251 \n\
15252 set cache_ $cache\n\
15253 \n\
15254 set req [$self gen-request]\n\
15255 set pageid $server:[lindex $req 1]\n\
15256 set itvl [lindex $req 0]\n\
15257 if {$itvl >= 0} {\n\
15258 $ns_ at [expr [$ns_ now] + $itvl] \\\n\
15259 \"$self next-request $server $pageid\"\n\
15260 } ;# otherwise it's the end of the request stream \n\
15261 }\n\
15262 \n\
15263 Http/Client instproc stop-session { server } {\n\
15264 $self instvar ns_ nextreq_ pending_ cache_\n\
15265 set sid [$server id]\n\
15266 \n\
15267 if [info exists nextreq_($sid)] {\n\
15268 $ns_ cancel $nextreq_($sid)\n\
15269 }\n\
15270 if {![info exists pending_]} {\n\
15271 return\n\
15272 }\n\
15273 if {[info exists cache_] && ($server == $cache_)} {\n\
15274 unset pending_\n\
15275 } else {\n\
15276 foreach p [array names pending_] {\n\
15277 if {$server == [lindex [split $p :] 0]} {\n\
15278 unset pending_($p)\n\
15279 }\n\
15280 }\n\
15281 }\n\
15282 }\n\
15283 \n\
15284 Http/Client instproc populate { cache server } {\n\
15285 $self instvar pgtr_ curpage_ status_ ns_\n\
15286 \n\
15287 if ![info exists status_] {\n\
15288 set status_ \"POPULATE\"\n\
15289 set curpage_ 0\n\
15290 }\n\
15291 \n\
15292 if [info exists pgtr_] {\n\
15293 if {$curpage_ < [$pgtr_ get-poolsize]} {\n\
15294 $self send-request $cache GET $server:$curpage_\n\
15295 incr curpage_\n\
15296 $ns_ at [expr [$ns_ now] + 1] \\\n\
15297 \"$self populate $cache $server\"\n\
15298 return\n\
15299 }\n\
15300 }\n\
15301 \n\
15302 $ns_ at [expr [$ns_ now] + 10] \"$self start-session $cache $server\"\n\
15303 }\n\
15304 \n\
15305 Http/Client instproc start { cache server } {\n\
15306 $self instvar cache_\n\
15307 set cache_ $cache\n\
15308 $self populate $cache $server\n\
15309 }\n\
15310 \n\
15311 Http/Client instproc request-mpush { page } {\n\
15312 $self instvar mpush_refresh_ ns_ cache_\n\
15313 $self send $cache_ [$self get-mpusize] \\\n\
15314 \"$cache_ request-mpush $page\"\n\
15315 Http/Client instvar hb_interval_\n\
15316 set mpush_refresh_($page) [$ns_ at [expr [$ns_ now] + $hb_interval_] \\\n\
15317 \"$self send-refresh-mpush $page\"]\n\
15318 }\n\
15319 \n\
15320 Http/Client instproc send-refresh-mpush { page } {\n\
15321 $self instvar mpush_refresh_ ns_ cache_\n\
15322 $self send $cache_ [$self get-mpusize] \"$cache_ refresh-mpush $page\"\n\
15323 Http/Client instvar hb_interval_\n\
15324 set mpush_refresh_($page) [$ns_ at [expr [$ns_ now] + $hb_interval_] \\\n\
15325 \"$self send-refresh-mpush $page\"]\n\
15326 }\n\
15327 \n\
15328 Http/Client instproc stop-mpush { page } {\n\
15329 $self instvar mpush_refresh_ ns_ cache_\n\
15330 \n\
15331 if [info exists mpush_refresh_($page)] {\n\
15332 $ns_ cancel $mpush_refresh_($page)\n\
15333 } else {\n\
15334 error \"no mpush to cancel!\"\n\
15335 }\n\
15336 $self send $cache_ [$self get-mpusize] \"$cache_ stop-mpush $page\"\n\
15337 }\n\
15338 \n\
15339 \n\
15340 Class Http/Client/Compound -superclass Http/Client\n\
15341 \n\
15342 Http/Client/Compound instproc set-interobj-generator { ranvar } {\n\
15343 $self instvar rvInterObj_\n\
15344 set rvInterObj_ $ranvar\n\
15345 }\n\
15346 \n\
15347 Http/Client/Compound instproc next-request { server pageid } {\n\
15348 eval $self next $server $pageid\n\
15349 \n\
15350 }\n\
15351 \n\
15352 Http/Client/Compound instproc next-obj { server args } {\n\
15353 $self instvar pgtr_ cache_ req_objs_ ns_ rvInterObj_\n\
15354 \n\
15355 if ![llength $args] {\n\
15356 return\n\
15357 }\n\
15358 \n\
15359 if [info exists cache_] {\n\
15360 set dest $cache_\n\
15361 } else {\n\
15362 set dest $server\n\
15363 }\n\
15364 \n\
15365 set pageid [lindex $args 0]\n\
15366 set mpgid [$pgtr_ get-mainpage $pageid] ;# main page id\n\
15367 set max 0\n\
15368 set origsvr [lindex [split $pageid :] 0]\n\
15369 \n\
15370 foreach pageid $args {\n\
15371 set id [lindex [split $pageid :] 1]\n\
15372 if {$max < $id} {\n\
15373 set max $id\n\
15374 }\n\
15375 incr req_objs_($mpgid) -1\n\
15376 $self send-request $dest GET $pageid\n\
15377 }\n\
15378 if {$req_objs_($mpgid) <= 0} {\n\
15379 return\n\
15380 }\n\
15381 \n\
15382 set objid [join [$pgtr_ get-next-objs $origsvr:$max]]\n\
15383 puts \"At [$ns_ now], client [$self id] get objs $objid\"\n\
15384 if [info exists rvInterObj_] {\n\
15385 $ns_ at [expr [$ns_ now] + [$rvInterObj_ value]] \\\n\
15386 \"$self next-obj $server $objid\"\n\
15387 } else {\n\
15388 $self next-obj $server $objid\n\
15389 }\n\
15390 }\n\
15391 \n\
15392 Http/Client/Compound instproc get-response-GET { server pageid args } {\n\
15393 $self instvar pending_ id_ ns_ recv_objs_ max_stale_ stat_ \\\n\
15394 simStartTime_ pgtr_\n\
15395 \n\
15396 if ![info exists pending_($pageid)] {\n\
15397 error \"Client $id_: Unrequested response page $pageid from server/cache [$server id]\"\n\
15398 }\n\
15399 \n\
15400 if [$pgtr_ is-mainpage $pageid] {\n\
15401 set mpgid $pageid\n\
15402 $self instvar req_objs_ recv_objs_ rvInterObj_\n\
15403 set recv_objs_($pageid) [$pgtr_ get-obj-num $pageid] \n\
15404 set req_objs_($pageid) $recv_objs_($pageid) \n\
15405 set objid [join [$pgtr_ get-next-objs $pageid]]\n\
15406 if [info exists rvInterObj_] {\n\
15407 $ns_ at [expr [$ns_ now] + [$rvInterObj_ value]] \\\n\
15408 \"$self next-obj $server $objid\"\n\
15409 } else {\n\
15410 eval $self next-obj $server $objid\n\
15411 }\n\
15412 } else {\n\
15413 set mpgid [$pgtr_ get-mainpage $pageid]\n\
15414 }\n\
15415 \n\
15416 array set data $args\n\
15417 \n\
15418 set origsvr [lindex [split $pageid :] 0]\n\
15419 set modtime [$origsvr get-modtime $pageid]\n\
15420 set reqtime [lindex $pending_($pageid) 0]\n\
15421 set reqrtt [expr [$ns_ now] - $reqtime]\n\
15422 if {$modtime > $data(modtime)} {\n\
15423 $self instvar ns_\n\
15424 set tmp [$origsvr stale-time $pageid $data(modtime)]\n\
15425 if {$tmp > $reqrtt/2} {\n\
15426 if ![info exists max_stale_($mpgid)] {\n\
15427 set max_stale_($mpgid) $tmp\n\
15428 } elseif {$max_stale_($mpgid) < $tmp} {\n\
15429 set max_stale_($mpgid) $tmp\n\
15430 }\n\
15431 }\n\
15432 }\n\
15433 \n\
15434 if [$pgtr_ is-mainpage $pageid] {\n\
15435 return\n\
15436 }\n\
15437 \n\
15438 $self evTrace C RCV p $pageid s [$server id] l $reqrtt z $data(size)\n\
15439 unset pending_($pageid)\n\
15440 \n\
15441 incr recv_objs_($mpgid) -1\n\
15442 if {$recv_objs_($mpgid) > 0} {\n\
15443 return\n\
15444 }\n\
15445 \n\
15446 $self instvar pgtr_\n\
15447 set reqtime [lindex $pending_($mpgid) 0]\n\
15448 $self evTrace C RCV p $mpgid s [$origsvr id] l \\\n\
15449 [expr [$ns_ now] - $reqtime] z $data(size)\n\
15450 unset pending_($mpgid)\n\
15451 \n\
15452 if [info exists simStartTime_] {\n\
15453 set tmp [expr [$ns_ now] - $reqtime]\n\
15454 set stat_(rep-time) [expr $stat_(rep-time) + $tmp]\n\
15455 if {$stat_(rt-min) > $tmp} {\n\
15456 set stat_(rt-min) $tmp\n\
15457 }\n\
15458 if {$stat_(rt-max) < $tmp} {\n\
15459 set stat_(rt-max) $tmp\n\
15460 }\n\
15461 unset tmp\n\
15462 }\n\
15463 if [info exists max_stale_($mpgid)] {\n\
15464 $self evTrace C STA p $mpgid s [$origsvr id] \\\n\
15465 l $max_stale_($mpgid)\n\
15466 if [info exists simStartTime_] {\n\
15467 incr stat_(stale-num)\n\
15468 set stat_(stale-time) [expr \\\n\
15469 $stat_(stale-time) + $max_stale_($mpgid)]\n\
15470 if {$stat_(st-min) > $max_stale_($mpgid)} {\n\
15471 set stat_(st-min) $max_stale_($mpgid)\n\
15472 }\n\
15473 if {$stat_(st-max) < $max_stale_($mpgid)} {\n\
15474 set stat_(st-max) $max_stale_($mpgid)\n\
15475 }\n\
15476 }\n\
15477 unset max_stale_($mpgid)\n\
15478 }\n\
15479 $self mark-response $mpgid\n\
15480 }\n\
15481 \n\
15482 Http/Client/Compound instproc mark-request { pageid } {\n\
15483 set id [lindex [split $pageid :] end]\n\
15484 if {$id == 0} {\n\
15485 $self next $pageid\n\
15486 }\n\
15487 }\n\
15488 \n\
15489 \n\
15490 \n\
15491 \n\
15492 Http/Client/Media instproc create-pagepool {} {\n\
15493 set pool [new PagePool/Client/Media]\n\
15494 $self set-pagepool $pool\n\
15495 return $pool\n\
15496 }\n\
15497 \n\
15498 Http/Client/Media instproc get-response-GET { server pageid args } {\n\
15499 eval $self next $server $pageid $args\n\
15500 \n\
15501 if [$self exist-page $pageid] {\n\
15502 error \"Http/Client/Media: receives an \\\"active\\\" page!\"\n\
15503 }\n\
15504 eval $self enter-page $pageid $args\n\
15505 \n\
15506 array set data $args\n\
15507 if {[info exists data(pgtype)] && ($data(pgtype) == \"MEDIA\")} {\n\
15508 $self media-connect $server $pageid\n\
15509 }\n\
15510 }\n\
15511 \n\
15512 Http/Client/Media instproc send-request { server type pageid args } {\n\
15513 $self instvar mmapp_ \n\
15514 if [info exists mmapp_($pageid)] {\n\
15515 return\n\
15516 }\n\
15517 eval $self next $server $type $pageid $args\n\
15518 }\n\
15519 \n\
15520 Http/Client/Media instproc media-connect { server pageid } {\n\
15521 \n\
15522 \n\
15523 $self instvar mmapp_ ns_ node_ \n\
15524 Http instvar MEDIA_TRANSPORT_ MEDIA_APP_\n\
15525 if [info exists mmapp_($pageid)] {\n\
15526 puts \"Media client [$self id] got a request for an existing stream\"\n\
15527 return\n\
15528 }\n\
15529 set agent [new Agent/$MEDIA_TRANSPORT_]\n\
15530 $ns_ attach-agent $node_ $agent\n\
15531 set app [new Application/$MEDIA_APP_ $pageid]\n\
15532 $app attach-agent $agent\n\
15533 $app target $self\n\
15534 $server alloc-mcon $self $pageid $agent\n\
15535 set mmapp_($pageid) $app\n\
15536 $app set-layer [$self get-layer $pageid]\n\
15537 }\n\
15538 \n\
15539 Http/Client/Media instproc media-disconnect { server pageid } {\n\
15540 $self instvar mmapp_ ns_ node_\n\
15541 \n\
15542 if {![info exists mmapp_($pageid)]} {\n\
15543 error \"Media client [$self id] disconnect: not connected to \\\n\
15544 server [$server id] with page $pageid\"\n\
15545 }\n\
15546 set app $mmapp_($pageid)\n\
15547 set agent [$app agent]\n\
15548 $ns_ detach-agent $node_ $agent\n\
15549 \n\
15550 \n\
15551 $server media-disconnect $self $pageid\n\
15552 \n\
15553 delete $agent\n\
15554 delete $app\n\
15555 unset mmapp_($pageid)\n\
15556 \n\
15557 $self stream-received $pageid\n\
15558 }\n\
15559 \n\
15560 \n\
15561 \n\
15562 Http/Server/Media instproc gen-page { pageid } {\n\
15563 $self instvar pgtr_ \n\
15564 set pginfo [$self next $pageid]\n\
15565 if [$pgtr_ is-media-page $pageid] {\n\
15566 return [lappend pginfo pgtype MEDIA]\n\
15567 } else {\n\
15568 return $pginfo\n\
15569 }\n\
15570 }\n\
15571 \n\
15572 Http/Server/Media instproc create-pagepool {} {\n\
15573 set pool [new PagePool/Client/Media]\n\
15574 $self set-pagepool $pool\n\
15575 $pool set max_size_ 2147483647\n\
15576 return $pool\n\
15577 }\n\
15578 \n\
15579 Http/Server/Media instproc medialog-on {} {\n\
15580 $self instvar MediaLog_\n\
15581 set MediaLog_ 1\n\
15582 }\n\
15583 \n\
15584 Http/Server/Media instproc alloc-mcon { client pageid dst_agent } {\n\
15585 $self instvar ns_ node_ mmapp_ \n\
15586 Http instvar MEDIA_TRANSPORT_ MEDIA_APP_\n\
15587 \n\
15588 set agent [new Agent/$MEDIA_TRANSPORT_]\n\
15589 $ns_ attach-agent $node_ $agent\n\
15590 set app [new Application/$MEDIA_APP_ $pageid]\n\
15591 $app attach-agent $agent\n\
15592 $app target $self \n\
15593 set mmapp_($client/$pageid) $app\n\
15594 $app set-layer [$self get-layer $pageid]\n\
15595 \n\
15596 $self register-client $app $client $pageid\n\
15597 \n\
15598 $self instvar MediaLog_\n\
15599 if [info exists MediaLog_] {\n\
15600 set lf [$self log]\n\
15601 if {$lf != \"\"} {\n\
15602 $app log $lf\n\
15603 }\n\
15604 }\n\
15605 \n\
15606 $ns_ connect $agent $dst_agent\n\
15607 $agent start\n\
15608 }\n\
15609 \n\
15610 Http/Server/Media instproc media-disconnect { client pageid } { \n\
15611 $self instvar mmapp_ ns_ node_\n\
15612 \n\
15613 \n\
15614 if {![info exists mmapp_($client/$pageid)]} {\n\
15615 error \"Media server [$self id] disconnect: not connected to \\\n\
15616 client [$client id] with page $pageid\"\n\
15617 }\n\
15618 set app $mmapp_($client/$pageid)\n\
15619 set agent [$app agent]\n\
15620 $ns_ detach-agent $node_ $agent\n\
15621 \n\
15622 $self unregister-client $app $client $pageid\n\
15623 \n\
15624 \n\
15625 delete $agent\n\
15626 delete $app\n\
15627 unset mmapp_($client/$pageid)\n\
15628 }\n\
15629 \n\
15630 Http/Server/Media instproc finish-stream { app } {\n\
15631 $self instvar mmapp_ \n\
15632 foreach n [array names mmapp_] {\n\
15633 if {$mmapp_($n) == $app} {\n\
15634 set tmp [split $n /]\n\
15635 set client [lindex $tmp 0]\n\
15636 set pageid [lindex $tmp 1]\n\
15637 $self send $client [$self get-reqsize] \\\n\
15638 \"$client media-disconnect $self $pageid\"\n\
15639 return\n\
15640 }\n\
15641 }\n\
15642 }\n\
15643 \n\
15644 Http/Server/Media instproc handle-request-GET { pageid args } {\n\
15645 set pginfo [eval $self next $pageid $args]\n\
15646 if {[$self get-pagetype $pageid] == \"MEDIA\"} {\n\
15647 set pginfo [lreplace $pginfo 0 0 [$self get-reqsize]]\n\
15648 }\n\
15649 return $pginfo\n\
15650 }\n\
15651 \n\
15652 Http/Server/Media instproc gen-pageinfo { pageid } {\n\
15653 set pginfo [eval $self next $pageid]\n\
15654 $self instvar pgtr_\n\
15655 if [$pgtr_ is-media-page $pageid] {\n\
15656 return [lappend pginfo pgtype MEDIA layer \\\n\
15657 [$pgtr_ get-layer $pageid]]\n\
15658 } else {\n\
15659 return $pginfo\n\
15660 }\n\
15661 }\n\
15662 \n\
15663 \n\
15664 Http/Server/Media instproc get-request { client type pageid args } {\n\
15665 if {$type == \"PREFSEG\"} {\n\
15666 set pagenum [lindex [split $pageid :] 1]\n\
15667 set conid [lindex $args 0]\n\
15668 set layer [lindex $args 1]\n\
15669 set seglist [lrange $args 2 end]\n\
15670 eval $self register-prefetch $client $pagenum $conid \\\n\
15671 $layer $seglist\n\
15672 $client start-prefetch $self $pageid $conid\n\
15673 $self evTrace S PREF p $pageid l $layer [join $seglist]\n\
15674 } elseif {$type == \"STOPPREF\"} {\n\
15675 set pagenum [lindex [split $pageid :] 1]\n\
15676 set conid [lindex $args 0]\n\
15677 if [$self stop-prefetching $client $conid $pagenum] {\n\
15678 $client media-disconnect $self $pageid $conid\n\
15679 }\n\
15680 } elseif {$type == \"OFFLPREF\"} {\n\
15681 if ![$self exist-page $pageid] {\n\
15682 error \"Server [$self id] offline-prefetch non-existent page $pageid!\"\n\
15683 }\n\
15684 set size [$self get-size $pageid]\n\
15685 $self send $client $size \"$client offline-complete $pageid\"\n\
15686 } else {\n\
15687 eval $self next $client $type $pageid $args\n\
15688 }\n\
15689 }\n\
15690 \n\
15691 \n\
15692 \n\
15693 \n\
15694 Http/Cache/Media instproc create-pagepool {} {\n\
15695 set pool [new PagePool/Client/Media]\n\
15696 $self set-pagepool $pool\n\
15697 return $pool\n\
15698 }\n\
15699 \n\
15700 Http/Cache/Media instproc start-prefetch { server pageid conid } {\n\
15701 $self instvar pref_ ns_\n\
15702 if [info exists pref_($server/$pageid)] {\n\
15703 if {[lsearch -exact $pref_($server/$pageid) $conid] == -1} {\n\
15704 lappend pref_($server/$pageid) $conid\n\
15705 }\n\
15706 return\n\
15707 } else {\n\
15708 lappend pref_($server/$pageid) $conid\n\
15709 }\n\
15710 Http instvar MEDIA_APP_\n\
15711 set oldapp $MEDIA_APP_\n\
15712 set oldipg [Agent/RAP set ipg_]\n\
15713 set oldsrtt [Agent/RAP set srtt_]\n\
15714 Agent/RAP set ipg_ 0.01\n\
15715 Agent/RAP set srtt_ 0.01\n\
15716 set MEDIA_APP_ MediaApp\n\
15717 $self media-connect $server $pageid\n\
15718 set MEDIA_APP_ $oldapp\n\
15719 Agent/RAP set ipg_ $oldipg\n\
15720 Agent/RAP set srtt_ $oldsrtt\n\
15721 }\n\
15722 \n\
15723 Http/Cache/Media instproc media-connect { server pageid } {\n\
15724 $self instvar s_mmapp_ ns_ node_ \n\
15725 \n\
15726 \n\
15727 Http instvar MEDIA_TRANSPORT_ MEDIA_APP_\n\
15728 if [info exists s_mmapp_($server/$pageid)] {\n\
15729 error \"Media client [$self id] got a request for an existing \\\n\
15730 stream\"\n\
15731 }\n\
15732 set agent [new Agent/$MEDIA_TRANSPORT_]\n\
15733 $ns_ attach-agent $node_ $agent\n\
15734 set app [new Application/$MEDIA_APP_ $pageid]\n\
15735 $app attach-agent $agent\n\
15736 $app target $self\n\
15737 $server alloc-mcon $self $pageid $agent\n\
15738 set s_mmapp_($server/$pageid) $app\n\
15739 $app set-layer [$self get-layer $pageid]\n\
15740 }\n\
15741 \n\
15742 Http/Cache/Media instproc alloc-mcon { client pageid dst_agent } {\n\
15743 $self instvar ns_ node_ c_mmapp_ \n\
15744 Http instvar MEDIA_TRANSPORT_ MEDIA_APP_\n\
15745 if [info exists c_mmapp_($client/$pageid)] {\n\
15746 error \"Media cache [$self id] got a request for an existing \\\n\
15747 stream $pageid from client [$client id]\"\n\
15748 }\n\
15749 \n\
15750 set agent [new Agent/$MEDIA_TRANSPORT_]\n\
15751 $ns_ attach-agent $node_ $agent\n\
15752 set app [new Application/$MEDIA_APP_ $pageid]\n\
15753 $app attach-agent $agent\n\
15754 $app target $self \n\
15755 set c_mmapp_($client/$pageid) $app\n\
15756 $app set-layer [$self get-layer $pageid]\n\
15757 \n\
15758 $self register-client $app $client $pageid\n\
15759 \n\
15760 $self instvar MediaLog_\n\
15761 if [info exists MediaLog_] {\n\
15762 set lf [$self log]\n\
15763 if {$lf != \"\"} {\n\
15764 $app log $lf\n\
15765 }\n\
15766 }\n\
15767 \n\
15768 $ns_ connect $agent $dst_agent\n\
15769 $agent start\n\
15770 }\n\
15771 \n\
15772 Http/Cache/Media instproc medialog-on {} {\n\
15773 $self instvar MediaLog_\n\
15774 set MediaLog_ 1\n\
15775 }\n\
15776 \n\
15777 Http/Cache/Media instproc media-disconnect { host pageid args } {\n\
15778 $self instvar c_mmapp_ s_mmapp_ ns_ node_ pref_ c_tbt_\n\
15779 \n\
15780 set cntdisco 0 \n\
15781 set svrdisco 0\n\
15782 \n\
15783 set server [lindex [split $pageid :] 0]\n\
15784 \n\
15785 if {($host != $server) && [info exists c_mmapp_($host/$pageid)]} {\n\
15786 set app $c_mmapp_($host/$pageid)\n\
15787 set agent [$app agent]\n\
15788 $ns_ detach-agent $node_ $agent\n\
15789 $self unregister-client $app $host $pageid\n\
15790 \n\
15791 if {[info exists pref_($server/$pageid)] && \\\n\
15792 [lsearch -exact $pref_($server/$pageid) $app] != -1} {\n\
15793 $self send $server [$self get-reqsize] \"$server get-request $self STOPPREF $pageid $app\"\n\
15794 set c_tbt_($host/$pageid) $app\n\
15795 $app stop\n\
15796 } else {\n\
15797 delete $app\n\
15798 }\n\
15799 delete $agent\n\
15800 unset c_mmapp_($host/$pageid)\n\
15801 \n\
15802 $self instvar pool_\n\
15803 foreach p [lsort [$pool_ list-pages]] {\n\
15804 $self dump-page $p\n\
15805 }\n\
15806 set cntdisco 1\n\
15807 \n\
15808 } elseif [info exists s_mmapp_($host/$pageid)] {\n\
15809 set svrdisco 1\n\
15810 if [info exists pref_($server/$pageid)] {\n\
15811 set teardown 0\n\
15812 set conid [lindex $args 0]\n\
15813 set pos [lsearch -exact $pref_($server/$pageid) $conid]\n\
15814 if {$pos == -1} {\n\
15815 error \"media-disconnect cannot find $conid!!\"\n\
15816 }\n\
15817 set pref_($server/$pageid) [lreplace \\\n\
15818 $pref_($server/$pageid) $pos $pos]\n\
15819 if {[llength $pref_($server/$pageid)] == 0} {\n\
15820 $self evTrace E STP s [$server id] p $pageid\n\
15821 unset pref_($server/$pageid)\n\
15822 set teardown 1\n\
15823 }\n\
15824 delete $conid\n\
15825 } else {\n\
15826 set teardown 1\n\
15827 }\n\
15828 if {$teardown} {\n\
15829 set app $s_mmapp_($host/$pageid)\n\
15830 set agent [$app agent]\n\
15831 $ns_ detach-agent $node_ $agent\n\
15832 $host media-disconnect $self $pageid\n\
15833 delete $agent\n\
15834 delete $app\n\
15835 unset s_mmapp_($host/$pageid)\n\
15836 }\n\
15837 $self instvar firstreq_\n\
15838 if {([$self get-pref-style] == \"OFFLINE_PREF\") && \\\n\
15839 [info exists firstreq_($pageid)]} { \n\
15840 $self send $server [$self get-reqsize] \\\n\
15841 \"$server get-request $self OFFLPREF $pageid\"\n\
15842 }\n\
15843 if [info exists firstreq_($pageid)] {\n\
15844 unset firstreq_($pageid)\n\
15845 }\n\
15846 } else {\n\
15847 error \"At [$ns_ now] Media cache [$self id] tries to \\\n\
15848 disconnect from a non-connected host [$host id]\"\n\
15849 }\n\
15850 \n\
15851 if {$svrdisco == 1} {\n\
15852 $self stream-received $pageid\n\
15853 }\n\
15854 }\n\
15855 \n\
15856 Http/Cache/Media instproc finish-stream { app } {\n\
15857 $self instvar c_mmapp_ s_mmapp_\n\
15858 foreach n [array names c_mmapp_] {\n\
15859 if {$c_mmapp_($n) == $app} {\n\
15860 set tmp [split $n /]\n\
15861 set client [lindex $tmp 0]\n\
15862 set pageid [lindex $tmp 1]\n\
15863 $self send $client [$self get-reqsize] \\\n\
15864 \"$client media-disconnect $self $pageid\"\n\
15865 return\n\
15866 }\n\
15867 }\n\
15868 }\n\
15869 \n\
15870 Http/Cache/Media instproc get-response-GET { server pageid args } {\n\
15871 $self instvar firstreq_\n\
15872 if ![$self exist-page $pageid] {\n\
15873 set firstreq_($pageid) 1\n\
15874 }\n\
15875 \n\
15876 eval $self next $server $pageid $args\n\
15877 \n\
15878 \n\
15879 array set data $args\n\
15880 if {[info exists data(pgtype)] && ($data(pgtype) == \"MEDIA\")} {\n\
15881 $self media-connect $server $pageid\n\
15882 }\n\
15883 }\n\
15884 \n\
15885 Http/Cache/Media instproc answer-request-GET { cl pageid args } {\n\
15886 array set data $args\n\
15887 if {[info exists data(pgtype)] && ($data(pgtype) == \"MEDIA\")} {\n\
15888 set size [$self get-reqsize]\n\
15889 } else {\n\
15890 set size $data(size)\n\
15891 }\n\
15892 $self send $cl $size \\\n\
15893 \"$cl get-response-GET $self $pageid $args\"\n\
15894 $self evTrace E SND c [$cl id] p $pageid z $data(size)\n\
15895 }\n\
15896 \n\
15897 Http/Cache/Media instproc pref-segment {conid pageid layer args} {\n\
15898 set server [lindex [split $pageid :] 0]\n\
15899 set size [$self get-reqsize]\n\
15900 $self send $server $size \"$server get-request $self PREFSEG \\\n\
15901 $pageid $conid $layer [join $args]\"\n\
15902 }\n\
15903 \n\
15904 Http/Cache/Media instproc set-repl-style { style } {\n\
15905 $self instvar pool_\n\
15906 $pool_ set-repl-style $style\n\
15907 }\n\
15908 \n\
15909 \n\
15910 PagePool/WebTraf set debug_ false\n\
15911 PagePool/WebTraf set TCPTYPE_ Reno\n\
15912 PagePool/WebTraf set TCPSINKTYPE_ TCPSink   ;#required for SACK1 Sinks.\n\
15913 \n\
15914 PagePool/WebTraf set FID_ASSIGNING_MODE_ 0 \n\
15915 PagePool/WebTraf set VERBOSE_ 0\n\
15916 \n\
15917 PagePool/WebTraf set recycle_page_ 1\n\
15918 \n\
15919 PagePool/WebTraf set dont_recycle_ 0\n\
15920 \n\
15921 PagePool/WebTraf set fulltcp_ 0\n\
15922 \n\
15923 PagePool/WebTraf set req_trace_ 0\n\
15924 PagePool/WebTraf set resp_trace_ 0\n\
15925 \n\
15926 PagePool/WebTraf set enable_conn_timer_ 0\n\
15927 PagePool/WebTraf set avg_waiting_time_ 30\n\
15928 \n\
15929 PagePool/WebTraf set FLOW_SIZE_TH_ 15\n\
15930 PagePool/WebTraf set FLOW_SIZE_OPS_ 0\n\
15931 \n\
15932 PagePool/WebTraf instproc launch-req { id pid clnt svr ctcp csnk size pobj} {\n\
15933 $self instvar timer_\n\
15934 \n\
15935 set launch_req 1\n\
15936 set flow_th [PagePool/WebTraf set FLOW_SIZE_TH_]\n\
15937 \n\
15938 if {[PagePool/WebTraf set FLOW_SIZE_OPS_] == 1 && $size > $flow_th} {\n\
15939 set launch_req 0\n\
15940 }\n\
15941 \n\
15942 if {$launch_req == 1} {\n\
15943 set ns [Simulator instance]\n\
15944 \n\
15945 $ns attach-agent $clnt $ctcp\n\
15946 $ns attach-agent $svr $csnk\n\
15947 $ns connect $ctcp $csnk\n\
15948 \n\
15949 if {[PagePool/WebTraf set fulltcp_] == 1} {\n\
15950 $csnk listen\n\
15951 }\n\
15952 \n\
15953 if {[PagePool/WebTraf set FID_ASSIGNING_MODE_] == 0} {\n\
15954 $ctcp set fid_ $id\n\
15955 \n\
15956 if {[PagePool/WebTraf set fulltcp_] == 1} {\n\
15957 $csnk set fid_ $id\n\
15958 }\n\
15959 }\n\
15960 \n\
15961 set timer_ [$self get-conn-timer $ctcp $csnk $clnt $svr]\n\
15962 \n\
15963 \n\
15964 $ctcp proc done {} \"$self done-req $id $pid $clnt $svr $ctcp $csnk $size $pobj $timer_\"\n\
15965 \n\
15966 if {[PagePool/WebTraf set req_trace_]} {    \n\
15967 puts \"req + $id $pid $size [$clnt id] [$svr id] [$ns now]\"\n\
15968 }   \n\
15969 \n\
15970 $self send-message $ctcp 1\n\
15971 }\n\
15972 \n\
15973 }\n\
15974 \n\
15975 PagePool/WebTraf instproc done-req { id pid clnt svr ctcp csnk size pobj timer} {\n\
15976 if {[PagePool/WebTraf set enable_conn_timer_]} {\n\
15977 $timer cancel\n\
15978 delete $timer\n\
15979 }\n\
15980 \n\
15981 set ns [Simulator instance]\n\
15982 \n\
15983 $ns detach-agent $clnt $ctcp\n\
15984 $ns detach-agent $svr $csnk\n\
15985 $ctcp reset\n\
15986 $csnk reset\n\
15987 \n\
15988 set delay [$self job_arrival $id $clnt $svr $ctcp $csnk $size $pobj]\n\
15989 \n\
15990 if {$delay == 0} {\n\
15991 if {[PagePool/WebTraf set req_trace_]} {    \n\
15992 puts \"req d $id $pid $size [$clnt id] [$svr id] [$ns now]\"\n\
15993 }\n\
15994 $self recycle $ctcp $csnk   \n\
15995 $self doneObj $pobj\n\
15996 } else {\n\
15997 if {[PagePool/WebTraf set req_trace_]} {    \n\
15998 puts \"req - $id $pid $size [$clnt id] [$svr id] [$ns now]\"\n\
15999 }\n\
16000 }\n\
16001 \n\
16002 }\n\
16003 \n\
16004 PagePool/WebTraf instproc launch-resp { id pid svr clnt stcp ssnk size pobj} {\n\
16005 set flow_th [PagePool/WebTraf set FLOW_SIZE_TH_]\n\
16006 \n\
16007 set ns [Simulator instance]\n\
16008 \n\
16009 $ns attach-agent $svr $stcp\n\
16010 $ns attach-agent $clnt $ssnk\n\
16011 $ns connect $stcp $ssnk\n\
16012 \n\
16013 if {[PagePool/WebTraf set fulltcp_] == 1} {\n\
16014 $ssnk listen\n\
16015 }\n\
16016 \n\
16017 if {[PagePool/WebTraf set FID_ASSIGNING_MODE_] == 0} {\n\
16018 $stcp set fid_ $id\n\
16019 \n\
16020 if {[PagePool/WebTraf set fulltcp_] == 1} {\n\
16021 $ssnk set fid_ $id\n\
16022 }\n\
16023 }\n\
16024 \n\
16025 if {[PagePool/WebTraf set FLOW_SIZE_OPS_] == 2 && $size > $flow_th} {\n\
16026 set sent $flow_th\n\
16027 } else {\n\
16028 set sent $size\n\
16029 }\n\
16030 \n\
16031 $stcp proc done {} \"$self done-resp $id $pid $clnt $svr $stcp $ssnk $size $sent $flow_th [$ns now] [$stcp set fid_] $pobj\"\n\
16032 \n\
16033 if {[PagePool/WebTraf set resp_trace_]} {\n\
16034 puts \"resp + $id $pid $sent $size [$svr id] [$clnt id] [$ns now]\"\n\
16035 }\n\
16036 $self send-message $stcp $sent\n\
16037 }\n\
16038 \n\
16039 PagePool/WebTraf instproc done-resp { id pid clnt svr stcp ssnk size sent sent_th {startTime 0} {fid 0} pobj } {\n\
16040 set ns [Simulator instance]\n\
16041 \n\
16042 if {[PagePool/WebTraf set resp_trace_]} {\n\
16043 puts \"resp - $id $pid $sent $size [$svr id] [$clnt id] [$ns now]\"\n\
16044 }\n\
16045 \n\
16046 if {[PagePool/WebTraf set VERBOSE_] == 1} {\n\
16047 puts \"done-resp - $id [$svr id] [$clnt id] $size $startTime [$ns now] $fid\"\n\
16048 }\n\
16049 \n\
16050 $stcp reset\n\
16051 $ssnk reset\n\
16052 $ns detach-agent $clnt $ssnk\n\
16053 $ns detach-agent $svr $stcp\n\
16054 \n\
16055 if {$sent < $size} {\n\
16056 $ns attach-agent $svr $stcp\n\
16057 $ns attach-agent $clnt $ssnk\n\
16058 $ns connect $stcp $ssnk\n\
16059 \n\
16060 if {[PagePool/WebTraf set fulltcp_] == 1} {\n\
16061 $ssnk listen\n\
16062 }\n\
16063 \n\
16064 if {[PagePool/WebTraf set FID_ASSIGNING_MODE_] == 0} {\n\
16065 $stcp set fid_ $id\n\
16066 \n\
16067 if {[PagePool/WebTraf set fulltcp_] == 1} {\n\
16068 $ssnk set fid_ $id\n\
16069 }\n\
16070 }\n\
16071 \n\
16072 set left [expr $size - $sent]\n\
16073 if {$left <= $sent_th} {\n\
16074 if {[PagePool/WebTraf set resp_trace_]} {\n\
16075 puts \"resp + $id $pid $left $size [$svr id] [$clnt id] [$ns now]\"\n\
16076 }\n\
16077 set sent [expr $sent + $left]\n\
16078 $stcp proc done {} \"$self done-resp $id $pid $clnt $svr $stcp $ssnk $size $sent $sent_th [$ns now] [$stcp set fid_]\"\n\
16079 \n\
16080 $self send-message $stcp $left\n\
16081 } else {\n\
16082 if {[PagePool/WebTraf set resp_trace_]} {\n\
16083 puts \"resp + $id $pid $sent_th $size [$svr id] [$clnt id] [$ns now]\"\n\
16084 }\n\
16085 set sent [expr $sent + $sent_th]\n\
16086 $stcp proc done {} \"$self done-resp $id $pid $clnt $svr $stcp $ssnk $size $sent $sent_th [$ns now] [$stcp set fid_]\"\n\
16087 \n\
16088 $self send-message $stcp $sent_th\n\
16089 }\n\
16090 } else {\n\
16091 $self recycle $stcp $ssnk   \n\
16092 $self doneObj $pobj\n\
16093 }\n\
16094 }\n\
16095 \n\
16096 PagePool/WebTraf instproc alloc-tcp {} {\n\
16097 set tcp [new Agent/TCP/[PagePool/WebTraf set TCPTYPE_]]\n\
16098 \n\
16099 set fidMode [PagePool/WebTraf set FID_ASSIGNING_MODE_]\n\
16100 if {$fidMode == 1} {\n\
16101 $self instvar maxFid_\n\
16102 $tcp set fid_ $maxFid_\n\
16103 incr maxFid_\n\
16104 } elseif  {$fidMode == 2} {\n\
16105 $self instvar sameFid_\n\
16106 $tcp set fid_ $sameFid_\n\
16107 }\n\
16108 \n\
16109 return $tcp\n\
16110 }\n\
16111 \n\
16112 PagePool/WebTraf instproc alloc-tcp-sink {} {\n\
16113 return [new Agent/[PagePool/WebTraf set TCPSINKTYPE_]]\n\
16114 }\n\
16115 \n\
16116 PagePool/WebTraf instproc send-message {tcp num_packet} {\n\
16117 if {[PagePool/WebTraf set fulltcp_] == 1} {\n\
16118 $tcp sendmsg [expr $num_packet * 1000] \"MSG_EOF\"\n\
16119 } else {\n\
16120 $tcp advanceby $num_packet\n\
16121 }\n\
16122 }\n\
16123 \n\
16124 \n\
16125 \n\
16126 PagePool/WebTraf instproc  add2asim { srcid dstid lambda mu } {\n\
16127 \n\
16128 set sf_ [[Simulator instance] set sflows_]\n\
16129 set nsf_ [[Simulator instance] set nsflows_]\n\
16130 \n\
16131 lappend sf_ $srcid:$dstid:$lambda:$mu\n\
16132 incr nsf_\n\
16133 \n\
16134 [Simulator instance] set sflows_ $sf_\n\
16135 [Simulator instance] set nsflows_ $nsf_\n\
16136 \n\
16137 \n\
16138 }\n\
16139 \n\
16140 PagePool/WebTraf instproc get-conn-timer { tcp snk clnt svr } {\n\
16141 if {[PagePool/WebTraf set enable_conn_timer_]} {\n\
16142 set timer_ [new ConnTimer $self [PagePool/WebTraf set avg_waiting_time_]]\n\
16143 $timer_ sched $tcp $snk $clnt $svr\n\
16144 } else {\n\
16145 set timer_ 0\n\
16146 }\n\
16147 \n\
16148 return $timer_\n\
16149 }\n\
16150 \n\
16151 Class ConnTimer -superclass Timer\n\
16152 \n\
16153 ConnTimer instproc init {webtraf delay} {\n\
16154 $self instvar webtraf_ avg_delay_\n\
16155 \n\
16156 $self set webtraf_ $webtraf\n\
16157 $self set avg_delay_ $delay\n\
16158 \n\
16159 $self next [Simulator instance]\n\
16160 }\n\
16161 \n\
16162 ConnTimer instproc sched {tcp snk n1 n2} {\n\
16163 $self instvar tcp_ snk_ n1_ n2_ avg_delay_\n\
16164 \n\
16165 $self set tcp_ $tcp\n\
16166 $self set snk_ $snk\n\
16167 $self set n1_ $n1\n\
16168 $self set n2_ $n2\n\
16169 \n\
16170 set waiting_time [new RandomVariable/Exponential]\n\
16171 $waiting_time set avg_ $avg_delay_\n\
16172 set delay [$waiting_time value]\n\
16173 puts \"delay: $delay\"\n\
16174 delete $waiting_time\n\
16175 \n\
16176 $self next $delay\n\
16177 }\n\
16178 \n\
16179 ConnTimer instproc timeout {} {\n\
16180 $self instvar webtraf_\n\
16181 $self instvar n1_ n2_ tcp_ snk_\n\
16182 \n\
16183 \n\
16184 set v [new RandomVariable/Uniform]\n\
16185 set p [$v value]\n\
16186 delete $v\n\
16187 \n\
16188 if {$p > 0.5} {\n\
16189 $self sched $tcp_ $snk_ $n1_ $n2_\n\
16190 } else {\n\
16191 set ns [Simulator instance] \n\
16192 \n\
16193 $ns detach-agent $n1_ $tcp_\n\
16194 $ns detach-agent $n2_ $snk_\n\
16195 $tcp_ reset\n\
16196 $snk_ reset\n\
16197 $webtraf_ recycle $tcp_ $snk_\n\
16198 \n\
16199 delete $self\n\
16200 }\n\
16201 }\n\
16202 \n\
16203 \n\
16204 PagePool/EmpWebTraf set debug_ false\n\
16205 PagePool/EmpWebTraf set TCPSINKTYPE_ TCPSink   ;#required for SACK1 Sinks.\n\
16206 PagePool/EmpWebTraf set REQ_TRACE_ 1\n\
16207 PagePool/EmpWebTraf set RESP_TRACE_ 1\n\
16208 \n\
16209 \n\
16210 PagePool/EmpWebTraf set TCPTYPE_ FullTcp\n\
16211 PagePool/EmpWebTraf set fulltcp_ 1\n\
16212 \n\
16213 \n\
16214 PagePool/EmpWebTraf set VERBOSE_ 0\n\
16215 \n\
16216 \n\
16217 \n\
16218 PagePool/EmpWebTraf instproc launch-req { id pid clnt svr ctcp csnk stcp ssnk size reqSize pobj persist} {\n\
16219 set ns [Simulator instance]\n\
16220 \n\
16221 $ns attach-agent $svr $stcp\n\
16222 $ns attach-agent $clnt $ssnk\n\
16223 $ns connect $stcp $ssnk\n\
16224 \n\
16225 $ns attach-agent $clnt $ctcp\n\
16226 $ns attach-agent $svr $csnk\n\
16227 $ns connect $ctcp $csnk\n\
16228 \n\
16229 \n\
16230 $ctcp proc done {} \"$self done-req $id $pid $clnt $svr $ctcp $csnk $stcp $size $pobj $persist\"\n\
16231 $stcp proc done {} \"$self done-resp $id $pid $clnt $svr $stcp $ssnk $size [$ns now] [$stcp set fid_] $pobj $persist\"\n\
16232 \n\
16233 if {[PagePool/EmpWebTraf set REQ_TRACE_]} {\n\
16234 puts \"req + obj:$id clnt:[$clnt id] svr:[$svr id] $size [$ns now]\"\n\
16235 }\n\
16236 \n\
16237 $ctcp advanceby $reqSize\n\
16238 }\n\
16239 \n\
16240 PagePool/EmpWebTraf instproc done-req { id pid clnt svr ctcp csnk stcp size pobj persist} {\n\
16241 set ns [Simulator instance]\n\
16242 \n\
16243 if {[PagePool/EmpWebTraf set REQ_TRACE_]} {\n\
16244 puts \"req - obj:$id clnt:[$clnt id] srv:[$svr id] [$ns now]\"\n\
16245 }   \n\
16246 $ns detach-agent $clnt $ctcp\n\
16247 $ns detach-agent $svr $csnk\n\
16248 \n\
16249 if {$persist != 1} {\n\
16250 $ctcp reset\n\
16251 $csnk reset\n\
16252 $self recycle $ctcp $csnk\n\
16253 }\n\
16254 \n\
16255 if {[PagePool/EmpWebTraf set RESP_TRACE_]} {\n\
16256 puts \"resp + obj:$id srv:[$svr id] clnt:[$clnt id] $size [$ns now]\"\n\
16257 }\n\
16258 \n\
16259 $stcp advanceby $size\n\
16260 }\n\
16261 \n\
16262 PagePool/EmpWebTraf instproc done-resp { id pid clnt svr stcp ssnk size {startTime 0} {fid 0} pobj persist} {\n\
16263 set ns [Simulator instance]\n\
16264 \n\
16265 if {[PagePool/EmpWebTraf set RESP_TRACE_]} {\n\
16266 puts \"resp - $id $pid $size [$svr id] [$clnt id] [$ns now]\"\n\
16267 }\n\
16268 \n\
16269 if {[PagePool/EmpWebTraf set VERBOSE_] == 1} {\n\
16270 puts \"done-resp - obj:$id srv:[$svr id] clnt:[$clnt id] $size $startTime [$ns now] $fid\"\n\
16271 }\n\
16272 \n\
16273 $ns detach-agent $clnt $ssnk\n\
16274 $ns detach-agent $svr $stcp\n\
16275 \n\
16276 if {$persist != 1} { \n\
16277 $stcp reset\n\
16278 $ssnk reset\n\
16279 $self recycle $stcp $ssnk\n\
16280 }\n\
16281 $self doneObj $pobj\n\
16282 }\n\
16283 \n\
16284 \n\
16285 \n\
16286 PagePool/EmpWebTraf instproc alloc-tcp { size mtu} {\n\
16287 \n\
16288 \n\
16289 set tcp [new Agent/TCP/[PagePool/EmpWebTraf set TCPTYPE_]]\n\
16290 \n\
16291 $tcp set window_ $size\n\
16292 \n\
16293 if {[PagePool/EmpWebTraf set fulltcp_] == 1} {\n\
16294 $tcp set segsize_ $mtu\n\
16295 } else {\n\
16296 $tcp set packetSize_ $mtu\n\
16297 }\n\
16298 \n\
16299 \n\
16300 return $tcp\n\
16301 }\n\
16302 \n\
16303 PagePool/EmpWebTraf instproc alloc-tcp-sink {} {\n\
16304 return [new Agent/[PagePool/EmpWebTraf set TCPSINKTYPE_]]\n\
16305 }\n\
16306 \n\
16307 \n\
16308 PagePool/EmpWebTraf instproc set-fid { id ctcp stcp} {\n\
16309 $stcp set fid_ $id\n\
16310 $ctcp set fid_ $id\n\
16311 }\n\
16312 \n\
16313 \n\
16314 PagePool/EmpWebTraf instproc connect-full { clnt svr ctcp stcp} {\n\
16315 \n\
16316 set ns [Simulator instance]\n\
16317 \n\
16318 $ns attach-agent $svr $stcp\n\
16319 $ns attach-agent $clnt $ctcp\n\
16320 $ns connect $stcp $ctcp\n\
16321 \n\
16322 $stcp listen\n\
16323 }\n\
16324 \n\
16325 PagePool/EmpWebTraf instproc launch-req-full { id pid clnt svr ctcp stcp size reqSize pobj persist} {\n\
16326 set ns [Simulator instance]\n\
16327 \n\
16328 if {$persist != 1} {\n\
16329 $self connect-full $clnt $svr $ctcp $stcp\n\
16330 }\n\
16331 \n\
16332 $ctcp proc done_data {} \"$self done-req-full $id $pid $clnt $svr $ctcp $stcp $size $pobj $persist\"\n\
16333 $stcp proc done_data {} \"$self done-resp-full $id $pid $clnt $svr $ctcp $stcp $size [$ns now] [$stcp set fid_] $pobj $persist\"\n\
16334 \n\
16335 if {[PagePool/EmpWebTraf set REQ_TRACE_]} {\n\
16336 puts \"req + obj:$id clnt:[$clnt id] svr:[$svr id] $size [$ns now]\"\n\
16337 }\n\
16338 \n\
16339 $self send-message $ctcp $reqSize\n\
16340 }\n\
16341 \n\
16342 PagePool/EmpWebTraf instproc done-req-full { id pid clnt svr ctcp stcp size pobj persist} {\n\
16343 set ns [Simulator instance]\n\
16344 \n\
16345 if {[PagePool/EmpWebTraf set REQ_TRACE_]} {\n\
16346 puts \"req - obj:$id clnt:[$clnt id] srv:[$svr id] [$ns now]\"\n\
16347 }   \n\
16348 \n\
16349 $self send-message $stcp $size\n\
16350 \n\
16351 if {[PagePool/EmpWebTraf set RESP_TRACE_]} {\n\
16352 puts \"resp + obj:$id srv:[$svr id] clnt:[$clnt id] $size [$ns now]\"\n\
16353 }\n\
16354 }\n\
16355 \n\
16356 PagePool/EmpWebTraf instproc done-resp-full { id pid clnt svr ctcp stcp size {startTime 0} {fid 0} pobj persist} {\n\
16357 set ns [Simulator instance]\n\
16358 \n\
16359 if {[PagePool/EmpWebTraf set RESP_TRACE_]} {\n\
16360 puts \"resp - $id $pid $size [$svr id] [$clnt id] [$ns now]\"\n\
16361 }\n\
16362 \n\
16363 if {$persist != 1} {\n\
16364 $self disconnect-full $clnt $svr $ctcp $stcp\n\
16365 }\n\
16366 \n\
16367 $self doneObj $pobj\n\
16368 }\n\
16369 \n\
16370 PagePool/EmpWebTraf instproc disconnect-full { clnt svr ctcp stcp} {\n\
16371 \n\
16372 set ns [Simulator instance]\n\
16373 \n\
16374 $ns detach-agent $clnt $ctcp\n\
16375 $ns detach-agent $svr $stcp\n\
16376 }\n\
16377 \n\
16378 \n\
16379 PagePool/EmpWebTraf instproc send-message {tcp num_bytes} {\n\
16380 \n\
16381 $tcp sendmsg $num_bytes \"DAT_EOF\"\n\
16382 }\n\
16383 \n\
16384 \n\
16385 \n\
16386 \n\
16387 Node instproc shape { shape } {\n\
16388 $self instvar attr_ \n\
16389 set attr_(SHAPE) $shape\n\
16390 }\n\
16391 \n\
16392 Node instproc get-shape {} {\n\
16393 $self instvar attr_\n\
16394 if [info exists attr_(SHAPE)] {\n\
16395 return $attr_(SHAPE)\n\
16396 } else {\n\
16397 return \"\"\n\
16398 }\n\
16399 }\n\
16400 \n\
16401 Node instproc color { color } {\n\
16402 $self instvar attr_ id_\n\
16403 \n\
16404 set ns [Simulator instance]\n\
16405 \n\
16406 if [$ns is-started] {\n\
16407 \n\
16408 $ns puts-nam-config \\\n\
16409 [eval list \"n -t [$ns now] -s $id_ -S COLOR -c $color -o $attr_(COLOR) -i $color -I $attr_(LCOLOR)\"]\n\
16410 set attr_(COLOR) $color\n\
16411 set attr_(LCOLOR) $color\n\
16412 } else {\n\
16413 set attr_(COLOR) $color\n\
16414 set attr_(LCOLOR) $color\n\
16415 }\n\
16416 }\n\
16417 \n\
16418 Node instproc label { str} {\n\
16419 $self instvar attr_ id_\n\
16420 \n\
16421 set ns [Simulator instance]\n\
16422 \n\
16423 if [info exists attr_(DLABEL)] {\n\
16424 $ns puts-nam-config \"n -t [$ns now] -s $id_ -S DLABEL -l \\\"$str\\\" -L $attr_(DLABEL)\"\n\
16425 } else {\n\
16426 $ns puts-nam-config \"n -t [$ns now] -s $id_ -S DLABEL -l \\\"$str\\\" -L \\\"\\\"\"\n\
16427 }\n\
16428 set attr_(DLABEL) \\\"$str\\\"\n\
16429 }\n\
16430 \n\
16431 Node instproc label-color { str} {\n\
16432 $self instvar attr_ id_\n\
16433 \n\
16434 set ns [Simulator instance]\n\
16435 \n\
16436 if [info exists attr_(DCOLOR)] {\n\
16437 $ns puts-nam-config \"n -t [$ns now] -s $id_ -S DCOLOR -e \\\"$str\\\" -E $attr_(DCOLOR)\"\n\
16438 } else {\n\
16439 $ns puts-nam-config \"n -t [$ns now] -s $id_ -S DCOLOR -e \\\"$str\\\" -E \\\"\\\"\"\n\
16440 }\n\
16441 set attr_(DCOLOR) \\\"$str\\\"\n\
16442 }\n\
16443 \n\
16444 Node instproc label-at { str } {\n\
16445 $self instvar attr_ id_\n\
16446 \n\
16447 set ns [Simulator instance]\n\
16448 \n\
16449 if [info exists attr_(DIRECTION)] {\n\
16450 $ns puts-nam-config \"n -t [$ns now] -s $id_ -S DIRECTION -p \\\"$str\\\" -P $attr_(DIRECTION)\"\n\
16451 } else {\n\
16452 $ns puts-nam-config \"n -t [$ns now] -s $id_ -S DIRECTION -p \\\"$str\\\" -P \\\"\\\"\"\n\
16453 }\n\
16454 set attr_(DIRECTION) \\\"$str\\\"\n\
16455 }\n\
16456 \n\
16457 Node instproc dump-namconfig {} {\n\
16458 $self instvar attr_ id_ address_ X_ Y_ Z_\n\
16459 set ns [Simulator instance]\n\
16460 \n\
16461 if ![info exists attr_(SHAPE)] {\n\
16462 set attr_(SHAPE) \"circle\"\n\
16463 } \n\
16464 if ![info exists attr_(COLOR)] {\n\
16465 set attr_(COLOR) \"black\"\n\
16466 set attr_(LCOLOR) \"black\"\n\
16467 }\n\
16468 if ![info exists attr_(DCOLOR)] {\n\
16469 set attr_(DCOLOR) \"black\"\n\
16470 }\n\
16471 if { [info exists X_] && [info exists Y_] } {\n\
16472 if [info exists Z_] {\n\
16473 $ns puts-nam-config \\\n\
16474 [eval list \"n -t * -a $address_ -s $id_ -S UP -v $attr_(SHAPE) -c $attr_(COLOR) -i $attr_(LCOLOR) -x $X_ -y $Y_ -Z $Z_\"]\n\
16475 } else {\n\
16476 $ns puts-nam-config \\\n\
16477 [eval list \"n -t * -a $address_ -s $id_ -S UP -v $attr_(SHAPE) -c $attr_(COLOR) -i $attr_(LCOLOR) -x $X_ -y $Y_\"]\n\
16478 }\n\
16479 } else {\n\
16480 $ns puts-nam-config \\\n\
16481 [eval list \"n -t * -a $address_ -s $id_ -S UP -v $attr_(SHAPE) -c $attr_(COLOR) -i $attr_(LCOLOR)\"]\n\
16482 }\n\
16483 }\n\
16484 \n\
16485 Node instproc change-color { color } {\n\
16486 puts \"Warning: Node::change-color is obsolete. Use Node::color instead\"\n\
16487 $self color $color\n\
16488 }\n\
16489 \n\
16490 Node instproc get-attribute { name } {\n\
16491 $self instvar attr_\n\
16492 if [info exists attr_($name)] {\n\
16493 return $attr_($name)\n\
16494 } else {\n\
16495 return \"\"\n\
16496 }\n\
16497 }\n\
16498 \n\
16499 Node instproc get-color {} {\n\
16500 puts \"Warning: Node::get-color is obsolete. Please use Node::get-attribute\"\n\
16501 return [$self get-attribute \"COLOR\"]\n\
16502 }\n\
16503 \n\
16504 Node instproc add-mark { name color {shape \"circle\"} } {\n\
16505 $self instvar id_ markColor_ shape_\n\
16506 set ns [Simulator instance]\n\
16507 \n\
16508 $ns puts-nam-config \"m -t [$ns now] -s $id_ -n $name -c $color -h $shape\"\n\
16509 set markColor_($name) $color\n\
16510 set shape_($name) $shape\n\
16511 }\n\
16512 \n\
16513 Node instproc delete-mark { name } {\n\
16514 $self instvar id_ markColor_ shape_\n\
16515 \n\
16516 if ![info exists markColor_($name)] {\n\
16517 return\n\
16518 }\n\
16519 \n\
16520 set ns [Simulator instance]\n\
16521 $ns puts-nam-config \\\n\
16522 \"m -t [$ns now] -s $id_ -n $name -c $markColor_($name) -h $shape_($name) -X\"\n\
16523 }\n\
16524 \n\
16525 SimpleLink instproc dump-namconfig {} {\n\
16526 $self instvar link_ attr_ fromNode_ toNode_\n\
16527 \n\
16528 if ![info exists attr_(COLOR)] {\n\
16529 set attr_(COLOR) \"black\"\n\
16530 }\n\
16531 \n\
16532 set ns [Simulator instance]\n\
16533 set bw [$link_ set bandwidth_]\n\
16534 set delay [$link_ set delay_]\n\
16535 \n\
16536 if [info exists attr_(ORIENTATION)] {\n\
16537 $ns puts-nam-config \\\n\
16538 \"l -t * -s [$fromNode_ id] -d [$toNode_ id] -S UP -r $bw -D $delay -c $attr_(COLOR) -o $attr_(ORIENTATION)\"\n\
16539 } else {\n\
16540 $ns puts-nam-config \\\n\
16541 \"l -t * -s [$fromNode_ id] -d [$toNode_ id] -S UP -r $bw -D $delay -c $attr_(COLOR)\"\n\
16542 }\n\
16543 }\n\
16544 \n\
16545 Link instproc dump-nam-queueconfig {} {\n\
16546 $self instvar attr_ fromNode_ toNode_\n\
16547 \n\
16548 if ![info exists attr_(COLOR)] {\n\
16549 set attr_(COLOR) \"black\"\n\
16550 }\n\
16551 \n\
16552 set ns [Simulator instance]\n\
16553 if [info exists attr_(QUEUE_POS)] {\n\
16554 $ns puts-nam-config \"q -t * -s [$fromNode_ id] -d [$toNode_ id] -a $attr_(QUEUE_POS)\"\n\
16555 } else {\n\
16556 set attr_(QUEUE_POS) \"\"\n\
16557 }\n\
16558 }\n\
16559 \n\
16560 Link instproc orient { ori } {\n\
16561 $self instvar attr_\n\
16562 set attr_(ORIENTATION) $ori\n\
16563 [Simulator instance] register-nam-linkconfig $self\n\
16564 }\n\
16565 \n\
16566 Link instproc get-attribute { name } {\n\
16567 $self instvar attr_\n\
16568 if [info exists attr_($name)] {\n\
16569 return $attr_($name)\n\
16570 } else {\n\
16571 return \"\"\n\
16572 }\n\
16573 }\n\
16574 \n\
16575 Link instproc queuePos { pos } {\n\
16576 $self instvar attr_\n\
16577 set attr_(QUEUE_POS) $pos\n\
16578 }\n\
16579 \n\
16580 Link instproc color { color } {\n\
16581 $self instvar attr_ fromNode_ toNode_ trace_\n\
16582 \n\
16583 set ns [Simulator instance]\n\
16584 if [$ns is-started] {\n\
16585 $ns puts-nam-config \\\n\
16586 [eval list \"l -t [$ns now] -s [$fromNode_ id] -d [$toNode_ id] -S COLOR -c $color -o $attr_(COLOR)\"]\n\
16587 set attr_(COLOR) $color\n\
16588 } else {\n\
16589 set attr_(COLOR) $color\n\
16590 }\n\
16591 }\n\
16592 \n\
16593 Link instproc change-color { color } {\n\
16594 puts \"Warning: Link::change-color is obsolete. Please use Link::color.\"\n\
16595 $self color $color\n\
16596 }\n\
16597 \n\
16598 Link instproc get-color {} {\n\
16599 puts \"Warning: Node::get-color is obsolete. Please use Node::get-attribute\"\n\
16600 return [$self get-attribute \"COLOR\"]\n\
16601 }\n\
16602 \n\
16603 Link instproc label { label } {\n\
16604 $self instvar attr_ fromNode_ toNode_ trace_\n\
16605 set ns [Simulator instance]\n\
16606 if [info exists attr_(DLABEL)] {\n\
16607 $ns puts-nam-config \\\n\
16608 \"l -t [$ns now] -s [$fromNode_ id] -d [$toNode_ id] -S DLABEL -l \\\"$label\\\" -L $attr_(DLABEL)\"\n\
16609 } else {\n\
16610 $ns puts-nam-config \\\n\
16611 \"l -t [$ns now] -s [$fromNode_ id] -d [$toNode_ id] -S DLABEL -l \\\"$label\\\" -L \\\"\\\"\"\n\
16612 }\n\
16613 set attr_(DLABEL) \\\"$label\\\"\n\
16614 }\n\
16615 \n\
16616 Link instproc label-color { str } {\n\
16617 $self instvar attr_ fromNode_ toNode_ trace_\n\
16618 set ns [Simulator instance]\n\
16619 if [info exists attr_(DCOLOR)] {\n\
16620 $ns puts-nam-config \\\n\
16621 \"l -t [$ns now] -s [$fromNode_ id] -d [$toNode_ id] -S DCOLOR -e \\\"$str\\\" -E $attr_(DCOLOR)\"\n\
16622 } else {\n\
16623 $ns puts-nam-config \\\n\
16624 \"l -t [$ns now] -s [$fromNode_ id] -d [$toNode_ id] -S DCOLOR -e \\\"$str\\\" -E \\\"\\\"\"\n\
16625 }\n\
16626 set attr_(DCOLOR) \\\"$str\\\"\n\
16627 }\n\
16628 \n\
16629 Link instproc label-at { str } {\n\
16630 $self instvar attr_ fromNode_ toNode_ trace_\n\
16631 set ns [Simulator instance]\n\
16632 if [info exists attr_(DIRECTION)] {\n\
16633 $ns puts-nam-config \\\n\
16634 \"l -t [$ns now] -s [$fromNode_ id] -d [$toNode_ id] -S DIRECTION -p \\\"$str\\\" -P $attr_(DIRECTION)\"\n\
16635 } else {\n\
16636 $ns puts-nam-config \\\n\
16637 \"l -t [$ns now] -s [$fromNode_ id] -d [$toNode_ id] -S DIRECTION -p \\\"$str\\\" -P \\\"\\\"\"\n\
16638 }\n\
16639 set attr_(DIRECTION) \\\"$str\\\"\n\
16640 }\n\
16641 \n\
16642 \n\
16643 Simulator instproc snapshot { } {\n\
16644 set ns [Simulator instance]\n\
16645 $ns puts-nam-config \\\n\
16646 \"v -t [$self now] take_snapshot\"\n\
16647 }\n\
16648 \n\
16649 Simulator instproc rewind-nam { } {\n\
16650 set ns [Simulator instance]\n\
16651 $ns puts-nam-config \\\n\
16652 \"v  -t [$self now] playing_backward\"\n\
16653 }\n\
16654 \n\
16655 Simulator instproc re-rewind-nam { } {\n\
16656 set ns [Simulator instance]\n\
16657 $ns puts-nam-config \\\n\
16658 \"v  -t [$self now] playing_forward\"\n\
16659 }\n\
16660 \n\
16661 Simulator instproc terminate-nam { } {\n\
16662 set ns [Simulator instance]\n\
16663 $ns puts-nam-config \\\n\
16664 \"v  -t [$self now] terminating_nam\"\n\
16665 }\n\
16666 \n\
16667 \n\
16668 Simulator instproc add-agent-trace { agent name {f \"\"} } {\n\
16669 $self instvar tracedAgents_\n\
16670 set tracedAgents_($name) $agent\n\
16671 \n\
16672 set trace [$self get-nam-traceall]\n\
16673 if {$f != \"\"} {\n\
16674 $agent attach-trace $f\n\
16675 } elseif {$trace != \"\"} {\n\
16676 $agent attach-trace $trace\n\
16677 }\n\
16678 }\n\
16679 \n\
16680 Simulator instproc delete-agent-trace { agent } {\n\
16681 $agent delete-agent-trace\n\
16682 }\n\
16683 \n\
16684 Simulator instproc monitor-agent-trace { agent } {\n\
16685 $self instvar monitoredAgents_\n\
16686 lappend monitoredAgents_ $agent\n\
16687 }\n\
16688 \n\
16689 Agent instproc attach-trace { file } {\n\
16690 $self instvar namTrace_\n\
16691 set namTrace_ $file \n\
16692 $self attach $file \n\
16693 }\n\
16694 \n\
16695 Simulator instproc dump-namagents {} {\n\
16696 $self instvar tracedAgents_ monitoredAgents_\n\
16697 \n\
16698 if {![$self is-started]} {\n\
16699 return\n\
16700 }\n\
16701 if [info exists tracedAgents_] {\n\
16702 foreach id [array names tracedAgents_] {\n\
16703 $tracedAgents_($id) add-agent-trace $id\n\
16704 $tracedAgents_($id) cmd dump-namtracedvars\n\
16705 }\n\
16706 unset tracedAgents_\n\
16707 }\n\
16708 if [info exists monitoredAgents_] {\n\
16709 foreach a $monitoredAgents_ {\n\
16710 $a show-monitor\n\
16711 }\n\
16712 unset monitoredAgents_\n\
16713 }\n\
16714 }\n\
16715 \n\
16716 Simulator instproc dump-namversion { v } {\n\
16717 $self puts-nam-config \"V -t * -v $v -a 0\"\n\
16718 }\n\
16719 \n\
16720 Simulator instproc dump-namwireless {} {\n\
16721 $self instvar namNeedsW_ namWx_ namWy_\n\
16722 \n\
16723 if ![info exists namNeedsW_] { set namNeedsW_ 0 }\n\
16724 if {[info exists namWx_] && [info exists namWy_]}  {\n\
16725 set maxX $namWx_\n\
16726 set maxY $namWy_\n\
16727 } else {\n\
16728 set maxX 10\n\
16729 set maxY 10\n\
16730 \n\
16731 foreach node [Node info instances] {\n\
16732 if {[lsearch -exact [$node info vars] X_] != -1} {\n\
16733 set namNeedsW_ 1\n\
16734 set curX [$node set X_]\n\
16735 if {$curX > $maxX} {set maxX $curX}\n\
16736 }\n\
16737 if {[lsearch -exact [$node info vars] Y_] != -1} {\n\
16738 set namNeedsW_ 1\n\
16739 set curY [$node set Y_]\n\
16740 if {$curY > $maxY} {set maxY $curY}\n\
16741 }\n\
16742 }\n\
16743 }\n\
16744 \n\
16745 if $namNeedsW_ {\n\
16746 $self puts-nam-config \"W -t * -x $maxX -y $maxY\"\n\
16747 }\n\
16748 }\n\
16749 \n\
16750 Simulator instproc dump-namcolors {} {\n\
16751 $self instvar color_\n\
16752 if ![$self is-started] {\n\
16753 return \n\
16754 }\n\
16755 foreach id [array names color_] {\n\
16756 $self puts-nam-config \"c -t * -i $id -n $color_($id)\"\n\
16757 }\n\
16758 }\n\
16759 \n\
16760 Simulator instproc dump-namlans {} {\n\
16761 if ![$self is-started] {\n\
16762 return\n\
16763 }\n\
16764 $self instvar Node_\n\
16765 foreach nn [array names Node_] {\n\
16766 if [$Node_($nn) is-lan?] {\n\
16767 $Node_($nn) dump-namconfig\n\
16768 }\n\
16769 }\n\
16770 }\n\
16771 \n\
16772 Simulator instproc dump-namlinks {} {\n\
16773 $self instvar linkConfigList_\n\
16774 if ![$self is-started] {\n\
16775 return\n\
16776 }\n\
16777 if [info exists linkConfigList_] {\n\
16778 foreach lnk $linkConfigList_ {\n\
16779 $lnk dump-namconfig\n\
16780 }\n\
16781 unset linkConfigList_\n\
16782 }\n\
16783 }\n\
16784 \n\
16785 Simulator instproc dump-namnodes {} {\n\
16786 $self instvar Node_\n\
16787 if ![$self is-started] {\n\
16788 return\n\
16789 }\n\
16790 foreach nn [array names Node_] {\n\
16791 if ![$Node_($nn) is-lan?] {\n\
16792 $Node_($nn) dump-namconfig\n\
16793 }\n\
16794 }\n\
16795 }\n\
16796 \n\
16797 Simulator instproc dump-namqueues {} {\n\
16798 $self instvar link_\n\
16799 if ![$self is-started] {\n\
16800 return\n\
16801 }\n\
16802 foreach qn [array names link_] {\n\
16803 $link_($qn) dump-nam-queueconfig\n\
16804 }\n\
16805 }\n\
16806 \n\
16807 Simulator instproc dump-namaddress {} {\n\
16808 $self puts-nam-config \\\n\
16809 \"A -t * -n [AddrParams hlevel] -p 0 -o [AddrParams set \\\n\
16810 ALL_BITS_SET] -c [AddrParams McastShift] -a [AddrParams McastMask]\"\n\
16811 \n\
16812 for {set i 1} {$i <= [AddrParams hlevel]} {incr i} {\n\
16813 $self puts-nam-config \"A -t * -h $i -m [AddrParams \\\n\
16814 NodeMask $i] -s [AddrParams NodeShift $i]\"\n\
16815 }\n\
16816 }\n\
16817 \n\
16818 Simulator instproc init-nam {} {\n\
16819 $self instvar annotationSeq_ \n\
16820 \n\
16821 set annotationSeq_ 0\n\
16822 \n\
16823 $self dump-namversion 1.0a5\n\
16824 \n\
16825 $self dump-namwireless\n\
16826 \n\
16827 $self dump-namaddress\n\
16828 \n\
16829 $self dump-namcolors\n\
16830 \n\
16831 $self dump-namnodes\n\
16832 \n\
16833 $self dump-namlinks \n\
16834 $self dump-namlans\n\
16835 \n\
16836 $self dump-namqueues\n\
16837 \n\
16838 $self dump-namagents\n\
16839 \n\
16840 }\n\
16841 \n\
16842 Simulator instproc trace-annotate { str } {\n\
16843 $self instvar annotationSeq_\n\
16844 $self puts-ns-traceall [format \\\n\
16845 \"v %s %s {set sim_annotation {%s}}\" [$self now] eval $str]\n\
16846 incr annotationSeq_\n\
16847 $self puts-nam-config [format \\\n\
16848 \"v -t %.15g -e sim_annotation %.15g $annotationSeq_ $str\" \\\n\
16849 [$self now] [$self now] ]\n\
16850 }\n\
16851 \n\
16852 proc trace_annotate { str } {\n\
16853 set ns [Simulator instance]\n\
16854 \n\
16855 $ns trace-annotate $str\n\
16856 }\n\
16857 \n\
16858 proc flash_annotate { start duration msg } {\n\
16859 set ns [Simulator instance]\n\
16860 $ns at $start \"trace_annotate {$msg}\"\n\
16861 $ns at [expr $start+$duration] \"trace_annotate periodic_message\"\n\
16862 }\n\
16863 \n\
16864 Simulator instproc set-animation-rate { rate } {\n\
16865 set r [time_parse $rate]\n\
16866 $self puts-nam-config \"v -t [$self now] set_rate_ext $r 1\"\n\
16867 }\n\
16868 \n\
16869 Agent/DSDV set sport_        0\n\
16870 Agent/DSDV set dport_        0\n\
16871 Agent/DSDV set wst0_         6        ;# As specified by Pravin\n\
16872 Agent/DSDV set perup_       15        ;# As given in the paper (update period)\n\
16873 Agent/DSDV set use_mac_      0        ;# Performance suffers with this on\n\
16874 Agent/DSDV set be_random_    1        ;# Flavor the performance numbers :)\n\
16875 Agent/DSDV set alpha_        0.875    ;# 7/8, as in RIP(?)\n\
16876 Agent/DSDV set min_update_periods_ 3  ;# Missing perups before linkbreak\n\
16877 Agent/DSDV set verbose_      0        ;# \n\
16878 Agent/DSDV set trace_wst_    0        ;# \n\
16879 \n\
16880 set opt(ragent)     Agent/DSDV\n\
16881 set opt(pos)        NONE            ;# Box or NONE\n\
16882 \n\
16883 if { $opt(pos) == \"Box\" } {\n\
16884 puts \"*** DSDV using Box configuration...\"\n\
16885 }\n\
16886 \n\
16887 Agent instproc init args {\n\
16888 eval $self next $args\n\
16889 }       \n\
16890 \n\
16891 Agent/DSDV instproc init args {\n\
16892 eval $self next $args\n\
16893 }       \n\
16894 \n\
16895 \n\
16896 \n\
16897 proc create-dsdv-routing-agent { node id } {\n\
16898 global ns_ ragent_ tracefd opt\n\
16899 \n\
16900 set ragent_($id) [new $opt(ragent)]\n\
16901 set ragent $ragent_($id)\n\
16902 \n\
16903 set addr [$node node-addr]\n\
16904 \n\
16905 $ragent addr $addr\n\
16906 $ragent node $node\n\
16907 if [Simulator set mobile_ip_] {\n\
16908 $ragent port-dmux [$node set dmux_]\n\
16909 }\n\
16910 $node addr $addr\n\
16911 $node set ragent_ $ragent\n\
16912 \n\
16913 $node attach $ragent [Node set rtagent_port_]\n\
16914 \n\
16915 \n\
16916 $ns_ at 0.0 \"$ragent_($id) start-dsdv\"    ;# start updates\n\
16917 \n\
16918 set drpT [cmu-trace Drop \"RTR\" $node]\n\
16919 $ragent drop-target $drpT\n\
16920 \n\
16921 set T [new Trace/Generic]\n\
16922 $T target [$ns_ set nullAgent_]\n\
16923 $T attach $tracefd\n\
16924 $T set src_ $id\n\
16925 $ragent tracetarget $T\n\
16926 }\n\
16927 \n\
16928 \n\
16929 proc dsdv-create-mobile-node { id args } {\n\
16930 global ns ns_ chan prop topo tracefd opt node_\n\
16931 global chan prop tracefd topo opt\n\
16932 \n\
16933 set ns_ [Simulator instance]\n\
16934 if [Simulator hier-addr?] {\n\
16935 if [Simulator set mobile_ip_] {\n\
16936 set node_($id) [new MobileNode/MIPMH $args]\n\
16937 } else {\n\
16938 set node_($id) [new Node/MobileNode/BaseStationNode $args]\n\
16939 }\n\
16940 } else {\n\
16941 set node_($id) [new Node/MobileNode]\n\
16942 }\n\
16943 set node $node_($id)\n\
16944 $node random-motion 0       ;# disable random motion\n\
16945 $node topography $topo\n\
16946 \n\
16947 if [info exists opt(energy)] {\n\
16948 $node addenergymodel [new $opt(energy) $node 1000 0.5 0.2]\n\
16949 }\n\
16950 \n\
16951 set T [new Trace/Generic]\n\
16952 $T target [$ns_ set nullAgent_]\n\
16953 $T attach $tracefd\n\
16954 $T set src_ $id\n\
16955 $node log-target $T\n\
16956 \n\
16957 if ![info exist inerrProc_] {\n\
16958 set inerrProc_ \"\"\n\
16959 }\n\
16960 if ![info exist outerrProc_] {\n\
16961 set outerrProc_ \"\"\n\
16962 }\n\
16963 if ![info exist FECProc_] {\n\
16964 set FECProc_ \"\"\n\
16965 }\n\
16966 \n\
16967 $node add-interface $chan $prop $opt(ll) $opt(mac)  \\\n\
16968 $opt(ifq) $opt(ifqlen) $opt(netif) $opt(ant) \\\n\
16969 $topo $inerrProc_ $outerrProc_ $FECProc_ \n\
16970 \n\
16971 create-$opt(rp)-routing-agent $node $id\n\
16972 \n\
16973 if { $opt(pos) == \"Box\" } {\n\
16974 set spacing 200\n\
16975 set maxrow 7\n\
16976 set col [expr ($id - 1) % $maxrow]\n\
16977 set row [expr ($id - 1) / $maxrow]\n\
16978 $node set X_ [expr $col * $spacing]\n\
16979 $node set Y_ [expr $row * $spacing]\n\
16980 $node set Z_ 0.0\n\
16981 $node set speed_ 0.0\n\
16982 \n\
16983 $ns_ at 0.0 \"$node_($id) start\"\n\
16984 }\n\
16985 return $node\n\
16986 }\n\
16987 \n\
16988 \n\
16989 \n\
16990 \n\
16991 \n\
16992 \n\
16993 \n\
16994 \n\
16995 \n\
16996 \n\
16997 set opt(rt_port) 255\n\
16998 set opt(cc)      \"off\"            ;# have god check the caches for bad links?\n\
16999 \n\
17000 \n\
17001 Class CacheTimer -superclass Timer\n\
17002 CacheTimer instproc timeout {} {\n\
17003 global opt node_;\n\
17004 $self instvar agent;\n\
17005 $agent check-cache\n\
17006 $self sched 1.0\n\
17007 }\n\
17008 \n\
17009 proc checkcache {a} {\n\
17010 global cachetimer ns\n\
17011 \n\
17012 set cachetimer [new CacheTimer]\n\
17013 $cachetimer set agent $a\n\
17014 $cachetimer sched 1.0\n\
17015 }\n\
17016 \n\
17017 Class SRNode -superclass Node/MobileNode\n\
17018 \n\
17019 SRNode instproc init {args} {\n\
17020 global ns ns_ opt tracefd RouterTrace\n\
17021 $self instvar dsr_agent_ dmux_ entry_point_ address_\n\
17022 set ns_ [Simulator instance]\n\
17023 \n\
17024 eval $self next $args   ;# parent class constructor\n\
17025 if {$dmux_ == \"\" } {\n\
17026 set dmux_ [new Classifier/Port]\n\
17027 $dmux_ set mask_ [AddrParams PortMask]\n\
17028 $dmux_ set shift_ [AddrParams PortShift]\n\
17029 }\n\
17030 set dsr_agent_ [new Agent/DSRAgent]\n\
17031 \n\
17032 $dsr_agent_ addr $address_\n\
17033 $dsr_agent_ node $self\n\
17034 if [Simulator set mobile_ip_] {\n\
17035 $dsr_agent_ port-dmux [$self set dmux_]\n\
17036 }\n\
17037 $self addr $address_\n\
17038 \n\
17039 if { $RouterTrace == \"ON\" } {\n\
17040 set rcvT [cmu-trace Recv \"RTR\" $self]\n\
17041 $rcvT target $dsr_agent_\n\
17042 set entry_point_ $rcvT  \n\
17043 } else {\n\
17044 set entry_point_ $dsr_agent_\n\
17045 }\n\
17046 \n\
17047 set drpT [cmu-trace Drop \"RTR\" $self]\n\
17048 $dsr_agent_ drop-target $drpT\n\
17049 \n\
17050 \n\
17051 set T [new Trace/Generic]\n\
17052 $T target [$ns_ set nullAgent_]\n\
17053 $T attach $tracefd\n\
17054 $T set src_ [$self id]\n\
17055 $dsr_agent_ log-target $T\n\
17056 \n\
17057 $dsr_agent_ target $dmux_\n\
17058 \n\
17059 set nullAgent_ [$ns_ set nullAgent_]\n\
17060 $dmux_ install $opt(rt_port) $nullAgent_\n\
17061 \n\
17062 $self instvar classifier_\n\
17063 set classifier_ \"srnode made illegal use of classifier_\"\n\
17064 \n\
17065 }\n\
17066 \n\
17067 SRNode instproc start-dsr {} {\n\
17068 $self instvar dsr_agent_\n\
17069 global opt;\n\
17070 \n\
17071 $dsr_agent_ startdsr\n\
17072 if {$opt(cc) == \"on\"} {checkcache $dsr_agent_}\n\
17073 }\n\
17074 \n\
17075 SRNode instproc entry {} {\n\
17076 $self instvar entry_point_\n\
17077 return $entry_point_\n\
17078 }\n\
17079 \n\
17080 \n\
17081 \n\
17082 SRNode instproc add-interface {args} {\n\
17083 global ns ns_ opt RouterTrace\n\
17084 \n\
17085 eval $self next $args\n\
17086 \n\
17087 $self instvar dsr_agent_ ll_ mac_ ifq_\n\
17088 \n\
17089 $dsr_agent_ mac-addr [$mac_(0) id]\n\
17090 \n\
17091 if { $RouterTrace == \"ON\" } {\n\
17092 set sndT [cmu-trace Send \"RTR\" $self]\n\
17093 $sndT target $ll_(0)\n\
17094 $dsr_agent_ add-ll $sndT $ifq_(0)\n\
17095 } else {\n\
17096 $dsr_agent_ add-ll $ll_(0) $ifq_(0)\n\
17097 }\n\
17098 \n\
17099 $dsr_agent_ install-tap $mac_(0)\n\
17100 \n\
17101 }\n\
17102 \n\
17103 SRNode instproc reset args {\n\
17104 $self instvar dsr_agent_\n\
17105 eval $self next $args\n\
17106 \n\
17107 $dsr_agent_ reset\n\
17108 }\n\
17109 \n\
17110 \n\
17111 proc dsr-create-mobile-node { id args } {\n\
17112 global ns_ chan prop topo tracefd opt node_\n\
17113 set ns_ [Simulator instance] \n\
17114 if [Simulator hier-addr?] {\n\
17115 if [Simulator set mobile_ip_] {\n\
17116 set node_($id) [new SRNode/MIPMH $args]\n\
17117 } else {\n\
17118 set node_($id) [new SRNode $args]\n\
17119 }\n\
17120 } else {\n\
17121 set node_($id) [new SRNode]\n\
17122 }\n\
17123 set node $node_($id)\n\
17124 $node random-motion 0       ;# disable random motion\n\
17125 $node topography $topo\n\
17126 \n\
17127 if [info exists opt(energy)] {\n\
17128 $node addenergymodel [new $opt(energy) $node 1000 0.5 0.2]\n\
17129 }\n\
17130 \n\
17131 if ![info exist inerrProc_] {\n\
17132 set inerrProc_ \"\"\n\
17133 }\n\
17134 if ![info exist outerrProc_] {\n\
17135 set outerrProc_ \"\"\n\
17136 }\n\
17137 if ![info exist FECProc_] {\n\
17138 set FECProc_ \"\"\n\
17139 }\n\
17140 \n\
17141 $node add-interface $chan $prop $opt(ll) $opt(mac)     \\\n\
17142 $opt(ifq) $opt(ifqlen) $opt(netif) $opt(ant) $topo \\\n\
17143 $inerrProc_ $outerrProc_ $FECProc_ \n\
17144 \n\
17145 set T [new Trace/Generic]\n\
17146 $T target [$ns_ set nullAgent_]\n\
17147 $T attach $tracefd\n\
17148 $T set src_ $id\n\
17149 $node log-target $T\n\
17150 \n\
17151 $ns_ at 0.0 \"$node start-dsr\"\n\
17152 return $node\n\
17153 }\n\
17154 \n\
17155 \n\
17156 proc create-base-station-node {address } {\n\
17157 \n\
17158 puts \"Method create-base-station-node is now obsolete. Use methods in ~ns/tcl/test/test-suite-WLtutorial.tcl to create base-station nodes\\n\\n\"\n\
17159 exit 0\n\
17160 \n\
17161 \n\
17162 \n\
17163 \n\
17164 }\n\
17165 \n\
17166 \n\
17167 proc create-dsdv-bs-node {node id} {\n\
17168 \n\
17169 puts \"Method create-dsdv-bs-node is now obsolete. Use methods in ~ns/tcl/test/test-suite-WLtutorial.tcl to create base-station nodes\\n\\n\"\n\
17170 exit 0\n\
17171 \n\
17172 }\n\
17173 \n\
17174 proc create-dsr-bs-node {node id} {\n\
17175 \n\
17176 puts \"Method create-dsr-bs-node is now obsolete. Use methods in ~ns/tcl/test/test-suite-WLtutorial.tcl to create base-station nodes\\n\\n\"\n\
17177 exit 0\n\
17178 \n\
17179 }\n\
17180 \n\
17181 \n\
17182 proc create-dsr-routing-agent { node id } {\n\
17183 \n\
17184 puts \"Method create-dsr-routing-agent is now obsolete. Use methods in ~ns/tcl/test/test-suite-WLtutorial.tcl to create base-station nodes\\n\\n\"\n\
17185 exit 0\n\
17186 \n\
17187 \n\
17188 \n\
17189 }\n\
17190 \n\
17191 \n\
17192 Node/MobileNode/BaseStationNode instproc create-xtra-interface { } {\n\
17193 global ns_ opt \n\
17194 $self instvar ragent_ ll_ mac_ ifq_\n\
17195 \n\
17196 $ragent_ mac-addr [$mac_(0) id]\n\
17197 \n\
17198 if { [Simulator set RouterTrace_] == \"ON\" } {\n\
17199 set sndT [cmu-trace Send \"RTR\" $self]\n\
17200 $sndT target $ll_(0)\n\
17201 $ragent_ add-ll $sndT $ifq_(0)\n\
17202 } else {\n\
17203 $ragent_ add-ll $ll_(0) $ifq_(0)\n\
17204 }\n\
17205 \n\
17206 $ragent_ install-tap $mac_(0)\n\
17207 \n\
17208 }\n\
17209 \n\
17210 Node/MobileNode/BaseStationNode instproc start-dsr {} {\n\
17211 $self instvar ragent_\n\
17212 global opt;\n\
17213 \n\
17214 $ragent_ startdsr\n\
17215 if {$opt(cc) == \"on\"} {checkcache $dsr_agent_}\n\
17216 }\n\
17217 \n\
17218 Node/MobileNode/BaseStationNode instproc reset args {\n\
17219 $self instvar ragent_\n\
17220 eval $self next $args\n\
17221 \n\
17222 $ragent_ reset\n\
17223 }\n\
17224 \n\
17225 \n\
17226 proc create-god { nodes } {\n\
17227 set god [God info instances]\n\
17228 if { $god == \"\" } {\n\
17229 set god [new God]\n\
17230 }\n\
17231 $god num_nodes $nodes\n\
17232 return $god\n\
17233 }\n\
17234 \n\
17235 God proc instance {} {\n\
17236 set god [God info instances]\n\
17237 if { $god != \"\" } {\n\
17238 return $god\n\
17239 }  \n\
17240 error \"Cannot find instance of god\"\n\
17241 }      \n\
17242 \n\
17243 proc cmu-trace { ttype atype node } {\n\
17244 global ns_ tracefd\n\
17245 \n\
17246 if { $tracefd == \"\" } {\n\
17247 return \"\"\n\
17248 }\n\
17249 set T [new CMUTrace/$ttype $atype]\n\
17250 $T target [$ns_ set nullAgent_]\n\
17251 $T attach $tracefd\n\
17252 $T set src_ [$node id]\n\
17253 \n\
17254 $T node $node\n\
17255 \n\
17256 return $T\n\
17257 }\n\
17258 \n\
17259 proc log-movement {} {\n\
17260 global logtimer ns_ ns\n\
17261 \n\
17262 set ns $ns_\n\
17263 source ../mobility/timer.tcl\n\
17264 Class LogTimer -superclass Timer\n\
17265 LogTimer instproc timeout {} {\n\
17266 global opt node_;\n\
17267 for {set i 0} {$i < $opt(nn)} {incr i} {\n\
17268 $node_($i) log-movement\n\
17269 }\n\
17270 $self sched 0.1\n\
17271 }\n\
17272 \n\
17273 set logtimer [new LogTimer]\n\
17274 $logtimer sched 0.1\n\
17275 }    \n\
17276 \n\
17277 proc set-wireless-traces { args } {\n\
17278 set len [llength $args]\n\
17279 if { $len <= 0 || [expr $len%2] } {\n\
17280 error \"Incorrect number of parameters\"\n\
17281 }\n\
17282 for {set n 0} {$n < $len} {incr n 2} {\n\
17283 if {[string compare [lindex $args $n] \"-AgentTrace\"] == 0 } {\n\
17284 Simulator set AgentTrace_ [lindex $args [expr $n+1]]\n\
17285 } elseif {[string compare [lindex $args $n] \"-RouterTrace\"] == 0 } {\n\
17286 Simulator set RouterTrace_ [lindex $args [expr $n+1]]\n\
17287 } elseif {[string compare [lindex $args $n] \"-MacTrace\"] == 0 } {\n\
17288 Simulator set MacTrace_ [lindex $args [expr $n+1]]\n\
17289 } else {\n\
17290 error \"Unknown wireless trace type: [lindex $args $n]\"\n\
17291 }\n\
17292 }\n\
17293 }  \n\
17294 \n\
17295 \n\
17296 \n\
17297 \n\
17298 \n\
17299 \n\
17300 \n\
17301 \n\
17302 \n\
17303 \n\
17304 Class PLM\n\
17305 \n\
17306 PLM instproc init {levels chk_estimate n_id} {\n\
17307 $self next\n\
17308 $self instvar PP_estimate wait_loss time_loss \n\
17309 $self instvar start_loss time_estimate check_estimate node_id\n\
17310 global rates\n\
17311 set PP_estimate {} \n\
17312 set start_loss -1\n\
17313 set wait_loss 0\n\
17314 set time_loss 0\n\
17315 set time_estimate 0\n\
17316 set check_estimate $chk_estimate\n\
17317 set node_id $n_id\n\
17318 \n\
17319 $self instvar debug_ env_ maxlevel_\n\
17320 \n\
17321 set debug_ 0\n\
17322 set env_ [lindex [split [$self info class] /] 1]\n\
17323 set maxlevel_ $levels\n\
17324 \n\
17325 global plm_debug_flag\n\
17326 if [info exists plm_debug_flag] {\n\
17327 set debug_ $plm_debug_flag\n\
17328 }\n\
17329 \n\
17330 $self instvar subscription_\n\
17331 \n\
17332 $self instvar layer_ layers_\n\
17333 set i 1\n\
17334 while { $i <= $maxlevel_ } {\n\
17335 set layer_($i) [$self create-layer [expr $i - 1]]\n\
17336 lappend layers_ $layer_($i)\n\
17337 incr i\n\
17338 }\n\
17339 \n\
17340 set subscription_ 0\n\
17341 $self add-layer\n\
17342 }\n\
17343 \n\
17344 \n\
17345 \n\
17346 PLM instproc make_estimate {PP_value} {\n\
17347 $self instvar PP_estimate PP_estimate_value ns_ time_estimate check_estimate debug_\n\
17348 global PP_estimation_length\n\
17349 \n\
17350 lappend PP_estimate $PP_value\n\
17351 \n\
17352 $self stability-drop $PP_value\n\
17353 \n\
17354 set ns_time [$ns_ now]\n\
17355 if {$time_estimate==0} {\n\
17356 set time_estimate [expr $ns_time + $check_estimate]\n\
17357 }\n\
17358 if {$debug_>=3} {\n\
17359 trace_annotate \"[$self node]: check: $check_estimate $PP_estimate , nb: [llength $PP_estimate]\"\n\
17360 }\n\
17361 \n\
17362 if {($time_estimate<=$ns_time) && ([llength $PP_estimate] >= $PP_estimation_length)} {\n\
17363 set PP_estimate_value [lindex [lsort -real $PP_estimate] 0]\n\
17364 if {$debug_>=3} {\n\
17365 trace_annotate \"[$self node]: check: $check_estimate PP estim: $PP_estimate, value: $PP_estimate_value\"\n\
17366 }\n\
17367 if {$debug_>=2} {\n\
17368 trace_annotate [expr round($PP_estimate_value)]\n\
17369 }\n\
17370 set PP_estimate {}\n\
17371 set time_estimate [expr $ns_time + $check_estimate]\n\
17372 $self choose_layer $PP_estimate_value\n\
17373 \n\
17374 }\n\
17375 }\n\
17376 \n\
17377 \n\
17378 PLM instproc stability-drop {PP_value} {\n\
17379 $self instvar subscription_ start_loss time_estimate PP_estimate\n\
17380 $self instvar check_estimate ns_\n\
17381 global rates_cum\n\
17382 \n\
17383 set ns_time [$ns_ now]\n\
17384 for {set i 0} {[lindex $rates_cum $i] < [expr round($PP_value)]} {incr i} {\n\
17385 if {$i > [llength $rates_cum]} {break}\n\
17386 }\n\
17387 \n\
17388 if {$subscription_ > $i} {\n\
17389 for {set j $subscription_} {$i < $j} {incr j -1} {\n\
17390 set start_loss -1\n\
17391 $self drop-layer        \n\
17392 }\n\
17393 set PP_estimate {}\n\
17394 set time_estimate [expr $ns_time + $check_estimate]\n\
17395 }\n\
17396 }\n\
17397 \n\
17398 proc calc_cum {rates} {\n\
17399 set temp 0\n\
17400 set rates_cum {}\n\
17401 for {set i 0} {$i<[llength $rates]} {incr i} {\n\
17402 set temp [expr $temp + [lindex $rates $i]]\n\
17403 lappend rates_cum $temp\n\
17404 }\n\
17405 return $rates_cum\n\
17406 }\n\
17407 \n\
17408 PLM instproc choose_layer {PP_estimate_value} {\n\
17409 $self instvar subscription_ start_loss\n\
17410 global rates_cum\n\
17411 \n\
17412 set start_loss -1\n\
17413 \n\
17414 for {set i 0} {[lindex $rates_cum $i] < [expr round($PP_estimate_value)]} {incr i} {\n\
17415 if {$i > [llength $rates_cum]} {break}\n\
17416 }\n\
17417 \n\
17418 if {$subscription_ < $i} {\n\
17419 for {set j $subscription_} {$j < $i} {incr j} {\n\
17420 $self add-layer     \n\
17421 }       \n\
17422 } elseif {$subscription_ > $i} {\n\
17423 for {set j $subscription_} {$i < $j} {incr j -1} {\n\
17424 $self drop-layer        \n\
17425 }\n\
17426 } elseif {$subscription_ == $i} {\n\
17427 return\n\
17428 }\n\
17429 }\n\
17430 \n\
17431 \n\
17432 PLM instproc log-loss {} {\n\
17433 $self instvar subscription_ h_npkts h_nlost start_loss debug_\n\
17434 $self instvar time_loss ns_ wait_loss\n\
17435 \n\
17436 $self debug \"LOSS [$self plm_loss]\" \n\
17437 \n\
17438 if {$debug_>=2} {\n\
17439 trace_annotate \"$self pkt_lost\"\n\
17440 }\n\
17441 set ns_time [$ns_ now]\n\
17442 \n\
17443 \n\
17444 if {$time_loss <= $ns_time} {\n\
17445 if {$debug_>=2} {\n\
17446 trace_annotate \"not enough losses during 1s: reinitialize\"\n\
17447 }\n\
17448 set start_loss -1\n\
17449 }\n\
17450 \n\
17451 if {($start_loss == -1) || ($wait_loss >= $ns_time)} {\n\
17452 if {$debug_>=2} {\n\
17453 trace_annotate \"$start_loss [expr $wait_loss >= $ns_time] reinitialize\"\n\
17454 }\n\
17455 set h_npkts [$self plm_pkts]\n\
17456 set h_nlost [$self plm_loss]\n\
17457 set start_loss 1\n\
17458 set time_loss [expr [$ns_ now] + 5]\n\
17459 if {$debug_>=2} {\n\
17460 trace_annotate \"time_loss : $time_loss\"\n\
17461 }\n\
17462 }\n\
17463 \n\
17464 if {([$self exceed_loss_thresh]) && ($wait_loss <= $ns_time)} {\n\
17465 $self drop-layer\n\
17466 set start_loss -1\n\
17467 set wait_loss [expr $ns_time + 0.5]\n\
17468 if {$debug_>=2} {\n\
17469 trace_annotate \"drop layer wait_loss: $wait_loss\"\n\
17470 }\n\
17471 }\n\
17472 }\n\
17473 \n\
17474 PLM instproc exceed_loss_thresh {} {\n\
17475 $self instvar h_npkts h_nlost debug_\n\
17476 set npkts [expr [$self plm_pkts] - $h_npkts]\n\
17477 if { $npkts >= 10 } {\n\
17478 set nloss [expr [$self plm_loss] - $h_nlost]\n\
17479 set loss [expr double($nloss) / ($nloss + $npkts)]\n\
17480 $self debug \"H-THRESH $nloss $npkts $loss\"\n\
17481 if { $loss > 0.10 } {\n\
17482 return 1\n\
17483 }\n\
17484 }\n\
17485 return 0\n\
17486 }\n\
17487 \n\
17488 \n\
17489 PLM instproc drop-layer {} {\n\
17490 $self instvar subscription_ layer_ node_id debug_\n\
17491 set n $subscription_\n\
17492 \n\
17493 if { $n > 0 } {\n\
17494 $self debug \"DRP-LAYER $n\"\n\
17495 $layer_($n) leave-group \n\
17496 incr n -1\n\
17497 set subscription_ $n\n\
17498 if {$debug_>=2} {\n\
17499 trace_annotate \" [$self set node_id] : change layer $subscription_ \"\n\
17500 }\n\
17501 }\n\
17502 \n\
17503 if { $subscription_ == 0 } {\n\
17504 set ns [Simulator instance]\n\
17505 set rejoin_timer 30\n\
17506 $ns at [expr [$ns now] + $rejoin_timer] \"$self add-layer\"\n\
17507 if {$debug_>=2} {\n\
17508 trace_annotate \" Try to re-join the session after dropping all the layers \"\n\
17509 }\n\
17510 }\n\
17511 }\n\
17512 \n\
17513 PLM instproc add-layer {} {\n\
17514 $self instvar maxlevel_ subscription_ layer_ node_id debug_\n\
17515 set n $subscription_\n\
17516 if { $n < $maxlevel_ } {\n\
17517 $self debug \"ADD-LAYER\"\n\
17518 incr n\n\
17519 set subscription_ $n\n\
17520 $layer_($n) join-group\n\
17521 if {$debug_>=2} {\n\
17522 trace_annotate \" [$self set node_id] : change layer $subscription_ \"\n\
17523 }\n\
17524 }\n\
17525 }\n\
17526 \n\
17527 PLM instproc plm_loss {} {\n\
17528 $self instvar layers_\n\
17529 set loss 0\n\
17530 foreach l $layers_ {\n\
17531 incr loss [$l nlost]\n\
17532 }\n\
17533 return $loss\n\
17534 }\n\
17535 \n\
17536 PLM instproc plm_pkts {} {\n\
17537 $self instvar layers_\n\
17538 set npkts 0\n\
17539 foreach l $layers_ {\n\
17540 incr npkts [$l npkts]\n\
17541 }\n\
17542 return $npkts\n\
17543 }\n\
17544 \n\
17545 PLM instproc debug { msg } {\n\
17546 $self instvar debug_ subscription_ ns_\n\
17547 \n\
17548 if {$debug_ <1} { return }\n\
17549 set time [format %.05f [$ns_ now]]\n\
17550 puts stderr \"PLM: $time  layer $subscription_ $msg\"\n\
17551 }\n\
17552 \n\
17553 Class PLMLayer\n\
17554 \n\
17555 PLMLayer instproc init { plm } {\n\
17556 $self next\n\
17557 \n\
17558 $self instvar plm_ npkts_\n\
17559 set plm_ $plm\n\
17560 set npkts_ 0\n\
17561 }\n\
17562 \n\
17563 PLMLayer instproc join-group {} {\n\
17564 $self instvar npkts_ add_time_ plm_\n\
17565 set npkts_ [$self npkts]\n\
17566 set add_time_ [$plm_ now]\n\
17567 }\n\
17568 \n\
17569 PLMLayer instproc leave-group {} {\n\
17570 }\n\
17571 \n\
17572 PLMLayer instproc getting-pkts {} {\n\
17573 $self instvar npkts_\n\
17574 return [expr [$self npkts] != $npkts_]\n\
17575 }\n\
17576 \n\
17577 \n\
17578 Application/Traffic/CBR_PP instproc set args {\n\
17579 $self instvar packet_size_ rate_ \n\
17580 if { [lindex $args 0] == \"interval_\" } {\n\
17581 puts \"Cannot use CBR_PP with interval_, specify rate_ instead\"\n\
17582 }\n\
17583 eval $self next $args\n\
17584 }\n\
17585 \n\
17586 Agent/LossMonitor/PLM instproc log-PP {} {\n\
17587 }\n\
17588 \n\
17589 Class PLMLossTrace -superclass Agent/LossMonitor/PLM\n\
17590 PLMLossTrace set expected_ -1\n\
17591 \n\
17592 PLMLossTrace instproc init {} {\n\
17593 $self next\n\
17594 $self instvar lastTime measure debug_\n\
17595 set lastTime 0\n\
17596 set measure -1\n\
17597 global plm_debug_flag\n\
17598 if [info exists plm_debug_flag] {\n\
17599 set debug_ $plm_debug_flag\n\
17600 }\n\
17601 }\n\
17602 \n\
17603 PLMLossTrace instproc log-loss {} {\n\
17604 $self instvar plm_\n\
17605 $plm_ log-loss\n\
17606 }\n\
17607 \n\
17608 \n\
17609 PLMLossTrace instproc log-PP {} {\n\
17610 $self instvar plm_ PP_first measure next_pkt debug_\n\
17611 global PP_burst_length packetSize\n\
17612 \n\
17613 if {[$self set flag_PP_] == 128} {\n\
17614 set measure 1\n\
17615 set next_pkt [expr [$self set seqno_] + 1]\n\
17616 set PP_first [$self set packet_time_PP_]\n\
17617 if {$debug_>=2} {\n\
17618 trace_annotate \"[$plm_ node]:  first PP [$self set seqno_], next: $next_pkt\"\n\
17619 }   \n\
17620 } elseif {$measure>-1} {\n\
17621 if {[$self set seqno_]==$next_pkt} {\n\
17622 set measure [expr $measure + 1]\n\
17623 set next_pkt [expr [$self set seqno_] + 1]  \n\
17624 if {$debug_>=2} {\n\
17625 trace_annotate \"[$plm_ node]:   pending measurement : $measure, next $next_pkt\"\n\
17626 }\n\
17627 if {$measure==$PP_burst_length} {\n\
17628 set PP_value [expr $packetSize*8.*($PP_burst_length - 1)/([$self set packet_time_PP_] - $PP_first)]\n\
17629 set measure -1\n\
17630 if {$debug_>=2} {\n\
17631 trace_annotate \"[$plm_ node]:  measure : $PP_value\"\n\
17632 }\n\
17633 $plm_ make_estimate $PP_value\n\
17634 } \n\
17635 } else {\n\
17636 if {$debug_>=2} {\n\
17637 trace_annotate \"[$plm_ node]:  out of sequence : [$self set seqno_], next: $next_pkt\"\n\
17638 }\n\
17639 set measure -1\n\
17640 }\n\
17641 }\n\
17642 }\n\
17643 \n\
17644 \n\
17645 \n\
17646 \n\
17647 Class PLMLayer/ns -superclass PLMLayer\n\
17648 \n\
17649 PLMLayer/ns instproc init {ns plm addr layerNo} {\n\
17650 $self next $plm\n\
17651 \n\
17652 $self instvar ns_ addr_ mon_\n\
17653 set ns_ $ns\n\
17654 set addr_ $addr\n\
17655 set mon_ [$ns_ PLMcreate-agent [$plm node] PLMLossTrace 0]\n\
17656 $mon_ set layerNo $layerNo\n\
17657 $mon_ set plm_ $plm\n\
17658 $mon_ set dst_addr_ $addr\n\
17659 $mon_ set dst_port_ 0\n\
17660 }\n\
17661 \n\
17662 PLMLayer/ns instproc join-group {} {\n\
17663 $self instvar mon_ plm_ addr_\n\
17664 $mon_ clear\n\
17665 [$plm_ node] join-group $mon_ $addr_\n\
17666 $self next\n\
17667 }\n\
17668 \n\
17669 PLMLayer/ns instproc leave-group {} {\n\
17670 $self instvar mon_ plm_ addr_\n\
17671 [$plm_ node] leave-group $mon_ $addr_\n\
17672 $self next\n\
17673 }\n\
17674 \n\
17675 PLMLayer/ns instproc npkts {} {\n\
17676 $self instvar mon_\n\
17677 return [$mon_ set npkts_]\n\
17678 }\n\
17679 \n\
17680 PLMLayer/ns instproc nlost {} {\n\
17681 $self instvar mon_\n\
17682 return [$mon_ set nlost_]\n\
17683 }\n\
17684 \n\
17685 PLMLayer/ns instproc mon {} {\n\
17686 $self instvar mon_\n\
17687 return $mon_\n\
17688 }\n\
17689 \n\
17690 Class PLM/ns -superclass PLM\n\
17691 \n\
17692 PLM/ns instproc init {ns localNode addrs check_estimate nn} {\n\
17693 $self instvar ns_ node_ addrs_\n\
17694 set ns_ $ns\n\
17695 set node_ $localNode\n\
17696 set addrs_ $addrs\n\
17697 \n\
17698 $self next [llength $addrs] $check_estimate $nn\n\
17699 }\n\
17700 \n\
17701 PLM/ns instproc create-layer {layerNo} {\n\
17702 $self instvar ns_ addrs_\n\
17703 return [new PLMLayer/ns $ns_ $self [lindex $addrs_ $layerNo] $layerNo]\n\
17704 }\n\
17705 \n\
17706 PLM/ns instproc now {} {\n\
17707 $self instvar ns_\n\
17708 return [$ns_ now]\n\
17709 }\n\
17710 \n\
17711 \n\
17712 \n\
17713 \n\
17714 \n\
17715 PLM/ns instproc node {} {\n\
17716 $self instvar node_\n\
17717 return $node_\n\
17718 }\n\
17719 \n\
17720 PLM/ns instproc debug { msg } {\n\
17721 $self instvar debug_ ns_\n\
17722 if {$debug_ <1} { return }\n\
17723 \n\
17724 $self instvar subscription_ node_\n\
17725 set time [format %.05f [$ns_ now]]\n\
17726 }\n\
17727 \n\
17728 PLM/ns instproc trace { trace } {\n\
17729 $self instvar layers_\n\
17730 foreach s $layers_ {\n\
17731 [$s mon] trace $trace\n\
17732 }\n\
17733 }\n\
17734 \n\
17735 \n\
17736 PLM/ns instproc total_bytes_delivered {} {\n\
17737 $self instvar layers_\n\
17738 set v 0\n\
17739 foreach s $layers_ {\n\
17740 incr v [[$s mon] set bytes]\n\
17741 }\n\
17742 return $v\n\
17743 }\n\
17744 \n\
17745 \n\
17746 \n\
17747 Simulator instproc PLMcreate-agent { node type pktClass } {\n\
17748 $self instvar Agents PortID \n\
17749 set agent [new $type]\n\
17750 $agent set fid_ $pktClass\n\
17751 $self attach-agent $node $agent\n\
17752 $agent proc get var {\n\
17753 return [$self set $var]\n\
17754 }\n\
17755 return $agent\n\
17756 }\n\
17757 \n\
17758 \n\
17759 Simulator instproc PLMcbr_flow_PP { node fid addr bw } {\n\
17760 global packetSize PP_burst_length\n\
17761 set agent [$self PLMcreate-agent $node Agent/UDP $fid]\n\
17762 set cbr [new Application/Traffic/CBR_PP]\n\
17763 $cbr attach-agent $agent\n\
17764 \n\
17765 $agent set dst_addr_ $addr\n\
17766 $agent set dst_port_ 0\n\
17767 \n\
17768 $cbr set packet_size_ $packetSize\n\
17769 $cbr set rate_ $bw\n\
17770 $cbr set random_ 1\n\
17771 $cbr set PBM_ $PP_burst_length\n\
17772 return $cbr\n\
17773 }\n\
17774 \n\
17775 \n\
17776 \n\
17777 Simulator instproc PLMbuild_source_set { plmName rates addrs baseClass node when } {\n\
17778 global src_plm src_rate\n\
17779 set n [llength $rates]\n\
17780 set r [lindex $rates 0]\n\
17781 set addr [expr [lindex $addrs 0]]\n\
17782 set src_rate($addr) $r\n\
17783 set k $plmName:0\n\
17784 set src_plm($k) [$self PLMcbr_flow_PP $node $baseClass $addr $r]\n\
17785 $self at 0 \"$src_plm($k) set maxpkts_ 1; $src_plm($k) start\"\n\
17786 $self at $when \"$src_plm($k) set maxpkts_ 268435456; $src_plm($k) start\"\n\
17787 \n\
17788 for {set i 1} {$i<$n} {incr i} {\n\
17789 set r [lindex $rates $i]\n\
17790 set addr [expr [lindex $addrs $i]]\n\
17791 \n\
17792 set src_rate($addr) $r\n\
17793 set k $plmName:$i\n\
17794 set src_plm($k) [$self PLMcbr_flow_PP $node $baseClass $addr $r]\n\
17795 $self at 0 \"$src_plm($k) set maxpkts_ 1; $src_plm($k) start\"\n\
17796 $self at $when \"$src_plm($k) set maxpkts_ 268435456; $src_plm($k) start\"\n\
17797 }\n\
17798 \n\
17799 }\n\
17800 \n\
17801 Class PLMTopology\n\
17802 \n\
17803 PLMTopology instproc init { simulator } {\n\
17804 $self instvar ns id\n\
17805 set ns $simulator\n\
17806 set id 0\n\
17807 }\n\
17808 \n\
17809 PLMTopology instproc mknode nn {\n\
17810 $self instvar node ns\n\
17811 if ![info exists node($nn)] {\n\
17812 set node($nn) [$ns node]\n\
17813 }\n\
17814 }\n\
17815 \n\
17816 \n\
17817 PLMTopology instproc build_link { a b delay bw } {\n\
17818 global buffers packetSize Queue_sched_\n\
17819 if { $a == $b } {\n\
17820 puts stderr \"link from $a to $b?\"\n\
17821 exit 1\n\
17822 }\n\
17823 $self instvar node ns\n\
17824 $self mknode $a\n\
17825 $self mknode $b\n\
17826 $ns duplex-link $node($a) $node($b) $bw $delay $Queue_sched_\n\
17827 }\n\
17828 \n\
17829 PLMTopology instproc build_link-simple { a b delay bw f} {\n\
17830 global buffers packetSize Queue_sched_ \n\
17831 if { $a == $b } {\n\
17832 puts stderr \"link from $a to $b?\"\n\
17833 exit 1\n\
17834 }\n\
17835 $self instvar node ns\n\
17836 $self mknode $a\n\
17837 $self mknode $b\n\
17838 $ns duplex-link-trace $node($a) $node($b) $bw $delay $Queue_sched_ $f\n\
17839 }\n\
17840 \n\
17841 \n\
17842 \n\
17843 PLMTopology instproc place_source { nn when } {\n\
17844 global rates \n\
17845 $self instvar node ns id addrs\n\
17846 \n\
17847 incr id\n\
17848 set addrs($id) {}\n\
17849 foreach r $rates {\n\
17850 lappend addrs($id) [Node allocaddr]\n\
17851 }\n\
17852 \n\
17853 $ns PLMbuild_source_set s$id $rates $addrs($id) $id $node($nn) $when\n\
17854 \n\
17855 return $id\n\
17856 }\n\
17857 \n\
17858 PLMTopology instproc place_receiver { nn id when check_estimate {nb 1}} {\n\
17859 $self instvar ns  \n\
17860 $ns at $when \"$self build_receiver $nn $id $check_estimate $nb\"\n\
17861 }\n\
17862 \n\
17863 PLMTopology instproc build_receiver { nn id check_estimate nb} {\n\
17864 $self instvar node ns addrs\n\
17865 global PLMrcvr\n\
17866 set PLMrcvr($nb) [new PLM/ns $ns $node($nn) $addrs($id) $check_estimate $nn]\n\
17867 \n\
17868 global plm_debug_flag\n\
17869 $PLMrcvr($nb) set debug_ $plm_debug_flag\n\
17870 }\n\
17871 \n\
17872 \n\
17873 \n\
17874 \n\
17875 \n\
17876 Simulator instproc mpls-node args {\n\
17877 $self node-config -MPLS ON\n\
17878 set n [$self node]\n\
17879 $self node-config -MPLS OFF\n\
17880 return $n\n\
17881 }\n\
17882 \n\
17883 Simulator instproc LDP-peer { src dst } {\n\
17884 if { ![$src is-neighbor $dst] } {\n\
17885 return\n\
17886 }\n\
17887 set ldpsrc [[$src get-module \"MPLS\"] make-ldp]\n\
17888 set ldpdst [[$dst get-module \"MPLS\"] make-ldp]\n\
17889 $ldpsrc set-peer [$dst id]\n\
17890 $ldpdst set-peer [$src id]\n\
17891 $self connect $ldpsrc $ldpdst\n\
17892 }\n\
17893 \n\
17894 Simulator instproc ldp-notification-color {color} {\n\
17895 $self color 101 $color\n\
17896 }\n\
17897 \n\
17898 Simulator instproc ldp-request-color {color} {\n\
17899 $self color 102 $color\n\
17900 }\n\
17901 \n\
17902 Simulator instproc ldp-mapping-color {color} {\n\
17903 $self color 103 $color\n\
17904 }\n\
17905 \n\
17906 Simulator instproc ldp-withdraw-color {color} {\n\
17907 $self color 104 $color\n\
17908 }\n\
17909 \n\
17910 Simulator instproc ldp-release-color {color} {\n\
17911 $self color 105 $color\n\
17912 }\n\
17913 \n\
17914 \n\
17915 \n\
17916 RtModule/MPLS instproc register { node } {\n\
17917 $self instvar classifier_\n\
17918 $self attach-node $node\n\
17919 $node route-notify $self\n\
17920 $node port-notify $self\n\
17921 set classifier_ [new Classifier/Addr/MPLS]\n\
17922 $classifier_ set-node $node $self\n\
17923 $node install-entry $self $classifier_ 0\n\
17924 $self attach-classifier $classifier_\n\
17925 }\n\
17926 \n\
17927 \n\
17928 \n\
17929 \n\
17930 RtModule/MPLS instproc enable-data-driven {} {\n\
17931 [$self set classifier_] cmd enable-data-driven\n\
17932 }\n\
17933 \n\
17934 RtModule/MPLS instproc enable-control-driven {} {\n\
17935 [$self set classifier_] cmd enable-control-driven\n\
17936 }\n\
17937 \n\
17938 RtModule/MPLS instproc make-ldp {} {\n\
17939 set ldp [new Agent/LDP]\n\
17940 $self cmd attach-ldp $ldp\n\
17941 $ldp set-mpls-module $self\n\
17942 [$self node] attach $ldp\n\
17943 return $ldp\n\
17944 }\n\
17945 \n\
17946 RtModule/MPLS instproc exist-fec {fec phb} {\n\
17947 return [[$self set classifier_] exist-fec $fec $phb]\n\
17948 }\n\
17949 \n\
17950 RtModule/MPLS instproc get-incoming-iface {fec lspid} {\n\
17951 return [[$self set classifier_] GetInIface $fec $lspid]\n\
17952 }\n\
17953 \n\
17954 RtModule/MPLS instproc get-incoming-label {fec lspid} {\n\
17955 return [[$self set classifier_] GetInLabel $fec $lspid]\n\
17956 }\n\
17957 \n\
17958 RtModule/MPLS instproc get-outgoing-label {fec lspid} {\n\
17959 return [[$self set classifier_] GetOutLabel $fec $lspid]\n\
17960 }\n\
17961 \n\
17962 RtModule/MPLS instproc get-outgoing-iface {fec lspid} {\n\
17963 return [[$self set classifier_] GetOutIface $fec $lspid]\n\
17964 }\n\
17965 \n\
17966 RtModule/MPLS instproc get-fec-for-lspid {lspid} {\n\
17967 return [[$self set classifier_] get-fec-for-lspid $lspid]\n\
17968 }\n\
17969 \n\
17970 RtModule/MPLS instproc in-label-install {fec lspid iface label} {\n\
17971 set dontcare [Classifier/Addr/MPLS dont-care]\n\
17972 $self label-install $fec $lspid $iface $label $dontcare $dontcare\n\
17973 }\n\
17974 \n\
17975 RtModule/MPLS instproc out-label-install {fec lspid iface label} {\n\
17976 set dontcare [Classifier/Addr/MPLS dont-care]\n\
17977 $self label-install $fec $lspid $dontcare $dontcare $iface $label\n\
17978 }\n\
17979 \n\
17980 RtModule/MPLS instproc in-label-clear {fec lspid} {\n\
17981 set dontcare [Classifier/Addr/MPLS dont-care]\n\
17982 $self label-clear $fec $lspid -1 -1 $dontcare $dontcare\n\
17983 }\n\
17984 \n\
17985 RtModule/MPLS instproc out-label-clear {fec lspid} {\n\
17986 set dontcare [Classifier/Addr/MPLS dont-care]\n\
17987 $self label-clear $fec $lspid $dontcare $dontcare -1 -1\n\
17988 }\n\
17989 \n\
17990 RtModule/MPLS instproc label-install {fec lspid iif ilbl oif olbl} {\n\
17991 [$self set classifier_] LSPsetup $fec $lspid $iif $ilbl $oif $olbl\n\
17992 }\n\
17993 \n\
17994 RtModule/MPLS instproc label-clear {fec lspid iif ilbl oif olbl} {\n\
17995 [$self set classifier_] LSPrelease $fec $lspid $iif $ilbl $oif $olbl\n\
17996 }\n\
17997 \n\
17998 RtModule/MPLS instproc flow-erlsp-install {fec phb lspid} {\n\
17999 [$self set classifier_] ErLspBinding $fec $phb $lspid\n\
18000 }\n\
18001 \n\
18002 RtModule/MPLS instproc erlsp-stacking {erlspid tunnelid} {\n\
18003 [$self set classifier_] ErLspStacking -1 $erlspid -1 $tunnelid\n\
18004 }\n\
18005 \n\
18006 RtModule/MPLS instproc flow-aggregation {fineFec finePhb coarseFec coarsePhb} {\n\
18007 [$self set classifier_] FlowAggregation $fineFec $finePhb $coarseFec \\\n\
18008 $coarsePhb\n\
18009 }\n\
18010 \n\
18011 RtModule/MPLS instproc enable-reroute {option} {\n\
18012 $self instvar classifier_ \n\
18013 $classifier_ set enable_reroute_ 1\n\
18014 if {$option == \"drop\"} {\n\
18015 $classifier_ set reroute_option_ 0\n\
18016 } elseif {$option == \"L3\"} {\n\
18017 $classifier_ set reroute_option_ 1\n\
18018 } elseif {$option == \"new\"} {\n\
18019 $classifier_ set reroute_option_ 2\n\
18020 } else {\n\
18021 $classifier_ set reroute_option_ 0\n\
18022 }\n\
18023 }\n\
18024 \n\
18025 RtModule/MPLS instproc reroute-binding {fec phb lspid} {\n\
18026 [$self set classifier_] aPathBinding $fec $phb -1 $lspid\n\
18027 }\n\
18028 \n\
18029 RtModule/MPLS instproc lookup-nexthop {node fec} {\n\
18030 set ns [Simulator instance]\n\
18031 set routingtable [$ns get-routelogic]\n\
18032 set nexthop [$routingtable lookup $node $fec]\n\
18033 return $nexthop\n\
18034 }\n\
18035 \n\
18036 RtModule/MPLS instproc get-nexthop {fec} {\n\
18037 set nodeid [[$self node] id]\n\
18038 set nexthop [$self lookup-nexthop $nodeid $fec]\n\
18039 return $nexthop\n\
18040 }\n\
18041 \n\
18042 RtModule/MPLS instproc get-link-status {hop} {\n\
18043 if {$hop < 0} {\n\
18044 return \"down\"\n\
18045 }\n\
18046 set nexthop [$self get-nexthop $hop]\n\
18047 if {$nexthop == $hop} {\n\
18048 set status \"up\"\n\
18049 } else {\n\
18050 set status \"down\"\n\
18051 }\n\
18052 return $status\n\
18053 }\n\
18054 \n\
18055 RtModule/MPLS instproc is-egress-lsr { fec } {\n\
18056 if { [[$self node] id] == $fec } {\n\
18057 return  \"1\"\n\
18058 }\n\
18059 set nexthopid [$self get-nexthop $fec]\n\
18060 if { $nexthopid < 0 } {\n\
18061 return \"-1\"\n\
18062 }\n\
18063 set nexthop [[Simulator instance] get-node-by-id $nexthopid]\n\
18064 if { [$nexthop get-module \"MPLS\"] == \"\" } {\n\
18065 return  \"1\"\n\
18066 } else {\n\
18067 return  \"-1\"\n\
18068 }\n\
18069 }\n\
18070 \n\
18071 RtModule/MPLS instproc ldp-trigger-by-routing-table {} {\n\
18072 if { [[$self set classifier_] cmd control-driven?] != 1 } {\n\
18073 return\n\
18074 }\n\
18075 set ns [Simulator instance]\n\
18076 for {set i 0} {$i < [$ns get-number-of-nodes]} {incr i} {\n\
18077 set host [$ns get-node-by-id $i]\n\
18078 if { [$self is-egress-lsr [$host id]] == 1 } {\n\
18079 $self ldp-trigger-by-control [$host id] *\n\
18080 }\n\
18081 }\n\
18082 }\n\
18083 \n\
18084 RtModule/MPLS instproc ldp-trigger-by-control {fec pathvec} {\n\
18085 lappend pathvec [[$self node] id]\n\
18086 set inlabel [$self get-incoming-label $fec -1]\n\
18087 set nexthop [$self get-nexthop $fec]\n\
18088 set ldpagents [lsort [$self get-ldp-agents]]\n\
18089 for {set i 0} {$i < [llength $ldpagents]} {incr i 1} {\n\
18090 set ldpagent [lindex $ldpagents $i]\n\
18091 if { [$ldpagent peer-ldpnode] == $nexthop } {\n\
18092 continue\n\
18093 }\n\
18094 if { $inlabel == -1 } {\n\
18095 if { [$self is-egress-lsr $fec] == 1 } {\n\
18096 set inlabel 0\n\
18097 } else {\n\
18098 set inlabel [$self new-incoming-label]\n\
18099 $self in-label-install $fec -1 -1 $inlabel\n\
18100 }\n\
18101 }\n\
18102 $ldpagent new-msgid\n\
18103 $ldpagent send-mapping-msg $fec $inlabel $pathvec -1\n\
18104 }\n\
18105 }\n\
18106 \n\
18107 RtModule/MPLS instproc ldp-trigger-by-data {reqmsgid src fec pathvec} {\n\
18108 if { [$self is-egress-lsr $fec] == 1 } {\n\
18109 return\n\
18110 }\n\
18111 set outlabel [$self get-outgoing-label $fec -1]\n\
18112 if { $outlabel > -1  } {\n\
18113 set outiface [$self get-outgoing-iface $fec -1]\n\
18114 if { [$self get-link-status $outiface] == \"up\" } {\n\
18115 return\n\
18116 }\n\
18117 }\n\
18118 lappend pathvec [[$self node] id]      \n\
18119 set nexthop [$self get-nexthop $fec]\n\
18120 set ldpagent [$self get-ldp-agent $nexthop]\n\
18121 if { $ldpagent == \"\" } {\n\
18122 return\n\
18123 }\n\
18124 if {$reqmsgid > -1} {\n\
18125 set working [$ldpagent msgtbl-get-msgid $fec -1 $src]\n\
18126 if { $working < 0 } {\n\
18127 set newmsgid [$ldpagent new-msgid]\n\
18128 $ldpagent msgtbl-install $newmsgid $fec -1 \\\n\
18129 $src $reqmsgid\n\
18130 $ldpagent send-request-msg $fec $pathvec\n\
18131 } else {\n\
18132 }\n\
18133 } else {\n\
18134 if {$fec == $nexthop} {\n\
18135 set outlabel 0\n\
18136 } else {\n\
18137 set outlabel [$self new-outgoing-label]\n\
18138 }\n\
18139 $self out-label-install $fec -1 $nexthop $outlabel\n\
18140 $ldpagent new-msgid\n\
18141 $ldpagent send-mapping-msg $fec $outlabel $pathvec -1\n\
18142 }\n\
18143 }\n\
18144 \n\
18145 RtModule/MPLS instproc make-explicit-route {fec er lspid rc} {\n\
18146 $self ldp-trigger-by-explicit-route -1 [[$self node] id] $fec \"*\" \\\n\
18147 $er $lspid $rc\n\
18148 }\n\
18149 \n\
18150 RtModule/MPLS instproc ldp-trigger-by-explicit-route {reqmsgid src fec \\\n\
18151 pathvec er lspid rc} {\n\
18152 $self instvar classifier_\n\
18153 set outlabel [$self get-outgoing-label $fec $lspid]\n\
18154 if { $outlabel > -1 } {\n\
18155 return\n\
18156 }\n\
18157 if { [[$self node] id] != $src && [[$self node] id] == $fec } {\n\
18158 set ldpagent [$self get-ldp-agent $src]\n\
18159 if { $ldpagent != \"\" } {\n\
18160 $ldpagent new-msgid\n\
18161 $ldpagent send-cr-mapping-msg $fec 0 $lspid $reqmsgid\n\
18162 }\n\
18163 return\n\
18164 }\n\
18165 lappend pathvec [[$self node] id]\n\
18166 set er [split $er \"_\"]\n\
18167 set erlen [llength $er]\n\
18168 for {set i 0} {$i <= $erlen} {incr i 1} {\n\
18169 if { $i != $erlen } {\n\
18170 set erhop [lindex $er $i]\n\
18171 } else {\n\
18172 set erhop $fec\n\
18173 }\n\
18174 set stackERhop -1\n\
18175 if { $erhop >= [Classifier/Addr/MPLS minimum-lspid] } {\n\
18176 set lspidFEC [$self get-fec-for-lspid $erhop]\n\
18177 set inlabel  [$self get-incoming-label -1 $erhop]\n\
18178 set outlabel [$self get-outgoing-label -1 $erhop]\n\
18179 if { $lspidFEC == $fec } {\n\
18180 if { $outlabel <= -1 } {\n\
18181 continue\n\
18182 }\n\
18183 if { $inlabel < 0 } {\n\
18184 set inlabel [$self new-incoming-label]\n\
18185 $self in-label-install -1 $erhop \\\n\
18186 $src $inlabel\n\
18187 }\n\
18188 set ldpagent [$self get-ldp-agent $src]\n\
18189 $ldpagent new-msgid\n\
18190 $ldpagent send-cr-mapping-msg $fec $inlabel \\\n\
18191 $lspid $reqmsgid\n\
18192 return\n\
18193 }\n\
18194 set existExplicitPeer [$self exist-ldp-agent $lspidFEC]\n\
18195 if { $outlabel > -1 && $existExplicitPeer == \"1\" } {\n\
18196 set stackERhop $erhop \n\
18197 set erhop $lspidFEC\n\
18198 } elseif { $outlabel > -1 && $existExplicitPeer == \"0\" } {\n\
18199 set nexthop [$self get-outgoing-iface -1 \\\n\
18200 $erhop]\n\
18201 set iiface  [$self get-incoming-iface -1 \\\n\
18202 $erhop]\n\
18203 set ldpagent [$self get-ldp-agent $nexthop]\n\
18204 set working [$ldpagent msgtbl-get-msgid $fec \\\n\
18205 $lspid $src]\n\
18206 if { $working < 0 } {\n\
18207 set newmsgid [$ldpagent new-msgid]\n\
18208 $ldpagent msgtbl-install $newmsgid \\\n\
18209 $fec $lspid $src $reqmsgid\n\
18210 if {($iiface == $src) && \\\n\
18211 ($inlabel > -1) } {\n\
18212 $ldpagent msgtbl-set-labelpass $newmsgid\n\
18213 } else {\n\
18214 $ldpagent msgtbl-set-labelstack $newmsgid $erhop\n\
18215 }\n\
18216 $ldpagent send-cr-request-msg $fec \\\n\
18217 $pathvec $er $lspid $rc\n\
18218 }\n\
18219 return\n\
18220 } else {\n\
18221 continue\n\
18222 }\n\
18223 }\n\
18224 if { [lsearch $pathvec $erhop] < 0 } {\n\
18225 set nexthop [$self get-nexthop $erhop]\n\
18226 if { [$self is-egress-lsr $nexthop] == 1 } {\n\
18227 set ldpagent [$self get-ldp-agent $src]\n\
18228 if { $erhop == $fec } {\n\
18229 $ldpagent new-msgid\n\
18230 $ldpagent send-cr-mapping-msg $fec 0 \\\n\
18231 $lspid $reqmsgid\n\
18232 } else {\n\
18233 $ldpagent new-msgid\n\
18234 $ldpagent send-notification-msg \\\n\
18235 \"NoRoute\" $lspid\n\
18236 }\n\
18237 } else {\n\
18238 set ldpagent [$self get-ldp-agent $nexthop]\n\
18239 set working [$ldpagent msgtbl-get-msgid $fec \\\n\
18240 $lspid $src]\n\
18241 if { $working < 0 } {\n\
18242 set newmsgid [$ldpagent new-msgid]\n\
18243 set id [$ldpagent msgtbl-install \\\n\
18244 $newmsgid $fec \\\n\
18245 $lspid $src $reqmsgid]\n\
18246 if { $stackERhop > -1 } {\n\
18247 $ldpagent msgtbl-set-labelstack $newmsgid $stackERhop\n\
18248 }\n\
18249 $ldpagent send-cr-request-msg $fec $pathvec $er $lspid $rc\n\
18250 }\n\
18251 } \n\
18252 return\n\
18253 }\n\
18254 }\n\
18255 set ldpagent [$self get-ldp-agent $src]\n\
18256 if { $ldpagent != \"\" } {\n\
18257 $ldpagent new-msgid\n\
18258 $ldpagent send-notification-msg \"NoRoute\" $lspid\n\
18259 }\n\
18260 }\n\
18261 \n\
18262 RtModule/MPLS instproc ldp-trigger-by-withdraw {fec lspid} {\n\
18263 set inlabel  [$self get-incoming-label $fec $lspid]\n\
18264 set iniface  [$self get-incoming-iface $fec $lspid]\n\
18265 \n\
18266 $self in-label-clear $fec $lspid\n\
18267 \n\
18268 if {$iniface > -1} {\n\
18269 set ldpagent [$self get-ldp-agent $iniface]\n\
18270 if { $ldpagent != \"\" } {\n\
18271 $ldpagent new-msgid\n\
18272 $ldpagent send-withdraw-msg $fec $lspid\n\
18273 }\n\
18274 } else {\n\
18275 set nexthop [$self get-nexthop $fec]\n\
18276 set ldpagents [lsort [$self get-ldp-agents]]\n\
18277 for {set i 0} {$i < [llength $ldpagents]} {incr i 1} {\n\
18278 set ldpagent [lindex $ldpagents $i]\n\
18279 if { [$ldpagent peer-ldpnode] == $nexthop } {\n\
18280 continue\n\
18281 }\n\
18282 $ldpagent new-msgid\n\
18283 $ldpagent send-withdraw-msg $fec $lspid\n\
18284 }\n\
18285 }   \n\
18286 }\n\
18287 \n\
18288 RtModule/MPLS instproc ldp-trigger-by-release {fec lspid} {\n\
18289 set outlabel  [$self get-outgoing-label $fec $lspid]\n\
18290 if {$outlabel < 0} {\n\
18291 return\n\
18292 }\n\
18293 set nexthop [$self get-outgoing-iface $fec $lspid]\n\
18294 $self out-label-clear $fec $lspid \n\
18295 set ldpagent [$self get-ldp-agent $nexthop]\n\
18296 if { $ldpagent != \"\" } {\n\
18297 $ldpagent new-msgid\n\
18298 $ldpagent send-release-msg $fec $lspid\n\
18299 }   \n\
18300 }\n\
18301 \n\
18302 \n\
18303 RtModule/MPLS instproc trace-mpls {} {\n\
18304 [$self set classifier_] set trace_mpls_ 1\n\
18305 }\n\
18306 \n\
18307 RtModule/MPLS instproc pft-dump {} {\n\
18308 set nodeid [[$self node] id]\n\
18309 [$self set classifier_] PFTdump $nodeid\n\
18310 }\n\
18311 \n\
18312 RtModule/MPLS instproc erb-dump {} {\n\
18313 set nodeid [[$self node] id]\n\
18314 [$self set classifier_] ERBdump $nodeid\n\
18315 }\n\
18316 \n\
18317 RtModule/MPLS instproc lib-dump {} {\n\
18318 set nodeid [[$self node] id]\n\
18319 [$self set classifier_] LIBdump $nodeid\n\
18320 }\n\
18321 \n\
18322 \n\
18323 \n\
18324 \n\
18325 \n\
18326 Agent/LDP instproc set-mpls-module { mod } {\n\
18327 $self set module_ $mod\n\
18328 }\n\
18329 \n\
18330 Agent/LDP instproc get-request-msg {msgid src fec pathvec} {\n\
18331 $self instvar node_ module_\n\
18332 \n\
18333 set pathvec [split $pathvec \"_\"]\n\
18334 if {[lsearch $pathvec [$node_ id]] > -1} {\n\
18335 set ldpagent [$module_ get-ldp-agent $src]\n\
18336 $ldpagent new-msgid\n\
18337 $ldpagent send-notification-msg \"LoopDetected\" -1           \n\
18338 \n\
18339 return\n\
18340 }\n\
18341 \n\
18342 set nexthop [$module_ get-nexthop $fec]\n\
18343 if {$src == $nexthop} {\n\
18344 $self request-msg-from-downstream $msgid $src $fec $pathvec\n\
18345 } else {\n\
18346 $self request-msg-from-upstream $msgid $src $fec $pathvec\n\
18347 }\n\
18348 }\n\
18349 \n\
18350 Agent/LDP instproc request-msg-from-downstream {msgid src fec pathvec} {\n\
18351 $self instvar module_\n\
18352 \n\
18353 set outlabel [$module_ get-outgoing-label $fec -1]\n\
18354 if { $outlabel < 0 } {\n\
18355 if { $fec == $src } {\n\
18356 set outlabel 0\n\
18357 } else {\n\
18358 set outlabel [$module_ new-outgoing-label]\n\
18359 }     \n\
18360 $module_ out-label-install $fec -1 $src $outlabel             \n\
18361 } else {\n\
18362 set outIface [$module_ get-outgoing-iface $fec -1]\n\
18363 if { $src != $outIface} {\n\
18364 $module_ out-label-install $fec -1 $src $outlabel\n\
18365 } \n\
18366 }\n\
18367 \n\
18368 set ldpagent [$module_ get-ldp-agent $src]\n\
18369 $ldpagent new-msgid\n\
18370 $ldpagent send-mapping-msg $fec $outlabel \"*\" $msgid\n\
18371 \n\
18372 $module_ ldp-trigger-by-control $fec $pathvec\n\
18373 }\n\
18374 \n\
18375 Agent/LDP instproc request-msg-from-upstream {msgid src fec pathvec} {\n\
18376 $self instvar module_\n\
18377 \n\
18378 set ldpagent [$module_ get-ldp-agent $src]\n\
18379 \n\
18380 if { [$module_ is-egress-lsr $fec] == 1 } {\n\
18381 $ldpagent new-msgid\n\
18382 $ldpagent send-mapping-msg $fec 0 \"*\" $msgid\n\
18383 return\n\
18384 }\n\
18385 \n\
18386 set inlabel  [$module_ get-incoming-label $fec -1]\n\
18387 set outlabel [$module_ get-outgoing-label $fec -1]\n\
18388 if { [Classifier/Addr/MPLS ordered-control?] == 1 } {\n\
18389 if { $outlabel > -1 } {\n\
18390 if { $inlabel < 0 } {\n\
18391 set inlabel [$module_ new-incoming-label]\n\
18392 }\n\
18393 $ldpagent new-msgid\n\
18394 $ldpagent send-mapping-msg $fec inlabel \"*\" $msgid\n\
18395 } else {\n\
18396 $module_ ldp-trigger-by-data $msgid $src $fec $pathvec\n\
18397 }\n\
18398 return\n\
18399 }\n\
18400 if { $inlabel < 0 } {\n\
18401 set inlabel [$module_ new-incoming-label]\n\
18402 $module_ in-label-install $fec -1 $src $inlabel\n\
18403 } else {\n\
18404 set inIface [$module_ get-incoming-iface $fec -1]\n\
18405 if { $src != $inIface} {\n\
18406 set classifier [$module_ set classifier_]\n\
18407 set dontcare [$classifier set dont_care_]\n\
18408 $module_ in-label-install $fec -1 -1 $dontcare\n\
18409 } \n\
18410 }\n\
18411 $ldpagent new-msgid\n\
18412 $ldpagent send-mapping-msg $fec $inlabel \"*\" $msgid\n\
18413 $module_ ldp-trigger-by-data $msgid $src $fec $pathvec\n\
18414 }\n\
18415 \n\
18416 Agent/LDP instproc get-cr-request-msg {msgid src fec pathvec er lspid rc} {\n\
18417 $self instvar node_ module_\n\
18418 \n\
18419 set pathvec [split $pathvec \"_\"]\n\
18420 if {[lsearch $pathvec [$node_ id]] > -1} {\n\
18421 set ldpagent [$module_ get-ldp-agent $src]\n\
18422 $ldpagent new-msgid\n\
18423 $ldpagent send-notification-msg \"NoRoute\" $lspid\n\
18424 return\n\
18425 }\n\
18426 \n\
18427 \n\
18428 set ldpagent [$module_ get-ldp-agent $src]\n\
18429 \n\
18430 set inlabel [$module_ get-incoming-label $fec $lspid]\n\
18431 set outlabel [$module_ get-outgoing-label $fec $lspid]\n\
18432 \n\
18433 if { $outlabel > -1 } {\n\
18434 if { $inlabel < 0 } {\n\
18435 set inlabel [$module_ new-incoming-label]\n\
18436 $module_ in-label-install $fec $lspid $src $inlabel\n\
18437 }\n\
18438 $ldpagent new-msgid\n\
18439 $ldpagent send-cr-mapping-msg $fec $inlabel $lspid $msgid\n\
18440 return\n\
18441 }\n\
18442 \n\
18443 $module_ ldp-trigger-by-explicit-route $msgid $src $fec $pathvec $er \\\n\
18444 $lspid $rc\n\
18445 }\n\
18446 \n\
18447 Agent/LDP instproc get-cr-mapping-msg {msgid src fec label lspid reqmsgid} {\n\
18448 $self instvar node_ trace_ldp_ module_\n\
18449 \n\
18450 \n\
18451 set prvsrc   [$self msgtbl-get-src       $reqmsgid]\n\
18452 set prvmsgid [$self msgtbl-get-reqmsgid  $reqmsgid]\n\
18453 set labelop  [$self msgtbl-get-labelop   $reqmsgid]\n\
18454 if {$labelop == 2} {\n\
18455 set tunnelid [$self msgtbl-get-erlspid   $reqmsgid]\n\
18456 } else {\n\
18457 set tunnelid -1\n\
18458 }\n\
18459 \n\
18460 $self msgtbl-clear $reqmsgid\n\
18461 \n\
18462 if { $trace_ldp_ } {\n\
18463 puts \"$src -> [$node_ id] : prvsrc($prvsrc)\"\n\
18464 }\n\
18465 \n\
18466 if { $labelop == 2 } {\n\
18467 $module_ out-label-install $fec $lspid $src $label\n\
18468 $module_ erlsp-stacking $lspid $tunnelid\n\
18469 } elseif {$labelop == 1} {\n\
18470 set ldpagent [$module_ get-ldp-agent $prvsrc]\n\
18471 $ldpagent new-msgid\n\
18472 $ldpagent send-cr-mapping-msg $fec $label $lspid $prvmsgid\n\
18473 return\n\
18474 } else {\n\
18475 $module_ out-label-install $fec $lspid  $src $label\n\
18476 }\n\
18477 \n\
18478 if {$prvsrc == [$node_ id]} {\n\
18479 return\n\
18480 }\n\
18481 \n\
18482 set inlabel [$module_ new-incoming-label]\n\
18483 $module_ in-label-install $fec $lspid $prvsrc $inlabel\n\
18484 \n\
18485 set ldpagent [$module_ get-ldp-agent $prvsrc]\n\
18486 $ldpagent new-msgid\n\
18487 $ldpagent send-cr-mapping-msg $fec $inlabel $lspid $prvmsgid\n\
18488 }\n\
18489 \n\
18490 Agent/LDP instproc get-mapping-msg {msgid src fec label pathvec reqmsgid} {\n\
18491 $self instvar node_ trace_ldp_ module_\n\
18492 \n\
18493 if { $trace_ldp_ } {\n\
18494 puts \"[[Simulator instance] now]: <mapping-msg> $src ->\\\n\
18495 [$node_ id] : fec($fec), label($label) [$module_ get-nexthop $fec]\"\n\
18496 }\n\
18497 \n\
18498 set pathvec [split $pathvec \"_\"]\n\
18499 if {[lsearch $pathvec [$node_ id]] > -1} {\n\
18500 set ldpagent [$module_ get-ldp-agent $src]\n\
18501 $ldpagent new-msgid\n\
18502 $ldpagent send-notification-msg \"LoopDetected\" -1           \n\
18503 return\n\
18504 }\n\
18505 \n\
18506 set nexthop [$module_ get-nexthop $fec]\n\
18507 if {$src == $nexthop} {\n\
18508 $self mapping-msg-from-downstream $msgid $src $fec $label \\\n\
18509 $pathvec $reqmsgid\n\
18510 } else {\n\
18511 $self mapping-msg-from-upstream $msgid $src $fec $label \\\n\
18512 $pathvec $reqmsgid\n\
18513 }\n\
18514 }\n\
18515 \n\
18516 Agent/LDP instproc mapping-msg-from-downstream {msgid src fec label \\\n\
18517 pathvec reqmsgid} {\n\
18518 $self instvar node_ module_\n\
18519 \n\
18520 $module_ out-label-install $fec -1 $src $label\n\
18521 if { $reqmsgid > -1 } {\n\
18522 \n\
18523 set prvsrc   [$self msgtbl-get-src      $reqmsgid]\n\
18524 set prvmsgid [$self msgtbl-get-reqmsgid $reqmsgid]\n\
18525 $self msgtbl-clear $reqmsgid\n\
18526 if { $prvsrc == [$node_ id] || $prvsrc < 0} {\n\
18527 return\n\
18528 }\n\
18529 if { [Classifier/Addr/MPLS ordered-control?] == 1 } {\n\
18530 \n\
18531 set inlabel [$module_ new-incoming-label]\n\
18532 $module_ in-label-install $fec -1 $prvsrc $inlabel\n\
18533 set ldpagent [$module_ get-ldp-agent $prvsrc]\n\
18534 $ldpagent new-msgid\n\
18535 $ldpagent send-mapping-msg $fec $inlabel -1 $prvmsgid\n\
18536 return\n\
18537 }\n\
18538 } else {\n\
18539 $module_ ldp-trigger-by-control $fec $pathvec\n\
18540 return\n\
18541 }\n\
18542 }\n\
18543 \n\
18544 Agent/LDP instproc mapping-msg-from-upstream {msgid src fec label pathvec \\\n\
18545 reqmsgid} {\n\
18546 $self instvar node_ module_\n\
18547 \n\
18548 set nexthop [$module_ lookup-nexthop $src $fec]\n\
18549 if { $nexthop != [$node_ id] } {\n\
18550 return\n\
18551 }\n\
18552 \n\
18553 set inlabel [$module_ get-incoming-label $fec -1]\n\
18554 if { $inlabel == -1 } {\n\
18555 if { [$module_ is-egress-lsr $fec] == 1 } {\n\
18556 if { $label != 0 } {\n\
18557 set ldpagent [$module_ get-ldp-agent $src]\n\
18558 $ldpagent new-msgid\n\
18559 $ldpagent send-mapping-msg $fec 0 \"*\" $msgid\n\
18560 }\n\
18561 } else {\n\
18562 $module_ in-label-install $fec -1 $src $label\n\
18563 }\n\
18564 } else {\n\
18565 set ldpagent [$module_ get-ldp-agent $src]\n\
18566 if { $reqmsgid < 0 } {\n\
18567 $ldpagent new-msgid\n\
18568 $ldpagent send-mapping-msg $fec $inlabel \"*\" $msgid\n\
18569 }   \n\
18570 }    \n\
18571 if { $reqmsgid < 0 } {\n\
18572 $module_ ldp-trigger-by-data -1 $src $fec $pathvec\n\
18573 } else {   \n\
18574 $self msgtbl-clear $reqmsgid\n\
18575 }    \n\
18576 }\n\
18577 \n\
18578 Agent/LDP instproc get-notification-msg {src status lspid} {\n\
18579 $self instvar node_ trace_ldp_ module_\n\
18580 \n\
18581 if { $trace_ldp_ } {\n\
18582 puts \"Notification($src->[$node_ id]): $status src=$src lspid=$lspid\"\n\
18583 }\n\
18584 set msgid [$self msgtbl-get-msgid -1 $lspid -1]\n\
18585 if {$msgid > -1} {\n\
18586 set prvsrc   [$self msgtbl-get-src      $msgid]\n\
18587 $self msgtbl-clear $msgid            \n\
18588 if { $prvsrc < -1 || $prvsrc == [$node_ id] } {\n\
18589 return\n\
18590 }\n\
18591 set ldpagent [$module_ get-ldp-agent $prvsrc]\n\
18592 $ldpagent new-msgid\n\
18593 $ldpagent send-notification-msg $status $lspid\n\
18594 }\n\
18595 }\n\
18596 \n\
18597 Agent/LDP instproc get-withdraw-msg {src fec lspid} {\n\
18598 $self instvar module_\n\
18599 \n\
18600 set outiface  [$module_ get-outgoing-iface $fec $lspid]\n\
18601 if {$src == $outiface} {\n\
18602 $module_ out-label-clear $fec $lspid\n\
18603 set inlabel [$module_ get-incoming-label $fec $lspid]\n\
18604 if {$inlabel > -1} {\n\
18605 $module_ ldp-trigger-by-withdraw $fec $lspid\n\
18606 }\n\
18607 }\n\
18608 }\n\
18609 \n\
18610 Agent/LDP instproc get-release-msg {src fec lspid} {\n\
18611 $self instvar module_\n\
18612 \n\
18613 set iniface  [$module_ get-incoming-iface $fec $lspid]\n\
18614 set outlabel [$module_ get-outgoing-label $fec $lspid]\n\
18615 if {$iniface == $src} {\n\
18616 $module_ in-label-clear $fec $lspid \n\
18617 if {$outlabel > -1} {\n\
18618 $module_ ldp-trigger-by-release $fec $lspid\n\
18619 }\n\
18620 } \n\
18621 }\n\
18622 \n\
18623 Agent/LDP instproc trace-ldp-packet {src_addr src_port msgtype msgid fec \\\n\
18624 label pathvec lspid er rc reqmsgid status atime} {\n\
18625 $self instvar node_\n\
18626 puts \"$atime [$node_ id]: $src_addr ($msgtype $msgid) $fec $label $pathvec  \\[$reqmsgid $status\\]  \\[$lspid $er $rc\\]\"\n\
18627 }\n\
18628 \n\
18629 Agent/LDP instproc send-notification-msg {status lspid} {\n\
18630 $self set fid_ 101\n\
18631 $self cmd notification-msg $status $lspid\n\
18632 }\n\
18633 \n\
18634 Agent/LDP instproc send-request-msg {fec pathvec} {\n\
18635 $self set fid_ 102\n\
18636 $self request-msg $fec $pathvec\n\
18637 }\n\
18638 \n\
18639 Agent/LDP instproc send-mapping-msg {fec label pathvec reqmsgid} {\n\
18640 $self set fid_ 103\n\
18641 $self cmd mapping-msg $fec $label $pathvec $reqmsgid\n\
18642 }\n\
18643 \n\
18644 Agent/LDP instproc send-withdraw-msg {fec lspid} {\n\
18645 $self set fid_ 104\n\
18646 $self withdraw-msg $fec $lspid\n\
18647 }\n\
18648 \n\
18649 Agent/LDP instproc send-release-msg {fec lspid} {\n\
18650 $self set fid_ 105\n\
18651 $self release-msg $fec $lspid\n\
18652 }\n\
18653 \n\
18654 Agent/LDP instproc send-cr-request-msg {fec pathvec er lspid rc} {\n\
18655 $self set fid_ 102\n\
18656 $self cr-request-msg $fec $pathvec $er $lspid $rc\n\
18657 }\n\
18658 \n\
18659 Agent/LDP instproc send-cr-mapping-msg {fec inlabel lspid prvmsgid} {\n\
18660 $self set fid_ 103\n\
18661 $self cr-mapping-msg $fec $inlabel $lspid $prvmsgid\n\
18662 }\n\
18663 \n\
18664 \n\
18665 \n\
18666 \n\
18667 \n\
18668 Classifier/Addr/MPLS instproc init {args} {\n\
18669 eval $self next $args\n\
18670 $self set rtable_ \"\"\n\
18671 }\n\
18672 \n\
18673 Classifier/Addr/MPLS instproc set-node { node module } {\n\
18674 $self set mpls_node_ $node\n\
18675 $self set mpls_mod_ $module\n\
18676 }\n\
18677 \n\
18678 Classifier/Addr/MPLS instproc no-slot args {\n\
18679 }\n\
18680 \n\
18681 \n\
18682 Classifier/Addr/MPLS instproc trace-packet-switching { time src dst ptype \\\n\
18683 ilabel op oiface olabel ttl psize } {\n\
18684 $self instvar mpls_node_ \n\
18685 puts \"$time [$mpls_node_ id]($src->$dst): $ptype $ilabel $op $oiface $olabel $ttl $psize\"\n\
18686 }\n\
18687 \n\
18688 \n\
18689 Classifier/Addr/MPLS instproc ldp-trigger-by-switch { fec } {\n\
18690 $self instvar mpls_node_ mpls_mod_\n\
18691 if { [Classifier/Addr/MPLS on-demand?] == 1 } {\n\
18692 set msgid  1\n\
18693 } else {\n\
18694 set msgid -1\n\
18695 }\n\
18696 $mpls_mod_ ldp-trigger-by-data $msgid [$mpls_node_ id] $fec *\n\
18697 }\n\
18698 \n\
18699 Classifier/Addr/MPLS instproc rtable-ready { fec } {\n\
18700 $self instvar rtable_\n\
18701 set ns [Simulator instance]\n\
18702 if { [lsearch $rtable_ $fec] == -1 } {\n\
18703 lappend rtable_ $fec\n\
18704 }\n\
18705 set rtlen [llength $rtable_]\n\
18706 set nodelen [$ns array size Node_]\n\
18707 if { $rtlen == $nodelen } {\n\
18708 return 1\n\
18709 } else {\n\
18710 return 0\n\
18711 }\n\
18712 }\n\
18713 \n\
18714 Classifier/Addr/MPLS instproc routing-new { slot time } {\n\
18715 $self instvar mpls_node_ rtable_ mpls_mod_\n\
18716 if { [$self control-driven?] != 1 } {\n\
18717 return\n\
18718 }\n\
18719 if { [lsearch $rtable_ [$mpls_node_ id]] == -1 } {\n\
18720 lappend rtable_ [$mpls_node_ id]\n\
18721 }\n\
18722 if { [$self rtable-ready $slot] == 1 } {\n\
18723 set rtlen [llength $rtable_]\n\
18724 for {set i 0} {$i < $rtlen} {incr i 1} {\n\
18725 set nodeid [lindex $rtable_ $i]\n\
18726 if { [$mpls_mod_ get-nexthop $nodeid] == -1 } {\n\
18727 set rtable_ \"\" \n\
18728 return\n\
18729 }\n\
18730 }\n\
18731 set rtable_ \"\" \n\
18732 [Simulator instance] at [expr $time] \\\n\
18733 \"$mpls_mod_ ldp-trigger-by-routing-table\"\n\
18734 }\n\
18735 }\n\
18736 \n\
18737 Classifier/Addr/MPLS instproc routing-nochange {slot time} {\n\
18738 $self instvar mpls_node_ rtable_ mpls_mod_\n\
18739 \n\
18740 if { [$self control-driven?] != 1 } {\n\
18741 return\n\
18742 }\n\
18743 if { [lsearch $rtable_ [$mpls_node_ id]] == -1 } {\n\
18744 lappend rtable_ [$mpls_node_ id]\n\
18745 }\n\
18746 if { [$self rtable-ready $slot] == 1 } {\n\
18747 set rtable_ \"\" \n\
18748 [Simulator instance] at $time \\\n\
18749 \"$mpls_mod_ ldp-trigger-by-routing-table\"\n\
18750 }\n\
18751 }\n\
18752 \n\
18753 Classifier/Addr/MPLS instproc routing-update {slot time} {\n\
18754 $self instvar mpls_mod_ rtable_\n\
18755 if {[$self control-driven?] != 1} {\n\
18756 return\n\
18757 }\n\
18758 set fec $slot\n\
18759 set pft_outif [$mpls_mod_ get-outgoing-iface $fec -1]\n\
18760 set rt_outif  [$mpls_mod_ get-nexthop $fec]\n\
18761 if { $pft_outif == -1 || $rt_outif == -1 } {\n\
18762 return\n\
18763 }\n\
18764 $mpls_mod_ ldp-trigger-by-control $fec *\n\
18765 return\n\
18766 }\n\
18767 \n\
18768 \n\
18769 \n\
18770 \n\
18771 \n\
18772 \n\
18773 Simulator set useasim_ 1\n\
18774 Asim set debug_ false\n\
18775 \n\
18776 set MAXSEQ 1073741824\n\
18777 set tcl_precision 17\n\
18778 \n\
18779 Connector set debug_ false\n\
18780 TTLChecker set debug_ false\n\
18781 \n\
18782 Trace set src_ -1\n\
18783 Trace set dst_ -1\n\
18784 Trace set callback_ 0\n\
18785 Trace set show_tcphdr_ 0\n\
18786 Trace set show_sctphdr_ 0\n\
18787 Trace set debug_ false\n\
18788 \n\
18789 \n\
18790 CMUTrace set debug_ false\n\
18791 CMUTrace set show_sctphdr_ 0\n\
18792 CMUTrace set radius_scaling_factor_ 1.0\n\
18793 CMUTrace set duration_scaling_factor_ 3.0e4\n\
18794 \n\
18795 Scheduler/RealTime set maxslop_ 0.010; # max allowed slop b4 error (sec)\n\
18796 \n\
18797 Integrator set lastx_ 0.0\n\
18798 Integrator set lasty_ 0.0\n\
18799 Integrator set sum_ 0.0\n\
18800 \n\
18801 Queue set limit_ 50\n\
18802 Queue set blocked_ false\n\
18803 Queue set unblock_on_resume_ true\n\
18804 \n\
18805 Queue set interleave_ false\n\
18806 Queue set acksfirst_ false\n\
18807 Queue set ackfromfront_ false\n\
18808 Queue set debug_ false\n\
18809 \n\
18810 Queue/SFQ set maxqueue_ 40\n\
18811 Queue/SFQ set buckets_ 16\n\
18812 \n\
18813 Queue/FQ set secsPerByte_ 0\n\
18814 FQLink set queueManagement_ DropTail\n\
18815 \n\
18816 Queue/DropTail set drop_front_ false\n\
18817 Queue/DropTail set summarystats_ false\n\
18818 Queue/DropTail set queue_in_bytes_ false\n\
18819 Queue/DropTail set mean_pktsize_ 500\n\
18820 \n\
18821 Queue/DropTail/PriQueue set Prefer_Routing_Protocols    1\n\
18822 \n\
18823 CMUPriQueue set qlen_logthresh_ 10\n\
18824 CMUPriQueue set fw_logthresh_ 25\n\
18825 CMUPriQueue set debug_ false\n\
18826 \n\
18827 Queue/dsRED set numQueues_ 4\n\
18828 Queue/dsRED set ecn_ 0\n\
18829 \n\
18830 Queue/XCP set spread_bytes_ 0\n\
18831 \n\
18832 Queue/XCP set tcp_xcp_on_ 0  ;\n\
18833 \n\
18834 Queue/RED set bytes_ true ;     # default changed on 10/11/2004.\n\
18835 Queue/RED set queue_in_bytes_ true ;    # default changed on 10/11/2004.\n\
18836 Queue/RED set thresh_ 0\n\
18837 Queue/RED set maxthresh_ 0\n\
18838 Queue/RED set thresh_queue_ [Queue set limit_]\n\
18839 Queue/RED set minthresh_queue_ [Queue set limit_]\n\
18840 Queue/RED set mean_pktsize_ 500\n\
18841 Queue/RED set idle_pktsize_ 100\n\
18842 Queue/RED set q_weight_ -1\n\
18843 Queue/RED set wait_ true\n\
18844 Queue/RED set linterm_ 10\n\
18845 Queue/RED set mark_p_ 0.1\n\
18846 Queue/RED set setbit_ false\n\
18847 Queue/RED set gentle_ true\n\
18848 Queue/RED set drop_tail_ true\n\
18849 Queue/RED set drop_front_ false\n\
18850 Queue/RED set drop_rand_ false\n\
18851 Queue/RED set doubleq_ false\n\
18852 Queue/RED set ns1_compat_ false\n\
18853 Queue/RED set dqthresh_ 50\n\
18854 Queue/RED set ave_ 0.0\n\
18855 Queue/RED set prob1_ 0.0\n\
18856 Queue/RED set curq_ 0\n\
18857 Queue/RED set cur_max_p_ 0\n\
18858 Queue/RED set summarystats_ false\n\
18859 Queue/RED set alpha_ 0.01\n\
18860 Queue/RED set beta_ 0.9 \n\
18861 Queue/RED set adaptive_ 0\n\
18862 Queue/RED set interval_ 0.5\n\
18863 Queue/RED set targetdelay_ 0.005\n\
18864 Queue/RED set top_ 0.5\n\
18865 Queue/RED set bottom_ 0\n\
18866 Queue/RED set cautious_ 0\n\
18867 Queue/RED set feng_adaptive_ 0\n\
18868 \n\
18869 Queue/RED/RIO set bytes_ false\n\
18870 Queue/RED/RIO set queue_in_bytes_ false\n\
18871 Queue/RED/RIO set thresh_ 5\n\
18872 Queue/RED/RIO set maxthresh_ 15\n\
18873 Queue/RED/RIO set in_thresh_ 15\n\
18874 Queue/RED/RIO set in_maxthresh_ 30\n\
18875 Queue/RED/RIO set out_thresh_ 5\n\
18876 Queue/RED/RIO set out_maxthresh_ 15\n\
18877 Queue/RED/RIO set mean_pktsize_ 500\n\
18878 Queue/RED/RIO set q_weight_ 0.002\n\
18879 Queue/RED/RIO set wait_ true\n\
18880 Queue/RED/RIO set linterm_ 10\n\
18881 Queue/RED/RIO set in_linterm_ 50\n\
18882 Queue/RED/RIO set out_linterm_ 5\n\
18883 Queue/RED/RIO set setbit_ false\n\
18884 Queue/RED/RIO set gentle_ false\n\
18885 Queue/RED/RIO set in_gentle_ false\n\
18886 Queue/RED/RIO set out_gentle_ false\n\
18887 Queue/RED/RIO set drop_tail_ true\n\
18888 Queue/RED/RIO set drop_front_ false\n\
18889 Queue/RED/RIO set drop_rand_ false\n\
18890 Queue/RED/RIO set doubleq_ false\n\
18891 Queue/RED/RIO set ns1_compat_ false\n\
18892 Queue/RED/RIO set dqthresh_ 50\n\
18893 Queue/RED/RIO set ave_ 0.0\n\
18894 Queue/RED/RIO set in_ave_ 0.0\n\
18895 Queue/RED/RIO set out_ave_ 0.0\n\
18896 Queue/RED/RIO set prob1_ 0.0\n\
18897 Queue/RED/RIO set in_prob1_ 0.0\n\
18898 Queue/RED/RIO set out_prob1_ 0.0\n\
18899 Queue/RED/RIO set curq_ 0\n\
18900 Queue/RED/RIO set priority_method_ 0\n\
18901 \n\
18902 Queue/RED/PD set auto_ false\n\
18903 Queue/RED/PD set global_target_ false\n\
18904 Queue/RED/PD set noMonitored_ 0\n\
18905 Queue/RED/PD set targetBW_ 0\n\
18906 Queue/RED/PD set unresponsive_penalty_ 1\n\
18907 Queue/RED/PD set P_testFRp_ -1\n\
18908 Queue/RED/PD set noidle_ false\n\
18909 \n\
18910 Queue/PI set bytes_ false\n\
18911 Queue/PI set queue_in_bytes_ false\n\
18912 Queue/PI set a_ 0.00001822\n\
18913 Queue/PI set b_ 0.00001816\n\
18914 Queue/PI set w_ 170\n\
18915 Queue/PI set qref_ 50\n\
18916 Queue/PI set mean_pktsize_ 500\n\
18917 Queue/PI set setbit_ false\n\
18918 Queue/PI set prob_ 0\n\
18919 Queue/PI set curq_ 0\n\
18920 \n\
18921 Queue/Vq set queue_in_bytes_ true\n\
18922 Queue/Vq set markpkts_ false \n\
18923 Queue/Vq set ecnlim_ 0.8\n\
18924 Queue/Vq set buflim_ 1.0 \n\
18925 Queue/Vq set gamma_ 0.98\n\
18926 Queue/Vq set mean_pktsize_ 1000\n\
18927 Queue/Vq set curq_ 0\n\
18928 Queue/Vq set drop_front_ 0\n\
18929 Queue/Vq set markfront_ 0\n\
18930 \n\
18931 Queue/REM set gamma_ 0.001\n\
18932 Queue/REM set phi_ 1.001\n\
18933 Queue/REM set inw_ 1\n\
18934 Queue/REM set mean_pktsize_ 1000\n\
18935 Queue/REM set pupdtime_ 0.002\n\
18936 Queue/REM set pbo_ 20.0\n\
18937 Queue/REM set prob_ 0.0\n\
18938 Queue/REM set curq_ 0.0\n\
18939 Queue/REM set pmark_ 0.0\n\
18940 Queue/REM set markpkts_ false\n\
18941 Queue/REM set qib_ false\n\
18942 \n\
18943 Queue/GK set ecnlim_ 0.95\n\
18944 Queue/GK set mean_pktsize_ 1000\n\
18945 Queue/GK set curq_ 0\n\
18946 Queue/GK set drop_front_ 0\n\
18947 \n\
18948 Queue/DRR set buckets_ 10\n\
18949 Queue/DRR set blimit_ 25000\n\
18950 Queue/DRR set quantum_ 250\n\
18951 Queue/DRR set mask_ 0\n\
18952 \n\
18953 Queue/SRR set maxqueuenumber_ 16\n\
18954 Queue/SRR set mtu_ 1000\n\
18955 Queue/SRR set granularity_ 1000\n\
18956 Queue/SRR set blimit_ 25000\n\
18957 \n\
18958 Queue/CBQ set algorithm_ 0 ;# used by compat only, not bound\n\
18959 Queue/CBQ set maxpkt_ 1024\n\
18960 CBQClass set priority_ 0\n\
18961 CBQClass set level_ 1\n\
18962 CBQClass set extradelay_ 0.0\n\
18963 CBQClass set def_qtype_ DropTail\n\
18964 CBQClass set okborrow_ true\n\
18965 CBQClass set automaxidle_gain_ 0.9375\n\
18966 CBQClass set debug_ false\n\
18967 \n\
18968 SnoopQueue/In set debug_ false\n\
18969 SnoopQueue/Out set debug_ false\n\
18970 SnoopQueue/Drop set debug_ false\n\
18971 SnoopQueue/EDrop set debug_ false\n\
18972 SnoopQueue/Tagger set debug_ false\n\
18973 \n\
18974 PacketQueue/Semantic set acksfirst_ false\n\
18975 PacketQueue/Semantic set filteracks_ false\n\
18976 PacketQueue/Semantic set replace_head_ false\n\
18977 PacketQueue/Semantic set priority_drop_ false\n\
18978 PacketQueue/Semantic set random_drop_ false\n\
18979 PacketQueue/Semantic set reconsAcks_ false\n\
18980 PacketQueue/Semantic set random_ecn_ false\n\
18981 \n\
18982 QueueMonitor set size_ 0\n\
18983 QueueMonitor set pkts_ 0\n\
18984 QueueMonitor set parrivals_ 0\n\
18985 QueueMonitor set barrivals_ 0\n\
18986 QueueMonitor set pdepartures_ 0\n\
18987 QueueMonitor set bdepartures_ 0\n\
18988 QueueMonitor set pdrops_ 0\n\
18989 QueueMonitor set pmarks_ 0\n\
18990 QueueMonitor set bdrops_ 0\n\
18991 \n\
18992 QueueMonitor set qs_pkts_ 0\n\
18993 QueueMonitor set qs_bytes_ 0\n\
18994 QueueMonitor set qs_drops_ 0\n\
18995 \n\
18996 QueueMonitor set first_pkt_ 0\n\
18997 QueueMonitor set last_pkt_ 0\n\
18998 \n\
18999 QueueMonitor set keepRTTstats_ 0\n\
19000 QueueMonitor set maxRTT_ 5\n\
19001 QueueMonitor set binsPerSec_ 100\n\
19002 \n\
19003 QueueMonitor set keepSeqnoStats_ 0\n\
19004 QueueMonitor set maxSeqno_ 1000\n\
19005 QueueMonitor set SeqnoBinSize_ 10\n\
19006 \n\
19007 QueueMonitor set k_ 0.1\n\
19008 QueueMonitor set prevTime_ 0\n\
19009 QueueMonitor set startTime_ 0\n\
19010 QueueMonitor set estRate_ 0\n\
19011 QueueMonitor set estimate_rate_ 0\n\
19012 \n\
19013 QueueMonitor/ED set epdrops_ 0\n\
19014 QueueMonitor/ED set ebdrops_ 0\n\
19015 \n\
19016 QueueMonitor/ED set mon_epdrops_ 0                     \n\
19017 QueueMonitor/ED set mon_ebdrops_ 0\n\
19018 \n\
19019 QueueMonitor/ED/Flowmon set enable_in_ true\n\
19020 QueueMonitor/ED/Flowmon set enable_out_ true\n\
19021 QueueMonitor/ED/Flowmon set enable_drop_ true\n\
19022 QueueMonitor/ED/Flowmon set enable_edrop_ true\n\
19023 QueueMonitor/ED/Flowmon set enable_mon_edrop_ true\n\
19024 \n\
19025 QueueMonitor/ED/Flow set src_ -1\n\
19026 QueueMonitor/ED/Flow set dst_ -1\n\
19027 QueueMonitor/ED/Flow set flowid_ -1\n\
19028 \n\
19029 QueueMonitor/ED/Flow/TB set target_rate_ 128000 \n\
19030 QueueMonitor/ED/Flow/TB set bucket_depth_ 10000\n\
19031 QueueMonitor/ED/Flow/TB set tbucket_ 10000\n\
19032 QueueMonitor/ED/Flow/TSW set target_rate_ 0\n\
19033 QueueMonitor/ED/Flow/TSW set win_len_ 10\n\
19034 QueueMonitor/ED/Flow/TSW set wait_ true\n\
19035 \n\
19036 QueueMonitor/ED/Flow/RedPD set targetBW_ 0\n\
19037 QueueMonitor/ED/Flow/RedPD set currentBW_ 0\n\
19038 QueueMonitor/ED/Flow/RedPD set monitored_ 0\n\
19039 QueueMonitor/ED/Flow/RedPD set unresponsive_ 0\n\
19040 QueueMonitor/ED/Flow/RedPD set monitorStartTime_ 0\n\
19041 QueueMonitor/ED/Flow/RedPD set unresponsiveStartTime_ 0\n\
19042 QueueMonitor/ED/Flow/RedPD set lastDropTime_ 0 \n\
19043 QueueMonitor/ED/Flow/RedPD set auto_ 0 \n\
19044 \n\
19045 DelayLink set bandwidth_ 1.5Mb\n\
19046 DelayLink set delay_ 100ms\n\
19047 DelayLink set debug_ false\n\
19048 DelayLink set avoidReordering_ false ;  # Added 3/27/2003.\n\
19049 DynamicLink set status_ 1\n\
19050 DynamicLink set debug_ false\n\
19051 \n\
19052 Filter set debug_ false\n\
19053 Filter/Field set offset_ 0\n\
19054 Filter/Field set match_  -1\n\
19055 \n\
19056 \n\
19057 \n\
19058 Classifier set offset_ 0\n\
19059 Classifier set shift_ 0\n\
19060 Classifier set mask_ 0xffffffff\n\
19061 Classifier set debug_ false\n\
19062 \n\
19063 Classifier/Hash set default_ -1; # none\n\
19064 Classifier/Replicator set ignore_ 0\n\
19065 \n\
19066 Classifier/Addr/MPLS set ttl_   32\n\
19067 Classifier/Addr/MPLS set trace_mpls_ 0\n\
19068 Classifier/Addr/MPLS set label_ -1\n\
19069 Classifier/Addr/MPLS set enable_reroute_    0\n\
19070 Classifier/Addr/MPLS set reroute_option_ 0\n\
19071 Classifier/Addr/MPLS set control_driven_ 0\n\
19072 Classifier/Addr/MPLS set data_driven_ 0\n\
19073 \n\
19074 \n\
19075 FECModel set debug_ false\n\
19076 \n\
19077 \n\
19078 ErrorModule set debug_ false\n\
19079 \n\
19080 ErrorModel set enable_ 1\n\
19081 ErrorModel set markecn_ false\n\
19082 ErrorModel set delay_pkt_ false\n\
19083 ErrorModel set delay_ 0\n\
19084 ErrorModel set rate_ 0\n\
19085 ErrorModel set bandwidth_ 2Mb\n\
19086 ErrorModel set debug_ false\n\
19087 \n\
19088 ErrorModel/Trace set good_ 123456789\n\
19089 ErrorModel/Trace set loss_ 0\n\
19090 ErrorModel/Periodic set period_ 1.0\n\
19091 ErrorModel/Periodic set offset_ 0.0\n\
19092 ErrorModel/Periodic set burstlen_ 0.0\n\
19093 ErrorModel/Periodic set default_drop_ 0 ;   # set to 1 for default-drop,\n\
19094 ErrorModel/MultiState set curperiod_ 0.0\n\
19095 ErrorModel/MultiState set sttype_ pkt\n\
19096 ErrorModel/MultiState set texpired_ 0\n\
19097 \n\
19098 SelectErrorModel set enable_ 1\n\
19099 SelectErrorModel set markecn_ false\n\
19100 SelectErrorModel set rate_ 0\n\
19101 SelectErrorModel set bandwidth_ 2Mb\n\
19102 SelectErrorModel set pkt_type_ 2\n\
19103 SelectErrorModel set drop_cycle_ 10\n\
19104 SelectErrorModel set drop_offset_ 1\n\
19105 SelectErrorModel set debug_ false\n\
19106 SelectErrorModel set delay_pkt_ false\n\
19107 SelectErrorModel set delay_ 0\n\
19108 SRMErrorModel set enable_ 1\n\
19109 SRMErrorModel set markecn_ false\n\
19110 SRMErrorModel set rate_ 0\n\
19111 SRMErrorModel set bandwidth_ 2Mb\n\
19112 SRMErrorModel set pkt_type_ 2\n\
19113 SRMErrorModel set drop_cycle_ 10\n\
19114 SRMErrorModel set drop_offset_ 1\n\
19115 SRMErrorModel set debug_ false\n\
19116 SRMErrorModel set delay_pkt_ false\n\
19117 SRMErrorModel set delay_ 0\n\
19118 \n\
19119 rtModel set startTime_ 0.5\n\
19120 rtModel set finishTime_ \"-\"\n\
19121 rtModel/Exponential set upInterval_   10.0\n\
19122 rtModel/Exponential set downInterval_  1.0\n\
19123 rtModel/Deterministic set upInterval_   2.0\n\
19124 rtModel/Deterministic set downInterval_ 1.0\n\
19125 \n\
19126 \n\
19127 Application/Traffic/CBR_PP set rate_ 448Kb ;# corresponds to interval of 3.75ms\n\
19128 Application/Traffic/CBR_PP set packetSize_ 210\n\
19129 Application/Traffic/CBR_PP set random_ 0\n\
19130 Application/Traffic/CBR_PP set maxpkts_ 268435456; # 0x10000000\n\
19131 Application/Traffic/CBR_PP set PBM_ 2\n\
19132 \n\
19133 Application/Traffic/Exponential set burst_time_ .5\n\
19134 Application/Traffic/Exponential set idle_time_ .5\n\
19135 Application/Traffic/Exponential set rate_ 64Kb\n\
19136 Application/Traffic/Exponential set packetSize_ 210\n\
19137 \n\
19138 Application/Traffic/Pareto set burst_time_ 500ms\n\
19139 Application/Traffic/Pareto set idle_time_ 500ms\n\
19140 Application/Traffic/Pareto set rate_ 64Kb\n\
19141 Application/Traffic/Pareto set packetSize_ 210\n\
19142 Application/Traffic/Pareto set shape_ 1.5\n\
19143 \n\
19144 Application/Traffic/RealAudio set burst_time_ 0.05ms\n\
19145 Application/Traffic/RealAudio set idle_time_ 1800ms\n\
19146 Application/Traffic/RealAudio set rate_ 2Kb\n\
19147 Application/Traffic/RealAudio set packetSize_ 240\n\
19148 Application/Traffic/RealAudio set minCDF_ 0\n\
19149 Application/Traffic/RealAudio set maxCDF_ 1\n\
19150 Application/Traffic/RealAudio set interpolation_ 0\n\
19151 Application/Traffic/RealAudio set maxEntry_ 32\n\
19152 \n\
19153 Application/Traffic/CBR set rate_ 448Kb ;# corresponds to interval of 3.75ms\n\
19154 Application/Traffic/CBR set packetSize_ 210\n\
19155 Application/Traffic/CBR set random_ 0\n\
19156 Application/Traffic/CBR set maxpkts_ 268435456; # 0x10000000\n\
19157 \n\
19158 Application/Telnet set interval_ 1.0\n\
19159 \n\
19160 Application/Worm set ScanRate 4000\n\
19161 Application/Worm set ScanPort 1434\n\
19162 Application/Worm set ScanPacketSize 404\n\
19163 Application/Worm/An set TimeStep 1\n\
19164 \n\
19165 Application/SctpApp1 set interval_ 1.0\n\
19166 Application/SctpApp1 set numStreams_ 1\n\
19167 Application/SctpApp1 set numUnreliable_ 0\n\
19168 Application/SctpApp1 set reliability_ 0\n\
19169 \n\
19170 RandomVariable/Uniform set min_ 0.0\n\
19171 RandomVariable/Uniform set max_ 1.0\n\
19172 RandomVariable/Exponential set avg_ 1.0\n\
19173 RandomVariable/Pareto set avg_ 1.0\n\
19174 RandomVariable/Pareto set shape_ 1.5\n\
19175 RandomVariable/ParetoII set avg_ 10.0\n\
19176 RandomVariable/ParetoII set shape_ 1.2\n\
19177 RandomVariable/Constant set val_ 1.0\n\
19178 RandomVariable/HyperExponential set avg_ 1.0\n\
19179 RandomVariable/HyperExponential set cov_ 4.0\n\
19180 RandomVariable/Empirical set minCDF_ 0\n\
19181 RandomVariable/Empirical set maxCDF_ 1\n\
19182 RandomVariable/Empirical set interpolation_ 0\n\
19183 RandomVariable/Empirical set maxEntry_ 32\n\
19184 RandomVariable/Normal set avg_ 0.0\n\
19185 RandomVariable/Normal set std_ 1.0\n\
19186 RandomVariable/LogNormal set avg_ 1.0\n\
19187 RandomVariable/LogNormal set std_ 1.0\n\
19188 \n\
19189 ADC/MS set debug_ false\n\
19190 ADC/HB set debug_ false\n\
19191 ADC/Param set debug_ false\n\
19192 ADC/ACTP set debug_ false\n\
19193 ADC/ACTO set debug_ false\n\
19194 \n\
19195 Est/Null set debug_ false\n\
19196 Est/TimeWindow set debug_ false\n\
19197 Est/ExpAvg set debug_ false\n\
19198 Est/PointSample set debug_ false\n\
19199 \n\
19200 MeasureMod set debug_ false\n\
19201 SALink set debug_ false\n\
19202 \n\
19203 \n\
19204 Node set multiPath_ 0\n\
19205 Node set rtagent_port_ 255\n\
19206 \n\
19207 Node set DIFFUSION_APP_PORT 254\n\
19208 \n\
19209 Node/MobileNode set X_              0\n\
19210 Node/MobileNode set Y_              0\n\
19211 Node/MobileNode set Z_              0\n\
19212 Node/MobileNode set speed_              0\n\
19213 Node/MobileNode set position_update_interval_   0\n\
19214 Node/MobileNode set bandwidth_          0   ;# not used\n\
19215 Node/MobileNode set delay_              0   ;# not used\n\
19216 Node/MobileNode set REGAGENT_PORT 0\n\
19217 Node/MobileNode set DECAP_PORT 1\n\
19218 \n\
19219 \n\
19220 AddrParams set ALL_BITS_SET 0xffffffff\n\
19221 AddrParams PortShift 0\n\
19222 AddrParams PortMask [AddrParams set ALL_BITS_SET]\n\
19223 AddrParams set domain_num_ 1\n\
19224 AddrParams set def_clusters 4\n\
19225 AddrParams set def_nodes 5\n\
19226 \n\
19227 AllocAddrBits set DEFADDRSIZE_ 32\n\
19228 AllocAddrBits set MAXADDRSIZE_ 32                ;# leaving the signed bit\n\
19229 \n\
19230 Simulator set node_factory_ Node\n\
19231 Simulator set nsv1flag 0\n\
19232 Simulator set mobile_ip_ 0           ;# flag for mobileIP\n\
19233 \n\
19234 \n\
19235 Simulator set routingAgent_ \"\"\n\
19236 Simulator set addressType_   \"\"\n\
19237 Simulator set MovementTrace_ OFF\n\
19238 \n\
19239 Simulator set EotTrace_ OFF\n\
19240 \n\
19241 \n\
19242 Simulator set IMEPFlag_ \"\"\n\
19243 Simulator set WirelessNewTrace_ 0\n\
19244 Simulator set propInstCreated_ 0\n\
19245 \n\
19246 SessionSim set rc_ 0\n\
19247 \n\
19248 Simulator set McastBaseAddr_ 0x80000000\n\
19249 Simulator set McastAddr_ 0x80000000\n\
19250 \n\
19251 Simulator set AgentTrace_ ON\n\
19252 Simulator set RouterTrace_ OFF\n\
19253 Simulator set MacTrace_   OFF\n\
19254 \n\
19255 Simulator set TaggedTrace_ OFF\n\
19256 \n\
19257 SessionHelper set rc_ 0                      ;# just to eliminate warnings\n\
19258 SessionHelper set debug_ false\n\
19259 \n\
19260 NetworkInterface set debug_ false\n\
19261 \n\
19262 \n\
19263 \n\
19264 TBF set rate_ 64k\n\
19265 TBF set bucket_ 1024\n\
19266 TBF set qlen_ 0\n\
19267 \n\
19268 MIPEncapsulator set addr_ 0\n\
19269 MIPEncapsulator set port_ 0\n\
19270 MIPEncapsulator set shift_ 0\n\
19271 MIPEncapsulator set mask_ [AddrParams set ALL_BITS_SET]\n\
19272 MIPEncapsulator set ttl_ 32\n\
19273 MIPEncapsulator set debug_ false\n\
19274 \n\
19275 \n\
19276 GAFPartner set addr_ 0\n\
19277 GAFPartner set port_ 254\n\
19278 GAFPartner set shift_ 0\n\
19279 GAFPartner set mask_ [AddrParams set ALL_BITS_SET]\n\
19280 GAFPartner set debug_ false                  \n\
19281 \n\
19282 \n\
19283 \n\
19284 Mac set debug_ false\n\
19285 ARPTable set debug_ false\n\
19286 ARPTable set avoidReordering_ false ; #not used\n\
19287 God set debug_ false\n\
19288 \n\
19289 Mac/Tdma set slot_packet_len_   1500\n\
19290 Mac/Tdma set max_node_num_  64\n\
19291 \n\
19292 LL set mindelay_                50us\n\
19293 LL set delay_                   25us\n\
19294 LL set bandwidth_               0       ;# not used\n\
19295 LL set debug_ false\n\
19296 LL set avoidReordering_ false ; #not used \n\
19297 \n\
19298 Snoop set debug_ false\n\
19299 \n\
19300 \n\
19301 Mac/802_11 set CWMin_         31\n\
19302 Mac/802_11 set CWMax_         1023\n\
19303 Mac/802_11 set SlotTime_      0.000020        ;# 20us\n\
19304 Mac/802_11 set SIFS_          0.000010        ;# 10us\n\
19305 Mac/802_11 set PreambleLength_        144             ;# 144 bit\n\
19306 Mac/802_11 set PLCPHeaderLength_      48              ;# 48 bits\n\
19307 Mac/802_11 set PLCPDataRate_  1.0e6           ;# 1Mbps\n\
19308 Mac/802_11 set RTSThreshold_  0               ;# bytes\n\
19309 Mac/802_11 set ShortRetryLimit_       7               ;# retransmittions\n\
19310 Mac/802_11 set LongRetryLimit_        4               ;# retransmissions\n\
19311 \n\
19312 \n\
19313 \n\
19314 \n\
19315 Classifier/Replicator set direction_ false\n\
19316 Mac set abstract_ false\n\
19317 \n\
19318 Mac/802_3 set trace_ false\n\
19319 \n\
19320 Mac/SMAC set syncFlag_ 1\n\
19321 \n\
19322 Mac/SMAC set selfConfigFlag_ 1\n\
19323 \n\
19324 Mac/SMAC set dutyCycle_ 10                                                                                                                \n\
19325 Antenna/OmniAntenna set X_ 0\n\
19326 Antenna/OmniAntenna set Y_ 0\n\
19327 Antenna/OmniAntenna set Z_ 1.5 \n\
19328 Antenna/OmniAntenna set Gt_ 1.0\n\
19329 Antenna/OmniAntenna set Gr_ 1.0\n\
19330 \n\
19331 Phy set debug_ false\n\
19332 \n\
19333 Phy/WirelessPhy set CPThresh_ 10.0\n\
19334 Phy/WirelessPhy set CSThresh_ 1.559e-11\n\
19335 Phy/WirelessPhy set RXThresh_ 3.652e-10\n\
19336 Phy/WirelessPhy set bandwidth_ 2e6\n\
19337 Phy/WirelessPhy set Pt_ 0.28183815\n\
19338 Phy/WirelessPhy set freq_ 914e+6\n\
19339 Phy/WirelessPhy set L_ 1.0  \n\
19340 \n\
19341 Phy/WiredPhy set bandwidth_ 10e6\n\
19342 \n\
19343 Propagation/Shadowing set pathlossExp_ 2.0\n\
19344 Propagation/Shadowing set std_db_ 4.0\n\
19345 Propagation/Shadowing set dist0_ 1.0\n\
19346 Propagation/Shadowing set seed_ 0\n\
19347 \n\
19348 Mac/SMAC set syncFlag_ 0\n\
19349 \n\
19350 \n\
19351 \n\
19352 \n\
19353 Agent set fid_ 0\n\
19354 Agent set prio_ 0\n\
19355 Agent set agent_addr_ -1\n\
19356 Agent set agent_port_ -1\n\
19357 Agent set dst_addr_ -1\n\
19358 Agent set dst_port_ -1\n\
19359 Agent set flags_ 0\n\
19360 Agent set ttl_ 32 ; # arbitrary choice here\n\
19361 Agent set debug_ false\n\
19362 Agent set class_ 0\n\
19363 \n\
19364 \n\
19365 Agent/Ping set packetSize_ 64\n\
19366 \n\
19367 Agent/UDP set packetSize_ 1000\n\
19368 Agent/UDP instproc done {} { }\n\
19369 Agent/UDP instproc process_data {from data} { }\n\
19370 \n\
19371 Agent/SCTP set debugMask_ 0             ;# all debugging off by default\n\
19372 Agent/SCTP set debugFileIndex_ -1       ;# default outputs to stderr\n\
19373 Agent/SCTP set associationMaxRetrans_ 10;# 10 attempts\n\
19374 Agent/SCTP set pathMaxRetrans_ 5        ;# 5 attempts (per destination)\n\
19375 Agent/SCTP set changePrimaryThresh_ -1  ;# infinite (ie, never change primary\n\
19376 Agent/SCTP set maxInitRetransmits_ 8    ;# 8 attempts\n\
19377 Agent/SCTP set oneHeartbeatTimer_ 1     ;# single heartbeat timer for all dests\n\
19378 Agent/SCTP set heartbeatInterval_ 30    ;# 30 secs\n\
19379 Agent/SCTP set mtu_ 1500                ;# MTU of ethernet (most common)\n\
19380 Agent/SCTP set initialRwnd_ 65536       ;# default inital receiver window\n\
19381 Agent/SCTP set initialSsthresh_ 65536   ;# default inital ssthresh value\n\
19382 Agent/SCTP set initialCwnd_ 2           ;# default cwnd = 2 * MTU\n\
19383 Agent/SCTP set initialRto_ 3.0          ;# default initial RTO = 3 secs       \n\
19384 Agent/SCTP set minRto_ 1.0              ;# default min RTO = 1 sec            \n\
19385 Agent/SCTP set maxRto_ 60.0             ;# default max RTO = 60 secs          \n\
19386 Agent/SCTP set fastRtxTrigger_ 4        ;# 4 missing reports trigger fast rtx\n\
19387 Agent/SCTP set numOutStreams_ 1         ;# single stream default\n\
19388 Agent/SCTP set numUnrelStreams_ 0       ;# by default all streams are reliable\n\
19389 Agent/SCTP set reliability_ 0           ;# by default unrel streams have 0 rtx's\n\
19390 Agent/SCTP set unordered_ 0             ;# by default all chunks are ordered\n\
19391 Agent/SCTP set ipHeaderSize_ 20         ;# default is IPv4\n\
19392 Agent/SCTP set dataChunkSize_ 1468      ;# restricted to 4 byte boundaries\n\
19393 Agent/SCTP set useDelayedSacks_ 1       ;# rfc2960 says SHOULD use delayed sacks\n\
19394 Agent/SCTP set sackDelay_ 0.200         ;# rfc2960 recommends 200 ms\n\
19395 Agent/SCTP set useMaxBurst_ 1           ;# sctp implementors guide adds this var\n\
19396 Agent/SCTP set rtxToAlt_ 1              ;# by default rtxs go to alternate dest\n\
19397 Agent/SCTP set dormantAction_ 0     ;# 0 = change dest, 1 = use primary, 2 = use last dest before dormant;\n\
19398 \n\
19399 Agent/SCTP set routeCalcDelay_ 0        ;# time to calculate a route          \n\
19400 Agent/SCTP set routeCacheLifetime_ 1.2  ;# how long a route remains cached  \n\
19401 \n\
19402 Agent/SCTP set trace_all_ 0             ;# trace all vars ?\n\
19403 \n\
19404 Agent/SCTP set cwnd_ 0                 ; \n\
19405 Agent/SCTP set rto_ 0                  ;\n\
19406 Agent/SCTP set errorCount_ 0           ;\n\
19407 Agent/SCTP set frCount_ 0              ;                                      \n\
19408 Agent/SCTP set timeoutCount_ 0         ;                                      \n\
19409 Agent/SCTP set rcdCount_ 0             ;# total count of route calc delays    \n\
19410 \n\
19411 Agent/SCTP/MultipleFastRtx set mfrCount_ 0                                    \n\
19412 Agent/SCTP/MfrTimestamp set mfrCount_ 0    \n\
19413 \n\
19414 \n\
19415 Agent/TCP set seqno_ 0\n\
19416 Agent/TCP set t_seqno_ 0\n\
19417 Agent/TCP set maxburst_ 0\n\
19418 Agent/TCP set aggressive_maxburst_ 1 ;  # Added 2003/6/2.\n\
19419 Agent/TCP set maxcwnd_ 0\n\
19420 Agent/TCP set numdupacks_ 3\n\
19421 Agent/TCP set numdupacksFrac_ 100 ; # Added 2002/10/18.\n\
19422 Agent/TCP set exitFastRetrans_ true ;   # Added 2003/7/28.\n\
19423 Agent/TCP set window_ 20\n\
19424 Agent/TCP set windowInit_ 2 ;       # default changed on 2001/5/26.\n\
19425 Agent/TCP set windowInitOption_ 1\n\
19426 Agent/TCP set syn_ true ;       # default changed on 2001/5/17.\n\
19427 Agent/TCP set windowOption_ 1\n\
19428 Agent/TCP set windowConstant_ 4\n\
19429 Agent/TCP set windowThresh_ 0.002\n\
19430 Agent/TCP set decrease_num_ 0.5\n\
19431 Agent/TCP set increase_num_ 1.0\n\
19432 Agent/TCP set k_parameter_ 0.0 ;    # for binomial congestion control\n\
19433 Agent/TCP set l_parameter_ 1.0 ;    # for binomial congestion control\n\
19434 Agent/TCP set overhead_ 0\n\
19435 Agent/TCP set ecn_ 0\n\
19436 Agent/TCP set old_ecn_ 0\n\
19437 Agent/TCP set packetSize_ 1000\n\
19438 Agent/TCP set tcpip_base_hdr_size_ 40\n\
19439 Agent/TCP set ts_option_size_ 10;   # in bytes\n\
19440 Agent/TCP set bugFix_ true\n\
19441 Agent/TCP set bugFix_ack_ false ;       # Variable added on 2003/08/13\n\
19442 Agent/TCP set bugFix_ts_ false ;    # Variable added on 2003/08/13\n\
19443 Agent/TCP set lessCareful_ false ;  # for the Less Careful variant of\n\
19444 Agent/TCP set timestamps_ false\n\
19445 Agent/TCP set ts_resetRTO_ false ;  # Added 2003/07/24.\n\
19446 Agent/TCP set slow_start_restart_ true\n\
19447 Agent/TCP set restart_bugfix_ true\n\
19448 Agent/TCP set tcpTick_ 0.01 ;       # default changed on 2002/03/07\n\
19449 Agent/TCP set maxrto_ 100000\n\
19450 Agent/TCP set minrto_ 0.2 ;     # Default changed to 200ms on \n\
19451 Agent/TCP set srtt_init_ 0\n\
19452 Agent/TCP set rttvar_init_ 12\n\
19453 Agent/TCP set rtxcur_init_ 6.0\n\
19454 Agent/TCP set T_SRTT_BITS 3\n\
19455 Agent/TCP set T_RTTVAR_BITS 2\n\
19456 Agent/TCP set rttvar_exp_ 2\n\
19457 Agent/TCP set timerfix_ true ;      # Variable added on 2001/05/11\n\
19458 Agent/TCP set rfc2988_ true ;       # Default set to \"true\" on 2002/03/07.\n\
19459 Agent/TCP instproc done {} { }\n\
19460 Agent/TCP set noFastRetrans_ false\n\
19461 Agent/TCP set partial_ack_ false ;  # Variable added on 2002/12/28.\n\
19462 Agent/TCP set dupacks_ 0\n\
19463 Agent/TCP set ack_ 0\n\
19464 Agent/TCP set cwnd_ 0\n\
19465 Agent/TCP set awnd_ 0\n\
19466 Agent/TCP set ssthresh_ 0\n\
19467 Agent/TCP set rtt_ 0\n\
19468 Agent/TCP set srtt_ 0\n\
19469 Agent/TCP set rttvar_ 0\n\
19470 Agent/TCP set backoff_ 0\n\
19471 Agent/TCP set maxseq_ 0\n\
19472 Agent/TCP set singledup_ 1 ;        # default changed on 2001/11/28.\n\
19473 Agent/TCP set LimTransmitFix_ false ;   # added on 2003/03/31.\n\
19474 Agent/TCP set precisionReduce_ false\n\
19475 Agent/TCP set oldCode_ false\n\
19476 Agent/TCP set useHeaders_ true ;    # default changed on 2001/11/28. \n\
19477 \n\
19478 Agent/TCP set low_window_ 38\n\
19479 Agent/TCP set high_window_ 83000\n\
19480 Agent/TCP set high_p_ 0.0000001\n\
19481 Agent/TCP set high_decrease_ 0.1\n\
19482 Agent/TCP set max_ssthresh_ 0\n\
19483 Agent/TCP set cwnd_range_ 0 ;       # cwnd_frac_ deleted on 6/6/04,\n\
19484 \n\
19485 Agent/TCP set rate_request_ 0\n\
19486 Agent/TCP set qs_enabled_ false\n\
19487 Agent/TCP set tcp_qs_recovery_ true ;   # Added on 2004/09/21, by Pasi.\n\
19488 Agent/TCP set qs_request_mode_ 1\n\
19489 Agent/TCP set qs_rtt_ 50\n\
19490 Agent/TCP set qs_thresh_ 4\n\
19491 \n\
19492 Agent/TCP set ndatapack_ 0\n\
19493 Agent/TCP set ndatabytes_ 0\n\
19494 Agent/TCP set nackpack_ 0\n\
19495 Agent/TCP set nrexmit_ 0\n\
19496 Agent/TCP set nrexmitpack_ 0\n\
19497 Agent/TCP set nrexmitbytes_ 0\n\
19498 Agent/TCP set necnresponses_ 0\n\
19499 Agent/TCP set ncwndcuts_ 0 \n\
19500 Agent/TCP set ncwndcuts1_ 0\n\
19501 \n\
19502 Agent/TCP set trace_all_oneline_ false\n\
19503 \n\
19504 Agent/TCP set QOption_ 0 \n\
19505 Agent/TCP set EnblRTTCtr_ 0\n\
19506 Agent/TCP set control_increase_ 0\n\
19507 \n\
19508 Agent/TCP set SetCWRonRetransmit_ false ; # added on 2005/06/19.\n\
19509 \n\
19510 Agent/TCP set nam_tracevar_ false\n\
19511 \n\
19512 Agent/TCP/Fack set ss-div4_ false\n\
19513 Agent/TCP/Fack set rampdown_ false\n\
19514 \n\
19515 Agent/TCP/Reno/XCP set timestamps_ true\n\
19516 Agent/TCP/Reno/XCP set xcp_sparse_ false\n\
19517 Agent/TCP/Reno/XCP set tcpTick_ 0.01\n\
19518 \n\
19519 Agent/TCP set eln_ 0\n\
19520 Agent/TCP set eln_rxmit_thresh_ 1\n\
19521 Agent/TCP set delay_growth_ true ;  # default changed on 2001/5/17.\n\
19522 \n\
19523 Agent/TCP set CoarseTimer_      0\n\
19524 \n\
19525 Agent/TCP set frto_enabled_ 0 ; # Added on 2004/10/26 for F-RTO\n\
19526 Agent/TCP set sfrto_enabled_    0 ; # Added on 2004/10/26 for F-RTO\n\
19527 Agent/TCP set spurious_response_ 1 ;    # Added on 2004/10/26 for F-RTO\n\
19528 \n\
19529 Agent/TCPSink set sport_        0\n\
19530 Agent/TCPSink set dport_        0         \n\
19531 \n\
19532 Agent/TCPSink set packetSize_ 40\n\
19533 Agent/TCPSink set maxSackBlocks_ 3\n\
19534 Agent/TCPSink set ts_echo_bugfix_ true ;    # default changed, 2003/8/13\n\
19535 Agent/TCPSink set ts_echo_rfc1323_ false ;  # default added, 2003/8/13\n\
19536 Agent/TCPSink set generateDSacks_ false\n\
19537 Agent/TCPSink set qs_enabled_ false\n\
19538 Agent/TCPSink set RFC2581_immediate_ack_ true\n\
19539 Agent/TCPSink set bytes_ 0\n\
19540 \n\
19541 Agent/XCPSink set packetSize_ 40\n\
19542 Agent/XCPSink set ts_echo_bugfix_ true\n\
19543 Agent/XCPSink set bytes_ 0\n\
19544 Agent/XCPSink set RFC2581_immediate_ack_ true\n\
19545 Agent/XCPSink set ts_echo_rfc1323_ false\n\
19546 \n\
19547 Agent/TCPSink/DelAck set interval_ 100ms\n\
19548 catch {\n\
19549 Agent/TCPSink/Asym set interval_ 100ms\n\
19550 Agent/TCPSink/Asym set maxdelack_ 5\n\
19551 }\n\
19552 Agent/TCPSink/Sack1/DelAck set interval_ 100ms\n\
19553 \n\
19554 Agent/TCP/Newreno set newreno_changes_ 0\n\
19555 Agent/TCP/Newreno set newreno_changes1_ 1\n\
19556 Agent/TCP/Newreno set partial_window_deflation_ 1 ; # Default changed to 1\n\
19557 Agent/TCP/Newreno set exit_recovery_fix_ 0\n\
19558 \n\
19559 Agent/TCP/Vegas set v_alpha_ 1\n\
19560 Agent/TCP/Vegas set v_beta_ 3\n\
19561 Agent/TCP/Vegas set v_gamma_ 1\n\
19562 Agent/TCP/Vegas set v_rtt_ 0\n\
19563 \n\
19564 Agent/TCP/Vegas/RBP set rbp_scale_ 0.75\n\
19565 Agent/TCP/Vegas/RBP set rbp_rate_algorithm_ 1\n\
19566 Agent/TCP/Vegas/RBP set rbp_segs_actually_paced_ 0\n\
19567 Agent/TCP/Vegas/RBP set rbp_inter_pace_delay_ 0\n\
19568 \n\
19569 Agent/TCP/Reno/RBP set rbp_scale_ 0.75\n\
19570 Agent/TCP/Reno/RBP set rbp_segs_actually_paced_ 0\n\
19571 Agent/TCP/Reno/RBP set rbp_inter_pace_delay_ 0\n\
19572 \n\
19573 Agent/TCP/Asym set g_ 0.125\n\
19574 Agent/TCP/Reno/Asym set g_ 0.125\n\
19575 Agent/TCP/Newreno/Asym set g_ 0.125\n\
19576 \n\
19577 Agent/TCP/RFC793edu set add793expbackoff_  true \n\
19578 Agent/TCP/RFC793edu set add793jacobsonrtt_ false\n\
19579 Agent/TCP/RFC793edu set add793fastrtx_     false\n\
19580 Agent/TCP/RFC793edu set add793slowstart_   false\n\
19581 Agent/TCP/RFC793edu set add793additiveinc_ false\n\
19582 Agent/TCP/RFC793edu set add793karnrtt_     true \n\
19583 Agent/TCP/RFC793edu set rto_               60\n\
19584 Agent/TCP/RFC793edu set syn_               true\n\
19585 Agent/TCP/RFC793edu set add793exponinc_    false\n\
19586 \n\
19587 Agent/TCP/FullTcp instproc done_data {} { }\n\
19588 \n\
19589 Agent/TFRC set packetSize_ 1000 \n\
19590 Agent/TFRC set rate_ 0 \n\
19591 Agent/TFRC set df_ 0.95 ;   # decay factor for accurate RTT estimate\n\
19592 Agent/TFRC set tcp_tick_ 0.1 ;  \n\
19593 Agent/TFRC set ndatapack_ 0 ;   # Number of packets sent\n\
19594 Agent/TFRC set ndatabytes_ 0 ;  # Number of bytes sent\n\
19595 Agent/TFRC set srtt_init_ 0 ;   # Variables for tracking RTT    \n\
19596 Agent/TFRC set rttvar_init_ 12  \n\
19597 Agent/TFRC set rtxcur_init_ 6.0 \n\
19598 Agent/TFRC set rttvar_exp_ 2    \n\
19599 Agent/TFRC set T_SRTT_BITS 3    \n\
19600 Agent/TFRC set T_RTTVAR_BITS 2  \n\
19601 Agent/TFRC set InitRate_ 300 ;  # Initial send rate \n\
19602 Agent/TFRC set overhead_ 0 ;    # If > 0, dither outgoing packets\n\
19603 Agent/TFRC set ssmult_ 2 ;  # Rate of increase during slow-start:\n\
19604 Agent/TFRC set bval_ 1 ;    # Value of B for TCP formula\n\
19605 Agent/TFRC set ca_ 1 ;      # Enable Sqrt(RTT) congestion avoidance\n\
19606 Agent/TFRC set printStatus_ 0 \n\
19607 Agent/TFRC set maxHeavyRounds_ 1; # Number of rounds for sending rate allowed\n\
19608 Agent/TFRC set conservative_ 0 ;  # Set to true for a conservative \n\
19609 Agent/TFRC set scmult_ 1.5 ;    # self clocking parameter for conservative_\n\
19610 Agent/TFRC set ecn_ 0 ;     # Set to 1 for ECN-capable connection.\n\
19611 Agent/TFRC set minrto_ 0.0 ;    # Minimum RTO, for use in TCP equation.\n\
19612 Agent/TFRC set SndrType_ 0 ;    # Set to 1 to use data-producing applications\n\
19613 Agent/TFRC set oldCode_ false ; # Set to 1 to use old code for datalimited\n\
19614 Agent/TFRC set maxqueue_ MAXSEQ ;  # queue from application.\n\
19615 Agent/TFRC set rate_init_ 2 ;       # Added on 10/20/2004\n\
19616 Agent/TFRC set rate_init_option_ 2 ;    # Added on 10/20/2004\n\
19617 Agent/TFRC set slow_increase_ 1 ;   # Added on 10/20//2004\n\
19618 Agent/TFRC set ss_changes_ 1 ;  # Added on 10/21//2004. \n\
19619 Agent/TFRC set voip_ 0 ;        # Added on 10/23/2004      \n\
19620 Agent/TFRC set voip_max_pkt_rate_ 100 ;  # Max rate in pps, for voip mode.\n\
19621 Agent/TFRC set fsize_ 1460 ;    # Default size for large TCP packets. \n\
19622 Agent/TFRC set headersize_ 32 ; # Size for packet headers.\n\
19623 Agent/TFRC set useHeaders_ true ;   # Added on 2005/06/24. \n\
19624 Agent/TFRC set true_loss_rate_ 0.0 ; # For statistics only.\n\
19625 \n\
19626 Agent/TFRCSink set packetSize_ 40\n\
19627 Agent/TFRCSink set InitHistorySize_ 100000\n\
19628 Agent/TFRCSink set NumFeedback_ 1 \n\
19629 Agent/TFRCSink set AdjustHistoryAfterSS_ 1\n\
19630 Agent/TFRCSink set NumSamples_ -1\n\
19631 Agent/TFRCSink set discount_ 1; # History Discounting\n\
19632 Agent/TFRCSink set printLoss_ 0\n\
19633 Agent/TFRCSink set smooth_ 1 ;  # smoother Average Loss Interval\n\
19634 Agent/TFRCSink set ShortIntervals_ 0 ; #  For calculating loss event rates \n\
19635 Agent/TFRCSink set minlc_ 4\n\
19636 Agent/TFRCSink set algo_ 1 ;    # 1: algo from sigcomm paper 2: ewma \n\
19637 Agent/TFRCSink set maxint_ 1000 ;     # max loss interval history \n\
19638 Agent/TFRCSink set history_ 0.75 ;    # loss history for EWMA\n\
19639 Agent/TFRCSink set PreciseLoss_ 1 ;   # 1 for more precise loss events\n\
19640 Agent/TFRCSink set numPkts_ 1;  # Num non-sequential packets before loss\n\
19641 Agent/TFRCSink set bytes_ 0 ;   # For counting bytes received.\n\
19642 \n\
19643 if [TclObject is-class Agent/TCP/FullTcp] {\n\
19644 Agent/TCP/FullTcp set segsperack_ 1; # ACK frequency\n\
19645 Agent/TCP/FullTcp set spa_thresh_ 0; # below do 1 seg per ack [0:disable]\n\
19646 Agent/TCP/FullTcp set segsize_ 536; # segment size\n\
19647 Agent/TCP/FullTcp set tcprexmtthresh_ 3; # num dupacks to enter recov\n\
19648 Agent/TCP/FullTcp set iss_ 0; # Initial send seq#\n\
19649 Agent/TCP/FullTcp set nodelay_ false; # Nagle disable?\n\
19650 Agent/TCP/FullTcp set data_on_syn_ false; # allow data on 1st SYN?\n\
19651 Agent/TCP/FullTcp set dupseg_fix_ true ; # no rexmt w/dup segs from peer\n\
19652 Agent/TCP/FullTcp set dupack_reset_ false; # exit recov on ack < highest\n\
19653 Agent/TCP/FullTcp set interval_ 0.1 ; # delayed ACK interval 100ms \n\
19654 Agent/TCP/FullTcp set close_on_empty_ false; # close conn if sent all\n\
19655 Agent/TCP/FullTcp set signal_on_empty_ false; # signal if sent all\n\
19656 Agent/TCP/FullTcp set ts_option_size_ 10; # in bytes\n\
19657 Agent/TCP/FullTcp set reno_fastrecov_ true; # fast recov true by default\n\
19658 Agent/TCP/FullTcp set pipectrl_ false; # use \"pipe\" ctrl\n\
19659 Agent/TCP/FullTcp set open_cwnd_on_pack_ true; # ^ win on partial acks?\n\
19660 Agent/TCP/FullTcp set halfclose_ false; # do simplex closes (shutdown)?\n\
19661 Agent/TCP/FullTcp set nopredict_ false; # disable header prediction code?\n\
19662 \n\
19663 Agent/TCP/FullTcp/Newreno set recov_maxburst_ 2; # max burst dur recov\n\
19664 \n\
19665 Agent/TCP/FullTcp/Sack set sack_block_size_ 8; # bytes in a SACK block\n\
19666 Agent/TCP/FullTcp/Sack set sack_option_size_ 2; # bytes in opt hdr\n\
19667 Agent/TCP/FullTcp/Sack set max_sack_blocks_ 3; # max # of sack blks\n\
19668 Agent/TCP/FullTcp/Sack set clear_on_timeout_ true; # clear sq at sender on timeout?\n\
19669 Agent/TCP/FullTcp/Sack set sack_rtx_cthresh_ 1; # dup cnt to trigger rtx\n\
19670 Agent/TCP/FullTcp/Sack set sack_rtx_bthresh_ 1; # dup bcnt to trigger rtx\n\
19671 Agent/TCP/FullTcp/Sack set sack_rtx_threshmode_ 1; # 1 = cnt only\n\
19672 \n\
19673 Agent/TCP/FullTcp/Tahoe instproc init {} {\n\
19674 $self next\n\
19675 $self instvar reno_fastrecov_\n\
19676 set reno_fastrecov_ false\n\
19677 }\n\
19678 \n\
19679 Agent/TCP/FullTcp/Sack instproc init {} {\n\
19680 $self next\n\
19681 $self instvar reno_fastrecov_ open_cwnd_on_pack_\n\
19682 set reno_fastrecov_ false\n\
19683 set open_cwnd_on_pack_ false\n\
19684 }\n\
19685 \n\
19686 Agent/TCP/FullTcp/Newreno instproc init {} {\n\
19687 $self next\n\
19688 $self instvar open_cwnd_on_pack_\n\
19689 set open_cwnd_on_pack_ false\n\
19690 }\n\
19691 \n\
19692 }\n\
19693 \n\
19694 if [TclObject is-class Agent/TCP/BayFullTcp] {\n\
19695 Agent/TCP/BayFullTcp set segsperack_ 1; # ACK frequency\n\
19696 Agent/TCP/BayFullTcp set segsize_ 536; # segment size\n\
19697 Agent/TCP/BayFullTcp set tcprexmtthresh_ 3; # num dupacks to enter recov\n\
19698 Agent/TCP/BayFullTcp set iss_ 0; # Initial send seq#\n\
19699 Agent/TCP/BayFullTcp set nodelay_ false; # Nagle disable?\n\
19700 Agent/TCP/BayFullTcp set data_on_syn_ false; # allow data on 1st SYN?\n\
19701 Agent/TCP/BayFullTcp set dupseg_fix_ true ; # no rexmt w/dup segs from peer\n\
19702 Agent/TCP/BayFullTcp set dupack_reset_ false; # exit recov on ack < highest\n\
19703 Agent/TCP/BayFullTcp set interval_ 0.1 ; # delayed ACK interval 100ms \n\
19704 Agent/TCP/BayFullTcp set close_on_empty_ false; # close conn if sent all\n\
19705 Agent/TCP/BayFullTcp set ts_option_size_ 10; # in bytes\n\
19706 Agent/TCP/BayFullTcp set reno_fastrecov_ true; # fast recov true by default\n\
19707 Agent/TCP/BayFullTcp set pipectrl_ false; # use \"pipe\" ctrl\n\
19708 Agent/TCP/BayFullTcp set open_cwnd_on_pack_ true; # ^ win on partial acks?\n\
19709 Agent/TCP/BayFullTcp set halfclose_ false; # do simplex closes (shutdown)?\n\
19710 Agent/TCP/BayFullTcp/Newreno set recov_maxburst_ 2; # max burst dur recov\n\
19711 \n\
19712 Agent/TCP/BayFullTcp/Sack set sack_block_size_ 8; # bytes in a SACK block\n\
19713 Agent/TCP/BayFullTcp/Sack set sack_option_size_ 2; # bytes in opt hdr\n\
19714 Agent/TCP/BayFullTcp/Sack set max_sack_blocks_ 3; # max # of sack blks\n\
19715 }\n\
19716 \n\
19717 Agent/Null set sport_           0\n\
19718 Agent/Null set dport_           0\n\
19719 \n\
19720 Agent/CBR set sport_            0\n\
19721 Agent/CBR set dport_            0\n\
19722 \n\
19723 Agent/HttpInval set inval_hdr_size_ 40\n\
19724 \n\
19725 Agent/RTP set seqno_ 0\n\
19726 Agent/RTP set interval_ 3.75ms\n\
19727 Agent/RTP set random_ 0\n\
19728 Agent/RTP set packetSize_ 210\n\
19729 Agent/RTP set maxpkts_ 0x10000000\n\
19730 Agent/RTP instproc done {} { }\n\
19731 \n\
19732 Agent/RTCP set seqno_ 0\n\
19733 \n\
19734 Agent/Message set packetSize_ 180\n\
19735 \n\
19736 Agent/MessagePassing set packetSize_ 1500\n\
19737 \n\
19738 Agent/LossMonitor set nlost_ 0\n\
19739 Agent/LossMonitor set npkts_ 0\n\
19740 Agent/LossMonitor set bytes_ 0\n\
19741 Agent/LossMonitor set lastPktTime_ 0\n\
19742 Agent/LossMonitor set expected_ 0\n\
19743 \n\
19744 Agent/RAP set packetSize_ 512\n\
19745 Agent/RAP set seqno_ 0\n\
19746 Agent/RAP set sessionLossCount_ 0\n\
19747 Agent/RAP set ipg_ 2.0\n\
19748 Agent/RAP set alpha_ 1.0\n\
19749 Agent/RAP set beta_ 0.5\n\
19750 Agent/RAP set srtt_ 2.0\n\
19751 Agent/RAP set variance_ 0.0\n\
19752 Agent/RAP set delta_ 0.5\n\
19753 Agent/RAP set mu_ 1.2\n\
19754 Agent/RAP set phi_ 4.0\n\
19755 Agent/RAP set timeout_ 2.0\n\
19756 Agent/RAP set overhead_ 0\n\
19757 Agent/RAP set useFineGrain_ 0\n\
19758 Agent/RAP set kfrtt_ 0.9\n\
19759 Agent/RAP set kxrtt_ 0.01\n\
19760 Agent/RAP set debugEnable_ 0\n\
19761 Agent/RAP set rap_base_hdr_size_ 44\n\
19762 Agent/RAP set dpthresh_ 50\n\
19763 Agent/RAP instproc done {} { }\n\
19764 \n\
19765 Agent/Mcast/Control set packetSize_ 80\n\
19766 \n\
19767 Agent/rtProto set preference_ 200       ;# global default preference\n\
19768 Agent/rtProto/Direct set preference_ 100\n\
19769 Agent/rtProto/DV set preference_    120\n\
19770 Agent/rtProto/DV set INFINITY        [Agent set ttl_]\n\
19771 Agent/rtProto/DV set advertInterval   2\n\
19772 \n\
19773 Agent/Encapsulator set status_ 1\n\
19774 Agent/Encapsulator set overhead_ 20\n\
19775 \n\
19776 Agent/DSRAgent set sport_ 255\n\
19777 Agent/DSRAgent set dport_ 255\n\
19778 \n\
19779 Agent/MIPBS set adSize_ 48\n\
19780 Agent/MIPBS set shift_ 0\n\
19781 Agent/MIPBS set mask_ [AddrParams set ALL_BITS_SET]\n\
19782 Agent/MIPBS set ad_lifetime_ 2\n\
19783 \n\
19784 Agent/MIPMH set home_agent_ 0\n\
19785 Agent/MIPMH set rreqSize_ 52\n\
19786 Agent/MIPMH set reg_rtx_ 0.5\n\
19787 Agent/MIPMH set shift_ 0\n\
19788 Agent/MIPMH set mask_ [AddrParams set ALL_BITS_SET]\n\
19789 Agent/MIPMH set reg_lifetime_ 2\n\
19790 \n\
19791 Agent/Diff_Sink set packetSize_ 512\n\
19792 Agent/Diff_Sink set interval_   0.5\n\
19793 Agent/Diff_Sink set random_     1\n\
19794 Agent/Diff_Sink set maxpkts_    10000\n\
19795 Agent/Diff_Sink set data_type_  0\n\
19796 \n\
19797 Agent/LossMonitor/PLM set flag_PP_ 0\n\
19798 Agent/LossMonitor/PLM set packet_time_PP_ 0\n\
19799 Agent/LossMonitor/PLM set fid_PP_ 0\n\
19800 Agent/LossMonitor/PLM set seqno_ 0\n\
19801 \n\
19802 Agent/LDP set trace_ldp_ 0\n\
19803 \n\
19804 Simulator set nix-routing 0\n\
19805 \n\
19806 RtModule set classifier_ \"\"\n\
19807 RtModule/Base set classifier_ \"\"\n\
19808 \n\
19809 LMSErrorModel set rate_     0.0 ;# just to eliminate warnings\n\
19810 LMSErrorModel set errPkt_   0\n\
19811 LMSErrorModel set errByte_  0\n\
19812 LMSErrorModel set errTime_  0.0\n\
19813 LMSErrorModel set onlink_   0\n\
19814 LMSErrorModel set enable_   0\n\
19815 LMSErrorModel set ndrops_   0\n\
19816 LMSErrorModel set bandwidth_    2Mb\n\
19817 LMSErrorModel set markecn_  false\n\
19818 LMSErrorModel set debug_    false\n\
19819 LMSErrorModel set delay_pkt_ false\n\
19820 LMSErrorModel set delay_ 0\n\
19821 \n\
19822 set lmsPacketSize 1024\n\
19823 set lsize [Application/Traffic/CBR set packetSize_]\n\
19824 \n\
19825 RtModule/LMS set node_  \"\"\n\
19826 \n\
19827 Agent/LMS set lms_enabled_  1\n\
19828 Agent/LMS set packetSize_   $lmsPacketSize\n\
19829 \n\
19830 Agent/LMS/Sender set interval_ 4.0ms\n\
19831 Agent/LMS/Sender set packetSize_ $lsize\n\
19832 Agent/LMS/Sender set lmsPacketSize_ $lmsPacketSize\n\
19833 Agent/LMS/Sender set random_ 0\n\
19834 Agent/LMS/Sender set maxpkts_ 0x10000000\n\
19835 Agent/LMS/Sender set odat_ 0\n\
19836 Agent/LMS/Sender instproc done {} { }\n\
19837 \n\
19838 Agent/LMS/Receiver set lmsPacketSize_ $lmsPacketSize\n\
19839 Agent/LMS/Receiver set bytes_ 0\n\
19840 Agent/LMS/Receiver set nlost_ 0\n\
19841 Agent/LMS/Receiver set npkts_ 0\n\
19842 Agent/LMS/Receiver set expected_ 0\n\
19843 Agent/LMS/Receiver set lastPktTime_ 0.0\n\
19844 Agent/LMS/Receiver instproc done {} { }\n\
19845 Agent/LMS/Receiver set packetSize_ $lsize\n\
19846 \n\
19847 \n\
19848 Agent/TCP/Newreno/QS set rbp_scale_ 0.75\n\
19849 Agent/TCP/Newreno/QS set rbp_segs_actually_paced_ 0\n\
19850 Agent/TCP/Newreno/QS set rbp_inter_pace_delay_ 0\n\
19851 Agent/TCP/Newreno/QS set rate_request_ 128\n\
19852 \n\
19853 Agent/QSAgent set qs_enabled_ 1\n\
19854 Agent/QSAgent set old_classifier_ 0\n\
19855 Agent/QSAgent set state_delay_ 0.2 ;    # Changed from 0.25 to 0.2, 2/25/05.\n\
19856 Agent/QSAgent set alloc_rate_ 0.85 ;    # Changed from 0.6 to 0.85, 2/25/05.\n\
19857 Agent/QSAgent set threshold_ 0.85 ;     # Changed from 0.4 to 0.85, 2/25/05.\n\
19858 Agent/QSAgent set max_rate_ 256\n\
19859 Agent/QSAgent set mss_ [Agent/TCP set packetSize_]\n\
19860 Agent/QSAgent set rate_function_ 2\n\
19861 Agent/QSAgent set algorithm_ 3  ;   # Changed from 2 to 3, 2/25/05.\n\
19862 \n\
19863 Agent/TCPSink/QS set sport_        0\n\
19864 Agent/TCPSink/QS set dport_        0         \n\
19865 \n\
19866 Agent/TCPSink/QS set packetSize_ 40\n\
19867 Agent/TCPSink/QS set maxSackBlocks_ 3\n\
19868 Agent/TCPSink/QS set ts_echo_bugfix_ false\n\
19869 Agent/TCPSink/QS set generateDSacks_ false\n\
19870 Agent/TCPSink/QS set RFC2581_immediate_ack_ true\n\
19871 \n\
19872 Queue set util_weight_ 0.8\n\
19873 Queue set util_check_intv_ 0.2 ;    # Changed from 1 to 0.2, 2/25/05.\n\
19874 Queue set util_records_ 5 ;         # Changed from 0 to 5, 2/25/05.\n\
19875 \n\
19876 \n\
19877 Delayer set debug_ false\n\
19878 if [TclObject is-class Network/Pcap/Live] {\n\
19879 Network/Pcap/Live set snaplen_ 4096;# bpf snap len\n\
19880 Network/Pcap/Live set promisc_ false;\n\
19881 Network/Pcap/Live set timeout_ 0\n\
19882 Network/Pcap/Live set optimize_ true;# bpf code optimizer\n\
19883 Network/Pcap/Live set offset_ 0.0; # \n\
19884 \n\
19885 Network/Pcap/File set offset_ 0.0; # ts for 1st pkt in trace file\n\
19886 }\n\
19887 \n\
19888 if [TclObject is-class Agent/Tap] {\n\
19889 Agent/Tap set maxpkt_ 1600\n\
19890 }\n\
19891 \n\
19892 if [TclObject is-class Agent/TCPTap] {\n\
19893 Agent/TCPTap set maxpkt_ 1600\n\
19894 }\n\
19895 \n\
19896 if [TclObject is-class Agent/IcmpAgent] {\n\
19897 Agent/IcmpAgent set ttl_ 254\n\
19898 }\n\
19899 \n\
19900 if [TclObject is-class Agent/IPTap] {\n\
19901 Agent/IPTap set maxpkt_ 1600\n\
19902 }\n\
19903 \n\
19904 if [TclObject is-class ArpAgent] {\n\
19905 \n\
19906 ArpAgent set cachesize_ 10; # entries in arp cache\n\
19907 ArpAgent instproc init {} {\n\
19908 $self next\n\
19909 }\n\
19910 \n\
19911 ArpAgent instproc config ifname {\n\
19912 $self instvar net_ myether_ myip_\n\
19913 set net_ [new Network/Pcap/Live]\n\
19914 $net_ open readwrite $ifname\n\
19915 set myether_ [$net_ linkaddr]\n\
19916 set myip_ [$net_ netaddr]\n\
19917 $net_ filter \"arp and (not ether src $myether_) and \\\n\
19918 (ether dst $myether_ \\\n\
19919 or ether dst ff:ff:ff:ff:ff:ff)\"\n\
19920 $self cmd network $net_\n\
19921 $self cmd myether $myether_\n\
19922 $self cmd myip $myip_\n\
19923 }\n\
19924 }\n\
19925 \n\
19926 \n\
19927 \n\
19928 \n\
19929 \n\
19930 Node instproc add-pushback-agent {} {\n\
19931 $self instvar pushback_\n\
19932 set pushback_ [new Agent/Pushback]\n\
19933 [Simulator instance] attach-agent $self $pushback_\n\
19934 $pushback_ initialize $self [[Simulator instance] get-routelogic]\n\
19935 return $pushback_\n\
19936 }\n\
19937 \n\
19938 Node instproc get-pushback-agent {} {\n\
19939 $self instvar pushback_\n\
19940 if [info exists pushback_] {\n\
19941 return $pushback_\n\
19942 } else {\n\
19943 return -1\n\
19944 }\n\
19945 }\n\
19946 \n\
19947 Simulator instproc pushback-duplex-link {n1 n2 bw delay} {\n\
19948 \n\
19949 $self pushback-simplex-link $n1 $n2 $bw $delay\n\
19950 $self pushback-simplex-link $n2 $n1 $bw $delay\n\
19951 }\n\
19952 \n\
19953 Simulator instproc pushback-simplex-link {n1 n2 bw delay} {\n\
19954 \n\
19955 set pba [$n1 get-pushback-agent]\n\
19956 if {$pba == -1} {\n\
19957 puts \"Node does not have a pushback agent\"\n\
19958 exit\n\
19959 }\n\
19960 $self simplex-link $n1 $n2 $bw $delay RED/Pushback $pba\n\
19961 \n\
19962 set link [$self link $n1 $n2]\n\
19963 set qmon [new QueueMonitor/ED]\n\
19964 $link attach-monitors [new SnoopQueue/In] [new SnoopQueue/Out] [new SnoopQueue/Drop] $qmon\n\
19965 \n\
19966 set queue [$link queue]\n\
19967 $queue set pushbackID_ [$pba add-queue $queue]\n\
19968 $queue set-monitor $qmon\n\
19969 $queue set-src-dst [$n1 set id_] [$n2 set id_]\n\
19970 \n\
19971 }\n\
19972 \n\
19973 Agent/Pushback instproc get-pba-port {nodeid} {\n\
19974 \n\
19975 set node [[Simulator instance] set Node_($nodeid)]\n\
19976 set pba [$node get-pushback-agent]\n\
19977 if {$pba == -1} {\n\
19978 return -1\n\
19979 } else {\n\
19980 return [$pba set agent_port_]\n\
19981 }\n\
19982 }\n\
19983 \n\
19984 Agent/Pushback instproc check-queue { src dst qToCheck } {\n\
19985 \n\
19986 set link [[Simulator instance] set link_($src:$dst)]\n\
19987 set queue [$link queue]\n\
19988 if {$qToCheck == $queue} {\n\
19989 return 1\n\
19990 } else {\n\
19991 return 0\n\
19992 }\n\
19993 }\n\
19994 \n\
19995 Queue/RED/Pushback set pushbackID_ -1\n\
19996 Queue/RED/Pushback set rate_limiting_ 1\n\
19997 \n\
19998 Agent/Pushback set last_index_ 0\n\
19999 Agent/Pushback set intResult_ -1\n\
20000 Agent/Pushback set enable_pushback_ 1\n\
20001 Agent/Pushback set verbose_ false\n\
20002 \n\
20003 Queue/RED/Pushback instproc attach-traces {src dst file {op \"\"}} {\n\
20004 \n\
20005 $self next $src $dst $file $op\n\
20006 \n\
20007 set ns [Simulator instance]\n\
20008 \n\
20009 \n\
20010 \n\
20011 set type \"Drop\"\n\
20012 set rldrop_trace [$ns create-trace $type $file $src $dst $op]\n\
20013 \n\
20014 set oldTrace [$self rldrop-trace]\n\
20015 if {$oldTrace!=0} {\n\
20016 puts \"exists\"\n\
20017 $rldrop_trace target $oldTrace\n\
20018 } else {\n\
20019 $rldrop_trace target [$ns set nullAgent_]\n\
20020 }\n\
20021 \n\
20022 $self rldrop-trace $rldrop_trace\n\
20023 \n\
20024 }\n\
20025 \n\
20026 \n\
20027 \n\
20028 \n\
20029 \n\
20030 RtModule/LMS instproc register { node } {\n\
20031 $self instvar node_ lms_classifier_\n\
20032 \n\
20033 set node_ $node\n\
20034 set lms_classifier_ [new Classifier/Lms]\n\
20035 set lms_agent [new Agent/LMS]\n\
20036 $node attach $lms_agent\n\
20037 $node insert-entry $self $lms_classifier_ 0\n\
20038 $lms_classifier_ install 1 $lms_agent\n\
20039 }\n\
20040 \n\
20041 RtModule/LMS instproc get-outlink { iface } {\n\
20042 $self instvar node_\n\
20043 \n\
20044 set oif [$node_ iif2oif $iface]\n\
20045 return $oif    \n\
20046 }\n\
20047 \n\
20048 Node instproc ifaceGetOutLink { iface } {\n\
20049 $self instvar ns_\n\
20050 set link [$self iif2link $iface]\n\
20051 set outlink [$ns_ link $self [$link src]]\n\
20052 set head [$outlink set head_]\n\
20053 return $head\n\
20054 }\n\
20055 \n\
20056 \n\
20057 Node instproc set-switch agent {\n\
20058 $self instvar switch_\n\
20059 set switch_ $agent\n\
20060 }\n\
20061 \n\
20062 Node instproc agent port {\n\
20063 $self instvar agents_\n\
20064 foreach a $agents_ {\n\
20065 if { [$a set agent_port_] == $port } {\n\
20066 return $a\n\
20067 }\n\
20068 }\n\
20069 return \"\"\n\
20070 }\n\
20071 \n\
20072 Agent/LMS/Receiver instproc log-loss {} {\n\
20073 }\n\
20074 \n\
20075 Simulator instproc detach-lossmodel {lossobj from to} {\n\
20076 set link [$self link $from $to]\n\
20077 set head [$link head]\n\
20078 $head target [$lossobj target]\n\
20079 } \n\
20080 \n\
20081 \n\
20082 if {[ns-hasSTL] == 1} {\n\
20083 \n\
20084 Simulator instproc set-nix-routing { } {\n\
20085 Simulator set nix-routing 1\n\
20086 Node enable-module \"Nix\"\n\
20087 }\n\
20088 \n\
20089 Simulator instproc get-link-head { n1 n2 } {\n\
20090 $self instvar link_\n\
20091 return [$link_($n1:$n2) head]\n\
20092 }\n\
20093 \n\
20094 Link instproc set-ipaddr { ipaddr netmask } {\n\
20095 }\n\
20096 \n\
20097 \n\
20098 \n\
20099 \n\
20100 RtModule/Nix instproc register { node } {\n\
20101 $self next $node\n\
20102 $self instvar classifier_\n\
20103 set classifier_ [new Classifier/Nix]\n\
20104 $classifier_ set-node-id [$node set id_]\n\
20105 $node install-entry $self $classifier_\n\
20106 }\n\
20107 \n\
20108 RtModule/Nix instproc route-notify { module } { }\n\
20109 \n\
20110 \n\
20111 \n\
20112 \n\
20113 RtModule/PGM set node_  \"\"\n\
20114 \n\
20115 PGMErrorModel set rate_         0.0     ;# just to eliminate warnings\n\
20116 PGMErrorModel set errPkt_       0\n\
20117 PGMErrorModel set errByte_      0\n\
20118 PGMErrorModel set errTime_      0.0\n\
20119 PGMErrorModel set onlink_       0\n\
20120 PGMErrorModel set delay_        0\n\
20121 PGMErrorModel set delay_pkt_    0\n\
20122 PGMErrorModel set enable_       0\n\
20123 PGMErrorModel set ndrops_       0\n\
20124 PGMErrorModel set bandwidth_    2Mb\n\
20125 PGMErrorModel set markecn_      false\n\
20126 PGMErrorModel set debug_        false\n\
20127 \n\
20128 Agent/PGM set pgm_enabled_ 1\n\
20129 \n\
20130 Agent/PGM set nak_retrans_ival_ 50ms\n\
20131 \n\
20132 Agent/PGM set nak_rpt_ival_ 1000ms\n\
20133 \n\
20134 Agent/PGM set nak_rdata_ival_ 10000ms\n\
20135 \n\
20136 Agent/PGM set nak_elim_ival_ 5000ms\n\
20137 \n\
20138 Agent/PGM instproc done {} { }\n\
20139 \n\
20140 \n\
20141 Agent/PGM/Sender set spm_interval_ 500ms\n\
20142 \n\
20143 Agent/PGM/Sender set rdata_delay_ 70ms\n\
20144 \n\
20145 Agent/PGM/Sender instproc done {} { }\n\
20146 \n\
20147 \n\
20148 Agent/PGM/Receiver set max_nak_ncf_retries_ 5\n\
20149 \n\
20150 Agent/PGM/Receiver set max_nak_data_retries_ 5\n\
20151 \n\
20152 Agent/PGM/Receiver set nak_bo_ivl_ 30ms\n\
20153 \n\
20154 Agent/PGM/Receiver set nak_rpt_ivl_ 50ms\n\
20155 \n\
20156 Agent/PGM/Receiver set nak_rdata_ivl_ 1000ms\n\
20157 \n\
20158 Agent/PGM/Receiver instproc done {} { }\n\
20159 \n\
20160 \n\
20161 \n\
20162 \n\
20163 RtModule/PGM instproc register { node } {\n\
20164 $self instvar node_ pgm_classifier_\n\
20165 \n\
20166 set node_ $node\n\
20167 set pgm_classifier_ [new Classifier/Pgm]\n\
20168 set pgm_agent [new Agent/PGM]\n\
20169 $node attach $pgm_agent\n\
20170 $node set-pgm $pgm_agent\n\
20171 $node insert-entry $self $pgm_classifier_ 0\n\
20172 $pgm_classifier_ install 1 $pgm_agent\n\
20173 }\n\
20174 \n\
20175 RtModule/PGM instproc get-outlink { iface } {\n\
20176 $self instvar node_\n\
20177 \n\
20178 set oif [$node_ iif2oif $iface]\n\
20179 return $oif    \n\
20180 }\n\
20181 \n\
20182 Node instproc ifaceGetOutLink { iface } {\n\
20183 $self instvar ns_\n\
20184 set link [$self iif2link $iface]\n\
20185 set outlink [$ns_ link $self [$link src]]\n\
20186 set head [$outlink set head_]\n\
20187 return $head\n\
20188 }\n\
20189 \n\
20190 \n\
20191 Node instproc set-switch agent {\n\
20192 $self instvar switch_\n\
20193 set switch_ $agent\n\
20194 }\n\
20195 \n\
20196 Node instproc agent port {\n\
20197 $self instvar agents_\n\
20198 foreach a $agents_ {\n\
20199 if { [$a set agent_port_] == $port } {\n\
20200 return $a\n\
20201 }\n\
20202 }\n\
20203 return \"\"\n\
20204 }\n\
20205 \n\
20206 Node instproc set-pgm agent {\n\
20207 $self instvar pgm_agent_\n\
20208 set pgm_agent_ $agent\n\
20209 }\n\
20210 \n\
20211 Node instproc get-pgm {} {\n\
20212 $self instvar pgm_agent_\n\
20213 return $pgm_agent_\n\
20214 }\n\
20215 \n\
20216 \n\
20217 Simulator instproc detach-lossmodel {lossobj from to} {\n\
20218 set link [$self link $from $to]\n\
20219 set head [$link head]\n\
20220 $head target [$lossobj target]\n\
20221 }\n\
20222 \n\
20223 Agent/PGM/Sender instproc init {} {\n\
20224 eval $self next\n\
20225 set ns [Simulator instance]\n\
20226 $ns create-eventtrace Event $self\n\
20227 }\n\
20228 \n\
20229 Agent/PGM/Receiver instproc init {} {\n\
20230 eval $self next\n\
20231 set ns [Simulator instance]\n\
20232 $ns create-eventtrace Event $self\n\
20233 }\n\
20234 \n\
20235 Agent/PGM instproc init {} {\n\
20236 eval $self next\n\
20237 set ns [Simulator instance]\n\
20238 $ns create-eventtrace Event $self\n\
20239 }\n\
20240 \n\
20241 \n\
20242 \n\
20243 \n\
20244 Agent/rtProto/LS set UNREACHABLE  [rtObject set unreach_]\n\
20245 Agent/rtProto/LS set preference_        120\n\
20246 Agent/rtProto/LS set INFINITY           [Agent set ttl_]\n\
20247 Agent/rtProto/LS set advertInterval     1800\n\
20248 \n\
20249 Agent/rtProto/LS proc init-all args {\n\
20250 if { [llength $args] == 0 } {\n\
20251 set nodeslist [[Simulator instance] all-nodes-list]\n\
20252 } else { \n\
20253 eval \"set nodeslist $args\"\n\
20254 }\n\
20255 Agent set-maxttl Agent/rtProto/LS INFINITY\n\
20256 eval rtObject init-all $nodeslist\n\
20257 foreach node $nodeslist {\n\
20258 set proto($node) [[$node rtObject?] add-proto LS $node]\n\
20259 }\n\
20260 foreach node $nodeslist {\n\
20261 foreach nbr [$node neighbors] {\n\
20262 set rtobj [$nbr rtObject?]\n\
20263 if { $rtobj == \"\" } {\n\
20264 continue\n\
20265 }\n\
20266 set rtproto [$rtobj rtProto? LS]\n\
20267 if { $rtproto == \"\" } {\n\
20268 continue\n\
20269 }\n\
20270 $proto($node) add-peer $nbr \\\n\
20271 [$rtproto set agent_addr_] \\\n\
20272 [$rtproto set agent_port_]\n\
20273 }\n\
20274 }\n\
20275 \n\
20276 set first_node [lindex $nodeslist 0 ]\n\
20277 foreach node $nodeslist {\n\
20278 set rtobj [$node rtObject?]\n\
20279 if { $rtobj == \"\" } {\n\
20280 continue\n\
20281 }\n\
20282 set rtproto [$rtobj rtProto? LS]\n\
20283 if { $rtproto == \"\" } {\n\
20284 continue\n\
20285 }\n\
20286 $rtproto cmd initialize\n\
20287 if { $node == $first_node } {\n\
20288 $rtproto cmd setNodeNumber \\\n\
20289 [[Simulator instance] get-number-of-nodes]\n\
20290 }\n\
20291 }\n\
20292 }\n\
20293 \n\
20294 Agent/rtProto/LS instproc init node {\n\
20295 global rtglibRNG\n\
20296 \n\
20297 $self next $node\n\
20298 $self instvar ns_ rtObject_ ifsUp_ rtsChanged_ rtpref_ nextHop_ \\\n\
20299 nextHopPeer_ metric_ multiPath_\n\
20300 Agent/rtProto/LS instvar preference_ \n\
20301 \n\
20302 ;# -- LS stuffs -- \n\
20303 $self instvar LS_ready\n\
20304 set LS_ready 0\n\
20305 set rtsChanged_ 1\n\
20306 \n\
20307 set UNREACHABLE [$class set UNREACHABLE]\n\
20308 foreach dest [$ns_ all-nodes-list] {\n\
20309 set rtpref_($dest) $preference_\n\
20310 set nextHop_($dest) \"\"\n\
20311 set nextHopPeer_($dest) \"\"\n\
20312 set metric_($dest)  $UNREACHABLE\n\
20313 }\n\
20314 set ifsUp_ \"\"\n\
20315 set multiPath_ [[$rtObject_ set node_] set multiPath_]\n\
20316 set updateTime [$rtglibRNG uniform 0.0 0.5]\n\
20317 $ns_ at $updateTime \"$self send-periodic-update\"\n\
20318 }\n\
20319 \n\
20320 Agent/rtProto/LS instproc add-peer {nbr agentAddr agentPort} {\n\
20321 $self instvar peers_\n\
20322 $self set peers_($nbr) [new rtPeer $agentAddr $agentPort $class]\n\
20323 }\n\
20324 \n\
20325 Agent/rtProto/LS instproc send-periodic-update {} {\n\
20326 global rtglibRNG\n\
20327 \n\
20328 $self instvar ns_\n\
20329 \n\
20330 $self cmd sendUpdates\n\
20331 \n\
20332 set updateTime [expr [$ns_ now] + ([$class set advertInterval] * \\\n\
20333 [$rtglibRNG uniform 0.5 1.5])]\n\
20334 $ns_ at $updateTime \"$self send-periodic-update\"\n\
20335 }\n\
20336 \n\
20337 Agent/rtProto/LS instproc compute-routes {} {\n\
20338 $self instvar node_\n\
20339 $self cmd computeRoutes\n\
20340 $self install-routes\n\
20341 }\n\
20342 \n\
20343 Agent/rtProto/LS instproc intf-changed {} {\n\
20344 $self instvar ns_ peers_ ifs_ ifstat_ ifsUp_ nextHop_ \\\n\
20345 nextHopPeer_ metric_\n\
20346 set INFINITY [$class set INFINITY]\n\
20347 set ifsUp_ \"\"\n\
20348 foreach nbr [lsort -dictionary [array names peers_]] {\n\
20349 set state [$ifs_($nbr) up?]\n\
20350 if {$state != $ifstat_($nbr)} {\n\
20351 set ifstat_($nbr) $state\n\
20352 }\n\
20353 }\n\
20354 $self cmd intfChanged\n\
20355 $self route-changed\n\
20356 }\n\
20357 \n\
20358 ;# called by C++ whenever a LSA or Topo causes a change in the routing table\n\
20359 Agent/rtProto/LS instproc route-changed {} {\n\
20360 $self instvar node_ \n\
20361 \n\
20362 $self instvar rtObject_  rtsChanged_\n\
20363 $self install-routes\n\
20364 set rtsChanged_ 1\n\
20365 $rtObject_ compute-routes\n\
20366 }\n\
20367 \n\
20368 Agent/rtProto/LS instproc install-routes {} {\n\
20369 $self instvar ns_ ifs_ rtpref_ metric_ nextHop_ nextHopPeer_\n\
20370 $self instvar peers_ rtsChanged_ multiPath_\n\
20371 $self instvar node_  preference_ \n\
20372 \n\
20373 set INFINITY [$class set INFINITY]\n\
20374 set MAXPREF  [rtObject set maxpref_]\n\
20375 set UNREACH  [rtObject set unreach_]\n\
20376 set rtsChanged_ 1 \n\
20377 \n\
20378 foreach dst [$ns_ all-nodes-list] {\n\
20379 if { $dst == $node_ } {\n\
20380 set metric_($dst) 32  ;# the magic number\n\
20381 continue\n\
20382 }\n\
20383 set path [$self cmd lookup [$dst id]]\n\
20384 if { [llength $path ] == 0 } {\n\
20385 set rtpref_($dst) $MAXPREF\n\
20386 set metric_($dst) $UNREACH\n\
20387 set nextHop_($dst) \"\"\n\
20388 continue\n\
20389 }\n\
20390 set cost [lindex $path 0]\n\
20391 set rtpref_($dst) $preference_\n\
20392 set metric_($dst) $cost\n\
20393 \n\
20394 if { ! $multiPath_ } {\n\
20395 set nhNode [$ns_ get-node-by-id [lindex $path 1]]\n\
20396 set nextHop_($dst) $ifs_($nhNode)\n\
20397 continue\n\
20398 }\n\
20399 set nextHop_($dst) \"\"\n\
20400 set nh \"\"\n\
20401 set count [llength $path]\n\
20402 foreach nbr [lsort -dictionary [array names peers_]] {\n\
20403 foreach nhId [lrange $path 1 $count ] {\n\
20404 if { [$nbr id] == $nhId } {\n\
20405 lappend nextHop_($dst) $ifs_($nbr)\n\
20406 break\n\
20407 }\n\
20408 }\n\
20409 }\n\
20410 }\n\
20411 }\n\
20412 \n\
20413 Agent/rtProto/LS instproc send-updates changes {\n\
20414 $self cmd send-buffered-messages\n\
20415 }\n\
20416 \n\
20417 Agent/rtProto/LS proc compute-all {} {\n\
20418 }\n\
20419 \n\
20420 Agent/rtProto/LS instproc get-node-id {} {\n\
20421 $self instvar node_\n\
20422 return [$node_ id]\n\
20423 }\n\
20424 \n\
20425 Agent/rtProto/LS instproc get-links-status {} {\n\
20426 $self instvar ifs_ ifstat_ \n\
20427 set linksStatus \"\"\n\
20428 foreach nbr [array names ifs_] {\n\
20429 lappend linksStatus [$nbr id]\n\
20430 if {[$ifs_($nbr) up?] == \"up\"} {\n\
20431 lappend linksStatus 1\n\
20432 } else {\n\
20433 lappend linksStatus 0\n\
20434 }\n\
20435 lappend linksStatus [$ifs_($nbr) cost?]\n\
20436 }\n\
20437 set linksStatus\n\
20438 }\n\
20439 \n\
20440 Agent/rtProto/LS instproc get-peers {} {\n\
20441 $self instvar peers_\n\
20442 set peers \"\"\n\
20443 foreach nbr [lsort -dictionary [array names peers_]] {\n\
20444 lappend peers [$nbr id]\n\
20445 lappend peers [$peers_($nbr) addr?]\n\
20446 lappend peers [$peers_($nbr) port?]\n\
20447 }\n\
20448 set peers\n\
20449 }\n\
20450 \n\
20451 Agent/rtProto/LS instproc get-delay-estimates {} {\n\
20452 $self instvar ifs_ ifstat_ \n\
20453 set total_delays \"\"\n\
20454 set packet_size 8000.0 ;# bits\n\
20455 foreach nbr [array names ifs_] {\n\
20456 set intf $ifs_($nbr)\n\
20457 set q_limit [ [$intf queue ] set limit_]\n\
20458 set bw [bw_parse [ [$intf link ] set bandwidth_ ] ]\n\
20459 set p_delay [time_parse [ [$intf link ] set delay_] ]\n\
20460 set total_delay [expr $q_limit * $packet_size / $bw + $p_delay]\n\
20461 $self cmd setDelay [$nbr id] $total_delay\n\
20462 }\n\
20463 }\n\
20464 }\n\
20465 \n\
20466 \n\
20467 RtModule/QS instproc register { node } {\n\
20468 $self next $node\n\
20469 \n\
20470 $self instvar classifier_ \n\
20471 $self set classifier_ [$node entry]\n\
20472 \n\
20473 $node set qs_classifier_ [new Classifier/QS]\n\
20474 $node set qs_agent_ [new Agent/QSAgent]\n\
20475 $node set switch_ [$node set qs_classifier_]\n\
20476 \n\
20477 $node insert-entry $self [$node set switch_] 1\n\
20478 \n\
20479 [$node set switch_] install 0 [$node set qs_agent_]\n\
20480 $node attach [$node set qs_agent_]\n\
20481 [$node set qs_agent_] set old_classifier_ $classifier_\n\
20482 \n\
20483 }\n\
20484 \n\
20485 Simulator instproc QS { val } {\n\
20486 if { $val == \"ON\" } {\n\
20487 add-packet-header \"TCP_QS\"\n\
20488 Node enable-module \"QS\"\n\
20489 } else {\n\
20490 Node disable-module \"QS\"\n\
20491 remove-packet-header \"TCP_QS\"\n\
20492 }\n\
20493 }\n\
20494 \n\
20495 Node instproc qs-agent {} {\n\
20496 $self instvar qs_agent_\n\
20497 return $qs_agent_\n\
20498 }\n\
20499 \n\
20500 Simulator instproc get-queue { addr daddr } {\n\
20501 $self instvar routingTable_\n\
20502 \n\
20503 set srcid [$self get-node-id-by-addr $addr]\n\
20504 set dstid [$self get-node-id-by-addr $daddr]\n\
20505 \n\
20506 set nexthop [$routingTable_ lookup $srcid $dstid]\n\
20507 \n\
20508 set node1 [$self  get-node-by-addr $addr]\n\
20509 set node2 [$self  get-node-by-addr $nexthop]\n\
20510 \n\
20511 set queue_ [[$self link $node1 $node2] queue]\n\
20512 \n\
20513 return $queue_\n\
20514 }       \n\
20515 \n\
20516 Simulator instproc get-link { addr daddr } {\n\
20517 $self instvar routingTable_\n\
20518 \n\
20519 set srcid [$self get-node-id-by-addr $addr]\n\
20520 set dstid [$self get-node-id-by-addr $daddr]\n\
20521 \n\
20522 set nexthop [$routingTable_ lookup $srcid $dstid]\n\
20523 \n\
20524 set node1 [$self  get-node-by-addr $addr]\n\
20525 set node2 [$self  get-node-by-addr $nexthop]\n\
20526 \n\
20527 set link_ [[$self  link $node1 $node2] link]\n\
20528 \n\
20529 return $link_\n\
20530 }\n\
20531 \n\
20532 \n\
20533 Simulator instproc init args {\n\
20534 \n\
20535 \n\
20536 $self instvar useasim_\n\
20537 $self instvar slinks_\n\
20538 $self instvar nconn_\n\
20539 $self instvar sflows_\n\
20540 $self instvar nsflows_\n\
20541 \n\
20542 set slinks_(0:0) 0\n\
20543 set nconn_ 0\n\
20544 set conn_ \"\"\n\
20545 set sflows_ \"\" \n\
20546 set nsflows_ 0\n\
20547 set useasim_ 0\n\
20548 \n\
20549 $self create_packetformat\n\
20550 $self use-scheduler Calendar\n\
20551 $self set nullAgent_ [new Agent/Null]\n\
20552 $self set-address-format def\n\
20553 if {[lindex $args 0] == \"-multicast\"} {\n\
20554 $self multicast $args\n\
20555 }\n\
20556 eval $self next $args\n\
20557 }\n\
20558 \n\
20559 Simulator instproc nullagent {} {\n\
20560 $self instvar nullAgent_\n\
20561 return $nullAgent_\n\
20562 }\n\
20563 \n\
20564 Simulator instproc use-scheduler type {\n\
20565 $self instvar scheduler_\n\
20566 if [info exists scheduler_] {\n\
20567 if { [$scheduler_ info class] == \"Scheduler/$type\" } {\n\
20568 return\n\
20569 } else {\n\
20570 delete $scheduler_\n\
20571 }\n\
20572 }\n\
20573 set scheduler_ [new Scheduler/$type]\n\
20574 $scheduler_ now\n\
20575 }\n\
20576 \n\
20577 Simulator instproc delay_parse { spec } {\n\
20578 return [time_parse $spec]\n\
20579 }\n\
20580 \n\
20581 Simulator instproc bw_parse { spec } {\n\
20582 return [bw_parse $spec]\n\
20583 }\n\
20584 \n\
20585 Simulator instproc dumper obj {\n\
20586 set t [$self alloc-trace hop stdout]\n\
20587 $t target $obj\n\
20588 return $t\n\
20589 }\n\
20590 \n\
20591 \n\
20592 \n\
20593 Simulator instproc addressType  {val} { $self set addressType_  $val }\n\
20594 Simulator instproc adhocRouting  {val} { $self set routingAgent_  $val }\n\
20595 Simulator instproc llType  {val} { $self set llType_  $val }\n\
20596 Simulator instproc macType  {val} { $self set macType_  $val }\n\
20597 Simulator instproc propType  {val} { $self set propType_  $val }\n\
20598 Simulator instproc propInstance  {val} { $self set propInstance_  $val }\n\
20599 Simulator instproc ifqType  {val} { $self set ifqType_  $val }\n\
20600 Simulator instproc ifqLen  {val} { $self set ifqlen_  $val }\n\
20601 Simulator instproc phyType  {val} { $self set phyType_  $val }\n\
20602 Simulator instproc antType  {val} { $self set antType_  $val }\n\
20603 Simulator instproc channel {val} {$self set channel_ $val}\n\
20604 Simulator instproc channelType {val} {$self set channelType_ $val}\n\
20605 Simulator instproc topoInstance {val} {$self set topoInstance_ $val}\n\
20606 Simulator instproc wiredRouting {val} {$self set wiredRouting_ $val}\n\
20607 Simulator instproc mobileIP {val} {$self set mobileIP_ $val}\n\
20608 Simulator instproc energyModel  {val} { $self set energyModel_  $val }\n\
20609 Simulator instproc initialEnergy  {val} { $self set initialEnergy_  $val }\n\
20610 Simulator instproc txPower  {val} { $self set txPower_  $val }\n\
20611 Simulator instproc rxPower  {val} { $self set rxPower_  $val }\n\
20612 Simulator instproc idlePower  {val} { $self set idlePower_  $val }\n\
20613 Simulator instproc sleepPower  {val} { $self set sleepPower_  $val }\n\
20614 Simulator instproc transitionPower  {val} { $self set transitionPower_  $val }\n\
20615 Simulator instproc transitionTime  {val} { $self set transitionTime_  $val }\n\
20616 Simulator instproc IncomingErrProc  {val} { $self set inerrProc_  $val }\n\
20617 Simulator instproc OutgoingErrProc  {val} { $self set outerrProc_  $val }\n\
20618 Simulator instproc FECProc  {val} { $self set FECProc_  $val }\n\
20619 Simulator instproc agentTrace  {val} { $self set agentTrace_  $val }\n\
20620 Simulator instproc routerTrace  {val} { $self set routerTrace_  $val }\n\
20621 Simulator instproc macTrace  {val} { $self set macTrace_  $val }\n\
20622 Simulator instproc movementTrace  {val} { $self set movementTrace_  $val }\n\
20623 Simulator instproc toraDebug {val} {$self set toraDebug_ $val }\n\
20624 Simulator instproc satNodeType {val} {$self set satNodeType_ $val}\n\
20625 Simulator instproc downlinkBW {val} {$self set downlinkBW_ $val}\n\
20626 Simulator instproc stopTime {val} {$self set stopTime_ $val}\n\
20627 \n\
20628 Simulator instproc eotTrace  {val} { $self set eotTrace_  $val }\n\
20629 Simulator instproc diffusionFilter {val} {$self set diffFilter_ $val}\n\
20630 \n\
20631 Simulator instproc MPLS { val } { \n\
20632 if { $val == \"ON\" } {\n\
20633 Node enable-module \"MPLS\"\n\
20634 } else {\n\
20635 Node disable-module \"MPLS\"\n\
20636 }\n\
20637 }\n\
20638 \n\
20639 \n\
20640 Simulator instproc PGM { val } { \n\
20641 if { $val == \"ON\" } {\n\
20642 Node enable-module \"PGM\"\n\
20643 } else {\n\
20644 Node disable-module \"PGM\"\n\
20645 }\n\
20646 }\n\
20647 Simulator instproc LMS { val } {\n\
20648 if { $val == \"ON\" } {\n\
20649 Node enable-module \"LMS\"\n\
20650 } else {\n\
20651 Node disable-module \"LMS\"\n\
20652 }\n\
20653 }\n\
20654 \n\
20655 Simulator instproc get-nodetype {} {\n\
20656 $self instvar addressType_ routingAgent_ wiredRouting_ \n\
20657 set val \"\"\n\
20658 \n\
20659 if { [info exists addressType_] && $addressType_ == \"hierarchical\" } {\n\
20660 set val Hier\n\
20661 }\n\
20662 if { [info exists routingAgent_] && $routingAgent_ != \"\" } {\n\
20663 set val Mobile\n\
20664 }\n\
20665 if { [info exists wiredRouting_] && $wiredRouting_ == \"ON\" } {\n\
20666 set val Base\n\
20667 }\n\
20668 if { [info exists wiredRouting_] && $wiredRouting_ == \"OFF\"} {\n\
20669 set val Base\n\
20670 }\n\
20671 if { [Simulator set mobile_ip_] } {\n\
20672 if { $val == \"Base\" && $wiredRouting_ == \"ON\" } {\n\
20673 set val MIPBS\n\
20674 }\n\
20675 if { $val == \"Base\" && $wiredRouting_ == \"OFF\" } {\n\
20676 set val MIPMH\n\
20677 }\n\
20678 }\n\
20679 return $val\n\
20680 }\n\
20681 \n\
20682 Simulator instproc node-config args {\n\
20683 set args [eval $self init-vars $args]\n\
20684 \n\
20685 $self instvar addressType_  routingAgent_ propType_  macTrace_ \\\n\
20686 routerTrace_ agentTrace_ movementTrace_ channelType_ channel_ \\\n\
20687 chan topoInstance_ propInstance_ mobileIP_ \\\n\
20688 rxPower_ txPower_ idlePower_ sleepPower_ transitionPower_ \\\n\
20689 transitionTime_ satNodeType_ eotTrace_\n\
20690 \n\
20691 if [info exists macTrace_] {\n\
20692 Simulator set MacTrace_ $macTrace_\n\
20693 }\n\
20694 if [info exists routerTrace_] {\n\
20695 Simulator set RouterTrace_ $routerTrace_\n\
20696 }\n\
20697 if [info exists agentTrace_] {\n\
20698 Simulator set AgentTrace_ $agentTrace_\n\
20699 }\n\
20700 if [info exists movementTrace_] {\n\
20701 Simulator set MovementTrace_ $movementTrace_\n\
20702 }\n\
20703 \n\
20704 if [info exists eotTrace_] {\n\
20705 Simulator set EotTrace_ $eotTrace_\n\
20706 }\n\
20707 \n\
20708 if {[info exists propInstance_]} {\n\
20709 if {[info exists propType_] && [Simulator set propInstCreated_] == 0} {\n\
20710 warn \"Both propType and propInstance are set. propType is ignored.\"\n\
20711 }\n\
20712 } else {\n\
20713 if {[info exists propType_]} {\n\
20714 set propInstance_ [new $propType_]\n\
20715 Simulator set propInstCreated_ 1\n\
20716 }\n\
20717 }\n\
20718 \n\
20719 if {[info exists channelType_] && [info exists channel_]} { \n\
20720 error \"Can't specify both channel and channelType, error!\"\n\
20721 } elseif {[info exists channelType_] && ![info exists satNodeType_]} {\n\
20722 warn \"Please use -channel as shown in tcl/ex/wireless-mitf.tcl\"\n\
20723 if {![info exists chan]} {\n\
20724 set chan [new $channelType_]\n\
20725 }\n\
20726 } elseif {[info exists channel_]} {\n\
20727 set chan $channel_\n\
20728 }\n\
20729 if [info exists topoInstance_] {\n\
20730 $propInstance_  topography $topoInstance_\n\
20731 }\n\
20732 if {[string compare $addressType_ \"\"] != 0} {\n\
20733 $self set-address-format $addressType_ \n\
20734 }\n\
20735 if { [info exists mobileIP_] && $mobileIP_ == \"ON\"} {\n\
20736 Simulator set mobile_ip_  1\n\
20737 } else {\n\
20738 if { [info exists mobileIP_] } {\n\
20739 Simulator set mobile_ip_ 0\n\
20740 }\n\
20741 }\n\
20742 }\n\
20743 \n\
20744 Simulator instproc node args {\n\
20745 $self instvar Node_ routingAgent_ wiredRouting_ satNodeType_\n\
20746 if { [Simulator info vars EnableMcast_] != \"\" } {\n\
20747 warn \"Flag variable Simulator::EnableMcast_ discontinued.\\n\\t\\\n\
20748 Use multicast methods as:\\n\\t\\t\\\n\
20749 % set ns \\[new Simulator -multicast on]\\n\\t\\t\\\n\
20750 % \\$ns multicast\"\n\
20751 $self multicast\n\
20752 Simulator unset EnableMcast_\n\
20753 }\n\
20754 if { [Simulator info vars NumberInterfaces_] != \"\" } {\n\
20755 warn \"Flag variable Simulator::NumberInterfaces_ discontinued.\\n\\t\\\n\
20756 Setting this variable will not affect simulations.\"\n\
20757 Simulator unset NumberInterfaces_\n\
20758 }\n\
20759 \n\
20760 if { [info exists satNodeType_] } {\n\
20761 set node [eval $self create-satnode]\n\
20762 if {[info exists wiredRouting_] && $wiredRouting_ == \"ON\"} {\n\
20763 $self add-node $node [$node id]\n\
20764 SatRouteObject set wiredRouting_ true\n\
20765 }\n\
20766 return $node\n\
20767 }\n\
20768 \n\
20769 if { [info exists routingAgent_] && ($routingAgent_ != \"\") } {\n\
20770 set node [eval $self create-wireless-node $args]\n\
20771 if {[info exists wiredRouting_] && $wiredRouting_ == \"ON\"} {\n\
20772 set Node_([$node id]) $node\n\
20773 $self add-node $node [$node id] \n\
20774 }\n\
20775 return $node\n\
20776 }\n\
20777 \n\
20778 \n\
20779 set node [eval new [Simulator set node_factory_] $args]\n\
20780 set Node_([$node id]) $node\n\
20781 \n\
20782 $self add-node $node [$node id] \n\
20783 \n\
20784 $node nodeid [$node id]\n\
20785 \n\
20786 $node set ns_ $self\n\
20787 $self check-node-num\n\
20788 return $node\n\
20789 }\n\
20790 \n\
20791 Simulator instproc imep-support {} {\n\
20792 return [Simulator set IMEPFlag_]\n\
20793 }\n\
20794 \n\
20795 Simulator instproc create-wireless-node args {\n\
20796 $self instvar routingAgent_ wiredRouting_ propInstance_ llType_ \\\n\
20797 macType_ ifqType_ ifqlen_ phyType_ chan antType_ \\\n\
20798 energyModel_ initialEnergy_ txPower_ rxPower_ \\\n\
20799 idlePower_ sleepPower_ transitionPower_ transitionTime_ \\\n\
20800 topoInstance_ level1_ level2_ inerrProc_ outerrProc_ FECProc_\n\
20801 \n\
20802 Simulator set IMEPFlag_ OFF\n\
20803 \n\
20804 set node [eval $self create-node-instance $args]\n\
20805 \n\
20806 if { [info exist wiredRouting_] && $wiredRouting_ == \"ON\" } {\n\
20807 $node base-station [AddrParams addr2id [$node node-addr]]\n\
20808 }\n\
20809 switch -exact $routingAgent_ {\n\
20810 DSDV {\n\
20811 set ragent [$self create-dsdv-agent $node]\n\
20812 }\n\
20813 DSR {\n\
20814 $self at 0.0 \"$node start-dsr\"\n\
20815 }\n\
20816 AODV {\n\
20817 set ragent [$self create-aodv-agent $node]\n\
20818 }\n\
20819 TORA {\n\
20820 Simulator set IMEPFlag_ ON\n\
20821 set ragent [$self create-tora-agent $node]\n\
20822 }\n\
20823 DIFFUSION/RATE {\n\
20824 eval $node addr $args\n\
20825 set ragent [$self create-diffusion-rate-agent $node]\n\
20826 }\n\
20827 DIFFUSION/PROB {\n\
20828 eval $node addr $args\n\
20829 set ragent [$self create-diffusion-probability-agent $node]\n\
20830 }\n\
20831 Directed_Diffusion {\n\
20832 eval $node addr $args\n\
20833 set ragent [$self create-core-diffusion-rtg-agent $node]\n\
20834 }\n\
20835 FLOODING {\n\
20836 eval $node addr $args\n\
20837 set ragent [$self create-flooding-agent $node]\n\
20838 }\n\
20839 OMNIMCAST {\n\
20840 eval $node addr $args\n\
20841 set ragent [$self create-omnimcast-agent $node]\n\
20842 }\n\
20843 DumbAgent {\n\
20844 set ragent [$self create-dumb-agent $node]\n\
20845 }\n\
20846 ManualRtg {\n\
20847 set ragent [$self create-manual-rtg-agent $node]\n\
20848 }\n\
20849 default {\n\
20850 eval $node addr $args\n\
20851 puts \"Wrong node routing agent!\"\n\
20852 exit\n\
20853 }\n\
20854 }\n\
20855 \n\
20856 if ![info exist inerrProc_] {\n\
20857 set inerrProc_ \"\"\n\
20858 }\n\
20859 if ![info exist outerrProc_] {\n\
20860 set outerrProc_ \"\"\n\
20861 }\n\
20862 if ![info exist FECProc_] {\n\
20863 set FECProc_ \"\"\n\
20864 }\n\
20865 \n\
20866 \n\
20867 \n\
20868 $node add-interface $chan $propInstance_ $llType_ $macType_ \\\n\
20869 $ifqType_ $ifqlen_ $phyType_ $antType_ $topoInstance_ \\\n\
20870 $inerrProc_ $outerrProc_ $FECProc_\n\
20871 if {$routingAgent_ != \"DSR\"} {\n\
20872 $node attach $ragent [Node set rtagent_port_]\n\
20873 }\n\
20874 if {$routingAgent_ == \"DIFFUSION/RATE\" ||\n\
20875 $routingAgent_ == \"DIFFUSION/PROB\" ||\n\
20876 $routingAgent_ == \"FLOODING\" ||\n\
20877 $routingAgent_ == \"OMNIMCAST\" ||\n\
20878 $routingAgent_ == \"Directed_Diffusion\" } {\n\
20879 $ragent port-dmux [$node demux]\n\
20880 $node instvar ll_\n\
20881 $ragent add-ll $ll_(0)\n\
20882 }\n\
20883 if { $routingAgent_ == \"DumbAgent\" } {\n\
20884 $ragent port-dmux [$node demux]\n\
20885 }\n\
20886 \n\
20887 \n\
20888 if { [info exist wiredRouting_] && $wiredRouting_ == \"ON\" } {\n\
20889 if { $routingAgent_ != \"DSR\" } {\n\
20890 $node mip-call $ragent\n\
20891 }\n\
20892 }\n\
20893 set tracefd [$self get-ns-traceall]\n\
20894 if {$tracefd != \"\" } {\n\
20895 $node nodetrace $tracefd\n\
20896 $node agenttrace $tracefd\n\
20897 }\n\
20898 set namtracefd [$self get-nam-traceall]\n\
20899 if {$namtracefd != \"\" } {\n\
20900 $node namattach $namtracefd\n\
20901 }\n\
20902 if [info exists energyModel_] {\n\
20903 if  [info exists level1_] {\n\
20904 set l1 $level1_\n\
20905 } else {\n\
20906 set l1 0.5\n\
20907 }\n\
20908 if  [info exists level2_] {\n\
20909 set l2 $level2_\n\
20910 } else {\n\
20911 set l2 0.2\n\
20912 }\n\
20913 $node addenergymodel [new $energyModel_ $node \\\n\
20914 $initialEnergy_ $l1 $l2]\n\
20915 }\n\
20916 if [info exists txPower_] {\n\
20917 $node setPt $txPower_\n\
20918 }\n\
20919 if [info exists rxPower_] {\n\
20920 $node setPr $rxPower_\n\
20921 }\n\
20922 if [info exists idlePower_] {\n\
20923 $node setPidle $idlePower_\n\
20924 }\n\
20925 if [info exists sleepPower_] {\n\
20926 $node setPsleep $sleepPower_\n\
20927 }\n\
20928 if [info exists transitionPower_] {\n\
20929 $node setPtransition $transitionPower_\n\
20930 }\n\
20931 if [info exists transitionTime_] {\n\
20932 $node setTtransition $transitionTime_\n\
20933 }   \n\
20934 $node topography $topoInstance_\n\
20935 \n\
20936 return $node\n\
20937 }\n\
20938 \n\
20939 Simulator instproc create-node-instance args {\n\
20940 $self instvar routingAgent_\n\
20941 if {$routingAgent_ == \"DSR\"} {\n\
20942 set nodeclass [$self set-dsr-nodetype]\n\
20943 } else {\n\
20944 set nodeclass Node/MobileNode\n\
20945 }\n\
20946 return [eval new $nodeclass $args]\n\
20947 }\n\
20948 \n\
20949 Simulator instproc set-dsr-nodetype {} {\n\
20950 $self instvar wiredRouting_ \n\
20951 set nodetype SRNodeNew\n\
20952 if [Simulator set mobile_ip_] {\n\
20953 set nodetype SRNodeNew/MIPMH\n\
20954 } \n\
20955 if { [info exists wiredRouting_] && $wiredRouting_ == \"ON\"} {\n\
20956 set nodetype Node/MobileNode/BaseStationNode\n\
20957 }\n\
20958 return $nodetype\n\
20959 }\n\
20960 \n\
20961 Simulator instproc create-tora-agent { node } {\n\
20962 set ragent [new Agent/TORA [$node id]]\n\
20963 $node set ragent_ $ragent\n\
20964 return $ragent\n\
20965 }\n\
20966 \n\
20967 Simulator instproc create-dsdv-agent { node } {\n\
20968 set ragent [new Agent/DSDV]\n\
20969 set addr [$node node-addr]\n\
20970 $ragent addr $addr\n\
20971 $ragent node $node\n\
20972 if [Simulator set mobile_ip_] {\n\
20973 $ragent port-dmux [$node demux]\n\
20974 }\n\
20975 $node addr $addr\n\
20976 $node set ragent_ $ragent\n\
20977 $self at 0.0 \"$ragent start-dsdv\"    ;# start updates\n\
20978 return $ragent\n\
20979 }\n\
20980 \n\
20981 \n\
20982 Simulator instproc create-dumb-agent { node } {\n\
20983 \n\
20984 \n\
20985 set ragent [new Agent/DumbAgent]\n\
20986 $node set ragent_ $ragent\n\
20987 \n\
20988 return $ragent\n\
20989 }\n\
20990 \n\
20991 Simulator instproc create-manual-rtg-agent { node } {\n\
20992 \n\
20993 \n\
20994 set ragent [new Agent/ManualRtgAgent]\n\
20995 $node set ragent_ $ragent\n\
20996 $node attach $ragent [Node set rtagent_port_]\n\
20997 \n\
20998 return $ragent\n\
20999 }\n\
21000 \n\
21001 Simulator instproc create-aodv-agent { node } {\n\
21002 set ragent [new Agent/AODV [$node node-addr]]\n\
21003 $self at 0.0 \"$ragent start\"     ;# start BEACON/HELLO Messages\n\
21004 $node set ragent_ $ragent\n\
21005 return $ragent\n\
21006 }\n\
21007 \n\
21008 Simulator instproc use-newtrace {} {\n\
21009 Simulator set WirelessNewTrace_ 1\n\
21010 } \n\
21011 \n\
21012 Simulator instproc use-taggedtrace { {tag ON} } {\n\
21013 Simulator set TaggedTrace_ $tag\n\
21014 }\n\
21015 \n\
21016 Simulator instproc hier-node haddr {\n\
21017 error \"hier-nodes should be created with [$ns_ node $haddr]\"\n\
21018 }\n\
21019 \n\
21020 Simulator instproc now {} {\n\
21021 $self instvar scheduler_\n\
21022 return [$scheduler_ now]\n\
21023 }\n\
21024 \n\
21025 Simulator instproc at args {\n\
21026 $self instvar scheduler_\n\
21027 return [eval $scheduler_ at $args]\n\
21028 }\n\
21029 \n\
21030 Simulator instproc at-now args {\n\
21031 $self instvar scheduler_\n\
21032 return [eval $scheduler_ at-now $args]\n\
21033 }\n\
21034 \n\
21035 Simulator instproc cancel args {\n\
21036 $self instvar scheduler_\n\
21037 return [eval $scheduler_ cancel $args]\n\
21038 }\n\
21039 \n\
21040 Simulator instproc after {ival args} {\n\
21041 eval $self at [expr [$self now] + $ival] $args\n\
21042 }\n\
21043 \n\
21044 Simulator instproc check-node-num {} {\n\
21045 if {[Node set nn_] > [expr pow(2, [AddrParams nodebits])]} {\n\
21046 error \"Number of nodes exceeds node-field-size of [AddrParams nodebits] bits\"\n\
21047 }\n\
21048 }\n\
21049 \n\
21050 Simulator instproc chk-hier-field-lengths {} {\n\
21051 AddrParams instvar domain_num_ cluster_num_ nodes_num_\n\
21052 if [info exists domain_num_] {\n\
21053 if {[expr $domain_num_ - 1]> [AddrParams NodeMask 1]} {\n\
21054 error \"\\# of domains exceed dom-field-size \"\n\
21055 }\n\
21056 } \n\
21057 if [info exists cluster_num_] {\n\
21058 set maxval [expr [find-max $cluster_num_] - 1] \n\
21059 if {$maxval > [expr pow(2, [AddrParams NodeMask 2])]} {\n\
21060 error \"\\# of clusters exceed clus-field-size \"\n\
21061 }\n\
21062 }\n\
21063 if [info exists nodes_num_] {\n\
21064 set maxval [expr [find-max $nodes_num_] -1]\n\
21065 if {$maxval > [expr pow(2, [AddrParams NodeMask 3])]} {\n\
21066 error \"\\# of nodess exceed node-field-size\"\n\
21067 }\n\
21068 }\n\
21069 }\n\
21070 \n\
21071 \n\
21072 Simulator instproc check-smac {} {\n\
21073 $self instvar macType_\n\
21074 if { [info exist macType_] && $macType_ == \"Mac/SMAC\" } {\n\
21075 if { [$macType_ set syncFlag_] } {\n\
21076 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\"\n\
21077 }\n\
21078 }\n\
21079 }\n\
21080 \n\
21081 \n\
21082 Simulator instproc run {} {\n\
21083 $self check-smac                      ;# print warning if in sleep/wakeup cycle\n\
21084 $self check-node-num\n\
21085 $self rtmodel-configure         ;# in case there are any\n\
21086 [$self get-routelogic] configure\n\
21087 $self instvar scheduler_ Node_ link_ started_ \n\
21088 \n\
21089 set started_ 1\n\
21090 \n\
21091 \n\
21092 foreach nn [array names Node_] {\n\
21093 $Node_($nn) reset\n\
21094 if { [Simulator set nix-routing] } {\n\
21095 $Node_($nn) populate-objects\n\
21096 }\n\
21097 }\n\
21098 \n\
21099 \n\
21100 foreach qn [array names link_] {\n\
21101 set q [$link_($qn) queue]\n\
21102 $q reset\n\
21103 }\n\
21104 \n\
21105 $self init-nam\n\
21106 \n\
21107 return [$scheduler_ run]\n\
21108 }\n\
21109 \n\
21110 Simulator instproc log-simstart { } {\n\
21111 global simstart\n\
21112 puts \"Starting Actual Simulation\"\n\
21113 set simstart [clock seconds]\n\
21114 }\n\
21115 \n\
21116 Simulator instproc halt {} {\n\
21117 $self instvar scheduler_\n\
21118 $scheduler_ halt\n\
21119 }\n\
21120 \n\
21121 Simulator instproc dumpq {} {\n\
21122 $self instvar scheduler_\n\
21123 $scheduler_ dumpq\n\
21124 }\n\
21125 \n\
21126 Simulator instproc is-started {} {\n\
21127 $self instvar started_\n\
21128 return [info exists started_]\n\
21129 }\n\
21130 \n\
21131 Simulator instproc clearMemTrace {} {\n\
21132 $self instvar scheduler_\n\
21133 $scheduler_ clearMemTrace\n\
21134 }\n\
21135 \n\
21136 Simulator instproc simplex-link { n1 n2 bw delay qtype args } {\n\
21137 $self instvar link_ queueMap_ nullAgent_ useasim_\n\
21138 set sid [$n1 id]\n\
21139 set did [$n2 id]\n\
21140 \n\
21141 if { $useasim_ == 1 } {\n\
21142 set slink_($sid:$did) $self\n\
21143 }\n\
21144 \n\
21145 if [info exists queueMap_($qtype)] {\n\
21146 set qtype $queueMap_($qtype)\n\
21147 }\n\
21148 set qtypeOrig $qtype\n\
21149 switch -exact $qtype {\n\
21150 ErrorModule {\n\
21151 if { [llength $args] > 0 } {\n\
21152 set q [eval new $qtype $args]\n\
21153 } else {\n\
21154 set q [new $qtype Fid]\n\
21155 }\n\
21156 }\n\
21157 intserv {\n\
21158 set qtype [lindex $args 0]\n\
21159 set q [new Queue/$qtype]\n\
21160 }\n\
21161 default {\n\
21162 if { [llength $args] == 0} {\n\
21163 set q [new Queue/$qtype]\n\
21164 } else {\n\
21165 set q [new Queue/$qtype $args]\n\
21166 }\n\
21167 }\n\
21168 }\n\
21169 switch -exact $qtypeOrig {\n\
21170 RTM {\n\
21171 set c [lindex $args 1]\n\
21172 set link_($sid:$did) [new CBQLink       \\\n\
21173 $n1 $n2 $bw $delay $q $c]\n\
21174 }\n\
21175 CBQ -\n\
21176 CBQ/WRR {\n\
21177 if {[llength $args] == 0} {\n\
21178 set c [new Classifier/Hash/Fid 33]\n\
21179 } else {\n\
21180 set c [lindex $args 0]\n\
21181 }\n\
21182 set link_($sid:$did) [new CBQLink       \\\n\
21183 $n1 $n2 $bw $delay $q $c]\n\
21184 }\n\
21185 FQ      {\n\
21186 set link_($sid:$did) [new FQLink $n1 $n2 $bw $delay $q]\n\
21187 }\n\
21188 intserv {\n\
21189 set link_($sid:$did) [new IntServLink   \\\n\
21190 $n1 $n2 $bw $delay $q   \\\n\
21191 [concat $qtypeOrig $args]]\n\
21192 }\n\
21193 default {\n\
21194 set link_($sid:$did) [new SimpleLink    \\\n\
21195 $n1 $n2 $bw $delay $q]\n\
21196 }\n\
21197 }\n\
21198 if {$qtype == \"RED/Pushback\"} {\n\
21199 set pushback 1\n\
21200 } else {\n\
21201 set pushback 0\n\
21202 }\n\
21203 $n1 add-neighbor $n2 $pushback\n\
21204 \n\
21205 if {[string first \"RED\" $qtype] != -1 || \n\
21206 [string first \"PI\" $qtype] != -1 || \n\
21207 [string first \"Vq\" $qtype] != -1 ||\n\
21208 [string first \"REM\" $qtype] != -1 ||  \n\
21209 [string first \"GK\" $qtype] != -1 ||  \n\
21210 [string first \"RIO\" $qtype] != -1 ||\n\
21211 [string first \"XCP\" $qtype] != -1} {\n\
21212 $q link [$link_($sid:$did) set link_]\n\
21213 }\n\
21214 \n\
21215 set trace [$self get-ns-traceall]\n\
21216 if {$trace != \"\"} {\n\
21217 $self trace-queue $n1 $n2 $trace\n\
21218 }\n\
21219 set trace [$self get-nam-traceall]\n\
21220 if {$trace != \"\"} {\n\
21221 $self namtrace-queue $n1 $n2 $trace\n\
21222 }\n\
21223 \n\
21224 $self register-nam-linkconfig $link_($sid:$did)\n\
21225 }\n\
21226 \n\
21227 Simulator instproc register-nam-linkconfig link {\n\
21228 $self instvar linkConfigList_ link_\n\
21229 if [info exists linkConfigList_] {\n\
21230 set i1 [[$link src] id]\n\
21231 set i2 [[$link dst] id]\n\
21232 if [info exists link_($i2:$i1)] {\n\
21233 set pos [lsearch $linkConfigList_ $link_($i2:$i1)]\n\
21234 if {$pos >= 0} {\n\
21235 set a1 [$link_($i2:$i1) get-attribute \\\n\
21236 \"ORIENTATION\"]\n\
21237 set a2 [$link get-attribute \"ORIENTATION\"]\n\
21238 if {$a1 == \"\" && $a2 != \"\"} {\n\
21239 set linkConfigList_ [lreplace \\\n\
21240 $linkConfigList_ $pos $pos]\n\
21241 } else {\n\
21242 return\n\
21243 }\n\
21244 }\n\
21245 }\n\
21246 set pos [lsearch $linkConfigList_ $link]\n\
21247 if {$pos >= 0} {\n\
21248 set linkConfigList_ \\\n\
21249 [lreplace $linkConfigList_ $pos $pos]\n\
21250 }\n\
21251 }\n\
21252 lappend linkConfigList_ $link\n\
21253 }\n\
21254 \n\
21255 Simulator instproc remove-nam-linkconfig {i1 i2} {\n\
21256 $self instvar linkConfigList_ link_\n\
21257 if ![info exists linkConfigList_] {\n\
21258 return\n\
21259 }\n\
21260 set pos [lsearch $linkConfigList_ $link_($i1:$i2)]\n\
21261 if {$pos >= 0} {\n\
21262 set linkConfigList_ [lreplace $linkConfigList_ $pos $pos]\n\
21263 return\n\
21264 }\n\
21265 set pos [lsearch $linkConfigList_ $link_($i2:$i1)]\n\
21266 if {$pos >= 0} {\n\
21267 set linkConfigList_ [lreplace $linkConfigList_ $pos $pos]\n\
21268 }\n\
21269 }\n\
21270 \n\
21271 Simulator instproc multihome-add-interface { core if } {\n\
21272 $self instvar link_\n\
21273 set coreId [$core id]\n\
21274 set ifId [$if id]\n\
21275 \n\
21276 set bw 1Mb\n\
21277 set delay 100ms\n\
21278 set type DropTail\n\
21279 \n\
21280 if [info exists link_($coreId:$ifId)] {\n\
21281 $self remove-nam-linkconfig $coreId $ifId\n\
21282 }\n\
21283 eval $self simplex-link $core $if $bw $delay $type \n\
21284 if { [Simulator set nix-routing] } {\n\
21285 $n1 set-neighbor [$core id]\n\
21286 $n2 set-neighbor [$if id]\n\
21287 }\n\
21288 \n\
21289 \n\
21290 $core instvar multihome_interfaces_ num_interfaces_\n\
21291 set interface_ {}\n\
21292 \n\
21293 lappend interface_ $if\n\
21294 \n\
21295 lappend interface_ [$link_($coreId:$ifId) set head_]\n\
21296 \n\
21297 lappend multihome_interfaces_ $interface_\n\
21298 }\n\
21299 \n\
21300 Simulator instproc duplex-link { n1 n2 bw delay type args } {\n\
21301 $self instvar link_\n\
21302 set i1 [$n1 id]\n\
21303 set i2 [$n2 id]\n\
21304 if [info exists link_($i1:$i2)] {\n\
21305 $self remove-nam-linkconfig $i1 $i2\n\
21306 }\n\
21307 eval $self simplex-link $n1 $n2 $bw $delay $type $args\n\
21308 eval $self simplex-link $n2 $n1 $bw $delay $type $args\n\
21309 if { [Simulator set nix-routing] } {\n\
21310 $n1 set-neighbor [$n2 id]\n\
21311 $n2 set-neighbor [$n1 id]\n\
21312 }\n\
21313 }\n\
21314 \n\
21315 Simulator instproc duplex-intserv-link { n1 n2 bw pd sched signal adc args } {\n\
21316 eval $self duplex-link $n1 $n2 $bw $pd intserv $sched $signal $adc $args\n\
21317 }\n\
21318 \n\
21319 Simulator instproc simplex-link-op { n1 n2 op args } {\n\
21320 $self instvar link_\n\
21321 eval $link_([$n1 id]:[$n2 id]) $op $args\n\
21322 }\n\
21323 \n\
21324 Simulator instproc duplex-link-op { n1 n2 op args } {\n\
21325 $self instvar link_\n\
21326 eval $link_([$n1 id]:[$n2 id]) $op $args\n\
21327 eval $link_([$n2 id]:[$n1 id]) $op $args\n\
21328 }\n\
21329 \n\
21330 Simulator instproc flush-trace {} {\n\
21331 $self instvar alltrace_\n\
21332 if [info exists alltrace_] {\n\
21333 foreach trace $alltrace_ {\n\
21334 $trace flush\n\
21335 }\n\
21336 }\n\
21337 }\n\
21338 \n\
21339 Simulator instproc namtrace-all file   {\n\
21340 $self instvar namtraceAllFile_\n\
21341 if {$file != \"\"} {\n\
21342 set namtraceAllFile_ $file\n\
21343 } else {\n\
21344 unset namtraceAllFile_\n\
21345 }\n\
21346 }\n\
21347 \n\
21348 Simulator instproc energy-color-change {level1 level2} {\n\
21349 $self instvar level1_ level2_\n\
21350 set level1_ $level1\n\
21351 set level2_ $level2\n\
21352 }\n\
21353 \n\
21354 Simulator instproc namtrace-all-wireless {file optx opty} {\n\
21355 $self instvar namtraceAllFile_\n\
21356 \n\
21357 $self set namNeedsW_ 1\n\
21358 if { $optx != \"\" && $opty != \"\" } {\n\
21359 $self set namWx_ $optx\n\
21360 $self set namWy_ $opty\n\
21361 }\n\
21362 \n\
21363 $self namtrace-all $file\n\
21364 }\n\
21365 \n\
21366 Simulator instproc nam-end-wireless {stoptime} {\n\
21367 $self instvar namtraceAllFile_\n\
21368 \n\
21369 if {$namtraceAllFile_ != \"\"} {\n\
21370 $self puts-nam-config \"W -t $stoptime\"\n\
21371 }\n\
21372 }\n\
21373 \n\
21374 Simulator instproc namtrace-some file {\n\
21375 $self instvar namtraceSomeFile_\n\
21376 set namtraceSomeFile_ $file\n\
21377 }\n\
21378 \n\
21379 \n\
21380 Simulator instproc eventtrace-all {{file \"\"}} {\n\
21381 $self instvar eventTraceAll_ eventtraceAllFile_ traceAllFile_\n\
21382 set eventTraceAll_ 1\n\
21383 if {$file != \"\"} {\n\
21384 set eventtraceAllFile_ $file\n\
21385 } else {\n\
21386 set eventtraceAllFile_ $traceAllFile_\n\
21387 }\n\
21388 \n\
21389 }\n\
21390 \n\
21391 \n\
21392 \n\
21393 Simulator instproc initial_node_pos {nodep size} {\n\
21394 $self instvar addressType_\n\
21395 $self instvar energyModel_ \n\
21396 \n\
21397 if [info exists energyModel_] {  \n\
21398 set nodeColor \"green\"\n\
21399 } else {\n\
21400 set nodeColor \"black\"\n\
21401 }\n\
21402 if { [info exists addressType_] && $addressType_ == \"hierarchical\" } {\n\
21403 $self puts-nam-config \"n -t * -a [$nodep set address_] \\\n\
21404 -s [$nodep id] -x [$nodep set X_] -y [$nodep set Y_] -Z [$nodep set Z_] \\\n\
21405 -z $size -v circle -c $nodeColor\"\n\
21406 } else { \n\
21407 $self puts-nam-config \"n -t * -s [$nodep id] \\\n\
21408 -x [$nodep set X_] -y [$nodep set Y_] -Z [$nodep set Z_] -z $size \\\n\
21409 -v circle -c $nodeColor\"\n\
21410 }\n\
21411 }\n\
21412 \n\
21413 Simulator instproc trace-all file {\n\
21414 $self instvar traceAllFile_\n\
21415 set traceAllFile_ $file\n\
21416 }\n\
21417 \n\
21418 Simulator instproc get-nam-traceall {} {\n\
21419 $self instvar namtraceAllFile_\n\
21420 if [info exists namtraceAllFile_] {\n\
21421 return $namtraceAllFile_\n\
21422 } else {\n\
21423 return \"\"\n\
21424 }\n\
21425 }\n\
21426 \n\
21427 Simulator instproc get-ns-traceall {} {\n\
21428 $self instvar traceAllFile_\n\
21429 if [info exists traceAllFile_] {\n\
21430 return $traceAllFile_\n\
21431 } else {\n\
21432 return \"\"\n\
21433 }\n\
21434 }\n\
21435 \n\
21436 Simulator instproc puts-ns-traceall { str } {\n\
21437 $self instvar traceAllFile_\n\
21438 if [info exists traceAllFile_] {\n\
21439 puts $traceAllFile_ $str\n\
21440 }\n\
21441 }\n\
21442 \n\
21443 Simulator instproc puts-nam-traceall { str } {\n\
21444 $self instvar namtraceAllFile_\n\
21445 if [info exists namtraceAllFile_] {\n\
21446 puts $namtraceAllFile_ $str\n\
21447 } elseif [info exists namtraceSomeFile_] {\n\
21448 puts $namtraceSomeFile_ $str\n\
21449 }\n\
21450 }\n\
21451 \n\
21452 Simulator instproc namtrace-config { f } {\n\
21453 $self instvar namConfigFile_\n\
21454 set namConfigFile_ $f\n\
21455 }\n\
21456 \n\
21457 Simulator instproc get-nam-config {} {\n\
21458 $self instvar namConfigFile_\n\
21459 if [info exists namConfigFile_] {\n\
21460 return $namConfigFile_\n\
21461 } else {\n\
21462 return \"\"\n\
21463 }\n\
21464 }\n\
21465 \n\
21466 Simulator instproc puts-nam-config { str } {\n\
21467 $self instvar namtraceAllFile_ namConfigFile_\n\
21468 \n\
21469 if [info exists namConfigFile_] {\n\
21470 puts $namConfigFile_ $str\n\
21471 } elseif [info exists namtraceAllFile_] {\n\
21472 puts $namtraceAllFile_ $str\n\
21473 } elseif [info exists namtraceSomeFile_] {\n\
21474 puts $namtraceSomeFile_ $str\n\
21475 }\n\
21476 }\n\
21477 \n\
21478 Simulator instproc color { id name } {\n\
21479 $self instvar color_\n\
21480 set color_($id) $name\n\
21481 }\n\
21482 \n\
21483 Simulator instproc get-color { id } {\n\
21484 $self instvar color_\n\
21485 return $color_($id)\n\
21486 }\n\
21487 \n\
21488 Simulator instproc create-trace { type file src dst {op \"\"} } {\n\
21489 $self instvar alltrace_\n\
21490 set p [new Trace/$type]\n\
21491 $p tagged [Simulator set TaggedTrace_]\n\
21492 if [catch {$p set src_ [$src id]}] {\n\
21493 $p set src_ $src\n\
21494 }\n\
21495 if [catch {$p set dst_ [$dst id]}] {\n\
21496 $p set dst_ $dst\n\
21497 }\n\
21498 lappend alltrace_ $p\n\
21499 if {$file != \"\"} {\n\
21500 $p ${op}attach $file        \n\
21501 }\n\
21502 return $p\n\
21503 }\n\
21504 \n\
21505 \n\
21506 Simulator instproc create-eventtrace {type owner } {\n\
21507 $self instvar alltrace_ \n\
21508 $self instvar eventTraceAll_ eventtraceAllFile_ namtraceAllFile_\n\
21509 \n\
21510 if ![info exists eventTraceAll_] return\n\
21511 \n\
21512 if { $eventTraceAll_ == 1 } {\n\
21513 \n\
21514 set et [new BaseTrace/$type]\n\
21515 $owner cmd eventtrace $et\n\
21516 \n\
21517 lappend alltrace_ $et\n\
21518 $et attach $eventtraceAllFile_\n\
21519 if [info exists namtraceAllFile_] {\n\
21520 $et namattach $namtraceAllFile_\n\
21521 }\n\
21522 }\n\
21523 }\n\
21524 \n\
21525 \n\
21526 Simulator instproc namtrace-queue { n1 n2 {file \"\"} } {\n\
21527 $self instvar link_ namtraceAllFile_\n\
21528 if {$file == \"\"} {\n\
21529 if ![info exists namtraceAllFile_] return\n\
21530 set file $namtraceAllFile_\n\
21531 }\n\
21532 $link_([$n1 id]:[$n2 id]) nam-trace $self $file\n\
21533 \n\
21534 set queue [$link_([$n1 id]:[$n2 id]) queue]\n\
21535 $queue attach-nam-traces $n1 $n2 $file\n\
21536 }\n\
21537 \n\
21538 Simulator instproc trace-queue { n1 n2 {file \"\"} } {\n\
21539 $self instvar link_ traceAllFile_\n\
21540 if {$file == \"\"} {\n\
21541 if ![info exists traceAllFile_] return\n\
21542 set file $traceAllFile_\n\
21543 }\n\
21544 $link_([$n1 id]:[$n2 id]) trace $self $file\n\
21545 \n\
21546 set queue [$link_([$n1 id]:[$n2 id]) queue]\n\
21547 $queue attach-traces $n1 $n2 $file\n\
21548 }\n\
21549 \n\
21550 Simulator instproc monitor-queue { n1 n2 qtrace { sampleInterval 0.1 } } {\n\
21551 $self instvar link_\n\
21552 return [$link_([$n1 id]:[$n2 id]) init-monitor $self $qtrace $sampleInterval]\n\
21553 }\n\
21554 \n\
21555 Simulator instproc queue-limit { n1 n2 limit } {\n\
21556 $self instvar link_\n\
21557 [$link_([$n1 id]:[$n2 id]) queue] set limit_ $limit\n\
21558 if {[[$link_([$n1 id]:[$n2 id]) queue] info class] == \"Queue/XCP\"} {\n\
21559 [$link_([$n1 id]:[$n2 id]) queue] queue-limit $limit\n\
21560 }\n\
21561 }\n\
21562 \n\
21563 Simulator instproc drop-trace { n1 n2 trace } {\n\
21564 $self instvar link_\n\
21565 [$link_([$n1 id]:[$n2 id]) queue] drop-target $trace\n\
21566 }\n\
21567 \n\
21568 Simulator instproc cost {n1 n2 c} {\n\
21569 $self instvar link_\n\
21570 $link_([$n1 id]:[$n2 id]) cost $c\n\
21571 }\n\
21572 \n\
21573 Simulator instproc multihome-attach-agent { core agent } {\n\
21574 $agent set-multihome-core [$core entry]\n\
21575 \n\
21576 foreach interface [$core set multihome_interfaces_] {\n\
21577 set ifNode [lindex $interface 0]\n\
21578 set coreLink [lindex $interface 1]\n\
21579 \n\
21580 $ifNode attach $agent\n\
21581 set addr [$agent set agent_addr_]\n\
21582 set port [$agent set agent_port_]\n\
21583 set entry [$ifNode entry]\n\
21584 \n\
21585 $agent add-multihome-interface $addr $port $entry $coreLink\n\
21586 \n\
21587 $agent instvar multihome_bindings_\n\
21588 set binding_ {}\n\
21589 lappend binding_ $addr\n\
21590 lappend binding_ $port\n\
21591 lappend multihome_bindings_ $binding_\n\
21592 }\n\
21593 }\n\
21594 \n\
21595 Simulator instproc attach-agent { node agent } {\n\
21596 $node attach $agent\n\
21597 \n\
21598 if {[lindex [split [$agent info class] \"/\"] 1] == \"SCTP\"} {\n\
21599 $agent instvar multihome_bindings_\n\
21600 set binding_ {}\n\
21601 set addr [$agent set agent_addr_]\n\
21602 set port [$agent set agent_port_]\n\
21603 lappend binding_ $addr\n\
21604 lappend binding_ $port\n\
21605 lappend multihome_bindings_ $binding_\n\
21606 }\n\
21607 }\n\
21608 \n\
21609 Simulator instproc attach-tbf-agent { node agent tbf } {\n\
21610 $node attach $agent\n\
21611 $agent attach-tbf $tbf\n\
21612 }\n\
21613 \n\
21614 \n\
21615 Simulator instproc detach-agent { node agent } {\n\
21616 \n\
21617 $self instvar conn_ nconn_ sflows_ nsflows_ useasim_\n\
21618 \n\
21619 if {$useasim_ == 1} {\n\
21620 set list \"\" \n\
21621 set s [$node id]\n\
21622 set d [[$self get-node-by-addr [$agent set dst_addr_]] id]\n\
21623 foreach x $conn_ {\n\
21624 set t [split $x \":\"] \n\
21625 if {[string compare [lindex $t 0]:[lindex $t 1] $s:$d] != 0} {\n\
21626 lappend list_ $x\n\
21627 }\n\
21628 }\n\
21629 set conn_ list\n\
21630 set nconn_ [expr $nconn_ -1]\n\
21631 }\n\
21632 \n\
21633 $self instvar nullAgent_\n\
21634 $node detach $agent $nullAgent_\n\
21635 }\n\
21636 \n\
21637 Simulator instproc delay { n1 n2 delay {type simplex} } {\n\
21638 $self instvar link_\n\
21639 set sid [$n1 id]\n\
21640 set did [$n2 id]\n\
21641 if [info exists link_($sid:$did)] {\n\
21642 set d [$link_($sid:$did) link]\n\
21643 $d set delay_ $delay\n\
21644 }\n\
21645 if {$type == \"duplex\"} {\n\
21646 if [info exists link_($did:$sid)] {\n\
21647 set d [$link_($did:$sid) link]\n\
21648 $d set delay_ $delay\n\
21649 }\n\
21650 }\n\
21651 }\n\
21652 \n\
21653 Simulator instproc bandwidth { n1 n2 bandwidth {type simplex} } {\n\
21654 $self instvar link_\n\
21655 set sid [$n1 id]\n\
21656 set did [$n2 id]\n\
21657 if [info exists link_($sid:$did)] {\n\
21658 set d [$link_($sid:$did) link]\n\
21659 $d set bandwidth_ $bandwidth\n\
21660 } \n\
21661 if {$type == \"duplex\"} {\n\
21662 if [info exists link_($did:$sid)] {\n\
21663 set d [$link_($did:$sid) link]\n\
21664 $d set bandwidth_ $bandwidth\n\
21665 }\n\
21666 }\n\
21667 }\n\
21668 \n\
21669 \n\
21670 Simulator instproc connect {src dst} {\n\
21671 \n\
21672 $self instvar conn_ nconn_ sflows_ nsflows_ useasim_\n\
21673 \n\
21674 if {[lindex [split [$src info class] \"/\"] 1] == \"SCTP\"} {\n\
21675 $self multihome-connect $src $dst\n\
21676 }\n\
21677 \n\
21678 $self simplex-connect $src $dst\n\
21679 $self simplex-connect $dst $src\n\
21680 \n\
21681 \n\
21682 \n\
21683 if {$useasim_ == 1} {\n\
21684 set sid [$src nodeid]\n\
21685 set sport [$src set agent_port_]\n\
21686 set did [$dst nodeid]\n\
21687 set dport [$dst set agent_port_]\n\
21688 \n\
21689 if {[lindex [split [$src info class] \"/\"] 1] == \"TCP\"} {\n\
21690 lappend conn_ $sid:$did:$sport:$dport\n\
21691 incr nconn_\n\
21692 }\n\
21693 }\n\
21694 \n\
21695 return $src\n\
21696 }\n\
21697 \n\
21698 Simulator instproc multihome-connect {src dst} {\n\
21699 \n\
21700 set destNum 0\n\
21701 foreach binding [$src set multihome_bindings_] {\n\
21702 incr destNum\n\
21703 set addr [lindex $binding 0]\n\
21704 set port [lindex $binding 1]\n\
21705 $dst add-multihome-destination $addr $port\n\
21706 }\n\
21707 if {$destNum == 0} {\n\
21708 $dst add-multihome-destination \\\n\
21709 [$src set agent_addr_] [$src set agent_port_]\n\
21710 }\n\
21711 \n\
21712 set destNum 0\n\
21713 foreach binding [$dst set multihome_bindings_] {\n\
21714 incr destNum\n\
21715 set addr [lindex $binding 0]\n\
21716 set port [lindex $binding 1]\n\
21717 $src add-multihome-destination $addr $port\n\
21718 }\n\
21719 if {$destNum == 0} {\n\
21720 $src add-multihome-destination \\\n\
21721 [$dst set agent_addr_] [$dst set agent_port_]\n\
21722 }\n\
21723 }\n\
21724 \n\
21725 Simulator instproc simplex-connect { src dst } {\n\
21726 $src set dst_addr_ [$dst set agent_addr_] \n\
21727 $src set dst_port_ [$dst set agent_port_]\n\
21728 \n\
21729 \n\
21730 if {[lindex [split [$src info class] \"/\"] 1] == \"AbsTCP\"} {\n\
21731 $self at [$self now] \"$self rtt $src $dst\"\n\
21732 $dst set class_ [$src set class_]\n\
21733 }\n\
21734 \n\
21735 return $src\n\
21736 }\n\
21737 \n\
21738 \n\
21739 Simulator proc instance {} {\n\
21740 set ns [Simulator info instances]\n\
21741 if { $ns != \"\" } {\n\
21742 return $ns\n\
21743 }\n\
21744 foreach sim [Simulator info subclass] {\n\
21745 set ns [$sim info instances]\n\
21746 if { $ns != \"\" } {\n\
21747 return $ns\n\
21748 }\n\
21749 }\n\
21750 error \"Cannot find instance of simulator\"\n\
21751 }\n\
21752 \n\
21753 Simulator instproc get-number-of-nodes {} {\n\
21754 return  [$self array size Node_]\n\
21755 }\n\
21756 \n\
21757 Simulator instproc get-node-by-id id {\n\
21758 $self instvar Node_\n\
21759 return $Node_($id)\n\
21760 }\n\
21761 \n\
21762 Simulator instproc get-node-id-by-addr address {\n\
21763 $self instvar Node_\n\
21764 set n [Node set nn_]\n\
21765 for {set q 0} {$q < $n} {incr q} {\n\
21766 set nq $Node_($q)\n\
21767 if {[string compare [$nq node-addr] $address] == 0} {\n\
21768 return $q\n\
21769 }\n\
21770 }\n\
21771 error \"get-node-id-by-addr:Cannot find node with given address\"\n\
21772 }\n\
21773 \n\
21774 Simulator instproc get-node-by-addr address {\n\
21775 return [$self get-node-by-id [$self get-node-id-by-addr $address]]\n\
21776 }\n\
21777 \n\
21778 Simulator instproc all-nodes-list {} {\n\
21779 $self instvar Node_\n\
21780 set nodes \"\"\n\
21781 foreach n [lsort -dictionary [array names Node_]] {\n\
21782 lappend nodes $Node_($n)\n\
21783 }\n\
21784 return $nodes\n\
21785 }\n\
21786 \n\
21787 Simulator instproc link { n1 n2 } {\n\
21788 $self instvar Node_ link_\n\
21789 if { ![catch \"$n1 info class Node\"] } {\n\
21790 set n1 [$n1 id]\n\
21791 }\n\
21792 if { ![catch \"$n2 info class Node\"] } {\n\
21793 set n2 [$n2 id]\n\
21794 }\n\
21795 if [info exists link_($n1:$n2)] {\n\
21796 return $link_($n1:$n2)\n\
21797 }\n\
21798 return \"\"\n\
21799 }\n\
21800 \n\
21801 Simulator instproc create-connection {s_type source d_type dest pktClass} {\n\
21802 set s_agent [new Agent/$s_type]\n\
21803 set d_agent [new Agent/$d_type]\n\
21804 $s_agent set fid_ $pktClass\n\
21805 $d_agent set fid_ $pktClass\n\
21806 $self attach-agent $source $s_agent\n\
21807 $self attach-agent $dest $d_agent\n\
21808 $self connect $s_agent $d_agent\n\
21809 \n\
21810 return $s_agent\n\
21811 }\n\
21812 \n\
21813 Simulator instproc create-highspeed-connection {s_type source d_type dest pktClass} {\n\
21814 set s_agent [new Agent/$s_type]\n\
21815 set d_agent [new Agent/$d_type]\n\
21816 $d_agent resize_buffers\n\
21817 $s_agent set fid_ $pktClass\n\
21818 $d_agent set fid_ $pktClass\n\
21819 $self attach-agent $source $s_agent\n\
21820 $self attach-agent $dest $d_agent\n\
21821 $self connect $s_agent $d_agent\n\
21822 \n\
21823 return $s_agent\n\
21824 }\n\
21825 \n\
21826 Simulator instproc create-connection-list {s_type source d_type dest pktClass} {\n\
21827 set s_agent [new Agent/$s_type]\n\
21828 set d_agent [new Agent/$d_type]\n\
21829 $s_agent set fid_ $pktClass\n\
21830 $d_agent set fid_ $pktClass\n\
21831 $self attach-agent $source $s_agent\n\
21832 $self attach-agent $dest $d_agent\n\
21833 $self connect $s_agent $d_agent\n\
21834 \n\
21835 return [list $s_agent $d_agent]\n\
21836 }   \n\
21837 \n\
21838 Simulator instproc create-connection-listen {s_type source d_type dest pktClass} {\n\
21839 set s_agent [new Agent/$s_type]\n\
21840 set d_agent [new Agent/$d_type]\n\
21841 $s_agent set fid_ $pktClass\n\
21842 $d_agent set fid_ $pktClass\n\
21843 $self attach-agent $source $s_agent\n\
21844 $self attach-agent $dest $d_agent\n\
21845 $self connect $s_agent $d_agent\n\
21846 $d_agent listen\n\
21847 \n\
21848 return $s_agent \n\
21849 }   \n\
21850 \n\
21851 Simulator instproc create-tcp-connection {s_type source d_type dest pktClass} {\n\
21852 set s_agent [new Agent/$s_type]\n\
21853 set d_agent [new Agent/$d_type]\n\
21854 $s_agent set fid_ $pktClass\n\
21855 $d_agent set fid_ $pktClass\n\
21856 $self attach-agent $source $s_agent\n\
21857 $self attach-agent $dest $d_agent\n\
21858 return \"$s_agent $d_agent\"\n\
21859 }\n\
21860 \n\
21861 Classifier instproc install {slot val} {\n\
21862 $self set slots_($slot) $val\n\
21863 $self cmd install $slot $val\n\
21864 }\n\
21865 \n\
21866 Classifier instproc installNext val {\n\
21867 set slot [$self cmd installNext $val]\n\
21868 $self set slots_($slot) $val\n\
21869 set slot\n\
21870 }\n\
21871 \n\
21872 Classifier instproc adjacents {} {\n\
21873 $self array get slots_\n\
21874 }\n\
21875 \n\
21876 Classifier instproc in-slot? slot {\n\
21877 $self instvar slots_\n\
21878 set ret \"\"\n\
21879 if {[array size slots_] < $slot} {\n\
21880 set ret slots_($slot)\n\
21881 }\n\
21882 set ret\n\
21883 }\n\
21884 \n\
21885 Classifier instproc dump {} {\n\
21886 $self instvar slots_ offset_ shift_ mask_\n\
21887 puts \"classifier $self\"\n\
21888 puts \"\\t$offset_ offset\"\n\
21889 puts \"\\t$shift_ shift\"\n\
21890 puts \"\\t$mask_ mask\"\n\
21891 puts \"\\t[array size slots_] slots\"\n\
21892 foreach i [lsort -integer [array names slots_]] {\n\
21893 set iv $slots_($i)\n\
21894 puts \"\\t\\tslot $i: $iv ([$iv info class])\"\n\
21895 }\n\
21896 }\n\
21897 \n\
21898 Classifier instproc no-slot slot {\n\
21899 puts stderr \"--- Classfier::no-slot{} default handler (tcl/lib/ns-lib.tcl) ---\"\n\
21900 puts stderr \"\\t$self: no target for slot $slot\"\n\
21901 puts stderr \"\\t$self type: [$self info class]\"\n\
21902 puts stderr \"content dump:\"\n\
21903 $self dump\n\
21904 puts stderr \"---------- Finished standard no-slot{} default handler ----------\"\n\
21905 [Simulator instance] flush-trace\n\
21906 exit 1\n\
21907 }\n\
21908 \n\
21909 Classifier/Hash instproc dump args {\n\
21910 eval $self next $args\n\
21911 $self instvar default_\n\
21912 puts \"\\t$default_ default\"\n\
21913 }\n\
21914 \n\
21915 Classifier/Hash instproc init nbuck {\n\
21916 $self next $nbuck\n\
21917 $self instvar shift_ mask_\n\
21918 set shift_ [AddrParams NodeShift 1]\n\
21919 set mask_ [AddrParams NodeMask 1]\n\
21920 }\n\
21921 \n\
21922 Classifier/Port/Reserve instproc init args {\n\
21923 eval $self next\n\
21924 $self reserve-port 2\n\
21925 }\n\
21926 \n\
21927 Simulator instproc makeflowmon { cltype { clslots 29 } } {\n\
21928 set flowmon [new QueueMonitor/ED/Flowmon]\n\
21929 set cl [new Classifier/Hash/$cltype $clslots]\n\
21930 \n\
21931 $cl proc unknown-flow { src dst fid }  {\n\
21932 set fdesc [new QueueMonitor/ED/Flow]\n\
21933 set dsamp [new Samples]\n\
21934 $fdesc set-delay-samples $dsamp\n\
21935 set slot [$self installNext $fdesc] \n\
21936 $self set-hash auto $src $dst $fid $slot\n\
21937 }\n\
21938 \n\
21939 $cl proc no-slot slotnum {\n\
21940 }\n\
21941 $flowmon classifier $cl\n\
21942 return $flowmon\n\
21943 }\n\
21944 \n\
21945 \n\
21946 Simulator instproc attach-fmon {lnk fm { edrop 0 } } {\n\
21947 set isnoop [new SnoopQueue/In]\n\
21948 set osnoop [new SnoopQueue/Out]\n\
21949 set dsnoop [new SnoopQueue/Drop]\n\
21950 $lnk attach-monitors $isnoop $osnoop $dsnoop $fm\n\
21951 if { $edrop != 0 } {\n\
21952 set edsnoop [new SnoopQueue/EDrop]\n\
21953 $edsnoop set-monitor $fm\n\
21954 [$lnk queue] early-drop-target $edsnoop\n\
21955 $edsnoop target [$self set nullAgent_]\n\
21956 }\n\
21957 [$lnk queue] drop-target $dsnoop\n\
21958 }\n\
21959 \n\
21960 \n\
21961 Simulator instproc maketbtagger { cltype { clslots 29 } } {\n\
21962 \n\
21963 set tagger [new QueueMonitor/ED/Tagger]\n\
21964 set cl [new Classifier/Hash/$cltype $clslots]\n\
21965 \n\
21966 $cl proc unknown-flow { src dst fid }  {\n\
21967 set fdesc [new QueueMonitor/ED/Flow/TB]\n\
21968 set dsamp [new Samples]\n\
21969 $fdesc set-delay-samples $dsamp\n\
21970 set slot [$self installNext $fdesc]\n\
21971 $self set-hash auto $src $dst $fid $slot\n\
21972 }\n\
21973 \n\
21974 $cl proc set-rate { src dst fid hashbucket rate depth init} {\n\
21975 set fdesc [new QueueMonitor/ED/Flow/TB]\n\
21976 set dsamp [new Samples]\n\
21977 $fdesc set-delay-samples $dsamp\n\
21978 $fdesc set target_rate_ $rate\n\
21979 $fdesc set bucket_depth_ $depth\n\
21980 $fdesc set tbucket_ $init  \n\
21981 set slot [$self installNext $fdesc]\n\
21982 $self set-hash $hashbucket $src $dst $fid $slot\n\
21983 }\n\
21984 \n\
21985 $cl proc no-slot slotnum {\n\
21986 }\n\
21987 $tagger classifier $cl\n\
21988 return $tagger\n\
21989 }\n\
21990 \n\
21991 \n\
21992 Simulator instproc maketswtagger { cltype { clslots 29 } } {\n\
21993 \n\
21994 set tagger [new QueueMonitor/ED/Tagger]\n\
21995 set cl [new Classifier/Hash/$cltype $clslots]\n\
21996 \n\
21997 $cl proc unknown-flow { src dst fid hashbucket }  {\n\
21998 set fdesc [new QueueMonitor/ED/Flow/TSW]\n\
21999 set dsamp [new Samples]\n\
22000 $fdesc set-delay-samples $dsamp\n\
22001 set slot [$self installNext $fdesc]\n\
22002 $self set-hash $hashbucket $src $dst $fid $slot\n\
22003 }\n\
22004 \n\
22005 $cl proc no-slot slotnum {\n\
22006 }\n\
22007 $tagger classifier $cl\n\
22008 return $tagger\n\
22009 }\n\
22010 \n\
22011 \n\
22012 Simulator instproc attach-tagger {lnk fm} {\n\
22013 set isnoop [new SnoopQueue/Tagger]\n\
22014 $lnk attach-taggers $isnoop $fm\n\
22015 }\n\
22016 \n\
22017 Simulator instproc lossmodel {lossobj from to} {\n\
22018 set link [$self link $from $to]\n\
22019 $link errormodule $lossobj\n\
22020 }\n\
22021 \n\
22022 Simulator instproc link-lossmodel {lossobj from to} {\n\
22023 set link [$self link $from $to]\n\
22024 $link insert-linkloss $lossobj\n\
22025 }\n\
22026 \n\
22027 \n\
22028 \n\
22029 Simulator instproc rtt { src dst } {\n\
22030 $self instvar routingTable_ delay_\n\
22031 set srcid [[$src set node_] id]\n\
22032 set dstid [[$dst set node_] id]\n\
22033 set delay 0\n\
22034 set tmpid $srcid\n\
22035 while {$tmpid != $dstid} {\n\
22036 set nextid [$routingTable_ lookup $tmpid $dstid]\n\
22037 set tmpnode [$self get-node-by-id $tmpid]\n\
22038 set nextnode [$self get-node-by-id $nextid]\n\
22039 set tmplink [[$self link $tmpnode $nextnode] link]\n\
22040 set delay [expr $delay + [expr 2 * [$tmplink set delay_]]]\n\
22041 set delay [expr $delay + [expr 8320 / [$tmplink set bandwidth_]]]\n\
22042 set tmpid $nextid\n\
22043 }\n\
22044 $src rtt $delay\n\
22045 return $delay\n\
22046 }\n\
22047 \n\
22048 Simulator instproc abstract-tcp {} {\n\
22049 $self instvar TahoeAckfsm_ RenoAckfsm_ TahoeDelAckfsm_ RenoDelAckfsm_ dropper_ \n\
22050 $self set TahoeAckfsm_ [new FSM/TahoeAck]\n\
22051 $self set RenoAckfsm_ [new FSM/RenoAck]\n\
22052 $self set TahoeDelAckfsm_ [new FSM/TahoeDelAck]\n\
22053 $self set RenoDelAckfsm_ [new FSM/RenoDelAck]\n\
22054 $self set nullAgent_ [new DropTargetAgent]\n\
22055 }\n\
22056 \n\
22057 \n\
22058 Simulator instproc create-diffusion-rate-agent {node} {\n\
22059 global opt\n\
22060 set diff [new Agent/Diffusion/RateGradient]\n\
22061 \n\
22062 $node set diffagent_ $diff\n\
22063 $node set ragent_ $diff\n\
22064 \n\
22065 $diff on-node $node\n\
22066 \n\
22067 if [info exist opt(enablePos)] {\n\
22068 if {$opt(enablePos) == \"true\"} {\n\
22069 $diff enable-pos\n\
22070 } else {\n\
22071 $diff disable-pos\n\
22072 }\n\
22073 } \n\
22074 \n\
22075 if [info exist opt(enableNeg)] {\n\
22076 if {$opt(enableNeg) == \"true\"} {\n\
22077 $diff enable-neg\n\
22078 } else {\n\
22079 $diff disable-neg\n\
22080 }\n\
22081 } \n\
22082 \n\
22083 if [info exist opt(suppression)] {\n\
22084 if {$opt(suppression) == \"true\"} {\n\
22085 $diff enable-suppression\n\
22086 } else {\n\
22087 $diff disable-suppression\n\
22088 }\n\
22089 } \n\
22090 \n\
22091 if [info exist opt(subTxType)] {\n\
22092 $diff set-sub-tx-type $opt(subTxType)\n\
22093 } \n\
22094 \n\
22095 if [info exist opt(orgTxType)] {\n\
22096 $diff set-org-tx-type $opt(orgTxType)\n\
22097 } \n\
22098 \n\
22099 if [info exist opt(posType)] {\n\
22100 $diff set-pos-type $opt(posType)\n\
22101 } \n\
22102 \n\
22103 if [info exist opt(posNodeType)] {\n\
22104 $diff set-pos-node-type $opt(posNodeType)\n\
22105 } \n\
22106 \n\
22107 if [info exist opt(negWinType)] {\n\
22108 $diff set-neg-win-type $opt(negWinType)\n\
22109 } \n\
22110 \n\
22111 if [info exist opt(negThrType)] {\n\
22112 $diff set-neg-thr-type $opt(negThrType)\n\
22113 } \n\
22114 \n\
22115 if [info exist opt(negMaxType)] {\n\
22116 $diff set-neg-max-type $opt(negMaxType)\n\
22117 } \n\
22118 \n\
22119 $self put-in-list $diff\n\
22120 $self at 0.0 \"$diff start\"\n\
22121 \n\
22122 return $diff\n\
22123 }\n\
22124 \n\
22125 Simulator instproc create-diffusion-probability-agent {node} {\n\
22126 global opt\n\
22127 set diff [new Agent/Diffusion/ProbGradient]\n\
22128 \n\
22129 $node set diffagent_ $diff\n\
22130 $node set ragent_ $diff\n\
22131 \n\
22132 $diff on-node $node\n\
22133 \n\
22134 if [info exist opt(enablePos)] {\n\
22135 if {$opt(enablePos) == \"true\"} {\n\
22136 $diff enable-pos\n\
22137 } else {\n\
22138 $diff disable-pos\n\
22139 }\n\
22140 } \n\
22141 if [info exist opt(enableNeg)] {\n\
22142 if {$opt(enableNeg) == \"true\"} {\n\
22143 $diff enable-neg\n\
22144 } else {\n\
22145 $diff disable-neg\n\
22146 }\n\
22147 } \n\
22148 \n\
22149 $self put-in-list $diff\n\
22150 $self at 0.0 \"$diff start\"\n\
22151 \n\
22152 return $diff\n\
22153 }\n\
22154 \n\
22155 Simulator instproc create-core-diffusion-rtg-agent {node} {\n\
22156 $self instvar stopTime_ diffFilter_\n\
22157 Node instvar ragent_ dmux_\n\
22158 set ragent [new Agent/DiffusionRouting [$node id]]\n\
22159 $node set ragent_ $ragent\n\
22160 if { [info exists stopTime_] } {\n\
22161 $ragent stop-time $stopTime_\n\
22162 }\n\
22163 if { ![info exists diffFilter_] } {\n\
22164 puts stderr \"Error: No filter defined for diffusion!\\n\"\n\
22165 exit 1\n\
22166 }\n\
22167 $node create-diffusionApp-agent $diffFilter_\n\
22168 return $ragent\n\
22169 }\n\
22170 \n\
22171 Simulator instproc create-flooding-agent {node} {\n\
22172 set flood [new Agent/Flooding]\n\
22173 \n\
22174 $node set ragent_ $flood\n\
22175 \n\
22176 $flood on-node $node\n\
22177 \n\
22178 $self put-in-list $flood\n\
22179 $self at 0.0 \"$flood start\"\n\
22180 \n\
22181 return $flood\n\
22182 }\n\
22183 \n\
22184 Simulator instproc create-omnimcast-agent {node} {\n\
22185 set omni [new Agent/OmniMcast]\n\
22186 \n\
22187 $node set ragent_ $omni\n\
22188 \n\
22189 $omni on-node $node\n\
22190 \n\
22191 $self put-in-list $omni\n\
22192 $self at 0.0 \"$omni start\"\n\
22193 \n\
22194 return $omni\n\
22195 }\n\
22196 \n\
22197 Simulator instproc put-in-list {agent} {\n\
22198 $self instvar lagent\n\
22199 lappend lagent $agent\n\
22200 }\n\
22201 \n\
22202 Simulator instproc terminate-all-agents {} {\n\
22203 $self instvar lagent\n\
22204 foreach i $lagent {\n\
22205 $i terminate\n\
22206 }\n\
22207 }\n\
22208 \n\
22209 Simulator instproc prepare-to-stop {} {\n\
22210 $self instvar lagent\n\
22211 foreach i $lagent {\n\
22212 $i stop\n\
22213 }\n\
22214 }\n\
22215 \n\
22216 \n\
22217 Simulator instproc attach-diffapp { node diffapp } {\n\
22218 $diffapp dr [$node get-dr]\n\
22219 }\n\
22220 \n\
22221 Node instproc get-dr {} {\n\
22222 $self instvar diffAppAgent_\n\
22223 if [info exists diffAppAgent_] {\n\
22224 return $diffAppAgent_\n\
22225 } else {\n\
22226 puts \"Error: No DiffusionApp agent created for this node!\\n\" \n\
22227 exit 1\n\
22228 }\n\
22229 }\n\
22230 \n\
22231 \n\
22232 Node instproc create-diffusionApp-agent { diffFilters } {\n\
22233 $self instvar gradient_ diffAppAgent_\n\
22234 \n\
22235 \n\
22236 if [info exists diffAppAgent_] {\n\
22237 puts \"diffAppAgent_ exists: $diffAppAgent_\"\n\
22238 return $diffAppAgent_\n\
22239 }\n\
22240 \n\
22241 $self set diffAppAgent_ [new Agent/DiffusionApp]\n\
22242 set da $diffAppAgent_\n\
22243 set port [get-da-port $da $self]\n\
22244 $da agent-id $port\n\
22245 $da node $self\n\
22246 \n\
22247 if {$diffFilters == \"\"} {\n\
22248 puts \"Error: No filter defined for diffusion!\\n\"\n\
22249 exit 1\n\
22250 }\n\
22251 set n 0\n\
22252 foreach filtertype [split $diffFilters \"/\"] {\n\
22253 if {$filtertype == \"GeoRoutingFilter\" } continue\n\
22254 set filter($n) [new Application/DiffApp/$filtertype $da]\n\
22255 $filter($n) start         ;# starts filter\n\
22256 incr n\n\
22257 }\n\
22258 \n\
22259 }\n\
22260 \n\
22261 \n\
22262 proc get-da-port {da node} {\n\
22263 \n\
22264 set port [Node set DIFFUSION_APP_PORT]\n\
22265 $node attach $da $port\n\
22266 return $port\n\
22267 }\n\
22268 ";
22269 #include "tclcl.h"
22270 EmbeddedTcl et_ns_lib(code);

Generated on Tue Mar 6 16:47:48 2007 for ns2 Network Simulator 2.29 by  doxygen 1.4.6