COMPUTER NETWORKS (practicals)

Posted: November 23, 2010 in Uncategorized

 

Practical No. 4 WRITE A PROGRAM TO PERFORM BIT STUFFING ON GIVEN DATA.

Objective: understand the concept of Bit stuffing

Skills Developed: programming skill

Prerequisite: DLL Framing Protocols ref- computer n/w 4th edition, A.S. Tanenbaum.

Theory:

The Data Link Layer is the second layer in the OSI model, above the Physical Layer, which ensures that the error free data is transferred between the adjacent nodes in the network. It breaks the datagrams passed down by above layers and convert them into frames ready for transfer. This is called Framing. It provides two main functionalities

  • Reliable data transfer service between two peer network layers
  • Flow Control mechanism which regulates the flow of frames such that data congestion is not there at slow receivers due to fast senders

Since the physical layer merely accepts and transmits a stream of bits without any regard to meaning or structure, it is upto the data link layer to create and recognize frame boundaries. This can be accomplished by attaching special bit patterns to the beginning and end of the frame. If these bit patterns can accidentally occur in data, special care must be taken to make sure these patterns are not incorrectly interpreted as frame delimiters. The four framing methods that are widely used are

  • Character count
  • Starting and ending characters, with character stuffing
  • Starting and ending flags, with bit stuffing
  • Physical layer coding violations

Bit stuffing

The third method allows data frames to contain an arbitrary number of bits and allows character codes with an arbitrary number of bits per character. At the start and end of each frame is a flag byte consisting of the special bit pattern 01111110 . Whenever the sender’s data link layer encounters five consecutive 1s in the data, it automatically stuffs a zero bit into the outgoing bit stream. This technique is called bit stuffing. When the receiver sees five consecutive 1s in the incoming data stream, followed by a zero bit, it automatically destuffs the 0 bit. The boundary between two frames can be determined by locating the flag pattern.

Procedure:

 

 

ALGORITHM:
1.Read the number of frames.
2.Read the binary data for each frame.
3.Add the flag.
4.Bit Stuffing:If there is five consecutive 1’s after zero ,add one zero as sixth bit.
5.Transmit the data.
6.Destuffing:If there is zero after the five consecutive 1’s ,remove that zero in the data.
7.Display the data.

Program:

#include<stdio.h>
main()
{ char a[10];
int count=0,i=0,j,l,k=0;
printf(“Enter the input string”);
scanf(“%s”,a);
L=strlen(a);
for(i=0;i<l;i++)
if(a[i]==’1′)
{ k=i;
count=0;
while(a[k]==’1′)
{ count+=1;
k++;
if(count==5)
{ for(j=l+1;j>k;j–)
{ a[j]=a[j-1];
} a[k]=’0′;
l++;
break;
}
i=k;
}
}
printf(“\n The bitstuffed string is %s”,a);
//getch();
k=0;
for(i=0;i<=l;i++)
{ if(a[i]==’1′)
{
k=i;
count=0;
while(a[k]==’1′)
{ count+=1;
k++;
if(count==5)
{
for(j=k;j<l+1;j++)
{
a[j]=a[j+1];
} l–;
a[l+1]=’0′;
break;
} }
i=k-1;
} }
printf(“String after unstuffing %s\n”,a);
}

Output:

Enter the input string 111111011
The bit stuffed string is 111110011
String after unstuffing is 11111011

 

Practical No. 5 WRITE A PROGRAM TO CALCULATE CRC (CYCLIC REDUNDANCY CHECK) OF GIVEN DATA.

Objective: understand about CRC

Skills Developed: how to detect multiple bit errors and how to implement.

Prerequisite: Error Detection codes Ref-Data comm.. & Networking 3rd edition  chapter 10  B.A. Forouzan.

Theory:

The cyclic redundancy check, or CRC, is a technique for detecting errors in digital data, but not for making corrections when errors are detected. It is used primarily in data transmission. In the CRC method, a certain number of check bits, often called a checksum, are appended to the message being transmitted. The receiver can determine whether or not the check bits agree with the data, to ascertain with a certain degree of probability whether or not an error occurred in transmission. If an error occurred, the receiver sends a “negative acknowledgement” (NAK) back to the sender, requesting that the message be retransmitted. The technique is also sometimes applied to data storage devices, such as a disk drive. In this situation each block on the disk would have check bits, and the hardware might automatically initiate a reread of the block when an error is

detected, or it might report the error to software. The material that follows speaks in terms of a “sender” and a “receiver” of a “message,” but it should be understood that it applies to storage writing and reading as well.

Procedure:

The CRC is calculated by performing a modulo 2 division of the data by a generator polynomial and recording the remainder after division.

 

  • A predetermined divisor of n+1 bits
  • A string of n 0s is appended to the data unit
  • Based on Binary division
  • Divides the data with the appended 0s by the divisor using binary division
  • The remainder is called CRC (n-bits), and will replaced the n 0s.
  • The data unit with the appended CRC (remainder) is send to the receiver
  • The receiver divides the received data by the same divisor.
  • If the remainder is zero then the data is passed (no errors)
  • Otherwise an error occurs

 

 

 

 

 

Program:

/* Calculation of CRC (Cyclic Redundancy Check)*/

#include< stdlib.h>
#include< conio.h>
#include< stdio.h>
void main()
{
int i,j,n,g,a,arr[20],gen[20],b[20],q[20],s;
clrscr();
printf(“Transmitter side:”);
printf(“\nEnter no. of data bits:”);
scanf(“%d”,&n);
printf(“Enter data:”);
for(i=0;i< n;i++)
scanf(“%d”,&arr[i]);

printf(“Enter size of generator:”);
scanf(“%d”,&g);
do{
printf(“Enter generator:”);
for(j=0;j< g;j++)
scanf(“%d”,&gen[j]);

}
while(gen[0]!=1);
printf(“\n\tThe generator matrix:”);
for(j=0;j< g;j++)
printf(“%d”,gen[j]);

a=n+(g-1);
printf(“\n\tThe appended matrix is:”);
for(i=0;i< j;++i)
arr[n+i]=0;

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

printf(“%d”,arr[i]);

for(i=0;i< n;++i)
q[i]= arr[i];

for(i=0;i< n;++i)
{
if(arr[i]==0)
{
for(j=i;j< g+i;++j)
arr[j] = arr[j]^0;
}
else
{
arr[i] = arr[i]^gen[0];
arr[i+1]=arr[i+1]^gen[1];
arr[i+2]=arr[i+2]^gen[2];
arr[i+3]=arr[i+3]^gen[3];
}
}
printf(“\n\tThe CRC is :”);
for(i=n;i < a;++i)
printf(“%d”,arr[i]);
s=n+a;
for(i=n;i< s;i++)
q[i]=arr[i];
printf(“\n”);
for(i=0;i< a;i++)
printf(“%d”,q[i]);
getch();
}

Output:

Transmitter side:
Enter no. of data bits:8
Enter data:1 0 1 0 0 0 0 1
Enter size of generator:4
Enter generator:1 0 0 1

The generator matrix:1001
The appended matrix is:10100001000
The CRC is :111
10100001111

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s