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

CN LAB (2)

The document outlines experiments for a Computer Networks Lab course, focusing on data link layer framing methods such as bit stuffing and character stuffing. It includes algorithms and program codes for implementing these methods, as well as a second experiment on computing CRC codes for various polynomial lengths. The document provides detailed steps and examples for both experiments, illustrating the practical application of these networking concepts.

Uploaded by

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

CN LAB (2)

The document outlines experiments for a Computer Networks Lab course, focusing on data link layer framing methods such as bit stuffing and character stuffing. It includes algorithms and program codes for implementing these methods, as well as a second experiment on computing CRC codes for various polynomial lengths. The document provides detailed steps and examples for both experiments, illustrating the practical application of these networking concepts.

Uploaded by

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

(A30515) COMPUTER NETWORKS LAB

B. Tech (CSE) V Semester

Experiment 1

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

Theory: In Data Link layer, the stream of bits from the physical layer is divided into data
frames. The data frames can be of fixed length or variable length. In variable – length framing,
the size of each frame to be transmitted may be different. So, a pattern of bits is used as a
delimiter to mark the end of one frame and the beginning of the next frame. However, if the
pattern occurs in the message, then mechanisms needs to be incorporated so that this situation is
avoided.
The two common approaches are −
 Bit - Stuffing − A pattern of bits of arbitrary length is stuffed in the message to
differentiate from the delimiter. This is also called bit - oriented framing.
In a data link frame, the delimiting flag sequence generally contains six or more consecutive 1s.
In order to differentiate the message from the flag in case of the same sequence, a single bit is
stuffed in the message. Whenever a 0 bit is followed by five consecutive 1bits in the message, an
extra 0 bit is stuffed at the end of the five 1s.
When the receiver receives the message, it removes the stuffed 0s after each sequence of five 1s.
The un-stuffed message is then sent to the upper layers.
 Byte - Stuffing − 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 sequence, there should be a strategy
so that the receiver does not consider the pattern as the end of the frame. Here, 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.

Algorithm for Bit−Stuffing


1. Start
2. Initialize the array for transmitted stream with the special bit pattern 0111 1110 which
indicates the beginning of the frame.
3. Get the bit stream to be transmitted in to the array.
4. Check for five consecutive ones and if they occur, stuff a bit 0
5. Display the data transmitted as it appears on the data line after appending 0111 1110 at the end
6. For de−stuffing, copy the transmitted data to another array after detecting the stuffed bits
7. Display the received bit stream
8. Stop

1
Program 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++)
{ 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]);
}

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

2
1
1
1
After stuffing the frame is:111110

Algorithm for Character stuffing


1. Start
2. Append DLE STX at the beginning of the string
3. Check the data if character is present; if character DLE is present in the string (example
DOODLE) insert another DLE in the string (ex: DOODLEDLE)
4. Transmit DLE ETXat the end of the string
5. Display the string
6. Stop
Algorithm for Character De−stuffing
1. Start
2. Neglect initial DLE STX
3. If DLE is present in the text, ngelect it; if another DLE follows, copy the same to output.
4. Neglect the trailing DLE ETX
5. Stop

3
Program 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");
ch=getche();
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';

4
j=j+3;
}
b[j]=a[i]; i+
+;
j++;
}
b[j]='d';
b[j+1]='l';
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);
}

Enter string
CMRCET
Enter position
2
Enter the character
frame after stuffing:
dlestxCdldleMRCETdleetx

5
Experiment 2

AIM: Write a program to compute CRC code for the polynomials CRC-12, CRC-16 and CRC,
CCIP.

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
sometimes is known as Cyclic Redundancy Code.

The most commonly used polynomial lengths are:

 9 bits (CRC-8)
 17 bits (CRC-16)
 33 bits (CRC-32)
 65 bits (CRC-64)

Algorithm Steps:

Step 1: Declare int crc 16, SHIFT_CRC, shift Byte, Byte_SIZE as global variables.

Step 2: Input the data in a file.

Step 3: perform the crc computation using cal CRC 16 ().

Step 4: In cal CRC 16 each character from input shifted with shift-byte where value 987.

Step 5: Output of step 4 and step 5 are exclusive.

Step 6: store in a temporary variable.

Step 7: Byte value is now left_shifted by 1.

Step 8: The loop is repeated for the Byte_size.

Step 9: The computed crc is display as output in screen.

6
Source Code:
// program for Cyclic Redundancy Check

#include<stdio.h>

int i.data[10].dl.gen[10],gl,temp[10],c;

void left_shift()

for(i=0;i<gl-1;i++)

temp(i)=temp[i+1];

if(c<d1)

temp[gl-1]=data[c];

else

temp[gl-1]=0

void xor()

if(temp[0]==0

left_shift();

c++;

for(i=0;i<gl;i++)

if(gen(i)==temp(i)

temp(i)=0

else

temp[i]=1; } }

7
main()

int j; printf("1.generate2.check\

nchoice:"); scanf("%d",&j);

printf("Enter the length of data:");

scanf("%d",&dl);

printf("Enter the data:");

for(i=0;i<dl;i++)

scanf("%d";&data[i]);

printf("Enter the length of generator:");

scanf("%d",&gl);

printf("Enter the generator:");

for(i=0;i<gl;i++)

temp[i]=data[i]

if(j==1)

for(c=4;c<dl+gl-2;c++)
{
xor();

printf("crc:");

for(i=0;i<dl;i++)

printf"%d",data[i]);

else

8
{

for(c=4;c<dl;c++)

xor();

left_shift();

printf("crc");

for(i=1;i<gl;i++)

printf("%d"'temp[i]);

printf("\n");

1.generate

2.check

choice:1
Enter the length of data:6
Enter the data:1
0
1
1
0
1
Enter the length of generator:4
Enter the generator:1
1
0
1
crc:101101001

9
10
11
12

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy