Guest User

Untitled

a guest
Apr 26th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 2.25 KB | None | 0 0
  1. #Create a simulator object
  2. set ns [new Simulator]
  3.  
  4. #Define different colors for data flows (for NAM)
  5.  
  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.  
  26. set n0 [$ns node]
  27. set n1 [$ns node]
  28. set n2 [$ns node]
  29. set n3 [$ns node]
  30.  
  31. #set labels of nodes
  32. $n0 label TCP
  33. $n1 label SINK
  34.  
  35. #create the links
  36. $ns duplex-link $n0 $n1 2Mb 5ms DropTail
  37. $ns duplex-link $n2 $n3 2Mb 5ms DropTail
  38. $ns duplex-link $n0 $n3 1.5Mb 15ms RED
  39. $ns duplex-link $n2 $n1 1.5Mb 15ms RED
  40.  
  41. #setting queue size of link (n0-n1) to 20
  42. $ns queue-limit $n0 $n1 20
  43.  
  44. #adjust position of the nodes
  45. $ns duplex-link-op $n0 $n1 orient right
  46. $ns duplex-link-op $n0 $n3 orient right-down
  47. $ns duplex-link-op $n2 $n3 orient right
  48. $ns duplex-link-op $n2 $n1 orient right-up
  49.  
  50. #Monitor the queue for link (n0-n1)
  51. $ns duplex-link-op $n0 $n1 queuePos 1
  52.  
  53.  
  54. #setup TCP agents
  55. set tcp0 [new Agent/TCP]
  56. $ns attach-agent $n0 $tcp0
  57.  
  58. set tcp1 [new Agent/TCP]
  59. $ns attach-agent $n2 $tcp1
  60.  
  61. set tcp2 [new Agent/TCP]
  62. $ns attach-agent $n0 $tcp2
  63.  
  64. set tcp3 [new Agent/TCP]
  65. $ns attach-agent $n2 $tcp3
  66.  
  67. #make connections
  68. set sink0 [new Agent/TCPSink]
  69. $ns attach-agent $n1 $sink0
  70. $ns connect $tcp0 $sink0
  71.  
  72.  
  73. set sink1 [new Agent/TCPSink]
  74. $ns attach-agent $n1 $sink1
  75. $ns connect $tcp1 $sink1
  76.  
  77. set sink2 [new Agent/TCPSink]
  78. $ns attach-agent $n3 $sink2
  79. $ns connect $tcp2 $sink2
  80.  
  81. set sink3 [new Agent/TCPSink]
  82. $ns attach-agent $n3 $sink3
  83. $ns connect $tcp3 $sink3
  84.  
  85. #Setup FTP over TCP connection
  86.  
  87. set ftp0 [new Application/FTP]
  88. $ftp0 attach-agent $tcp0
  89.  
  90. set ftp1 [new Application/FTP]
  91. $ftp1 attach-agent $tcp1
  92.  
  93. set ftp2 [new Application/FTP]
  94. $ftp2 attach-agent $tcp2
  95.  
  96. set ftp3 [new Application/FTP]
  97. $ftp3 attach-agent $tcp3
  98.  
  99. #Schedule events for FTP agents
  100. $ns at 0.1 "$ftp0 start"
  101. $ns at 5.0 "$ftp0 stop"
  102.  
  103. $ns at 0.1 "$ftp1 start"
  104. $ns at 5.0 "$ftp1 stop"
  105.  
  106.  
  107. #Call the finish procedure after 5 seconds of simulation time
  108. $ns at 5.0 "finish"
  109.  
  110. #Run the simulation
  111. $ns run
Add Comment
Please, Sign In to add comment