Advertisement
Shailrshah

I don't know what this is [Part 2]

Apr 3rd, 2014
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 2.17 KB | None | 0 0
  1. #Simulation of Network Queue Management Algorithms (Droptail)
  2.  
  3. set ns [new Simulator]
  4.  
  5. #Define different colors for data flows (for NAM)
  6. $ns color 1 Blue
  7. $ns color 2 Red
  8.  
  9. #Open the NAM trace file
  10. set nf [open out.nam w]
  11. $ns namtrace-all $nf
  12.  
  13. #Define a 'finish' procedure
  14. proc finish {} {
  15.     global ns nf
  16.     $ns flush-trace
  17.     #Close the NAM trace file
  18.     close $nf
  19.     #Execute NAM on the trace file
  20.     exec nam out.nam &
  21.     exit 0
  22. }
  23.  
  24. #Create four nodes
  25. set n0 [$ns node]
  26. set n1 [$ns node]
  27. set n2 [$ns node]
  28. set n3 [$ns node]
  29.  
  30. #Create links between the nodes
  31. $ns duplex-link $n0 $n2 2Mb 10ms DropTail
  32. $ns duplex-link $n1 $n2 2Mb 10ms DropTail
  33. $ns duplex-link $n2 $n3 1.7Mb 20ms DropTail
  34.  
  35. #Set Queue Size of link (n2-n3) to 10
  36. $ns queue-limit $n2 $n3 3
  37.  
  38. #Give node position (for NAM)
  39. $ns duplex-link-op $n0 $n2 orient right-down
  40. $ns duplex-link-op $n1 $n2 orient left-down
  41. $ns duplex-link-op $n2 $n3 orient right
  42.  
  43. #Monitor the queue for link (n2-n3). (for NAM)
  44. $ns duplex-link-op $n2 $n3 queuePos 0.5
  45.  
  46. #Setup a TCP connection
  47. set tcp [new Agent/TCP]
  48. $tcp set class_ 2
  49. $ns attach-agent $n0 $tcp
  50. set sink [new Agent/TCPSink]
  51. $ns attach-agent $n3 $sink
  52. $ns connect $tcp $sink
  53. $tcp set fid_ 1
  54.  
  55. #Setup a FTP over TCP connection
  56. set ftp [new Application/FTP]
  57. $ftp attach-agent $tcp
  58. $ftp set type_ FTP
  59.  
  60. #Setup a UDP connection
  61. set udp [new Agent/UDP]
  62. $ns attach-agent $n1 $udp
  63. set null [new Agent/Null]
  64. $ns attach-agent $n3 $null
  65. $ns connect $udp $null
  66. $udp set fid_ 2
  67.  
  68. #Setup a CBR over UDP connection
  69. set cbr [new Application/Traffic/CBR]
  70. $cbr attach-agent $udp
  71. $cbr set type_ CBR
  72. $cbr set packet_size_ 1000
  73. $cbr set rate_ 1mb
  74. $cbr set random_ false
  75.  
  76. #Schedule events for the CBR and FTP agents
  77. $ns at 0.1 "$cbr start"
  78. $ns at 1.0 "$ftp start"
  79. $ns at 4.0 "$ftp stop"
  80. $ns at 4.5 "$cbr stop"
  81.  
  82. #Detach tcp and sink agents (not really necessary)
  83. $ns at 4.5 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n3 $sink"
  84.  
  85. #Call the finish procedure after 5 seconds of simulation time
  86. $ns at 5.0 "finish"
  87.  
  88. #Print CBR packet size and interval
  89. puts "CBR packet size = [$cbr set packet_size_]"
  90. puts "CBR interval = [$cbr set interval_]"
  91.  
  92. #Run the simulation
  93. $ns run
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement