Advertisement
Guest User

aboSamoor

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