Advertisement
coding_2018

class 2-5-18

May 1st, 2018
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 2.66 KB | None | 0 0
  1. set ns [new Simulator]
  2.  
  3. #Define different colors for data flows (for NAM)
  4. $ns color 1 Blue
  5. $ns color 2 Red
  6.  
  7. #Open the Trace files
  8. set file1 [open out.tr w]
  9. set winfile [open WinFile w]
  10. $ns trace-all $file1
  11.  
  12. #Open the NAM trace file
  13. set file2 [open out.nam w]
  14. $ns namtrace-all $file2
  15.  
  16. #Define a 'finish' procedure
  17. proc finish {} {
  18.         global ns file1 file2 winfile
  19.         $ns flush-trace
  20.         close $file1
  21.         close $file2
  22.     close $winfile
  23.         exec nam out.nam &
  24.         exit 0
  25. }
  26.  
  27. #Create six nodes
  28. set n0 [$ns node]
  29. set n1 [$ns node]
  30. set n2 [$ns node]
  31. set n3 [$ns node]
  32. set n4 [$ns node]
  33. set n5 [$ns node]
  34.  
  35. #Create links between the nodes
  36. $ns duplex-link $n0 $n2 2Mb 10ms DropTail
  37. $ns duplex-link $n1 $n2 2Mb 10ms DropTail
  38. $ns simplex-link $n2 $n3 0.3Mb 100ms DropTail
  39. $ns simplex-link $n3 $n2 0.3Mb 100ms DropTail
  40. $ns duplex-link $n3 $n4 0.5Mb 40ms DropTail
  41. $ns duplex-link $n3 $n5 0.5Mb 30ms DropTail
  42.  
  43. #Give node position (for NAM)
  44. $ns duplex-link-op $n0 $n2 orient right-down
  45. $ns duplex-link-op $n1 $n2 orient right-up
  46. $ns simplex-link-op $n2 $n3 orient right
  47. $ns simplex-link-op $n3 $n2 orient left
  48. $ns duplex-link-op $n3 $n4 orient right-up
  49. $ns duplex-link-op $n3 $n5 orient right-down
  50.  
  51.  
  52. #Set Queue Size of link (n2-n3) to 10
  53. $ns queue-limit $n2 $n3 20
  54.  
  55. #Setup a TCP connection
  56. set tcp [new Agent/TCP]
  57. $ns attach-agent $n0 $tcp
  58. set sink [new Agent/TCPSink]
  59. $ns attach-agent $n4 $sink
  60. $ns connect $tcp $sink
  61. $tcp set fid_ 1
  62. $tcp set window_ 500
  63. $tcp set packetSize_ 5527
  64. #$tcp set slow_start_restart_ true
  65. #https://www.isi.edu/nsnam/ns/doc/node396.html TCP Parameters
  66.  
  67. #Setup a FTP over TCP connection
  68. set ftp [new Application/FTP]
  69. $ftp attach-agent $tcp
  70. $ftp set type_ FTP
  71.  
  72.  
  73. #Setup a UDP connection
  74. set udp [new Agent/UDP]
  75. $ns attach-agent $n1 $udp
  76. set null [new Agent/Null]
  77. $ns attach-agent $n5 $null
  78. $ns connect $udp $null
  79. $udp set fid_ 2
  80.  
  81. #Setup a CBR over UDP connection
  82. set cbr [new Application/Traffic/CBR]
  83. $cbr attach-agent $udp
  84. $cbr set type_ CBR
  85. $cbr set packet_size_ 1000
  86. $cbr set rate_ 0.01mb
  87. $cbr set random_ false
  88.  
  89. $ns at 0.1 "$cbr start"
  90. $ns at 1.0 "$ftp start"
  91. $ns at 124.0 "$ftp stop"
  92. $ns at 124.5 "$cbr stop"
  93.  
  94. # next procedure gets two arguments: the name of the
  95. # tcp source node, will be called here "tcp",
  96. # and the name of output file.
  97.  
  98. proc plotWindow {tcpSource file} {
  99. global ns
  100. set time 0.1
  101. set now [$ns now]
  102. set cwnd [$tcpSource set cwnd_]
  103. set wnd [$tcpSource set window_]
  104. set sst [$tcpSource set ssthresh_]
  105. puts $file "$now $cwnd $sst $wnd"
  106. $ns at [expr $now+$time] "plotWindow $tcpSource $file" }
  107. $ns at 0.1 "plotWindow $tcp $winfile"
  108.  
  109. $ns at 125.0 "finish"
  110. $ns run
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement