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

📄 ns-node.tcl

📁 跑leach需要的
💻 TCL
📖 第 1 页 / 共 2 页
字号:
# -*-	Mode:tcl; tcl-indent-level:8; tab-width:8; indent-tabs-mode:t -*-## Time-stamp: <2000-09-22 09:41:04 haoboy>## Copyright (c) 1996-2000 Regents of the University of California.# All rights reserved.# # Redistribution and use in source and binary forms, with or without# modification, are permitted provided that the following conditions# are met:# 1. Redistributions of source code must retain the above copyright#    notice, this list of conditions and the following disclaimer.# 2. Redistributions in binary form must reproduce the above copyright#    notice, this list of conditions and the following disclaimer in the#    documentation and/or other materials provided with the distribution.# 3. All advertising materials mentioning features or use of this software#    must display the following acknowledgement:# 	This product includes software developed by the MASH Research# 	Group at the University of California Berkeley.# 4. Neither the name of the University nor of the Research Group may be#    used to endorse or promote products derived from this software without#    specific prior written permission.# # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF# SUCH DAMAGE.## @(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/tcl/lib/ns-node.tcl,v 1.89 2001/11/06 06:16:21 tomh Exp $#Node set nn_ 0Node proc getid {} {	set id [Node set nn_]	Node set nn_ [expr $id + 1]	return $id}# The list of modules to be installed. More can be added via node-config. # Base should always be the first module in this list.Node set module_list_ { Base }Node proc enable-module { mod_name } {	Node instvar module_list_	if { [lsearch $module_list_ $mod_name] < 0 } {		lappend module_list_ $mod_name	}}Node proc disable-module { mod_name } {	Node instvar module_list_	set pos [lsearch $module_list_ $mod_name]	if { $pos >= 0 } {		set module_list_ [lreplace $module_list_ $pos $pos]	}}Node instproc init args {	eval $self next $args        $self instvar id_ agents_ dmux_ neighbor_ rtsize_ address_ \			nodetype_ multiPath_ ns_ rtnotif_ ptnotif_	set ns_ [Simulator instance]	set id_ [Node getid]	$self nodeid $id_	;# Propagate id_ into c++ space	if {[llength $args] != 0} {		set address_ [lindex $args 0]	} else {		set address_ $id_	}	$self cmd addr $address_; # Propagate address_ into C++ space	#$ns_ add-node $self $id_        	set neighbor_ ""	set agents_ ""	set dmux_ ""        set rtsize_ 0	set ptnotif_ {}	set rtnotif_ {}	set nodetype_ [$ns_ get-nodetype]	$self mk-default-classifier	# XXX Eventually these two should also be converted to modules	set multiPath_ [$class set multiPath_]}# XXX This instproc is backward compatibility; when satellite node, mobile# node (incl. MIP) are converted to routing modules, this should be merged # into init{}Node instproc mk-default-classifier {} {	Node instvar module_list_	# At minimum we should enable base module	foreach modname [Node set module_list_] {		$self register-module [new RtModule/$modname]	}}Node instproc id {} {	return [$self set id_]}Node instproc node-addr {} {	return [$self set address_]}#----------------------------------------------------------------------# XXX This should eventually go away, as we replace nodetype_ with # routing modulesNode instproc node-type {} {	return [$self set nodetype_]}#----------------------------------------------------------------------## Module registration#Node instproc register-module { mod } {	$self instvar reg_module_	$mod register $self	set reg_module_([$mod module-name]) $mod}Node instproc unregister-module { mod } {	$self instvar reg_module_	$mod unregister	# We do not explicitly check the existence of reg_module_($name).	# If not, tcl will issue an error by itself. 	unset reg_module_([$mod module-name])	delete $mod}Node instproc list-modules {} {	$self instvar reg_module_	set ret ""	foreach n [array names reg_module_] {		lappend ret $reg_module_($n)	}	return $ret}Node instproc get-module { name } {	$self instvar reg_module_	# Must do an error check here.	if [info exists reg_module_($name)] {		return $reg_module_($name)	} else {		return ""	}}## Address classifier manipulation## Increase the routing table size counter - keeps track of rtg table # size for each node. For bookkeeping only.Node instproc incr-rtgtable-size {} {	$self instvar rtsize_	incr rtsize_}Node instproc decr-rtgtable-size {} {	$self instvar rtsize_	incr rtsize_ -1}Node instproc entry {} {	return [$self set classifier_]}# Place classifier $clsfr at the node entry point. ## - Place the existing entry at slot $hook of the new classifier. Usually #   it is an address classifier sitting in a node entry, so this means that#   a special address should be assigned to pass packets to the original #   classifier, if this is necessary. ## - Associate the new classifier with $module (stored in mod_assoc_). This#   information is used later when the associated classifier is replaced, #   then $module will be notified of this event and requested to unregister.## - The original classifier is stored in hook_assoc_, this is used in #   install-entry{} to connect the new classifier to the "classifier chain"#   to which the replaced classifier is linked.## - To install at the entry something derived from Connector rather than #   Classifier, you should specify $hook as "target". Node instproc insert-entry { module clsfr {hook ""} } {	$self instvar classifier_ mod_assoc_ hook_assoc_	if { $hook != "" } {		# Build a classifier "chain" when specified		set hook_assoc_($clsfr) $classifier_		if { $hook == "target" } {			$clsfr target $classifier_		} elseif { $hook != "" } {			$clsfr install $hook $classifier_		}	}	# Associate this module to the classifier, so if the classifier is	# removed later, we'll remove the module as well.	set mod_assoc_($clsfr) $module	set classifier_ $clsfr}# We separate insert-entry from install-entry because we need a method to # replace the current entry classifier and _remove_ routing functionality # associated with that classifier. These two methods cannot be merged by # checking whether $hook is empty. Node instproc install-entry { module clsfr {hook ""} } {	$self instvar classifier_ mod_assoc_ hook_assoc_	if [info exists classifier_] {		if [info exists mod_assoc_($classifier_)] {			$self unregister-module $mod_assoc_($classifier_)			unset mod_assoc_($classifier_)		}		# Connect the new classifier to the existing classifier chain,		# if there is any.		if [info exists hook_assoc_($classifier_)] {			if { $hook == "target" } {				$clsfr target $hook_assoc($classifier_)			} elseif { $hook != "" } {				$clsfr install $hook $hook_assoc_($classifier_)			}			set hook_assoc_($clsfr) $hook_assoc_($classifier_)			unset hook_assoc_($classifier_)		}	}	set mod_assoc_($clsfr) $module	set classifier_ $clsfr}# CHANGE:# Node no longer keeps list of all rtmodules to be notified.# Instead we now have a chain (linked list) of modules, # with rtnotif_ being the head of this linked list. # Routing info flows from thru all rtmodules linked by this # chain.# Whenever a route is added or deleted, $module should be notifiedNode instproc route-notify { module } {	$self instvar rtnotif_	if {$rtnotif_ == ""} {		set rtnotif_ $module	} else {		$rtnotif_ route-notify $module	}	$module cmd route-notify $self}Node instproc unreg-route-notify { module } {	$self instvar rtnotif_	if {$rtnotif_ != ""} {		if {$rtnotif_ == $module} {			set rtnotif_ [$rtnotif_ set next_rtm_]		} else {			$rtnotif_ unreg-route-notify $module		}	}	$module cmd unreg-route-notify $self}Node instproc add-route { dst target } {	$self instvar rtnotif_	# Notify every module that is interested about this 	# route installation		if {$rtnotif_ != ""} {		$rtnotif_ add-route $dst $target	}	$self incr-rtgtable-size}Node instproc delete-route args {

⌨️ 快捷键说明

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