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

📄 ns-node.tcl

📁 这个软件的功能是实现多播协议
💻 TCL
📖 第 1 页 / 共 2 页
字号:
	$self instvar rtnotif_	if {$rtnotif_ != ""} {		eval $rtnotif_ delete-route $args	}	$self decr-rtgtable-size}## Node support for detailed dynamic unicast routing#Node instproc init-routing rtObject {	$self instvar multiPath_ routes_ rtObject_	set nn [$class set nn_]	for {set i 0} {$i < $nn} {incr i} {		set routes_($i) 0	}	if ![info exists rtObject_] {		$self set rtObject_ $rtObject	}	$self set rtObject_}Node instproc rtObject? {} {    $self instvar rtObject_	if ![info exists rtObject_] {		return ""	} else {		return $rtObject_    }}Node instproc intf-changed {} {	$self instvar rtObject_	if [info exists rtObject_] {	;# i.e. detailed dynamic routing		$rtObject_ intf-changed	}}#----------------------------------------------------------------------# XXX Eventually add-routes{} and delete-routes{} should be # unified with add-route{} for a single interface to install routes.# Node support for equal cost multi path routingNode instproc add-routes {id ifs} {	$self instvar classifier_ multiPath_ routes_ mpathClsfr_	if !$multiPath_ {		if {[llength $ifs] > 1} {			warn "$class::$proc cannot install multiple routes"			set ifs [lindex $ifs 0]		}		$self add-route $id [$ifs head]		set routes_($id) 1		return	}	if {$routes_($id) <= 0 && [llength $ifs] == 1 && \			![info exists mpathClsfr_($id)]} {		$self add-route $id [$ifs head]		set routes_($id) 1	} else {		if ![info exists mpathClsfr_($id)] {			#			# 1. get new MultiPathClassifier,			# 2. migrate existing routes to that mclassifier			# 3. install the mclassifier in the node classifier_			#			set mpathClsfr_($id) [new Classifier/MultiPath]			if {$routes_($id) > 0} {				assert "$routes_($id) == 1"				$mpathClsfr_($id) installNext \						[$classifier_ in-slot? $id]			}			$classifier_ install $id $mpathClsfr_($id)		}		foreach L $ifs {			$mpathClsfr_($id) installNext [$L head]			incr routes_($id)		}	}}Node instproc delete-routes {id ifs nullagent} {	$self instvar mpathClsfr_ routes_	if [info exists mpathClsfr_($id)] {		foreach L $ifs {			set nonLink([$L head]) 1		}		foreach {slot link} [$mpathClsfr_($id) adjacents] {			if [info exists nonLink($link)] {				$mpathClsfr_($id) clear $slot				incr routes_($id) -1			}		}	} else {		$self delete-route $id $nullagent		incr routes_($id) -1		# Notice that after this operation routes_($id) may not 		# necessarily be 0.	}}# Enable multicast routing support in this node. # # XXX This instproc should ONLY be used when you want multicast only on a # subset of nodes as a means to save memory. If you want to run multicast on# your entire topology, use [new Simulator -multicast on].Node instproc enable-mcast args {	# Do NOT add Mcast using Node enable-module, because the latter 	# enables mcast for all nodes that may be created later	$self register-module [new RtModule/Mcast]	}#--------------------------------------------------------------## Port classifier manipulation#Node instproc alloc-port { nullagent } {	return [[$self set dmux_] alloc-port $nullagent]}Node instproc agent port {	$self instvar agents_	foreach a $agents_ {		if { [$a set agent_port_] == $port } {			return $a		}	}	return ""}Node instproc demux {} {	return [$self set dmux_]}# Install $demux as the default demuxer of the node, place the existing demux# at $port of the new demuxer. ## XXX Here we do not have a similar difference like that between # "insert-entry" and "install-entry", because even if a demux # is replaced, the associated routing module should not be removed. ## This is a rather arbitrary decision, but we do not have better clue# how demuxers will be used among routing modules.Node instproc install-demux { demux {port ""} } {	$self instvar dmux_ address_	if { $dmux_ != "" } {		$self delete-route $dmux_		if { $port != "" } {			$demux install $port $dmux_		}	}	set dmux_ $demux	$self add-route $address_ $dmux_}# Whenever an agent is attached or detached, $module should be notified.Node instproc port-notify { module } {	$self instvar ptnotif_	lappend ptnotif_ $module}Node instproc unreg-port-notify { module } {	$self instvar ptnotif_	set pos [lsearch $ptnotif_ $module]	if { $pos >= 0 } {		set ptnotif_ [lreplace $ptnotif_ $pos $pos]	}}## Attach an agent to a node: pick a port and bind the agent to the port.## To install module-specific demuxers, do that in your module's register{}# method. Since this method will be called during Node::init{}, when # Node::attach{} is called dmux_ will already be present hence the following# default dmux_ construction will not be triggered.#Node instproc attach { agent { port "" } } {	$self instvar agents_ address_ dmux_ 	#	# Assign port number (i.e., this agent receives	# traffic addressed to this host and port)	#	lappend agents_ $agent	#	# Attach agents to this node (i.e., the classifier inside).	# We call the entry method on ourself to find the front door	# (e.g., for multicast the first object is not the unicast classifier)	#	# Also, stash the node in the agent and set the local addr of 	# this agent.	#	$agent set node_ $self	$agent set agent_addr_ [AddrParams addr2id $address_]	#	# If a port demuxer doesn't exist, create it.	#	if { $dmux_ == "" } {		# Use the default mask_ and port_ values		set dmux_ [new Classifier/Port]		# point the node's routing entry to itself		# at the port demuxer (if there is one)		$self add-route $address_ $dmux_	}	if { $port == "" } {		set port [$dmux_ alloc-port [[Simulator instance] nullagent]]	}	$agent set agent_port_ $port	$self add-target $agent $port}# XXX For backward compatibility. When both satellite node and mobile node# are converted to modules, this should be merged into attach{}.Node instproc add-target { agent port } {	$self instvar ptnotif_	# Replaces the following line from old ns (2.1b7 and earlier)	#   $self add-target $agent $port	foreach m [$self set ptnotif_] {		$m attach $agent $port	}}# Detach an agent from a node.Node instproc detach { agent nullagent } {	$self instvar agents_ dmux_	#	# remove agent from list	#	set k [lsearch -exact $agents_ $agent]	if { $k >= 0 } {		set agents_ [lreplace $agents_ $k $k]	}	#	# sanity -- clear out any potential linkage	#	$agent set node_ ""	$agent set agent_addr_ 0	$agent target $nullagent	# Install nullagent to sink transit packets   	$dmux_ install [$agent set agent_port_] $nullagent	foreach m [$self set ptnotif_] {		$m detach $agent $nullagent	}}# reset all agents attached to this nodeNode instproc reset {} {	$self instvar agents_	foreach a $agents_ {		$a reset	}	foreach m [$self list-modules] {		$m reset	}}## Some helpers#Node instproc neighbors {} {	$self instvar neighbor_	return [lsort $neighbor_]}Node instproc add-neighbor {p {pushback 0}} {	$self instvar neighbor_	lappend neighbor_ $p		#added for keeping the neighbor list in the Node (for pushback) - ratul	if { $pushback == 1 } {		$self cmd add-neighbor $p	}}Node instproc is-neighbor { node } {	$self instvar neighbor_	return [expr [lsearch $neighbor_ $node] != -1]}

⌨️ 快捷键说明

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