Mizuhara_Chizuru

Untitled

Aug 20th, 2026
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.47 KB | None | 0 0
  1. gnome-text-editor five-node-wireless.tcl &
  2.  
  3. # ======================================================================
  4. # Define Wireless Simulation Parameters
  5. # ======================================================================
  6. set val(chan) Channel/WirelessChannel ;# channel type
  7. set val(prop) Propagation/TwoRayGround ;# radio-propagation model
  8. set val(netif) Phy/WirelessPhy ;# network interface type
  9. set val(mac) Mac/802_11 ;# MAC type
  10. set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
  11. set val(ll) LL ;# link layer type
  12. set val(ant) Antenna/OmniAntenna ;# antenna model
  13. set val(ifqlen) 50 ;# max packet in ifq
  14. set val(nn) 5 ;# number of mobilenodes
  15. set val(rp) AODV ;# AODV Routing (Creates LOTS of broadcast ripples)
  16. set val(x) 500 ;# X dimension of topography
  17. set val(y) 500 ;# Y dimension of topography
  18. set val(stop) 10.0 ;# time of simulation end
  19.  
  20. # --- NEW BANDWIDTH OPTION ---
  21. set val(bw) 11Mb ;# Set your custom bandwidth here (e.g., 2Mb, 11Mb, 54Mb)
  22. Mac/802_11 set dataRate_ $val(bw)
  23. Mac/802_11 set basicRate_ 1Mb
  24.  
  25. # ======================================================================
  26. # Initialize Simulator and Trace Files
  27. # ======================================================================
  28. set ns_ [new Simulator]
  29.  
  30. set tracefd [open five-node-wireless.tr w]
  31. $ns_ trace-all $tracefd
  32.  
  33. set namtrace [open five-node-wireless.nam w]
  34. $ns_ namtrace-all-wireless $namtrace $val(x) $val(y)
  35.  
  36. # ======================================================================
  37. # Setup Topography and God
  38. # ======================================================================
  39. set topo [new Topography]
  40. $topo load_flatgrid $val(x) $val(y)
  41.  
  42. create-god $val(nn)
  43.  
  44. # ======================================================================
  45. # Configure the Nodes
  46. # ======================================================================
  47. $ns_ node-config -adhocRouting $val(rp) \
  48. -llType $val(ll) \
  49. -macType $val(mac) \
  50. -ifqType $val(ifq) \
  51. -ifqLen $val(ifqlen) \
  52. -antType $val(ant) \
  53. -propType $val(prop) \
  54. -phyType $val(netif) \
  55. -channelType $val(chan) \
  56. -topoInstance $topo \
  57. -agentTrace ON \
  58. -routerTrace ON \
  59. -macTrace OFF \
  60. -movementTrace ON
  61.  
  62. # ======================================================================
  63. # Create 5 Nodes and Set Their Starting Positions
  64. # ======================================================================
  65. for {set i 0} {$i < $val(nn)} {incr i} {
  66. set node_($i) [$ns_ node]
  67. $node_($i) random-motion 0
  68. }
  69.  
  70. $node_(0) set X_ 50.0
  71. $node_(0) set Y_ 250.0
  72. $node_(0) set Z_ 0.0
  73.  
  74. $node_(1) set X_ 150.0
  75. $node_(1) set Y_ 100.0
  76. $node_(1) set Z_ 0.0
  77.  
  78. $node_(2) set X_ 250.0
  79. $node_(2) set Y_ 250.0
  80. $node_(2) set Z_ 0.0
  81.  
  82. $node_(3) set X_ 350.0
  83. $node_(3) set Y_ 400.0
  84. $node_(3) set Z_ 0.0
  85.  
  86. $node_(4) set X_ 450.0
  87. $node_(4) set Y_ 250.0
  88. $node_(4) set Z_ 0.0
  89.  
  90. for {set i 0} {$i < $val(nn)} {incr i} {
  91. $ns_ initial_node_pos $node_($i) 30
  92. }
  93.  
  94. # ======================================================================
  95. # Setup Network Traffic (Heavy traffic = more ripples)
  96. # ======================================================================
  97. # Traffic 1: TCP from Node 0 to Node 4
  98. set tcp [new Agent/TCP]
  99. $ns_ attach-agent $node_(0) $tcp
  100. set sink [new Agent/TCPSink]
  101. $ns_ attach-agent $node_(4) $sink
  102. $ns_ connect $tcp $sink
  103. set ftp [new Application/FTP]
  104. $ftp attach-agent $tcp
  105. $ns_ at 0.5 "$ftp start"
  106. $ns_ at 9.5 "$ftp stop"
  107.  
  108. # Traffic 2: Aggressive UDP from Node 1 to Node 3
  109. set udp1 [new Agent/UDP]
  110. $ns_ attach-agent $node_(1) $udp1
  111. set null1 [new Agent/Null]
  112. $ns_ attach-agent $node_(3) $null1
  113. $ns_ connect $udp1 $null1
  114. set cbr1 [new Application/Traffic/CBR]
  115. $cbr1 set packetSize_ 1024
  116. $cbr1 set interval_ 0.01 ;# Blasting 100 packets a second
  117. $cbr1 attach-agent $udp1
  118. $ns_ at 1.0 "$cbr1 start"
  119. $ns_ at 8.5 "$cbr1 stop"
  120.  
  121. # Traffic 3: Aggressive UDP from Node 2 to Node 0 (Creates cross-traffic ripples)
  122. set udp2 [new Agent/UDP]
  123. $ns_ attach-agent $node_(2) $udp2
  124. set null2 [new Agent/Null]
  125. $ns_ attach-agent $node_(0) $null2
  126. $ns_ connect $udp2 $null2
  127. set cbr2 [new Application/Traffic/CBR]
  128. $cbr2 set packetSize_ 1024
  129. $cbr2 set interval_ 0.01 ;# Blasting another 100 packets a second
  130. $cbr2 attach-agent $udp2
  131. $ns_ at 1.5 "$cbr2 start"
  132. $ns_ at 9.0 "$cbr2 stop"
  133.  
  134. # ======================================================================
  135. # Stop the Simulation and Launch NAM
  136. # ======================================================================
  137. for {set i 0} {$i < $val(nn)} {incr i} {
  138. $ns_ at $val(stop) "$node_($i) reset"
  139. }
  140.  
  141. proc finish {} {
  142. global ns_ tracefd namtrace
  143. $ns_ flush-trace
  144. close $tracefd
  145. close $namtrace
  146. puts "Simulation Complete. Launching NAM..."
  147. exec nam five-node-wireless.nam &
  148. exit 0
  149. }
  150.  
  151. $ns_ at $val(stop) "finish"
  152. $ns_ at [expr $val(stop) + 0.1] "puts \"NS EXITING...\" ; $ns_ halt"
  153.  
  154. puts "Starting Simulation..."
  155. $ns_ run
  156.  
  157. ns five-node-wireless.tcl
Advertisement
Add Comment
Please, Sign In to add comment