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

📄 ns-sat.tcl

📁 跑leach需要的
💻 TCL
📖 第 1 页 / 共 2 页
字号:
## Copyright (c) 1999 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.## Contributed by Tom Henderson, UCB Daedalus Research Group, June 1999# @(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/tcl/lib/ns-sat.tcl,v 1.13 2002/07/10 02:29:50 tomh Exp $# ======================================================================## The Node/SatNode class (a pure virtual class)## ======================================================================Node/SatNode instproc init args {	eval $self next $args		;# parent class constructor	$self instvar nifs_ 	$self instvar phy_tx_ phy_rx_ mac_ ifq_ ll_ pos_ hm_ id_	set nifs_	0		;# number of network interfaces	# Create a drop trace to log packets for which no route exists	set ns_ [Simulator instance]	set trace_ [$ns_ get-ns-traceall]	if {$trace_ != ""} {		set dropT_ [$ns_ create-trace Sat/Drop $trace_ $self $self ""]		$self set_trace $dropT_	}	$self cmd set_address $id_ ; # Used to indicate satellite node in array}Node/SatNode instproc reset {} {        eval $self next 	$self instvar hm_ instvar nifs_ phy_tx_ phy_rx_ mac_ ifq_ ll_	set ns [Simulator instance]	set now_ [$ns now]        for {set i 0} {$i < $nifs_} {incr i} {		$phy_tx_($i) reset		$phy_rx_($i) reset		if {[info exists mac_($i)]} {			$mac_($i) reset		}		if {[info exists ll_($i)]} {			$ll_($i) reset		}		if {[info exists ifq_($i)]} {			$ifq_($i) reset		}	}	if {$now_ == 0} {		if {[info exists hm_]} {			$ns at 0.0 "$self start_handoff"		}	}}Node/SatNode instproc set_next {node_} {	$self instvar pos_	$pos_ set_next [$node_ set pos_]}## 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/SatNode instproc add-target {agent port } {	$self instvar dmux_ 		if { $port == [Node set rtagent_port_] } {					# Set the default target at C++ level.  		[$self set classifier_] defaulttarget $agent		$dmux_ install $port $agent	} else {		#		# Send Target		#		$agent target [$self entry]		#		# Recv Target		#		$dmux_ install $port $agent	}}# ======================================================================## methods for creating SatNodes## ======================================================================Simulator instproc create-satnode {} {	$self instvar satNodeType_ llType_ ifqType_ ifqlen_ macType_ \		downlinkBW_ phyType_ channelType_	if {![info exists satNodeType_]} {		puts "Error: create-satnode called, but no satNodeType_; exiting"		exit 1	}	# Case conversion (for backward compatibility)	if {$satNodeType_ == "Polar"} {set satNodeType_ "polar"}	if {$satNodeType_ == "Geo"} {set satNodeType_ "geo"}	if {$satNodeType_ == "Terminal"} {set satNodeType_ "terminal"}	if {$satNodeType_ == "Geo-repeater"} {set satNodeType_ "geo-repeater"}	if {[lsearch {polar geo terminal geo-repeater} $satNodeType_] < 0} {		puts "Error: undefined satNodeType: $satNodeType_; exiting"		exit 1	}	# Create the satnode	set tmp [$self newsatnode]	# Add uplink and downlink if this is not a terminal	if {$satNodeType_ == "polar" || $satNodeType_ == "geo"} {		set linkargs "$llType_ $ifqType_ $ifqlen_ $macType_ \		    $downlinkBW_ $phyType_"		$self add-first-links $tmp gsl $linkargs $channelType_	} elseif {$satNodeType_ == "geo-repeater"} {		$self add-first-links $tmp gsl-repeater "" $channelType_	}	return $tmp}Simulator instproc newsatnode {} {	$self instvar Node_ satNodeType_	if ![info exists satNodeType_] {		puts "Error: satNodeType_ does not exist in newsatnode; exiting"		exit 1	}	set node [new Node/SatNode]	# Create a routing agent for all types except the repeater node	if {$satNodeType_ == "polar" || $satNodeType_ == "geo" || \	    $satNodeType_ == "terminal"} {		$node create-ragent	}	set Node_([$node id]) $node	$node set ns_ $self	if [$self multicast?] {		$node enable-mcast $self	}	$self check-node-num	return $node}Node/SatNode instproc set-position args {	set ns_ [Simulator instance]	set nodetype_ [$ns_ set satNodeType_]	if {$nodetype_ == "polar"} {		if {[llength $args] != 5 } {			puts "Error:  satNodeType_ is polar, but number\			      of position arguments incorrect: $args; exiting"			exit 1		}		$self set pos_ [new Position/Sat/Polar $args]		$self cmd set_position [$self set pos_]		[$self set pos_] setnode $self		# Set up handoff manager		$self set hm_ [new HandoffManager/Sat]		$self cmd set_handoff_mgr [$self set hm_]		[$self set hm_] setnode $self	} elseif {$nodetype_ == "geo" || $nodetype_ == "geo-repeater"} {		if {[llength $args] != 1 } {			puts "Error:  satNodeType_ is geo, but number\			      of position arguments incorrect: $args; exiting"			exit 1		}		$self set pos_ [new Position/Sat/Geo $args]		$self cmd set_position [$self set pos_]		[$self set pos_] setnode $self	} elseif {$nodetype_ == "terminal"} {		if {[llength $args] != 2 } {			puts "Error:  satNodeType_ is terminal, but number\		              of position arguments incorrect: $args; exiting"			exit 1		}		$self set pos_ [new Position/Sat/Term $args]		$self cmd set_position [$self set pos_]		[$self set pos_] setnode $self		$self set hm_ [new HandoffManager/Term]		$self cmd set_handoff_mgr [$self set hm_]		[$self set hm_] setnode $self	} else {		puts "Error:  satNodeType_ not set appropriately:\		     $satNodeType_ exiting"		exit 1	}}## Backward compatibility code starts# Wrapper method for making a polar satellite node that first creates a # satnode plus two link interfaces (uplink and downlink) plus two # satellite channels (uplink and downlink)# Additional ISLs can be added laterSimulator instproc satnode-polar {alt inc lon alpha plane linkargs chan} {        set tmp [$self satnode polar $alt $inc $lon $alpha $plane]	$self add-first-links $tmp gsl $linkargs $chan        return $tmp}# Wrapper method for making a geo satellite node that first creates a # satnode plus two link interfaces (uplink and downlink) plus two # satellite channels (uplink and downlink)Simulator instproc satnode-geo {lon linkargs chan} {        set tmp [$self satnode geo $lon]	$self add-first-links $tmp gsl $linkargs $chan	return $tmp}# Wrapper method for making a geo satellite repeater node that first creates a # satnode plus two link interfaces (uplink and downlink) plus two # satellite channels (uplink and downlink)Simulator instproc satnode-geo-repeater {lon chan} {        set tmp [$self satnode geo $lon]	$self add-first-links $tmp gsl-repeater "" $chan	return $tmp}# Wrapper method that does nothing really but makes the API consistent Simulator instproc satnode-terminal {lat lon} {	$self satnode terminal $lat $lon}Simulator instproc satnode args {	$self instvar Node_	set node [new Node/SatNode]	if {[lindex $args 0] == "polar" || [lindex $args 0] == "Polar"} {		set args [lreplace $args 0 0]		# Set up position object		$node set pos_ [new Position/Sat/Polar $args]		$node cmd set_position [$node set pos_]		[$node set pos_] setnode $node		# Set up handoff manager		$node set hm_ [new HandoffManager/Sat]		$node cmd set_handoff_mgr [$node set hm_]		[$node set hm_] setnode $node		$node create-ragent 	} elseif {[lindex $args 0] == "geo" || [lindex $args 0] == "Geo"} {  		set args [lreplace $args 0 0]		$node set pos_ [new Position/Sat/Geo $args]		$node cmd set_position [$node set pos_]		[$node set pos_] setnode $node		$node create-ragent	} elseif {[lindex $args 0] == "geo-repeater" || [lindex $args 0] == "Geo-repeater"} {  		set args [lreplace $args 0 0]		$node set pos_ [new Position/Sat/Geo $args]		$node cmd set_position [$node set pos_]		[$node set pos_] setnode $node	} elseif {[lindex $args 0] == "terminal" || [lindex $args 0] == "Terminal"} {  		set args [lreplace $args 0 0]		$node set pos_ [new Position/Sat/Term $args]		$node cmd set_position [$node set pos_]		[$node set pos_] setnode $node		$node set hm_ [new HandoffManager/Term]		$node cmd set_handoff_mgr [$node set hm_]		[$node set hm_] setnode $node		$node create-ragent	} else {		puts "Otcl error; satnode specified incorrectly: $args"	}	set Node_([$node id]) $node	$node set ns_ $self        if [$self multicast?] {                $node enable-mcast $self        }	$self check-node-num	return $node}## Backward compatibility code ends # ======================================================================## methods for creating satellite links, channels, and error models## ======================================================================# Helper method for creating uplinks and downlinks for a satellite nodeSimulator instproc add-first-links {node_ linktype linkargs chan} {	$node_ set_downlink $chan        $node_ set_uplink $chan        # Add the interface for these channels and then attach the channels	if {$linktype == "gsl-repeater"} {		$node_ add-repeater $chan	} else {        	eval $node_ add-interface $linktype $linkargs	}        $node_ attach-to-outlink [$node_ set downlink_]        $node_ attach-to-inlink [$node_ set uplink_]}#  Add network stack and attach to the channels Node/SatNode instproc add-gsl {ltype opt_ll opt_ifq opt_qlim opt_mac \opt_bw opt_phy opt_inlink opt_outlink} {	$self add-interface $ltype $opt_ll $opt_ifq $opt_qlim $opt_mac $opt_bw \		$opt_phy 	$self attach-to-inlink $opt_inlink	$self attach-to-outlink $opt_outlink}# Add network stacks for ISLs, and create channels for themSimulator instproc add-isl {ltype node1 node2 bw qtype qlim} {	set opt_ll LL/Sat	set opt_mac Mac/Sat	set opt_phy Phy/Sat	set opt_chan Channel/Sat	set chan1 [new $opt_chan]	set chan2 [new $opt_chan]	$node1 add-interface $ltype $opt_ll $qtype $qlim $opt_mac $bw $opt_phy $chan1 $chan2	$node2 add-interface $ltype $opt_ll $qtype $qlim $opt_mac $bw $opt_phy $chan2 $chan1	if {$ltype == "crossseam"} {		# Add another spare interface between node 1 and node 2		$node1 add-interface $ltype $opt_ll $qtype $qlim $opt_mac $bw $opt_phy 		$node2 add-interface $ltype $opt_ll $qtype $qlim $opt_mac $bw $opt_phy 			}}Node/SatNode instproc add-repeater chan { 	$self instvar nifs_ phy_tx_ phy_rx_ linkhead_ 	set t $nifs_	incr nifs_	# linkhead_($t) is a simple connector that provides an API for	# accessing elements of the network interface stack	set linkhead_($t) [new Connector/LinkHead/Sat]	set phy_tx_($t)	[new Phy/Repeater]		;# interface	set phy_rx_($t)	[new Phy/Repeater]	# linkhead maintains a collection of pointers	$linkhead_($t) setnode $self	$linkhead_($t) setphytx $phy_tx_($t)	$linkhead_($t) setphyrx $phy_rx_($t)	$linkhead_($t) set_type "gsl-repeater"	$linkhead_($t) set type_ "gsl-repeater"	$phy_rx_($t) up-target $phy_tx_($t)	$phy_tx_($t) linkhead $linkhead_($t)	$phy_rx_($t) linkhead $linkhead_($t)	$phy_tx_($t) node $self		;# Bind node <---> interface	$phy_rx_($t) node $self		;# Bind node <---> interface}##  The following sets up link layer, mac layer, interface queue #  and physical layer structures for the satellite nodes.#  Propagation model is an optional argument#Node/SatNode instproc add-interface args { 	$self instvar nifs_ phy_tx_ phy_rx_ mac_ ifq_ ll_ drophead_ linkhead_	global ns_ MacTrace opt	set t $nifs_	incr nifs_	# linkhead_($t) is a simple connector that provides an API for	# accessing elements of the network interface stack	set linkhead_($t) [new Connector/LinkHead/Sat]	set linktype 	[lindex $args 0]	set ll_($t)	[new [lindex $args 1]]		;# link layer	set ifq_($t)	[new [lindex $args 2]]		;# interface queue	set qlen	[lindex $args 3]	set mac_($t)	[new [lindex $args 4]]		;# mac layer	set mac_bw	[lindex $args 5]	set phy_tx_($t)	[new [lindex $args 6]]		;# interface	set phy_rx_($t)	[new [lindex $args 6]]		;# interface	set inchan 	[lindex $args 7]	set outchan 	[lindex $args 8]	set drophead_($t) [new Connector]	;# drop target for queue	set iif_($t) [new NetworkInterface]	

⌨️ 快捷键说明

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