?? ns-lib.tcl~
字號:
} } 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] }}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_ if {$file != ""} { set namtraceAllFile_ $file } else { unset namtraceAllFile_ } if { $optx != "" && $opty != "" } { $self puts-nam-config "W -t * -x $optx -y $opty" }}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}Simulator instproc namtrace-all-wireless {file optx opty} { $self instvar namtraceAllFile_ if {$file != ""} { set namtraceAllFile_ $file } else { unset namtraceAllFile_ } $self puts-nam-config "W -t * -x $optx -y $opty"}# 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 } elseif [info exists namtraceSomeFile_] { puts $namtraceSomeFile_ $str }}# namConfigFile is used for writing color/link/node/queue/annotations. # XXX It cannot co-exist with namtraceAll.Simulator instproc namtrace-config { f } { $self instvar namConfigFile_ set namConfigFile_ $f}Simulator instproc get-nam-config {} { $self instvar namConfigFile_ if [info exists namConfigFile_] { return $namConfigFile_ } else { return "" }}# Used only for writing nam configurations to trace file(s). This is different# from puts-nam-traceall because we may want to separate configuration # informations and actual tracing informationSimulator instproc puts-nam-config { str } { $self instvar namtraceAllFile_ namConfigFile_ if [info exists namConfigFile_] { puts $namConfigFile_ $str } elseif [info exists namtraceAllFile_] { puts $namtraceAllFile_ $str } elseif [info exists namtraceSomeFile_] { puts $namtraceSomeFile_ $str }}Simulator instproc color { id name } { $self instvar color_ set color_($id) $name}Simulator instproc get-color { id } { $self instvar color_ return $color_($id)}# you can pass in {} as a null fileSimulator instproc create-trace { type file src dst {op ""} } { $self instvar alltrace_ set p [new Trace/$type] if [catch {$p set src_ [$src id]}] { $p set src_ $src } if [catch {$p set dst_ [$dst id]}] { $p set dst_ $dst } lappend alltrace_ $p if {$file != ""} { $p ${op}attach $file } return $p}Simulator instproc create-eventtrace {type owner } { $self instvar alltrace_ $self instvar eventTraceAll_ eventtraceAllFile_ namtraceAllFile_ if ![info exists eventTraceAll_] return if { $eventTraceAll_ == 1 } { set et [new BaseTrace/$type] $owner cmd eventtrace $et lappend alltrace_ $et $et attach $eventtraceAllFile_ if [info exists namtraceAllFile_] { $et namattach $namtraceAllFile_ } }}Simulator instproc namtrace-queue { n1 n2 {file ""} } { $self instvar link_ namtraceAllFile_ if {$file == ""} { if ![info exists namtraceAllFile_] return set file $namtraceAllFile_ } $link_([$n1 id]:[$n2 id]) nam-trace $self $file # Added later for queue specific tracing events other than enque, # deque and drop as of now nam does not understand special events. # Changes will have to be made to nam for it to understand events # like early drops if they are prefixed differently than "d". - ratul set queue [$link_([$n1 id]:[$n2 id]) queue] $queue attach-nam-traces $n1 $n2 $file}Simulator instproc trace-queue { n1 n2 {file ""} } { $self instvar link_ traceAllFile_ if {$file == ""} { if ![info exists traceAllFile_] return set file $traceAllFile_ } $link_([$n1 id]:[$n2 id]) trace $self $file # Added later for queue specific tracing events other than enque, # deque and drop - ratul set queue [$link_([$n1 id]:[$n2 id]) queue] $queue attach-traces $n1 $n2 $file}## arrange for queue length of link between nodes n1 and n2# to be tracked and return object that can be queried# to learn average q size etc. XXX this API still rough#Simulator instproc monitor-queue { n1 n2 qtrace { sampleInterval 0.1 } } { $self instvar link_ return [$link_([$n1 id]:[$n2 id]) init-monitor $self $qtrace $sampleInterval]}Simulator instproc queue-limit { n1 n2 limit } { $self instvar link_ [$link_([$n1 id]:[$n2 id]) queue] set limit_ $limit}Simulator instproc drop-trace { n1 n2 trace } { $self instvar link_ [$link_([$n1 id]:[$n2 id]) queue] drop-target $trace}Simulator instproc cost {n1 n2 c} { $self instvar link_ $link_([$n1 id]:[$n2 id]) cost $c}Simulator instproc attach-agent { node agent } { $node attach $agent # $agent set nodeid_ [$node id]}Simulator instproc attach-tbf-agent { node agent tbf } { $node attach $agent $agent attach-tbf $tbf}Simulator instproc detach-agent { node agent } { $self instvar nullAgent_ $node detach $agent $nullAgent_}## Helper proc for setting delay on an existing link#Simulator instproc delay { n1 n2 delay {type simplex} } { $self instvar link_ set sid [$n1 id] set did [$n2 id] if [info exists link_($sid:$did)] { set d [$link_($sid:$did) link] $d set delay_ $delay } if {$type == "duplex"} { if [info exists link_($did:$sid)] { set d [$link_($did:$sid) link] $d set delay_ $delay } }}# # Helper proc for setting bandwidth on an existing link#Simulator instproc bandwidth { n1 n2 bandwidth {type simplex} } { $self instvar link_ set sid [$n1 id] set did [$n2 id] if [info exists link_($sid:$did)] { set d [$link_($sid:$did) link] $d set bandwidth_ $bandwidth } if {$type == "duplex"} { if [info exists link_($did:$sid)] { set d [$link_($did:$sid) link] $d set bandwidth_ $bandwidth } }}#XXX need to check that agents are attached to nodes alreadySimulator instproc connect {src dst} { $self simplex-connect $src $dst $self simplex-connect $dst $src # Debo global nconn_ conn_ set sid [$src nodeid] set did [$dst nodeid] if {[lindex [split [$src info class] "/"] 1] == "TCP"} { set conn_($nconn_) $sid:$did incr nconn_ # set $nconn_ [expr $nconn_ + 1] # puts "Set a connection with id $nconn_ between $sid and $did" } return $src}Simulator instproc simplex-connect { src dst } { $src set dst_addr_ [$dst set agent_addr_] $src set dst_port_ [$dst set agent_port_] # Polly Huang: to support abstract TCP simulations if {[lindex [split [$src info class] "/"] 1] == "AbsTCP"} { $self at [$self now] "$self rtt $src $dst" $dst set class_ [$src set class_] } return $src}## Here are a bunch of helper methods.#Simulator proc instance {} { set ns [Simulator info instances] if { $ns != "" } { return $ns } foreach sim [Simulator info subclass] { set ns [$sim info instances] if { $ns != "" } { return $ns } } error "Cannot find instance of simulator"}Simulator instproc get-number-of-nodes {} { return [$self array size Node_]}Simulator instproc get-node-by-id id { $self instvar Node_ return $Node_($id)}# Given an node's address, Return the node-idSimulator instproc get-node-id-by-addr address { $self instvar Node_ set n [Node set nn_] for {set q 0} {$q < $n} {incr q} { set nq $Node_($q) if {[string compare [$nq node-addr] $address] == 0} { return $q } } error "get-node-id-by-addr:Cannot find node with given address"}# Given an node's address, return the node Simulator instproc get-node-by-addr address { return [$self get-node-by-id [$self get-node-id-by-addr $address]]}Simulator instproc all-nodes-list {} { $self instvar Node_ set nodes "" foreach n [lsort -dictionary [array names Node_]] { lappend nodes $Node_($n) } return $nodes}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -