⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ns-lib.tcl

📁 ZigBee路由协议指的是ZigBee规范中规定的与路由相关的功能和算法部分
💻 TCL
📖 第 1 页 / 共 4 页
字号:
	}	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	} 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]	$p tagged [Simulator set TaggedTrace_]	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}# Armando L. Caro Jr. <acaro@@cis,udel,edu> 10/22/2001Simulator instproc multihome-attach-agent { core agent } {      	$agent set-multihome-core [$core entry]      	foreach interface [$core set multihome_interfaces_] {  		set ifNode [lindex $interface 0]		set coreLink [lindex $interface 1]      		# attach agent to the node for each interface      		$ifNode attach $agent      		set addr [$agent set agent_addr_]      		set port [$agent set agent_port_]      		set entry [$ifNode entry]      		# give the interface info to the agent		$agent add-multihome-interface $addr $port $entry $coreLink			      		$agent instvar multihome_bindings_      		set binding_ {}      		lappend binding_ $addr      		lappend binding_ $port      		lappend multihome_bindings_ $binding_      	}}Simulator instproc attach-agent { node agent } {	$node attach $agent	# $agent set nodeid_ [$node id]        # Armando L. Caro Jr. <acaro@@cis,udel,edu> 10/22/2001 	#	# list of tuples (addr, port)	# This is NEEDED so that single homed agents can play with multihomed	# ones!	# multihoming only for SCTP agents -Padma H.	if {[lindex [split [$agent info class] "/"] 1] == "SCTP"} {		$agent instvar multihome_bindings_		set binding_ {}		set addr [$agent set agent_addr_]		set port [$agent set agent_port_]		lappend binding_ $addr		lappend binding_ $port		lappend multihome_bindings_ $binding_	}}Simulator instproc attach-tbf-agent { node agent tbf } {	$node attach $agent	$agent attach-tbf $tbf}Simulator instproc detach-agent { node agent } {	# Debo added this	$self instvar conn_ nconn_ sflows_ nsflows_ useasim_	if {$useasim_ == 1} {		set list "" 		set s [$node id]		set d [[$self get-node-by-addr [$agent set dst_addr_]] id]		foreach x $conn_ {			set t [split $x ":"] 			if {[string compare [lindex $t 0]:[lindex $t 1] $s:$d] != 0} {				lappend list_ $x			}		}		set conn_ list		set nconn_ [expr $nconn_ -1]		# ---------------------------------------	}	$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 instvar conn_ nconn_ sflows_ nsflows_ useasim_        # Armando L. Caro Jr. <acaro@@cis,udel,edu>	# does the agent type support multihoming??	# @@@ do we need to worry about $useasim_ below?? (wasn't in 2.1b8)    	if {[lindex [split [$src info class] "/"] 1] == "SCTP"} {    		$self multihome-connect $src $dst    	}	$self simplex-connect $src $dst	$self simplex-connect $dst $src	# Debo	if {$useasim_ == 1} {		set sid [$src nodeid]		set sport [$src set agent_port_]		set did [$dst nodeid]		set dport [$dst set agent_port_]				if {[lindex [split [$src info class] "/"] 1] == "TCP"} {			lappend conn_ $sid:$did:$sport:$dport			incr nconn_			# set $nconn_ [expr $nconn_ + 1]			# puts "Set a connection with id $nconn_ between $sid and $did"		}	}	return $src}# Armando L. Caro Jr. <acaro@@cis,udel,edu> 10/12/2001Simulator instproc multihome-connect {src dst} {	        set destNum 0	foreach binding [$src set multihome_bindings_] {		incr destNum  		set addr [lindex $binding 0]  		set port [lindex $binding 1]      		$dst add-multihome-destination $addr $port    	}	if {$destNum == 0} {	        # src isn't multihomed, so make sure we do an		# add-multihome-destination		$dst add-multihome-destination \				[$src set agent_addr_] [$src set agent_port_]	}	        set destNum 0	foreach binding [$dst set multihome_bindings_] {		incr destNum  		set addr [lindex $binding 0]  		set port [lindex $binding 1]      		$src add-multihome-destination $addr $port    	}	if {$destNum == 0} {	        # dst isn't multihomed, so make sure we do an		# add-multihome-destination		$src add-multihome-destination \				[$dst set agent_addr_] [$dst set agent_port_]	}}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] {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -