· 6 years ago · Sep 17, 2019, 04:46 AM
1SIR M. VISVESVARAYA INSTITUTE OF TECHNOLOGY
2(Affiliated to VTU & recognized by AICTE, New Delhi)
3ACCREDATED BY NBA
4
5
6Department of Computer Science and Engineering
7COMPUTER NETWORKS LABORATORY
8
915CSL57
105th SEMESTER
11
12
13Complied by: Mrs. Nethravathi S Prepared by: Mrs. Ajina A
14
15
16
17Under the Guidance of HOD
18Prof. Dilip K Sen
19
20
21COMPUTER NETWORK LABORATORY
22[As per Choice Based Credit System (CBCS) scheme]
23(Effective from the academic year 2016 -2017)
24SEMESTER – V
25
26
27Subject Code: 15CSL57 IA Marks: 20
28Number of Lecture Hours/Week: 01I + 02P Exam Marks: 80
29Total Number of Lecture Hours: 40 Exam Hours: 03
30
31
32CREDITS 02
33
34Course objectives: This course will enable students to
35•Demonstrate operation of network and its management commands.
36•Simulate and demonstrate the performance of GSM and CDMA.
37•Implement data link layer and transport layer protocols.
38
39Description (If any):
40For the experiments below modify the topology and parameters set for the experiment and take multiple rounds of reading and analyze the results available in log files. Plot necessary graphs and conclude. Use NS2/NS3.
41
42Lab Experiments:
43PART A
44
451. Implement three nodes point – to – point network with duplex links between them. Set the queue size, vary the bandwidth and find the number of packets dropped.
46
472. Implement transmission of ping messages/trace route over a network topology consisting of 6 nodes and find the number of packets dropped due to congestion.
48
493. Implement an Ethernet LAN using n nodes and set multiple traffic nodes and plot congestion window for different source / destination.
50
514. Implement simple ESS and with transmitting nodes in wire-less LAN by simulation and determine the performance with respect to transmission of packets.
52
535. Implement and study the performance of GSM on NS2/NS3 (Using MAC layer) or equivalent environment.
54
556. Implement and study the performance of CDMA on NS2/NS3 (Using stack called Call net) or equivalent environment.
56
57
58PART B
59Implement the following in Java:
60
617. Write a program for error detecting code using CRC-CCITT (16- bits).
62
638. Write a program to find the shortest path between vertices using bellman-ford algorithm.
64
659. Using TCP/IP sockets, write a client – server program to make the client send the file name and to make the server send back the contents of the requested file if present.
66
6710. Write a program on datagram socket for client/server to display the messages on client side, typed at the server side.
68
6911. Write a program for simple RSA algorithm to encrypt and decrypt the data.
70
7112. Write a program for congestion control using leaky bucket algorithm.
72
73Study Experiment / Project: NIL
74
75Course outcomes: The students should be able to:
76•Analyze and Compare various networking protocols.
77
78•Demonstrate the working of different concepts of networking.
79
80•Implement, analyze and evaluate networking protocols in NS2 / NS3
81
82Conduction of Practical Examination:
831. All laboratory experiments are to be included for practical examination.
84
852. Students are allowed to pick one experiment from part A and part B with lot.
86
873. Strictly follow the instructions as printed on the cover page of answer script
88
894. Marks distribution: Procedure + Conduction + Viva: 80
90 Part A: 10+25+5 =40
91 Part B: 10+25+5 =40
92
935. Change of experiment is allowed only once and marks allotted to the procedure part to be made zero.
94
95Introduction to Network Simulators
96
97Network simulators implemented in software are valuable tools for researchers to develop, test, and diagnose network protocols. Simulation is economical because it can carry out experiments without the actual hardware. It is flexible because it can, for example, simulate a link with any bandwidth and propagation delay. Simulation results are easier to analyze than experimental results because important information at critical points can be easily logged to help researchers diagnose network protocols.
98Network simulators, however, have their limitations. A complete network simulator needs to simulate networking devices (e.g., hosts and routers) and application programs that generate network traffic. It also needs to provide network utility programs to configure, monitor, and gather statistics about a simulated network. Therefore, developing a complete network simulator is a large effort. Due to limited development resources, traditional network simulators usually have the following drawbacks:
99• Simulation results are not as convincing as those produced by real hardware and software equipment. In order to constrain their complexity and development cost, most network simulators usually can only simulate real-life network protocol implementations with limited details, and this may lead to incorrect results.
100• These simulators are not extensible in the sense that they lack the standard UNIX POSIX application programming interface (API). As such, existing or to-be-developed real-life application programs cannot run normally to generate traffic for a simulated network.
101Instead, they must be rewritten to use the internal API provided by the simulator (if there is any) and be compiled with the simulator to form a single, big, and complex program.
102To overcome these problems, Wang invented a kernel re-entering simulation methodology and used it to implement the Harvard network simulator. Later on, Wang further improved the methodology and used it to design and implement the NCTUns network simulator and emulator.
103Different types of simulators
104Some of the different types of simulators are as follows:-
105• MIT's NETSIM
106• NIST
107• CPSIM
108• INSANE
109• NEST
110• REAL
111• NS
112• OPNET
113• NCTUns
114• P
115• GNS3
116• WireShark
117
118PART – A
1191. Implement three nodes point – to – point network with duplex links between them. Set the queue size, vary the bandwidth and find the number of packets dropped.
120
121Source Code :
122pa1.tcl
123
124set ns [new Simulator]
125
126set nf [open pa1.nam w]
127$ns namtrace-all $nf
128
129set tf [open pa1.tr w]
130$ns trace-all $tf
131
132proc finish {} {
133global ns nf tf
134$ns flush-trace
135close $nf
136close $tf
137exec nam pa1.nam &
138exit 0
139}
140set n0 [$ns node]
141set n1 [$ns node]
142set n2 [$ns node]
143set n3 [$ns node]
144
145#$ns color 1 "red"
146#$ns color 2 "blue"
147
148$ns duplex-link $n0 $n2 20Mb 10ms DropTail
149$ns duplex-link $n1 $n2 50Mb 5ms DropTail
150$ns duplex-link $n2 $n3 10Mb 1000ms DropTail
151
152#$ns duplex-link $n0 $n2 color "green"
153
154$ns queue-limit $n0 $n2 10
155$ns queue-limit $n1 $n2 10
156
157set udp0 [new Agent/UDP]
158$ns attach-agent $n0 $udp0
159
160set cbr0 [new Application/Traffic/CBR]
161$cbr0 set packetSize_ 500
162$cbr0 set interval_ 0.005
163$cbr0 attach-agent $udp0
164
165set udp1 [new Agent/UDP]
166$ns attach-agent $n1 $udp1
167
168set cbr1 [new Application/Traffic/CBR]
169$cbr1 attach-agent $udp1
170
171set udp2 [new Agent/UDP]
172$ns attach-agent $n2 $udp2
173
174set cbr2 [new Application/Traffic/CBR]
175$cbr2 attach-agent $udp2
176
177set null0 [new Agent/Null]
178$ns attach-agent $n3 $null0
179
180$ns connect $udp0 $null0
181$ns connect $udp1 $null0
182
183$ns at 0.1 "$cbr0 start"
184$ns at 0.2 "$cbr1 start"
185$ns at 1.0 "finish"
186
187$ns run
188Source Code :
189pa1.awk
190
191BEGIN {
192c=0;
193}
194{
195if ($1=="d")
196{
197c++;
198printf("%s\t%s\n",$5,$11);
199}
200}
201END{
202printf("The number of packet dropped= %d\n",c);
203}
204
205
206
207
208
2092. Implement transmission of ping messages/trace route over a network topology consisting of 6 nodes and find the number of packets dropped due to congestion.
210
211Source Code:
212
213pa2.tcl
214
215set ns [ new Simulator ]
216set nf [ open pa2.nam w ]
217$ns namtrace-all $nf
218set tf [ open pa2.tr w ]
219$ns trace-all $tf
220set n0 [$ns node]
221set n1 [$ns node]
222set n2 [$ns node]
223set n3 [$ns node]
224set n4 [$ns node]
225set n5 [$ns node]
226$n4 shape box
227$ns duplex-link $n0 $n4 1005Mb 1ms DropTail
228$ns duplex-link $n1 $n4 50Mb 1ms DropTail
229$ns duplex-link $n2 $n4 2000Mb 1ms DropTail
230$ns duplex-link $n3 $n4 200Mb 1ms DropTail
231$ns duplex-link $n4 $n5 1Mb 1ms DropTail
232
233set p1 [new Agent/Ping]
234$ns attach-agent $n0 $p1
235$p1 set packetSize_ 500000
236$p1 set interval_ 0.0001
237set p2 [new Agent/Ping]
238$ns attach-agent $n1 $p2
239set p3 [new Agent/Ping]
240$ns attach-agent $n2 $p3
241$p3 set packetSize_ 30000
242$p3 set interval_ 0.00001
243set p4 [new Agent/Ping]
244$ns attach-agent $n3 $p4
245set p5 [new Agent/Ping]
246$ns attach-agent $n5 $p5
247$ns queue-limit $n0 $n4 5
248$ns queue-limit $n2 $n4 3
249$ns queue-limit $n4 $n5 2
250Agent/Ping instproc recv {from rtt} {
251$self instvar node_
252puts "node [$node_ id] received answer from $from with round trip time $rtt msec"
253}
254$ns connect $p1 $p5
255$ns connect $p3 $p4
256proc finish { } {
257global ns nf tf
258$ns flush-trace
259close $nf
260close $tf
261exec nam pa2.nam &
262exit 0
263}
264$ns at 0.1 "$p1 send"
265$ns at 0.2 "$p1 send"
266$ns at 0.3 "$p1 send"
267$ns at 0.4 "$p1 send"
268$ns at 0.5 "$p1 send"
269$ns at 0.6 "$p1 send"
270$ns at 0.7 "$p1 send"
271$ns at 0.8 "$p1 send"
272$ns at 0.9 "$p1 send"
273$ns at 1.0 "$p1 send"
274$ns at 1.1 "$p1 send"
275$ns at 1.2 "$p1 send"
276$ns at 1.3 "$p1 send"
277$ns at 1.4 "$p1 send"
278$ns at 1.5 "$p1 send"
279$ns at 1.6 "$p1 send"
280$ns at 1.7 "$p1 send"
281$ns at 1.8 "$p1 send"
282$ns at 1.9 "$p1 send"
283$ns at 2.0 "$p1 send"
284$ns at 2.1 "$p1 send"
285$ns at 2.2 "$p1 send"
286$ns at 2.3 "$p1 send"
287$ns at 2.4 "$p1 send"
288$ns at 2.5 "$p1 send"
289$ns at 2.6 "$p1 send"
290$ns at 2.7 "$p1 send"
291$ns at 2.8 "$p1 send"
292$ns at 2.9 "$p1 send"
293$ns at 0.1 "$p3 send"
294$ns at 0.2 "$p3 send"
295$ns at 0.3 "$p3 send"
296$ns at 0.4 "$p3 send"
297$ns at 0.5 "$p3 send"
298$ns at 0.6 "$p3 send"
299$ns at 0.7 "$p3 send"
300$ns at 0.8 "$p3 send"
301$ns at 0.9 "$p3 send"
302$ns at 1.0 "$p3 send"
303$ns at 1.1 "$p3 send"
304$ns at 1.2 "$p3 send"
305$ns at 1.3 "$p3 send"
306$ns at 1.4 "$p3 send"
307$ns at 1.5 "$p3 send"
308$ns at 1.6 "$p3 send"
309$ns at 1.7 "$p3 send"
310$ns at 1.8 "$p3 send"
311$ns at 1.9 "$p3 send"
312$ns at 2.0 "$p3 send"
313$ns at 2.1 "$p3 send"
314$ns at 2.2 "$p3 send"
315$ns at 2.3 "$p3 send"
316$ns at 2.4 "$p3 send"
317$ns at 2.5 "$p3 send"
318$ns at 2.6 "$p3 send"
319$ns at 2.7 "$p3 send"
320$ns at 2.8 "$p3 send"
321$ns at 2.9 "$p3 send"
322$ns at 3.0 "finish"
323$ns run
324
325Source Code :
326pa2.awk
327BEGIN{
328drop=0;
329}
330{
331if($1=="d")
332{
333drop++;
334}
335}
336END{
337printf("Total number of %s packets dropped due to congestion=%d\n",$5,drop);
338}
339
340
341
342
343
3443. Implement an Ethernet LAN using n nodes and set multiple traffic nodes and plot congestion window for different source / destination.
345
346Source Code:
347
348pa3.tcl
349
350set ns [new Simulator]
351set tf [open pa3.tr w]
352$ns trace-all $tf
353set nf [open pa3.nam w]
354$ns namtrace-all $nf
355
356set n0 [$ns node]
357$n0 color "magenta"
358$n0 label "src1"
359set n1 [$ns node]
360set n2 [$ns node]
361$n2 color "magenta"
362$n2 label "src2"
363set n3 [$ns node]
364$n3 color "blue"
365$n3 label "dest2"
366set n4 [$ns node]
367set n5 [$ns node]
368$n5 color "blue"
369$n5 label "dest1"
370
371$ns make-lan "$n0 $n1 $n2 $n3 $n4" 100Mb 100ms LL Queue/DropTail Mac/802_3
372$ns duplex-link $n4 $n5 1Mb 1ms DropTail
373
374set tcp0 [new Agent/TCP]
375$ns attach-agent $n0 $tcp0
376set ftp0 [new Application/FTP]
377$ftp0 attach-agent $tcp0
378$ftp0 set packetSize_ 500
379$ftp0 set interval_ 0.0001
380set sink5 [new Agent/TCPSink]
381$ns attach-agent $n5 $sink5
382
383$ns connect $tcp0 $sink5
384
385set tcp2 [new Agent/TCP]
386$ns attach-agent $n2 $tcp2
387set ftp2 [new Application/FTP]
388$ftp2 attach-agent $tcp2
389$ftp2 set packetSize_ 600
390$ftp2 set interval_ 0.0001
391set sink3 [new Agent/TCPSink]
392$ns attach-agent $n3 $sink3
393
394$ns connect $tcp2 $sink3
395
396set file1 [open file1.tr w]
397$tcp0 attach $file1
398set file2 [open file2.tr w]
399$tcp2 attach $file2
400
401$tcp0 trace cwnd_
402$tcp2 trace cwnd_
403
404proc finish { } {
405global ns nf tf
406$ns flush-trace
407close $tf
408close $nf
409exec nam pa3.nam &
410exit 0
411}
412$ns at 0.1 "$ftp0 start"
413$ns at 5 "$ftp0 stop"
414$ns at 7 "$ftp0 start"
415$ns at 0.2 "$ftp2 start"
416$ns at 8 "$ftp2 stop"
417$ns at 14 "$ftp0 stop"
418$ns at 10 "$ftp2 start"
419$ns at 15 "$ftp2 stop"
420$ns at 16 "finish"
421$ns run
422
423Source Code:
424pa3.awk
425BEGIN {
426}
427{
428if($6=="cwnd_")
429printf("%f\t%f\t\n",$1,$7);
430}
431END{
432}
433
434
435
436
4374. Implement simple ESS and with transmitting nodes in wire-less LAN by simulation and determine the performance with respect to transmission of packets.
438
439Source Code:
440pa4.tcl
441
442set ns [new Simulator]
443set tf [open pa4.tr w]
444$ns trace-all $tf
445set topo [new Topography]
446$topo load_flatgrid 1000 1000
447set nf [open pa4.nam w]
448$ns namtrace-all-wireless $nf 1000 1000
449$ns node-config -adhocRouting DSDV \
450 -llType LL \
451 -macType Mac/802_11 \
452 -ifqType Queue/DropTail \
453 -ifqLen 50 \
454 -phyType Phy/WirelessPhy \
455 -channelType Channel/WirelessChannel \
456 -propType Propagation/TwoRayGround \
457 -antType Antenna/OmniAntenna \
458 -topoInstance $topo \
459 -agentTrace ON \
460 -routerTrace ON
461create-god 3
462set n0 [$ns node]
463set n1 [$ns node]
464set n2 [$ns node]
465
466$n0 label "tcp0"
467$n1 label "sink1/tcp1"
468$n2 label "sink2"
469
470$n0 set X_ 50
471$n0 set Y_ 50
472$n0 set Z_ 0
473$n1 set X_ 100
474$n1 set Y_ 100
475$n1 set Z_ 0
476$n2 set X_ 600
477$n2 set Y_ 600
478$n2 set Z_ 0
479
480$ns at 0.1 "$n0 setdest 50 50 15"
481$ns at 0.1 "$n1 setdest 100 100 25"
482$ns at 0.1 "$n2 setdest 600 600 25"
483
484set tcp0 [new Agent/TCP]
485$ns attach-agent $n0 $tcp0
486
487set ftp0 [new Application/FTP]
488$ftp0 attach-agent $tcp0
489
490set sink1 [new Agent/TCPSink]
491$ns attach-agent $n1 $sink1
492$ns connect $tcp0 $sink1
493
494set tcp1 [new Agent/TCP]
495$ns attach-agent $n1 $tcp1
496
497set ftp1 [new Application/FTP]
498$ftp1 attach-agent $tcp1
499
500set sink2 [new Agent/TCPSink]
501$ns attach-agent $n2 $sink2
502
503$ns connect $tcp1 $sink2
504$ns at 5 "$ftp0 start"
505$ns at 5 "$ftp1 start"
506$ns at 100 "$n1 setdest 550 550 15"
507$ns at 190 "$n1 setdest 70 70 15"
508proc finish { } {
509global ns nf tf
510$ns flush-trace
511exec nam pa4.nam &
512close $tf
513exit 0
514}
515$ns at 250 "finish"
516$ns run
517
518Source Code:
519
520pa4.awk
521
522BEGIN{
523count1=0
524count2=0
525pack1=0
526pack2=0
527time1=0
528time2=0
529}
530{
531if($1=="r"&&$3=="_1_"&&$4=="AGT")
532{
533count1++
534pack1=pack1+$8
535time1=$2
536}
537if($1=="r"&&$3=="_2_"&&$4=="AGT")
538{
539count2++
540pack2=pack2+$8
541time2=$2
542}
543}
544END{
545printf("The Throughput from n0 to n1:%f Mbps \n",((count1*pack1*8)/(time1*1000000)));
546printf("The Throughput from n1 to n2: %f Mbps",((count2*pack2*8)/(time2*1000000)));
547}
548
549
550
551
552
553
554
555
5565. Implement and study the performance of GSM on NS2/NS3 (Using MAC layer) or equivalent environment.
557Source Code:
558pa5.tcl
559# General Parameters
560set stop 100 ;# Stop time.
561# Topology
562set type gsm ;#type of link:
563# AQM parameters
564set minth 30 ;
565set maxth 0 ;
566set adaptive 1 ;# 1 for Adaptive RED, 0 for plain RED
567# Traffic generation.
568set flows 0 ;# number of long-lived TCP flows
569set window 30 ;# window for long-lived traffic
570set web 2 ;# number of web sessions
571# Plotting statics.
572set opt(wrap) 100 ;# wrap plots?
573set opt(srcTrace) is ;# where to plot traffic
574set opt(dstTrace) bs2 ;# where to plot traffic
575
576#default downlink bandwidth in bps
577set bwDL(gsm) 9600
578#default uplink bandwidth in bps
579set bwUL(gsm) 9600
580#default downlink propagation delay in seconds
581set propDL(gsm) .500
582#default uplink propagation delay in seconds
583set propUL(gsm) .500
584
585set ns [new Simulator]
586set tf [open out.tr w]
587$ns trace-all $tf
588
589set nodes(is) [$ns node]
590set nodes(ms) [$ns node]
591set nodes(bs1) [$ns node]
592set nodes(bs2) [$ns node]
593set nodes(lp) [$ns node]
594
595proc cell_topo {} {
596 global ns nodes
597 $ns duplex-link $nodes(lp) $nodes(bs1) 3Mbps 10nodes(ms) DropTail
598 $ns duplex-link $nodes(bs1) $nodes(ms) 1 1 RED
599 $ns duplex-link $nodes(ms) $nodes(bs2) 1 1 RED
600 $ns duplex-link $nodes(bs2) $nodes(is) 3Mbps 50nodes(ms) DropTail
601 puts " GSM Cell Topology"
602}
603proc set_link_para {t} {
604 global ns nodes bwUL bwDL propUL propDL buf
605 $ns bandwidth $nodes(bs1) $nodes(ms) $bwDL($t) duplex
606 $ns bandwidth $nodes(bs2) $nodes(ms) $bwDL($t) duplex
607 $ns delay $nodes(bs1) $nodes(ms) $propDL($t) duplex
608 $ns delay $nodes(bs2) $nodes(ms) $propDL($t) duplex
609 $ns queue-limit $nodes(bs1) $nodes(ms) 10
610 $ns queue-limit $nodes(bs2) $nodes(ms) 10
611}
612# RED and TCP parameters
613Queue/RED set adaptive_ $adaptive
614Queue/RED set thresh_ $minth
615Queue/RED set maxthresh_ $maxth
616Agent/TCP set window_ $window
617
618source web.tcl
619
620#Create topology
621switch $type {
622 gsm -
623 gprs -
624 umts {cell_topo}
625}
626 set_link_para $type
627 $ns insert-delayer $nodes(ms) $nodes(bs1) [new Delayer]
628 $ns insert-delayer $nodes(ms) $nodes(bs2) [new Delayer]
629
630# Set up forward TCP connection
631if {$flows == 0} {
632 set tcp1 [$ns create-connection TCP/Sack1 $nodes(is) TCPSink/Sack1 $nodes(lp) 0]
633 set ftp1 [[set tcp1] attach-app FTP]
634 $ns at 0.8 "[set ftp1] start"
635}
636if {$flows > 0} {
637 set tcp1 [$ns create-connection TCP/Sack1 $nodes(is) TCPSink/Sack1 $nodes(lp) 0]
638 set ftp1 [[set tcp1] attach-app FTP]
639 $tcp1 set window_ 100
640 $ns at 0.0 "[set ftp1] start"
641 $ns at 3.5 "[set ftp1] stop"
642 set tcp2 [$ns create-connection TCP/Sack1 $nodes(is) TCPSink/Sack1 $nodes(lp) 0]
643 set ftp2 [[set tcp2] attach-app FTP]
644 $tcp2 set window_ 3
645 $ns at 1.0 "[set ftp2] start"
646 $ns at 8.0 "[set ftp2] stop"
647}
648
649proc stop {} {
650 global nodes opt nf
651 set wrap $opt(wrap)
652 set sid [$nodes($opt(srcTrace)) id]
653 set did [$nodes($opt(dstTrace)) id]
654 set a "out.tr"
655 set GETRC "../../../bin/getrc"
656 set RAW2XG "../../../bin/raw2xg"
657 exec $GETRC -s $sid -d $did -f 0 out.tr | \
658 $RAW2XG -s 0.01 -m $wrap -r > plot.xgr
659 exec $GETRC -s $did -d $sid -f 0 out.tr | \
660 $RAW2XG -a -s 0.01 -m $wrap >> plot.xgr
661 exec xgraph -x time -y packets plot.xgr &
662 exit 0
663}
664$ns at $stop "stop"
665$ns run
666
667
668
669
6706. Implement and study the performance of CDMA on NS2/NS3 (Using stack called Call net) or equivalent environment.
671
672Source Code:
673
674pa6.tcl
675
676# General Parameters
677set stop 100 ;# Stop time.
678# Topology
679set type cdma ;#type of link:
680# AQM parameters
681set minth 30 ;
682set maxth 0 ;
683set adaptive 1 ;# 1 for Adaptive RED, 0 for plain RED
684# Traffic generation.
685set flows 0 ;# number of long-lived TCP flows
686set window 30 ;# window for long-lived traffic
687set web 2 ;# number of web sessions
688# Plotting statics.
689set opt(wrap) 100 ;# wrap plots?
690set opt(srcTrace) is ;# where to plot traffic
691set opt(dstTrace) bs2 ;# where to plot traffic
692#default downlink bandwidth in bps
693set bwDL(cdma) 384000
694#default uplink bandwidth in bps
695set bwUL(cdma) 64000
696#default downlink propagation delay in seconds
697set propDL(cdma) .150
698#default uplink propagation delay in seconds
699set propUL(cdma) .150
700set ns [new Simulator]
701set tf [open out.tr w]
702$ns trace-all $tf
703set nodes(is) [$ns node]
704set nodes(ms) [$ns node]
705set nodes(bs1) [$ns node]
706set nodes(bs2) [$ns node]
707set nodes(lp) [$ns node]
708proc cell_topo {} {
709 global ns nodes
710 $ns duplex-link $nodes(lp) $nodes(bs1) 3Mbps 10nodes(ms) DropTail
711 $ns duplex-link $nodes(bs1) $nodes(ms) 1 1 RED
712 $ns duplex-link $nodes(ms) $nodes(bs2) 1 1 RED
713 $ns duplex-link $nodes(bs2) $nodes(is) 3Mbps 50nodes(ms) DropTail
714 puts " cdma Cell Topology"
715}
716proc set_link_para {t} {
717 global ns nodes bwUL bwDL propUL propDL buf
718 $ns bandwidth $nodes(bs1) $nodes(ms) $bwDL($t) duplex
719 $ns bandwidth $nodes(bs2) $nodes(ms) $bwDL($t) duplex
720 $ns delay $nodes(bs1) $nodes(ms) $propDL($t) duplex
721 $ns delay $nodes(bs2) $nodes(ms) $propDL($t) duplex
722 $ns queue-limit $nodes(bs1) $nodes(ms) 20
723 $ns queue-limit $nodes(bs2) $nodes(ms) 20
724}
725# RED and TCP parameters
726Queue/RED set adaptive_ $adaptive
727Queue/RED set thresh_ $minth
728Queue/RED set maxthresh_ $maxth
729Agent/TCP set window_ $window
730source web.tcl
731#Create topology
732switch $type {
733cdma {cell_topo}
734}
735 set_link_para $type
736 $ns insert-delayer $nodes(ms) $nodes(bs1) [new Delayer]
737 $ns insert-delayer $nodes(ms) $nodes(bs2) [new Delayer]
738# Set up forward TCP connection
739if {$flows == 0} {
740 set tcp1 [$ns create-connection TCP/Sack1 $nodes(is) TCPSink/Sack1 $nodes(lp) 0]
741 set ftp1 [[set tcp1] attach-app FTP]
742 $ns at 0.8 "[set ftp1] start"
743}
744if {$flows > 0} {
745 set tcp1 [$ns create-connection TCP/Sack1 $nodes(is) TCPSink/Sack1 $nodes(lp) 0]
746 set ftp1 [[set tcp1] attach-app FTP]
747 $tcp1 set window_ 100
748 $ns at 0.0 "[set ftp1] start"
749 $ns at 3.5 "[set ftp1] stop"
750 set tcp2 [$ns create-connection TCP/Sack1 $nodes(is) TCPSink/Sack1 $nodes(lp) 0]
751 set ftp2 [[set tcp2] attach-app FTP]
752 $tcp2 set window_ 3
753 $ns at 1.0 "[set ftp2] start"
754 $ns at 8.0 "[set ftp2] stop"
755}
756proc stop {} {
757 global nodes opt nf
758 set wrap $opt(wrap)
759 set sid [$nodes($opt(srcTrace)) id]
760 set did [$nodes($opt(dstTrace)) id]
761 set a "out.tr"
762 set GETRC "../../../bin/getrc"
763 set RAW2XG "../../../bin/raw2xg"
764 exec $GETRC -s $sid -d $did -f 0 out.tr | \
765 $RAW2XG -s 0.01 -m $wrap -r > plot.xgr
766 exec $GETRC -s $did -d $sid -f 0 out.tr | \
767 $RAW2XG -a -s 0.01 -m $wrap >> plot.xgr
768 exec xgraph -x time -y packets plot.xgr &
769 exit 0
770}
771$ns at $stop "stop"
772$ns run
773
774
775
776
777PART - B
7787. Write a program for error detecting code using CRC-CCITT (16- bits).
779
780Cyclic Redundancy Check Code for Error – Detection
781The cyclic Redundancy Check (CRC) id a technique for detecting errors in data transmission, but not for correcting errors when they are detected.
782CCITT- Consultative Committee for International Telegraphy and Telephone.
783
784Algorithm:
785A) For Computing CRC:
786• The CRC Algorithm is based on polynomial arithmetic.
787• Let the message that we have to send has k bits (denoted by M(x) in polynomial form having degree (k-1)) the sender and the receiver are agreed upon a generator polynomial having r bits (denoted by G(x) in polynomial form having degree (r-1)). The generator polynomial is also called “Divisor”.
788• Now, append (r-1) zero bits to the LSB side of the message M(x) so it will now contain (k+r-1) bits and corresponds to the polynomial x(r-1) M (x).
789• Divide the polynomial x(r-1) M (x) by Divisor, using modulo-2 subtraction (bit by bit XOR operation). Add the remainder R(x) (called frame check sequence) to x(r-1) M (x), using modulo -2 additions (bit by bit XOR operation). This is the message that will be transmitted by the transmitter denoted by T(x).
790B) For Error Detection:
791• Suppose that a transmission error occurs, so that the received message at the receiver is T(x) +E(x), instead of T(x). Each 1 bit in E(x) corresponds to a bit that has been inverted.
792• The received message at the receiver end is divided by G(x), i.e. [T(x) + E(x) / G(x) ]. Since T(x)/G(x) is 0, so the result is simply E(x)/G(x).
793• If E(x)/G(x) =0 than there is no error in the received message, otherwise there is an error.
794• The following type of errors can be detected using CRC:
795 If G(x) has more than one bit and the coefficient of x0 is 1, then all single bit errors are detected.
796 If G(x) is not divisible by x ( the coefficient of x0 is 1) , and t is the least positive integer (0<t<n-1) such that G(x) divides x1 + 1, then all isolated double errors are detected.
797 If G(x) has a factor (x+1), then all odd numbered errors are detected.
798Source code:
799import java.io.*;
800class crc
801{
802public static void main(String[] args)
803{
804 InputStreamReader isr=new InputStreamReader (System.in);
805 BufferedReader br=new BufferedReader(isr);
806 int[] message;
807 int[] gen;
808 int[] app_message;
809 int[] rem;
810 int[] trans_message;
811 int message_bits,gen_bits,total_bits;
812 System.out.println("\n Enter the no of bits in the message");
813 message_bits=Integer.parseInt(br.readLine());
814 message=new int[message_bits];
815 System.out.println("\n Enter the message bits");
816 for(int i=o;i<message_bits;i++)
817 message[i]=Integer.parseInt(br.readLine());
818 System.out.println("\n Enter the no of bits generated ");
819 gen_bits=Integer.parseInt(br.readLine());
820 gen=new int[gen_bits];
821 System.out.println("\n Enter the generated bits");
822 for(int i=o;i<gen_bits;i++);
823 {
824 gen[i]=Integer.parseInt(br.readLine());
825 }
826 total_bits=message_bits+gen_bits-1;
827 app_message=new int[total_bits];
828 rem=new int[total_bits];
829 trans_message=new int[total_bits];
830 for(int i=0;i<message.length;i++)
831 {
832 app_message[i]=message[i];
833 }
834 System.out.print("\n Message bits :");
835 for(int i=o;i<message_bits;i++)
836 {
837 System.out.print(message[i]);
838 }
839 System.out.print("\n Generated bits :");
840 for(int i=0;i<gen_bits;i++)
841 {
842 System.out.print(gen[i]);
843 }
844 System.out.print("\n Appended message :");
845 for(int i=0;i<app_message.length;i++)
846 {
847 System.out.print(app_message[i]);
848 }
849 for(int j=0;j<app_message.length;j++)
850 {
851 rem[j]=app_message[j];
852 }
853 rem=computecrc(app_message.length;i++)
854 for(int i=0;i<app_message.length;i++)
855 {
856 trans_mesage[i]=(app_message[i]^rem[i]);
857 }
858 System.out.println("\n Transmitted message from the transmitter :");
859 for(int i=0;i<trans_message.length;i++)
860 {
861 System.out.print(trans_message[i]);
862 }
863 System.out.println("\n Message of"+total_bits+"bits received");
864 for(int i=0;i<trans_message.length;i++)
865 {
866 trans_messge[i]=Inter.parseInt(br.readLine());
867 }
868 System.out.println("\n Recevied message is :");
869 for(int i=0;i<trans_message.length;i++)
870 {
871 System.out.print(trans_message[i]);
872 }
873 for(int j=0;j<trans_message.length;j++)
874 {
875 rem[j]=trans_message[j];
876 }
877 rem=computercrc(trans_message,gen,rem);
878 for (int i=0;i<rem.length;i++)
879 {
880 if(rem[i]!=0)
881 {
882 System.out.println("\n There is error");
883 break;
884 }
885 if(i==rem.length-1)
886 {
887 System.out.println("\n There is no error");
888 }
889}
890
891static int[] computecrc(int app_message[],int gen[],int rem[])
892{
893 int current=0;
894 while(true)
895 {
896 for(int i=0;i<gen.length;i++)
897 {
898 rem[current+i]=(rem[current+i]^gen[i]);
899 }
900 while(rem[current]==0&¤t!=rem.length-1)
901 {
902 current++;
903 }
904 if(rem.length-current)<gen.length)
905 {
906 break;
907 }
908 }
909return rem;
910}
911}
912}
913Enter the no of bits in the message : 4
914Enter the message bits : 1 0 0 1
915Enter the no of bits generated : 17
916Enter the generated bits :
9171 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 1
918Message bits: 1 0 0 1
919Generated bits : 1 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 1
920Appended message : 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
921Transmitted message from transmitter : 1 0 0 1 1 0 0 1 0 0 0 1 0 0 1 0 1 0 0 1
922Message of 20 bits received :
9231 0 0 1 1 0 0 1 0 0 0 1 0 0 1 0 1 0 0 1
924There is no error
925
926
927Enter the no of bits in the message : 4
928Enter the message bits : 1 0 0 1
929Enter the no of bits generated : 17
930Enter the generated bits :
9311 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 1
932Message bits: 1 0 0 1
933Generated bits : 1 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 1
934Appended message : 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
935Transmitted message from transmitter : 1 0 0 1 1 0 0 1 0 0 0 1 0 0 0 1 0 1 0 0 1
936Message of 20 bits received :
9371 0 0 1 1 0 0 1 0 1 0 1 0 0 1 0 1 0 1 0
938There is an error
939
9408. Write a program to find the shortest path between vertices using bellman-ford algorithm.
941
942Bell man ford algorithm is a procedure used to find all shortest path in a graph from one source to all other nodes. The algorithm was introduced by American mathematicians Richard Bellman and Lester ford. Computes shortest from a single source vertex to all of the other vertices in a weighted diagraph.
943 Source Code:
944import java.io.*;
945import java.util.*;
946import java.io.DataInputStream;
947class Edge
948{
949int source;
950int dest;
951int weight;
952}
953class Bellman
954{
955public static void BellmanFord(Edge edges[], int edgecount, int nodecount, int source)
956{
957int infinity=50000;
958int i, j;
959int distance[]=new int[nodecount];
960for(i=0; i<nodecount; i++)
961distance[i]=infinity;
962distance[source]=0;
963for(i=0; i<nodecount; i++)
964{
965boolean somethingchanged=false;
966for(j=0; j<edgecount; j++)
967{
968if(distance[edges[j].source]!=infinity)
969{
970int new_distance=distance[edges[j].source]+edges[j].weight;
971if(new_distance<distance[edges[j].dest])
972{
973distance[edges[j].dest]=new_distance;
974somethingchanged=true;
975}
976}
977}
978if(!somethingchanged)
979break;
980}
981for(i=0; i<edgecount; ++i)
982{
983if(distance[edges[i].dest]>distance[edges[i].source]+edges[i].weight)
984System.out.println("Negative edge weight cycles detected!!!");
985}
986for(i=0; i<nodecount; ++i)
987System.out.println("The shortest distance between nodes "+source+" & "+i+" is "+distance[i]);
988}
989public static void main(String args[])
990{
991Scanner in=new Scanner(System.in);
992Edge edges[]=new Edge[10];
993for( int i=0; i<10; i++)
994{
995edges[i]=new Edge();
996System.out.print("Enter source number ["+i+"] : ");
997edges[i].source=in.nextInt();
998System.out.print("Enter destination number ["+i+"] : ");
999edges[i].dest=in.nextInt();
1000System.out.print("Enter weight number ["+i+"] : ");
1001edges[i].weight=in.nextInt();
1002System.out.println();
1003}
1004BellmanFord(edges, 10, 5, 4);
1005}
1006}
1007Enter the number of vertices : 4
1008Enter the adjacency matrix:
10090 5 999 999
10105 0 2 4
1011999 2 0 1
1012999 4 1 0
1013Enter source of vertex: 1
1014Distance of source 1 to 1 is 0
1015 Distance of source 1 to 2 is 5
1016Distance of source 1 to 3 is 7
1017Distance of source 1 to 4 is 8
1018
1019
1020Enter the number of vertices : 6
1021Enter the adjacency matrix:
10220 10 3 999 999 999
1023999 0 999 -3 2 999
1024999 999 0 3 999 999
1025999 999 999 0 4 1
1026999 -1 999 999 0 999
1027999 999 999 999 4 0
1028Enter source of vertex: 1
1029Distance of source 1 to 1 is 0
1030 Distance of source 1 to 2 is 9
1031Distance of source 1 to 3 is 3
1032Distance of source 1 to 4 is 6
1033Distance of source 1 to 5 is 10
1034Distance of source 1 to 6 is 7
1035
1036
10379. Using TCP/IP sockets, write a client – server program to make the client send the file name and to make the server send back the contents of the requested file if present.
1038
1039 A socket is an endpoint of a two-way communication link between two programs running on the network. Socket is bound to a port number so that the TCP layer can identify the application that data is destined to be sent. Java p.
1040
1041
1042
1043
1044rovides a set of classes, defined in a package called java.net, to enable the rapid development of network applications.
1045
1046The steps for creating a server program in TCP/IP are:
10471. Open the Server Socket:
1048ServerSocket server = new ServerSocket( PORT );
1049
1050 2. Wait for the Client Request:
1051Socket client = server.accept(); // bind with the port no
1052
1053 3. Create I/O streams for communicating to the client
1054InputStream istream = sock.getInputStream( );
1055BufferedReader fileRead =new BufferedReader(new InputStreamReader(istream));
1056 4. Perform communication with client
1057Receive from client: String fname = fileRead.readLine( );
1058Send to client: pwrite.println(str);
1059 5. Close socket:
1060client.close();
1061
1062The steps for creating a client program in TCP/IP are:
1063 1. Create a Socket Object:
1064Socket client = new Socket(server, port_id);
1065
1066 2. Create I/O streams for communicating with the server.
1067 is = new DataInputStream(client.getInputStream());
1068os = new DataOutputStream(client.getOutputStream());
1069
1070 3. Perform I/O or communication with the server:
1071Receive data from the server: String line = is.readLine();
1072Send data to the server: os.writeBytes(“Hello\n”);
1073
1074 4. Close the socket when done:
1075client.close();
1076
1077
1078Source Code:
1079
1080import java.net.*;
1081import java.io.*;
1082public class contentclient
1083{
1084 public static void main( String args[ ] ) throws Exception
1085 {
1086 Socket sock = new Socket( "127.0.0.1", 4000);
1087 System.out.print("Enter the file name");
1088 BufferedReader keyRead = new BufferedReader(new InputStreamReader(System.in));
1089 String fname = keyRead.readLine();
1090 OutputStream ostream = sock.getOutputStream( );
1091 PrintWriter pwrite = new PrintWriter(ostream, true);
1092 pwrite.println(fname);
1093 InputStream istream = sock.getInputStream();
1094 BufferedReader socketRead = new BufferedReader(new InputStreamReader(istream));
1095 String str;
1096 while((str = socketRead.readLine()) != null)
1097 {
1098 System.out.println(str);
1099 }
1100 pwrite.close(); socketRead.close(); keyRead.close();
1101 }
1102}
1103
1104
1105Source Code:
1106import java.net.*;
1107import java.io.*;
1108public class contentserver
1109{
1110 public static void main(String args[]) throws Exception
1111 {
1112 ServerSocket sersock = new ServerSocket(4000);
1113 System.out.println("Server ready for connection");
1114 Socket sock =
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148.accept();
1149System.out.println("Connection is successful and wating for chatting");
1150 InputStream istream = sock.getInputStream( );
1151BufferedReader fileRead =new BufferedReader(new InputStreamReader(istream));
1152String fname = fileRead.readLine( );
1153BufferedReader contentRead = new BufferedReader(new FileReader(fname) );
1154OutputStream ostream = sock.getOutputStream( );
1155PrintWriter pwrite = new PrintWriter(ostream, true);
1156String str;
1157while((str = contentRead.readLine()) != null)
1158 {
1159pwrite.println(str);
1160
1161
1162 }
1163sock.close();
1164sersock.close();
1165pwrite.close();
1166fileRead.close();
1167contentRead.close();
1168 }
1169}
1170
1171Computer Network lab
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
119010. Write a program on datagram socket for client/server to display the messages on client side, typed at the server side
1191Source Code:
1192Client:
1193import java.io.*;
1194import java.net.*;
1195public class udpc
1196{
1197public static void main(string[] args)
1198{
1199 DatagramSocket skt;
1200 try
1201 {
1202 skt=new DatagramSocket();
1203 String msg=”udp”;
1204 Byte[] b= msg.getBytes();
1205 InetAddress host=InetAddress.getByName(“127.0.0.1”);
1206 int serverSocket=6788;
1207 DatagramPacket request=new DatagramPacket(b,b.length,host,serverSocket);
1208skt.send(request);
1209Byte[] buffer=new byte[1000];
1210DatagramPacket reply=new DatagramPacket(buffer,buffer.length);
1211skt.receive(reply);
1212System.out.println(“Client received :” + new String(reply.getData()));
1213skt.close();
1214}
1215Catch(Exception ex)
1216{ }
1217}
1218}
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228Server:
1229import java.io.*;
1230import java.net.*;
1231public class udps
1232{
1233public static void main(string[] args)
1234{
1235 DatagramSocket Skt=null;
1236 try
1237 {
1238 Skt=new DatagramSocket(6788);
1239 Byte[] buffer= new byte(1000);
1240 While(true)
1241{
1242 DatagramPacket request=new DatagramPacket(buffer,buffer.length);
1243Skt.receive(request);
1244String[] message=(new string(request.getData())).split(“ “);
1245Byte[] sendMsg=(message[1]+”Network Laboratory”).getByte();
1246 DatagramPacket reply=new DatagramPacket(sendMsg,sendMsg.length,request.getAddress(),request.getport());
1247Skt.send(reply);
1248System.out.println(“Client received :” + new String(reply.getData()));
1249Skt.close();
1250}
1251Catch(Exception ex)
1252{ }
1253}
1254}
1255
1256Server ready for communication
1257Connection successful and waiting for chatting
1258Enter file name:
1259Sample.txt
1260Hello
1261World
1262
1263
1264
1265
126611. Write a program for simple RSA algorithm to encrypt and decrypt the data.
1267
1268RSA is an example of public key cryptography. It was developed by Rivest, Shamir and Adelman. The RSA algorithm can be used for both public key encryption and digital signatures. Its security is based on the difficulty of factoring large integers.
1269The RSA algorithm’s efficiency requires a fast method for performing the modular exponentiation operation. A less efficient, conventional method includes raising a number (the input) to a power (the secret or public key of the algorithm, denoted e and d, respectively) and taking the remainder of the division with N. A straight- forward implementation performs these two steps of the operation sequentially: first, raise it to the power and second, apply modulo. The RSA algorithm comprises of three steps, which are depicted below:
1270Key generation algorithm
12711. Generate two large random primes, p and q, of approximately equal size such that their product n=p*q
12722. Compute n= p*q and Euler’s totient function (@) phi(n) = (p-1)(q-1)
12733. Choose an integer e, 1< e < phi, such that gcd(e, phi)=1
12744. Compute the secret exponent d, 1< d <phi , such that e*d ≡1(mod phi)
12755. The public key is (e,n) and the private key is (d,n). The values of p, q and phi should also be kept secret.
1276Encryption
1277Sender A does the following:
12781. Using the public key(e,n)
12792. Represents the plaintext message as a positive integer M
12803. Computes the cipher text C= M^e mod n.
12814. Sends the cipher text C to B (Receiver)
1282Decryption
1283Recipient B does the following:
12841. Uses his private key (d,n) to compute M=C^d mod n
12852. Extracts the plaintext from the integer representative m.
1286
1287
1288
1289Source Code:
1290
1291import java.io.DataInputStream;
1292import java.io.IOException;
1293import java.math.BigInteger;
1294import java.util.Random;
1295public class RSA12
1296{
1297 private BigInteger p;
1298 private BigInteger q;
1299 private BigInteger N;
1300 private BigInteger phi;
1301 private BigInteger e;
1302 private BigInteger d;
1303 private int bitlength = 1024;
1304 private Random r;
1305 public RSA12()
1306 {
1307 r = new Random();
1308 p = BigInteger.probablePrime(bitlength, r);
1309 q = BigInteger.probablePrime(bitlength, r);
1310 N = p.multiply(q);
1311 phi = p.subtract(BigInteger.ONE).multiply(q.subtract(BigInteger.ONE));
1312 e = BigInteger.probablePrime(bitlength / 2, r);
1313 while (phi.gcd(e).compareTo(BigInteger.ONE) > 0 && e.compareTo(phi) < 0)
1314 {
1315 e.add(BigInteger.ONE);
1316 }
1317 d = e.modInverse(phi);
1318 }
1319
1320 public RSA12(BigInteger e, BigInteger d, BigInteger N)
1321 {
1322 this.e = e;
1323 this.d = d;
1324 this.N = N;
1325 }
1326
1327 public static void main(String[] args) throws IOException
1328 {
1329 RSA12 rsa = new RSA12();
1330 DataInputStream in = new DataInputStream(System.in);
1331 String teststring;
1332 System.out.println("Enter the plain text:");
1333 teststring = in.readLine();
1334 System.out.println("Encrypting String: " + teststring);
1335 System.out.println("String in Bytes: "+ bytesToString(teststring.getBytes()));
1336 byte[] encrypted = rsa.encrypt(teststring.getBytes());
1337 byte[] decrypted = rsa.decrypt(encrypted);
1338 System.out.println("Decrypting Bytes: " + bytesToString(decrypted));
1339 System.out.println("Decrypted String: " + new String(decrypted));
1340 }
1341
1342 private static String bytesToString(byte[] encrypted)
1343 {
1344 String test = "";
1345 for (byte b : encrypted)
1346 {
1347 test += Byte.toString(b);
1348 }
1349 return test;
1350 }
1351
1352 public byte[] encrypt(byte[] message)
1353 {
1354 return (new BigInteger(message)).modPow(e, N).toByteArray();
1355 }
1356
1357 public byte[] decrypt(byte[] message)
1358 {
1359 return (new BigInteger(message)).modPow(d, N).toByteArray();
1360 }
1361}
1362
1363Enter the plain text :
1364hello
1365Encrypting string : hello
1366String in bytes : 1 0 4 1 0 1 1 0 8 1 0 8 1 1 1
1367Encrypted string : CB@a83b8a
1368Decrypting string : 1 0 4 1 0 1 1 0 8 1 0 8 1 1 1
1369Decrypted string : hello
1370
1371
1372
1373
1374
1375
137612. Write a program for congestion control using leaky bucket algorithm.
1377
1378What is congestion?
1379A state occurring in network layer when the message traffic is so heavy that it slows down network response time.
1380Effects of Congestion
1381• As delay increases, performance decreases.
1382• If delay increases, retransmission occurs, making situation worse.
1383Traffic shaping or policing: To control the amount and rate of traffic is called Traffic shaping or policing. Traffic shaping term is used when the traffic leaves a network. Policing term is used when the data enters the network. Two techniques can shape or police the traffic leaky bucket and token bucket.
1384Congestion control algorithms
1385• Leaky Bucket Algorithm
1386Let us consider an example to understand
1387Imagine a bucket with a small hole in the bottom. No matter at what rate water enters the bucket, the outflow is at constant rate. When the bucket is full with water additional water entering spills over the sides and is lost.
1388
1389Similarly, each network interface contains a leaky bucket and the following steps are involved in leaky bucket algorithm:
13901. When host wants to send packet, packet is thrown into the bucket.
13912. The bucket leaks at a constant rate, meaning the network interface transmits packets at a constant rate.
13923. Bursty traffic is converted to a uniform traffic by the leaky bucket.
13934. In practice the bucket is a finite queue that outputs at a finite rate.
1394
1395Source Code:
1396importjava.util.*;
1397public class leaky
1398{
1399 public static void main(String[] args)
1400{
1401 Scanner my = new Scanner(System.in);
1402 intno_groups,bucket_size;
1403 System.out.print("\n Enter the bucket size : \t");
1404 bucket_size = my.nextInt();
1405 System.out.print("\n Enter the no of groups : \t");
1406 no_groups = my.nextInt();
1407 intno_packets[] = new int[no_groups];
1408 intin_bw[] = new int[no_groups];
1409 intout_bw,reqd_bw=0,tot_packets=0;
1410 for(inti=0;i<no_groups;i++)
1411 {
1412 System.out.print("\n Enter the no of packets for group " + (i+1) + "\t");
1413 no_packets[i] = my.nextInt();
1414 System.out.print("\n Enter the input bandwidth for the group " + (i+1) + "\t");
1415 in_bw[i] = my.nextInt();
1416 if((tot_packets+no_packets[i])<=bucket_size)
1417 {
1418 tot_packets += no_packets[i];
1419 }
1420 else
1421 {
1422 do
1423 {
1424 System.out.println(" Bucket Overflow ");
1425 System.out.println(" Enter value less than " + (bucket_size-tot_packets));
1426 no_packets[i] = my.nextInt();
1427 }while((tot_packets+no_packets[i])>bucket_size);
1428 tot_packets += no_packets[i];
1429 }
1430 reqd_bw += (no_packets[i]*in_bw[i]);
1431 }
1432 System.out.println("\nThe total required bandwidth is " + reqd_bw);
1433 System.out.println("Enter the output bandwidth ");
1434 out_bw = my.nextInt();
1435 int temp=reqd_bw;
1436 intrem_pkts = tot_packets;
1437 while((out_bw<=temp)&&(rem_pkts>0))
1438 {
1439 System.out.println("Data Sent \n" + (--rem_pkts) + " packets remaining");
1440 System.out.println("Remaining Bandwidth " + (temp -= out_bw));
1441 if((out_bw>temp)&&(rem_pkts>0))
1442 System.out.println(rem_pkts + " packet(s) discarded due to insufficient bandwidth");
1443 }
1444 }
1445}
1446
1447Enter bucket size : 20
1448Enter number of groups :2
1449Enter number of packets of group 1:2
1450Enter input bandwidth for group 1:2
1451Enter number of packets of group 2 :3
1452Enter input bandwidth for group 2 : 3
1453Total required bandwidth :13
1454Enter the output bandwidth:2
1455Data sent
14564 packets remaining
1457Remaining bandwidth:11
1458Data sent
14593 packets remaining
1460Remaining bandwidth : 9
1461Data sent
14622 packets remaining
1463Remaining bandwidth :7
1464Data sent
14651 packets remaining
1466Remaining bandwidth :5
1467Data sent
14680 packets remaining
1469Remaining bandwidth :3
1470
1471Viva Questions:
14721. What are functions of different layers?
14732. Differentiate between TCP/IP Layers and OSI Layers
14743. Why header is required?
14754. What is the use of adding header and trailer to frames?
14765. What is encapsulation?
14776. Why fragmentation requires?
14787. What is MTU?
14798. Which layer imposes MTU?
14809. Differentiate between flow control and congestion control.
148110. Differentiate between Point-to-Point Connection and End-to-End connections.
148211. What are protocols running in different layers?
148312. What is Protocol Stack?
148413. Differentiate between TCP and UDP.
148514. Differentiate between Connectionless and connection oriented connection.
148615. Why frame sorting is required?
148716. What is meant by subnet?
148817. What is meant by Gateway?
148918. What is an IP address?
149019. What is MAC address?
149120. Why IP address is required when we have MAC address?
149221. What is meant by port?
149322. What are ephemerical port number and well known port numbers?
149423. What is a socket?
149524. What are the parameters of socket()?
149625. Describe bind(), listen(), accept(), connect(), send() and recv().
149726. What are system calls? Mention few of them.
149827. What is meant by file descriptor?
149928. What is meant by traffic shaping?
150029. How do you classify congestion control algorithms?
150130. How do you implement Leaky bucket?
150231. How do you generate busty traffic?
150332. What is the polynomial used in CRC-CCITT?
150433. . What are the other error detection algorithms?
150534. What are Routing algorithms?
150635. How do you classify routing algorithms? Give examples for each.
150736. What are drawbacks in distance vector algorithm?
150837. How routers update distances to each of its neighbor?
150938. How do you overcome count to infinity problem?
151039. What is cryptography?
151140. How do you classify cryptographic algorithms?
151241. What is public key?
151342. What is private key?
151443. What are key cipher text and plaintext?
151544. What is simulation?
151645. What are advantages of simulation?
151746. Differentiate between Simulation and Emulation.
151847. What is meant by router?
151948. What is meant by bridge?
152049. What is meant by switch?
152150. What is meant by hub?
152251. Differentiate between route, bridge, switch and hub.
152352. What is ping and telnet?
152453. What is FTP?
152554. What is collision?
152655. How do you generate multiple traffics across different sender-receiver pairs?
152756. What is meant by mobile host?
152857. Name few other Network simulators
152958. Differentiate between logical and physical address.
153059. Which address gets affected if a system moves from one place to another place?
153160. What is ICMP? What are uses of ICMP? Name few.
153261. Which layer implements security for data?
153362. What is connectionless and connection oriented protocol?
153463. What is Congestion window?
153564. What is flow control?