0% found this document useful (0 votes)
80 views66 pages

3-1 CN Lab Manual Naac

The document is a laboratory manual for the Computer Networks Lab course at Raghu Engineering College for the academic year 2022-2023. It outlines the vision and mission of the institute and department, along with program educational objectives, outcomes, and specific outcomes for students. The manual includes course objectives, a list of experiments, and detailed implementations of various communication protocols and error detection techniques.

Uploaded by

mukeshbalaga2003
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)
80 views66 pages

3-1 CN Lab Manual Naac

The document is a laboratory manual for the Computer Networks Lab course at Raghu Engineering College for the academic year 2022-2023. It outlines the vision and mission of the institute and department, along with program educational objectives, outcomes, and specific outcomes for students. The manual includes course objectives, a list of experiments, and detailed implementations of various communication protocols and error detection techniques.

Uploaded by

mukeshbalaga2003
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/ 66

RAGHU ENGINEERING COLLEGE

(Autonomous)
(Approved by AICTE, New Delhi, Permanently Affiliated to JNTU Kakinada,
Accredited by NBA & Accredited by NAAC with A grade)

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

Academic Year: 2022-2023

B.Tech III Year-I Semester (AR20)

STAFF LABORATORY MANUAL


For

COMPUTER NETWORKS Lab (20CS5112)

Prepared by
Mr.K.PavanKumar,Associate Professor,
Dept of CSE
Vision of the Institute:
Envision to be a world class technical institution by synergizing quality educationwith ethical values.

Mission of the Institute:


 To enlist the services of expert faculty.

 To encourage training and research in cutting-edge technologies

 To develop and strengthen strategic linkswith the industry

 To kindle the zeal among the students and promote their quest for academic
excellence

 To encourage extra-curricular activities along with good communication skills

Vision of the Department:


To generate competent professionals to become part of the industry and research
organizations at the national and international levels.

Mission of the Department:


M1: To impart high quality professional training in undergraduate level with emphasis on
basic principles of Computer Science and Engineering and to foster leading edge research in
the fast changing field

M2: To inculcate professional behaviour, strong ethical values values, innovative research
capabilities and leadership abilities in the young minds so as to work with a commitment.

Program Educational Objectives (PEOs):

PEO No. Program Educational Objectives Statements


PEO1 To produce graduates who have strong foundation in mathematics, science, engineering
fundamentals, laboratory and work-based experiences to formulate and solve
engineering problems in computer science engineering domains and shall have
proficiency in implementation software tools and languages
PEO2 To progressively impart training to the students for success in various engineering
positions within the core areas in computer science engineering, computational or
adapting themselves to latest trends by learning themselves
PEO3 To produce graduates having the ability to pursue advanced higher studies and research.
To have professional and communication skills to function as leaders and members of
multi-disciplinary teams in engineering and other industries with strong work ethics,
organizational skills, team work and understand the importance of being athorough
professional
PROGRAM OUTCOMES (POs)
Engineering knowledge: Apply the knowledge of mathematics, science, engineering
fundamentals, and an engineering specialization to the solution of complex engineering
problems.

Problem analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
Design/development of solutions: Design solutions for complex engineering problems
and design system components or processes that meet the specified needs with appropriate
considerationfor the public health and safety, and the cultural, societal, and environmental
considerations.

Conduct investigations of complex problems: Use research-based knowledge and research


methods including design of experiments, analysis and interpretation of data, and
synthesis of the information to provide valid conclusions.

Modern tool usage: Create, select, and apply appropriate techniques, resources, and
modern engineering and IT tools including prediction and modeling to complex
engineering activities withan understanding of the limitations.

The engineer and society: Apply reasoning informed by the contextual knowledge to
assess societal, health, safety, legal and cultural issues and the consequent responsibilities
relevant to the professional engineering practice.

Environment and sustainability: Understand the impact of the professional engineering


solutions in societal and environmental contexts, and demonstrate the knowledge of, and
need for sustainable development.

Ethics: Apply ethical principles and commit to professional ethics and responsibilities
and normsof the engineering practice.

Individual and team work: Function effectively as an individual, and as a member or


leader indiverse teams, and in multidisciplinary settings.

Communication: Communicate effectively on complex engineering activities with the


engineering community and with society at large, such as, being able to comprehend and
write effective reports and design documentation, make effective presentations, and give
and receive clearinstructions.

Project management and finance: Demonstrate knowledge and understanding of the


engineering and management principles and apply these to one’s own work, as a member
and leaderin a team, to manage projects and in multidisciplinary environments.

Life-long learning: Recognize the need for, and have the preparation and ability to
engage inindependent and life-long learning in the broadest context of technological
change.
PROGRAM SPECIFIC OUTCOMES (PSOS)

PSO1:
Apply the concepts and techniques of the Computer Science & Engineering and the
Mathematical foundations in the significant domains to address the complex engineering
problems.
PSO2:
Employ emerging computer languages, computer networks, database management systems
and platforms in developing innovative career prospects as an entrepreneur.

PSO3:

Apply the knowledge of interdisciplinary skills, and domain-specific tools in working


system processes to implement and deploy a quality-based software product to meet
evolving needs.
III - B. Tech., I-Semester (20CS5112)
COMPUTER NETWORKS LAB
Int. Marks Ext. Marks Total Mark L T P C
15 35 50 0 0 3 1.5

Pre-Requisites: Programming Knowledge in C, Data Communication concepts

COURSE OBJECTIVES:
The objectives of this course are,
1. To understand the working principle of various communication protocols.
2. To gain knowledge on the error detecting and error correction techniques in data link layer.
3. To analyze the various routing algorithms.

List of Experiments:
1. Implement the data link layer framing methods such as character count and character
stuffing.
2. Implement the data link layer framing methods such as bit stuffing.
3. Implement the data link layer framing methods such as byte stuffing.
4. Implement the Cyclic Redundancy Check (CRC) of data link layerusing various polynomials like
CRC-CRC 12, CRC 16.
5. Implement the Cyclic Redundancy Check (CRC) of data link layerusing CRC CCIPP.
6. Implement Dijkstra ‘s algorithm to compute the Shortest path through a graph.
7. Consider a subnet graph with weights indicating delay between nodes. Obtain Routing table
at each node using Distance Vector Routing algorithm.
8. Implement Link State Routing algorithm.
9. Implementation of Error Detection techniques.
10. Implementation of Error Correction techniques.
11. Implementation of Stop-and-Wait protocol.
12. Implementation of Goback-N and Selective Repeat protocols.

COURSE OUTCOMES:

S.No Course Outcomes BTL

1 Implementation of different communication protocols. L3

2 Implement the error detection and correction in Data Link Layer. L3

3 Implement the different routing protocols in Network Layer. L3


CO/PO/PSO MAPPING
CO PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2 PSO3
CO1 2 1 3 - - 1 1 1 - - - 2 1 2 1

CO2 2 1 3 - - 1 1 1 - - - 2 1 2 1

CO3 2 1 3 - - 1 1 1 - - - 2 1 2 1

TEXT BOOKS

1. Tanenbaum and David J Wetherall, Computer Networks, 5th Edition, Pearson Edu, 2010
2. Computer Networks: A Top Down Approach, Behrouz A. Forouzan, FirouzMosharraf,McGraw
Hill Education

REFERENCE BOOKS

1. Larry L. Peterson and Bruce S. Davie, “Computer Networks - A Systems Approach” (5thed),
Morgan Kaufmann/ Elsevier, 2011
LIST OF EXPERIMENTS
S.no Name of the Experiment Page no:
1 Parity checker 1
2 Hamming Code 4
3 Vertical Redundancy check 7
4 Longitudinal Redundancy check 11
5 Check Sum 14
6 Cyclic Redundancy check 17
7 Bit Stuffing 20
8 Character Stuffing 23
9 Character Count: a framing method at DLL 26
10 Stop and wait ARQ 28
11 Sliding Window protocol in a noise free channel 35
12 Go Back n:ARQ 40
13 Selective Repeat: ARQ 45
14 Dijkstras Routing algorithm 48
15 Distance Vector Routing algorithm 52
16 Link State Routing algorithm 56
PARITY CHECKER
Aim:
Implementation of parity checker at the destination node using a C program both for EVEN
parity and ODD parity.

Software Requirement:
Online C compiler.

Theory:
 A parity check is an error-correction process in network communication that ensures
data transmissions between communication nodes are accurate.
 In this process, the receiver agrees to use the same even parity bit or odd parity
bit scheme as the sender.
 In an even parity check, parity bits ensure there are an even number of 1s and 0s in
the transmission.
 In an odd parity check, there are an odd number of 1s and 0s in the transmission.
 Once the source transmits data, the number of bits is checked by the receiver.
 If the number of received bits does not match what was agreed upon, it raises a red
flag.
 Example: Imagine a data transfer that looks like this: 1010001. This example has an
odd number of 1s and and even number of 0s.
When an even parity checking is used, a parity bit with value 1 could be added to the
data’s right side to make the number of 1s even -- and the transmission would look
like this: 10100011. If an odd parity check was used, the transmission would look like
this: 10100010.

Source Code:
#include <stdio.h>
int main()
{
char byte[10],ch;
printf("Enter the 8-bit Data:");
scanf("%s",byte);

printf("Enter 'e' for Even parity\n");


printf("Enter 'o' for Odd parity\n");
printf("Enter your choice: ");
scanf(" %c",&ch);

int count=0; //logic to count no.of 1's in received 8-bit Data


for(int i=0;i<8;i++)
if(byte[i]=='1')
count++;

if(ch == 'e'){

1
if(count%2 == 0)
printf("No error in the received Data");
else{
printf("There is an error in the received Data\n");
byte[8]='1';
printf("After error correction the Data is: %s",byte);
}
}

else if(ch == 'o'){


if(count%2 == 1)
printf("No error in the received Data");
else{
printf("There is an error in the received Data\n");
byte[8]='1';
printf("After error correction the Data is: %s",byte);
}
}

else
printf("Invalid Choice");

return 0;
}

Input/Output:

2
Input/Output:
Enter the 8-bit Data:11001100
Enter 'e' for Even parity
Enter 'o' for Odd parity
Enter your choice: e
No error in the received Data

Enter the 8-bit Data:11001101


Enter 'e' for Even parity
Enter 'o' for Odd parity
Enter your choice: e
There is an error in the received Data
After error correction the Data is: 110011011

Enter the 8-bit Data:11001101


Enter 'e' for Even parity
Enter 'o' for Odd parity
Enter your choice: o
No error in the received Data

Enter the 8-bit Data:11001100


Enter 'e' for Even parity
Enter 'o' for Odd parity
Enter your choice:o
There is an error in the received Data
After error correction the Data is: 110011001

3
HAMMING CODE
Aim:
Implementation of Hamming code using a C program to detect and correct the errors at
Destination node.

Software Requirement:
Online C compiler.

Theory:
 Hamming code is a set of error-correction codes that can be used to detect and correct the
errors that can occur when the data is moved or stored from the sender to the receiver.
 Redundant bits – Redundant bits are extra binary bits that are generated and added to the
information-carrying bits of data transfer to ensure that no bits were lost during the data
transfer.
 The number of redundant bits can be calculated using the following formula: 2^r ≥ m + r + 1
where, r = redundant bit, m = data bit
 Suppose the number of data bits is 7, then the number of redundant bits can be calculated
using: = 2^4 ≥ 7 + 4 + 1 Thus, the number of redundant bits= 4 Parity bits –
 A parity bit is a bit appended to a data of binary bits to ensure that the total number of 1’s in
the data is even or odd. Parity bits are used for error detection. There are two types of parity
bits:
 Even parity bit: In the case of even parity, for a given set of bits, the number of 1’s are
counted. If that count is odd, the parity bit value is set to 1, making the total count of
occurrences of 1’s an even number. If the total number of 1’s in a given set of bits is already
even, the parity bit’s value is 0.
 Odd Parity bit – In the case of odd parity, for a given set of bits, the number of 1’s are
counted. If that count is even, the parity bit value is set to 1, making the total count of
occurrences of 1’s an odd number. If the total number of 1’s in a given set of bits is already
odd, the parity bit’s value is 0.
 General Algorithm of Hamming code – The Hamming Code is simply the use of extra
parity bits to allow the identification of an error. Write the bit positions starting from 1 in
binary form (1, 10, 11, 100, etc). All the bit positions that are a power of 2 are marked as
parity bits (1, 2, 4, 8, etc). All the other bit positions are marked as data bits. Each data bit is
included in a unique set of parity bits, as determined its bit position in binary form.
 a. Parity bit 1 covers all the bits positions whose binary representation includes a 1 in the least
significant position (1, 3, 5, 7, 9, 11, etc).
 b. Parity bit 2 covers all the bits positions whose binary representation includes a 1 in the
second position from the least significant bit (2, 3, 6, 7, 10, 11, etc).
 c. Parity bit 4 covers all the bits positions whose binary representation includes a 1 in the
third position from the least significant bit (4–7, 12–15, 20–23, etc).
 d. Parity bit 8 covers all the bits positions whose binary representation includes a 1 in the
fourth position from the least significant bit bits (8–15, 24–31, 40–47, etc).
 e. In general, each parity bit covers all bits where the bitwise AND of the parity position and
the bit position is non-zero. Since we check for even parity set a parity bit to 1 if the total
number of ones in the positions it checks is odd. Set a parity bit to 0 if the total number of
ones in the positions it checks is even.

4
Source Code:
#include<stdio.h>
#include<string.h>
int main()
{
char byte[20];
int cr1=0,cr2=0,cr4=0,cr8=0,r1,r2,r4,r8,binary,len;
printf("Enter the 11-bit code:");
scanf("%s",byte);
len=strlen(byte);

//determining parity bit values


for(int i=len-1,pos=1;i>=0;i--,pos++)
{
char c=byte[i];
if(pos==1||pos==3||pos==5||pos==7||pos==11)
if(c=='1')
cr1++;
if(pos==2||pos==3||pos==6||pos==7||pos==10||pos==11)
if(c=='1')
cr2++;
if(pos==4||pos==5||pos==6||pos==7)
if(c=='1')
cr4++;
if(pos==8||pos==9||pos==10||pos==11)
if(c=='1')
cr8++;
}
r1=cr1%2==0?0:1;
r2=cr2%2==0?0:1;
r4=cr4%2==0?0:1;
r8=cr8%2==0?0:1;

//producing binary number from parity bits


binary=(1000*r8)+(100*r4)+(10*r2)+r1;

5
//convert the binary number into decimal
int decimal = 0, base = 1, rem;
while(binary != 0)
{
rem = binary % 10;
decimal = decimal + (rem*base);
binary = binary / 10;
base=base*2;
}

if(decimal!=0)
{
printf("There is an error at position %d\n",decimal);
if(byte[len-decimal]=='1')
byte[len-decimal]='0';
else
byte[len-decimal]='1';
printf("There data after correction is %s",byte);
}
else
printf("No error in Data");

return 0;
}
Input/Output:

Input/Output:
Enter the 11-bit code:10010100101
There is an error at position 7
There data after correction is 10011100101

Enter the 11-bit code:10011100101


No error in Data

6
VERTICAL REDUNDANCY CHECK
Aim:
Implementation of vertical redundancy check using a c program.

Software Requirement:
Online C compiler.

Theory:
 Vertical redundancy check is an error detecting technique used to detect errors on aneight-
bit ASCII character. To determine either the transmission is correct, a parity bit is
linked to every byte of data.
 Vertical redundancy check only works if an even number of bits is distorted hence it is
not considered as reliable technique for error detection.
 Vertical redundancy check is maintenance of parity bit. An additional bit is added
with original block to ensure that data transmitted correctly. It is also known as parity
check technique.
 Example: Consider a sender sends a data 1 0 0 0 0 0 1 and we count the number of
1’s in data. They are even so we add 0 in the end. The data becomes 1 0 0 0 0 0 1
0.
 In case sender sends a data 1 0 0 0 0 0 1 if it has error and data becomes 1 0 0 0 1 0
1, the parity bit will be added and data become 1 0 0 0 1 0 1 1.
 Whenever even number of bits found in the data during transmission, either there is
an error or not VRC will accept the data and will not detect the error. So this is the
major problem with vertical redundancy check.
 To overcome the problem of vertical redundancy there is another solution called
Longitudinal redundancy check.

Source Code:
#include <stdio.h>
int main()
{

7
char f[4][8];
int i,c=0,j,count;
printf("Enter 4 frames of length 8\n");
for(i=0;i<4;i++)
{
printf("Frame%d: ",i+1);
scanf("%s",f[i]);
}
for(i=0;i<4;i++)
{
count=0;
for(j=0;j<8;j++)
if(f[i][j]=='1')
count++;
if(count%2!=0)
{
printf("There is an error in Frame %d\n",i+1);
c=1;
}
}
if(c==0)
printf("No errors in received data at destination node");
return 0;
}

Input/Output:

8
Input/Output:

Enter 4 frames of length 8


Frame1: 00001111
Frame2: 11001100
Frame3: 11110000
Frame4: 01010101
No errors in received data at destination node

Enter 4 frames of length 8


Frame1: 00110011
Frame2: 11100110
Frame3: 01101101
Frame4: 11110000
There is an error in Frame 2

9
There is an error in Frame 3

10
LONGITUDINAL REDUNDANCY CHECK
Aim:
Implementation of longitudinal redundancy check using a c program.

Software Requirement:
Online C compiler.

Theory:
 a longitudinal redundancy check (LRC) is an error-detection method for
determining the correctness of transmitted and stored data.
 LRC verifies the accuracy of stored and transmitted data using parity bits. It is a
redundancy check applied to a parallel group of bit streams. The data to be
transmitted is divided into transmission blocks into which additional check data is
inserted.
 This term is also known as a horizontal redundancy check.
 The main problem with LRC is that, it is not able to detect error if two bits in a data unit are
damaged and two bits in exactly the same position in other data unit are also damaged.

Source Code:
#include <stdio.h>
int main()
{
char f[4][8];
int i,j,count;
printf("Enter frames of length 8\n");
for(i=0;i<5;i++)
{
printf("Frame%d: ",i);
scanf("%s",f[i]);
}
for(i=0;i<8;i++)
{
count=0;

11
for(j=0;j<5;j++)
if(f[j][i]=='1')
count++;
if(count%2!=0)
{
printf("There is an error in the received data at destination node");
return 0;
}
}
printf("No errors in received data at destination node");
return 0;
}

Input/Output:

12
Input/Output:
Enter frames of length 8
Frame0: 00110011
Frame1: 00001111
Frame2: 11110000
Frame3: 01010101
Frame4: 01011100
There is an error in the received data at destination node

Enter frames of length 8


Frame0: 11100110
Frame1: 00011011
Frame2: 01010101
Frame3: 00101011
Frame4: 10000011
No errors in received data at destination node

13
CHECK SUM
Aim:
Implementation of check sum using a c program.

Software Requirement:
Online C compiler.

Theory:
 Checksum is the error detection method used by upper layer protocols and is considered
to be more reliable than LRC, VRC and CRC. This method makes the use of Checksum
Generator on Sender side and Checksum Checker on Receiver side.
 At the Sender side, the data is divided into equal subunits of n bit length by the checksum
generator.
 This bit is generally of 16-bit length. These subunits are then added together using one’s
complement method. This sum is of n bits. The resultant bit is then complemented. This
complemented sum which is called checksum is appended to the end of original data unit
and is then transmitted to Receiver.

Source Code:
#include<stdio.h>
int main()
{
int i,j,c[8],d[8],e[8];
char f[4][8];
printf("Enter frame of length 8 bits\n");
for(i=0;i<4;i++)
{
printf("Frame%d: ",i+1);
scanf("%s",f[i]);
}
for(i=0;i<8;i++)
{
c[i]=(int)f[0][i]|(int)f[1][i];
d[i]=(int)f[2][i]|(int)f[3][i];
e[i]=c[i]|d[i];
}
for(i=0;i<8;i++)
{
if(e[i]==49)
e[i]=0;
else
e[i]=1;
}
for(i=0;i<8;i++)
{
if(e[i]==1)
{

14
printf("Errors in the received frame in destination");
return 0;
}
}
printf("No errors in the received data frames at destination");
return 0;
}

Input/Output:

15
Input/Output:

Enter frame of length 8 bits


Frame1: 00101001
Frame2: 10111001
Frame3: 00011101
Frame4: 11111111
No errors in the received data frames at destination

Enter frame of length 8 bits


Frame1: 00011100
Frame2: 01010101
Frame3: 10010101
Frame4: 01011101
Errors in the received frame in destination

16
CYCLIC REDUNDANCY CHECK
Aim:
Implementation of cyclic redundancy check using a c program.

Software Requirement:
Online C compiler.

Theory:
 CRC or Cyclic Redundancy Check is a method of detecting accidental changes/errors in the
communication channel.
 CRC uses Generator Polynomial which is available on both sender and receiver side. An
3
example generator polynomial is of the form like x + x + 1. This generator polynomial
2
represents key 1011. Another example is x + 1 that represents key 101.
 The process of modulo-2 binary division is the same as the familiar division process we use
for decimal numbers. Just that instead of subtraction, we use XOR here.
 In each step, a copy of the divisor (or data) is XORed with the k bits of the dividend (or
key).
 The result of the XOR operation (remainder) is (n-1) bits, which is used for the next step
after 1 extra bit is pulled down to make it n bits long.
 When there are no bits left to pull down, we have a result. The (n-1)-bit remainder which is
appended at the sender side.

17
Source Code:
#include<stdio.h>
char exor(char a,char b)
{
if(a=='0' && b=='0' || a=='1' && b=='1')
{
return '0';
}
else
{
return '1';
}
}
int main()
{
int i,j;
char d[4],dd[9];
printf("Enter the divisor : ");
scanf("%s",d);
printf("Enter the dividend : ");
scanf("%s",dd);
i=0;
for(j=0;j<6;j++)
{
if(dd[j]=='0')
{
dd[j]=exor(dd[j],'0');
dd[j+1]=exor(dd[j+1],'0');
dd[j+2]=exor(dd[j+2],'0');
dd[j+3]=exor(dd[j+3],'0');
continue;
}
else
{
dd[j]=exor(dd[j],d[i]);
dd[j+1]=exor(dd[j+1],d[i+1]);
dd[j+2]=exor(dd[j+2],d[i+2]);
dd[j+3]=exor(dd[j+3],d[i+3]);
}
}
if(dd[6]=='0' && dd[7]=='0' && dd[8]=='0')
{
printf("No error !");
}
else
{
printf("Error");
}
return 0;
}

18
Input/Output:

Input/Output:

Enter the divisor : 1101


Enter the dividend : 100100001
NO error !

Enter the divisor : 1011


Enter the dividend : 1001000
Error

19
BIT STUFFING
AIM:
Implementation of Bit Stuffing using a C program at datalink layer of source node
and destination node.

SOFTWARE REQUIREMENT:
Online C Compiler

THEORY:
Bit stuffing is the mechanism of inserting one or mar non-information bits into a
message to be transmitted, to break up the message sequence, for
synchronization purpose.

Mechanism:
->In a data link home, the delimiting flag Sequence generally contains six or more
consecutive 1’s.In order to differentiate the message from the flag in case of the
same sequence , a singe bit is stuffed in the message.
->Whenever a 0 bit is followed by five consecutive1 bits in the message, an extra
0 bit is stuffed at the and of the five 1’s.
->When the receiver receives the message, it removes the stuffed 0’s after each
sequence of five 1’s.The unstuffed message is then sent to the upper layers.
Frame Header − It contains the source and the destination addresses of the
frame.
Payload field − It contains the message to be delivered.
Trailer − It contains the error detection and error correction bits.
Flags − A bit pattern that defines the beginning and end bits in a frame. It is
generally 8-bits. Most protocols use the 8-bit pattern 01111110 as flag.

20
SOURCE CODE:
#include <stdio.h>
#include<string.h>
int main()
{
char bit[50],dup[50];
printf("enter the data existing at network layer of source node is:");
scanf("%s",bit);
strcpy(dup,bit);

//bit stuffing
for(int i=0;i<strlen(dup);i++)
{
if(dup[i]=='1' && dup[i+1]=='1' && dup[i+2]=='1' && dup[i+3]=='1' &&
dup[i+4]=='1')
21
{
int j=strlen(dup)+1;
while(j>i+5)
{
dup[j]=dup[j-1];
j--;
}
dup[i+5]='0';
}
}
printf("Data stuffing done by data link layer of source node is :%s\n",dup);
printf("Data received by data link layer of destination node is :%s\n",dup);
printf("Data received by network layer after bit unstuffing of destination node
is :%s",bit);
return 0;
}
INPUT/OUTPUT:

INPUT/OUTPUT:
enter the data existing at network layer of source node is:0011111111010100011111001
Data stuffing done by data link layer of source node is :001111101110101000111110001
Data received by data link layer of destination node is :001111101110101000111110001
Data received by network layer after bit unstuffing of destination node is
:0011111111010100011111001

CONCLUSION:
Implementation of Bit Stuffing at data link layer of source node and destination node verified.

22
CHARACTER STUFFING
Aim:
Implementation of character stuffing using a c program at datalink layer of source node and
destination node.

Software Requirement:
Online C compiler.

Theory:
 A byte is stuffed in the message to differentiate from the delimiter. This is also called
character-oriented framing.
 If the pattern of the flag byte is present in the message byte, there should be a strategy
so that the receiver does not consider the pattern as the end of the frame. In character
– oriented protocol, the mechanism adopted is byte stuffing.
 In byte stuffing, a special byte called the escape character (ESC) is stuffed before
every byte in the message with the same pattern as the flag byte. If the ESC sequence
is found in the message byte, then another ESC byte is stuffed before it.

Source Code:
#include <stdio.h>
#include<string.h>

23
void decimalToBinary(int n)
{
int bNum[8],i;
for (i=0;n>0;)
{
bNum[i++]=n%2;
n/=2;
}
bNum[i]=0;
for (int j=i;j>=0;j--)
{
printf("%d",bNum[j]);
}
printf(" ");
}
int main()
{
int i,a[10],b[5]={0},rev,esc=11011,flag=1111110;
char ch[10];
printf("Enter the original data: ");
scanf("%s",ch);
for(i=0;i<strlen(ch);i++)
a[i]=(int)ch[i];
printf("\n\nData existing at network layer of source node is: %08d ",flag);
for(i=0;i<strlen(ch);i++)
decimalToBinary(a[i]);
printf("%08d",esc);
printf("\nData after byte stuffing done by data link layer at source node is:%08d %08d
",esc,flag);
for(i=0;i<strlen(ch);i++)
decimalToBinary(a[i]);
printf("%08d %08d",esc,esc);
printf("\nData received by data link layer of destination node is: %08d %08d ",esc,flag);
for(i=0;i<strlen(ch);i++)
decimalToBinary(a[i]);
printf("%08d %08d",esc,esc);
printf("\nData received by the network layer after byte unstuffing is : %08d ",flag);
for(i=0;i<strlen(ch);i++)
decimalToBinary(a[i]);
printf("%08d",esc);
return 0;
}

Input/Output:

24
Input/Output:

Enter the original data: tea


Data existing at network layer of source node is:
01111110 01110100 01100101 01100001 00011011
Data after byte stuffing done by data link layer at source node is:
00011011 01111110 01110100 01100101 01100001 00011011 00011011
Data received by data link layer of destination node is:
00011011 01111110 01110100 01100101 01100001 00011011 00011011
Data received by the network layer after byte unstuffing is :
01111110 01110100 01100101 01100001 00011011

25
CHARACTER COUNT
Aim:
Implementation of Character count concept using a C program at the destination node.

Software Requirement:
Online C compiler.

Theory:
 First framing method uses a field in the header to specify the number of characters in
the frame. When the data link layer at the destination sees the character count, it
knows how many characters follow and hence where the end of the frame is.
 Techniques: The techniques we used to find the start and end frame are − Character
count Flag byte with byte stuffing Starting and ending flag with bit stuffing Encoding
Violation. Now let us see the character count technique.
 Character Count First framing method uses a field in the header to specify the number
of characters in the frame.
 When the data link layer at the destination sees the character count, it knows how
many characters follow and hence where the end of the frame is.
 For Example, Consider a data − 1 2 3 4 5 6 7 8 9 0 1 2 3 Divide this data into three
frames

Explanation:
 Step 1 −Starting header in the frame indicate the character count, so first frame
consists of 5 units of data including that number,
 Step 2 − Second frame header consists of 5 units of data including that number, so
second frame consists of data 5,6,7,8. 8 indicate the end of the frame here.
 Step 3 − Third frame header consists of character count 6 that means the frame
consists of 6 characters including 6. So the data in the third frame is 9, 0,1,2,3.
 Step 4 − My data transfer to the receiver side without any errors.
Source Code:
#include <stdio.h>
#include<string.h>
void decimalToBinary(int num) {
int bNum[8],i;
for (i=0 ;num > 0; ){
bNum[i++] = num % 2;
num /= 2;
}
bNum[i]=0;
for (int j = i; j >= 0; j--)

26
printf("%d", bNum[j]);
printf(" ");
}
int main()
{
char ch[100][100],f=' ';
int i,j,a[100][100],k,tot=0;
printf("Enter original data: ");
for(i=0;f!='\n';i++){
scanf("%[^' '||'\n']c",ch[i]);
f=getchar();
}
k=i;

for(i=0;i<k;i++){
for(j=0;j<strlen(ch[i]);j++)
a[i][j]=(int)ch[i][j];
}

for(i=0;i<k;i++){
printf("%s : ",ch[i]);
for(j=0;j<strlen(ch[i]);j++){
decimalToBinary(a[i][j]);
}
printf(" = %d bits",j*8);
tot+=j*8;
printf("\n");
}
printf("Total number of bits in given data is %d bits",tot);
}
Input/Output:

Input/Output:
Enter original data: apple is red in colour
apple : 01100001 01110000 01110000 01101100 01100101 = 40 bits
is : 01101001 01110011 = 16 bits
red : 01110010 01100101 01100100 = 24 bits
in : 01101001 01101110 = 16 bits
colour : 01100011 01101111 01101100 01101111 01110101 01110010 = 48 bits
Total number of bits in given data is 144 bits

27
STOP AND WAIT ARQ
Aim:
Implementation of Stop and Wait ARQ using a C program in the cases.
Case i: Error free channel(all success)
Case ii: When the received frame us having Error (Assume a frame with error)
Case iii: Acknowledgment is lost (Assume acknowledgment of frame 4 is lost)
Case iv: Frame is Lost (Assume frame 4 is lost)

Software Requirement:
Online C compiler.

Theory:
 The stop and wait ARQ is one of the Sliding Window Protocol strategies that is used
where reliable ordered delivery of the data frames is required.
 The stop and wait ARQ is used for noisy channels or links and it manages the flow
and error control between the sender and the receiver.
 The stop and wait ARQ protocol sends a data frame and then waits for an
acknowledgment or ACK from the receiver.
 The ACK means that the receiver has successfully received the data frame. After the
sender receives the ACK from the receiver, it sends the next data frame. So, there is a
wait and then the next data frame is transmitted so the name came to be Stop and Wait
ARQ protocol.
 In the stop and wait ARQ, both the sender and the receiver have windows of the same
size i.e. 1.
 Primitives of Stop and Wait Protocol
 Sender's side:
 Rule1: Send one data packet at a time.
 Rule2: Send the next packet only after receiving the acknowledgement for the
previous packet.
 Receiver's side:
 Rule 1: Receive and consume data packet.
 Rule 2: After consuming the packet, acknowledgement needs to be sent (Flow
Control).

28
29
Source Code:
#include<stdio.h>
#include<stdbool.h>
#include<string.h>
bool valid(char f[8])
{
int c=0;
for(int i=0;i<8;i++){
if(f[i]=='0' || f[i]=='1')
c++;
}
if(c==8)
return true;
else
return false;
}

int main()
{
int s;
int fcount1=0,fcount2=0,fcount3=0,fcount4=0;
printf("1:ERROR FREE CHANNEL\n2:FRAME WITH ERROR\n3:ACK IS
LOST\n4:FRAME IS LOST\n");
printf("Enter the choice:");
scanf("%d",&s);
switch(s)
{
case 1:
for(int i=1;i<=4;i++){
char f[8];
printf("Enter the value of frame %d:",i);
scanf("%s",f);
printf("ack%d, frame %d is received\n",i,i);
fcount1++;
}
if(fcount1==4)
printf("\nAll frames received successfully");
break;

case 2:
for(int i=1;i<=4;i++){
int e=0;
while(e!=1){
char f[8];
printf("Enter the value of frame %d:",i);
scanf("%s",f);
if(valid(f)){

30
printf("ack%d, frame %d is received\n",i,i);
e=1;
fcount2++;
}
else{
printf("Nack%d-frame %d is in error\n",i,i);
printf("re-enter the value of frame%d\n",i);
e=0;
}
}
}
if(fcount2==4)
printf("\nAll frames received successfully");
break;

case 3:
for(int i=1;i<=4;i++){
int e=0;
while(e!=1){
char f[8];
printf("Enter the value of frame %d:",i);
scanf("%s",f);
if(i<=3){
if(valid(f)){
printf("ack%d, frame %d is received\n",i,i);
e=1;
fcount3++;
}
else{
printf("Error in the received frame\n");
e=0;
}
}
else{
printf("Ack lost...\n");
printf("Re-enter the frame 4:");
scanf("%s",f);
printf("ack%d, frame %d is received\n",i,i);
fcount3++;
e=1;
}
}
}

if(fcount3==4)
printf("\nAll frames received successfully");
break;

case 4:
for(int i=1;i<=4;i++){

31
int e=0;
while(e!=1){
char f[8]={0};
printf("Enter the value of frame %d:",i);
scanf("%s",f);
if(strlen(f)<=1){
printf("Frame %d is missing\n",i);
printf("Re-Enter the Frame\n");
continue;
}
if(valid(f)){
printf("ack%d, frame %d is received\n",i,i);
e=1;
fcount4++;
}
else{
printf("Error in the received frame\n");
e=0;
}
}
}
if(fcount4==4)
printf("\nAll frames received successfully");
break;
default:
printf("Invalid Choice");
}
}
Input/Output:

32
Input/Output:
1:ERROR FREE CHANNEL
2:FRAME WITH ERROR
3:ACK IS LOST
4:FRAME IS LOST
Enter the choice:1
Enter the value of frame 1:10101010
ack1, frame 1 is received
Enter the value of frame 2:11001100
ack2, frame 2 is received
Enter the value of frame 3:11100010
ack3, frame 3 is received
Enter the value of frame 4:11110000
ack4, frame 4 is received
All frames received successfully

1:ERROR FREE CHANNEL


2:FRAME WITH ERROR
3:ACK IS LOST
4:FRAME IS LOST
Enter the choice:2
Enter the value of frame 1:10101010
ack1, frame 1 is received
Enter the value of frame 2:10010100
ack2, frame 2 is received
Enter the value of frame 3:00101011
ack3, frame 3 is received
Enter the value of frame 4:10190001
Nack4-frame 4 is in error
re-enter the value of frame4
Enter the value of frame 4:10100001

33
ack4, frame 4 is received
All frames received successfully

1:ERROR FREE CHANNEL


2:FRAME WITH ERROR
3:ACK IS LOST
4:FRAME IS LOST
Enter the choice:3
Enter the value of frame 1:10101010
ack1, frame 1 is received
Enter the value of frame 2:11000110
ack2, frame 2 is received
Enter the value of frame 3:10101011
ack3, frame 3 is received
Enter the value of frame 4:10101001
Ack lost...
Re-enter the frame 4:10101001
ack4, frame 4 is received
All frames received successfully

1:ERROR FREE CHANNEL


2:FRAME WITH ERROR
3:ACK IS LOST
4:FRAME IS LOST
Enter the choice:4
Enter the value of frame 1:10010101
ack1, frame 1 is received
Enter the value of frame 2:11001100
ack2, frame 2 is received
Enter the value of frame 3:11100011
ack3, frame 3 is received
Enter the value of frame 4:.
Frame 4 is missing
Re-Enter the Frame
Enter the value of frame 4:10101010
ack4, frame 4 is received

All frames received successfully

34
SLIDING WINDOW PROTOCOL
AIM:
Implementation of Sliding Window using a C program.

SOFTWARE REQUIRED:
Online C Complier

THEORY:

->A sliding window protocol is a feature of packet based date


transmission protocols. Sliding window protocols are used where
reliable in order delivery of packets is required, such as in data link
layer (OSI layer) as well as in transmission control protocol.

-> Packet based systems are based on the idea of sending a batch of
data, the packet along a with additional data that allows the receiver to
ensure it.

-> This ensures packets arrive in the correct older, as Only one may be
sent at a time.

->To address this, sliding window protocols allows a selected number of


packets, the windows to be sent without having to wait for an ACK.

-> Each packet receives a sequence number, and the ack’s send back
that number. The protocol keeps track of which packets have been
acknowledged and when they are received, sends more packets. In this
way, the window sides along the stream of packets making up the
transfer.

35
SOURCE CODE:
#include <stdio.h>

int main()

char f1[50], f2[50];

int Csw, Crw,Cack,i=0;

printf("Enter the number of frames in sender window:");

scanf("%d",&Csw);

printf("Enter the no.of bytes in buffer space of receiver window:");

scanf("%d",&Crw);

while(1)

36
{

int fc;

printf("\nNo.of frames sent from the sender window:");

scanf("%d",&fc);

Csw--;

Crw--;

printf("\nNo.of frames in sender window %d frames”, Csw);

printf("\nNo.of bytes in buffer space of receiver window %d bytes”, Crw);

i++;

if(i==2 || i==3 || i==6 )

printf("\nAfter how many frames ACK is received by sender node:");

scanf("%d",&Cack);

Csw+=Cack;

Crw+=Cack;

printf("\nNo.of frames in sender window %d frames",Csw);

printf("\nNo.of bytes in buffer space of receiver window %d bytes",Crw);

if(i==6)

break;

37
INPUT/OUTPUT:

INPUT/OUTPUT:
Enter the number of frames in sender window:7
Enter the no. of bytes in buffer space of receiver window:7

No. of frames sent from the sender window:1

No. of frames in sender window 6 frames


No. of bytes in buffer space of receiver window 6 bytes
No.of frames sent from the sender window:1

38
No.of frames in sender window 5 frames
No.of bytes in buffer space of receiver window 5 bytes
After how many frames ACK is received by sender node:2

No.of frames in sender window 7 frames


No.of bytes in buffer space of receiver window 7 bytes
No.of frames sent from the sender window:1

No.of frames in sender window 6 frames


No.of bytes in buffer space of receiver window 6 bytes
After how many frames ACK is received by sender node:1

No.of frames in sender window 7 frames


No.of bytes in buffer space of receiver window 7 bytes
No.of frames sent from the sender window:1

No.of frames in sender window 6 frames


No.of bytes in buffer space of receiver window 6 bytes
No.of frames sent from the sender window:1

No. of frames in sender window 5 frames


No.of bytes in buffer space of receiver window 5 bytes
No.of frames sent from the sender window:1

No.of frames in sender window 4 frames


No.of bytes in buffer space of receiver window 4 bytes
After how many frames ACK is received by sender node:3

No.of frames in sender window 7 frames


No.of bytes in buffer space of receiver window 7 bytes

CONCLUSION:
Implementation of sliding window is verified using a C program.

39
GO BACK-N
Aim:
Implementation of go back-n using a c program for the following 3 cases.
1.Frame is damaged.
2. Frame is lost.
3.Acknowledgment is lost.

Software Requirement:
Online C compiler.

Theory:
 When multiple frames are transmitted from sender node to receiver node then
acknowledgment can be generated by the receiver node randomly may be after 1 or 2
or 3 frames because go back n is the method under sliding window ARQ.
 When multiple frames are forwarded from sender node to receiver node like frame
1,frame2,frame3 and then acknowledgment is generated from receiver node to sender
node.
 Whatever the frames received by the receiver after the damaged frame will be
rejected. This is the concept of go back n.
 Go back n have following cases:
 1.Received frame is in error.
 2.ACK is lost.
 3.Frame is lost.
 The drawback of go back n is rejecting all the frames coming after the damaged frame
even though there are no errors. This drawback is resolved in selective reject method.

40
41
Source Code:
#include<stdio.h>
#include<string.h>
int main()
{
char frame[10][10];
int ch;
printf("1:damaged frame\n2:lost frame\n3:lost acknowledgment\nenter your choice:");
scanf("%d",&ch);
switch(ch){
case 1:
for(int i=0;i<3;i++){
printf("enter the value of frame %d:",i);
scanf("%s",frame[i]);
}
printf("ACK3:frame 0, frame 1, frame 2\trecieved sucessfully\n");
printf("enter the value of frame 3:");
scanf("%s",frame[3]);
for(int j=0;j<8;j++){
if(frame[3][j]-'0'!=0 && frame[3][j]-'1'!=0){
printf("NAk 3: error in frame 3\n");
break;
}
}
for(int i=4;i<=5;i++){
printf("enter the value of frame %d:",i);
scanf("%s",frame[i]);
printf("frame %d is discarded by the reciever node\n",i);
}
for(int i=3;i<=5;i++){
printf("re-enter the value of frame %d:",i);
scanf("%s",frame[i]);
}
printf("frame0 ,frame1 ,frame2 ,frame3, frame4 ,frame 5 revieved sucessfully by reciever node");
break;

case 2:
for(int i=0;i<=3;i++){
printf("enter the value of frame %d:",i);
scanf("%s",frame[i]);
}
printf("frame 3 is discarded by reciever node\n");
printf("NAK 2:frame 2 not recieved properly\n");
printf("enter the value of frame 4:");
scanf("%s",frame[4]);
printf("frame 4 is discarded by the reciever node\n");
for(int i=2;i<=4;i++){
printf("re-enter the value of frame %d:",i);
scanf("%s",frame[i]);
}
printf("frame0 ,frame1 ,frame2 ,frame3, frame4 revieved sucessfully by reciever node");
break;
case 3:
for(int i=0;i<3;i++){

42
printf("enter the value of frame %d:",i);
scanf("%s",frame[i]);
}
printf("ACK 3: genetated after recieving 3 frame is lost\n");
printf("sender node waiting time is expired(time out) .... \n");
for(int i=0;i<=3;i++){
printf("re-enter the value of frame%d:",i);
scanf("%s",frame[i]);
}
printf("frame0 ,frame1 ,frame2 ,frame3 revieved sucessfully by reciever node");
break;
}
}

Input/Output:

43
44
SELECTIVE REJECT
Aim:
Implementation of selective reject using a C program in a noisy channel.

Software Requirement:
Online C compiler.

Theory:
 Selective repeat protocol, also known as Selective Repeat Automatic Repeat
Request (ARQ), is a data link layer protocol that uses the sliding window technique for
reliable data frame delivery.
 Only erroneous or lost frames are retransmitted in this case, while good frames are
received and buffered.
 Selective Repeat ARQ is used in the data link layer for error detection and control.
 The sender sends several frames specified by a window size in the selective repeat
without waiting for individual acknowledgement from the receiver as in Go-Back-N
ARQ.
 Working of Selective Repeat ARQ:
 In Selective Repeat ARQ, only the erroneous or lost frames are retransmitted, while
correct frames are received and buffered.
 While keeping track of sequence numbers, the receiver buffers the frames in memory
and sends NACK (negative acknowledgement) for only the missing or damaged frame.
 The sender will send/retransmit the packet for which NACK (negative
acknowledgement) is received.

45
Source Code:
#include<stdio.h>
#include<stdbool.h>
bool valid(char f[8])
{
int c=0;
for(int i=0;i<8;i++)
{
if(f[i]=='0' || f[i]=='1')
c++;
}
if(c==8)
return true;
else
return false;
}
int main()
{
int error=-1;
char f[5][8],r[8];
for(int i=0;i<=5;i++){
printf("Enter the Value of frame %d:",i);
scanf("%s",f[i]);
if(!valid(f[i]))//NACK 'i' is received from the receiver
error=i;
}
if(error!=-1){
printf("NAK%d:frame %d is rejected selectively\n",error,error);
printf("Re-Enter the value of frame %d:",error);
scanf("%s",r);
printf("FRAME 0,FRAME 1,FRAME 2,FRAME 3,FRAME 4,FRAME 5 are received
successfully,repeat only for FRAME %d",error);
}
else
printf("FRAME 0,FRAME 1,FRAME 2,FRAME 3,FRAME 4,FRAME 5 are received
successfully");
return 0;
}

46
Input/Output:

Input/Output:

Enter the Value of frame 0:11001100


Enter the Value of frame 1:10101010
Enter the Value of frame 2:11110009
Enter the Value of frame 3:11001010
Enter the Value of frame 4:10001011
Enter the Value of frame 5:11010010
NAK2:frame 2 is rejected selectively
Re-Enter the value of frame 2:11110000
FRAME 0,FRAME 1,FRAME 2,FRAME 3,FRAME 4,FRAME 5 are received
successfully,repeat only for FRAME 2

47
DIJKSTRA’S SHORTEST PATH
AIM:
Implementation of shortest path routing algorithm using a C program
(DIJKSTRA’S).

SOFTWARE REQUIRED:
Online C Compiler

THEORY:
 Let us begin our study of feasible routing algorithms with a technique that is
widely used in many forms because it is simple and easy to understand.
 The idea 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 (often called a link).
 To choose a route between a given pair of routers, the algorithm just finds the
shortest path between them on the graph.
 The concept of the shortest path deserves some explanation. One way of
measuring path length is the number of hops.
 By changing the weighting function, the algorithm would then compute the
''shortest'' path measured according to any one of a number of criteria or to a
combination of criteria.
 Several algorithms for computing the shortest path between two nodes of a
graph are known.
 This one is due to Dijkstra (1959). Each node is labeled (in parentheses) with its
distance from the source node along the best-known path. Initially, no paths are
known, so all nodes are labeled with infinity.
 As the algorithm proceeds and paths are found, the labels may
change,reflecting better paths.

48
 A label may be either tentative or permanent. Initially, all labels are tentative.
When it is discovered that a label represents the shortest possible path from the
source to that node, it is made permanent and never changed thereafter.

SOURCE CODE:
#include<stdio.h>
int main()
{
int n,AB,BC,CD,BE,EF,FH,AG,GH,HD,EG,P1,P2;
printf("Enter the number of nodes in subnet:");
scanf("%d",&n);
printf("Computation of shortest path connecting node A & node D is as follows\n");
printf("Enter the distance between Node A and Node B:");
scanf("%d",&AB);
printf("Enter the distance between Node B and Node C:");
scanf("%d",&BC);
printf("Enter the distance between Node C and Node D:");
scanf("%d",&CD);
printf("Enter the distance between Node B and Node E:");
scanf("%d",&BE);
printf("Enter the distance between Node E and Node F:");
scanf("%d",&EF);

49
printf("Enter the distance between Node F and Node H:");
scanf("%d",&FH);
printf("Enter the distance between Node A and Node G:");
scanf("%d",&AG);
printf("Enter the distance between Node G and Node H:");
scanf("%d",&GH);
printf("Enter the distance between Node H and Node D:");
scanf("%d",&HD);
printf("Enter the distance between Node E and Node G:");
scanf("%d",&EG);
printf("Computation of path from node A to node D is path P1 or path P2\n");
printf("Path P1:(A->B)+(B->E)+(E->G)+(G->H)+(H->D) \n");
P1=AB+BE+EG+GH+HD;
printf("Path P1= %d\n",P1);
printf("Path P2:(A->B)+(B->E)+(E->F)+(F->H)+(H->D) \n");
P2=AB+BE+EF+FH+HD;
printf("Path P2= %d\n",P2);
if(P1<P2)
printf("Path connecting node A and node D is P1=%d",P1);
else
printf("Path connecting node A and node D is P2=%d",P2);
}

INPUT/OUTPUT:

INPUT/OUTPUT:
Enter the number of nodes in subnet:8
Computation of shortest path connecting node A & node D is as follows

50
Enter the distance between Node A and Node B:2
Enter the distance between Node B and Node C:7
Enter the distance between Node C and Node D:3
Enter the distance between Node B and Node E:2
Enter the distance between Node E and Node F:2
Enter the distance between Node F and Node H:2
Enter the distance between Node A and Node G:6
Enter the distance between Node G and Node H:4
Enter the distance between Node H and Node D:2
Enter the distance between Node E and Node G:1
Computation of path from node A to node D is path P1 or path P2
Path P1:(A->B)+(B->E)+(E->G)+(G->H)+(H->D)
Path P1= 11
Path P2:(A->B)+(B->E)+(E->F)+(F->H)+(H->D)
Path P2= 10
Path connecting node A and node D is P2=10

CONCLUSION:
Implementation of shortest path routing algorithm using a C program
(DIJKSTRA’S) is verified.

51
DISTANCE VECTOR ROUTING ALGORITHM
AIM:
Implementation of Distance Vector Routing Algorithm using a C
program.

SOFTWARE REQUIRED:
Online C Compiler

THEORY:
 Modern computer networks generally use dynamic routing algorithms rather
than the static ones described above because static algorithms do not take the
current network load into account.
 Two dynamic algorithms in particular, distance vector routing and link state
routing, are the most popular. In this section we will look at the former algorithm.
In the following section we will study the latter algorithm.
 Distance vector routing algorithms operate by having each router maintain a
table (i.e., a vector) giving the best-known distance to each destination and which
line to use to get there. These tables are updated by exchanging information with
the neighbors.
 The distance vector routing algorithm is sometimes called by other names, most
commonly the distributed Bellman-Ford routing algorithm and the Ford-Fulkerson
algorithm, after the researchers who developed it (Bellman, 1957; and Ford and
Fulkerson, 1962).
 It was the original ARPANET routing algorithm and was also used in the Internet
under the name RIP.
 In distance vector routing, each router maintains a routing table indexed by,
and containing one entry for, each router in the subnet. This entry contains two
parts: the preferred outgoing line to use for that destination and an estimate of
the time or distance to that destination.

52
 The metric used might be the number of hops, time delay in milliseconds, total
number of packets queued along the path, or something similar.
 The router is assumed to know the “distance” to each of its neighbors. If the
metric is hops, the distance is just one hop. If the metric is queue length, the
router simply examines each queue. If the metric is delay, the router can measure
it directly with special ECHO packets that the receiver just timestamps and sends
back as fast as it can.

SOURCE CODE:
#include<stdio.h>
int main()
{
int n,P[4],JH,HG,JK,KG,JA,AG,JI,IG;
printf("Enter the number of nods in subnet:");
scanf("%d",&n);
printf("Computation of shortest path from node J to node G applying Distance Vector Routing
Algorithm\n");
printf("Possible paths connecting node J & node G are P1/P2/P3/P4\n");
printf("Path P1: JH + HG\n");

53
printf("Enter the values of JH & HG:");
scanf("%d %d",&JH,&HG);
P[1]=JH+HG;
printf("Path P1= %d\n",P[1]);
printf("Path P2: JK + KG\n");
printf("Enter the values of JK & KG:");
scanf("%d %d",&JK,&KG);
P[2]=JK+KG;
printf("Path P2= %d\n",P[2]);
printf("Path P3: JA + AG\n");
printf("Enter the values of JA & AG:");
scanf("%d %d",&JA,&AG);
P[3]=JA+AG;
printf("Path P3= %d\n",P[3]);
printf("Path P4: JI + IG\n");
printf("Enter the values of JI & IG:");
scanf("%d %d",&JI,&IG);
P[4]=JI+IG;
printf("Path P4= %d\n",P[4]);
//SORTING
int value=P[1],index=1;
for(int i=1;i<=4;i++){
if(P[i]<value){
value=P[i];
index=i;
}
}
printf("The shortest path connecting Node J & Node G is:P%d = %d",index,P[index]);

INPUT/OUTPUT:

54
INPUT/OUTPUT:

Enter the number of nodes in subnet:12


Computation of shortest path from node J to node G applying Distance Vector Routing
Algorithm
Possible paths connecting node J & node G are P1/P2/P3/P4
Path P1: JH + HG
Enter the values of JH & HG:12 6
Path P1= 18
Path P2: JK + KG
Enter the values of JK & KG:6 31
Path P2= 37
Path P3: JA + AG
Enter the values of JA & AG:8 18
Path P3= 26
Path P4: JI + IG
Enter the values of JI & IG:10 31
Path P4= 41
The shortest path connecting Node J & Node G is:P1 = 18

CONCLUSION:
Implementation of Distance Vector Routing Algorithm using a C program is
verified.

55
LINK STATE ROTUTING ALGORITHM
AIM:
Implementation of Link State Routing Algorithm using a C program.

SOFTWARE REQUIREMENTS:
Online C Complier

THEORY:
 Distance vector routing was used in the ARPANET until 1979, when it was
replaced by link state routing.
 Two primary problems caused its demise. First, since the delay metric was
queue length, it did not take line bandwidth into account when choosing routes.
 Initially, all the lines were 56 kbps, so line bandwidth was not an issue, but after
some lines had been upgraded to 230 kbps and others to 1.544 Mbps, not taking
bandwidth into account was a major problem.
 Of course, it would have been possible to change the delay metric to factor in
line bandwidth, but a second problem also existed, namely, the algorithm often
took too long to converge (the count-to-infinity problem).
 For these reasons, it was replaced by an entirely new algorithm, now called link
state routing. Variants of link state routing are now widely used.

 The idea behind link state routing is simple and can be stated as five parts. Each
router must do the following:
1. Discover its neighbors and learn their network addresses.
2. Measure the delay or cost to each of its neighbors.
3. Construct a packet telling all it has just learned.
4. Send this packet to all other routers.
5. Compute the shortest path to every other router.

56
SOURCE CODE:
#include<stdio.h>
int main()
{
int n,AB,AE,BA,BC,BF,CB,CD,CE,DC,DF,EA,EC,EF,FB,FD,FE,P[5];
printf("Enter the number of nodes in subnet:");
scanf("%d",&n);
printf("Computation of shortest path from node A and node D applying Link State Routing
Algorithm\n");
printf("The link state packets of Node A:AB & AE\n");
printf("Enter the values of AB & AE:");
scanf("%d %d",&AB,&AE);
printf("The link state packets of Node B:BA, BC & BF\n");
printf("Enter the values of BA, BC & BF:");
scanf("%d %d %d",&BA,&BC,&BF);
printf("The link state packets of Node C:CB, CD & CE\n");
printf("Enter the values of CB, CD & CE:");
scanf("%d %d %d",&CB,&CD,&CE);
printf("The link state packets of Node D:DC & DF\n");
printf("Enter the values of DC & DF:");
scanf("%d %d",&DC,&DF);
printf("The link state packets of Node E:EA, EC & EF\n");
printf("Enter the values of EA, EC & EF:");
scanf("%d %d %d",&EA,&EC,&EF);
printf("The link state packets of Node F:FB, FD & FE\n");
printf("Enter the values of FB, FD & FE:");
scanf("%d %d %d",&FB,&FD,&FE);
printf("Possible paths connecting node A and node D:P1/P2/P3/P4:\n");
printf("Path P1:(A->B)+(B->C)+(C->D)\n");
P[1]=AB+BC+CD;

57
printf("Path P1=%d\n",P[1]);
printf("Path P2:(A->E)+(E->F)+(F->D)\n");
P[2]=AE+EF+FD;
printf("Path P2=%d\n",P[2]);
printf("Path P3:(A->B)+(B->F)+(F->D)\n");
P[3]=AB+BF+FD;
printf("Path P3=%d\n",P[3]);
printf("Path P4:(A->E)+(E->C)+(C->D)\n");
P[4]=AE+EC+CD;
printf("Path P4=%d\n",P[4]);
//sorting paths
int value=P[1],index=1;
for(int i=1;i<=4;i++){
if(P[i]<value){
value=P[i];
index=i;
}
}
printf("\nShortest path connecting Node A & Node D is:P%d = %d",index,P[index]);
}

INPUT/OUTPUT:

58
INPUT/OUTPUT:
Enter the number of nodes in subnet:6
Computation of shortest path from node A and node D applying Link State Routing Algorithm
The link state packets of Node A:AB & AE
Enter the values of AB & AE:4 5
The link state packets of Node B:BA, BC & BF
Enter the values of BA, BC & BF:4 2 6
The link state packets of Node C:CB, CD & CE
Enter the values of CB, CD & CE:2 3 1
The link state packets of Node D:DC & DF
Enter the values of DC & DF:3 7
The link state packets of Node E:EA, EC & EF
Enter the values of EA, EC & EF:5 1 8
The link state packets of Node F:FB, FD & FE
Enter the values of FB, FD & FE:6 7 8
Possible paths connecting node A and node D:P1/P2/P3/P4:
Path P1:(A->B)+(B->C)+(C->D)
Path P1=9
Path P2:(A->E)+(E->F)+(F->D)
Path P2=20
Path P3:(A->B)+(B->F)+(F->D)
Path P3=17
Path P4:(A->E)+(E->C)+(C->D)
Path P4=9

Shortest path connecting Node A & Node D is:P1 = 9

CONCLUSION:
Implementation of Link State Routing Algorithm using a C program is verified.

59

You might also like