Advertisement
ImperfectionistCoder

Untitled

Dec 31st, 2021
1,875
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 7.12 KB | None | 0 0
  1. #Copyright (c) 1997 Regents of the University of California.
  2. # All rights reserved.
  3. #
  4. # Redistribution and use in source and binary forms, with or without
  5. # modification, are permitted provided that the following conditions
  6. # are met:
  7. # 1. Redistributions of source code must retain the above copyright
  8. #    notice, this list of conditions and the following disclaimer.
  9. # 2. Redistributions in binary form must reproduce the above copyright
  10. #    notice, this list of conditions and the following disclaimer in the
  11. #    documentation and/or other materials provided with the distribution.
  12. # 3. All advertising materials mentioning features or use of this software
  13. #    must display the following acknowledgement:
  14. #      This product includes software developed by the Computer Systems
  15. #      Engineering Group at Lawrence Berkeley Laboratory.
  16. # 4. Neither the name of the University nor of the Laboratory may be used
  17. #    to endorse or promote products derived from this software without
  18. #    specific prior written permission.
  19. #
  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/ex/wireless-mitf.tcl,v 1.2 2000/08/30 00:10:45 haoboy Exp $
  33. #
  34. # Simple demo script for the new APIs to support multi-interface for
  35. # wireless node.
  36. #
  37. # Define options
  38. # Please note:
  39. # 1. you can still specify "channelType" in node-config right now:
  40. # set val(chan)           Channel/WirelessChannel
  41. # $ns_ node-config ...
  42. #        -channelType $val(chan)
  43. #                  ...
  44. # But we recommend you to use node-config in the way shown in this script
  45. # for your future simulations.  
  46. #
  47. # 2. Because the ad-hoc routing agents do not support multiple interfaces
  48. #    currently, this script can't generate anything interesting if you config
  49. #    the interfaces of node 1 and 2 on different channels
  50. #  
  51. #     --Xuan Chen, USC/ISI, July 21, 2000
  52. #
  53. set val(chan)           Channel/WirelessChannel    ;#Channel Type
  54. set val(prop)           Propagation/TwoRayGround   ;# radio-propagation model
  55. set val(netif)          Phy/WirelessPhy            ;# network interface type
  56. set val(mac)            Mac/802_11                 ;# MAC type
  57. set val(ifq)            Queue/DropTail/PriQueue    ;# interface queue type
  58. set val(ll)             LL                         ;# link layer type
  59. set val(ant)            Antenna/OmniAntenna        ;# antenna model
  60. set val(ifqlen)         50                         ;# max packet in ifq
  61. set val(nn)             7                         ;# number of mobilenodes
  62. set val(rp)             DSDV                       ;# routing protocol
  63. #set val(rp)             DSR                       ;# routing protocol
  64. set val(x)      1000
  65. set val(y)      1000
  66.  
  67. # Initialize Global Variables
  68. set ns_     [new Simulator]
  69. set tracefd     [open sanet2021.tr w]
  70. $ns_ trace-all $tracefd
  71.  
  72. set namtrace [open sanet2021.nam w]
  73. $ns_ namtrace-all-wireless $namtrace $val(x) $val(y)
  74.  
  75. # set up topography object
  76. set topo       [new Topography]
  77.  
  78. $topo load_flatgrid $val(x) $val(y)
  79.  
  80. # Create God
  81. create-god $val(nn)
  82.  
  83. # New API to config node:
  84. # 1. Create channel (or multiple-channels);
  85. # 2. Specify channel in node-config (instead of channelType);
  86. # 3. Create nodes for simulations.
  87.  
  88. # Create channel #1 and #2
  89. set chan_1_ [new $val(chan)]
  90. set chan_2_ [new $val(chan)]
  91.  
  92. # Create node(0) "attached" to channel #1
  93.  
  94. # configure node, please note the change below.
  95. $ns_ node-config -adhocRouting $val(rp) \
  96.         -llType $val(ll) \
  97.         -macType $val(mac) \
  98.         -ifqType $val(ifq) \
  99.         -ifqLen $val(ifqlen) \
  100.         -antType $val(ant) \
  101.         -propType $val(prop) \
  102.         -phyType $val(netif) \
  103.         -topoInstance $topo \
  104.         -agentTrace ON \
  105.         -routerTrace ON \
  106.         -macTrace ON \
  107.         -movementTrace OFF \
  108.         -channel $chan_1_
  109.  
  110.  
  111.  
  112. # node_(1) can also be created with the same configuration, or with a different
  113. # channel specified.
  114. # Uncomment below two lines will create node_(1) with a different channel.
  115. #  $ns_ node-config \
  116. #        -channel $chan_2_
  117.  
  118.  
  119. for {set i 0} {$i < $val(nn) } {incr i} {
  120.     set node_($i) [$ns_ node];
  121. }
  122.  
  123.            
  124. $node_(0) label "Source1"
  125. $node_(1) label "Source2"
  126. $node_(2) label "Gateway0"            
  127. $node_(3) label "Gateway1"            
  128. $node_(4) label "Gateway2"
  129. $node_(5) label "Destination1"  
  130. $node_(6) label "Destination2"  
  131.  
  132. for {set i 0} {$i < $val(nn) } {incr i} {
  133.     $node_($i) random-motion 0
  134. }
  135.  
  136.  
  137. for {set i 0} {$i < $val(nn)} {incr i} {
  138.     $ns_ initial_node_pos $node_($i) 20
  139. }
  140.  
  141.  
  142. # Provide initial (X,Y, for now Z=0) co-ordinates for mobilenodes
  143.  
  144. #Source1
  145. $node_(0) set X_ 50.0
  146. $node_(0) set Y_ 500.0
  147. $node_(0) set Z_ 0.0
  148.  
  149. #Source2
  150. $node_(1) set X_ 50.0
  151. $node_(1) set Y_ 250.0
  152. $node_(1) set Z_ 0.0
  153.  
  154. #Gateway1
  155. $node_(2) set X_ 250.0  
  156. $node_(2) set Y_ 375.0
  157. $node_(2) set Z_ 0.0
  158.  
  159. #Gateway2
  160. $node_(3) set X_ 450.0
  161. $node_(3) set Y_ 375.0
  162. $node_(3) set Z_ 0.0
  163.  
  164. #Gateway3
  165. $node_(4) set X_ 650.0
  166. $node_(4) set Y_ 375.0
  167. $node_(4) set Z_ 0.0
  168.  
  169. #Destination1
  170. $node_(5) set X_ 850.0
  171. $node_(5) set Y_ 500.0
  172. $node_(5) set Z_ 0.0
  173.  
  174. #Destination2
  175. $node_(6) set X_ 850.0
  176. $node_(6) set Y_ 250.0
  177. $node_(6) set Z_ 0.0
  178.  
  179.  
  180.  
  181.  
  182.  
  183. #
  184. # Now produce some simple node movements
  185.  
  186. $ns_ at 0.0 "$node_(0) setdest 50.0 500.0 0.0"
  187. $ns_ at 0.0 "$node_(1) setdest 50.0 250.0 0.0"
  188. $ns_ at 0.0 "$node_(2) setdest 250.0 375.0 0.0"
  189. $ns_ at 0.0 "$node_(3) setdest 450.0 375.0 0.0"
  190. $ns_ at 0.0 "$node_(4) setdest 650.0 375.0 0.0"
  191. $ns_ at 0.0 "$node_(5) setdest 850.0 500.0 0.0"
  192. $ns_ at 0.0 "$node_(6) setdest 850.0 250.0 0.0"
  193.  
  194.  
  195. # Setup traffic flow between nodes
  196.  
  197. # TCP connections between node_(0) and node_(5)
  198. set tcp1 [new Agent/TCP]
  199. $tcp1 set class_ 2
  200. set sink [new Agent/TCPSink]
  201. $ns_ attach-agent $node_(0) $tcp1
  202. $ns_ attach-agent $node_(5) $sink
  203. $ns_ connect $tcp1 $sink
  204. set ftp1 [new Application/FTP]
  205. $ftp1 attach-agent $tcp1
  206. $ns_ at 3.0 "$ftp1 start"
  207.  
  208. # TCP connections between node_(1) and node_(6)
  209. set tcp2 [new Agent/TCP]
  210. $tcp2 set class_ 2
  211. set sink [new Agent/TCPSink]
  212. $ns_ attach-agent $node_(1) $tcp2
  213. $ns_ attach-agent $node_(6) $sink
  214. $ns_ connect $tcp2 $sink
  215. set ftp2 [new Application/FTP]
  216. $ftp2 attach-agent $tcp2
  217. $ns_ at 3.0 "$ftp2 start"
  218.  
  219. #
  220. # Tell nodes when the simulation ends
  221. #
  222. for {set i 0} {$i < $val(nn) } {incr i} {
  223.     $ns_ at 30.0 "$node_($i) reset";
  224. }
  225. $ns_ at 90.0 "stop"
  226. $ns_ at 90.01 "puts \"NS EXITING...\" ; $ns_ halt"
  227. proc stop {} {
  228.     global ns_ tracefd
  229.     $ns_ flush-trace
  230.     close $tracefd
  231. }
  232.  
  233. puts "Starting Simulation..."
  234. $ns_ run
  235.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement