📄 ns-node.tcl
字号:
if [info exists mpathClsfr_($id)] { foreach L $ifs { set nonLink([$L head]) 1 } foreach {slot link} [$mpathClsfr_($id) adjacents] { if [info exists nonLink($link)] { $mpathClsfr_($id) clear $slot incr routes_($id) -1 } } } else { $self add-route $id $nullagent incr routes_($id) -1 }}Node instproc intf-changed { } { $self instvar rtObject_ if [info exists rtObject_] { ;# i.e. detailed dynamic routing $rtObject_ intf-changed }}### PGM Router support #### Simulator instproc attach-PgmNE (args) {# foreach node $args {# $node attach-PgmNEAgent# }# Node instproc attach-PgmNEAgent {} {# $self instvar switch_ router_supp_ ns_# # if![$ns_ multicast?] {# # error "Error :Attaching PGM without Mcast option!"# # }# set router_supp_ [new Agent/NE/Pgm $switch_]# [Simulator instance] attach-agent $self $router-supp_# $switch_ install 1 $router-supp_# }## Manual Routing Nodes:# like normal nodes, but with a hash classifier.#Class ManualRtNode -superclass NodeManualRtNode instproc mk-default-classifier {} { $self instvar address_ classifier_ id_ dmux_ # Note the very small hash size--- # you're supposed to resize it if you want more. set classifier_ [new Classifier/Hash/Dest 2] $classifier_ set mask_ [AddrParams set NodeMask_(1)] $classifier_ set shift_ [AddrParams set NodeShift_(1)] set address_ $id_ # # When an agent is created, # $self add-route $address_ $dmux_ is called # which will do this. #}ManualRtNode instproc add-route {dst_address target} { $self instvar classifier_ set slot [$classifier_ installNext $target] if {$dst_address == "default"} { $classifier_ set default_ $slot } else { # don't encode the address here, set-hash bypasses that for us set encoded_dst_address [expr $dst_address << [AddrParams set NodeShift_(1)]] $classifier_ set-hash auto 0 $encoded_dst_address 0 $slot # $classifier_ set-hash auto 0 $dst_address 0 $slot }# puts "ManualRtNode::add-route: $dst $target, classifier=$classifier_ slot=$slot"# puts "\t*slot=[$classifier_ slot $slot]"}ManualRtNode instproc add-route-to-adj-node args { $self instvar classifier_ address_ set dst "" if {[lindex $args 0] == "-default"} { set dst default set args [lrange $args 1 end] } if {[llength $args] != 1} { error "ManualRtNode::add-route-to-adj-node [-default] node" } set target_node $args if {$dst == ""} { set dst [$target_node set address_] } set ns [Simulator instance] set link [$ns link $self $target_node] set target [$link head] # puts "ManualRtNode::add-route-to-adj-node: in $self for addr $dst to target $target" return [$self add-route $dst $target]}## Virtual Classifier Nodes:# like normal nodes, but with a virtual unicast classifier.#Class VirtualClassifierNode -superclass NodeVirtualClassifierNode instproc mk-default-classifier {} { $self instvar address_ classifier_ id_ set classifier_ [new Classifier/Virtual] $classifier_ set node_ $self $classifier_ set mask_ [AddrParams set NodeMask_(1)] $classifier_ set shift_ [AddrParams set NodeShift_(1)] set address_ $id_ $classifier_ nodeaddr $address_}VirtualClassifierNode instproc add-route { dst target } {}Classifier/Virtual instproc find dst { $self instvar node_ ns_ routingTable_ if ![info exist ns_] { set ns_ [Simulator instance] } if {[$node_ id] == $dst} { return [$node_ set dmux_] } else { return [[$ns_ link $node_ [$ns_ set Node_($dst)]] head] }}Classifier/Virtual instproc install {dst target} {}# # Broadcast Nodes:# accept limited broadcast packets# Class Node/Broadcast -superclass Node Node/Broadcast instproc mk-default-classifier {} { $self instvar address_ classifier_ id_ dmux_ set classifier_ [new Classifier/Hash/Dest/Bcast 32] $classifier_ set mask_ [AddrParams set NodeMask_(1)] $classifier_ set shift_ [AddrParams set NodeShift_(1)] set address_ $id_ if { $dmux_ == "" } { set dmux_ [new Classifier/Port/Reserve] $dmux_ set mask_ [AddrParams set ALL_BITS_SET] $dmux_ set shift_ 0 if [Simulator set EnableHierRt_] { $self add-hroute $address_ $dmux_ } else { $self add-route $address_ $dmux_ } } $classifier_ bcast-receiver $dmux_}# New node structureNode instproc add-target-NewMobile {agent port} { #global opt $self instvar dmux_ classifier_ $self instvar imep_ toraDebug_ 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 } if { $port == 255 } { # non-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 # $agent target [$self set ll_(0)] # # Recv Target # $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] } $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] } $rcvT target $agent $dmux_ install $port $rcvT } else { # # Send Target # $agent target [$self entry] # # Recv Target # $dmux_ install $port $agent } }}Node instproc add-interface { channel pmodel \ lltype mactype qtype qlen iftype anttype} { $self instvar arptable_ nifs_ $self instvar netif_ mac_ ifq_ ll_ $self instvar imep_ #global ns_ opt #set MacTrace [Simulator set MacTrace_] set ns_ [Simulator instance] set imepflag [$ns_ imep-support] set t $nifs_ incr nifs_ set netif_($t) [new $iftype] ;# interface set mac_($t) [new $mactype] ;# mac layer set ifq_($t) [new $qtype] ;# interface queue set ll_($t) [new $lltype] ;# link layer set ant_($t) [new $anttype] if {$imepflag == "ON" } { ;# IMEP layer set imep_($t) [new Agent/IMEP [$self id]] set imep $imep_($t) set drpT [$ns_ mobility-trace Drop "RTR" $self] $imep drop-target $drpT if [info exists namtraceFile_] { $drpT namattach $namtraceFile_ } $ns_ at 0.[$self id] "$imep_($t) start" ;# start beacon timer } # # Local Variables # set nullAgent_ [$ns_ set nullAgent_] set netif $netif_($t) set mac $mac_($t) set ifq $ifq_($t) set ll $ll_($t) # # Initialize ARP table only once. # if { $arptable_ == "" } { set arptable_ [new ARPTable $self $mac] # FOR backward compatibility sake, hack only if {$imepflag != ""} { set drpT [$ns_ mobility-trace Drop "IFQ" $self] } else { set drpT [cmu-trace Drop "IFQ" $self] } $arptable_ drop-target $drpT } # # Link Layer # $ll arptable $arptable_ $ll mac $mac# $ll up-target [$self entry] $ll down-target $ifq if {$imepflag == "ON" } { $imep recvtarget [$self entry] $imep sendtarget $ll $ll up-target $imep } else { $ll up-target [$self entry] } # # Interface Queue # $ifq target $mac $ifq set qlim_ $qlen if {$imepflag != ""} { set drpT [$ns_ mobility-trace Drop "IFQ" $self] } else { set drpT [cmu-trace Drop "IFQ" $self] } $ifq drop-target $drpT # # Mac Layer # $mac netif $netif $mac up-target $ll $mac down-target $netif #$mac nodes $opt(nn) set god_ [God instance] $mac nodes [$god_ num_nodes] # # Network Interface # $netif channel $channel $netif up-target $mac $netif propagation $pmodel ;# Propagation Model $netif node $self ;# Bind node <---> interface $netif antenna $ant_($t) # # Physical Channel` # $channel addif $netif # ============================================================ if { [Simulator set MacTrace_] == "ON" } { # # Trace RTS/CTS/ACK Packets # Trace end of transmission time for packets # if {$imepflag != ""} { set logT [$ns_ mobility-trace Recv "MAC" $self] set eotT [$ns_ mobility-trace EOT "MAC" $self] } else { set logT [cmu-trace Recv "MAC" $self] set eotT [cmu-trace EOT "MAC" $self] } $mac log-target $logT $mac eot-target $eotT if [info exists namtraceFile_] { $rcvT namattach $namtraceFile_ } # # Trace Sent Packets # if {$imepflag != ""} { set sndT [$ns_ mobility-trace Send "MAC" $self] } else { set sndT [cmu-trace Send "MAC" $self] } $sndT target [$mac down-target] $mac down-target $sndT if [info exists namtraceFile_] { $sndT namattach $namtraceFile_ } # # Trace Received Packets # if {$imepflag != ""} { set rcvT [$ns_ mobility-trace Recv "MAC" $self] } else { set rcvT [cmu-trace Recv "MAC" $self] } $rcvT target [$mac up-target] $mac up-target $rcvT if [info exists namtraceFile_] { $rcvT namattach $namtraceFile_ } # # Trace Dropped Packets # if {$imepflag != ""} { set drpT [$ns_ mobility-trace Drop "MAC" $self] } else { set drpT [cmu-trace Drop "MAC" $self]` } $mac drop-target $drpT if [info exists namtraceFile_] { $drpT namattach $namtraceFile_ } } else { $mac log-target [$ns_ set nullAgent_] $mac drop-target [$ns_ set nullAgent_] } # ============================================================ $self addif $netif}Node instproc agenttrace {tracefd} { set ns_ [Simulator instance] set ragent [$self set ragent_] # # Drop Target (always on regardless of other tracing) # set drpT [$ns_ mobility-trace Drop "RTR" $self] $ragent drop-target $drpT # # Log Target # set T [new Trace/Generic] $T target [$ns_ set nullAgent_] $T attach $tracefd $T set src_ [$self id] #$ragent log-target $T $ragent tracetarget $T # # XXX: let the IMEP agent use the same log target. # set imepflag [$ns_ imep-support] if {$imepflag == "ON"} { [$self set imep_(0)] log-target $T } if [info exists namtraceFile_] { $drpT namattach $namtraceFile_ }}Node instproc nodetrace { tracefd } { set ns_ [Simulator instance] # # This Trace Target is used to log changes in direction # and velocity for the mobile node. # set T [new Trace/Generic] $T target [$ns_ set nullAgent_] $T attach $tracefd $T set src_ [$self id] $self log-target $T }Node instproc install-defaulttarget {rcvT} { #set nodetype [[Simulator instance] get-nodetype] $self instvar nodetype_ $self install-defaulttarget-New$nodetype_ $rcvT}Node instproc install-defaulttarget-New {rcvT} { [$self set classifier_] defaulttarget $rcvT}Node instproc install-defaulttarget-NewMobile {rcvT} { [$self set classifier_] defaulttarget $rcvT}Node instproc install-defaulttarget-NewBase {rcvT} { $self instvar classifiers_ set level [AddrParams set hlevel_] for {set i 1} {$i <= $level} {incr i} { $classifiers_($i) defaulttarget $rcvT# $classifiers_($i) bcast-receiver $rcvT }}Node instproc install-defaulttarget-NewMIPMH {rcvT} { $self install-defaulttarget-NewBase $rcvT}Node instproc install-defaulttarget-NewMIPBS {rcvT} { $self install-defaulttarget-NewBase $rcvT}# set transmission powerNode instproc setPt { val } { $self instvar netif_ $netif_(0) setTxPower $val}# set receiving powerNode instproc setPr { val } { $self instvar netif_ $netif_(0) setRxPower $val}# set idle power -- ChalermekNode instproc setPidle { val } { $self instvar netif_ $netif_(0) setIdlePower $val}Node instproc add-hroute { dst target } { $self instvar classifiers_ rtsize_ set al [$self split-addrstr $dst] set l [llength $al] for {set i 1} {$i <= $l} {incr i} { set d [lindex $al [expr $i-1]] if {$i == $l} { $classifiers_($i) install $d $target } else { $classifiers_($i) install $d $classifiers_([expr $i + 1]) } } # # increase the routing table size counter - keeps track of rtg table size for # each node set rtsize_ [expr $rtsize_ + 1]}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -