Advertisement
war99859

Untitled

May 7th, 2023 (edited)
612
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 4.66 KB | Cybersecurity | 0 0
  1. # Star Topology
  2. set ns [new Simulator]
  3.  
  4. set nf [open st.nam w]
  5. $ns namtrace-all $nf
  6.  
  7. proc finish {} {
  8. global ns nf
  9. $ns flush-trace
  10. close $nf
  11. exec nam st.nam &
  12. exit 0
  13.  }
  14.  
  15. set n0 [$ns node]
  16. set n1 [$ns node]
  17. set n2 [$ns node]
  18. set n3 [$ns node]
  19.  
  20. $ns duplex-link $n0 $n2 10Mb 10ms DropTail
  21. $ns duplex-link $n1 $n2 10Mb 10ms DropTail
  22. $ns duplex-link $n2 $n3 10Mb 10ms DropTail
  23.  
  24. $ns duplex-link-op $n0 $n2 orient right-down
  25. $ns duplex-link-op $n1 $n2 orient right-up
  26. $ns duplex-link-op $n2 $n3 orient right
  27.  
  28. $ns at 5.0 "finish"
  29.  
  30. $ns run
  31.  
  32. -----------------------------------------------------------------------------------------------------------
  33.  
  34. #Throuhput Latency
  35.  
  36. set ns [new Simulator]
  37.  
  38. $ns color 1 red
  39. $ns color 2 green
  40.  
  41. set nf [open tl.nam w]
  42. $ns namtrace-all $nf
  43.  
  44. set nt [open tl.tr w]
  45. $ns trace-all $nt
  46.  
  47. proc finish {} {
  48. global ns nf nt
  49. $ns flush-trace
  50. close $nf
  51. close $nt
  52. exec nam tl.nam &
  53. exec awk -f throughput.awk tl.tr &
  54. exit 0
  55. }
  56.  
  57. set n0 [$ns node]
  58. set n1 [$ns node]
  59. set n2 [$ns node]
  60. set n3 [$ns node]
  61.  
  62. $ns duplex-link $n0 $n2 10Mb 10ms DropTail
  63. $ns duplex-link $n1 $n2 10Mb 10ms DropTail
  64. $ns duplex-link $n2 $n3 10Mb 10ms DropTail
  65.  
  66. $ns duplex-link-op $n0 $n2 orient right-down
  67. $ns duplex-link-op $n1 $n2 orient right-up
  68. $ns duplex-link-op $n2 $n3 orient right
  69.  
  70. set tcp [new Agent/TCP]
  71. $tcp set class_ 2
  72. $ns attach-agent $n0 $tcp
  73. set sink [new Agent/TCPSink]
  74. $ns attach-agent $n3 $sink
  75. $ns connect $tcp $sink
  76. $tcp set fid_ 1
  77.  
  78. set ftp [new Application/FTP]
  79. $ftp attach-agent $tcp
  80. $ftp set type_ FTP
  81. $ftp set packet_size_ 1000
  82. $ftp set rate_ 1mb
  83.  
  84. set udp [new Agent/UDP]
  85. $ns attach-agent $n1 $udp
  86. set null [new Agent/Null]
  87. $ns attach-agent $n3 $null
  88. $ns connect $udp $null
  89. $udp set fid_ 2
  90.  
  91. set cbr [new Application/Traffic/CBR]
  92. $cbr attach-agent $udp
  93. $cbr set type_ UDP
  94. $cbr set packet_size_ 1000
  95. $cbr set rate_ 1mb
  96.  
  97. $ns at 1.0 "$ftp start"
  98. $ns at 2.0 "$ftp stop"
  99.  
  100. $ns at 1.2 "$cbr start"
  101. $ns at 2.2 "$cbr stop"
  102.  
  103. $ns at 5.0 "finish"
  104.  
  105. $ns run
  106.  
  107.  
  108.  
  109. # throughput.awk
  110.  
  111. BEGIN {
  112. stime=0
  113. ftime=0
  114. flag=0
  115. fsize=0
  116. throughput=0
  117. latecy=0
  118. }
  119.  
  120. {
  121. if($1=="r" && $4==3)
  122.  {
  123.   fsize+=$6
  124.   if(flag==0)
  125.    {
  126.     stime=$2
  127.     flag=1
  128.    }
  129.   ftime=$2
  130.  }
  131. }
  132.  
  133. END {
  134. latency=ftime-stime
  135. throughput=(fsize*8)/latency
  136. printf("\nLatency: %f",latency)
  137. printf("\nThroughput: %f",throughput)
  138. }
  139.  
  140. ----------------------------------------------------------------------------------------
  141.  
  142. #ping
  143.  
  144. set ns [new Simulator]
  145.  
  146. set tracefile [open out.tr w]
  147. $ns trace-all $tracefile
  148.  
  149. set namfile [open out.nam w]
  150. $ns namtrace-all $namfile
  151.  
  152. proc finish {} {
  153.     global ns tracefile namfile
  154.     $ns flush-trace
  155.     close $tracefile
  156.     close $namfile
  157.     exec nam out.nam &
  158.     exec awk -f pingtp.awk out.tr &
  159.     exit 0
  160. }
  161.  
  162. set n0 [$ns node]
  163. set n1 [$ns node]
  164. set n2 [$ns node]
  165. set n3 [$ns node]
  166. set n4 [$ns node]
  167. set n5 [$ns node]
  168. $n0 label "ping0"
  169. $n1 label "ping1"
  170. $n2 label "R1"
  171. $n3 label "R2"
  172. $n4 label "ping4"
  173. $n5 label "ping5"
  174. $ns color 1 red
  175. $ns color 2 blue
  176. $ns color 3 green
  177. $ns color 4 orange
  178.  
  179. $ns duplex-link $n0 $n2 1Mb 10ms DropTail
  180. $ns duplex-link $n1 $n2 0.4Mb 10ms DropTail
  181. $ns duplex-link $n2 $n3 4Kb 10ms DropTail
  182. $ns duplex-link $n3 $n4 1Mb 10ms DropTail
  183. $ns duplex-link $n3 $n5 1Mb 10ms DropTail
  184.  
  185. $ns duplex-link-op $n0 $n2 orient right-down
  186. $ns duplex-link-op $n1 $n2 orient right-up
  187. $ns duplex-link-op $n2 $n3 orient right
  188. $ns duplex-link-op $n3 $n4 orient right-up
  189. $ns duplex-link-op $n3 $n5 orient right-down
  190.  
  191. set ping0 [new Agent/Ping]
  192. $ns attach-agent $n0 $ping0
  193.  
  194. set ping1 [new Agent/Ping]
  195. $ns attach-agent $n1 $ping1
  196.  
  197. set ping4 [new Agent/Ping]
  198. $ns attach-agent $n4 $ping4
  199.  
  200. set ping5 [new Agent/Ping]
  201. $ns attach-agent $n5 $ping5
  202.  
  203. $ns connect $ping0 $ping4
  204. $ns connect $ping1 $ping5
  205.  
  206. $ping0 set class_ 1
  207. $ping1 set class_ 2
  208. $ping4 set class_ 3
  209. $ping5 set class_ 4
  210.  
  211. proc sendPingPacket {} {
  212.         global ns ping0 ping1
  213.         set intervalTime 0.001
  214.         set now [$ns now]
  215.         $ns at [expr $now + $intervalTime] "$ping0 send"
  216.         $ns at [expr $now + $intervalTime] "$ping1 send"
  217.         $ns at [expr $now + $intervalTime] "sendPingPacket"
  218. }
  219.  
  220. Agent/Ping instproc recv {from rtt} {
  221.         global seq
  222.         $self instvar node_
  223.         puts "The node [$node_ id] received an ACK from the node $from with RTT $rtt ms"
  224. }
  225.  
  226. $ns at 0.01 "sendPingPacket"
  227. $ns at 10.0 "finish"
  228. $ns run
  229.  
  230.  
  231.  
  232. # Pingtp.awk
  233.  
  234. BEGIN {
  235.  count=0
  236. }
  237.  
  238. {
  239.  event=$1
  240.  if(event=="d") {
  241.    count++
  242.  }
  243. }
  244.  
  245. END {
  246.  printf("No. of Packets dropped: %d\n",count);
  247. }
  248.  
  249. ----------------------------------------------------------------------------------------------------------
  250.  
  251.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement