Advertisement
Guest User

Wireless Simulation

a guest
Oct 31st, 2014
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 2.66 KB | None | 0 0
  1. set val(chan)         Channel/WirelessChannel  ;# channel type
  2. set val(prop)         Propagation/TwoRayGround ;# radio-propagation model
  3. set val(ant)          Antenna/OmniAntenna      ;# Antenna type
  4. set val(ll)           LL                       ;# Link layer type
  5. set val(ifq)          Queue/DropTail/PriQueue  ;# Interface queue type
  6. set val(ifqlen)       50                       ;# max packet in ifq
  7. set val(netif)        Phy/WirelessPhy          ;# network interface type
  8. set val(mac)          Mac/802_11               ;# MAC type
  9. set val(rp)           DSDV                     ;# ad-hoc routing protocol  
  10. set val(nn)           5                        ;# number of mobilenodes
  11. set val(x)            500
  12. set val(y)            400
  13. set val(stop)         150
  14.  
  15. set ns [new Simulator]
  16. set tracefd [open ns2.tr w]
  17. set windowVsTime2 [open win.tr w]
  18. set namtrace [open ns2.nam w]
  19.  
  20.  
  21. $ns trace-all $tracefd
  22. $ns namtrace-all-wireless $namtrace $val(x) $val(y)
  23.  
  24. $ns color 2 Red
  25. set topo [new Topography]
  26.  
  27. $topo load_flatgrid $val(x) $val(y)
  28.  
  29. create-god $val(nn)
  30.  
  31. $ns node-config -adhocRouting $val(rp) \
  32.     -llType $val(ll) \
  33.     -macType $val(mac) \
  34.     -ifqType $val(ifq) \
  35.     -ifqLen $val(ifqlen) \
  36.     -antType $val(ant) \
  37.     -propType $val(prop) \
  38.     -phyType $val(netif) \
  39.     -channelType $val(chan) \
  40.     -topoInstance $topo \
  41.     -agentTrace ON \
  42.     -routerTrace ON \
  43.     -macTrace OFF \
  44.     -movementTrace ON
  45.  
  46. for {set i 0} {$i < $val(nn) } {incr i} {
  47.     set node_($i) [$ns node]   
  48. }
  49.  
  50. $node_(0) set X_ 5.0
  51. $node_(0) set Y_ 5.0
  52. $node_(0) set Z_ 0.0
  53.  
  54. $node_(1) set X_ 490.0
  55. $node_(1) set Y_ 285.0
  56. $node_(1) set Z_ 0.0
  57.  
  58. $node_(2) set X_ 150.0
  59. $node_(2) set Y_ 240.0
  60. $node_(2) set Z_ 0.0
  61.  
  62. $ns at 10.0 "$node_(0) setdest 250.0 250.0 3.0"
  63. $ns at 15.0 "$node_(1) setdest 245.0 285.0 5.0"
  64. $ns at 110.0 "$node_(0) setdest 480.0 300.0 10.0"
  65.  
  66. set tcp [new Agent/TCP]
  67. $tcp set class_ 2
  68. set sink [new Agent/TCPSink]
  69. $ns attach-agent $node_(0) $tcp
  70. $ns attach-agent $node_(1) $sink
  71. $ns connect $tcp $sink
  72. $tcp set fid_ 2
  73. set ftp [new Application/FTP]
  74. $ftp attach-agent $tcp
  75. $ns at 10.0 "$ftp start"
  76.  
  77. proc plotWindow {tcpSource file} {
  78.     global ns
  79.     set time 0.1
  80.     set now [$ns now]
  81.     set cwnd [$tcpSource set cwnd_]
  82.     puts $file "$now $cwnd"
  83.     $ns at [expr $now+$time] "plotWindow $tcpSource $file"
  84.  
  85. }
  86.  
  87. $ns at 10.1 "plotWindow $tcp $windowVsTime2"
  88.  
  89. for {set i 0} {$i < $val(nn) } {incr i} {
  90.     $ns initial_node_pos $node_($i) 30
  91. }
  92.  
  93. $ns at $val(stop) "$ns nam-end-wireless $val(stop)"
  94. $ns at $val(stop) "stop"
  95. #$ns at 150.01 "puts \"end simulation\"; $ns Halt"
  96.  
  97. proc stop {} {
  98.     global ns tracefd namtrace
  99.     $ns flush-trace
  100.     close $tracefd
  101.     close $namtrace
  102.     exit 0
  103. }
  104.  
  105. $ns run
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement