Advertisement
Guest User

aboSamoor

a guest
Nov 3rd, 2008
1,157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.09 KB | None | 0 0
  1.  
  2. ### This simulation is an example of combination of wired and wireless
  3. ### topologies.
  4. #-------------------------------------------------------------------------------
  5. #defining a new hashtable to store values
  6. global opt
  7. set adhocRouting DSDV
  8. set stop 350
  9. set num_wired_nodes 1
  10. set num_bs_nodes 1
  11. set num_wireless_nodes 2
  12. set x 300
  13. set y 300
  14. #-------------------------------------------------------------------------------
  15.  
  16. proc plotWindow { tcpSource file } {
  17. global ns_
  18. set time 0.1
  19. set now [$ns_ now]
  20. set cwnd [$tcpSource set cwnd_]
  21. set wnd [$tcpSource set window_]
  22. puts $file "$now $cwnd"
  23. $ns_ at [expr $now+$time] "plotWindow $tcpSource $file"
  24. }
  25.  
  26. proc wireless_node_config {ns topo em} {
  27. $ns node-config -adhocRouting DSDV \
  28. -llType LL \
  29. -macType Mac/802_11 \
  30. -ifqType Queue/DropTail/PriQueue \
  31. -ifqLen 50 \
  32. -antType Antenna/OmniAntenna \
  33. -propInstance [new Propagation/TwoRayGround] \
  34. -phyType Phy/WirelessPhy \
  35. -channel [new Channel/WirelessChannel] \
  36. -topoInstance $topo \
  37. -wiredRouting ON \
  38. -agentTrace ON \
  39. -routerTrace OFF \
  40. -macTrace OFF \
  41. @@ -outgoingErrProc $em
  42. @@ -incomingErrProc $em
  43.  
  44. }
  45.  
  46. proc nam {ns namFile trFile namOutFile} {
  47. $ns flush-trace
  48. close $namFile
  49. close $trFile
  50. puts "running nam..."
  51. # exec nam $namOutFile &
  52. puts "I am in nam"
  53. }
  54. proc finish { } {
  55. exit 0
  56. }
  57. #-------------------------------------------------------------------------------
  58. # The global simulator instance
  59. set ns_ [new Simulator]
  60. #-------------------------------------------------------------------------------
  61. #Hierarchical routing is needed to in mixed environments
  62. #each of wireless and wired environment must be in seperated domains
  63. #so at least we want 2 domains
  64.  
  65. # set up for hierarchical routing
  66. $ns_ node-config -addressType hierarchical
  67. AddrParams set domain_num_ 2
  68. lappend cluster_num 1 2
  69. AddrParams set cluster_num_ $cluster_num
  70. lappend eilastlevel 1 1 2
  71. AddrParams set nodes_num_ $eilastlevel
  72. #-------------------------------------------------------------------------------
  73. #set the Topology
  74. set topo [new Topography]
  75. $topo load_flatgrid x y
  76.  
  77. # god needs to know the number of all wireless interfaces
  78. create-god [expr $num_wireless_nodes+$num_wired_nodes]
  79. #-------------------------------------------------------------------------------
  80. #trace output file
  81. set trFile [open mixed.tr w]
  82. $ns_ trace-all $trFile
  83.  
  84. # nam output files
  85. set namFile [open mixed.nam w]
  86. $ns_ namtrace-all $namFile
  87. $ns_ namtrace-all-wireless $namFile x y
  88.  
  89. #xgraph output files
  90. set x0 [open xgraph0.tr w]
  91.  
  92. #extra files
  93. set cwndFile [open cwndFile.wtc w]
  94. #-------------------------------------------------------------------------------
  95. #Define different colors for data flows (for NAM)
  96. $ns_ color 1 Blue
  97. $ns_ color 2 Red
  98. $ns_ color 3 Green
  99. #-------------------------------------------------------------------------------
  100. @@#creating the error model
  101. @@set m1_ubstate 27.0
  102. @@set m1_bstate 12.0
  103. @@set m2_ubstate 0.4
  104. @@set m2_bstate 0.4
  105. @@set durlist "$m1_ubstate $m1_bstate $m2_ubstate $m2_bstate"
  106. @@set errmodel [new ErrorModel/ComplexTwoStateMarkov $durlist time]
  107. @@$errmodel unit packet
  108. @@$errmodel drop-target [new Agent/Null]
  109.  
  110. #the option below is for wired links, there is no links in wireless environment
  111.  
  112. #$ns_ link-lossmodel $loss_module $BS(0) $node_(0)
  113. #-------------------------------------------------------------------------------
  114. #Creating the nodes
  115.  
  116. # The wired nodes
  117. set addresses {0.0.0 1.0.0 1.1.0 1.1.1}
  118. set W(0) [$ns_ node [lindex $addresses 0]]
  119. #The wireless nodes
  120. wireless_node_config $ns_ $topo $errmodel
  121. set BS(0) [$ns_ node [lindex $addresses 1]]
  122.  
  123.  
  124. $ns_ node-config -wiredRouting OFF
  125. #base stations nodes
  126. $BS(0) random-motion 0
  127.  
  128. #mobile nodes
  129. for {set j 0} {$j < [expr $num_wired_nodes + $num_bs_nodes]} {incr j} {
  130. set node_($j) [ $ns_ node [lindex $addresses [expr $j+2]] ]
  131. #attach nodes to base station
  132. $node_($j) base-station [AddrParams addr2id [$BS(0) node-addr]]
  133. }
  134.  
  135. # End Creating the Nodes
  136. #-------------------------------------------------------------------------------
  137. # Positioning the nodes
  138. $BS(0) set X_ 50.0
  139. $BS(0) set Y_ 50.0
  140. $BS(0) set Z_ 0.0
  141. $node_(0) set X_ 0.0
  142. $node_(0) set Y_ 0.0
  143. $node_(0) set Z_ 0.0
  144. $node_(1) set X_ 100.0
  145. $node_(1) set Y_ 0.0
  146. $node_(1) set Z_ 0.0
  147. #-------------------------------------------------------------------------------
  148. #create links between wired and BS nodes
  149. $ns_ duplex-link $W(0) $BS(0) 2Mb 2ms DropTail down
  150. $ns_ duplex-link-op $W(0) $BS(0) orient down
  151. $ns_ queue-limit $W(0) $BS(0) 2020Mb
  152. #$ns_ duplex-link-op $W(0) $BS(0) queuePos 0.5
  153. #-------------------------------------------------------------------------------
  154.  
  155. #Sizing the mobile nodes this will make them appear in NAM
  156. for {set i 0} {$i < $num_wireless_nodes} {incr i} {
  157. $ns_ initial_node_pos $node_($i) 10
  158. }
  159. #-------------------------------------------------------------------------------
  160. # setup TCP connections
  161. set tcp1 [new Agent/TCP/Newreno]
  162. $tcp1 set class_ 2
  163. set sink1 [new Agent/TCPSink/DelAck]
  164. $ns_ attach-agent $W(0) $tcp1
  165. $ns_ attach-agent $node_(0) $sink1
  166. $ns_ connect $tcp1 $sink1
  167. set ftp1 [new Application/FTP]
  168. $ftp1 attach-agent $tcp1
  169. #-------------------------------------------------------------------------------
  170. #time line scenario.
  171. $ns_ at 1.5 "$ftp1 start"
  172. $ns_ at [expr $stop-10] "$ftp1 stop"
  173.  
  174. #reset nodes after finishing
  175. for {set i 0} {$i < $num_wireless_nodes } {incr i} {
  176. $ns_ at $stop.000000 "$node_($i) reset";
  177. }
  178. $ns_ at $stop.000000 "$BS(0) reset";
  179.  
  180. puts "Starting Simulation..."
  181. $ns_ at 0.1 "plotWindow $tcp1 $cwndFile"
  182. $ns_ at $stop.1 "nam $ns_ $namFile $trFile mixed.nam"
  183. $ns_ at $stop.2 "finish"
  184. #-------------------------------------------------------------------------------
  185. $ns_ run
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement