Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.42 KB | None | 0 0
  1. # ======================================================================
  2. # Define options
  3. # ======================================================================
  4. set val(chan) Channel/WirelessChannel ;# Channel Type
  5. set val(prop) Propagation/TwoRayGround ;# radio-propagation model
  6. set val(netif) Phy/WirelessPhy
  7. set val(mac) Mac/802_11
  8. set arg1 [lindex $argv 0]
  9. set val(ll) LL ;# link layer type
  10. set val(ant) Antenna/OmniAntenna ;# antenna model
  11. set val(ifqlen) 50 ;# max packet in ifq
  12. set val(nn) [lindex $argv 0] ;# number of mobilenodes
  13. set val(rp) [lindex $argv 1] ;# routing protocol
  14.  
  15. set val(ifq) Queue/DropTail/PriQueue
  16.  
  17.  
  18. set val(x) 500
  19. set val(y) 500
  20. set val(stop) 150;
  21.  
  22.  
  23. set ns [new Simulator]
  24. #Creating trace file and nam file
  25. set tracefd [open M.tr w]
  26. set windowVsTime2 [open win.tr w]
  27. set namtrace [open M.nam w]
  28.  
  29. $ns trace-all $tracefd
  30. $ns namtrace-all-wireless $namtrace $val(x) $val(y)
  31.  
  32. # set up topography object
  33. set topo [new Topography]
  34.  
  35. $topo load_flatgrid $val(x) $val(y)
  36.  
  37. create-god $val(nn)
  38.  
  39. # configure the nodes
  40. $ns node-config -adhocRouting $val(rp) \
  41. -llType $val(ll) \
  42. -macType $val(mac) \
  43. -ifqType $val(ifq) \
  44. -ifqLen $val(ifqlen) \
  45. -antType $val(ant) \
  46. -propType $val(prop) \
  47. -phyType $val(netif) \
  48. -channelType $val(chan) \
  49. -topoInstance $topo \
  50. -agentTrace ON \
  51. -routerTrace ON \
  52. -macTrace OFF \
  53. -movementTrace ON
  54.  
  55. for {set i 0} {$i < $val(nn) } { incr i } {
  56. set node_($i) [$ns node]
  57. }
  58.  
  59. # Provide initial location of mobilenodes
  60. for {set i 0} {$i < $val(nn) } { incr i } {
  61. set u [new RandomVariable/Uniform]
  62. $u set min_ 20
  63. $u set max_ 600
  64.  
  65. set y [new RandomVariable/Uniform]
  66. $y set min_ 20
  67. $y set max_ 600
  68.  
  69.  
  70.  
  71. $node_($i) set X_ [$u value]
  72. $node_($i) set Y_ [$y value]
  73. $node_($i) set Z_ 0.0
  74.  
  75. }
  76. $node_(0) set X_ 00.0
  77. $node_(0) set Y_ 100.0
  78. $node_(0) set Z_ 0.0
  79.  
  80. $node_(1) set X_ 20.0
  81. $node_(1) set Y_ 20.0
  82. $node_(1) set Z_ 0.0
  83.  
  84. $node_(2) set X_ 500.0
  85. $node_(2) set Y_ 500.0
  86. $node_(2) set Z_ 0.0
  87.  
  88. # Generation of movements
  89. $ns at 10.0 "$node_(0) setdest 250.0 250.0 3.0"
  90. $ns at 15.0 "$node_(1) setdest 45.0 285.0 5.0"
  91. $ns at 90.0 "$node_(0) setdest 490.0 300.0 5.0"
  92. $ns at 10.0 "$node_(2) setdest 100 100.0 20.0"
  93.  
  94.  
  95.  
  96. # Set a TCP connection between node_(0) and node_(1)
  97. set tcp [new Agent/TCP]
  98. $tcp set class_ 2 # Changes window_ for the $tcp object only
  99. set sink [new Agent/TCPSink]
  100. $ns attach-agent $node_(0) $tcp
  101. $ns attach-agent $node_(1) $sink
  102. $ns connect $tcp $sink
  103. set ftp [new Application/FTP]
  104. $ftp attach-agent $tcp
  105. $ns at 5.0 "$ftp start"
  106.  
  107. # Set a TCP connection between node_(2) and node_(1)
  108. set tcp1 [new Agent/TCP]
  109. $tcp1 set class_ 3 # Changes window_ for the $tcp object only
  110. set sink1 [new Agent/TCPSink]
  111. $ns attach-agent $node_(2) $tcp1
  112. $ns attach-agent $node_(1) $sink1
  113. $ns connect $tcp1 $sink1
  114. set ftp1 [new Application/FTP]
  115. $ftp1 attach-agent $tcp1
  116. $ns at 5.0 "$ftp1 start"
  117.  
  118. $ns color 2 Blue
  119. $ns color 3 Red
  120.  
  121. # Printing the window size
  122. proc plotWindow {tcpSource file} {
  123. global ns
  124. set time 0.01
  125. set now [$ns now]
  126. set packetSize_ 1000 ;
  127. set cwnd [$tcpSource set cwnd_]
  128. puts $file "$now $cwnd"
  129. $ns at [expr $now+$time] "plotWindow $tcpSource $file" }
  130. $ns at 10.1 "plotWindow $tcp $windowVsTime2"
  131.  
  132. # Define node initial position in nam
  133. for {set i 0} {$i < $val(nn)} { incr i } {
  134. # 30 defines the node size for nam
  135. $ns initial_node_pos $node_($i) 35
  136. }
  137.  
  138. # Telling nodes when the simulation ends
  139. for {set i 0} {$i < $val(nn) } { incr i } {
  140. $ns at $val(stop) "$node_($i) reset";
  141. }
  142.  
  143. # ending nam and the simulation
  144. $ns at $val(stop) "$ns nam-end-wireless $val(stop)"
  145. $ns at $val(stop) "stop"
  146. $ns at 150.01 "puts \"end simulation\" ; $ns halt"
  147. proc stop {} {
  148. global ns tracefd namtrace
  149. $ns flush-trace
  150. close $tracefd
  151. close $namtrace
  152.  
  153. exec nam M.nam &
  154. exec ./run.sh &
  155. exit 0
  156. }
  157.  
  158. $ns run
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement