📄 cipinit.tcl
字号:
$self SetRMC $m_addr [[$ns_ set link_([$mynode_ set id_]:$pnode_id)] head] $ss $ciptype } #return hop for root node to forward packet return [$self getRootHop] } } else { if { $mynode_ == $gw } { #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) } { $self SetRMC $m_addr [[$ns_ set link_([$mynode_ set id_]:$pnode_id)] head] $ss $ciptype } } } return -1; #return -1 so that gw doesn't not forward } Classifier/Addr/Cip instproc getRootHop { } { $self instvar mynode_ #cipRoot_ "$rootnode [[$ns set link_($id_:$rootnodeid)] head]" set rh [lindex [$mynode_ set cipRoot_] 1] if { $rh != "" } { return $rh } else { return -1 }}Classifier instproc PacketArrivedMobile { ciptype source destination } { $self instvar mynode_ global MH_IDLE CIP_PAGE CIP_DATA CIP_ROUTE MAX_ROUTES MH_ACTIVE if {$destination == -1} { return } set ns [Simulator instance] #puts "PacketArrivedMobile ciptype : $ciptype src: $source dst: $destination* [$ns now]" if { $ciptype == $CIP_PAGE } { if { [$mynode_ set status_] == $MH_IDLE } { ; } } elseif { $ciptype == $CIP_DATA } { if {[$mynode_ set status_] == $MH_IDLE} { set when [expr [$ns now] + 0.00001] #puts "*** MH active ciptype : $ciptype src: $source dst: $destination [$ns now]**" $ns at $when "$mynode_ GoActive" } $mynode_ set showupcnt_ 0 } elseif {$ciptype == $CIP_ROUTE } { #puts "** MH sent CIP_ROUTE ciptype: $ciptype src: $source dst $destination showupcnt: [$mynode_ set showupcnt_] [$ns now]" $mynode_ set showupcnt_ [expr [$mynode_ set showupcnt_] + 1] if {[$mynode_ set showupcnt_] >= $MAX_ROUTES && [$mynode_ set status_] == $MH_ACTIVE} { # Schedule going idle after some time. set when [expr [$ns now] + 0.00001] #puts "** MH idle at $when ciptype: $ciptype src: $source dst $destination showupcnt: [$mynode_ set showupcnt_] [$ns now]**" $ns at $when "$mynode_ GoIdle" } }}Classifier/Addr/Cip instproc MakePMC {} { $self instvar cipPMC_ rootnodeid_}Classifier/Addr/Cip instproc MakeRMC {} { $self instvar cipRMC_ rootnodeid_}Classifier/Addr/Cip instproc GetPMC {m_addr} { $self instvar cipPMC_ cipSS_ global PMCtimeout set ns [Simulator instance] set tmptime 0 if {[info exist cipPMC_($m_addr)]} { foreach entry $cipPMC_($m_addr) { set mylink [lindex $entry 0] set mytime [lindex $entry 1] #it must check if the mapping is still valid set limit [expr [$ns now] - $PMCtimeout] if {$mytime > $limit} { lappend reply $mylink } set tmptime $mytime } if {[llength $reply] == 0} { return -2 } } if {[info exist reply]} { return $reply } else { return -2 }}Classifier/Addr/Cip instproc GetRMC {m_addr} { $self instvar cipRMC_ cipSS_ global RMCtimeout set ns [Simulator instance] set tmptime 0 if {[info exist cipRMC_($m_addr)]} { foreach entry $cipRMC_($m_addr) { set mylink [lindex $entry 0] set mytime [lindex $entry 1] #it must check if the mapping is still valid set limit [expr [$ns now] - $RMCtimeout] if {$mytime > $limit} { if { $cipSS_($m_addr) == 1 } { lappend reply $mylink } else { if {$mytime > $tmptime} { set reply $mylink set tmptime mytime } } } else { #return -1 } set tmptime $mytime } } if {[info exist reply]} { return $reply } else { return -1 }}Classifier/Addr/Cip instproc SetPMC {m_addr link} { $self instvar cipPMC_ mynode_ global PMCtimeout CIP ROUTE CIP_PAGE set ns [Simulator instance] set now [$ns now] if {[info exist cipPMC_($m_addr)]} { for {set i 0} {$i < [llength $cipPMC_($m_addr)]} {incr i} { set entry [lindex $cipPMC_($m_addr) $i] set mylink [lindex $entry 0] set mytime [lindex $entry 1] if { $mylink == $link } { # update timer only set cipPMC_($m_addr) [lreplace $cipPMC_($m_addr) $i $i "$mylink $now"] return } } if {$i == [llength $cipPMC_($m_addr)]} { lappend cipPMC_($m_addr) "$link $now" } } else { set validity [expr $now + $PMCtimeout] lappend cipPMC_($m_addr) "$link $now" }}Classifier/Addr/Cip instproc SetRMC {m_addr link ss ctype} { $self instvar cipRMC_ cipSS_ mynode_ global RMCtimeout CIP_ROUTE set ns [Simulator instance] set now [$ns now] if { [info exist cipSS_($m_addr)] } { if { ($cipSS_($m_addr) == 1) & ($ctype == $CIP_ROUTE)} { set cipSS_($m_addr) $ss } else { set cipSS_($m_addr) $ss } } else { set cipSS_($m_addr) $ss } if {[info exist cipRMC_($m_addr)]} { if { $ss == 1 } { for {set i 0} {$i < [llength $cipRMC_($m_addr)]} {incr i} { set entry [lindex $cipRMC_($m_addr) $i] set mylink [lindex $entry 0] set mytime [lindex $entry 1] if { $mylink == $link } { # update timer only set cipRMC_($m_addr) [lreplace $cipRMC_($m_addr) $i $i "$mylink $now"] return } } if {$i == [llength $cipRMC_($m_addr)]} { lappend cipRMC_($m_addr) "$link $now" } #puts "$self: cipRMC in SetRMC $cipRMC_($m_addr)" } else { set validity [expr $now + $RMCtimeout] set cipRMC_($m_addr) [list "$link $now"] } } else { set validity [expr $now + $RMCtimeout] lappend cipRMC_($m_addr) "$link $now" }}Node/MobileNode instproc makemip-NewMIPMH {} { $self instvar regagent_ dmux_ address_ 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/CIPMH $self] $self attach $regagent_ [Node/MobileNode set REGAGENT_PORT] $regagent_ node $self}Node/MobileNode instproc MakeMobile {} { $self instvar classifiers_ $classifiers_(1) set mynode_ $self $classifiers_(1) set mFlag_ 1 $classifiers_(1) set bsFlag_ 0 $classifiers_(1) instvar cipnodeid_ $classifiers_(1) set cipnodeid_ -3 $self set-mobile $self $self set showupcnt_ 0}Agent/MIPMH instproc printTime { } { set ns [Simulator instance] puts "time: [$ns now]"}Agent/CIPBS set adSize_ 48 Agent/CIPBS set shift_ 0Agent/CIPBS set mask_ [AddrParams set ALL_BITS_SET]Agent/CIPBS set ad_lifetime_ 2Agent/CIPBS instproc init { node args } { eval $self next $args # if mobilenode, donot use bcasttarget; use target_ instead; if {[$node info class] != "MobileNode/MIPBS" && [$node info class] != "Node/MobileNode"} { $self instvar BcastTarget_ set BcastTarget_ [new Classifier/Replicator] $self bcast-target $BcastTarget_ } $self beacon-period 1.0 ;# default value}Node instproc mk-default-classifierHier {} { $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_ 1 } else { set classifiers_($n) [new Classifier/Addr] } $classifiers_($n) set mask_ [AddrParams set NodeMask_($n)] $classifiers_($n) set shift_ [AddrParams set NodeShift_($n)] }}Node/MobileNode instproc makemip-NewMIPBS {} { $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/CIPBS $self] #set regagent_ [new Agent/MIPBS $self] $self attach $regagent_ [Node/MobileNode set REGAGENT_PORT]}# Given overlaping area, calculate the desired coverageproc CellCoverage { x1 y1 x2 y2 overlap} { set d2 [expr ($x2-$x1)*($x2-$x1) + ($y2-$y1)*($y2-$y1)] set d [expr sqrt($d2)] return [expr ($overlap + $d) / 2]}# Calculate Transmission Power Pt given coverageproc SetPt { coverage } { set Gt [Antenna/OmniAntenna set Gt_] set Gr [Antenna/OmniAntenna set Gr_] set ht [Antenna/OmniAntenna set Z_] set hr [Antenna/OmniAntenna set Z_] set RXThresh [Phy/WirelessPhy set RXThresh_] set d4 [expr pow($coverage,4)] set Pt [expr ($RXThresh*$d4)/($Gt*$Gr*$ht*$ht*$hr*$hr)] return $Pt}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -