Professional Documents
Culture Documents
CN Program1
CN Program1
CN Program1
CO1: Gain the knowledge layer functionality of the OSI and TCP/IP reference model.
CO2: Implement Encoding and Decoding techniques used in Presentation layer.
CO3: Understand and Implement the Data link layer its design issues.
CO4: To understand layer and its design issues.
CO5: To Analyze the Congestion control algorithms and experiment with the Transport
layer, its services and Protocols.
CO6: To be able to work with different network tools.
1.a) AIM: To implement the data link layer framing methods such as character count
Theory:
This method is rarely used and is generally required to count total number of characters that
are present in frame. This is done by using field in header. Character count method ensures
data link layer at the receiver or destination about total number of characters that follow, and
about where the frame ends.
There is a disadvantage also of using this method i.e., if character count is disturbed or
distorted by an error occurring during transmission, then destination or receiver might lose
synchronization. The destination or receiver might also be not able to locate or identify
beginning of next frame.
Algorithm:
Begin
Step 1: Read the data
Step 2: Read the string length
Source Code:
#include<stdio.h>
#include<string.h>
int main()
{
char data[50],stuff[50],dstuff[50];
int i,j,fsize,n,tframe,dsize,s;
printf("Enter Data \n");
scanf("%s",data);
dsize=strlen(data);
printf("Enter frame size \n");
scanf("%d",&fsize);
s=fsize;
tframe=fsize-1;
n=(dsize/tframe)+1;
j=0;
for(i=0;i<(dsize+n);i++)
{
if(i%fsize==0)
{
if((dsize-j)<fsize)
{
fsize=dsize-j+1;
}
stuff[i]=(char)(48+fsize);
fsize=s;
}
else
{
stuff[i]=data[j];
j++;
}
}
stuff[dsize+n]='\0';
printf("stuffed data is %s\n",stuff);
return 0;
}
OUTPUT:
Enter Data
welcome
Enter frame size
4
stuffed data is 4wel4com2e
1.b) AIM: To implement the data link layer framing methods such as bit stuffing.
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. Whenever the sender’s data link layer encounters five
consecutive ones in the data, it automatically stuffs a 0 bit into the outgoing bit stream.
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.
Source Code:
#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:");
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 bit stuffing:");
for(i=0;i<j;i++)
printf("%d",b[i]);
}
OUTPUT:
Enter frame length 9
Enter input frame:1
0
0
1
1
1
1
1
0
After bit stuffing:1001111100
1.c) AIM: To implement the data link layer framing methods such as character stuffing.
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 and extra
character that is stuffed is added with DLE before and after it. 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
OUTPUT
1.character stuffing
2.exit
enter choice1
enter the number of characters
9
original data
dledleabc
transmitted data:
dlestx
dledledledleabcdleetx
received data:
dledleabc
1.character stuffing
2.exit
enter choice 2
RESULT: Character count, Bit-stuffing and Character-stuffing data link framing methods are
implemented in GCC compiler.