1km before electronic city, hosur road ... - pesit southpesitsouth.pes.edu/pdf/2017/ise/cn lab...

49
PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100. Department OF Information Science & Engineering COMPUTER NETWORK LABORATORY 15CSL57 Lab Manual 2017-18

Upload: vonhan

Post on 12-Apr-2018

221 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100.

Department OF Information Science &

Engineering

COMPUTER NETWORK LABORATORY

15CSL57

Lab Manual

2017-18

Page 2: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100
Page 3: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

Introduction to Network Simulators

Network Simulator Version 2, widely known as NS2, is an event driven simulation tool that is useful in

studying the dynamic nature of communication networks. Simulation of wired as well as wireless network

functions and protocols (e.g., routing algorithms, TCP, UDP) can be done using NS2. In general, NS2

provides users with a way of specifying such network protocols and simulating their corresponding

behaviors. Due to its flexibility and modular nature, NS2 has gained constant popularity in the networking

research community since its birth in 1989. Ever since, several revolutions and revisions have marked the

growing maturity of the tool, thanks to substantial contributions from the players in the field. Among

these are the University of California and Cornell University who developed the REAL network simulator,1

the foundation which NS is based on. Since 1995 the Defense Advanced Research Projects Agency

(DARPA) supported development of NS through the Virtual InterNetwork Testbed (VINT) project.Currently

the National Science Foundation (NSF) has joined the ride in development. Last but not the least, the

group of researchers and developers in the community are constantly working to keep NS2 strong and

versatile.

Figure given below shows the basic architecture of NS2. NS2 provides users with an executable command

ns which takes on input argument, the name of a Tcl simulation scripting file. Users are feeding the name

of a Tcl simulation script (which sets up a simulation) as an input argument of an NS2 executable

command ns. In most cases, a simulation trace file is created, and is used to plot graph and/or to create

animation

Page 4: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

Figure 1: Basic Ns architecture

NS2 consists of two key languages: C++ and Object-oriented Tool Command Language (OTcl). While the

C++ defines the internal mechanism (i.e.,a back end) of the simulation objects, the OTcl sets up simulation

by assembling and configuring the objects as well as scheduling discrete events (i.e.,a front end). The C++

and the OTcl are linked together using TclCL. Mapped to a C++ object, variables in the OTcl domains are

sometimes referred to as handles. Conceptually, a handle (e.g., n as a Node handle) is just a string

(e.g.,o10) in the OTcl domain, and does not contain any functionality. Instead, the functionality(e.g.,

receiving a packet) is defined in the mapped C++ object (e.g., of class Connector). In the OTcl domain, a

handle acts as a front end which interacts with users and other OTcl objects. It may defines its own

procedures and variables to facilitate the interaction. Note that the member procedures and variables in

the OTcl domain are called instance procedures(instprocs) and instance variables(instvars), respectively.

Before proceeding further, the readers are encouraged to learn C++ and OTcl languages and we include it

on our previous posts.

NS2 provides a large number of built in C++ objects. It is advisable to use these C++ objects to set up a

simulation using a Tcl simulation script. However, advance users may find these objects insufficient. They

need to develop their own C++ objects, and use a OTcl configuration interface to put together these

objects. After simulation, NS2 outputs either text-based or animation-based simulation results. To

interpret these results graphically and interactively, tools such as NAM (Network AniMator) and

XGraph are used. To analyze a particular behavior of the network, users can extract a relevant subset of

text-based data and transform it to a more conceivable presentation.

NS2 program Structure

The NS2 program is basically a Tcl/OTcl script written using any text editor such as vi or emacs. The normal

program structure is as follows:

• Program description as comment (optional)

• Create a Simulator Object

• Create NS2 trace file

• Create NAM trace file

Page 5: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

• Create topology (define nodes and links with permissible characteristics like simplex/duplex, bandwidth,

etc.)

• Create a transport agent in pair (both source and sink ), attach them to corresponding nodes, and

connect them

• Create application/traffic agent and attach it to the required nodes

• Schedule different events (when to start and stop, etc.)

• Define a finish procedure

• Start the simulation

The normal finish procedure consists of the following steps:

• Declare simulator object and trace files as global

• Flush the traces

• Close trace files (both NS and NAM)

• Execute NAM with NAM trace file as input (if any)

Labroratory Programs

PART A

Program 1

Simulate a three nodes point – to – point network with duplex links between them. Set the queue size and

vary the bandwidth and find the number of packets dropped.

STEPS:

Step1: Select the hub icon on the toolbar and drag it onto the working window.

Step2: Select the host icon on the toolbar and drag it onto the working window. Repeat this for another

host icon.

Page 6: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

Step3: Select the link icon on the toolbar and drag it on the screen from host (node 1) to the hub and

again from host(node 2) to the hub. Here the hub acts as node 3 in the point-to-point network. This leads

to the creation of the 3-node point-to-point network topology. Save this topology as a .tpl file.

Step4: Double-click on host(node 1), a host dialog box will open up. Click on Node editor and you can see

the different layers- interface, ARP, FIFO, MAC, TCPDUMP, Physical layers. Select MAC and then select full-

duplex for switches and routers and half duplex for hubs, and in log Statistics, select Number of Drop

Packets, Number of Collisions, Throughput of incoming packets and Throughput of outgoing packets.

Select FIFO and set the queue size to 50 and press OK. Then click on Add. Another dialog box pops up.

Click on the Command box and type the Command according to the following syntax:

stg [-t duration(sec)] [-p port number]HostIPaddr and click OK.

Step 5: Double-click on host (node 2), and follow the same step as above with only change in command

according to the following syntax:

rtg [-t] [-w log] [-p port number] and click OK.

Step 6: Double click on the link between node 1 and the hub to set the bandwidth to some initial

value say, 10 Mbps. Repeat the same for the other node.

Step 7: Click on the E button (Edit Property) present on the toolbar in order to save the changes made to

the topology. Now click on the R button (RunSimulation). By doing so a user can

run/pause/continue/stop/abort/disconnect/reconnect/submit a simulation. No simulation settings can be

changed in this mode.

Step 8: Now go to Menu->Simulation->Run. Executing this command will submit he current simulation job

to one available simulation server managed by the dispatcher. When the simulation server is executing,

the user will see the time knot at the bottom of the screen move. The time knot reflects the current

virtual time (progress) of the simulation case.

Step 9:To start the playback, the user can left-click the start icon( |>) of the time bar located at the

bottom. The animation player will then start playing the recorded packet animation.

Step 10: Change the bandwidth say, 9 Mbps, and run the simulation and compare the two

results.

Step 12: To view the results, go to the filename. results folder.

Note: To get the syntax of any command, double click on the host icon. Host dialog boxes appear and

then choose App. Usage.

Page 7: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

Execution.

To run the simulation:

$ns 1.tcl

To plot the graph:

$xgraph [-fg <color>][-bg <color>][-lw <int value>] <name>.xg

NS2 code :

#Create a new Simulation Instance

set ns [new Simulator]

#Turn on the Trace and the animation files

set f [open out.tr w]

set nf [open out.nam w]

$ns trace-all $f

$ns namtrace-all $nf

#Define the finish procedure to perform at the end of the simulation

proc finish {} {

global f nf ns

$ns flush-trace

close $f

close $nf

exec nam out.nam &

exec awk -f 1.awk out.tr &

exit 0

}

#Create the nodes

set n0 [$ns node]

set n1 [$ns node]

Page 8: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

set n2 [$ns node]

#Label the nodes

$n0 label "TCP Source"

$n1 label "UDP Source"

$n2 label "Sink"

#Set the color

$ns color 1 red

$ns color 2 yellow

#Create the Topology

$ns duplex-link $n0 $n1 2Mb 10ms DropTail

$ns duplex-link $n1 $n2 1.75Mb 20ms DropTail

#Attach a Queue of size N Packets between the nodes n1 n2

$ns queue-limit $n1 $n2 10

#Make the Link Orientation

$ns duplex-link-op $n0 $n1 orient right

$ns duplex-link-op $n1 $n2 orient right

Set udp0 [new/Agent/UDP]

$ns attach-agent $n0 $udp0

Set cbr0[new Application/Traffic/CBR]

$cbr0 attach-agent $udp0

$cbr set packetsize_ 500

$cbr set interval_ 0.005

Set null [Agent/null]

$ns attach-agent $n2 $null0

$ns connect $udp0$null0

Page 9: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

Set tcp0 [new Agent/TCP]

$ns attach-agent $n0 $tcp0

Set ftp0 [new Application/FTP]

$ftp0 attach-agent $tcp0

Set sink0 [new Agent/TCPsink]

$ftp0 set maxPackets_ 1000

$ns connect $tcp0 $sink0

$udp0 set class_ 1

$tcp0 set class_ 2

$ns at 0.5 “cbr0 start”

$ns at 1.0 “ftp0 start”

$ns at 4.0 “ftp0 start”

$ns at 5.0 “cbr0 stop”

$ns run

Awk 1

#!/usr/bin/awk -f

BEGIN{

cbrPkt=0;

tcpPkt=0;

}

{

if(($1 == "d")&&($5 == "cbr")) {

cbrPkt = cbrPkt + 1;

}

Page 10: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

if(($1 == "d")&&($5 == "tcp")) {

tcpPkt = tcpPkt + 1;

}

}

END {

printf "\nNo. of CBR Packets Dropped %d", cbrPkt;

printf "\nNo. of TCP Packets Dropped %d", tcpPkt;

}

Xgraph 1

TitleText: Performance Analysis (Bandwidth vs Packet Dropped)

XUnitText: Bandwidth(in Mbps)

YUnitText: No.of Packet Dropped

"CBR"

0.25 617

0.50 369

0.75 138

1.0 80

1.25 62

1.5 32

1.75 38

2.0 0

"TCP"

0.25 6

0.50 8

0.75 6

1.0 9

1.25 15

1.5 10

1.75 8

2.0 0

Program 2:

Program 2:

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.

STEPS:

Step 1: Click on the subnet icon on the toolbar and then click on the screen of the working window.

Page 11: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

Step 2: Select the required number of hosts and a suitable radius between the host and the switch.

switch.

Step 3: In the edit mode, get the IP address of one of the hosts say, host 1 and then for the other host say,

host2 set the drop packet and no: of collisions statistics as described in the earlier experiments.

Step 4: Now run the simulation.

Step 5: Now click on any one of the hosts and click on command console and ping the

destination node.

ping IP Address

Note: The no: of drop packets are obtained only when the traffic is more in the network.

For checking the number of packet dropped press ctrl +C

Ns2 code:

set ns [new Simulator]

set f [open out.tr w]

set nf [open out.nam w]

$ns trace-all $f

$ns namtrace-all $nf

proc finish {} {

global ns f nf

$ns flush-trace

close $f

close $nf

exec nam out.nam &

exit 0

}

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

Page 12: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

set n3 [$ns node]

set n4 [$ns node]

set n5 [$ns node]

$n0 label "ping0"

$n1 label "ping1"

$n2 label "R1"

$n3 label "R2"

$n4 label "ping4"

$n5 label "ping5"

$ns color 1 red

$ns color 2 blue

$ns color 3 green

$ns color 4 orange

$ns duplex-link $n0 $n2 1Mb 10ms DropTail

$ns duplex-link $n1 $n2 1Mb 10ms DropTail

$ns duplex-link $n2 $n3 0.4Mb 30ms DropTail

$ns duplex-link $n3 $n4 1Mb 10ms DropTail

$ns duplex-link $n3 $n5 1Mb 10ms DropTail

set ping0 [new Agent/Ping]

$ns attach-agent $n0 $ping0

set ping1 [new Agent/Ping]

$ns attach-agent $n1 $ping1

set ping4 [new Agent/Ping]

Page 13: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

$ns attach-agent $n4 $ping4

set ping5 [new Agent/Ping]

$ns attach-agent $n5 $ping5

$ns connect $ping0 $ping4

$ns connect $ping1 $ping5

proc sendPingPacket {} {

global ns ping0 ping1

set intervalTime 0.001

set now [$ns now]

$ns at [expr $now + $intervalTime] "$ping0 send"

$ns at [expr $now + $intervalTime] "$ping1 send"

$ns at [expr $now + $intervalTime] "sendPingPacket"

}

Set seq 1

Agent/Ping instproc recv {from rtt} {

global seq

$self instvar node_

Put “64 bytes from[$node_ id] icmp_$ seq ttl=64 times=$rtt ms”

Set seq [expr] $seq+1

}

$ns at 0.01 “$ping0 send”

$ns at 0.01 “$ping1 send”

$$ns at 0.01 “$ping4 send”

$$ns at 0.01 “$SendPingPacket”

$$ns at 10 “finish”

$ns run

Page 14: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

Xgraph

TitleText: Performance Analysis of Bandwidth v/s Packet Dropped

xUnitText: Bandwidth in Mbps

yUnitText: Packet Dropped

0.1 17960

0.2 16011

0.3 14062

0.4 12113

0.5 10164

0.6 8216

0.7 6267

0.8 4318

0.9 2369

1.0 420

Program 3.

Implement an Ethernet LAN using n nodes and set multiple traffic nodes and plot congestion window for

different source / destination.

Steps

Step 1:

Connect one set of hosts with a hub and another set of hosts also through a hub and

connect these two hubs through a switch. This forms an Ethernet LAN.

Step 2:

Setup a TCP connection between a host on one hub and host on another hub

using the following command:

stcp [-p port] [-l writesize] hostIPaddr

rtcp [-p port] [-l readsize]

Step 3: Setup the error rate, data rate in the physical layer, input and output throughput in the mac layer

as described above.

Step 4: Change error rate and data rate and compare the throughputs. Step 5: View the results in the

filename.results.

Page 15: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

Ns2 code3:

#Create a new Simulation Instance

set ns [new Simulator]

#Turn on the Trace and the animation files

set f [open out.tr w]

setnf [open out.nam w]

$ns trace-all $f

$ns namtrace-all $nf

#Define the finish procedure to perform at the end of the simulation

proc finish {} {

global f nf ns

$ns flush-trace

close $f

close $nf

execnamout.nam&

execawk -f 4.awk out.tr &

exit 0

}

#Create the nodes

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]

Page 16: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

set n4 [$ns node]

set n5 [$ns node]

set n6 [$ns node]

set n7 [$ns node]

set n8 [$ns node]

set n9 [$ns node]

#create the lan topology

$ns make-lan "$n0 $n1 $n2 $n3 $n4" 1Mb 10ms LL Queue/DropTail Mac/802_3

$ns make-lan "$n5 $n6 $n7 $n8 $n9" 1Mb 10ms LL Queue/DropTail Mac/802_3

$ns duplex-link $n2 $n6 1Mb 30ms DropTail

Mac/802_3 set datarate_ 10Mb

#Create a UDP Agent and attach to the node n1

set udp0 [new Agent/UDP]

$ns attach-agent $n0 $udp0

#Create a CBR Traffic source and attach to the UDP Agent

set cbr0 [new Application/Traffic/CBR]

$cbr0 attach-agent $udp0

$cbr0 set packetSize_ 500

$cbr0 set Interval_ 0.05

#Create a TCP agent and attach to the node n0

set tcp0 [new Agent/TCP]

$ns attach-agent $n3 $tcp0

Page 17: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

#Create a FTP source and attach to the TCP agent

set ftp0 [new Application/FTP]

#Attach the FTP source to the TCP Agent

$ftp0 attach-agent $tcp0

$ftp0 set packetSize_ 500

#Create a Null Agent and attach to the node n2

set null0 [new Agent/Null]

$ns attach-agent $n7 $null0

#Create a TCPSink agent and attach to the node n2

set sink0 [new Agent/TCPSink]

$ns attach-agent $n8 $sink0

#Connect

$ns connect $udp0 $null0

$ns connect $tcp0 $sink0

set err [new ErrorModel]

$ns lossmodel $err $n2 $n6

$err set rate_ 0.1

$ns at 1.0 "$cbr0 start"

$ns at 1.0 "$ftp0 start"

$ns at 9.0 "$cbr0 stop"

$ns at 9.0 "$ftp0 stop"

Page 18: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

$ns at 10.0 "finish"

$ns run

/****************************************************************************************

***************

*File : p4.awk

****************************************************************************************

***************/

#!/usr/bin/awk -f

BEGIN {

cbrPktReceived=0;

totalPktReceived=0;

ftpPktReceived=0;

throughput=0.0;

}

{

src=$3;

des=$4;

type=$5;

event=$1;

if((event=="+") && (src=="2") && (des=="6") && (type=="cbr"))

cbrPktReceived++;

if(($1=="+") && ($3=="2") && ($4=="6") && (type=="tcp"))

ftpPktReceived++;

totalPktReceived=cbrPktReceived+ftpPktReceived;

}

Page 19: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

END {

throughput=((totalPktReceived*500*8)/(8*1000000));

printf "the throughput is:%f\n",throughput;

printf "the throughput is:%d\n",cbrPktReceived;

printf "the throughput is:%d\n",ftpPktReceived;

}

Program 4.

Implement simple ESS and with transmitting nodes in wire-less LAN by simulation and determine the

performance with respect to transmission of packets.

Ns2 code4:

if {$argc != 1} {

error "Command: ns <ScriptName.tcl><Number_of_Nodes>"

exit 0

}

#Define the simulation options

setval(chan) Channel/WirelessChannel

setval(prop) Propagation/TwoRayGround

setval(ant) Antenna/OmniAntenna

setval(ll) LL

setval(ifq) Queue/DropTail/PriQueue

setval(ifqlen) 50

setval(netif) Phy/WirelessPhy

setval(mac) Mac/802_11

setval(rp) AODV

setval(nn) [lindex $argv 0]

set opt(x) 750

set opt(y) 750

setval(stop) 100

Page 20: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

set ns [new Simulator]

settrfd [open Wireless.tr w]

setnamfd [open Wireless.nam w]

$ns trace-all $trfd

$ns namtrace-all-wireless $namfd $opt(x) $opt(y)

settopo [new Topography]

$topoload_flatgrid $opt(x) $opt(y)

set god_ [create-god $val(nn)]

#Configure the nodes

$ns node-config -adhocRouting $val(rp) \

-llType $val(ll) \

-macType $val(mac) \

-ifqType $val(ifq) \

-channelType $val(chan) \

-propType $val(prop) \

-antType $val(ant) \

-ifqLen $val(ifqlen) \

-phyType $val(netif) \

-topoInstance $topo \

-agentTrace ON \

-routerTrace ON \

-macTrace OFF \

-movementTrace OFF

for {set i 0} {$i< $val(nn)} {incri} {

Page 21: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

set n($i) [$ns node]

}

#Randomly placing the nodes

for {set i 0} {$i< $val(nn)} {incri} {

set XX [expr rand()*750]

set YY [expr rand()*750]

$n($i) set X_ $XX

$n($i) set Y_ $YY

}

for {set i 0} {$i< $val(nn)} {incri} {

$ns initial_node_pos $n($i) 30

}

set tcp1 [new Agent/TCP]

$ns attach-agent $n(1) $tcp1

set ftp1 [new Application/FTP]

$ftp1 attach-agent $tcp1

set sink1 [new Agent/TCPSink]

$ns attach-agent $n(3) $sink1

$ns connect $tcp1 $sink1

$ns at 0.0 "destination"

proc destination {} {

global ns val n

set now [$ns now]

Page 22: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

set time 5.0

for {set i 0} {$i< $val(nn)} {incri} {

set XX [expr rand()*750]

set YY [expr rand()*750]

$ns at [expr $now + $time] "$n($i) setdest $XX $YY 20.0"

}

$ns at [expr $now + $time] "destination"

}

#tell nodes when the simulation ends

for {set i 0} {$i< $val(nn)} {incri} {

$ns at $val(stop) "$n($i) reset"

}

$ns at 5.0 "$ftp1 start"

$ns at $val(stop) "$ns nam-end-wireless $val(stop)"

$ns at $val(stop) "stop"

proc stop {} {

global ns trfdnamfd

close $trfd

close $namfd

execnamWireless.nam&

execawk -f 6.awk Wireless.tr &

exit 0

}

$ns run

Page 23: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

/****************************************************************************************

************************

*File : p6.awk

****************************************************************************************

************************/

BEGIN{

PacketRcvd=0;

Throughput=0.0;

}

{

if(($1=="r")&&($3=="_3_")&&($4=="AGT")&&($7=="tcp")&&($8>1000))

{

PacketRcvd++;

}

}

END {

Throughput=((PacketRcvd*1000*8)/(95.0*1000000));

printf "the throughput is:%f\n",Throughput;

}

Program 5.

Implement and study the performance of GSM on NS2/NS3 (Using MAC layer) or equivalent environment.

Program 6.

Implement and study the performance of CDMA on NS2/NS3 (Using stack called Call net) or equivalent

environment.

PART B

Implementation in Java

Page 24: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

Program 7: Write a program for error detecting code using CRC-CCITT (16-bits).

Description:

The cyclic redundancy check, or CRC, is a technique for detecting

errors in digital data, but not for making corrections when errors are detected. It is used primarily in data

transmission.

In the CRC method, a certain number of check bits, often called a checksum, are appended to the message

being transmitted. The receiver can determine whether or not the check bits agree with the data, to

ascertain with a certain degree of probability whether or not an error occurred in transmission.

If an error occurred, the receiver sends a "negative acknowledgement" (NAK) back to the sender, requesting

that the message be retransmitted. The technique is also sometimes applied to data storage devices, such as

a disk drive. In this situation each block on the disk would have check bits, and the hardware might

automatically initiate a reread of the block when an error is detected, or it might report the error to

software. The material that follows speaks in terms of a "sender" and a "receiver" of a "message," but it

should be understood that it applies to storage writing and reading as well.

Theory

It does error checking via polynomial division. In general, a bit string

bn-1bn-2bn-3…b2b1b0

As

bn-1Xn-1 + bn-2 X

n-2 + bn-3 Xn-3

+ …b2 X2 + b1 X1

+ b0

Ex: -

10010101110

As

X10

+ X7

+ X5

+ X3

+ X2

+ X1

All computations are done in modulo 2

Page 25: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

Algorithm:-

1. Given a bit string, append 0S to the end of it (the number of 0

s is the same as the degree of the

generator polynomial) let B(x) be the polynomial corresponding to B.

2. Divide B(x) by some agreed on polynomial G(x) (generator polynomial) and determine the remainder

R(x). This division is to be done using Modulo 2 Division.

3. Define T(x) = B(x) –R(x)

(T(x)/G(x) => remainder 0)

4. Transmit T, the bit string corresponding to T(x).

5. Let T’ represent the bit stream the receiver gets and T’(x) the associated polynomial. The receiver

divides T1(x) by G(x). If there is a 0 remainder, the receiver concludes T = T’ and no error occurred otherwise,

the receiver concludes an error occurred and requires a retransmission.

Program

import java.io.*;

class crc

{

public static void main(String a[]) throws IOException {

InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr);

int[] message;

int[] gen;

int[] app_message;

int[] rem;

int[] trans_message;

int message_bits,gen_bits, total_bits;

System.out.println("\n Enter number of bits in message : "); message_bits=Integer.parseInt(br.readLine());

message=new int[message_bits];

System.out.println("\n Enter message bits : ");

for(int i=0; i<message_bits; i++)

message[i]=Integer.parseInt(br.readLine());

Page 26: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

System.out.println("\n Enter number of bits in gen : "); gen_bits=Integer.parseInt(br.readLine());

gen=new int[gen_bits];

System.out.println("\n Enter gen bits : ");

for(int i=0; i<gen_bits; i++)

{

gen[i]=Integer.parseInt(br.readLine());

}

total_bits=message_bits+gen_bits-1;

app_message=new int[total_bits];

rem=new int[total_bits];

trans_message=new int[total_bits];

for(int i=0;i<message.length;i++)

{

app_message[i]=message[i];

}

System.out.print("\n Message bits are : ");

for(int i=0; i< message_bits; i++)

{

System.out.print(message[i]);

}

Page 27: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

System.out.print("\n Generators bits are : ");

for(int i=0; i< gen_bits; i++)

{

System.out.print(gen[i]);

}

System.out.print("\n Appended message is : ");

for(int i=0; i< app_message.length; i++)

{

System.out.print(app_message[i]);

}

for(int j=0; j<app_message.length; j++)

{

rem[j] = app_message[j];

}

rem=computecrc(app_message, gen, rem);

for(int i=0;i<app_message.length;i++)

{

trans_message[i]=(app_message[i]^rem[i]);

}

System.out.println("\n Transmitted message from the transmitter is : "); for(int

i=0;i<trans_message.length;i++) {

System.out.print(trans_message[i]);

}

System.out.println("\n Enter received message of "+total_bits+" bits at receiver end : ");

for(int i=0; i<trans_message.length; i++)

{

trans_message[i]=Integer.parseInt(br.readLine());

}

System.out.println("\n Received message is :");

for(int i=0; i< trans_message.length; i++)

Page 28: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

{

System.out.print(trans_message[i]);

}

for(int j=0; j<trans_message.length; j++)

{

rem[j] = trans_message[j];

}

rem=computecrc(trans_message, gen, rem);

for(int i=0; i< rem.length; i++)

{

if(rem[i]!=0)

Page 29: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

{

System.out.println("\n There is Error in the received message!!!"); break;

}

if(i==rem.length-1)

{

System.out.println("\n There is No Error in the received message!!!");

}

}

static int[] computecrc(int app_message[],int gen[], int rem[])

{

int current=0;

while(true)

{

for(int i=0;i<gen.length;i++)

{

rem[current+i]=(rem[current+i]^gen[i]);

}

while(rem[current]==0 && current!=rem.length-1)

{

current++;

}

if((rem.length-current)<gen.length)

{

break;

}

}

Page 30: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

return rem;

}

}

Program 8: Bellman Ford algorithm

package com.hinguapps.graph;

import java.util.Scanner;

public class BellmanFord

{

private int distances[];

private int numberofvertices;

public static final int MAX_VALUE = 999;

public BellmanFord(int numberofvertices)

{

this.numberofvertices = numberofvertices;

distances = new int[numberofvertices + 1];

}

public void BellmanFordEvaluation(int source, int destination,

int adjacencymatrix[][])

{

for (int node = 1; node <= numberofvertices; node++)

{

distances[node] = MAX_VALUE;

Page 31: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

}

distances[source] = 0;

for (int node = 1; node <= numberofvertices - 1; node++)

{

for (int sourcenode = 1; sourcenode <= numberofvertices; sourcenode++)

{

for (int destinationnode = 1; destinationnode <= numberofvertices; destinationnode++)

{

if (adjacencymatrix[sourcenode][destinationnode] != MAX_VALUE)

{

if (distances[destinationnode] > distances[sourcenode]

+ adjacencymatrix[sourcenode][destinationnode])

distances[destinationnode] = distances[sourcenode]

+ adjacencymatrix[sourcenode][destinationnode];

}

}

}

}

for (int sourcenode = 1; sourcenode <= numberofvertices; sourcenode++)

{

for (int destinationnode = 1; destinationnode <= numberofvertices; destinationnode++)

{

if (adjacencymatrix[sourcenode][destinationnode] != MAX_VALUE)

{

if (distances[destinationnode] > distances[sourcenode]

+ adjacencymatrix[sourcenode][destinationnode])

System.out

Page 32: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

.println("The Graph contains negative egde cycle");

}

}

}

for (int vertex = 1; vertex <= numberofvertices; vertex++)

{

if (vertex == destination)

System.out.println("distance of source " + source + " to "

+ vertex + " is " + distances[vertex]);

}

}

public static void main(String... arg)

{

int numberofvertices = 0;

int source, destination;

Scanner scanner = new Scanner(System.in);

System.out.println("Enter the number of vertices");

numberofvertices = scanner.nextInt();

int adjacencymatrix[][] = new int[numberofvertices + 1][numberofvertices + 1];

System.out.println("Enter the adjacency matrix");

for (int sourcenode = 1; sourcenode <= numberofvertices; sourcenode++)

{

for (int destinationnode = 1; destinationnode <= numberofvertices; destinationnode++)

{

adjacencymatrix[sourcenode][destinationnode] = scanner

.nextInt();

Page 33: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

if (sourcenode == destinationnode)

{

adjacencymatrix[sourcenode][destinationnode] = 0;

continue;

}

if (adjacencymatrix[sourcenode][destinationnode] == 0)

{

adjacencymatrix[sourcenode][destinationnode] = MAX_VALUE;

}

}

}

System.out.println("Enter the source vertex");

source = scanner.nextInt();

System.out.println("Enter the destination vertex: ");

destination = scanner.nextInt();

BellmanFord bellmanford = new BellmanFord(numberofvertices);

bellmanford.BellmanFordEvaluation(source, destination, adjacencymatrix);

scanner.close();

}

}

