📄 hfa-lib.tcl
字号:
########################################################## ## HFA-1 Library for routing modules## Author: Chieh-Yih Wan (wan@comet.columbia.edu)# 5/15/2000Class Node/GFA-Node -superclass NodeNode/GFA-Node instproc init args { $self next $args}Node/GFA-Node instproc mk-default-classifier {} { $self instvar np_ id_ classifiers_ agents_ dmux_ neighbor_ address_ set levels [AddrParams set hlevel_] for {set n 1} {$n <= $levels} {incr n} { set classifiers_($n) [new Classifier/Addr 32] $classifiers_($n) set mask_ [AddrParams set NodeMask_($n)] $classifiers_($n) set shift_ [AddrParams set NodeShift_($n)] }}Node/GFA-Node instproc entry {} { #XXX although mcast is not supported with wireless networking currently $self instvar ns_ if ![info exist ns_] { set ns_ [Simulator instance] } if [$ns_ multicast?] { $self instvar switch_ return $switch_ } $self instvar classifiers_ return $classifiers_(1)}Node/GFA-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]}## method to remove an entry from the hier classifiersNode/GFA-Node instproc clear-hroute args { $self instvar classifiers_ set a [split $args] set l [llength $a] $classifiers_($l) clear [lindex $a [expr $l-1]] }Node/GFA-Node instproc node-addr {} { $self instvar address_ return $address_}Node/GFA-Node instproc split-addrstr addrstr { set L [split $addrstr .] return $L}Node/GFA-Node instproc add-target {agent port } { #global RouterTrace AgentTrace $self instvar dmux_ classifiers_ $agent set sport_ $port set level [AddrParams set hlevel_] # Wan: # tracefd that used in cmu-trace is set in mobility-trace # in ns-lib. For now, ignore cmu-trace but set it manually global tracefd ns_ set ns_ [Simulator instance] if { $port == 255 } { if { [Simulator set RouterTrace_] == "ON" } { # # Send Target # set sndT [cmu-trace Send "RTR" $self] $sndT target [$self set ll_(0)] $agent target $sndT # # Recv Target # set rcvT [cmu-trace Recv "RTR" $self] $rcvT target $agent for {set i 1} {$i <= $level} {incr i} { $classifiers_($i) defaulttarget $rcvT $classifiers_($i) bcast-receiver $rcvT } $dmux_ install $port $rcvT } else { $agent target [$self set ll_(0)] for {set i 1} {$i <= $level} {incr i} { $classifiers_($i) bcast-receiver $agent $classifiers_($i) defaulttarget $agent } $dmux_ install $port $agent } } else { if { [Simulator set AgentTrace_] == "ON" } { # # Send Target # set sndT [cmu-trace Send AGT $self] $sndT target [$self entry] $agent target $sndT # # Recv Target # set rcvT [cmu-trace Recv AGT $self] $rcvT target $agent $dmux_ install $port $rcvT } else { $agent target [$self entry] $dmux_ install $port $agent } }}Class MobileNode/GFA -superclass Node/GFA-NodeMobileNode/GFA instproc init {args} { $self instvar address_ set address_ $args $self next $args $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 }MobileNode/GFA 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}MobileNode/GFA instproc attach-decap {} { $self instvar decap_ dmux_ agents_ set decap_ [new Classifier/Addr/MIPDecapsulator] $decap_ set mynode_ $self 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_}############################### Base Station ###############################Agent/MIPBS instproc node-class {} { $self instvar node_ return [$node_ info class]}Agent/MIPBS instproc myNodeID { } { $self instvar node_ return [$node_ id]}# Value: 1 -> MH is attach to this BS# Value: 2 -> MH is attach to other BSClassifier instproc BS_update_routing_table { m_addr } { $self instvar mynode_ rt_table_ set ns_ [Simulator instance] puts "BS_update_routing_table called at [$ns_ now]" set rt_table_($m_addr) 1}Classifier instproc BS_Handoff_Update { m_addr } { $self instvar mynode_ rt_table_ set ns_ [Simulator instance] puts "BS_Handoff_Update called at [$ns_ now]" set rt_table_($m_addr) 2}Classifier instproc Lookup_RT { m_addr } { $self instvar mynode_ rt_table_ if {[info exists rt_table_($m_addr)]} { return $rt_table_($m_addr) } return -1 }Classifier instproc myNodeID {} { $self instvar mynode_ return [$mynode_ id]}# set the node that this agent is attached to.Agent/MIPBS instproc set_node { node } { $self instvar mynode_ set mynode_ $node}Agent/MIPBS instproc create-route { m_addr } { $self instvar mynode_ set ns_ [Simulator instance] [$mynode_ set decap_] BS_update_routing_table $m_addr }Agent/MIPBS instproc clear-route { m_addr old_BS} { $self instvar mynode_ set ns_ [Simulator instance] set old_BS [$ns_ get-node-by-addr [addrToString $old_BS]] [$old_BS set decap_] BS_Handoff_Update $m_addr}Agent/MIPBS instproc validate_COA { m_addr new_FA} { $self instvar mynode_ set ns_ [Simulator instance] set new_FA [$ns_ get-node-by-addr [addrToString $new_FA]] puts "COA for $new_FA:[$new_FA id] is [[$new_FA set decap_] Lookup_RT $m_addr]" return [[$new_FA set decap_] Lookup_RT $m_addr]}Agent/MIPMH instproc myNode {} { $self instvar node_ return $node_}Agent/MIPMH instproc create-route { m_addr old_BS } { set ns_ [Simulator instance] if { $old_BS == -1 } { puts "Power up!" return } set old_BS [$ns_ get-node-by-addr [addrToString $old_BS]] [$old_BS set decap_] BS_update_routing_table $m_addr }Agent/MIPMH instproc clear-route { m_addr old_BS} { $self instvar mynode_ set ns_ [Simulator instance] if { $old_BS == -1 } { puts "Power up!" return } set old_BS [$ns_ get-node-by-addr [addrToString $old_BS]] [$old_BS set decap_] BS_Handoff_Update $m_addr}proc createAddrTable { node } { global addrTable_ set addr [$node address?] set addrTable_($addr) [$node set address_] }proc addrToString { addr } { global addrTable_ if {[info exists addrTable_($addr)]} { return $addrTable_($addr) } return -1}#logged mobile movementproc log-movement {} { global logtimer set ns_ [Simulator instance] source ../mobility/timer.tcl Class LogTimer -superclass Timer LogTimer instproc timeout {} { global MH_ $MH_(1) log-movement $self sched 0.05 } set logtimer [new LogTimer] $logtimer sched 0.05}proc makeHfaBS { baseStation } { $baseStation color "blue" createAddrTable $baseStation [$baseStation set regagent_] set_node $baseStation [$baseStation set classifiers_(1)] set foreignBS_ 1 [$baseStation set classifiers_(1)] set mynode_ $baseStation [$baseStation set decap_] set mynode_ $baseStation}proc makeHfaMH { Mobile GFA } { [$Mobile set regagent_] set home_agent_ $GFA [$Mobile set regagent_] set reg_lifetime_ 3}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -