Advertisement
iPPle

Untitled

Sep 29th, 2022
2,550
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 3.11 KB | None | 0 0
  1. # A 3-node example for ad-hoc simulation with AODV
  2. # Define options
  3. set val(chan) Channel/WirelessChannel ;# channel type
  4. set val(prop) Propagation/TwoRayGround ;# radio-propagation model
  5. set val(netif) Phy/WirelessPhy ;# network interface type
  6. set val(mac) Mac/802_11 ;# MAC type
  7.  
  8. set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
  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) 3 ;# number of mobilenodes
  13. set val(rp) AODV ;# routing protocol
  14. set val(x) 300 ;# X dimension of topography
  15. set val(y) 300 ;# Y dimension of topography
  16. set val(stop) 15 ;# time of simulation end
  17. set ns [new Simulator]
  18. set tracefd [open simple.tr w]
  19. set windowVsTime2 [open win.tr w]
  20. set namtrace [open simwrls.nam w]
  21. $ns trace-all $tracefd
  22. $ns namtrace-all-wireless $namtrace $val(x) $val(y)
  23.  
  24. # set up topography object
  25. set topo [new Topography]
  26. $topo load_flatgrid $val(x) $val(y)
  27. create-god $val(nn)
  28.  
  29. #
  30. # Create nn mobilenodes [$val(nn)], attach to the channel anf configure them.
  31. #
  32. $ns node-config -adhocRouting $val(rp) \
  33.     -llType $val(ll) \
  34.     -macType $val(mac) \
  35.     -ifqType $val(ifq) \
  36.     -ifqLen $val(ifqlen) \
  37.     -antType $val(ant) \
  38.     -propType $val(prop) \
  39.     -phyType $val(netif) \
  40.     -channelType $val(chan) \
  41.     -topoInstance $topo \
  42.     -agentTrace ON \
  43.     -routerTrace ON \
  44.     -macTrace OFF \
  45.     -movementTrace ON
  46. for {set i 0} {$i < $val(nn) } { incr i } {
  47.     set node_($i) [$ns node]
  48. }
  49.  
  50. # Provide initial location of mobilenodes
  51. $node_(0) set X_ 150.0
  52. $node_(0) set Y_ 50.0
  53. $node_(0) set Z_ 0.0
  54. $node_(1) set X_ 280.0
  55. $node_(1) set Y_ 10.0
  56.  
  57. $node_(1) set Z_ 0.0
  58. $node_(2) set X_ 40.0
  59. $node_(2) set Y_ 50.0
  60. $node_(2) set Z_ 0.0
  61.  
  62. # Generation of movements : set dest to x, y with speed s.
  63. $ns at 1.0 "$node_(0) setdest 80.0 100.0 5.0"
  64. $ns at 1.0 "$node_(2) setdest 1.0 250.0 15.0"
  65.  
  66. # Set a TCP connection between node_(0) and node_(1)
  67. set tcp [new Agent/TCP/Newreno]
  68. $tcp set class_ 2
  69. set sink [new Agent/TCPSink]
  70. $ns attach-agent $node_(1) $tcp
  71. $ns attach-agent $node_(2) $sink
  72. $ns connect $tcp $sink
  73. set ftp [new Application/FTP]
  74. $ftp attach-agent $tcp
  75. $ns at 1.0 "$ftp start"
  76. $ns at 12.0 "$ftp stop"
  77.  
  78. # Printing the window size
  79. proc plotWindow {tcpSource file} {
  80.     global ns
  81.     set time 0.01
  82.     set now [$ns now]²
  83.     set cwnd [$tcpSource set cwnd_]
  84.     puts $file "$now $cwnd"
  85.     $ns at [expr $now+$time] "plotWindow $tcpSource $file"
  86.     $ns at 10.1 "plotWindow $tcp $windowVsTime2"
  87. }
  88.  
  89. # Define node initial position in nam
  90. for {set i 0} {$i < $val(nn)} { incr i } {
  91.     # 30 defines the node size for nam
  92.     $ns initial_node_pos $node_($i) 30
  93. }
  94.  
  95. # Telling nodes when the simulation ends
  96. for {set i 0} {$i < $val(nn) } { incr i } {
  97.     $ns at $val(stop) "$node_($i) reset";
  98. }
  99.  
  100. # ending nam and the simulation
  101. $ns at $val(stop) "$ns nam-end-wireless $val(stop)"
  102. $ns at $val(stop) "stop"
  103. $ns at 150.01 "puts \"end simulation\" ; $ns halt"
  104. proc stop {} {
  105.     global ns tracefd namtrace
  106.     $ns flush-trace
  107.     close $tracefd
  108.     close $namtrace
  109. }
  110.  
  111. $ns run
  112.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement