📄 ns-lib.tcl
字号:
error "\# of clusters exceed clus-field-size " } } if [info exists nodes_num_] { set maxval [expr [find-max $nodes_num_] -1] if {$maxval > [expr pow(2, [AddrParams NodeMask 3])]} { error "\# of nodess exceed node-field-size" } }}Simulator instproc check-smac {} { $self instvar macType_ if { [info exist macType_] && $macType_ == "Mac/SMAC" } { if { [$macType_ set syncFlag_] } { 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" } }} Simulator instproc run {} { # NIXVECTOR? # global runstart # set runstart [clock seconds] $self check-smac ;# print warning if in sleep/wakeup cycle $self check-node-num $self rtmodel-configure ;# in case there are any [$self get-routelogic] configure $self instvar scheduler_ Node_ link_ started_ set started_ 1 # # Reset every node, which resets every agent. # foreach nn [array names Node_] { $Node_($nn) reset # GFR Additions for NixVector Routing if { [Simulator set nix-routing] } { $Node_($nn) populate-objects } } # # Also reset every queue # foreach qn [array names link_] { set q [$link_($qn) queue] $q reset } # Do all nam-related initialization here $self init-nam # NIXVECTOR xxx? # global simstart # set simstart [clock seconds] return [$scheduler_ run]}# johnh xxx?Simulator instproc log-simstart { } { # GFR Modification to log actual start global simstart puts "Starting Actual Simulation" set simstart [clock seconds]}Simulator instproc halt {} { $self instvar scheduler_ #puts "time: [clock format [clock seconds] -format %X]" $scheduler_ halt}Simulator instproc dumpq {} { $self instvar scheduler_ $scheduler_ dumpq}Simulator instproc is-started {} { $self instvar started_ return [info exists started_]}Simulator instproc clearMemTrace {} { $self instvar scheduler_ $scheduler_ clearMemTrace}Simulator instproc simplex-link { n1 n2 bw delay qtype args } { $self instvar link_ queueMap_ nullAgent_ useasim_ set sid [$n1 id] set did [$n2 id] # Debo if { $useasim_ == 1 } { set slink_($sid:$did) $self } if [info exists queueMap_($qtype)] { set qtype $queueMap_($qtype) } # construct the queue set qtypeOrig $qtype switch -exact $qtype { ErrorModule { if { [llength $args] > 0 } { set q [eval new $qtype $args] } else { set q [new $qtype Fid] } } intserv { set qtype [lindex $args 0] set q [new Queue/$qtype] } default { if { [llength $args] == 0} { set q [new Queue/$qtype] } else { set q [new Queue/$qtype $args] } } } # Now create the link switch -exact $qtypeOrig { RTM { set c [lindex $args 1] set link_($sid:$did) [new CBQLink \ $n1 $n2 $bw $delay $q $c] } CBQ - CBQ/WRR { # assume we have a string of form "linktype linkarg" if {[llength $args] == 0} { # default classifier for cbq is just Fid type set c [new Classifier/Hash/Fid 33] } else { set c [lindex $args 0] } set link_($sid:$did) [new CBQLink \ $n1 $n2 $bw $delay $q $c] } FQ { set link_($sid:$did) [new FQLink $n1 $n2 $bw $delay $q] } intserv { #XX need to clean this up set link_($sid:$did) [new IntServLink \ $n1 $n2 $bw $delay $q \ [concat $qtypeOrig $args]] } default { set link_($sid:$did) [new SimpleLink \ $n1 $n2 $bw $delay $q] } } if {$qtype == "RED/Pushback"} { set pushback 1 } else { set pushback 0 } $n1 add-neighbor $n2 $pushback #XXX yuck if {[string first "RED" $qtype] != -1 || [string first "PI" $qtype] != -1 || [string first "Vq" $qtype] != -1 || [string first "REM" $qtype] != -1 || [string first "GK" $qtype] != -1 || [string first "RIO" $qtype] != -1 || [string first "XCP" $qtype] != -1} { $q link [$link_($sid:$did) set link_] } set trace [$self get-ns-traceall] if {$trace != ""} { $self trace-queue $n1 $n2 $trace } set trace [$self get-nam-traceall] if {$trace != ""} { $self namtrace-queue $n1 $n2 $trace } # Register this simplex link in nam link list. Treat it as # a duplex link in nam $self register-nam-linkconfig $link_($sid:$did)}## This is used by Link::orient to register/update the order in which links # should created in nam. This is important because different creation order# may result in different layout.## A poor hack. :( Any better ideas?#Simulator instproc register-nam-linkconfig link { $self instvar linkConfigList_ link_ if [info exists linkConfigList_] { # Check whether the reverse simplex link is registered, # if so, don't register this link again. # We should have a separate object for duplex link. set i1 [[$link src] id] set i2 [[$link dst] id] if [info exists link_($i2:$i1)] { set pos [lsearch $linkConfigList_ $link_($i2:$i1)] if {$pos >= 0} { set a1 [$link_($i2:$i1) get-attribute \ "ORIENTATION"] set a2 [$link get-attribute "ORIENTATION"] if {$a1 == "" && $a2 != ""} { # If this duplex link has not been # assigned an orientation, do it. set linkConfigList_ [lreplace \ $linkConfigList_ $pos $pos] } else { return } } } # Remove $link from list if it's already there set pos [lsearch $linkConfigList_ $link] if {$pos >= 0} { set linkConfigList_ \ [lreplace $linkConfigList_ $pos $pos] } } lappend linkConfigList_ $link}## GT-ITM may occasionally generate duplicate links, so we need this check# to ensure duplicated links do not appear in nam trace files.#Simulator instproc remove-nam-linkconfig {i1 i2} { $self instvar linkConfigList_ link_ if ![info exists linkConfigList_] { return } set pos [lsearch $linkConfigList_ $link_($i1:$i2)] if {$pos >= 0} { set linkConfigList_ [lreplace $linkConfigList_ $pos $pos] return } set pos [lsearch $linkConfigList_ $link_($i2:$i1)] if {$pos >= 0} { set linkConfigList_ [lreplace $linkConfigList_ $pos $pos] }}# Armando L. Caro Jr. <acaro@@cis,udel,edu> 10/22/2001## we create a simplex link (NOT duplex) from the core to the interface. we can# use arbitrary params (bw, delay, etc) since we'll never actually transmit# data on these links. they are only used for routing (ie, to determine which # interface a packet should go out from)#Simulator instproc multihome-add-interface { core if } { $self instvar link_ set coreId [$core id] set ifId [$if id] # arbitrary values (doesn't matter since link will NEVER be used!) set bw 1Mb set delay 100ms set type DropTail if [info exists link_($coreId:$ifId)] { $self remove-nam-linkconfig $coreId $ifId } eval $self simplex-link $core $if $bw $delay $type # Modified by GFR for nix-vector routing if { [Simulator set nix-routing] } { # Inform nodes of neighbors $n1 set-neighbor [$core id] $n2 set-neighbor [$if id] } $core instvar multihome_interfaces_ num_interfaces_ set interface_ {} # interface node lappend interface_ $if # link from interface node to core node lappend interface_ [$link_($coreId:$ifId) set head_] lappend multihome_interfaces_ $interface_}Simulator instproc duplex-link { n1 n2 bw delay type args } { $self instvar link_ set i1 [$n1 id] set i2 [$n2 id] if [info exists link_($i1:$i2)] { $self remove-nam-linkconfig $i1 $i2 } eval $self simplex-link $n1 $n2 $bw $delay $type $args eval $self simplex-link $n2 $n1 $bw $delay $type $args # Modified by GFR for nix-vector routing if { [Simulator set nix-routing] } { # Inform nodes of neighbors $n1 set-neighbor [$n2 id] $n2 set-neighbor [$n1 id] }}Simulator instproc duplex-intserv-link { n1 n2 bw pd sched signal adc args } { eval $self duplex-link $n1 $n2 $bw $pd intserv $sched $signal $adc $args}Simulator instproc simplex-link-op { n1 n2 op args } { $self instvar link_ eval $link_([$n1 id]:[$n2 id]) $op $args}Simulator instproc duplex-link-op { n1 n2 op args } { $self instvar link_ eval $link_([$n1 id]:[$n2 id]) $op $args eval $link_([$n2 id]:[$n1 id]) $op $args}Simulator instproc flush-trace {} { $self instvar alltrace_ if [info exists alltrace_] { foreach trace $alltrace_ { $trace flush } }}Simulator instproc namtrace-all file { $self instvar namtraceAllFile_ if {$file != ""} { set namtraceAllFile_ $file } else { unset namtraceAllFile_ }}Simulator instproc energy-color-change {level1 level2} { $self instvar level1_ level2_ set level1_ $level1 set level2_ $level2}Simulator instproc namtrace-all-wireless {file optx opty} { $self instvar namtraceAllFile_ # indicate that we need a W event written to the trace $self set namNeedsW_ 1 if { $optx != "" && $opty != "" } { $self set namWx_ $optx $self set namWy_ $opty } $self namtrace-all $file}Simulator instproc nam-end-wireless {stoptime} { $self instvar namtraceAllFile_ if {$namtraceAllFile_ != ""} { $self puts-nam-config "W -t $stoptime" }}Simulator instproc namtrace-some file { $self instvar namtraceSomeFile_ set namtraceSomeFile_ $file}# Support for event-tracing Simulator instproc eventtrace-all {{file ""}} { $self instvar eventTraceAll_ eventtraceAllFile_ traceAllFile_ set eventTraceAll_ 1 if {$file != ""} { set eventtraceAllFile_ $file } else { set eventtraceAllFile_ $traceAllFile_ } }Simulator instproc initial_node_pos {nodep size} { $self instvar addressType_ $self instvar energyModel_ if [info exists energyModel_] { set nodeColor "green" } else { set nodeColor "black" } if { [info exists addressType_] && $addressType_ == "hierarchical" } { # Hierarchical addressing $self puts-nam-config "n -t * -a [$nodep set address_] \-s [$nodep id] -x [$nodep set X_] -y [$nodep set Y_] -Z [$nodep set Z_] \-z $size -v circle -c $nodeColor" } else { # Flat addressing $self puts-nam-config "n -t * -s [$nodep id] \-x [$nodep set X_] -y [$nodep set Y_] -Z [$nodep set Z_] -z $size \-v circle -c $nodeColor" }}Simulator instproc trace-all file { $self instvar traceAllFile_ set traceAllFile_ $file}Simulator instproc get-nam-traceall {} { $self instvar namtraceAllFile_ if [info exists namtraceAllFile_] { return $namtraceAllFile_ } else { return "" }}Simulator instproc get-ns-traceall {} { $self instvar traceAllFile_ if [info exists traceAllFile_] { return $traceAllFile_ } else { return "" }}# If exists a traceAllFile_, print $str to $traceAllFile_Simulator instproc puts-ns-traceall { str } { $self instvar traceAllFile_ if [info exists traceAllFile_] { puts $traceAllFile_ $str }}# If exists a traceAllFile_, print $str to $traceAllFile_Simulator instproc puts-nam-traceall { str } { $self instvar namtraceAllFile_ if [info exists namtraceAllFile_] { puts $namtraceAllFile_ $str
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -