Advertisement
cyberpunk7925

Untitled

May 7th, 2023 (edited)
639
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 9.01 KB | None | 0 0
  1. STAR TOPOLOGY USING TCP
  2. set ns [new Simulator]
  3.  
  4. set nf [open prac1.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 prac1.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. set tcp [new Agent/TCP]
  29. $tcp set class_ 2
  30. $ns attach-agent $n0 $tcp
  31. set sink [new Agent/TCPSink]
  32. $ns attach-agent $n3 $sink
  33. $ns connect $tcp $sink
  34.  
  35. set ftp [new Application/FTP]
  36. $ftp attach-agent $tcp
  37. $ftp set type_ FTP
  38. $ftp set packet_size_ 1000
  39. $ftp set rate_ 1mb
  40.  
  41. $ns at 1.0  "$ftp start"
  42. $ns at 2.0  "$ftp stop"
  43.  
  44. $ns at 5.0 "finish"
  45. $ns run
  46. --------------------------------------------------------------------------------------------------------------------------------------
  47. THROUGHPUT AND LATENCY
  48. set ns [new Simulator]
  49.  
  50. set nf [open pgm1.nam w]
  51. $ns namtrace-all $nf
  52.  
  53. set nt [open pgm1.tr w]
  54. $ns trace-all $nt
  55.  
  56. proc finish {} {
  57. global ns nf nt
  58. $ns flush-trace
  59. close $nf
  60. close $nt
  61. exec nam pgm1.nam &
  62. exec awk -f throughput.awk pgm1.tr &
  63. exit 0
  64. }
  65.  
  66. set n0 [$ns node]
  67. set n1 [$ns node]
  68. set n2 [$ns node]
  69. set n3 [$ns node]
  70.  
  71. $ns duplex-link $n0 $n2 10Mb 10ms DropTail
  72. $ns duplex-link $n1 $n2 5Mb 15ms DropTail
  73. $ns duplex-link $n2 $n3 15Mb 6ms DropTail
  74.  
  75. $ns duplex-link-op $n0 $n2 orient right-down
  76. $ns duplex-link-op $n1 $n2 orient right-up
  77. $ns duplex-link-op $n2 $n3 orient right
  78.  
  79. set tcp [new Agent/TCP]
  80. $tcp set class_ 2
  81. $ns attach-agent $n0 $tcp
  82. set sink [new Agent/TCPSink]
  83. $ns attach-agent $n3 $sink
  84. $ns connect $tcp $sink
  85. set ftp [new Application/FTP]
  86. $ftp attach-agent $tcp
  87. $ftp set type_ FTP
  88. $ftp set packet_size_ 1000
  89. $ftp set rate_ 1mb
  90.  
  91. $ns at 1.0 "$ftp start"
  92. $ns at 2.0 "$ftp stop"
  93. $ns at 5.0 "finish"
  94. $ns run
  95. Step3:
  96.     Throughput.awk file
  97. Code:
  98. BEGIN{
  99. stime=0
  100. ftime=0
  101. flag=0
  102. fsize=0
  103. throughput=0
  104. latency=0
  105. }
  106.  
  107. {
  108. if($1=="r"&&$4==3)
  109. fsize+=$6
  110. if(flag==0)
  111. {
  112. stime=$2
  113. flag=1
  114. }
  115. ftime=$2
  116. }
  117.  
  118.  
  119. END{
  120. latency=ftime-stime
  121. throughput=(fsize*8)/latency
  122. printf("Latency : %f", latency)
  123. printf("Throughput : %f",throughput)
  124. }
  125.  
  126. --------------------------------------------------------------------------------------------------------------------------------------
  127. PING
  128. set val(stop)   10.0;# time of simulation end
  129. #Create a ns simulator
  130. set ns [new Simulator]
  131.  
  132. #Open the NS trace file
  133. set tracefile [open out.tr w]
  134. $ns trace-all $tracefile
  135.  
  136. #Open the NAM trace file
  137. set namfile [open out.nam w]
  138. $ns namtrace-all $namfile
  139.  
  140. #Create 6 nodes
  141. set n0 [$ns node]
  142. set n1 [$ns node]
  143. set n2 [$ns node]
  144. set n3 [$ns node]
  145. set n4 [$ns node]
  146. set n5 [$ns node]
  147. $n0 label "ping0"
  148. $n1 label "ping1"
  149. $n2 label "R1"
  150. $n3 label "R2"
  151. $n4 label "ping4"
  152. $n5 label "ping5"
  153. $ns color 1 red
  154. $ns color 2 blue
  155. $ns color 3 green
  156. $ns color 4 orange
  157.  
  158. #Createlinks between nodes
  159. $ns duplex-link $n0 $n2 1Mb 10ms DropTail
  160. $ns duplex-link $n1 $n2 0.4Mb 10ms DropTail
  161. $ns duplex-link $n2 $n3 4Kb 10ms DropTail
  162. $ns duplex-link $n3 $n4 1Mb 10ms DropTail
  163. $ns duplex-link $n3 $n5 1Mb 10ms DropTail
  164.  
  165.  
  166. #Give node position (for NAM)
  167. $ns duplex-link-op $n0 $n2 orient right-down
  168. $ns duplex-link-op $n1 $n2 orient right-up
  169. $ns duplex-link-op $n2 $n3 orient right
  170. $ns duplex-link-op $n3 $n4 orient right-up
  171. $ns duplex-link-op $n3 $n5 orient right-down
  172. #add manually
  173. set ping0 [new Agent/Ping]
  174. $ns attach-agent $n0 $ping0
  175.  
  176. set ping1 [new Agent/Ping]
  177. $ns attach-agent $n1 $ping1
  178.  
  179. set ping4 [new Agent/Ping]
  180. $ns attach-agent $n4 $ping4
  181.  
  182. set ping5 [new Agent/Ping]
  183. $ns attach-agent $n5 $ping5
  184.  
  185. $ns connect $ping0 $ping4
  186. $ns connect $ping1 $ping5
  187. proc sendPingPacket {} {
  188.         global ns ping0 ping1
  189.         set intervalTime 0.001
  190.         set now [$ns now]
  191.         $ns at [expr $now + $intervalTime] "$ping0 send"
  192.         $ns at [expr $now + $intervalTime] "$ping1 send"
  193.         $ns at [expr $now + $intervalTime] "sendPingPacket"
  194. }
  195. #rtt=round trip time(packet travel from src to dest and back to src)
  196. Agent/Ping instproc recv {from rtt} {
  197.         global seq
  198.         $self instvar node_
  199.         puts "The node [$node_ id] received an ACK from the node $from with RTT $rtt ms"
  200. }
  201. $ping0 set class_ 1
  202. $ping1 set class_ 2
  203. $ping4 set class_ 3
  204. $ping5 set class_ 4
  205. #end
  206. #Define a 'finish' procedure
  207. proc finish {} {
  208.     global ns tracefile namfile
  209.     $ns flush-trace
  210.     close $tracefile
  211.     close $namfile
  212.     exec nam out.nam &
  213.     exit 0
  214. }
  215. #add manually
  216. $ns at 0.01 "sendPingPacket"
  217. $ns at 10.0 "finish"
  218. $ns run
  219. ------------------------------------------------------------------------------------------------------------------------------------
  220. IPSPOOFING
  221. if config
  222. nc -lnvp portnumber to open a port
  223. l-listen
  224. n- skip DNS lookup
  225. v- verbose
  226. p-port number
  227. Sudo nmap -sS -Pn -D ip address spoofed ipaddress
  228. -sS stealth scan
  229. -Pn  skip host discovery
  230. -D decoy scan <ip>
  231. -------------------------------------------------------------------------------------------------------------------------------------
  232. DOS ATTACK
  233. nc lnvp [port-number]
  234. sudo hping3 -S --flood -V -p 3333 192.168.19.6
  235.  
  236. where
  237.     -S: specifies SYN packets.
  238. • –flood: replies will be ignored and packets will be sent as fast as possible.
  239. • -V: Verbosity.
  240. -p <portnumber>: port number
  241. filter in wireshark
  242. ip.addr == <ip address of attacking machine> && tcp.flags.syn
  243.  
  244.  
  245. -------------------------------------------------------------------------------------------------------------------------------------
  246. set val(stop) 10.0;
  247.  
  248. set ns [new Simulator]
  249.  
  250. set nf [open out.nam w]
  251. $ns namtrace-all $nf
  252.  
  253. set nt [open out.tr w]
  254. $ns trace-all $nt
  255.  
  256. proc finish {} {
  257.  global ns nt nf
  258.  $ns flush-trace
  259.  close $nt
  260.  close $nf
  261.  exec nam out.nam &
  262.  exec awk -f out.awk out.tr &
  263.  exit 0
  264. }
  265.  
  266. set n0 [$ns node]
  267. set n1 [$ns node]
  268. set n2 [$ns node]
  269. set n3 [$ns node]
  270. set n4 [$ns node]
  271. set n5 [$ns node]
  272.  
  273.  
  274.  
  275.  
  276. $ns duplex-link $n0 $n2 1Mb 10ms DropTail
  277. $ns duplex-link $n1 $n2 0.4Mb 10ms DropTail
  278. $ns duplex-link $n2 $n3 4Kb 10ms DropTail
  279. $ns duplex-link $n3 $n4 1Mb 10ms DropTail
  280. $ns duplex-link $n3 $n5 1Mb 10ms DropTail
  281.  
  282.  
  283. $ns duplex-link-op $n0 $n2 orient right-down
  284. $ns duplex-link-op $n1 $n2 orient right-up
  285. $ns duplex-link-op $n2 $n3 orient right
  286. $ns duplex-link-op $n3 $n4 orient right-up
  287. $ns duplex-link-op $n3 $n5 orient right-down
  288.  
  289.  
  290. set ping0 [new Agent/Ping]
  291. $ns attach-agent $n0 $ping0
  292.  
  293. set ping1 [new Agent/Ping]
  294. $ns attach-agent $n1 $ping1
  295.  
  296. set ping4 [new Agent/Ping]
  297. $ns attach-agent $n4 $ping4
  298.  
  299. set ping5 [new Agent/Ping]
  300. $ns attach-agent $n5 $ping5
  301.  
  302. $ns connect $ping0 $ping4
  303. $ns connect $ping1 $ping5
  304.  
  305. proc sendPingPacket {} {
  306.  global ns ping0 ping1
  307.  set intervalTime 0.001
  308.  set now [$ns now]
  309.  $ns at [expr $now + $intervalTime] "$ping0 send"
  310.  $ns at [expr $now + $intervalTime] "$ping1 send"
  311.  $ns at [expr $now + $intervalTime] "sendPingPacket"
  312. }
  313.  
  314. Agent/Ping instproc recv {from rtt} {
  315.  global seq
  316.  $self instvar node_
  317.  puts "The node [$node_ id] received an ACK from the node
  318. $from with RTT $rtt ms"
  319.  
  320. }
  321.  
  322. $ns at 0.01 "sendPingPacket"
  323. $ns at 10.0 "finish"
  324. $ns run
  325.  
  326.  
  327.  
  328. throughput.awk
  329. BEGIN {
  330.     count=0;
  331. }
  332. {
  333.     event=$1;
  334.     if(event=="d")
  335.     {
  336.     count++;
  337.     }
  338. }
  339. END {
  340.     printf("No of packets dropped : %d\n",count);
  341. }
  342.  
  343. _---++++++-----------------------------------------------
  344.  
  345.  
  346.  active queue management (AQM) is the policy of dropping packets inside a buffer before that buffer becomes full, often with the goal of reducing network congestion or improving end-to-end latency. This task is performed by the network scheduler
  347. An emulator is a tool that replicates the actual hardware and software environment of a network device, allowing the protocol implementation to run on the actual device
  348. Dummynet is a network emulation tool that allows network engineers to test and
  349. analyze the behavior of various network protocols and applications in a controlled
  350. environment.
  351.  simulator is a tool that models the behavior of a protocol implementation and the network environment in which it operates. A simulator can be used to create a virtual network environment with multiple network nodes, each running a protocol implementation, and simulate the interactions between these nodes.
  352. a test bed is a physical or virtual network environment that is set up to test and evaluate the behavior of a protocol implementation. The purpose of a test bed is to provide an environment in which the protocol implementation can be tested and validated in a variety of real-world network scenarios and conditions.
  353.  SPIN PROTOCOL It transfers all the useful data only from each node to every node in the network assuming that all the nodes in the network are Base Station. SPIN node uses three types of messages for communication.
  354. 1.  ADV- It is used to advertise new data.
  355. 2.  REQ- REQ is used to receive the actual data.
  356. 3.  DATA- DATA is the actual message itself.
  357.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement