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

📄 ns-mobilenode.tcl

📁 NS-2.28的802.11e协议扩展源代码
💻 TCL
📖 第 1 页 / 共 2 页
字号:
## Copyright (c) 1996-1998 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: ## Ported from CMU-Monarch project's mobility extensions -Padma, 10/98.##IT IS NOT ENCOURAGED TO SUBCLASSS MOBILNODE CLASS DEFINED IN THIS FILE#Class ARPTable# ======================================================================## The ARPTable class## ======================================================================ARPTable instproc init args {	eval $self next $args		;# parent class constructor}ARPTable set bandwidth_         0ARPTable set delay_             5usARPTable set off_prune_         0ARPTable set off_CtrMcast_      0# ======================================================================## PHY/MAC/PLevels MIBs## ======================================================================proc create_mibs { } {	global plevels_ phy_mib_ mac_mib_	if {![info exists plevels_]} {		set plevels_ [new PLevels]	;# has to be created from Tcl	}	if {![info exists phy_mib_]} {		set phy_mib_ [new PHY_MIB]	;# has to be created from Tcl	}	if {![info exists mac_mib_]} {		set mac_mib_ [new MAC_MIB]	;# has to be created from Tcl	}}PLevels set max_plevels_	  8	;# 8 priority levels availablePLevels set plevels_		  1	;# single priority level used by defaultMAC_MIB set RTSThreshold_	 -1	;# use default from C++ codeMAC_MIB set ShortRetryLimit_	 -1	;# use default from C++ codeMAC_MIB set LongRetryLimit_	 -1	;# use default from C++ codePHY_MIB set CWMin_0		 -1	;# use default from C++ codePHY_MIB set CWMin_1		 -1	;# use default from C++ codePHY_MIB set CWMin_2		 -1	;# use default from C++ codePHY_MIB set CWMin_3		 -1	;# use default from C++ codePHY_MIB set CWMin_4		 -1	;# use default from C++ codePHY_MIB set CWMin_5		 -1	;# use default from C++ codePHY_MIB set CWMin_6		 -1	;# use default from C++ codePHY_MIB set CWMin_7		 -1	;# use default from C++ codePHY_MIB set CWMax_0		 -1	;# use default from C++ codePHY_MIB set CWMax_1		 -1	;# use default from C++ codePHY_MIB set CWMax_2		 -1	;# use default from C++ codePHY_MIB set CWMax_3		 -1	;# use default from C++ codePHY_MIB set CWMax_4		 -1	;# use default from C++ codePHY_MIB set CWMax_5		 -1	;# use default from C++ codePHY_MIB set CWMax_6		 -1	;# use default from C++ codePHY_MIB set CWMax_7		 -1	;# use default from C++ codePHY_MIB set CWOffset_0		 -1	;# use default from C++ codePHY_MIB set CWOffset_1		 -1	;# use default from C++ codePHY_MIB set CWOffset_2		 -1	;# use default from C++ codePHY_MIB set CWOffset_3		 -1	;# use default from C++ codePHY_MIB set CWOffset_4		 -1	;# use default from C++ codePHY_MIB set CWOffset_5		 -1	;# use default from C++ codePHY_MIB set CWOffset_6		 -1	;# use default from C++ codePHY_MIB set CWOffset_7		 -1	;# use default from C++ codePHY_MIB set SlotTime_		 -1	;# use default from C++ codePHY_MIB set SIFS_		 -1	;# use default from C++ codePHY_MIB set MinimumBandwidth_	0Mb	;# use default from C++ code# ======================================================================## The Node/MobileNode class## ======================================================================Node/MobileNode instproc init args {    $self instvar nifs_ arptable_    $self instvar netif_ mac_ ifq_ ll_    $self instvar X_ Y_ Z_    $self instvar address_    $self instvar nodetype_    if {[llength $args] != 0} {	set address_ $args		set args [lreplace $args 0 1]    }        eval $self next $args		;# parent class constructor        set X_ 0.0    set Y_ 0.0    set Z_ 0.0    set arptable_ ""			;# no ARP table yet    set nifs_ 0				;# number of network interfaces       # MIP node processing    $self makemip-New$nodetype_        }Node/MobileNode instproc makemip-New {} {}Node/MobileNode instproc makemip-NewBase {} {}Node/MobileNode instproc makemip-NewMobile {} {}Node/MobileNode instproc makemip-NewMIPBS {} {   $self instvar regagent_ encap_ decap_ agents_ address_ dmux_ id_   if { $dmux_ == "" } {       set dmux_ [new Classifier/Port/Reserve]       $dmux_ set mask_ 0x7fffffff       $dmux_ set shift_ 0              if [Simulator set EnableHierRt_] {  	   $self add-hroute $address_ $dmux_       } else {	   $self add-route $address_ $dmux_       }   }       set regagent_ [new Agent/MIPBS $self]      $self attach $regagent_ [Node/MobileNode  set REGAGENT_PORT]   $self attach-encap    $self attach-decap}Node/MobileNode instproc makemip-NewMIPMH {} {    $self instvar regagent_ dmux_ address_     if { $dmux_ == "" } {	set dmux_ [new Classifier/Port/Reserve]	$dmux_ set mask_ 0x7fffffff	$dmux_ set shift_ 0		if [Simulator set EnableHierRt_] {  	    $self add-hroute $address_ $dmux_	} else {	    $self add-route $address_ $dmux_	}    }         set regagent_ [new Agent/MIPMH $self]    $self attach $regagent_ [Node/MobileNode set REGAGENT_PORT]    $regagent_ node $self}Node/MobileNode instproc attach-encap {} {    $self instvar encap_ address_         set encap_ [new MIPEncapsulator]    set mask 0x7fffffff    set shift 0    if [Simulator set EnableHierRt_] {	set nodeaddr [AddrParams set-hieraddr $address_]    } else {	set nodeaddr [expr ( $address_ &			\		[AddrParams set NodeMask_(1)] ) <<	\		[AddrParams set NodeShift_(1) ]]    }    $encap_ set addr_ [expr ( ~($mask << $shift) & $nodeaddr)]    $encap_ set port_ 1    $encap_ target [$self entry]    $encap_ set node_ $self    #$encap_ set mask_ [AddrParams set NodeMask_(1)]    #$encap_ set shift_ [AddrParams set NodeShift_(1)]}Node/MobileNode instproc attach-decap {} {    $self instvar decap_ dmux_ agents_        set decap_ [new Classifier/Addr/MIPDecapsulator]    lappend agents_ $decap_    set mask 0x7fffffff    set shift 0    if {[expr [llength $agents_] - 1] > $mask} {	error "\# of agents attached to node $self exceeds port-field length of $mask bits\n"    }    $dmux_ install [Node/MobileNode set DECAP_PORT] $decap_    #$decap_ set mask_ [AddrParams set NodeMask_(1)]    #$decap_ set shift_ [AddrParams set NodeShift_(1)]    #$decap_ def-target [$self entry]}Node/MobileNode instproc reset {} {	$self instvar arptable_ nifs_	$self instvar netif_ mac_ ifq_ ll_	$self instvar imep_        for {set i 0} {$i < $nifs_} {incr i} {	    $netif_($i) reset	    $mac_($i) reset	    $ll_($i) reset	    $ifq_($i) reset	    if { [info exists opt(imep)] && $opt(imep) == "ON" } { $imep_($i) reset }	}	if { $arptable_ != "" } {	    $arptable_ reset 	}}## Attach an agent to a node.  Pick a port and# bind the agent to the port number.# if portnumber is 255, default target is set to the routing agent#Node/MobileNode instproc add-target {agent port } {    #global opt    $self instvar dmux_ classifier_    $self instvar imep_ toraDebug_    $self instvar namtraceFile_      set ns_ [Simulator instance]    set newapi [$ns_ imep-support]    $agent set sport_ $port    #special processing for TORA/IMEP node    set toraonly [string first "TORA" [$agent info class]]     if {$toraonly != -1 } {	$agent if-queue [$self set ifq_(0)]    ;# ifq between LL and MAC	 #        # XXX: The routing protocol and the IMEP agents needs handles        # to each other.        #        $agent imep-agent [$self set imep_(0)]        [$self set imep_(0)] rtagent $agent    }    # speciall processing for AODV    set aodvonly [string first "AODV" [$agent info class]]     if {$aodvonly != -1 } {	$agent if-queue [$self set ifq_(0)]    ;# ifq between LL and MAC    }        if { $port == 255 } {			# routing agents	if { [Simulator set RouterTrace_] == "ON" } {	    #	    # Send Target	    #	    	    if {$newapi != ""} {	        set sndT [$ns_ mobility-trace Send "RTR" $self]	    } else {		set sndT [cmu-trace Send "RTR" $self]	    }            if [info exists namtraceFile_] {                $sndT namattach $namtraceFile_            }            if { $newapi == "ON" } {                 $agent target $imep_(0)                 $imep_(0) sendtarget $sndT		 # second tracer to see the actual                 # types of tora packets before imep packs them                 #if { [info exists opt(debug)] && $opt(debug) == "ON" } {		  if { [info exists toraDebug_] && $toraDebug_ == "ON"} {                       set sndT2 [$ns_ mobility-trace Send "TRP" $self]                       $sndT2 target $imep_(0)                       $agent target $sndT2                 }             } else {  ;#  no IMEP                  $agent target $sndT             }	    	    $sndT target [$self set ll_(0)]#	    $agent target $sndT	    	    #	    # Recv Target	    #	     	    if {$newapi != ""} {	         set rcvT [$ns_ mobility-trace Recv "RTR" $self]	    } else {		 set rcvT [cmu-trace Recv "RTR" $self]	    }            if [info exists namtraceFile_] {                $rcvT namattach $namtraceFile_            }            if {$newapi == "ON" } {            #    puts "Hacked for tora20 runs!! No RTR revc trace"                [$self set ll_(0)] up-target $imep_(0)                $classifier_ defaulttarget $agent                # need a second tracer to see the actual                # types of tora packets after imep unpacks them                #if { [info exists opt(debug)] && $opt(debug) == "ON" } {		# no need to support any hier node		if {[info exists toraDebug_] && $toraDebug_ == "ON" } {		    set rcvT2 [$ns_ mobility-trace Recv "TRP" $self]		    $rcvT2 target $agent		    [$self set classifier_] defaulttarget $rcvT2		}		             } else {                 $rcvT target $agent		 $self install-defaulttarget $rcvT#                 [$self set classifier_] defaulttarget $rcvT#		 $classifier_ defaulttarget $rcvT                 $dmux_ install $port $rcvT	     }#	    $rcvT target $agent#	    $classifier_ defaulttarget $rcvT#	    $dmux_ install $port $rcvT	    	} else {	    #	    # Send Target	    #	    # if tora is used            if { $newapi == "ON" } {                 $agent target $imep_(0)                 # $imep_(0) sendtarget $sndT		 # second tracer to see the actual                 # types of tora packets before imep packs them                 #if { [info exists opt(debug)] && $opt(debug) == "ON" } {		  if { [info exists toraDebug_] && $toraDebug_ == "ON"} {                       set sndT2 [$ns_ mobility-trace Send "TRP" $self]                       $sndT2 target $imep_(0)                       $agent target $sndT2                 }		 $imep_(0) sendtarget [$self set ll_(0)]             } else {  ;#  no IMEP		 		 $agent target [$self set ll_(0)]                 # $agent target $sndT             }    	    #$agent target [$self set ll_(0)]			    #	    # Recv Target	    #            if {$newapi == "ON" } {            #    puts "Hacked for tora20 runs!! No RTR revc trace"                [$self set ll_(0)] up-target $imep_(0)                $classifier_ defaulttarget $agent                # need a second tracer to see the actual                # types of tora packets after imep unpacks them                #if { [info exists opt(debug)] && $opt(debug) == "ON" } 		# no need to support any hier node		if {[info exists toraDebug_] && $toraDebug_ == "ON" } {		    set rcvT2 [$ns_ mobility-trace Recv "TRP" $self]		    $rcvT2 target $agent		    [$self set classifier_] defaulttarget $rcvT2		}	    } else {	        $self install-defaulttarget $agent	    	        #$classifier_ defaulttarget $agent	        $dmux_ install $port $agent	    }	}	    } else {	if { [Simulator set AgentTrace_] == "ON" } {	    #	    # Send Target	    #	   	    if {$newapi != ""} {	        set sndT [$ns_ mobility-trace Send AGT $self]			    } else {		set sndT [cmu-trace Send AGT $self]            }            if [info exists namtraceFile_]  {                $sndT namattach $namtraceFile_            }	    $sndT target [$self entry]	    $agent target $sndT			    #	    # Recv Target	    #	    if {$newapi != ""} {	        set rcvT [$ns_ mobility-trace Recv AGT $self]	    } else {		set rcvT [cmu-trace Recv AGT $self]	    }            if [info exists namtraceFile_]  {	       $rcvT namattach $namtraceFile_	    }	    $rcvT target $agent	    $dmux_ install $port $rcvT			} else {	    #	    # Send Target	    #	    $agent target [$self entry]	    	    #	    # Recv Target	    #	    $dmux_ install $port $agent	}    }}# set transmission powerNode/MobileNode instproc setPt { val } {    $self instvar netif_    $netif_(0) setTxPower $val}# set receiving powerNode/MobileNode instproc setPr { val } {    $self instvar netif_    $netif_(0) setRxPower $val}# set idle power -- ChalermekNode/MobileNode instproc setPidle { val } {    $self instvar netif_    $netif_(0) setIdlePower $val}

⌨️ 快捷键说明

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