Advertisement
iPPle

Untitled

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