Advertisement
Atul_Kumar

CN LAB PART-B

Aug 4th, 2022 (edited)
590
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 10.46 KB | None | 0 0
  1. CN LAB
  2. PART-B
  3.  
  4. 1. Simulate a three nodes point – to – point network with duplex links between
  5. them.Set the queue size and vary the bandwidth and find the number of packets
  6. dropped.
  7.  
  8. set ns [new Simulator]
  9.  
  10. set tf [open out.tr w]
  11. $ns trace-all $tf
  12. set nf [open out.nam w]
  13. $ns namtrace-all $nf
  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 300ms DropTail
  21. $ns duplex-link $n1 $n2 10Mb 300ms DropTail
  22. $ns duplex-link $n2 $n3 1Mb 300ms DropTail
  23.  
  24. $ns queue-limit $n0 $n2 10
  25. $ns queue-limit $n1 $n2 10
  26. $ns queue-limit $n2 $n3 10
  27.  
  28. set udp0 [new Agent/UDP]
  29. set udp1 [new Agent/UDP]
  30. set null3 [new Agent/Null]
  31. $ns attach-agent $n0 $udp0
  32. $ns attach-agent $n1 $udp1
  33. $ns attach-agent $n3 $null3
  34.  
  35. set cbr0 [new Application/Traffic/CBR]
  36. set cbr1 [new Application/Traffic/CBR]
  37. $cbr0 attach-agent $udp0
  38. $cbr1 attach-agent $udp1
  39.  
  40. $ns connect $udp0 $null3
  41. $ns connect $udp1 $null3
  42.  
  43. $cbr0 set packetSize_ 500Mb
  44. $cbr1 set packetSize_ 500Mb
  45. $cbr0 set interval_ 0.005
  46. $cbr1 set interval_ 0.005
  47.  
  48. proc finish {} {
  49. global ns nf tf
  50. $ns flush-trace
  51. exec nam out.nam &
  52. close $tf
  53. close $nf
  54. set count 0
  55. set tf [open out.tr r]
  56. while {[gets $tf line] != -1} {
  57.  
  58. if { [string match "d*" $line] } {
  59. set count [expr $count + 1]
  60. }
  61. }
  62. puts "Number of packets dropped: $count"
  63. exit 0
  64. }
  65.  
  66. $ns at 0.01 "$cbr0 start"
  67. $ns at 0.01 "$cbr1 start"
  68. $ns at 5.0 "finish"
  69. $ns run
  70. ############# output #############
  71. # Number of packets dropped: 700
  72.  
  73. ---------------------------------------------------------------------------------------------------
  74. 2. Simulate the different types of Internet traffic such as FTP and TELNET over
  75. a network and analyze the throughput.
  76.  
  77. set ns [new Simulator]
  78.  
  79. set tf [open out.tr w]
  80. $ns trace-all $tf
  81. set nf [open out.nam w]
  82. $ns namtrace-all $nf
  83.  
  84. set n0 [$ns node]
  85. set n1 [$ns node]
  86. set n2 [$ns node]
  87. set n3 [$ns node]
  88.  
  89. $ns duplex-link $n0 $n2 2Mb 1ms DropTail
  90. $ns duplex-link $n1 $n2 2Mb 1ms DropTail
  91. $ns duplex-link $n2 $n3 2Mb 1ms DropTail
  92.  
  93. set tcp0 [new Agent/TCP]
  94. set tcp1 [new Agent/TCP]
  95. $ns attach-agent $n0 $tcp0
  96. $ns attach-agent $n1 $tcp1
  97.  
  98. set TCPS0 [new Agent/TCPSink]
  99. set TCPS1 [new Agent/TCPSink]
  100. $ns attach-agent $n3 $TCPS0
  101. $ns attach-agent $n3 $TCPS1
  102.  
  103. set ftp0 [new Application/FTP]
  104. $ftp0 attach-agent $tcp0
  105.  
  106. set tel1 [new Application/Telnet]
  107. $tel1 attach-agent $tcp1
  108. $tel1 set packetSize_ 500Mb
  109. $tel1 set interval_ 0.001
  110.  
  111. $ns connect $tcp0 $TCPS0
  112. $ns connect $tcp1 $TCPS1
  113. proc finish { } {
  114. global ns nf tf
  115. $ns flush-trace
  116. exec nam out.nam &
  117. close $tf
  118. close $nf
  119.  
  120. set time 2
  121. set fCount 0
  122. set tCount 0
  123. set tf [open out.tr r]
  124. while {[gets $tf line] != -1} {
  125. if { [string match "*tcp*0.0*3.0*" $line] } {
  126. set fCount [expr $fCount + 1]
  127. }
  128. if { [string match "*tcp*1.0*3.1*" $line] } {
  129. set tCount [expr $tCount + 1]
  130. }
  131. }
  132. puts "Throughput of FTP: [expr $fCount/$time]"
  133. puts "Throughput of TELNET: [expr $tCount/$time]"
  134. exit 0
  135. }
  136.  
  137. $ns at 0.01 "$ftp0 start"
  138. $ns at 0.01 "$tel1 start"
  139. $ns at 2.01 "finish"
  140. $ns run
  141. ############### output #################
  142. # No of FTP packets: 767
  143. # No of TELNET packets: 750
  144.  
  145.  
  146. -------------------------------------------------------------------------------------------------------------
  147.  3. Simulate an Ethernet LAN using n nodes (6-10), change error rate and data
  148. rate and compare the throughput.
  149.  
  150. set ns [new Simulator]
  151.  
  152. set tf [open out.tr w]
  153. set nf [open out.nam w]
  154. $ns trace-all $tf
  155. $ns namtrace-all $nf
  156.  
  157. puts "Enter error rate (<1) : "
  158. gets stdin erate
  159. puts "Enter data rate (in Mbps) : "
  160. gets stdin drate
  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. set n6 [$ns node]
  169. # set label and color (OPTIONAL)
  170. $n1 label "udp/source"
  171. $n5 label "udp/null"
  172. $n0 color "blue"
  173. $n1 color "blue"
  174. $n2 color "blue"
  175. $n3 color "blue"
  176. $n4 color "red"
  177. $n5 color "red"
  178. $n6 color "red"
  179.  
  180. $ns make-lan "$n0 $n1 $n2 $n3" 10Mb 10ms LL Queue/DropTail Mac/802_3
  181. $ns make-lan "$n4 $n5 $n6" 10Mb 10ms LL Queue/DropTail Mac/802_3
  182.  
  183. $ns duplex-link $n3 $n6 10Mb 10ms DropTail
  184.  
  185. set udp1 [new Agent/UDP]
  186. set null5 [new Agent/Null]
  187. $ns attach-agent $n1 $udp1
  188. $ns attach-agent $n5 $null5
  189.  
  190. set cbr1 [new Application/Traffic/CBR]
  191. $cbr1 attach-agent $udp1
  192.  
  193. $ns connect $udp1 $null5
  194.  
  195. set err [new ErrorModel]
  196. $ns lossmodel $err $n3 $n6
  197. $err set rate_ $erate
  198.  
  199. $cbr1 set packetSize_ $drate.Mb
  200. $cbr1 set interval_ 0.001
  201.  
  202. proc finish { } {
  203. global ns nf tf
  204. $ns flush-trace
  205. exec nam out.nam &
  206. close $nf
  207. close $tf
  208. set count 0
  209. set tr [open out.tr r]
  210. while {[gets $tr line] != -1} {
  211. if {[string match "* 8 5 *" $line]} {
  212. set count [expr $count+1]
  213. }
  214. }
  215. set thr [expr $count/5]
  216. puts "Throughput : $thr"
  217. exit 0
  218. }
  219. $ns at 0.1 "$cbr1 start"
  220. $ns at 5.1 "finish"
  221. $ns run
  222.  
  223.  
  224. -------------------------------------------------------------------------------------------------------------------
  225. 4. Simulate an Ethernet LAN using n nodes and set multiple traffic nodes and
  226. determine the collision across different nodes.
  227.  
  228. set ns [new Simulator]
  229.  
  230. set tf [open out.tr w]
  231. set nf [open out.nam w]
  232. $ns trace-all $tf
  233. $ns namtrace-all $nf
  234.  
  235. set n0 [$ns node]
  236. set n1 [$ns node]
  237. set n2 [$ns node]
  238. set n3 [$ns node]
  239.  
  240. $ns make-lan -trace on "$n0 $n1 $n2 $n3" 100Mb 10ms LL Queue/DropTail Mac/802_3
  241.  
  242. set tcp0 [new Agent/TCP]
  243. set tcp1 [new Agent/TCP]
  244. set udp2 [new Agent/UDP]
  245. set null1 [new Agent/Null]
  246. set sink2 [new Agent/TCPSink]
  247. set sink3 [new Agent/TCPSink]
  248.  
  249. $ns attach-agent $n0 $tcp0
  250. $ns attach-agent $n1 $tcp1
  251. $ns attach-agent $n2 $udp2
  252. $ns attach-agent $n1 $null1
  253. $ns attach-agent $n2 $sink2
  254. $ns attach-agent $n3 $sink3
  255.  
  256. set ftp0 [new Application/FTP]
  257. set ftp1 [new Application/FTP]
  258. set cbr2 [new Application/Traffic/CBR]
  259. $ftp0 attach-agent $tcp0
  260. $ftp1 attach-agent $tcp1
  261. $cbr2 attach-agent $udp2
  262.  
  263. $ns connect $tcp0 $sink2
  264. $ns connect $udp2 $null1
  265. $ns connect $tcp1 $sink3
  266.  
  267. $ftp0 set interval_ 0.001
  268. $ftp1 set interval_ 0.001
  269. $cbr2 set interval_ 0.01
  270.  
  271. proc finish {} {
  272. global ns nf tf
  273. $ns flush-trace
  274. exec nam out.nam &
  275. close $tf
  276. close $nf
  277. set count 0
  278. set tr [open out.tr r]
  279. while {[gets $tr line] !=-1 } {
  280. if { [string match "c*" $line] } {
  281. set count [expr $count + 1]
  282. }
  283. }
  284. puts "No of packets collided: $count"
  285. exit 0
  286. }
  287.  
  288. $ns at 0.1 "$cbr2 start"
  289. $ns at 0.1 "$ftp0 start"
  290. $ns at 0.1 "$ftp1 start"
  291. $ns at 5.0 "finish"
  292. $ns run
  293. ############ output ############
  294. # No of packets collided: 242
  295.  
  296.  
  297. --------------------------------------------------------------------------------------------------------
  298. 5. Simulate the transmission of ping messages over a network topology
  299. consisting of 6 nodes and find the number of packets dropped due to congestion.
  300.  
  301. set ns [new Simulator]
  302.  
  303. set tf [open out.tr w]
  304. set nf [open out.nam w]
  305. $ns trace-all $tf
  306. $ns namtrace-all $nf
  307.  
  308. set n0 [$ns node]
  309. set n1 [$ns node]
  310. set n2 [$ns node]
  311. set n3 [$ns node]
  312. set n4 [$ns node]
  313. set n5 [$ns node]
  314. set n6 [$ns node]
  315.  
  316. $ns duplex-link $n0 $n2 100Mb 300ms DropTail
  317. $ns duplex-link $n5 $n2 100Mb 300ms DropTail
  318. $ns duplex-link $n1 $n2 100Mb 300ms DropTail
  319. $ns duplex-link $n3 $n2 100Mb 300ms DropTail
  320. $ns duplex-link $n2 $n4 100Mb 300ms DropTail
  321. $ns duplex-link $n2 $n6 100Mb 300ms DropTail
  322.  
  323. set ping0 [new Agent/Ping]
  324. set ping4 [new Agent/Ping]
  325. set ping5 [new Agent/Ping]
  326. set ping6 [new Agent/Ping]
  327.  
  328. $ns attach-agent $n0 $ping0
  329. $ns attach-agent $n4 $ping4
  330. $ns attach-agent $n5 $ping5
  331. $ns attach-agent $n6 $ping6
  332.  
  333. $ns connect $ping0 $ping4
  334. $ns connect $ping5 $ping6
  335.  
  336. Agent/Ping instproc recv {from rtt} {
  337. $self instvar node_
  338. puts "The node [$node_ id] recieved $from with round trip time $rtt"
  339. }
  340.  
  341. proc finish { } {
  342. global ns nf tf
  343. $ns flush-trace
  344. exec nam out.nam &
  345. close $nf
  346. close $tf
  347. set count 0
  348. set tr [open out.tr r]
  349. while {[gets $tr line]!=-1} {
  350. if {[string match "d*" $line]} {
  351. set count [expr $count + 1]
  352. }
  353. }
  354. puts "No. of packet dropped : $count"
  355. exit 0
  356. }
  357.  
  358. $ns rtmodel-at 1 down $n2 $n6
  359. $ns rtmodel-at 2 up $n2 $n6
  360.  
  361. for {set i 0.1} {$i<2} {set i [expr $i+0.1]} {
  362.  $ns at $i "$ping0 send"
  363.  $ns at $i "$ping5 send"
  364. }
  365. $ns at 5.0 "finish"
  366. $ns run
  367.  
  368.  
  369.  
  370. ----------------------------------------------------------------------------------------------------------
  371. 6. A Simple ESS with transmitting nodes in Wireless LAN
  372. 7. A simple ad-hoc network with transmitting nodes
  373.  
  374. set ns [new Simulator]
  375.  
  376. set tf [open out.tr w]
  377. $ns trace-all $tf
  378.  
  379. set nf [open out.nam w]
  380. $ns namtrace-all-wireless $nf 500 500
  381.  
  382. set topo [new Topography]
  383. $topo load_flatgrid 500 500
  384.  
  385. $ns node-config -adhocRouting DSDV \
  386. -llType LL \
  387. -macType Mac/802_11 \
  388. -ifqType Queue/DropTail \
  389. -ifqLen 50 \
  390. -phyType Phy/WirelessPhy \
  391. -channelType Channel/WirelessChannel \
  392. -propType Propagation/TwoRayGround \
  393. -antType Antenna/OmniAntenna \
  394. -topoInstance $topo \
  395. -agentTrace ON \
  396. -routerTrace ON \
  397. -macTrace OFF
  398. # Create a god object
  399. create-god 3
  400.  
  401.  
  402. set n0 [$ns node]
  403. set n1 [$ns node]
  404. set n2 [$ns node]
  405.  
  406. $n0 set X_ 10
  407. $n0 set Y_ 10
  408. $n0 set Z_ 0
  409. $n1 set X_ 100
  410. $n1 set Y_ 100
  411. $n1 set Z_ 0
  412. $n2 set X_ 400
  413. $n2 set Y_ 400
  414. $n2 set Z_ 0
  415.  
  416. $ns at 0.0 "$n0 setdest 10 10 15"
  417. $ns at 0.0 "$n1 setdest 100 100 15"
  418. $ns at 0.0 "$n2 setdest 400 400 15"
  419.  
  420. $ns at 50 "$n1 setdest 300 300 15"
  421. $ns at 100 "$n1 setdest 100 100 15"
  422.  
  423. set tcp0 [new Agent/TCP]
  424. set tcp1 [new Agent/TCP]
  425. $ns attach-agent $n0 $tcp0
  426. $ns attach-agent $n1 $tcp1
  427. set sink1 [new Agent/TCPSink]
  428. set sink2 [new Agent/TCPSink]
  429. $ns attach-agent $n1 $sink1
  430. $ns attach-agent $n2 $sink2
  431.  
  432. set ftp0 [new Application/FTP]
  433. set ftp1 [new Application/FTP]
  434. $ftp0 attach-agent $tcp0
  435. $ftp1 attach-agent $tcp1
  436.  
  437. $ns connect $tcp0 $sink1
  438. $ns connect $tcp1 $sink2
  439. proc finish { } {
  440.  global ns nf tf
  441.  $ns flush-trace
  442.  exec nam out.nam &
  443.  close $tf
  444.  set ctr1 0
  445.  set ctr2 0
  446.  set tf [open out.tr r]
  447.  
  448.  while {[gets $tf line] != -1} {
  449.  if {[string match "r*_1_*AGT*" $line]} {
  450.  set ctr1 [expr $ctr1 + 1]
  451.  }
  452.  if {[string match "r*_2_*AGT*" $line]} {
  453.  set ctr2 [expr $ctr2 + 1]
  454.  }
  455.  }
  456.  puts "\nThroughput from n0 to n1: $ctr1"
  457.  puts "Throughput from n1 to n2: $ctr2"
  458.  exit 0
  459. }
  460.  
  461. $ns at 1 "$ftp0 start"
  462. $ns at 1 "$ftp1 start"
  463. $ns at 150 "finish"
  464. $ns run
  465. ######################## output ###########################
  466. # num_nodes is set 3
  467. # INITIALIZE THE LIST xListHead
  468. # channel.cc:sendUp - Calc highestAntennaZ_ and distCST_
  469. # highestAntennaZ_ = 1.5, distCST_ = 550.0
  470. # SORTING LISTS ...DONE!
  471. #
  472. # Throughput from n0 to n1: 8438
  473. # Throughput from n1 to n2: 3000
  474. ###########################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement