fork download
  1. # Create a new simulator instance
  2. set ns [new Simulator]
  3.  
  4. # Open NAM trace file for network animation
  5. set nf [open lab1.nam w]
  6. $ns namtrace-all $nf
  7.  
  8. # Open trace file for analysis
  9. set tf [open lab1.tr w]
  10. $ns trace-all $tf
  11.  
  12. # Define finish procedure
  13. proc finish {} {
  14. global ns nf tf
  15. $ns flush-trace
  16. close $nf
  17. close $tf
  18. exec nam lab1.nam &
  19. exit 0
  20. }
  21.  
  22. # Create 4 nodes
  23. set n0 [$ns node]
  24. set n1 [$ns node]
  25. set n2 [$ns node]
  26. set n3 [$ns node]
  27.  
  28. # Create duplex links between nodes
  29. $ns duplex-link $n0 $n2 200Mb 10ms DropTail
  30. $ns duplex-link $n1 $n2 100Mb 5ms DropTail
  31. $ns duplex-link $n2 $n3 1Mb 1000ms DropTail
  32.  
  33. # Set queue limits
  34. $ns queue-limit $n0 $n2 10
  35. $ns queue-limit $n1 $n2 10
  36.  
  37. # Create UDP agents
  38. set udp0 [new Agent/UDP]
  39. $ns attach-agent $n0 $udp0
  40.  
  41. set udp1 [new Agent/UDP]
  42. $ns attach-agent $n1 $udp1
  43.  
  44. set udp2 [new Agent/UDP]
  45. $ns attach-agent $n2 $udp2
  46.  
  47. # Create CBR traffic generators
  48. set cbr0 [new Application/Traffic/CBR]
  49. $cbr0 set packetSize_ 500
  50. $cbr0 set interval_ 0.005
  51. $cbr0 attach-agent $udp0
  52.  
  53. set cbr1 [new Application/Traffic/CBR]
  54. $cbr1 attach-agent $udp1
  55.  
  56. set cbr2 [new Application/Traffic/CBR]
  57. $cbr2 attach-agent $udp2
  58.  
  59. # Create null agent (sink)
  60. set null0 [new Agent/Null]
  61. $ns attach-agent $n3 $null0
  62.  
  63. # Connect UDP agents to null agent
  64. $ns connect $udp0 $null0
  65. $ns connect $udp1 $null0
  66.  
  67. # Schedule events
  68. $ns at 0.1 "$cbr0 start"
  69. $ns at 0.2 "$cbr1 start"
  70. $ns at 1.0 "finish"
  71.  
  72. # Start simulation
  73. $ns run
Success #stdin #stdout #stderr 0.01s 5316KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
./prog.sh: line 6: namtrace-all: command not found
./prog.sh: line 10: trace-all: command not found
./prog.sh: line 13: proc: command not found
./prog.sh: line 14: global: command not found
./prog.sh: line 15: flush-trace: command not found
./prog.sh: line 16: close: command not found
./prog.sh: line 17: close: command not found
./prog.sh: line 18: exec: nam: not found