📄 ns-sat.tcl
字号:
## 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.6 1999/10/19 05:05:32 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_ 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_ }}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 == 255 } { # 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## ======================================================================# 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}# ======================================================================## 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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -