Advertisement
Guest User

Wireless-Cum-wired

a guest
Oct 31st, 2014
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 8.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. # wireless2.tcl
  33. # simulation of a wired-cum-wireless scenario consisting of 2 wired nodes
  34. # connected to a wireless domain through a base-station node.
  35. # ======================================================================
  36. # Define options
  37. # ======================================================================
  38. set opt(chan)           Channel/WirelessChannel    ;# channel type
  39. set opt(prop)           Propagation/TwoRayGround   ;# radio-propagation model
  40. set opt(netif)          Phy/WirelessPhy            ;# network interface type
  41. set opt(mac)            Mac/802_11                 ;# MAC type
  42. set opt(ifq)            Queue/DropTail/PriQueue    ;# interface queue type
  43. set opt(ll)             LL                         ;# link layer type
  44. set opt(ant)            Antenna/OmniAntenna        ;# antenna model
  45. set opt(ifqlen)         50                         ;# max packet in ifq
  46. set opt(nn)             3                          ;# number of mobilenodes
  47. set opt(adhocRouting)   DSDV                       ;# routing protocol
  48.  
  49. set opt(cp)             ""                         ;# connection pattern file
  50. set opt(sc)     "../mobility/scene/scen-3-test"    ;# node movement file.
  51.  
  52. set opt(x)      670                            ;# x coordinate of topology
  53. set opt(y)      670                            ;# y coordinate of topology
  54. set opt(seed)   0.0                            ;# seed for random number gen.
  55. set opt(stop)   250                            ;# time to stop simulation
  56.  
  57. set opt(ftp1-start)      160.0
  58. set opt(ftp2-start)      170.0
  59.  
  60. set num_wired_nodes      2
  61. set num_bs_nodes         1
  62.  
  63. # ============================================================================
  64. # check for boundary parameters and random seed
  65. if { $opt(x) == 0 || $opt(y) == 0 } {
  66.     puts "No X-Y boundary values given for wireless topology\n"
  67. }
  68. if {$opt(seed) > 0} {
  69.     puts "Seeding Random number generator with $opt(seed)\n"
  70.     ns-random $opt(seed)
  71. }
  72.  
  73. # create simulator instance
  74. set ns_   [new Simulator]
  75.  
  76. # set up for hierarchical routing
  77. $ns_ node-config -addressType hierarchical
  78. AddrParams set domain_num_ 2           ;# number of domains
  79. lappend cluster_num 2 1                ;# number of clusters in each domain
  80. AddrParams set cluster_num_ $cluster_num
  81. lappend eilastlevel 1 1 4              ;# number of nodes in each cluster
  82. AddrParams set nodes_num_ $eilastlevel ;# of each domain
  83.  
  84. set tracefd  [open wireless2-out.tr w]
  85. set namtrace [open wireless2-out.nam w]
  86. $ns_ trace-all $tracefd
  87. $ns_ namtrace-all-wireless $namtrace $opt(x) $opt(y)
  88.  
  89. # Create topography object
  90. set topo   [new Topography]
  91.  
  92. # define topology
  93. $topo load_flatgrid $opt(x) $opt(y)
  94.  
  95. # create God
  96. create-god [expr $opt(nn) + $num_bs_nodes]
  97.  
  98. #create wired nodes
  99. set temp {0.0.0 0.1.0}        ;# hierarchical addresses for wired domain
  100. for {set i 0} {$i < $num_wired_nodes} {incr i} {
  101.     set W($i) [$ns_ node [lindex $temp $i]]
  102. }
  103.  
  104. # configure for base-station node
  105. $ns_ node-config -adhocRouting $opt(adhocRouting) \
  106.                  -llType $opt(ll) \
  107.                  -macType $opt(mac) \
  108.                  -ifqType $opt(ifq) \
  109.                  -ifqLen $opt(ifqlen) \
  110.                  -antType $opt(ant) \
  111.                  -propType $opt(prop) \
  112.                  -phyType $opt(netif) \
  113.                  -channelType $opt(chan) \
  114.          -topoInstance $topo \
  115.                  -wiredRouting ON \
  116.          -agentTrace ON \
  117.                  -routerTrace OFF \
  118.                  -macTrace OFF
  119.  
  120. #create base-station node
  121. set temp {1.0.0 1.0.1 1.0.2 1.0.3}   ;# hier address to be used for wireless
  122.                                      ;# domain
  123. set BS(0) [$ns_ node [lindex $temp 0]]
  124. $BS(0) random-motion 0               ;# disable random motion
  125.  
  126. #provide some co-ord (fixed) to base station node
  127. $BS(0) set X_ 1.0
  128. $BS(0) set Y_ 2.0
  129. $BS(0) set Z_ 0.0
  130.  
  131. # create mobilenodes in the same domain as BS(0)  
  132. # note the position and movement of mobilenodes is as defined
  133. # in $opt(sc)
  134.  
  135. #configure for mobilenodes
  136. $ns_ node-config -wiredRouting OFF
  137.  
  138.   for {set j 0} {$j < $opt(nn)} {incr j} {
  139.     set node_($j) [ $ns_ node [lindex $temp \
  140.         [expr $j+1]] ]
  141.     $node_($j) base-station [AddrParams addr2id \
  142.         [$BS(0) node-addr]]
  143. }
  144.  
  145. #create links between wired and BS nodes
  146.  
  147. $ns_ duplex-link $W(0) $W(1) 5Mb 2ms DropTail
  148. $ns_ duplex-link $W(1) $BS(0) 5Mb 2ms DropTail
  149.  
  150. $ns_ duplex-link-op $W(0) $W(1) orient down
  151. $ns_ duplex-link-op $W(1) $BS(0) orient left-down
  152.  
  153. # setup TCP connections
  154. set tcp1 [new Agent/TCP]
  155. $tcp1 set class_ 2
  156. set sink1 [new Agent/TCPSink]
  157. $ns_ attach-agent $node_(0) $tcp1
  158. $ns_ attach-agent $W(0) $sink1
  159. $ns_ connect $tcp1 $sink1
  160. set ftp1 [new Application/FTP]
  161. $ftp1 attach-agent $tcp1
  162. $ns_ at $opt(ftp1-start) "$ftp1 start"
  163.  
  164. set tcp2 [new Agent/TCP]
  165. $tcp2 set class_ 2
  166. set sink2 [new Agent/TCPSink]
  167. $ns_ attach-agent $W(1) $tcp2
  168. $ns_ attach-agent $node_(2) $sink2
  169. $ns_ connect $tcp2 $sink2
  170. set ftp2 [new Application/FTP]
  171. $ftp2 attach-agent $tcp2
  172. $ns_ at $opt(ftp2-start) "$ftp2 start"
  173.  
  174.  
  175. # source connection-pattern and node-movement scripts
  176. if { $opt(cp) == "" } {
  177.     puts "*** NOTE: no connection pattern specified."
  178.         set opt(cp) "none"
  179. } else {
  180.     puts "Loading connection pattern..."
  181.     source $opt(cp)
  182. }
  183. if { $opt(sc) == "" } {
  184.     puts "*** NOTE: no scenario file specified."
  185.         set opt(sc) "none"
  186. } else {
  187.     puts "Loading scenario file..."
  188.     source $opt(sc)
  189.     puts "Load complete..."
  190. }
  191.  
  192. # Define initial node position in nam
  193.  
  194. for {set i 0} {$i < $opt(nn)} {incr i} {
  195.  
  196.     # 20 defines the node size in nam, must adjust it according to your
  197.     # scenario
  198.     # The function must be called after mobility model is defined
  199.  
  200.     $ns_ initial_node_pos $node_($i) 20
  201. }    
  202.  
  203. # Tell all nodes when the simulation ends
  204. for {set i } {$i < $opt(nn) } {incr i} {
  205.     $ns_ at $opt(stop).0 "$node_($i) reset";
  206. }
  207. $ns_ at $opt(stop).0 "$BS(0) reset";
  208.  
  209. $ns_ at $opt(stop).0002 "puts \"NS EXITING...\" ; $ns_ halt"
  210. $ns_ at $opt(stop).0001 "stop"
  211. proc stop {} {
  212.     global ns_ tracefd namtrace
  213.     $ns_ flush-trace
  214.     close $tracefd
  215.     close $namtrace
  216. }
  217.  
  218. # informative headers for CMUTracefile
  219. #puts $tracefd "M 0.0 nn $opt(nn) x $opt(x) y $opt(y) rp \ $opt(adhocRouting)"
  220. #puts $tracefd "M 0.0 sc $opt(sc) cp $opt(cp) seed $opt(seed)"
  221. #puts $tracefd "M 0.0 prop $opt(prop) ant $opt(ant)"
  222.  
  223. puts "Starting Simulation..."
  224. $ns_ run
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement