0% found this document useful (0 votes)
97 views

Cn-Lab-Manual SREYAS

The document provides a syllabus for a Computer Networks Lab course. It outlines the course objectives which are to understand communication protocols, network simulators, and traffic flow analysis. It also lists the course outcomes, which include implementing various layers of the network, analyzing error detection/correction codes, and network design concepts like routing and congestion control. Finally, it provides a list of 10 experiments that will be conducted, which cover topics like data link layer framing, CRC polynomials, flow control, routing algorithms, encryption, and congestion control.

Uploaded by

nikksssss666
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
97 views

Cn-Lab-Manual SREYAS

The document provides a syllabus for a Computer Networks Lab course. It outlines the course objectives which are to understand communication protocols, network simulators, and traffic flow analysis. It also lists the course outcomes, which include implementing various layers of the network, analyzing error detection/correction codes, and network design concepts like routing and congestion control. Finally, it provides a list of 10 experiments that will be conducted, which cover topics like data link layer framing, CRC polynomials, flow control, routing algorithms, encryption, and congestion control.

Uploaded by

nikksssss666
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 51

COMPUTER NETWORKS LAB (CS506PC)

SYLLABUS

IIIB Tech I-Sem A.Y: 2023-2024

Course Objectives

1. To understand the working principle of various communication protocols.


2. To understand the network simulator environment and visualize a network topology and observe its performance
3. To analyze the traffic flow and the contents of protocol frames

Course Outcomes

1. Implement data link layer farming methods


2. Analyze error detection and error correction codes.
3. Implement and analyze routing and congestion issues in network design.
4. Implement Encoding and Decoding techniques used in presentation layer
5. To be able to work with different network tools

LIST OF EXPERIMENTS

1. Implement the data link layer farming methods such as


a. Character stuffing
b. Bit stuffing
2. Implement on a data set of characters the three CRC polynomials – CRC 12, CRC 16 and CRC CCIP

3. Develop a simple data link layer that performs the flow control using the sliding window protocol, and loss recovery
using the Go-Back-N mechanism

4. Implement Dijkstra„s algorithm to compute the Shortest path thru a given graph.

5. Implement broadcast tree for a given subnet of hosts

6. Obtain Routing table at each node using distance vector routing algorithm for a given subnet.

7. Implement data encryption and data decryption

8. Write a program for congestion control using Leaky bucket algorithm

9. Write a program for frame sorting technique used in buffers

Sreyas Institute Of Engineering And Technology


INDEX

Experiment No. Name of the Experiment PageNo.


EX PER IME N T 1 Implement the datalinklayerfarmingmethodssuchasBi
tstuffing
EX PER IME N T 2 ImplementthedatalinklayerfarmingmethodssuchasCharact
erstuffing
EXP E RI M E NT 3 Implement on a data set of characters the three CRC
polynomials – CRC 12, CRC 16 and CRC CCIP

EXPERIMENT 4 Develop a simple data link layer that performs the flow control
using the sliding window protocol, and loss recovery using the
Go-Back-N mechanism

EXPERIMENT 5 Implement Dijkstra„s algorithm to compute the Shortest path


thru a given graph

EXPERIMENT 6 Implement broadcast tree for a given subnet of hosts

EX PER IME N T 7 Obtain Routing table at each node using distance vector routing
algorithm for a given subnet.

EXPERIMENT 8 Implement data encryption and data decryption

EXPERIMENT 9 Write a program for congestion control using Leaky bucket


algorithm

EXPERIMENT 10 Write a program for frame sorting technique used in buffers

Sreyas Institute Of Engineering And Technology


EXPERIMENT NO: 1.
1. Implement the data link layer framing methods such as character, character stuffing and bit stuffing.

NAME OF THE EXPERIMENT: Bit Stuffing.

AIM: Implement the data link layer framing methods such as and bit stuffing.

HARDWARE REQUIREMENTS: Intel based Desktop PC:- RAM of 512 MB

SOFTWARE REQUIREMENTS: Turbo C / Borland C.

THEORY:
The new technique allows data frames to contain an arbitrary number if bits and allows character codes with an
arbitrary no of bits per character. Each frame begins and ends with special bit pattern, 01111110, called a flag byte.
When ever the senders data link layer encounters five consecutive one‟s in the data, it automatically stuffs a 0 bit
into the out going bit stream. This bit stuffing is analogous to character stuffing, in which a DLE is stuffed into the
out going character stream before DLE in the data

ALGORITHM:

Begin
Step 1: Read frame length n
Step 2: Repeat step (3 to 4) until i<n(: Read values in to the input frame (0‟s and 1‟s) i.e.
Step 3: initialize I i=0;
Step 4: read a[i] and increment i
Step 5: Initialize i=0, j=0,count =0
Step 6: repeat step (7 to 22) until i<n
Step 7: If a[i] == 1 then
Step 8: b[j] = a[i]
Step 9: Repeat step (10 to 18) until (a[k] =1 and k<n and count <5)
Step 10: Initialize k=i+1;
Step 11: Increment j and b[j]= a[k];
Step 12: Increment count ;
Step 13: if count =5 then
Step 14: increment j,
Step 15: b[j] =0
Step 16: end if
Step 17: i=k;
Step 18: increment k
Step 19: else
Step 20: b[j] = a[i]
Step 21: end if
Step 22: increment I and j
Step 23: print the frame after bit stuffing
Step 24: repeat step (25 to 26) until i< j
Step 25: print b[i]
Step 26: increment i
End

CREATE THE NAME OF THE PROGRAM

[m0033@agni cnlabprograms]$ vi exp1a.c

SOURCE CODE:

// BIT Stuffing program

#include<stdio.h>
#include<string.h>
void main()
{
int a[20],b[30],i,j,k,count,n;
printf("Enter frame length:");
scanf("%d",&n);
printf("Enter input frame (0's & 1's only):");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
i=0; count=1; j=0;
while(i<n)
{
if(a[i]==1)
{
b[j]=a[i];
for(k=i+1;a[k]==1 && k<n && count<5;k++)

Sreyas Institute Of Engineering And Technology


{
j++;
b[j]=a[k]; count+
+; if(count==5)
{
j++;
b[j]=0;
}
i=k;
}
}
else
{

b[j]=a[i];
} i+
+;
j++;
}
printf("After stuffing the frame is:");
for(i=0;i<j;i++)
printf("%d",b[i]);
}
COMPILE THE PROGRAM:
[m0033@agni cnlabprograms]$ cc exp1a.c

OUTPUT

[m0033@agni cnlabprograms]$ ./a.out

Enter frame length:12

Enter input frame (0's & 1's only):

Sreyas Institute Of Engineering And Technology


1

After stuffing the frame is: 1111101111111

VIVA QUESTIONS:

1. What is bit stuffing?


2. What is the use of bit stuffing?
3. with bit stuffing the boundary b/w 2 frames can be unambiguously recognized by ------------------------
4. is analogous to character stuffing
5. Each frame begins and ends with a special bit pattern 01111110 called ---------
6. The senders data link layer encounters ----------------no of 1‟s consecutively

Sreyas Institute Of Engineering And Technology


EXPERIMENT NO: 2

NAME OF THE EXPERIMENT: Character Stuffing.

AIM: Implement the data link layer framing methods such as character, character stuffing.

HARDWARE REQUIREMENTS: Intel based Desktop PC:-


RAM of 512 MB

SOFTWARE REQUIREMENTS: Turbo C / Borland C.

THEORY:
The framing method gets around the problem of resynchronization after an error by having each frame start with the
ASCII character sequence DLE STX and the sequence DLE ETX. If the destination ever losses the track of the
frame boundaries all it has to do is look for DLE STX or DLE ETX characters to figure out. The data link layer on
the receiving end removes the DLE before the data are given to the network layer. This technique is called character
stuffing

ALGORITHM:
Begin
Step 1: Initialize I and j as 0
Step 2: Declare n and pos as integer and a[20],b[50],ch as character
Step 3: read the string a
Step 4: find the length of the string n, i.e n-strlen(a)
Step 5: read the position, pos
Step 6: if pos > n then
Step 7: print invalid position and read again the position, pos
Step 8: end if
Step 9: read the character, ch
Step 10: Initialize the array b , b[0…5] as ‟d‟, ‟l‟, ‟e‟, ‟s‟ ,‟t‟ ,‟x‟
respectively
Step 11: j=6;
Step 12: Repeat step[(13to22) until i<n
Step 13: if i==pos-1 then
Step 14: initialize b array,b[j],b[j+1]…b[j+6] as„d‟, „l‟, „e‟ ,‟ch, ‟d‟, „l‟,„e‟
respectively

Sreyas Institute Of Engineering And Technology


Step 15: increment j by 7, i.e j=j+7
Step 16: end if
Step 17: if a[i]==‟d‟ and a[i+1]==‟l‟ and a[i+2]==‟e‟ then
Step 18: initialize array b, b[13…15]=‟d‟, „l‟, „e‟ respectively
Step 19: increment j by 3, i.e j=j+3
Step 20: end if
Step 21: b[j]=a[i]
Step 22: increment I and j;
Step 23: initialize b array,b[j],b[j+1]…b[j+6] as„d‟, „l‟,„e‟ ,‟e‟,„t‟, „x‟,„\0‟
respectively
Step 24: print frame after stiuffing
Step 25: print b
End
CREATE THE PROGRAM NAME

[m0033@agni cnlabprograms]$ vi exp1b.c

SOURCE CODE:
//PROGRAM FOR CHARACTER STUFFING
#include<stdio.h>
#include<string.h>
#include<process.h>
void main()
{
int i=0,j=0,n,pos;
char a[20],b[50],ch;
printf("enter string\n");
scanf("%s",&a);
n=strlen(a);
printf("enter position\n");
scanf("%d",&pos);
if(pos>n)
{
printf("invalid position, Enter again :");
scanf("%d",&pos);
}
printf("enter the character\n");

Sreyas Institute Of Engineering And Technology


scanf("%s",&ch);

b[0]='d';
b[1]='l';
b[2]='e';
b[3]='s';
b[4]='t';
b[5]='x';
j=6;
while(i<n)
{
if(i==pos-1)
{

b[j]='d';
b[j+1]='l';
b[j+2]='e';
b[j+3]=ch;
b[j+4]='d';
b[j+5]='l';
b[j+6]='e';
j=j+7;
}
if(a[i]=='d' && a[i+1]=='l' && a[i+2]=='e')
{
b[j]='d';
b[j+1]='l';
b[j+2]='e';
j=j+3;
}

b[j]=a[i];
i++;
j++;
}
b[j]='d';
b[j+1]='l';

Sreyas Institute Of Engineering And Technology


b[j+2]='e';
b[j+3]='e';
b[j+4]='t';
b[j+5]='x';
b[j+6]='\0';
printf("\nframe after stuffing:\n");
printf("%s",b);
}
COMPILE THE PROGRAM:
[m0033@agni cnlabprograms]$ cc exp1b.c

OUTPUT:
[m0033@agni cnlabprograms]$ ./a.out

enter string

archana

enter position

enter the character

frame after stuffing:

dlestxardlehdlechanadleetx

VIVA QUESTIONS:
1. What is character stuffing?
2. What is the use of character stuffing?
3. is analogous to bit stuffing.
4. are the delimiters for character stuffing
5. Expand DLE STX
6. Expand DLE ETX

Sreyas Institute Of Engineering And Technology


EXPERIMENT NO: 3

NAME OF THE EXPERIMENT: Cyclic Redundancy Check.

AIM: Implement on a data set of characters the three CRC polynomials – CRC 12, CRC 16 and CRC CCIP.

HARDWARE REQUIREMENTS: Intel based Desktop PC:- RAM of 512 MB

SOFTWARE REQUIREMENTS: Turbo C / Borland C.

THEORY:
CRC method can detect a single burst of length n, since only one bit per column will be changed, a burst of length
n+1 will pass undetected, if the first bit is inverted, the last bit is inverted and all other bits are correct. If the block is
badly garbled by a long burst or by multiple shorter burst, the probability that any of the n columns will have the
correct parity that is 0.5. so the probability of a bad block being expected when it should not be 2 power(-n). This
scheme some times known as Cyclic Redundancy Code

ALGORITHM/FLOWCHART:
Begin
Step 1: Declare I,j,fr[8],dupfr[11],recfr[11],tlen,flag,gen[4],genl,frl,
rem[4] as integer
Step 2: initialize frl=8 and genl=4
Step 3: initialize i=0
Step 4: Repeat step(5to7) until i<frl
Step 5: read fr[i]
Step 6: dupfr[i]=fr[i]
Step 7: increment i
Step 8: initialize i=0
Step 9: repeat step(10to11) until i<genl
Step 10: read gen[i]
Step 11: increment i
Step 12: tlen=frl+genl-1
Step 13: initialize i=frl
Step 14: Repeat step(15to16) until i<tlen
Step 15: dupfr[i]=0
Step 16: increment i

Sreyas Institute Of Engineering And Technology


Step 17: call the function remainder(dupfr)
Step 18: initialize i=0
Step 19: repeat step(20 to 21) until j<genl
Step 20: recfr[i]=rem[j]
Step 21: increment I and j
Step 22: call the function remainder(dupfr)
Step 23: initialize flag=0 and i=0
Step 24: Repeat step(25to28) until i<4
Step 25: if rem[i]!=0 then
Step 26: increment flag
Step 27: end if
Step 28: increment i
Step 29: if flag=0 then
Step 25: print frame received correctly
Step 25: else
Step 25: print the received frame is wrong
End
Function: Remainder(int fr[])
Begin
Step 1: Declare k,k1,I,j as integer
Step 2: initialize k=0;
Step 3: repeat step(4 to 14) until k< frl
Step 4: if ((fr[k] == 1) then
Step 5: k1=k
Step 6: initialize i=0, j=k
Step 7: repeat step(8 to 9) until i< genl
Step 8: rem[i] =fr[j] exponential gen[i]
Step 9: increment I and j
Step 10: initialize I = 0
Step 11: repeat step(12to13) until I <genl
Step 12: fr[k1] = rem[i]
Step 13: increment k1 and i
Step 14: end if
End
CREATE THE PROGRAM NAME
[m0033@agni cnlabprograms]$ vi exp2.c

SOURCE CODE:

Sreyas Institute Of Engineering And Technology


//PROGRAM FOR CYCLIC REDUNDENCY CHECK
#include<stdio.h>
int gen[4],genl,frl,rem[4];
void main()
{
int i,j,fr[8],dupfr[11],recfr[11],tlen,flag;
frl=8; genl=4;
printf("enter frame:");
for(i=0;i<frl;i++)
{
scanf("%d",&fr[i]);
dupfr[i]=fr[i];
}
printf("enter generator:");
for(i=0;i<genl;i++)
scanf("%d",&gen[i]);

tlen=frl+genl-1;
for(i=frl;i<tlen;i++)
{
dupfr[i]=0;
}
remainder(dupfr);

for(i=0;i<frl;i++)
{
recfr[i]=fr[i];
}
for(i=frl,j=1;j<genl;i++,j++)
{
recfr[i]=rem[j];
}

remainder(recfr);
flag=0;
for(i=0;i<4;i++)
{

Sreyas Institute Of Engineering And Technology


if(rem[i]!=0)
flag++;
}
if(flag==0)
{
printf("frame r eceived correctly");
}
else
{

printf("the received frame is wrong");


}

remainder(int fr[])
{
int k,k1,i,j;
for(k=0;k<frl;k++)
{
if(fr[k]==1)
{
k1=k; for(i=0,j=k;i<genl;i+
+,j++)
{
rem[i]=fr[j]^gen[i];
}

for(i=0;i<genl;i++)
{
fr[k1]=rem[i];
k1++;
}
}
}
}

Sreyas Institute Of Engineering And Technology


COMPILE THE PROGRAM
[m0033@agni cnlabprograms]$ cc exp2.c

OUTPUT:

[m0033@agni cnlabprograms]$ ./a.out

enter frame:1

enter generator:1

frame received correctly

[m0033@agni cnlabprograms]$ ./a.out

enter frame:1

enter generator:1

Sreyas Institute Of Engineering And Technology


0

the received frame is wrong

PROG -2

// Include headers
#include<stdio.h>
#include<string.h>
// length of the generator polynomial
#define N strlen(gen_poly)
// data to be transmitted and received
char data[28];
// CRC value
char check_value[28];
// generator polynomial
char gen_poly[10];
// variables
int data_length,i,j;
// function that performs XOR operation
void XOR(){
// if both bits are the same, the output is 0
// if the bits are different the output is 1
for(j = 1;j < N; j++)
check_value[j] = (( check_value[j] == gen_poly[j])?'0':'1');
}
// Function to check for errors on the receiver side
void receiver(){
// get the received data
printf("Enter the received data: ");
scanf("%s", data);
printf("\n-----------------------------\n");
printf("Data received: %s", data);
// Cyclic Redundancy Check
crc();
// Check if the remainder is zero to find the error
for(i=0;(i<N-1) && (check_value[i]!='1');i++);
if(i<N-1)

Sreyas Institute Of Engineering And Technology


printf("\nError detected\n\n");
else
printf("\nNo error detected\n\n");
}
void crc(){
// initializing check_value
for(i=0;i<N;i++)
check_value[i]=data[i];
do{
// check if the first bit is 1 and calls XOR function
if(check_value[0]=='1')
XOR();
// Move the bits by 1 position for the next computation
for(j=0;j<N-1;j++)
check_value[j]=check_value[j+1];
// appending a bit from data
check_value[j]=data[i++];
}while(i<=data_length+N-1);
// loop until the data ends
}
int main()
{
// get the data to be transmitted
printf("\nEnter data to be transmitted: ");
scanf("%s",data);
printf("\n Enter the Generating polynomial: ");
// get the generator polynomial
scanf("%s",gen_poly);
// find the length of data
data_length=strlen(data);
// appending n-1 zeros to the data
for(i=data_length;i<data_length+N-1;i++)
data[i]='0';
printf("\n----------------------------------------");
// print the data with padded zeros
printf("\n Data padded with n-1 zeros : %s",data);
printf("\n----------------------------------------");
// Cyclic Redundancy Check
crc();

Sreyas Institute Of Engineering And Technology


// print the computed check value
printf("\nCRC or Check value is : %s",check_value);
// Append data with check_value(CRC)
for(i=data_length;i<data_length+N-1;i++)
data[i]=check_value[i-data_length];
printf("\n----------------------------------------");
// printing the final data to be sent
printf("\n Final data to be sent : %s",data);
printf("\n----------------------------------------\n");
// Calling the receiver function to check errors
receiver();
return 0;
}
OUT PUT:
Enter data to be transmitted: 1001101
Enter the Generating polynomial: 1011
Data padded with n-1 zeros : 1001101000
CRC or Check value is : 101
Final data to be sent : 1001101101
Enter the received data: 1001101101
Data received: 1001101101
No error detected.

VIVA QUESTIONS:
1. What is CRC?
2. What is the use of CRC?
3. Name the CRC standards
4. Define checksum?
5. Define generator polynomial?
6. Polynomial arithmetic is done by

Sreyas Institute Of Engineering And Technology


EXPERIMENT : 4

Develop a simple data link layer that performs the flow control using the sliding window
protocol, and loss recovery using the Go-Back-N mechanism

Solution:

In computer networks sliding window protocol is a method to transmit data on a network. Sliding
window protocol is applied on the Data Link Layer of OSI model. At data link layer data is in the
form of frames. In Networking, Window simply means a buffer which has data frames that needs
to be transmitted.

Both sender and receiver agrees on some window size. If window size=w then after sending w
frames sender waits for the acknowledgement (ack) of the first frame.

As soon as sender receives the acknowledgement of a frame it is replaced by the next frames to
be transmitted by the sender. If receiver sends a collective or cumulative acknowledgement to
sender then it understands that more than one frames are properly received, for eg:- if ack of
frame 3 is received it understands that frame 1 and frame 2 are received properly.

Image Source

In sliding window protocol the receiver has to have some memory to compensate any loss in
transmission or if the frames are received unordered.

Sreyas Institute Of Engineering And Technology


Efficiency of Sliding Window Protocol
η = (W*tx)/(tx+2tp)

W = Window Size

tx = Transmission time
tp = Propagation delay

Sliding window works in full duplex mode

It is of two types:-

1. Selective Repeat: Sender transmits only that frame which is erroneous or is lost.
2. Go back n: Sender transmits all frames present in the window that occurs after the error bit
including error bit also.

Sliding Window Protocol Program in C

#include<stdio.h>

int main()
{
int w,i,f,frames[50];

printf("Enter window size: ");


scanf("%d",&w);

printf("\nEnter number of frames to transmit: ");


scanf("%d",&f);

printf("\nEnter %d frames: ",f);

for(i=1;i<=f;i++)
scanf("%d",&frames[i]);

printf("\nWith sliding window protocol the frames will be sent in the following manner
(assuming no corruption of frames)\n\n");
printf("After sending %d frames at each stage sender waits for acknowledgement sent by the
receiver\n\n",w);

for(i=1;i<=f;i++)
{
if(i%w==0)
{
printf("%d\n",frames[i]);

Sreyas Institute Of Engineering And Technology


printf("Acknowledgement of above frames sent is received by sender\n\n");
}
else
printf("%d ",frames[i]);
}

if(f%w!=0)
printf("\nAcknowledgement of above frames sent is received by sender\n");

return 0;
}

Output :

Enter window size: 3


Enter number of frames to transmit: 5
Enter 5 frames: 12 5 89 4 6
With sliding window protocol the frames will be sent in the following manner (assuming no
corruption of frames)
After sending 3 frames at each stage sender waits for acknowledgement sent by the receiver
12 5 89
Acknowledgement of above frames sent is received by sender
46
Acknowledgement of above frames sent is received by sender

Sreyas Institute Of Engineering And Technology


EXPERIMENT NO: 5

NAME OF THE EXPERIMENT: Shortest Path.

AIM: Implement Dijkstra„s algorithm to compute the Shortest path thru a given graph.

HARDWARE REQUIREMENTS: Intel based Desktop PC:- RAM of 512 MB

SOFTWARE REQUIREMENTS: Turbo C / Borland C.

THEORY:

ALGORITHM/FLOWCHART:

Begin
Step1: Declare array path [5] [5], min, a [5][5], index, t[5];
Step2: Declare and initialize st=1,ed=5
Step 3: Declare variables i, j, stp, p, edp
Step 4: print “enter the cost “
Step 5: i=1
Step 6: Repeat step (7 to 11) until (i<=5)
Step 7: j=1
Step 8: repeat step (9 to 10) until (j<=5)
Step 9: Read a[i] [j]

Sreyas Institute Of Engineering And Technology


Step 10: increment j
Step 11: increment i
Step 12: print “Enter the path”
Step 13: read p
Step 14: print “Enter possible paths”
Step 15: i=1
Step 16: repeat step(17 to 21) until (i<=p)
Step 17: j=1
Step 18: repeat step(19 to 20) until (i<=5)
Step 19: read path[i][j]
Step 20: increment j
Step 21: increment i
Step 22: j=1
Step 23: repeat step(24 to 34) until(i<=p)
Step 24: t[i]=0
Step 25: stp=st
Step 26: j=1
Step 27: repeat step(26 to 34) until(j<=5)
Step 28: edp=path[i][j+1]
Step 29: t[i]= [ti]+a[stp][edp]
Step 30: if (edp==ed) then
Step 31: break;
Step 32: else
Step 33: stp=edp
Step 34: end if
Step 35: min=t[st]
Step 36: index=st
Step 37: repeat step( 38 to 41) until (i<=p)
Step 38: min>t[i]
Step 39: min=t[i]
Step 40: index=i
Step 41: end if
Step 42: print” minimum cost” min
Step 43: print” minimum cost pth”
Step 44: repeat step(45 to 48) until (i<=5)
Step 45: print path[index][i]
Step 46: if(path[idex][i]==ed) then

Sreyas Institute Of Engineering And Technology


Step 47: break
Step 48: end if
End
CREATE THE PROGRAM NAME
[m0033@agni cnlabprograms]$ vi exp3.c

SOURCE CODE:
//*********************************
//5 .PROGRAM FOR FINDING SHORTEST //PATH FOR A GIVEN GRAPH
//*********************************

#include<stdio.h>
void main()
{
int path[5][5],i,j,min,a[5][5],p,st=1,ed=5,stp,edp,t[5],index;
printf("enter the cost matrix\n");
for(i=1;i<=5;i++)
for(j=1;j<=5;j++)
scanf("%d",&a[i][j]);
printf("enter the paths\n");
scanf("%d",&p);
printf("enter possible paths\n");
for(i=1;i<=p;i++)
for(j=1;j<=5;j++)
scanf("%d",&path[i][j]);
for(i=1;i<=p;i++)
{ t[i]=
0;
stp=st;
for(j=1;j<=5;j++)
{
edp=path[i][j+1];
t[i]=t[i]+a[stp][edp];
if(edp==ed)
break;
else

Sreyas Institute Of Engineering And Technology


stp=edp;
}
}
min=t[st];index=st;
for(i=1;i<=p;i++)
{
if(min>t[i])
{
min=t[i];
index=i;
}
}
printf("minimum cost %d",min);
printf("\n minimum cost path ");
for(i=1;i<=5;i++)
{
printf("--> %d",path[index][i]);
if(path[index][i]==ed)
break;
}
}
COMPILE THE PROGRAM
[m0033@agni cnlabprograms]$ cc exp3.c

OUTPUT:
[m0033@agni cnlabprograms]$ ./a.out

enter the cost matrix

01420

10370

43050

27506

00060

enter the paths

Sreyas Institute Of Engineering And Technology


enter possible paths

12345

12450

13450

14500

minimum cost 8

minimum cost path --> 1--> 4--> 5

VIVA QUESTIONS:

1. Write the logic for shortest path?


2. DVR stands for ?
3. What is the purpose of router?
4. Write any two types of router names?
5. Define static routing?
6. In which layer router is available?

Sreyas Institute Of Engineering And Technology


EXPERIMENT NO: 6

NAME OF THE EXPERIMENT: Broadcast Tree.

AIM: Implement broadcast tree for a given subnet of hosts

Fig: Broadcast Tree

HARDWARE REQUIREMENTS: Intel based Desktop PC:- RAM of 512 MB

SOFTWARE REQUIREMENTS: Turbo C / Borland C.

THEORY:
This technique is widely used because it is simple and easy to understand. The idea of this algorithm is to build a
graph of the subnet with each node of the graph representing a router and each arc of the graph representing a
communication line. To choose a route between a given pair of routers the algorithm just finds the broadcast
between them on the graph.

ALGORITHM/FLOWCHART:

Sreyas Institute Of Engineering And Technology


step 1: declare variable as int p,q,u,v,n;
step 2: Initialize min=99,mincost=0;
step 3: declare variable as int t[50][2],i,j;
step 4: declare variable as int parent[50],edge[50][50];
step 5: Begin
step 6: write "Enter the number of nodes"
step 7: read "n"
step 8: Initialize i=0
step 9: repeat step(10-12) until i<n
step10: increment i
step11: write"65+i"
step12: Initialize parent[i]=-1
step13:wite "\n"
step14: Initialize i=0
step15: repeat step(15-21) until i<n
step16: increment i
step17: write"65+i"
step18: Initialize j=0
step19: repeat until j<n
step20: increment j
step21: read edge[i][j]
step22: Initialize i=0
step23: repeat step(23-43) until i<n
step24: increment i
step25: Initialize j=0
step26: repeat until j<n
step27: increment j
step28: if'edge[i]j]!=99
step29: if'min>edge[i][j] repeat step (29-32)
step30: intialize min=edge[i][j]
step31: intialize u=i
step32: intialize v=j
step33: calling function p=find(u);
step34: calling function q=find(v);
step35: if'P!=q repeat steps(35-39)
step36: intialize t[i][0]=u

Sreyas Institute Of Engineering And Technology


step37: intialize t[i][1]=v
step38: initialize mincost=mincost+edge[u][v]
step39: call function sunion(p,q)
step40: else repeat steps(40-42)
step41: Intialize t[i][0]=-1;
step42: Intialize t[i][1]=-1;
step43: intialize min=99;
step44; write"Minimum cost is %d\n Minimum spanning tree is",mincost
step45: Initialize i=0
step46: repeat until i<n
step47: increment i
step48: if't[i][0]!=-1 && t[i][1]!=-1'repeat step(48-50)
step49: write "%c %c %d", 65+t[i][0], 65+t[i][1], edge[t[i][0]][t[i][1]]
step50: write"\n"
step51: end
step52: called function sunion(int l,int m) repeat step(51-52)
step53: intialize parent[l]=m
step54: called function find(int l) repeat step(53-56)
step55: if parent([l]>0)
step56: initialize l=parent
step57: return l
COMPILE THE PROGRAM NAME
[m0033@agni cnlabprograms]$ vi exp5.c

SOURCE CODE:

// Write a „c‟ program for Broadcast tree from subnet of host

#include<stdio.h>
int p,q,u,v,n;
int min=99,mincost=0;
int t[50][2],i,j;
int parent[50],edge[50][50];
main()
{
printf("\n Enter the number of nodes");
scanf("%d",&n);
for(i=0;i<n;i++)

Sreyas Institute Of Engineering And Technology


{
printf("%c\t",65+i);
parent[i]=-1;
}
printf("\n");
for(i=0;i<n;i++)
{
printf("%c",65+i);
for(j=0;j<n;j++)
scanf("%d",&edge[i][j]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
if(edge[i][j]!=99)
if(min>edge[i][j])
{
min=edge[i][j];
u=i;
v=j;
}
p=find(u);
q=find(v);
if(p!=q)
{ t[i]
[0]=u;
t[i][1]=v;
mincost=mincost+edge[u][v];
sunion(p,q);
}
else
{
t[i][0]=-1;
t[i][1]=-1;
}
min=99;
}

Sreyas Institute Of Engineering And Technology


printf("Minimum cost is %d\n Minimum spanning tree is\n" ,mincost);
for(i=0;i<n;i++)
if(t[i][0]!=-1 && t[i][1]!=-1)
{
printf("%c %c %d", 65+t[i][0], 65+t[i][1],
edge[t[i][0]][t[i][1]]);
printf("\n");
}
}
sunion(int l,int m)
{
parent[l]=m;
}
find(int l)
{
if(parent[l]>0)
l=parent[l];
return l;
}
COMPILE THE PROGRAM
[m0033@agni cnlabprograms]$ cc exp5.c
OUTPUT:

[m0033@agni cnlabprograms]$ ./a.out

Enter the number of nodes 4

A B C D

A 1 3 5 6

B 6 7 8 9

C 2 3 5 6

D 1 2 3 7

Minimum cost is 9

Minimum spanning tree is

BA6

Sreyas Institute Of Engineering And Technology


CA2

DA1

VIVA QUESTIONS:
1. what is spanning tree
2. what is broad cast tree
3. what are the advantages of broad cast tree
4. where we should use the broad cast tree
5. what is flooding
6. what is the subnet

Sreyas Institute Of Engineering And Technology


EXPERIMENT NO: 7

NAME OF THE EXPERIMENT: Distance Vector routing.

AIM: Obtain Routing table at each node using distance vector routing algorithm for a given subnet.

HARDWARE REQUIREMENTS: Intel based Desktop PC:- RAM of 512 MB

SOFTWARE REQUIREMENTS: Turbo C / Borland C.

THEORY:
Distance Vector Routing Algorithms calculate a best route to reach a destination based solely on distance. E.g. RIP.
RIP calculates the reach ability based on hop count. It‟s different from link state algorithms which consider some
other factors like bandwidth and other metrics to reach a destination. Distance vector routing algorithms are not
preferable for complex networks and take longer to converge.

#include<stdlib.h>
#define NUL 1000
#define NODES 10
struct node
{
int t[NODES][3];
};
struct node n[NODES];
typedef struct node NOD;
int main()
{
void init(int,int);
void inp(int,int);
void caller(int,int);
void
op1(int,int,int);
void find(int,int);
int i,j,x,y,no;
clrscr();
do{
printf("\n Enter the no of nodes required:");
scanf("%d",&no);
}while(no>10||no<0);
for(i=0;i<no;i++)

Sreyas Institute Of Engineering And Technology


{
init(no,i);
inp(no,i);
}
printf("\nThe configuration of the nodes after initalization is
as follows:");
for(i=0;i<no;i++)
op1(no,i,0);
for(j=0;j<no;j++)
{
for(i=0;i<no;i++)
caller(no,i);
}
printf("\nThe config of the nodes after the comp of the paths is as
follows:");
for(i=0;i<no;i++)
op1(no,i,1);
while(1)
{
printf("\n Enter 0 to exit or any other key to find the
shortest path:");
scanf("%d",&j);
if(!j)
break;
clrscr();
do{
printf("\n Enter the nodes btn which path is to be found
:");
scanf("%d%d",&x,&y);
}while((x<0||x>no) && (y<0||y>no));
printf("\nThe most suitable route from node %d to %d is as
follows\n",x,y);
find(x,y);
printf("%d",y);
printf("\nTheleng oftheshortestpath btn node%d & %dis%d",x,y,n[x1].t[y-1][2]);
}
}
void init(int no,int x)
{
int i;
for(i=0;i<no;i++)
{
n[x].t[i][1]=i;
n[x].t[i][2]=999;
n[x].t[i][3]=NUL;
}

Sreyas Institute Of Engineering And Technology


n[x].t[x][2]=0;
n[x].t[x][3]=x;
}
void inp(int no,int x)
{
int i;
printf("\nEnter the dists from the nodes %d to other
node...",x+1);
printf("\nPls enter 999 if there is no direct \n");
for(i=0;i<no;i++)
{
if(i!=x)
{
do
{
printf("\n Enter dist to node %d=",i+1);
scanf("%d",&n[x].t[i][2]);
}while(n[x].t[i][2]<0|| n[x].t[i][2]>999);
if(n[x].t[i][2]!=999)
n[x].t[i][3]=i;
}}
}
void caller(int no,int x)
{
void compar(int,int,int);
int i;
for(i=0;i<no;i++)
{
if(n[x].t[i][2]!=999 && n[x].t[i][2]!=0)
{
compar(x,i,no);
}
}
}
void compar(int x,int y,int no)
{
int i,z;
for(i=0;i<no;i++)
{
z=n[x].t[y][2]+n[y].t[i][2];
if(n[x].t[i][2]>z)
{
n[x].t[i][2]=z;
n[x].t[i][3]=y;
}
}

Sreyas Institute Of Engineering And Technology


}
void op1(int no,int x,int z)
{
int i,j;
printf("\n The routing table for node no %d is as follows",x+1);
printf("\n\n\t\t\tDESTINATION\tDISTANCE\tNEXT_HOP");
for(i=0;i<no;i++)
{
if((!z && n[x].t[i][2]>=999) ||(n[x].t[i][2]>=(999*no)))
printf("\n\t\t\t %d \tNO LINK \t NO HOP",n[x].t[i][1]+1);
else
if(n[x].t[i][3]==NUL)
printf("\n\t\t\t %d \t %d \t NO OP",n[x].t[i][1]+1,n[x].t[i][2]);
else
printf("\n\t\t\t %d \t %d
\t%d",n[x].t[i][1]+1,n[x].t[i][2],n[x].t[i][3]+1);
}
getch();
}
void find(int x,int y)
{
int i,j;
i=x-1;
j=y-1;
printf("%d-->",x);
if(n[i].t[j][3]!=j)
{
find(n[i].t[j][3]+1,y);
return;
}
}

OUTPUT
Enter the dists from the nodes 1 to other node...
Pls enter 999 if there is no direct
/* Enter dist to node 2=3
Enter dist to node 3=8
Enter dist to node 4=6
Enter dist to node 5=999
Enter the dists from the nodes 2 to other node...
Pls enter 999 if there is no direct
Enter dist to node 1=3
Enter dist to node 3=999

Sreyas Institute Of Engineering And Technology


Enter dist to node 4=7
Enter dist to node 5=5
Enter the dists from the nodes 3 to other node...
Pls enter 999 if there is no direct
Enter dist to node 1=8
Enter dist to node 2=999
Enter dist to node 4=9
Enter dist to node 5=999
Enter the dists from the nodes 4 to other node...
Pls enter 999 if there is no direct
Enter dist to node 1=6
Enter dist to node 2=7
Enter dist to node 3=9
Enter dist to node 5=1
Enter the dists from the nodes 5 to other node...
Pls enter 999 if there is no direct
Enter dist to node 1=999
Enter dist to node 2=5
Enter dist to node 3=999
Enter dist to node 4=1
The configuration of the nodes after initalization is as follows:
The routing table for node no 1 is as follows
DESTINATION DISTANCE NEXT_HOP
101
232
383
464
5 NO LINK NO HOP
The routing table for node no 2 is as follows
DESTINATION DISTANCE NEXT_HOP
131
202
3 NO LINK NO HOP
474
555
The routing table for node no 3 is as follows
DESTINATION DISTANCE NEXT_HOP

Sreyas Institute Of Engineering And Technology


181
2 NO LINK NO HOP
303
494
5 NO LINK NO HOP
The routing table for node no 4 is as follows
DESTINATION DISTANCE NEXT_HOP
161
272
393
404
515
The routing table for node no 5 is as follows
DESTINATION DISTANCE NEXT_HOP
1 NO LINK NO HOP
252
3 NO LINK NO HOP
414
505
515
The config of the nodes after the completion of the paths is as
follows:
The routing table for node no 1 is as follows

DESTINATION DISTANCE NEXT_HOP


101
232
383
464
574
The routing table for node no 2 is as follows

DESTINATION DISTANCE NEXT_HOP


131
202
3 11 1
465

Sreyas Institute Of Engineering And Technology


555
The routing table for node no 3 is as follows

DESTINATION DISTANCE NEXT_HOP


181
2 11 1
303
494
5 10 4
The routing table for node no 4 is as follows

DESTINATION DISTANCE NEXT_HOP


161
265
393
404
515
The routing table for node no 5 is as follows

DESTINATION DISTANCE NEXT_HOP


174
252
3 10 4
414
505
Enter 0 to exit or any other key to find the shortest path:
Enter the nodes btn which path is to be found :1 5

The most suitable route from node 1 to 5 is as follows


1-->4-->5
The length of the shortest path btn node 1 & 5 is 7
Enter 0 to exit or any other key to find the shortest path:0

COMPILE THE PROGRAM


[m0033@agni cnlabprograms]$ cc exp4.c

OUTPUT:

Sreyas Institute Of Engineering And Technology


[m0033@agni cnlabprograms]$ ./a.out

Enter the number of nodes : 3

Enter the cost matrix :

024

204

450

State value for router 1 is

node 1 via 1 Distance0

node 2 via 2 Distance2

node 3 via 3 Distance4

State value for router 2 is

node 1 via 1 Distance2

node 2 via 2 Distance0

node 3 via 3 Distance4

State value for router 3 is

node 1 via 1 Distance4

node 2 via 2 Distance5

node 3 via 3 Distance0

VIVA QUESTIONS:
1. What is routing
2. What is best algorithm among all routing algorithms?
3. What is static routing?
4. Difference between static and dynamic
5. How distance vector routing works
6. What is optimality principle?

Sreyas Institute Of Engineering And Technology


EXPERIMENT : 8

NAME OF THE EXPERIMENT: Implement data encryption and data decryption

AIM: Take a 64 bit playing text and encrypt the same using DES algorithm.

HARDWARE REQUIREMENTS: Intel based Desktop PC:- RAM of 512 MB

SOFTWARE REQUIREMENTS: Turbo C / Borland C.

THEORY:
Data encryption standard was widely adopted by the industry in security products. Plain text is encrypted in blocks
of 64 bits yielding 64 bits of cipher text. The algorithm which is parameterized by a 56 bit key has 19 distinct stages.
The first stage is a key independent transposition and the last stage is exactly inverse of the transposition. The
remaining stages are functionally identical but are parameterized by different functions of the key. The algorithm
has been designed to allow decryption to be done with the same key as encryption

ALGORITHM/FLOWCHART:

Begin
Step1: Initialize as int i,ch,lp;
Step2: Initialize as char cipher[50],plain[50];
Step3: Initialize as char key[50];
Step4: while(1) repeat steps(4-36)
Step5: write "\n-----MENU -----\n"
Step6: write "\n1:Data Encryption\t\n\n2:Data Decryption\t\n\n3:Exit"
Step7: write ("\n\nEnter your choice:"
Step8: read"%d",&ch
Step9: stament switch(ch) repeat steps(9-35)
case 1:
step10: read "\nData Encryption"
step11:read ("\nEnter the plain text:"
step12: fflush(stdin)
step13 : gets(plain)
step14: write "\nEnter the encryption key:"
step15: gets(key)
step16: lp=strlen(key)
step17: Initialize i=0

Sreyas Institute Of Engineering And Technology


step18: repeat until plain[i]!='\0'
step19: increment i
step20: initialize cipher[i]=plain[i]^lp
step21: initialize cipher[i]='\0';
step22: write "\nThe encrypted text is:"
step23: puts(cipher)
step24: break
case 2:
step25: write"\nData decryption"
step26: Initialize i=0
step27: repeat until plain[i]!='\0'
step28: increment i
step29: initialize plain[i]=cipher[i]^lp
step30:write"\nDecrypted text is:"
step32: puts(plain)
step33:break
case 3:
step34:exit(0);
step35: end switch stmt
step36: end while(1)stmt
End

CREATE THE NAME OF THE PROGRAM


[m0033@agni cnlabprograms]$ vi exp6.c

SOURCE CODE:

/*Take a 64 bit playing text and encrypt the same using DES algorithm */
#include<stdio.h>

#include<stdlib.h>

#include<string.h>

void main()

int i,ch,lp;

char cipher[50],plain[50];

Sreyas Institute Of Engineering And Technology


char key[50];

while(1)

printf("\n-----MENU ----- \n");

printf("\n1:Data Encryption\t\n\n2:Data Decryption\t\n\n3:Exit");

printf("\n\nEnter your choice:");

scanf("%d",&ch);

switch(ch)

case 1: printf("\nData Encryption");

printf("\nEnter the plain text:");

fflush(stdin);

scanf("%s",&plain);

printf("\nEnter the encryption key:");

scanf("%s",&key);

lp=strlen(key); for(i=0;plain[i]!='\

0';i++)

cipher[i]=plain[i]^lp;

cipher[i]='\0';

printf("\nThe encrypted text is:");

puts(cipher);

break;

case 2: printf("\nData decryption");

for(i=0;cipher[i]!='\0';i++)

plain[i]=cipher[i]^lp; printf("\

nDecrypted text is:");

puts(plain);

break;

Sreyas Institute Of Engineering And Technology


case 3: exit(0);

COMPILE THE PROGRAM


[m0033@agni cnlabprograms]$ cc exp6.c

OUTPUT:
[m0033@agni cnlabprograms]$ ./a.out

-----MENU-----

1:Data

Encryption

2:Data Decryption

3:Exit

Enter your choice:1

Data Encryption

Enter the plain text:archan

Enter the encryption key:123a

The encrypted text is:evgleje

-----MENU-----

1:Data

Encryption

2:Data Decryption

3:Exit

Enter your choice:2

Data decryption

Decrypted text is:archana

VIVA QUESTIONS:
Sreyas Institute Of Engineering And Technology
1. Expand DES
2. What is cipher text?
3. What is plain text?
4. Define public key?
5. Define encryption?
6. Substitutions are performed by boxes

Sreyas Institute Of Engineering And Technology


EXPERIMENT: 9

Write a program for congestion control using Leaky bucket algorithm

#include<stdio.h>
#include<math.h>
#include<stdlib.h>
void main()
{ int
packets[8],i,j,clk,b_size,o_rate,i_rate,p_sz_rm=0,p_sz,p_time;
clrscr();
for(i=0;i<5;++i)
{ packets[i]=rand()%10;
if(packets[i]==0) --i;
}
printf("Enter output rate:");
scanf("%d",&o_rate);
printf("\nEnter bucket size:");
scanf("%d",&b_size);
for(i=0;i<5;++i)
{ if((packets[i]+p_sz_rm) > b_size)
{ if(packets[i]>b_size)
printf("\nIncoming packet size:%d greater than
bucket capacity\n",packets[i]);
else printf("Bucket size exceeded\n");
}
else
{
p_sz=packets[i];
p_sz_rm+=p_sz;
printf("\n
-\n");
printf("Incoming packet:%d",p_sz); printf("\
nTransmission left:%d\n",p_sz_rm);
p_time=rand()%10;
printf("Next packet will come at %d",p_time);
for(clk=0;clk<p_time&&p_sz_rm>0;++clk)
{
printf("\nTime left %d---No packets to
transmit!!\n",p_time-clk);

Sreyas Institute Of Engineering And Technology


sleep(1);
if(p_sz_rm)
{ printf("Transmitted\n");
if(p_sz_rm<o_rate)
p_sz_rm=0;
else p_sz_rm-=o_rate;
printf("Bytes remaining:%d\n",p_sz_rm);
}
else printf("No packets to transmit\n");
}
}
}
getch();

Output:
Enter output rate:2
Enter bucket size:10

Incoming packet:6
Transmission left:6
Next packet will come at 7
Time left 7 ------- No packets to transmit!!
Transmitted
Bytes remaining:4
Time left 6 ------- No packets to transmit!!
Transmitted
Bytes remaining:2
Time left 5 ------- No packets to transmit!!
Transmitted
Bytes remaining:0

Incoming packet:0
Transmission left:0
Next packet will come at 5

Incoming packet:2
Transmission left:2
Next packet will come at 5

Sreyas Institute Of Engineering And Technology


Time left 5 ------- No packets to transmit!!
Transmitted
Bytes remaining:0

Incoming packet:0
Transmission left:0
Next packet will come at 8

Incoming packet:6
Transmission left:6
Next packet will come at 6
Time left 6 ------- No packets to transmit!!
Transmitted
Bytes remaining:4
Time left 5 ------- No packets to transmit!!
Transmitted
Bytes remaining:2
Time left 4 ------- No packets to transmit!!
Transmitted
Bytes remaining:0

Sreyas Institute Of Engineering And Technology


EXPERIMENT : 9

Write a program for frame sorting technique used in buffers.

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct frame{
int fslno;
char finfo[20];
};
struct frame arr[10];
int n;
void sort()
{
int i,j,ex;
struct frame temp;
for(i=0;i<n;i++)
{
ex=0;
for(j=0;j<n-i-1;j++)
if(arr[j].fslno>arr[j+1].fslno)
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
ex++;
}

if(ex==0) break;
}
}
void main()
{
int i;
clrscr();
printf("\n Enter the number of frames \n");
scanf("%d",&n);
for(i=0;i<n;i++)

Sreyas Institute Of Engineering And Technology


{ arr[i].fslno=random(50);
printf("\n Enter the frame contents for sequence number
%d\n",arr[i].fslno);
scanf("%s",arr[i].finfo);
}
sort();
printf("\n The frames in sequence \n");
for(i=0;i<n;i++)
printf("\n %d\t%s \n",arr[i].fslno,arr[i].finfo);
getch();
}

OUTPUT
Enter the number of frames:10
Enter the frame contents for sequence number 3
institute
Enter the frame contents for sequence number 25
Of
Enter the frame contents for sequence number 8
Technology
Enter the frame contents for sequence number 28
is
Enter the frame contents for sequence number 19
a
Enter the frame contents for sequence number 33
very
Enter the frame contents for sequence number 14
good
Enter the frame contents for sequence number 41
college
Enter the frame contents for sequence number 45
did
Enter the frame contents for sequence number 1
SREYAS
The frames in sequence
1 SREYAS
3 institute
8 technology
14 good

Sreyas Institute Of Engineering And Technology


19 a
25 of
28 is
33 very
41 college

Sreyas Institute Of Engineering And Technology

You might also like