[go: up one dir, main page]

100% found this document useful (1 vote)
11K views21 pages

Aim: Program:: Implement The Data Link Layer Framing Methods Such As Character Count

The program implements the Go Back N sliding window protocol. It begins by prompting the user to enter the window size and number of frames to transmit. It then simulates the transmission by storing the frame numbers in an array, with empty elements representing frames that have not yet been transmitted. It tracks which frames have been acknowledged using the window, and will retransmit any unacknowledged frames if the window becomes full before moving the window ahead.

Uploaded by

Umme Aaiman
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
100% found this document useful (1 vote)
11K views21 pages

Aim: Program:: Implement The Data Link Layer Framing Methods Such As Character Count

The program implements the Go Back N sliding window protocol. It begins by prompting the user to enter the window size and number of frames to transmit. It then simulates the transmission by storing the frame numbers in an array, with empty elements representing frames that have not yet been transmitted. It tracks which frames have been acknowledged using the window, and will retransmit any unacknowledged frames if the window becomes full before moving the window ahead.

Uploaded by

Umme Aaiman
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/ 21

AIM: Implement the data link layer framing methods such as

Character Count.

PROGRAM:
#include<stdio.h>
int main()
{
char str[100];
int n,i,j,c=0,count=0;
printf("Enter the String:");
scanf("%s",str);
printf("Enter the number of frames:");
scanf("%d",&n);
int frames[n];
printf("Enter the frames size of the frames:\n");
for(i=0;i<n;i++)
{
printf("Frame %d:",i);
scanf("%d",&frames[i]);
}
printf("\nThe number of frames : %d\n",n);
for(i=0;i<n;i++)
{
printf("The content of the frame %d:",i);
j=0;
while(c<strlen(str) && j<frames[i])
{
printf("%c",str[c]);
if(str[c]!='\0')
{
count++;

CSE-A Computer Networks Lab 19251A0514


}
c=c+1;
j=j+1;
}
printf("\nSize of frame %d : %d\n\n",i,count);
count=0;
}
}

OUTPUT:
Enter the frames size of the frames:
Frame 0:5
Frame 1:5
Frame 2:5

The number of frames : 3


The content of the frame 0:10010
Size of frame 0 : 5

The content of the frame 1:10101


Size of frame 1 : 5

The content of the frame 2:01


Size of frame 2 : 2

CSE-A Computer Networks Lab 19251A0514


AIM: Implement the data link layer framing methods such as
Character Stuffing.

PROGRAM:
#include<stdio.h>
#include<string.h>
void main()
{
int i,k=0,n,j=6;
char s[100],res[100]="",a[100]="";
printf("Enter the string:");
gets(s);
strcpy(res,"dlestx");
for(i=0;s[i]!='\0';i++)
{
if(s[i]=='d' && s[i+1]=='l' && s[i+2]=='e')
{
res[j]='d';
res[j+1]='l';
res[j+2]='e';
j=j+3;
}
res[j]=s[i];
j++;
}
strcat(res,"dleetx");
printf("Stuffed char:%s",res);
n=strlen(res);
for(i=6;i<n-6;i++)
{
if(res[i]=='d' && res[i+1]=='l' && res[i+2]=='e')

CSE-A Computer Networks Lab 19251A0514


{
i=i+3;
}
a[k]=res[i];
k++;
}
printf("\nDestuffed char:%s",a);
}

OUTPUT 1:
Enter the string:hello
Stuffed char:dlestxhellodleetx
Destuffed char:hello

OUTPUT 2:
Enter the string:hellodle
Stuffed char:dlestxhellodledledleetx
Destuffed char:hellodle

CSE-A Computer Networks Lab 19251A0514


AIM: Implement the data link layer framing methods such as
Bit Stuffing.

PROGRAM:
#include<stdio.h>
#include<string.h>
int main()
{
int n,i,j=8,c=0,c1=0,k=8;
char s[100],res[100];
printf("Enter string:");
scanf("%s",s);
n=strlen(s);
strcpy(res,"01111110");
strcat(res," ");
for(i=0;i<n;i++)
{
res[j]=s[i];
j++;
if(s[i]=='1')
{
c+=1;
if(c==5)
{
res[j]='0';
j++;
c=0;
}
}
else
{
c=0;

CSE-A Computer Networks Lab 19251A0514


}
}
strcat(res," 01111110");
printf("Stuffed string:");
printf("%s",res);
printf("\nDestuffed string:");
for(i=8;i<strlen(res)-8;i++)
{
if(res[i]=='1')
{
c1++;
}
else
{
c1=0;
}
printf("%c",res[i]);
if(c1==5)
{
i++;
c1=0;
}
}
res[i]='\0';
}

OUTPUT 1:
Enter string:011111101
Stuffed string:01111110011111010101111110
Destuffed string:011111101

OUTPUT 2:

CSE-A Computer Networks Lab 19251A0514


Enter string:10001
Stuffed string:011111101000101111110
Destuffed string:10001

CSE-A Computer Networks Lab 19251A0514


AIM : Implement on a dataset of characters using Parity bits.
(Hamming code problem).

PROGRAM :
#include<stdio.h>
#include<math.h>
int r=0,m=0;
int data[10];
int dataatrec[10];
int no_pbits()
{
while(1)
{
if(m+r-1<=pow(2,r))
return ;
r+=1;
}
}
void is_pbit()
{
int i;
for (i=0;i<r;i++)
data[m+r-(int)pow(2,i)]=-1;
}
void pbits()
{
for(int i=0;i<r;i++)
{
int p=pow(2,i);
int q=m+r-p-1;
int d=0,cnt=0;
while(cnt!=p-1)

CSE-A Computer Networks Lab 19251A0514


{
d=d^data[q];
q--;
cnt++;
}
q-=p;
while(q>=0)
{
cnt=0;
while(cnt!=p)
{
d=d^data[q];
q--;
cnt++;
}
q-=p;
}
data[m+r-(int)pow(2,i)]=d;
}
}
int cbits()
{
int cb=0;
for(int i=0;i<r;i++)
{
int p=pow(2,i);
int q=m+r-p;
int d=0,cnt=0;
while(q>=0)
{
cnt=0;

CSE-A Computer Networks Lab 19251A0514


while(cnt!=p)
{
d=d^dataatrec[q];
q--;
cnt++;
}
q-=p;
}
cb=cb+d*p;
}
return cb;
}
void main()
{

int c,i;//,c1,c2,c3,i;
printf("Enter number of bits:\n");
scanf("%d",&m);
no_pbits(8);
is_pbit();
int count=0;
printf("Enter data bits\n");
for(i=0;i<(m+r);i++)
{
if(data[i]!=-1)
{
scanf("%d",&data[i]);
count+=1;
}
if(count==m)
break;

CSE-A Computer Networks Lab 19251A0514


}
pbits();
printf("Data bits after adding parity bits:");
for(i=0;i<(m+r);i++)
printf("%d\n",data[i]);
printf("Enter the received data bits one by one\n");
for(i=0;i<m+r;i++)
scanf("%d",&dataatrec[i]);
c=cbits();
if(c==0)
printf("\nNo error while transmission of data\n");
else
{
printf("\nError on position %d",m+r-c);
printf("\nData received : ");
for(i=0;i<m+r;i++)
printf("%d",dataatrec[i]);
printf("\nCorrect message is\n");
if(dataatrec[m+r-c]==0)
dataatrec[m+r-c]=1;
else
dataatrec[m+r-c]=0;
for (i=0;i<m+r;i++)
printf("%d",dataatrec[i]);
}
}

CSE-A Computer Networks Lab 19251A0514


OUTPUT 1:
Enter number of bits:
7
Enter data bits
1
0
1
0
1
1
0
Data bits after adding parity bits:1
0
1
0
0
1
1
0
0
0
1
Enter the received data bits one by one
1
0
1
0
0
1
1
0
1

CSE-A Computer Networks Lab 19251A0514


0
1
Error on position 8
Data received : 10100110101
Correct message is
10100110001

OUTPUT 2:
Enter number of bits:
7
Enter data bits
1
0
1
0
1
1
0
Data bits after adding parity bits:1
0
1
0
0
1
1
0
0
0
1
Enter the received data bits one by one
1
0

CSE-A Computer Networks Lab 19251A0514


1
0
0
1
1
0
0
0
1
No error while transmission of data

CSE-A Computer Networks Lab 19251A0514


AIM: Implement on a dataset of characters using CRC
polynomials CRC 12 and CRC 16.

