ns-mobilenode.tcl
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:23k
源码类别:

通讯编程

开发平台:

Visual C++

  1. # -*- Mode:tcl; tcl-indent-level:8; tab-width:8; indent-tabs-mode:t -*-
  2. #
  3. # Copyright (c) 1998-2000 Regents of the University of California.
  4. # All rights reserved.
  5. # Redistribution and use in source and binary forms, with or without
  6. # modification, are permitted provided that the following conditions
  7. # are met:
  8. # 1. Redistributions of source code must retain the above copyright
  9. #    notice, this list of conditions and the following disclaimer.
  10. # 2. Redistributions in binary form must reproduce the above copyright
  11. #    notice, this list of conditions and the following disclaimer in the
  12. #    documentation and/or other materials provided with the distribution.
  13. # 3. All advertising materials mentioning features or use of this software
  14. #    must display the following acknowledgement:
  15. #  This product includes software developed by the MASH Research
  16. #  Group at the University of California Berkeley.
  17. # 4. Neither the name of the University nor of the Research Group may be
  18. #    used to endorse or promote products derived from this software without
  19. #    specific prior written permission.
  20. # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  21. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23. # ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  24. # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25. # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  26. # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  27. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  28. # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  29. # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. # SUCH DAMAGE.
  31. #
  32. # $Header: /cvsroot/nsnam/ns-2/tcl/lib/ns-mobilenode.tcl,v 1.58 2008/03/19 04:35:35 tom_henderson Exp $
  33. #
  34. # Ported from CMU-Monarch project's mobility extensions -Padma, 10/98.
  35. #
  36. # IT IS NOT ENCOURAGED TO SUBCLASSS MOBILENODE CLASS DEFINED IN THIS FILE
  37. #======================================================================
  38. # The ARPTable class
  39. #======================================================================
  40. ARPTable instproc init args {
  41. eval $self next $args ;# parent class constructor
  42. }
  43. ARPTable set bandwidth_         0
  44. ARPTable set delay_             5us
  45. #======================================================================
  46. # The Node/MobileNodeNode class
  47. #======================================================================
  48. Node/MobileNode instproc init args {
  49. #   # I don't care about address classifier; it's not my business
  50. #   # All I do is to setup port classifier so we can do broadcast, 
  51. #   # and to set up interface stuff.
  52. #   $self attach-node $node
  53. #   $node port-notify $self
  54. eval $self next $args
  55. $self instvar nifs_ arptable_ X_ Y_ Z_ nodetype_
  56. set X_ 0.0
  57. set Y_ 0.0
  58. set Z_ 0.0
  59.         set arptable_ ""                ;# no ARP table yet
  60. set nifs_ 0 ;# number of network interfaces
  61. # Mobile IP node processing
  62.         $self makemip-New$nodetype_
  63. }
  64. #----------------------------------------------------------------------
  65. # XXX Following are the last remnant of nodetype_. Need to be completely 
  66. # removed, however, we need a better mechanism to distinguish vanilla 
  67. # mobile node from MIP base station, and MIP mobile host.
  68. Node/MobileNode instproc makemip-NewMobile {} {
  69. }
  70. Node/MobileNode instproc makemip-NewBase {} {
  71. }
  72. Node/MobileNode instproc makemip-New {} {
  73. }
  74. Node/MobileNode instproc makemip-NewMIPBS {} {
  75. $self instvar regagent_ encap_ decap_ agents_ id_
  76. set dmux [new Classifier/Port/Reserve]
  77. $dmux set mask_ 0x7fffffff
  78. $dmux set shift_ 0
  79. $self install-demux $dmux
  80.    
  81. set regagent_ [new Agent/MIPBS $self]
  82. $self attach $regagent_ [Node/MobileNode set REGAGENT_PORT]
  83. $self attach-encap 
  84. $self attach-decap
  85. }
  86. Node/MobileNode instproc attach-encap {} {
  87. $self instvar encap_ 
  88. set encap_ [new MIPEncapsulator]
  89. $encap_ set mask_ [AddrParams NodeMask 1]
  90. $encap_ set shift_ [AddrParams NodeShift 1]
  91. #set mask 0x7fffffff
  92. #set shift 0
  93. set nodeaddr [AddrParams addr2id [$self node-addr]]
  94. $encap_ set addr_ [expr ( ~([AddrParams NodeMask 1] << 
  95. [AddrParams NodeShift 1]) & $nodeaddr )]
  96. $encap_ set port_ 1
  97. $encap_ target [$self entry]
  98. $encap_ set node_ $self
  99. }
  100. Node/MobileNode instproc attach-decap {} {
  101. $self instvar decap_ dmux_ agents_
  102. set decap_ [new Classifier/Addr/MIPDecapsulator]
  103. lappend agents_ $decap_
  104. $decap_ set mask_ [AddrParams NodeMask 1]
  105. $decap_ set shift_ [AddrParams NodeShift 1]
  106. $dmux_ install [Node/MobileNode set DECAP_PORT] $decap_
  107. }
  108. Node/MobileNode instproc makemip-NewMIPMH {} {
  109. $self instvar regagent_
  110.  
  111. set dmux [new Classifier/Port/Reserve]
  112. $dmux set mask_ 0x7fffffff
  113. $dmux set shift_ 0
  114. $self install-demux $dmux
  115. set regagent_ [new Agent/MIPMH $self]
  116. $self attach $regagent_ [Node/MobileNode set REGAGENT_PORT]
  117. $regagent_ set mask_ [AddrParams NodeMask 1]
  118. $regagent_ set shift_ [AddrParams NodeShift 1]
  119.   $regagent_ set dst_addr_ [expr (~0) << [AddrParams NodeShift 1]]
  120. $regagent_ set dst_port_ 0
  121. $regagent_ node $self
  122. }
  123. #----------------------------------------------------------------------
  124. Node/MobileNode instproc reset {} {
  125. $self instvar arptable_ nifs_ netif_ mac_ ifq_ ll_ imep_
  126.         for {set i 0} {$i < $nifs_} {incr i} {
  127. $netif_($i) reset
  128. $mac_($i) reset
  129. $ll_($i) reset
  130. $ifq_($i) reset
  131. if { [info exists opt(imep)] && $opt(imep) == "ON" } { 
  132. $imep_($i) reset 
  133. }
  134. }
  135. if { $arptable_ != "" } {
  136. $arptable_ reset 
  137. }
  138. }
  139. #
  140. # Attach an agent to a node.  Pick a port and
  141. # bind the agent to the port number.
  142. # if portnumber is 255, default target is set to the routing agent
  143. #
  144. Node/MobileNode instproc add-target { agent port } {
  145. $self instvar dmux_ imep_ toraDebug_ 
  146. set ns [Simulator instance]
  147. set newapi [$ns imep-support]
  148. $agent set sport_ $port
  149. # special processing for TORA/IMEP node
  150. set toraonly [string first "TORA" [$agent info class]] 
  151. if {$toraonly != -1 } {
  152. $agent if-queue [$self set ifq_(0)]  ;# ifq between LL and MAC
  153. #
  154. # XXX: The routing protocol and the IMEP agents needs handles
  155. # to each other.
  156. #
  157. $agent imep-agent [$self set imep_(0)]
  158. [$self set imep_(0)] rtagent $agent
  159. }
  160. # Special processing for AODV
  161. set aodvonly [string first "AODV" [$agent info class]] 
  162. if {$aodvonly != -1 } {
  163. $agent if-queue [$self set ifq_(0)]   ;# ifq between LL and MAC
  164. }
  165. #<zheng: add>
  166. # Special processing for ZBR
  167. #set zbronly [string first "ZBR" [$agent info class]] 
  168. #if {$zbronly != -1 } {
  169. # $agent if-queue [$self set ifq_(0)]   ;# ifq between LL and MAC
  170. #}
  171. #</zheng: add>
  172. if { $port == [Node set rtagent_port_] } {
  173. # Ad hoc routing agent setup needs special handling
  174. $self add-target-rtagent $agent $port
  175. return
  176. }
  177. # Attaching a normal agent
  178. set namfp [$ns get-nam-traceall]
  179. if { [Simulator set AgentTrace_] == "ON" } {
  180. #
  181. # Send Target
  182. #
  183. if {$newapi != ""} {
  184. set sndT [$self mobility-trace Send "AGT"]
  185. } else {
  186. set sndT [cmu-trace Send AGT $self]
  187. }
  188. if { $namfp != "" } {
  189. $sndT namattach $namfp
  190. }
  191. $sndT target [$self entry]
  192. $agent target $sndT
  193. #
  194. # Recv Target
  195. #
  196. if {$newapi != ""} {
  197. set rcvT [$self mobility-trace Recv "AGT"]
  198. } else {
  199. set rcvT [cmu-trace Recv AGT $self]
  200. }
  201. if { $namfp != "" } {
  202. $rcvT namattach $namfp
  203. }
  204. $rcvT target $agent
  205. $dmux_ install $port $rcvT
  206. } else {
  207. #
  208. # Send Target
  209. #
  210. $agent target [$self entry]
  211. #
  212. # Recv Target
  213. #
  214. $dmux_ install $port $agent
  215. }
  216. }
  217. Node/MobileNode instproc add-target-rtagent { agent port } {
  218. $self instvar imep_ toraDebug_ 
  219. set ns [Simulator instance]
  220. set newapi [$ns imep-support]
  221. set namfp [$ns get-nam-traceall]
  222. set dmux_ [$self demux]
  223. set classifier_ [$self entry]
  224. # let the routing agent know about the port dmux
  225. $agent port-dmux $dmux_
  226. if { [Simulator set RouterTrace_] == "ON" } {
  227. #
  228. # Send Target
  229. #
  230. if {$newapi != ""} {
  231. set sndT [$self mobility-trace Send "RTR"]
  232. } else {
  233. set sndT [cmu-trace Send "RTR" $self]
  234. }
  235. if { $namfp != "" } {
  236. $sndT namattach $namfp
  237. }
  238. if { $newapi == "ON" } {
  239. $agent target $imep_(0)
  240. $imep_(0) sendtarget $sndT
  241. # second tracer to see the actual
  242. # types of tora packets before imep packs them
  243. if { [info exists toraDebug_] && $toraDebug_ == "ON"} {
  244. set sndT2 [$self mobility-trace Send "TRP"]
  245. $sndT2 target $imep_(0)
  246. $agent target $sndT2
  247. }
  248. } else {  ;#  no IMEP
  249. $agent target $sndT
  250. }
  251. $sndT target [$self set ll_(0)]
  252. #
  253. # Recv Target
  254. #
  255. if {$newapi != ""} {
  256. set rcvT [$self mobility-trace Recv "RTR"]
  257. } else {
  258. set rcvT [cmu-trace Recv "RTR" $self]
  259. }
  260. if { $namfp != "" } {
  261. $rcvT namattach $namfp
  262. }
  263. if {$newapi == "ON" } {
  264. [$self set ll_(0)] up-target $imep_(0)
  265. $classifier_ defaulttarget $agent
  266. # need a second tracer to see the actual
  267. # types of tora packets after imep unpacks them
  268. # no need to support any hier node
  269. if {[info exists toraDebug_] && $toraDebug_ == "ON" } {
  270. set rcvT2 [$self mobility-trace Recv "TRP"]
  271. $rcvT2 target $agent
  272. $classifier_ defaulttarget $rcvT2
  273. }
  274. } else {
  275. $rcvT target $agent
  276. $classifier_ defaulttarget $rcvT
  277. $dmux_ install $port $rcvT
  278. }
  279. } else {
  280. #
  281. # Send Target
  282. #
  283. # if tora is used
  284. if { $newapi == "ON" } {
  285. $agent target $imep_(0)
  286. # second tracer to see the actual
  287. # types of tora packets before imep packs them
  288. if { [info exists toraDebug_] && $toraDebug_ == "ON"} {
  289. set sndT2 [$self mobility-trace Send "TRP"]
  290. $sndT2 target $imep_(0)
  291. $agent target $sndT2
  292. }
  293. $imep_(0) sendtarget [$self set ll_(0)]
  294. } else {  ;#  no IMEP
  295. $agent target [$self set ll_(0)]
  296. }    
  297. #
  298. # Recv Target
  299. #
  300. if {$newapi == "ON" } {
  301. [$self set ll_(0)] up-target $imep_(0)
  302. $classifier_ defaulttarget $agent
  303. # need a second tracer to see the actual
  304. # types of tora packets after imep unpacks them
  305. # no need to support any hier node
  306. if {[info exists toraDebug_] && $toraDebug_ == "ON" } {
  307. set rcvT2 [$self mobility-trace Recv "TRP"]
  308. $rcvT2 target $agent
  309. [$self set classifier_] defaulttarget $rcvT2
  310. }
  311. } else {
  312. $classifier_ defaulttarget $agent
  313. $dmux_ install $port $agent
  314. }
  315. }
  316. }
  317. #
  318. # The following setups up link layer, mac layer, network interface
  319. # and physical layer structures for the mobile node.
  320. #
  321. Node/MobileNode instproc add-interface { channel pmodel lltype mactype qtype qlen iftype anttype topo inerrproc outerrproc fecproc } {
  322. $self instvar arptable_ nifs_ netif_ mac_ ifq_ ll_ imep_ inerr_ outerr_ fec_
  323. set ns [Simulator instance]
  324. set imepflag [$ns imep-support]
  325. set t $nifs_
  326. incr nifs_
  327. set netif_($t) [new $iftype] ;# interface
  328. set mac_($t) [new $mactype] ;# mac layer
  329. set ifq_($t) [new $qtype] ;# interface queue
  330. set ll_($t) [new $lltype] ;# link layer
  331.         set ant_($t)    [new $anttype]
  332. $ns mac-type $mactype
  333. set inerr_($t) ""
  334. if {$inerrproc != ""} {
  335. set inerr_($t) [$inerrproc]
  336. }
  337. set outerr_($t) ""
  338. if {$outerrproc != ""} {
  339. set outerr_($t) [$outerrproc]
  340. }
  341. set fec_($t) ""
  342. if {$fecproc != ""} {
  343. set fec_($t) [$fecproc]
  344. }
  345. set namfp [$ns get-nam-traceall]
  346.         if {$imepflag == "ON" } {              
  347. # IMEP layer
  348. set imep_($t) [new Agent/IMEP [$self id]]
  349. set imep $imep_($t)
  350. set drpT [$self mobility-trace Drop "RTR"]
  351. if { $namfp != "" } {
  352. $drpT namattach $namfp
  353. }
  354. $imep drop-target $drpT
  355. $ns at 0.[$self id] "$imep_($t) start"   ;# start beacon timer
  356.         }
  357. #
  358. # Local Variables
  359. #
  360. set nullAgent_ [$ns set nullAgent_]
  361. set netif $netif_($t)
  362. set mac $mac_($t)
  363. set ifq $ifq_($t)
  364. set ll $ll_($t)
  365. set inerr $inerr_($t)
  366. set outerr $outerr_($t)
  367. set fec $fec_($t)
  368. #
  369. # Initialize ARP table only once.
  370. #
  371. if { $arptable_ == "" } {
  372. set arptable_ [new ARPTable $self $mac]
  373. # FOR backward compatibility sake, hack only
  374. if {$imepflag != ""} {
  375. set drpT [$self mobility-trace Drop "IFQ"]
  376. } else {
  377. set drpT [cmu-trace Drop "IFQ" $self]
  378. }
  379. $arptable_ drop-target $drpT
  380. if { $namfp != "" } {
  381. $drpT namattach $namfp
  382. }
  383.         }
  384. #
  385. # Link Layer
  386. #
  387. $ll arptable $arptable_
  388. $ll mac $mac
  389. $ll down-target $ifq
  390. if {$imepflag == "ON" } {
  391. $imep recvtarget [$self entry]
  392. $imep sendtarget $ll
  393. $ll up-target $imep
  394.         } else {
  395. $ll up-target [$self entry]
  396. }
  397. #
  398. # Interface Queue
  399. #
  400. $ifq target $mac
  401. $ifq set limit_ $qlen
  402. if {$imepflag != ""} {
  403. set drpT [$self mobility-trace Drop "IFQ"]
  404. } else {
  405. set drpT [cmu-trace Drop "IFQ" $self]
  406.         }
  407. $ifq drop-target $drpT
  408. if { $namfp != "" } {
  409. $drpT namattach $namfp
  410. }
  411. if {[$ifq info class] == "Queue/XCP"} {
  412. $mac set bandwidth_ [$ll set bandwidth_]
  413. $mac set delay_ [$ll set delay_]
  414. $ifq set-link-capacity [$mac set bandwidth_]
  415. $ifq queue-limit $qlen
  416. $ifq link $ll
  417. $ifq reset
  418. }
  419. #
  420. # Mac Layer
  421. #
  422. $mac netif $netif
  423. $mac up-target $ll
  424. if {$outerr == "" && $fec == ""} {
  425. $mac down-target $netif
  426. } elseif {$outerr != "" && $fec == ""} {
  427. $mac down-target $outerr
  428. $outerr target $netif
  429. } elseif {$outerr == "" && $fec != ""} {
  430. $mac down-target $fec
  431. $fec down-target $netif
  432. } else {
  433. $mac down-target $fec
  434. $fec down-target $outerr
  435. $err target $netif
  436. }
  437. set god_ [God instance]
  438.         if {$mactype == "Mac/802_11"} {
  439. $mac nodes [$god_ num_nodes]
  440. }
  441. #
  442. # Network Interface
  443. #
  444. #if {$fec == ""} {
  445.         # $netif up-target $mac
  446. #} else {
  447.         # $netif up-target $fec
  448. # $fec up-target $mac
  449. #}
  450. $netif channel $channel
  451. if {$inerr == "" && $fec == ""} {
  452. $netif up-target $mac
  453. } elseif {$inerr != "" && $fec == ""} {
  454. $netif up-target $inerr
  455. $inerr target $mac
  456. } elseif {$err == "" && $fec != ""} {
  457. $netif up-target $fec
  458. $fec up-target $mac
  459. } else {
  460. $netif up-target $inerr
  461. $inerr target $fec
  462. $fec up-target $mac
  463. }
  464. $netif propagation $pmodel ;# Propagation Model
  465. $netif node $self ;# Bind node <---> interface
  466. $netif antenna $ant_($t)
  467. #
  468. # Physical Channel
  469. #
  470. $channel addif $netif
  471.         # List-based improvement
  472. # For nodes talking to multiple channels this should
  473. # be called multiple times for each channel
  474. $channel add-node $self
  475. # let topo keep handle of channel
  476. $topo channel $channel
  477. # ============================================================
  478. if { [Simulator set PhyTrace_] == "ON" } {
  479. #
  480. # Trace Dropped Packets
  481. #
  482. if {$imepflag != ""} {
  483. set drpPhyT [$self mobility-trace Drop "PHY"]
  484. } else {
  485. set drpPhyT [cmu-trace Drop "PHY" $self]
  486. }
  487. $netif drop-target $drpPhyT
  488. if { $namfp != "" } {
  489. $drpPhyT namattach $namfp
  490. }
  491. #
  492. # Trace Sent Packets
  493. #
  494.         if {$imepflag != ""} {
  495.             set sndPhyT [$self mobility-trace Send "PHY"]
  496.         } else {
  497.             set sndPhyT [cmu-trace Send "PHY" $self]
  498.         }
  499.         $sndPhyT target $channel
  500.         $netif down-target $sndPhyT
  501.         if { $namfp != "" } {
  502.             $sndPhyT namattach $namfp
  503.         }
  504.         
  505. } else {
  506. $netif drop-target [$ns set nullAgent_]
  507. }
  508. if { [Simulator set MacTrace_] == "ON" } {
  509. #
  510. # Trace RTS/CTS/ACK Packets
  511. #
  512. if {$imepflag != ""} {
  513. set rcvT [$self mobility-trace Recv "MAC"]
  514. } else {
  515. set rcvT [cmu-trace Recv "MAC" $self]
  516. }
  517. $mac log-target $rcvT
  518. if { $namfp != "" } {
  519. $rcvT namattach $namfp
  520. }
  521. #
  522. # Trace Sent Packets
  523. #
  524. if {$imepflag != ""} {
  525. set sndT [$self mobility-trace Send "MAC"]
  526. } else {
  527. set sndT [cmu-trace Send "MAC" $self]
  528. }
  529. $sndT target [$mac down-target]
  530. $mac down-target $sndT
  531. if { $namfp != "" } {
  532. $sndT namattach $namfp
  533. }
  534. #
  535. # Trace Received Packets
  536. #
  537. if {$imepflag != ""} {
  538. set rcvT [$self mobility-trace Recv "MAC"]
  539. } else {
  540. set rcvT [cmu-trace Recv "MAC" $self]
  541. }
  542. $rcvT target [$mac up-target]
  543. $mac up-target $rcvT
  544. if { $namfp != "" } {
  545. $rcvT namattach $namfp
  546. }
  547. #
  548. # Trace Dropped Packets
  549. #
  550. if {$imepflag != ""} {
  551. set drpT [$self mobility-trace Drop "MAC"]
  552. } else {
  553. set drpT [cmu-trace Drop "MAC" $self]
  554. }
  555. $mac drop-target $drpT
  556. if { $namfp != "" } {
  557. $drpT namattach $namfp
  558. }
  559. } else {
  560. $mac log-target [$ns set nullAgent_]
  561. $mac drop-target [$ns set nullAgent_]
  562. }
  563. # change wrt Mike's code
  564.        if { [Simulator set EotTrace_] == "ON" } {
  565.                #
  566.                # Also trace end of transmission time for packets
  567.                #
  568.                if {$imepflag != ""} {
  569.                        set eotT [$self mobility-trace EOT "MAC"]
  570.                } else {
  571.                        set eoT [cmu-trace EOT "MAC" $self]
  572.                }
  573.                $mac eot-target $eotT
  574.        }
  575. # ============================================================
  576. $self addif $netif
  577. }
  578. # set transmission power
  579. Node/MobileNode instproc setPt { val } {
  580. $self instvar netif_
  581. $netif_(0) setTxPower $val
  582. }
  583. # set receiving power
  584. Node/MobileNode instproc setPr { val } {
  585. $self instvar netif_
  586. $netif_(0) setRxPower $val
  587. }
  588. # set idle power -- Chalermek
  589. Node/MobileNode instproc setPidle { val } {
  590. $self instvar netif_
  591. $netif_(0) setIdlePower $val
  592. }
  593. #
  594. Node/MobileNode instproc setPsleep { val } {
  595. $self instvar netif_
  596. $netif_(0) setSleepPower $val
  597. }
  598. #
  599. Node/MobileNode instproc setTSleep { val } {
  600. $self instvar netif_
  601. $netif_(0) setSleepTime $val
  602. }
  603. #
  604. Node/MobileNode instproc setPtransition { val } {
  605. $self instvar netif_
  606. $netif_(0) setTransitionPower $val
  607. }
  608. Node/MobileNode instproc setTtransition { val } {
  609. $self instvar netif_
  610. $netif_(0) setTransitionTime $val
  611. }
  612. #
  613. # change wrt Mike's code
  614.  Node/MobileNode instproc getMac {param0} {
  615.        $self instvar mac_
  616.        return $mac_($param0)
  617.  }
  618.  Node/MobileNode instproc CFP { beacon_period cfp_duration } {
  619.        if {$mactype == "Mac/802_11"} {
  620.                $self instvar mac_
  621.                set ns_ [Simulator instance]
  622.                set beacon_period [$ns_ delay_parse $beacon_period]
  623.                set cfp_duration [$ns_ delay_parse $cfp_duration]
  624.                $mac_(0) cfp $beacon_period $cfp_duration
  625.        }
  626.  }
  627. Node/MobileNode instproc mobility-trace { ttype atype } {
  628. set ns [Simulator instance]
  629.         set tracefd [$ns get-ns-traceall]
  630.         if { $tracefd == "" } {
  631.         puts "Warning: You have not defined you tracefile yet!"
  632.         puts "Please use trace-all command to define it."
  633. return ""
  634. }
  635. set T [new CMUTrace/$ttype $atype]
  636. $T newtrace [Simulator set WirelessNewTrace_]
  637. $T tagged [Simulator set TaggedTrace_]
  638. $T target [$ns nullagent]
  639. $T attach $tracefd
  640.         $T set src_ [$self id]
  641.         $T node $self
  642. return $T
  643. }
  644. Node/MobileNode instproc nodetrace { tracefd } {
  645. #
  646. # This Trace Target is used to log changes in direction
  647. # and velocity for the mobile node.
  648. #
  649. set T [new Trace/Generic]
  650. $T target [[Simulator instance] set nullAgent_]
  651. $T attach $tracefd
  652. $T set src_ [$self id]
  653. $self log-target $T    
  654. }
  655. Node/MobileNode instproc agenttrace {tracefd} {
  656. set ns [Simulator instance]
  657. set ragent [$self set ragent_]
  658. #
  659. # Drop Target (always on regardless of other tracing)
  660. #
  661. set drpT [$self mobility-trace Drop "RTR"]
  662. set namfp [$ns get-nam-traceall]
  663. if { $namfp != ""} {
  664. $drpT namattach $namfp
  665. }
  666. $ragent drop-target $drpT
  667. #
  668. # Log Target
  669. #
  670. set T [new Trace/Generic]
  671. $T target [$ns set nullAgent_]
  672. $T attach $tracefd
  673. $T set src_ [$self id]
  674. $ragent tracetarget $T
  675. #
  676. # XXX: let the IMEP agent use the same log target.
  677. #
  678. set imepflag [$ns imep-support]
  679. if {$imepflag == "ON"} {
  680. [$self set imep_(0)] log-target $T
  681. }
  682. }
  683. Node/MobileNode instproc mip-call {ragent} {
  684. $self instvar regagent_
  685. if [info exists regagent_] {
  686. $regagent_ ragent $ragent
  687. }
  688. }
  689. Node/MobileNode instproc attach-gafpartner {} {
  690.         $self instvar gafpartner_ address_ ll_ 
  691.         set gafpartner_ [new GAFPartner]
  692. $gafpartner_ set mask_ [AddrParams NodeMask 1]
  693. $gafpartner_ set shift_ [AddrParams NodeShift 1]
  694. set nodeaddr [AddrParams addr2id [$self node-addr]]
  695. #$gafpartner_ set addr_ [expr ( ~([AddrParams NodeMask 1] << 
  696. # [AddrParams NodeShift 1]) & $nodeaddr )]
  697. $gafpartner_ set addr_ $nodeaddr
  698. $gafpartner_ set port_ 254
  699. #puts [$gafpartner_ set addr_]
  700.         $gafpartner_ target [$self entry]
  701. $ll_(0) up-target $gafpartner_
  702. }
  703. Node/MobileNode instproc unset-gafpartner {} {
  704. $self instvar gafpartner_
  705. $gafpartner_ set-gafagent 0
  706. }
  707. # <zheng: add>
  708. Node/MobileNode instproc sscs args {
  709. $self instvar mac_
  710. eval $mac_(0) sscs $args
  711. }
  712. Node/MobileNode instproc NodeClr {arg1} {
  713. $self instvar mac_
  714. $mac_(0) NodeClr $arg1
  715. }
  716. Node/MobileNode instproc NodeLabel args {
  717. $self instvar mac_
  718. eval $mac_(0) NodeLabel $args
  719. }
  720. Node/MobileNode instproc node-down {} {
  721. $self instvar mac_
  722. $mac_(0) node-down
  723. }
  724. Node/MobileNode instproc node-up {} {
  725. $self instvar mac_
  726. $mac_(0) node-up
  727. }
  728. Node/MobileNode instproc RNType args {
  729. $self instvar ragent_
  730. eval $ragent_ RNType $args
  731. }
  732. # </zheng: add>
  733. Class SRNodeNew -superclass Node/MobileNode
  734. SRNodeNew instproc init args {
  735. $self instvar dsr_agent_ dmux_ entry_point_ address_
  736.         set ns [Simulator instance]
  737. eval $self next $args ;# parent class constructor
  738. if {$dmux_ == "" } {
  739. # Use the default mash and shift
  740. set dmux_ [new Classifier/Port]
  741. }
  742. set dsr_agent_ [new Agent/DSRAgent]
  743. # setup address (supports hier-address) for dsragent
  744. $dsr_agent_ addr $address_
  745. $dsr_agent_ node $self
  746. if [Simulator set mobile_ip_] {
  747. $dsr_agent_ port-dmux [$self set dmux_]
  748. }
  749. # set up IP address
  750. $self addr $address_
  751. if { [Simulator set RouterTrace_] == "ON" } {
  752. # Recv Target
  753. set rcvT [$self mobility-trace Recv "RTR"]
  754. set namfp [$ns get-nam-traceall]
  755. if {  $namfp != "" } {
  756. $rcvT namattach $namfp
  757. }
  758. $rcvT target $dsr_agent_
  759. set entry_point_ $rcvT
  760. } else {
  761. # Recv Target
  762. set entry_point_ $dsr_agent_
  763. }
  764. $self set ragent_ $dsr_agent_
  765. $dsr_agent_ target $dmux_
  766. # packets to the DSR port should be dropped, since we've
  767. # already handled them in the DSRAgent at the entry.
  768. set nullAgent_ [$ns set nullAgent_]
  769. $dmux_ install [Node set rtagent_port_] $nullAgent_
  770. # SRNodes don't use the IP addr classifier.  The DSRAgent should
  771. # be the entry point
  772. $self instvar classifier_
  773. set classifier_ "srnode made illegal use of classifier_"
  774. return $self
  775. }
  776. SRNodeNew instproc start-dsr {} {
  777. $self instvar dsr_agent_
  778. $dsr_agent_ startdsr
  779. }
  780. SRNodeNew instproc entry {} {
  781.         $self instvar entry_point_
  782.         return $entry_point_
  783. }
  784. SRNodeNew instproc add-interface args {
  785. eval $self next $args
  786. $self instvar dsr_agent_ ll_ mac_ ifq_
  787. set ns [Simulator instance]
  788. $dsr_agent_ mac-addr [$mac_(0) id]
  789. if { [Simulator set RouterTrace_] == "ON" } {
  790. # Send Target
  791. set sndT [$self mobility-trace Send "RTR"]
  792. set namfp [$ns get-nam-traceall]
  793. if {$namfp != "" } {
  794. $sndT namattach $namfp
  795. }
  796. $sndT target $ll_(0)
  797. $dsr_agent_ add-ll $sndT $ifq_(0)
  798. } else {
  799. # Send Target
  800. $dsr_agent_ add-ll $ll_(0) $ifq_(0)
  801. }
  802. # setup promiscuous tap into mac layer
  803. $dsr_agent_ install-tap $mac_(0)
  804. }
  805. SRNodeNew instproc reset args {
  806. $self instvar dsr_agent_
  807. eval $self next $args
  808. $dsr_agent_ reset
  809. }