Advertisement
AnindyaBiswas

TCL 8th class

May 25th, 2022
1,421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 1.40 KB | None | 0 0
  1. #Create a simulator object
  2. set ns [new Simulator]
  3.  
  4. #Tell the simulator to use dynamic routing
  5. $ns rtproto DV
  6.  
  7. #Open the nam trace file
  8. set nf [open out.nam w]
  9. $ns namtrace-all $nf
  10.  
  11.  
  12. #Define a 'finish' procedure
  13. proc finish {} {
  14.         global ns nf
  15.         $ns flush-trace
  16.     #Close the trace file
  17.         close $nf
  18.     #Execute nam on the trace file
  19.         exec nam out.nam &
  20.         exit 0
  21. }
  22.  
  23. #Create seven nodes
  24. for {set i 0} {$i < 7} {incr i} {
  25.         set n($i) [$ns node]
  26. }
  27.  
  28.  
  29. #Create links between the nodes
  30. for {set i 0} {$i < 7} {incr i} {
  31.         $ns duplex-link $n($i) $n([expr ($i+1)%7]) 1Mb 10ms DropTail
  32. }
  33.  
  34. #Create a UDP agent and attach it to node n(0)
  35. set udp0 [new Agent/UDP]
  36. $ns attach-agent $n(0) $udp0
  37.  
  38. # Create a CBR traffic source and attach it to udp0
  39. set cbr0 [new Application/Traffic/CBR]
  40. $cbr0 set packetSize_ 500
  41. $cbr0 set interval_ 0.005
  42. $cbr0 attach-agent $udp0
  43.  
  44. #Create a Null agent (a traffic sink) and attach it to node n(3)
  45. set null0 [new Agent/Null]
  46. $ns attach-agent $n(3) $null0
  47.  
  48. #Connect the traffic source with the traffic sink
  49. $ns connect $udp0 $null0  
  50.  
  51. #Schedule events for the CBR agent and the network dynamics
  52. $ns at 0.5 "$cbr0 start"
  53. $ns rtmodel-at 1.0 down $n(1) $n(2)
  54. $ns rtmodel-at 2.0 up $n(1) $n(2)
  55. $ns at 4.5 "$cbr0 stop"
  56. #Call the finish procedure after 5 seconds of simulation time
  57. $ns at 5.0 "finish"
  58.  
  59. #Run the simulation
  60. $ns run
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement