Aim: Study of Sliding Window Protocol. Theory
Aim: Study of Sliding Window Protocol. Theory
Theory:
At any instant of time, the sender maintains a set of sequence numbers which
correspond to the frames it is permitted to send. Such frames are said to be a set of the
sending window. Similarly, the receiver also maintains a receiving window which indicates
the set of frames it is allowed to receive.
A window can be visualised as a circle divided into (2n) 1 parts where n is the number of
bits required to represent, in binary, the maximum sequence number in a given sequence of
packets.
The upper and lower edges of a sending window indicate the set of packets which are allowed
to be sent but have not been acknowledged. The upper and lower edges of a receiving
window indicate the set of packets it may accept.
Program:
#include<stdio.h>
#include<iostream.h>
#include<conio.h>
#include<dos.h>
void main()
int ti,ri,i,j,ack=0,pack=0;
int rx[11],tx[11];
clrscr();
for(i=0;i<4;i++)
for(ti=ack;ti<11;ti++)
delay(ack*(5%2+25));
tx[ti]=ti;
printf("%d",ti);
pack=ack;
if(i==3)
ack=11;
else
if(i==2)
ack=6;
else
if(i==1)
ack=3;
for(ti=pack;ti<ack;ti++)
delay(ack*(5%100+5));
rx[ti]=ti;
printf("%d",ti);
//else
pack=pack;
getch();
}
output
transmission packet:012345678910
receiving packet:
transmission packet:012345678910
receiving packet:012
transmission packet:345678910
receiving packet:345
transmission packet:678910
receiving packet:678910
Conclusion:--------------------------------------------------------------------------------------
Exp.No.-8
Theory:
A CRC is an example of a block code, but it can operate on blocks of any size. Given
a message block of size k bits, it produces a compact digest of size r bits, where r is a
constant (typically between 8 and 32 bits in real implementations). Together, the k + r = n
bits constitute a code word. Every valid code word has a certain minimum Hamming distance
from every other valid code word to aid in error detection. A CRC is an example of a
polynomial code as well as an example of a cyclic code. The idea in a polynomial code is to
represent every code word w = wn1wn2wn2 ...w0 as a polynomial of degree n 1. That
is, we write
For example, the code word 11000101 may be represented as the polynomial x7 + x6 + x2 +
1, plugging the bits into Eq.(7.1). We use the term code polynomial to refer to the polynomial
corresponding to a code word. The key idea in a CRC (and, indeed, in any cyclic code) is to
ensure that every valid code polynomial is a multiple of a generator polynomial, g(x). We
will look at the properties of good generator polynomials in a bit, but for now lets look at
some properties of codes built with this property. All arithmetic in our CRC will be done in
F2. The normal rules of polynomial addition, division, multiplication, and division apply,
except that all coefficients are either 0 or 1 and the coefficients add and multiply using the F2
rules. In particular, note that all minus signs can be replaced with + signs, making life quite
convenient.
Program
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
#include<graphics.h>
intxor(intx,int y);
void main()
{
inti,j,k,n,d[20],m,g[10],msb,rem[25],z[30];
clrscr();
cout<<"\nEnter the data bits:";
cin>>n;
cout<<"\nEnter the data(press space after each data bits)";
for(i=0;i<n;i++)
cin>>d[i];
cout<<\"nEnter the no. of generator bits";
cin>>m;
cout<<"\nEnter the generator(press space after each data bits)";
for(i=0;i<m;i++)
cin>>g[i];
for(j=0;j<m-1;j++)
d[n+j]=0;
for(i=0;i<24;i++)
rem[i]=d[i];
cout<<endl;
for(i=0;i<m;i++)
z[i]=0;
for(i=0;i<n;i++)
{
k=0;
msb=rem[i];
for(j=i;j<m+i;j++)
{
if(msb==0)
rem[j]=xor(rem[j],z[k]);
else
rem[j]=xor(rem[j],g[k]);
k++;
}
rem[m+i]=d[m+i];
}
cout<<endl<<"The code bits are\n";
for(i=n;i<n+m-1;i++)
{
d[i]=rem[i];
cout<<d[i];
}
cout<<"\nThe coded data is\n";
for(i=0;i<m+n-1;i++)
cout<<d[i];
getch();
}
intxor(intx,int y)
{
if(x==y)
return(0);
else
return(1);
}
Conclusion:------------------------------------------------------------------------------- .
Exp.No.-9
ARQ
Aim: Study of
Theory:
PROGRAM:
#include<stdio.h>
#include<iostream.h>
#include<conio.h>
#include<dos.h>
#include<time.h>
#include<math.h>
#include<stdlib.h>
void main()
{
inti,j,k,n;
long d[8];
clrscr();
printf("Enter the data frame:");
scanf("%1d",&n);
for(i=0;i<n;i++)
{
printf("frame%d=",i);
scanf("%1d",&d[i]);
}
randomize();
for(i=0;i<n;i++)
{
j=random(1000);
if(j<500)
{
printf("\nFrame%d=%d is successfully transmitted\n",i,d[i]);
}
else
{
printf("\nFrame%d=%d is lost\nretransmitframe%d",i,i);
i--;
delay(1000);
}
}
getch();
}
Conclusion:------------------------------------------------------------------------------- .