Output:

$ javac BellmanFord.java

$ java BellmanFord

Output:

Enter the number of vertices

6

Page 34: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

Enter the adjacency matrix

0 4 0 0 -1 0

0 0 -1 0 -2 0

0 0 0 0 0 0

0 0 0 0 0 0

0 0 0 -5 0 3

0 0 0 0 0 0

Enter the source vertex

1

Enter the destination vertex:

4

distance of source 1 to 4 is -6

Problem 9:

TCP Socket

Using TCP/IP sockets, write a client-server program to make client sending the file name and the server

to send back the contents of the requested file if present.

Algorithm (Client Side)

1. Start.

2. Create a socket using socket() system call.

3. Connect the socket to the address of the server using connect() system call.

4. Send the filename of required file using send() system call.

5. Read the contents of the file sent by server by recv() system call.

6. Stop.

Algorithm (Server Side)

Page 35: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

1. Start.

2. Create a socket using socket() system call.

3. Bind the socket to an address using bind() system call.

4. Listen to the connection using listen() system call.

5. accept connection using accept()

6. Receive filename and transfer contents of file with client.

7. Stop.

Program 10

Write a program on datagram socket for client/server to display the messages on client side, typed at

the server side.

import java.net.*;

class WriteServer {

public static int serverPort = 666;

public static int clientPort = 999;

public static int buffer_size = 1024;

public static DatagramSocket ds;

public static byte buffer[] = new byte[buffer_size];

public static void TheServer() throws Exception {

int pos=0;

while (true) {

int c = System.in.read();

switch (c) {

case -1:

System.out.println("Server Quits.");

return;

case '\\r':

break;

case '\\n':

ds.send(new DatagramPacket(buffer,pos,

Page 36: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

InetAddress.getLocalHost(),clientPort));

pos=0;

break;

default:

buffer[pos++] = (byte) c;

}

}

}

public static void TheClient() throws Exception {

while(true) {

DatagramPacket p = new DatagramPacket(buffer,

buffer.length);

ds.receive(p);

System.out.println(new String(p.getData(), 0,

p.getLength()));

}

}

public static void main(String args[]) throws Exception {

if(args.length == 1) {

ds = new DatagramSocket(serverPort);

TheServer();

} else {

ds = new DatagramSocket(clientPort);

TheClient();

}

}

}

This sample program is restricted by the DatagramSocket constructor to running between two ports on

the local machine. To use the program, run

java WriteServer

in one window; this will be the client. Then run

java WriteServer 1

Page 37: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

This will be the server. Anything that is typed in the server window will be sent to the client window

after a newline is received.

Note This example requires that your computer be connected to the Internet.

Program 11

RSA Algorithm

Write a program for simple RSA algorithm to encrypt and decrypt the data.

Theory

Cryptography has a long and colorful history. The message to be encrypted, known as the plaintext, are

transformed by a function that is parameterized by a key. The output of the encryption process, known

as the ciphertext, is then transmitted, often by messenger or radio. The enemy, or intruder, hears and

accurately copies down the complete ciphertext. However, unlike the intended recipient, he does not

know the decryption key and so cannot decrypt the ciphertext easily. The art of breaking ciphers is

called cryptanalysis the art of devising ciphers (cryptography) and breaking them (cryptanalysis) is

collectively known as cryptology.

There are several ways of classifying cryptographic algorithms. They are generally categorized based on

the number of keys that are employed for encryption and decryption, and further defined by their

application and use. The three types of algorithms are as follows:

1. Secret Key Cryptography (SKC): Uses a single key for both encryption and decryption. It is also

known as symmetric cryptography.

2. Public Key Cryptography (PKC): Uses one key for encryption and another for decryption. It is also

known as asymmetric cryptography.

3. Hash Functions: Uses a mathematical transformation to irreversibly "encrypt" information

Public-key cryptography has been said to be the most significant new development in cryptography.

Modern PKC was first described publicly by Stanford University professor Martin Hellman and graduate

student Whitfield Diffie in 1976. Their paper described a two-key crypto system in which two parties

could engage in a secure communication over a non-secure communications channel without having to

share a secret key.

Generic PKC employs two keys that are mathematically related although knowledge of one key does not

allow someone to easily determine the other key. One key is used to encrypt the plaintext and the other

key is used to decrypt the ciphertext. The important point here is that it does not matter which key is

Page 38: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

applied first, but that both keys are required for the process to work. Because pair of keys is required,

this approach is also called asymmetric cryptography.

In PKC, one of the keys is designated the public key and may be advertised as widely as the owner

wants. The other key is designated the private key and is never revealed to another party. It is straight

forward to send messages under this scheme.

The RSA algorithm is named after Ron Rivest, Adi Shamir and Len Adleman, who invented it in 1977. 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.

Algorithm

1. Generate two large random primes, P and Q, of approximately equal size.

2. Compute N = P x Q

3. Compute Z = (P-1) x (Q-1).

4. Choose an integer E, 1 < E < Z, such that GCD (E, Z) = 1

5. Compute the secret exponent D, 1 < D < Z, such that E x D ≡ 1 (mod Z)

6. The public key is (N, E) and the private key is (N, D).

Note: The values of P, Q, and Z should also be kept secret.

The message is encrypted using public key and decrypted using private key.

An example of RSA encryption

1. Select primes P=11, Q=3.

2. N = P x Q = 11 x 3 = 33

Z = (P-1) x (Q-1) = 10 x 2 = 20

3. Lets choose E=3

Check GCD(E, P-1) = GCD(3, 10) = 1 (i.e. 3 and 10 have no common factors except 1),

and check GCD(E, Q-1) = GCD(3, 2) = 1

therefore GCD(E, Z) = GCD(3, 20) = 1

Page 39: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

4. Compute D such that E x D ≡ 1 (mod Z)

compute D = E^-1 mod Z = 3^-1 mod 20

find a value for D such that Z divides ((E x D)-1)

find D such that 20 divides 3D-1.

Simple testing (D = 1, 2, ...) gives D = 7

Check: (E x D)-1 = 3.7 - 1 = 20, which is divisible by Z.

5. Public key = (N, E) = (33, 3)

Private key = (N, D) = (33, 7).

Now say we want to encrypt the message m = 7,

Cipher code = M^E mod N

= 7^3 mod 33

= 343 mod 33

= 13.

Hence the ciphertext c = 13.

To check decryption we compute Message’ = C^D mod N

= 13^7 mod 33

= 7.

Note that we don't have to calculate the full value of 13 to the power 7 here. We can make use of the

fact that a = bc mod n = (b mod n).(c mod n) mod n so we can break down a potentially large number

into its components and combine the results of easier, smaller calculations to calculate the final value.

Program

package com.sanfoundry.setandstring;

import java.io.DataInputStream;

import java.io.IOException;

import java.math.BigInteger;

Page 40: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

import java.util.Random;

public class RSA

{

private BigInteger p;

private BigInteger q;

private BigInteger N;

private BigInteger phi;

private BigInteger e;

private BigInteger d;

private int bitlength = 1024;

private Random r;

public RSA()

{

r = new Random();

p = BigInteger.probablePrime(bitlength, r);

q = BigInteger.probablePrime(bitlength, r);

N = p.multiply(q);

phi = p.subtract(BigInteger.ONE).multiply(q.subtract(BigInteger.ONE));

e = BigInteger.probablePrime(bitlength / 2, r);

while (phi.gcd(e).compareTo(BigInteger.ONE) > 0 && e.compareTo(phi) < 0)

{

e.add(BigInteger.ONE);

}

d = e.modInverse(phi);

}

Page 41: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

public RSA(BigInteger e, BigInteger d, BigInteger N)

{

this.e = e;

this.d = d;

this.N = N;

}

@SuppressWarnings("deprecation")

public static void main(String[] args) throws IOException

{

RSA rsa = new RSA();

DataInputStream in = new DataInputStream(System.in);

String teststring;

System.out.println("Enter the plain text:");

teststring = in.readLine();

System.out.println("Encrypting String: " + teststring);

System.out.println("String in Bytes: "

+ bytesToString(teststring.getBytes()));

// encrypt

byte[] encrypted = rsa.encrypt(teststring.getBytes());

// decrypt

byte[] decrypted = rsa.decrypt(encrypted);

System.out.println("Decrypting Bytes: " + bytesToString(decrypted));

System.out.println("Decrypted String: " + new String(decrypted));

}

private static String bytesToString(byte[] encrypted)

Page 42: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

{

String test = "";

for (byte b : encrypted)

{

test += Byte.toString(b);

}

return test;

}

// Encrypt message

public byte[] encrypt(byte[] message)

{

return (new BigInteger(message)).modPow(e, N).toByteArray();

}

// Decrypt message

public byte[] decrypt(byte[] message)

{

return (new BigInteger(message)).modPow(d, N).toByteArray();

}

}

Output:

$ javac RSA.java

$ java RSA

Enter the plain text:

Sanfoundry

Page 43: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

Encrypting String: Sanfoundry

String in Bytes: 8397110102111117110100114121

Decrypting Bytes: 8397110102111117110100114121

Decrypted String: Sanfoundry

Leaky Bucket

Problem Statement

Write a program for congestion control using Leaky bucket algorithm.

Theory

The congesting control algorithms are basically divided into two groups: open loop and closed loop.

Open loop solutions attempt to solve the problem by good design, in essence, to make sure it does not

occur in the first place. Once the system is up and running, midcourse corrections are not made. Open

loop algorithms are further divided into ones that act at source versus ones that act at the destination.

In contrast, closed loop solutions are based on the concept of a feedback loop if there is any congestion.

Closed loop algorithms are also divided into two sub categories: explicit feedback and implicit feedback.

In explicit feedback algorithms, packets are sent back from the point of congestion to warn the source.

In implicit algorithm, the source deduces the existence of congestion by making local observation, such

as the time needed for acknowledgment to come back.

The presence of congestion means that the load is (temporarily) greater than the resources (in part of

the system) can handle. For subnets that use virtual circuits internally, these methods can be used at the

network layer.

Another open loop method to help manage congestion is forcing the packet to be transmitted at a more

predictable rate. This approach to congestion management is widely used in ATM networks and is called

traffic shaping.

Page 44: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

The other method is the leaky bucket algorithm. Each host is connected to the network by an interface

containing a leaky bucket, that is, a finite internal queue. If a packet arrives at the queue when it is full,