PROGRAM :
#include <stdio.h>
void func(int[],int,int[],int);
void main()
{
int i,g,l,f=0,d[20],p[20],r[20];
printf("Enter the length of the generator: ");
scanf("%d",&g);
printf("Enter the generator: ");
for(i=0;i<g;i++)
{
scanf("%d",&p[i]);
}
printf("Enter the length of the dataword: ");
scanf("%d",&l);
printf("Enter the dataword: ");
for(i=0;i<l;i++)
{
scanf("%d",&d[i]);
r[i]=d[i];
}
for(i=l;i<(l+g-1);i++)
d[i]=0;
printf("Code word:");
for(i=0;i<(l+g-1);i++)
{
printf("%d ",d[i]);
}

CSE-A Computer Networks Lab 19251A0514


func(d,l,p,g);
printf("\nCRC: ");
for(i=l;i<(l+g-1);i++)
{
printf("%d ",d[i]);
r[i]=d[i];
}
printf("\nResult of dataword: ");
for(i=0;i<(l+g-1);i++)
printf("%d ",r[i]);
printf("\nReceived dataword: ");
for(i=0;i<(l+g-1);i++)
scanf("%d",&d[i]);
func(d,l,p,g);
printf("\nFinal result: ");
for(i=l;i<(l+g-1);i++){
printf("%d ",d[i]);
if(d[i]!=0)
f=1;
}
if(f==0)
printf("\nNo errors,data accepted");
else
printf("\nError in data");
}
void func(int r[],int l,int p[],int g){
int i,j,k;
for(i=0;i<l;i++){
if(r[i]==1){
for(j=0,k=i;j<g;j++,k++){
if(r[k]==p[j])

CSE-A Computer Networks Lab 19251A0514


r[k]=0;

else
r[k]=1;
}}}}

OUTPUT 1:
Enter the length of the generator: 5
Enter the generator: 1
0
0
1
1
Enter the length of the dataword: 10
Enter the dataword: 1
1
0
1
0
1
1
1
1
1
Code word:1 1 0 1 0 1 1 1 1 1 0 0 0 0
CRC: 0 0 1 0
Result of dataword: 1 1 0 1 0 1 1 1 1 1 0 0 1 0
Received dataword: 1
1
0
1
0

CSE-A Computer Networks Lab 19251A0514


1
1
1
1
1
0
0
1
0
Final result: 0 0 0 0
No errors, data accepted

OUTPUT 2:
Enter the length of the generator: 5
Enter the generator: 1
0
0
1
1
Enter the length of the dataword: 10
Enter the dataword: 1
1
0
1
0
1
1
1
1
1
Code word:1 1 0 1 0 1 1 1 1 1 0 0 0 0
CRC: 0 0 1 0

CSE-A Computer Networks Lab 19251A0514


Result of dataword: 1 1 0 1 0 1 1 1 1 1 0 0 1 0
Received dataword: 1
1
0
1
0
1
1
1
1
1
1
0
1
0
Final result: 1 0 0 0
Error in data

AIM: Implement Go Back N Sliding window Protocol.

CSE-A Computer Networks Lab 19251A0514


PROGRAM :

#include<stdio.h>
int main()
{
int w,i,f,frames[50];
printf("Enter window size: ");
scanf("%d",&w);
printf("Enter number of frames to transmit: ");
scanf("%d",&f);
printf("Enter %d frames: ",f);
for(i=1;i<=f;i++)
{
scanf("%d",&frames[i]);
}
printf("With sliding window protocol the frames will be sent in
the following manner (assuming no correction of frames)\n");
printf("After sending %d frames at each stage sender waits for
acknowledgement sent by the receiver\n",w);
for(i=1;i<=f;i++)
{
if(i%w==0)
{
printf("%d\n",frames[i]);
printf("Acknowledgement of above frames sent is received
by sender\n");
}
else
{
printf("%d ",frames[i]);
}
}
if(f%w!=0)

CSE-A Computer Networks Lab 19251A0514


{
printf("Acknowledgement of above frames sent is received by
sender\n");
}
return 0;

}OUTPUT:

Enter window size: 3


Enter number of frames to transmit: 15
Enter 15 frames: 12 34 13 65 21 32 56 78 2 33 54 87 39 42 77 99
With sliding window protocol the frames will be sent in the
following manner (assuming no correction of frames)
After sending 3 frames at each stage sender waits for
acknowledgement sent by the receiver
12 34 13
Acknowledgement of above frames sent is received by sender
65 21 32
Acknowledgement of above frames sent is received by sender
56 78 33
Acknowledgement of above frames sent is received by sender
54 87 39
Acknowledgement of above frames sent is received by sender
42 77 99
Acknowledgement of above frames sent is received by sender

CSE-A Computer Networks Lab 19251A0514

You might also like