📄 ns-sat.tcl
字号:
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] # # Local Variables # #set nullAgent_ [$ns_ set nullAgent_] set linkhead $linkhead_($t) set phy_tx $phy_tx_($t) set phy_rx $phy_rx_($t) set mac $mac_($t) set ifq $ifq_($t) set ll $ll_($t) set drophead $drophead_($t) set iif $iif_($t) # linkhead maintains a collection of pointers $linkhead setnode $self $linkhead setll $ll $linkhead setmac $mac $linkhead setqueue $ifq $linkhead setphytx $phy_tx $linkhead setphyrx $phy_rx $linkhead setnetinf $iif $self addlinkhead $linkhead; # Add NetworkInterface to node's list $linkhead target $ll; $linkhead set_type $linktype $linkhead set type_ $linktype # # NetworkInterface # $iif target [$self entry] # # Link Layer # $ll mac $mac; # XXX is this needed? $ll up-target $iif $ll down-target $ifq $ll set delay_ 0ms; # processing delay between ll and ifq # # Interface Queue # $ifq target $mac $ifq set qlim_ $qlen $drophead target [[Simulator instance] set nullAgent_] $ifq drop-target $drophead # # Mac Layer # $mac netif $phy_tx; # Not used by satellite code at this time $mac up-target $ll $mac down-target $phy_tx $mac set bandwidth_ $mac_bw; #$mac nodes $opt(nn) # # Physical Layer # $phy_rx up-target $mac $phy_tx linkhead $linkhead $phy_rx linkhead $linkhead $phy_tx node $self ;# Bind node <---> interface $phy_rx node $self ;# Bind node <---> interface # If we have a channel to attach this link to (for an point-to-point # ISL), do so here if {$outchan != "" && $inchan != ""} { $phy_tx channel $outchan $phy_rx channel $inchan # Add to list of Phys receiving on the channel $inchan addif $phy_rx } return $t}Node/SatNode instproc set_uplink {chan} { $self instvar uplink_ set uplink_ [new $chan] $self cmd set_uplink $uplink_}Node/SatNode instproc set_downlink {chan} { $self instvar downlink_ set downlink_ [new $chan] $self cmd set_downlink $downlink_}# Attaches channel to the phy indexed by "index" (by default, the first one)Node/SatNode instproc attach-to-outlink {chan {index 0} } { $self instvar phy_tx_ mac_ $phy_tx_($index) channel $chan #$mac_($index) channel $chan; # For mac addr resolution (rather than ARP)}# Attaches channel to the phy indexed by "index" (by default, the first one)Node/SatNode instproc attach-to-inlink { chan {index 0}} { $self instvar phy_rx_ $phy_rx_($index) channel $chan $chan addif $phy_rx_($index)}# Attaches error model to interface "index" (by default, the first one)Node/SatNode instproc interface-errormodel { em { index 0 } } { $self instvar mac_ ll_ em_ linkhead_ $mac_($index) up-target $em $em target $ll_($index) $em drop-target [new Agent/Null]; # otherwise, packet is only marked set em_($index) $em $linkhead_($index) seterrmodel $em} # ======================================================================## methods for routing ## ======================================================================# Create a network interface (for one uplink and downlink), add routing agent# At least one interface must be created before routing agent is addedNode/SatNode instproc create-ragent {} { set ragent [new Agent/SatRoute] $self attach $ragent 255; # attaches to default target of classifier $ragent set myaddr_ [$self set id_] $self set_ragent $ragent; # sets pointer at C++ level $ragent set_node $self; # sets back pointer in ragent to node}# When running all routing in C++, we want a dummy OTcl routing#Class Agent/rtProto/Dummy -superclass Agent/rtProtoAgent/rtProto/Dummy proc init-all args { # Nothing}# ======================================================================## methods for tracing## ======================================================================Simulator instproc trace-all-satlinks {f} { $self instvar Node_ foreach nn [array names Node_] { if {![$Node_($nn) info class Node/SatNode]} { continue; # Not a SatNode } $Node_($nn) trace-all-satlinks $f }}# All satlinks should have an interface indexed by nifs_Node/SatNode instproc trace-all-satlinks {f} { $self instvar nifs_ enqT_ rcvT_ linkhead_ for {set i 0} {$i < $nifs_} {incr i} { if {[$linkhead_($i) set type_] == "gsl-repeater"} { continue; } if {[info exists enqT_($i)]} { puts "Tracing already exists on node [$self id]" } else { $self trace-outlink-queue $f $i } if {[info exists rcvT_($i)]} { puts "Tracing already exists on node [$self id]" } else { $self trace-inlink-queue $f $i } }}# Set up trace objects around first output queue for packets destined to nodeNode/SatNode instproc trace-outlink-queue {f {index_ 0} } { $self instvar id_ enqT_ deqT_ drpT_ mac_ ll_ ifq_ drophead_ set ns [Simulator instance] set fromNode_ $id_ set toNode_ -1 set enqT_($index_) [$ns create-trace Sat/Enque $f $fromNode_ $toNode_] $enqT_($index_) target $ifq_($index_) $ll_($index_) down-target $enqT_($index_) set deqT_($index_) [$ns create-trace Sat/Deque $f $fromNode_ $toNode_] $deqT_($index_) target $mac_($index_) $ifq_($index_) target $deqT_($index_) set drpT_($index_) [$ns create-trace Sat/Drop $f $fromNode_ $toNode_] $drpT_($index_) target [$drophead_($index_) target] $drophead_($index_) target $drpT_($index_) $ifq_($index_) drop-target $drpT_($index_)}# Trace element between mac and ll tracing packets between node and nodeNode/SatNode instproc trace-inlink-queue {f {index_ 0} } { $self instvar id_ rcvT_ mac_ ll_ phy_rx_ em_ errT_ set ns [Simulator instance] set toNode_ $id_ set fromNode_ -1 if {[info exists em_($index_)]} { # if error model, then chain mac -> em -> rcvT -> ll # First, set up an error trace on the ErrorModule set errT_($index_) [$ns create-trace Sat/Error $f $fromNode_ $toNode_] $errT_($index_) target [$em_($index_) drop-target] $em_($index_) drop-target $errT_($index_) set rcvT_($index_) [$ns create-trace Sat/Recv $f $fromNode_ $toNode_] $rcvT_($index_) target [$em_($index_) target] $em_($index_) target $rcvT_($index_) } else { # if no error model, then insert between mac and ll set rcvT_($index_) [$ns create-trace Sat/Recv $f $fromNode_ $toNode_] $rcvT_($index_) target [$mac_($index_) up-target] $mac_($index_) up-target $rcvT_($index_) } }############ TRACE MODIFICATIONS########### This creates special satellite tracing elements# See __FILE__.cc# Support for Enque, Deque, Recv, Drop, Generic (not Session)Class Trace/Sat/Hop -superclass Trace/SatTrace/Sat/Hop instproc init {} { $self next "h"}Class Trace/Sat/Enque -superclass Trace/SatTrace/Sat/Enque instproc init {} { $self next "+"}Trace/Sat/Deque instproc init {} { $self next "-"}Class Trace/Sat/Recv -superclass Trace/SatTrace/Sat/Recv instproc init {} { $self next "r"}Class Trace/Sat/Drop -superclass Trace/SatTrace/Sat/Drop instproc init {} { $self next "d"}Class Trace/Sat/Error -superclass Trace/SatTrace/Sat/Error instproc init {} { $self next "e"}Class Trace/Sat/Generic -superclass Trace/SatTrace/Sat/Generic instproc init {} { $self next "v"}# ======================================================================## Defaults for bound variables ## ======================================================================Node/SatNode set dist_routing_ "false"; # distributed routing not yet supportedPosition/Sat set time_advance_ 0; # time offset to start of simulation Position/Sat/Polar set plane_ 0HandoffManager/Term set elevation_mask_ 0HandoffManager/Term set term_handoff_int_ 10HandoffManager/Sat set sat_handoff_int_ 10HandoffManager/Sat set latitude_threshold_ 70HandoffManager/Sat set longitude_threshold_ 0HandoffManager set handoff_randomization_ "false" SatRouteObject set metric_delay_ "true"SatRouteObject set data_driven_computation_ "false"Mac/Sat/UnslottedAloha set mean_backoff_ 1s; # mean backoff time upon collisionMac/Sat/UnslottedAloha set rtx_limit_ 3; # Retransmission limit Mac/Sat/UnslottedAloha set send_timeout_ 270ms; # Timer interval for new sendsAgent/SatRoute set myaddr_ 0 ;# My addressMac/Sat set bandwidth_ 2Mb
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -