📄 cipinit.tcl
字号:
Node set Num_Handoff 0Node set oldBS 0set CIP_DATA 0set CIP_PAGING 1set CIP_PAGE 2set CIP_ROUTE 3set MH_OFF 0set MH_IDLE 1set MH_ACTIVE 2set MOBILE_ACTIVETIME 1; # Maximum time spent in active state by a mobile # without incoming or out going data [sec]set ROUTE_INTERVAL 0.5; # must be in secset PAGE_INTERVAL 3; # must be in secset MAX_ROUTES [expr $MOBILE_ACTIVETIME / $ROUTE_INTERVAL]set BROADCAST -2set PMCtimeout 10 set RMCtimeout 1.5 #In semisoft handoff, MH waits this amount of time #after detecting a beacon from new BSset SS_DELAY 0.05 set cipfid($CIP_DATA) 0set cipfid($CIP_PAGING) 1set cipfid($CIP_PAGE) 2set cipfid($CIP_ROUTE) 3Agent/Watchdog set interval_ 0.1 Agent/Watchdog set random_ 0Agent/Watchdog set packetSize_ 50 Agent/Watchdog set maxpkts_ 0x10000000 Agent/Watchdog instproc done {} { }Agent set ciptype_ 0Agent set ciptype_ 0Agent set cipnodeid_ 0Agent set cipsemisoft_ 0Classifier set top_ 0Classifier set bsFlag_ 0Classifier set mFlag_ 0Classifier set cipFlag_ 0Classifier set cipnodeid_ 0Classifier set rootnodeid_ 0Classifier set activeMH_ 1set gw "" ;# No GW node yet# Turn node into a Cellular IP node and initialize variables.Node instproc cipEnabledNode {} { $self instvar cipFlag_ mainClassifier_ cipLeaves_ cipRoot_ $self instvar id_ nPorts_ allLMP_ allRMP_ cell_ aiPort_ # To distinguish cip enabled nodes from regular ns nodes: [$self set classifiers_(1)] set cipFlag_ 1 $self set cipRoot_ ""}# Called for a cip node to configure its port towards $rootnode as "root-port"Node instproc cipConnectToRoot rootnode { $self instvar id_ cipRoot_ global gw if {$self == $gw} { #puts "CIP ERROR: GW node may not have a root-port." } if {$cipRoot_ == ""} { set rootnodeid [$rootnode id] # rootnodeid_ is used to see if received packet is from root [$self set classifiers_(1)] set rootnodeid_ $rootnodeid set id_ [$self id] set ns_ [Simulator instance] set cipRoot_ "$rootnode [[$ns_ set link_($id_:$rootnodeid)] head]" # Also notify, in the same step, rootnode that it has a new leaf $rootnode cipLeafAttached $self } else { #puts "CIP ERROR: node $self is configured for root-port twice" }}Node instproc cipLeafAttached leafnode { $self instvar cipLeaves_ id_ set leafnodeid [$leafnode id] set ns [Simulator instance] set nh [[$ns set link_($id_:$leafnodeid)] head] lappend cipLeaves_ "$leafnode $nh"}Node instproc MakeGW internetnode { $self instvar id_ cipRoot_ myPager_ cipGWport_ global gw CIP_PAGING if {$gw != ""} { puts "CIP ERROR: Only one GW can be defined." return } if {$cipRoot_ != ""} { puts "CIP ERROR: GW node may not have a root-port configured" return } if {$cipRoot_ == ""} { set rootnodeid [$internetnode id] set id_ [$self id] set ns_ [Simulator instance] set cipRoot_ "$internetnode [[$ns_ set link_($id_:$rootnodeid)] head]" # set internet node default target #[$internetnode set classifiers_(1)] defaulttarget [[$ns_ set link_($rootnodeid:$id_)] head] } else { puts "CIP ERROR: node $self is configured for root-port twice" } set gw $self}Node instproc MakeBS {} { $self instvar classifiers_ [$self set classifiers_(1)] set top_ 1 [$self set classifiers_(1)] set mynode_ $self [$self set classifiers_(1)] set cipnodeid_ [$self id] [$self set classifiers_(1)] set bsFlag_ 1 $self set-base $self [AddrParams set-hieraddr [$self node-addr]]}Node instproc MakePMC {} { $self instvar classifiers_ [$self set classifiers_(1)] MakePMC }Node instproc MakeRMC {} { $self instvar classifiers_ [$self set classifiers_(1)] MakeRMC}Node instproc create-watchdog gw { $self instvar watchdog_ set ns [Simulator instance] set watchdog_ [new Agent/Watchdog] ;# This will send page-update and route-update packets $watchdog_ set mynode_ $self $ns attach-agent $self $watchdog_ $watchdog_ set agent_addr_ $watchdog_ set dst_addr_ set null0 [new Agent/Null] $ns attach-agent $gw $null0 $ns connect $watchdog_ $null0 $self GoIdle}# To set the status of a mobile host: IDLENode instproc GoIdle {} { $self instvar status_ watchdog_ global MH_IDLE CIP_PAGE PAGE_INTERVAL set status_ $MH_IDLE $watchdog_ cipPacketType $CIP_PAGE $watchdog_ set interval_ $PAGE_INTERVAL $watchdog_ start}# To set the status of a mobile host: ACTIVE Node instproc GoActive {} { $self instvar status_ watchdog_ global MH_ACTIVE CIP_ROUTE ROUTE_INTERVAL set status_ $MH_ACTIVE $watchdog_ cipPacketType $CIP_ROUTE $watchdog_ set interval_ $ROUTE_INTERVAL set ns [Simulator instance] $watchdog_ start} # This procedure is called when handoff is called based on SNR Node instproc Handoff_called {new_bs_node} { $self instvar cur_bs_node Num_Handoff global MH_IDLE if {$Num_Handoff == 0 } { puts "MH detects beacon signal for the first time" } else { puts "** Handoff initiated ** Number of Handoff: $Num_Handoff" } set Num_Handoff [expr $Num_Handoff +1] set ns [Simulator instance] set when [expr [$ns now] + 0.00001] #puts "when: $when" if {[$self set status_] == $MH_IDLE } { $ns at $when "$self GoIdle" } else { $ns at $when "$self GoActive" }}Node instproc chg2ss { } { [$self set classifiers_(1)] chg2ss 0}Node instproc Semi_Handoff_called {new_bs_node} { $self instvar cur_bs_node Num_Handoff global SS_DELAY if {$Num_Handoff == 0 } { puts "MH detects beacon signal for the first time" } else { puts "** Semisoft Handoff initiated ** Number of Handoff: $Num_Handoff" } set Num_Handoff [expr $Num_Handoff +1] set ns [Simulator instance] set when [expr [$ns now] + 0.00001] set semi [expr [$ns now] + $SS_DELAY] $ns at $when "[$self set watchdog_] cipSemisoft 1" $ns at $when "$self GoActive" $ns at $semi "$self set oldBS" $ns at $semi "$self set cur_bs_node $new_bs_node"}Agent instproc cipPacketType tp { $self instvar ciptype_ fid_ global cipfid set ciptype_ $tp set fid_ $cipfid($tp) }Agent instproc cipSemisoft ss { $self instvar cipsemisoft_ set cipsemisoft_ $ss}HierNode 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} { if { $n == 1 } { set classifiers_($n) [new Classifier/Addr/Cip] $classifiers_(1) set top_ 1 $classifiers_(1) set mynode_ $self $classifiers_(1) set cipnodeid_ $id_ $classifiers_(1) set bsFlag_ 0 } else { set classifiers_($n) [new Classifier/Addr] } $classifiers_($n) set mask_ [AddrParams set NodeMask_($n)] $classifiers_($n) set shift_ [AddrParams set NodeShift_($n)] }} Classifier/Addr/Cip instproc Getlink { pnode_id } { $self instvar mynode_ set ns_ [Simulator instance] #puts " [[$ns_ set link_([$mynode_ set id_]:$pnode_id) ] head]" return [[$ns_ set link_([$mynode_ set id_]:$pnode_id) ] head]}Classifier/Addr/Cip instproc Lookup_CIP_RT { m_addr } { $self instvar mynode_ rt_table_ bsFlag_ global BROADCAST if { $bsFlag_ == 1 } { return -1 } #puts "** Lookup_CIP_RT called in $self of node [$mynode_ id]" # look up the RMC first set nh [$self GetRMC $m_addr] if { $nh == -1 } { set nh [$self GetPMC $m_addr] #puts "** classifier return: PMC $nh for mobile: $m_addr" } #puts "** classifier return: $nh for mobile: $m_addr" return $nh #puts "** classifier return: PMC [$self GetPMC $m_addr] for mobile: $m_addr" #return [$self GetPMC $m_addr] #puts "** classifier return: RMC [$self GetRMC $m_addr] for mobile: $m_addr" #return [$self GetRMC $m_addr]}Classifier/Addr/Cip instproc update_routing_table { m_addr d_addr pnode_id ciptype ss} { $self instvar mynode_ rt_table_ bsFlag_ global gw CIP_DATA CIP_ROUTE set ns_ [Simulator instance] # puts "$self: m_addr:$m_addr d_addr:$d_addr pid:$pnode_id type:$ciptype ss:$ss at [$mynode_ set id_] [$ns_ now]" set my_addr [AddrParams set-hieraddr [$mynode_ node-addr]] if { ($d_addr == "-1") || ([$mynode_ set id_] == $pnode_id) } { return -1; } if { ($my_addr != $d_addr) } { if { $bsFlag_ != 1 } { #puts "** update rt table in $self of node [$mynode_ id] ciptype: $ciptype" #puts "** src: $m_addr dst: $d_addr btw [$mynode_ set id_]:$pnode_id" $self SetPMC $m_addr [[$ns_ set link_([$mynode_ set id_]:$pnode_id)] head] if { ($ciptype == $CIP_DATA) | ($ciptype == $CIP_ROUTE) } {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -