fork download
  1. #Creating simulator object
  2. set ns [new Simulator]
  3.  
  4. #creating two color classes for ns object to distinguish the traffic coming from various sources
  5. $ns color 0 blue
  6. $ns color 1 red
  7.  
  8. #Creating the nam file
  9. set nf [open out.nam w]
  10. $ns namtrace-all $nf
  11.  
  12. #Finish Procedure
  13. proc finish {} {
  14. global ns nf
  15. $ns flush-trace
  16. close $nf
  17. exec nam out.nam &
  18. exit 0
  19. }
  20.  
  21. #Creating Four nodes
  22. set n0 [$ns node]
  23. set n1 [$ns node]
  24. set n2 [$ns node]
  25. set n3 [$ns node]
  26.  
  27. #Creating a duplex links
  28. $ns duplex-link $n0 $n2 2Mb 10ms DropTail
  29. $ns duplex-link-op $n0 $n2 orient right-down
  30.  
  31. $ns duplex-link $n1 $n2 2Mb 10ms DropTail
  32. $ns duplex-link-op $n1 $n2 orient right-up
  33.  
  34. $ns duplex-link $n2 $n3 1.7Mb 20ms DropTail
  35. $ns duplex-link-op $n2 $n3 orient right
  36.  
  37. #Limiting the queue to only 10 packets
  38. $ns queue-limit $n0 $n2 10
  39. $ns queue-limit $n1 $n2 10
  40. $ns queue-limit $n2 $n3 10
  41.  
  42. #Creating a TCP agent and connecting it to n1
  43. set tcp1 [new Agent/TCP]
  44.  
  45. #Specifying tcp traffic to have blue color as defined in the second line of the program
  46. $tcp1 set fid_ 0
  47.  
  48. $ns attach-agent $n1 $tcp1
  49.  
  50. #Creating a Sink Agent and attaching it to n3
  51. set sinkTCP3 [new Agent/TCPSink]
  52. $ns attach-agent $n3 $sinkTCP3
  53.  
  54. #Connecting TCP agent with Sink agent
  55. $ns connect $tcp1 $sinkTCP3
  56.  
  57.  
  58.  
  59. #Specifying the UDP agent
  60. set udp0 [new Agent/UDP]
  61.  
  62. #Specifying udp traffic to have red color as defined in the second line of program
  63. $udp0 set fid_ 1
  64.  
  65. #Attaching the UDP agent with n0
  66. $ns attach-agent $n0 $udp0
  67.  
  68. #Specifying the Null agent
  69. set null0 [new Agent/Null]
  70.  
  71. #Attaching the NULL agent with n3
  72. $ns attach-agent $n3 $null0
  73.  
  74. #Connecting both udp0 and null0 agents for transferring data between n0 and n1
  75. $ns connect $udp0 $null0
  76.  
  77. #Creating FTP agent for traffic and attaching it to tcp1
  78. set ftp0 [new Application/FTP]
  79. $ftp0 attach-agent $tcp1
  80.  
  81. #Specifying the CBR agent to generate the traffic over udp0 agent
  82. set cbr0 [new Application/Traffic/CBR]
  83.  
  84. #Each packet having 1K bytes
  85. $cbr0 set packetSize_ 1000
  86.  
  87. #Each packet will be generated after 10ms i.e., 100 packets per second
  88. $cbr0 set interval 0.010
  89.  
  90. #Attaching cbr0 with udp0
  91. $cbr0 attach-agent $udp0
  92.  
  93. #Starting the FTP Traffic
  94. $ns at 0.5 "$ftp0 start"
  95. $ns at 4.0 "$ftp0 stop"
  96.  
  97. #Starting the cbr0 at 0.5 simulation time
  98. $ns at 0.1 "$cbr0 start"
  99.  
  100. #Stoping the cbr0 at 4.5 simulation time
  101. $ns at 4.5 "$cbr0 stop"
  102.  
  103. #Calling the finish procedure
  104. $ns at 5.0 "finish"
  105.  
  106. #Run the simulation
  107. $ns run
  108.  
Success #stdin #stdout #stderr 0.01s 5316KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
./prog.sh: line 5: color: command not found
./prog.sh: line 6: color: command not found
./prog.sh: line 10: namtrace-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