the packet is discarded. In other words, if one or more process are already queued, the new packet is

unceremoniously discarded. This arrangement can be built into the hardware interface or simulate d by

the host operating system. In fact it is nothing other than a single server queuing system with constant

service time.

The host is allowed to put one packet per clock tick onto the network. This mechanism turns an uneven

flow of packet from the user process inside the host into an even flow of packet onto the network,

smoothing out bursts and greatly reducing the chances of congestion.

Program

import java.util.*;

public class leaky

{

public static void main(String[] args)

{

Scanner my = new Scanner(System.in);

int no_groups,bucket_size;

System.out.print("\n Enter the bucket size : \t");

bucket_size = my.nextInt();

System.out.print("\n Enter the no of groups : \t");

no_groups = my.nextInt();

Page 45: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

int no_packets[] = new int[no_groups];

int in_bw[] = new int[no_groups];

int out_bw,reqd_bw=0,tot_packets=0;

for(int i=0;i<no_groups;i++)

{

System.out.print("\n Enter the no of packets for group " + (i+1) + "\t");

no_packets[i] = my.nextInt();

System.out.print("\n Enter the input bandwidth for the group " + (i+1) + "\t");

in_bw[i] = my.nextInt();

if((tot_packets+no_packets[i])<=bucket_size)

{

tot_packets += no_packets[i];

}

else

{

do

{

System.out.println(" Bucket Overflow ");

System.out.println(" Enter value less than " + (bucket_size-tot_packets));

no_packets[i] = my.nextInt();

}while((tot_packets+no_packets[i])>bucket_size);

tot_packets += no_packets[i];

}

reqd_bw += (no_packets[i]*in_bw[i]);

}

System.out.println("\nThe total required bandwidth is " + reqd_bw);

System.out.println("Enter the output bandwidth ");

Page 46: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

out_bw = my.nextInt();

int temp=reqd_bw;

int rem_pkts = tot_packets;

while((out_bw<=temp)&&(rem_pkts>0))

{

System.out.println("Data Sent \n" + (--rem_pkts) + " packets remaining");

System.out.println("Remaining Bandwidth " + (temp -= out_bw));

if((out_bw>temp)&&(rem_pkts>0))

System.out.println(rem_pkts + " packet(s) discarded due to insufficient bandwidth");

}

}

}

Viva Questions

1. What are functions of different layers?

2. Differentiate between TCP/IP Layers and OSI Layers

3. Why header is required?

4. What is the use of adding header and trailer to frames?

5. What is encapsulation?

6. Why fragmentation requires?

7. What is MTU?

8. Which layer imposes MTU?

9. Differentiate between flow control and congestion control.

10. Differentiate between Point-to-Point Connection and End-to-End connections.

11. What are protocols running in different layers?

12. What is Protocol Stack?

Page 47: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

13. Differentiate between TCP and UDP.

14. Differentiate between Connectionless and connection oriented connection.

15. Why frame sorting is required?

16. What is meant by subnet?

17. What is meant by Gateway?

18. What is an IP address?

19. What is MAC address?

20. Why IP address is required when we have MAC address?

21. What is meant by port?

22. What are ephemerical port number and well known port numbers?

23. What is a socket?

24. What are the parameters of socket()?

25. Describe bind(), listen(), accept(),connect(), send() and recv().

26. What are system calls? Mention few of them.

27. What is IPC? Name three techniques.

28. Explain mkfifo(), open(), close() with parameters.

29. What is meant by file descriptor?

30. What is meant by traffic shaping?

31. How do you classify congestion control algorithms?

32. Differentiate between Leaky bucket and Token bucket.

33. How do you implement Leaky bucket?

34. How do you generate busty traffic?

35. What is the polynomial used in CRC-CCITT?

36. What are the other error detection algorithms?

37. What is difference between CRC and Hamming code?

38. Why Hamming code is called 7,4 code?

39. What is odd parity and even parity?

Page 48: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

40. What is meant by syndrome?

41. What is generator matrix?

42. What is spanning tree?

43. Where Pirm’s algorithm does finds its use in Networks?

44. Differentiate between Prim’s and Kruskal’s algorithm.

45. What are Routing algorithms?

46. How do you classify routing algorithms? Give examples for each.

47. What are drawbacks in distance vector algorithm?

48. How routers update distances to each of its neighbor?

49. How do you overcome count to infinity problem?

50. What is cryptography?

51. How do you classify cryptographic algorithms?

52. What is public key?

53. What is private key?

54. What are key, ciphertext and plaintext?

55. What is simulation?

56. What are advantages of simulation?

57. Differentiate between Simulation and Emulation.

58. What is meant by router?

59. What is meant by bridge?

60. What is meant by switch?

61. What is meant by hub?

62. Differentiate between route, bridge, switch and hub.

63. What is ping and telnet?

64. What is FTP?

65. What is BER?

66. What is meant by congestion window?

Page 49: 1Km before Electronic City, Hosur Road ... - PESIT Southpesitsouth.pes.edu/pdf/2017/ISE/CN LAB MANUAL.pdf · PESIT Bangalore South Campus 1Km before Electronic City, Hosur Road, Bangalore-560100

67. What is BSS?

68. What is incoming throughput and outgoing throughput?

69. What is collision?

70. How do you generate multiple traffics across different sender-receiver pairs?

71. How do you setup Ethernet LAN?

72. What is meant by mobile host?

73. What is meant by NCTUns?

74. What are dispatcher, coordinator and nctunsclient?

75. Name few other Network simulators

76. Differentiate between logical and physical address.

77. Which address gets affected if a system moves from one place to another place?

78. What is ICMP? What are uses of ICMP? Name few.

79. Which layer implements security for data?