Professional Documents
Culture Documents
DCCN Programs 123 PDF
DCCN Programs 123 PDF
AIM:
Implement the data link layer framing methods such as bit stuffing and destuffing.
THEORY:
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.
PROGRAM:
#include<stdio.h>
#include<string.h>
void main()
//decaring the three string arrays for storing the input frame(in str1) ,stuffed frame(in str2) and
destuffed frame(in str3)
char str1[20],str2[20],str3[20],ch;
scanf("%s",str1);
for(i=0;i<n;i++)
str2[j++]=ch; //copy each character into string2 which consists stuffed string.
//Converting the character value(ch) into interger value by subtracting 48 form ch.
else
c=0;//if the character is not a ‘1’. Then count should be zero.
if(c==5)
str2[j++]='0';
puts(str2);
c=0;
j=0;
ch=str2[i];
str3[j++]=ch;
m=ch-48;
if(m==1)
c++;
else
c=0;
if(c==5)
c=0;
puts(str3);
getch();
OUTPUT:
101111100011
1011111000011
101111100011
CHARACTER STUFFING
AIM:
Implement the data link layer framing methods such as character stuffing and destuffing.
THEORY:
each frame starts with the ASCII character sequence DLE STX and ends with the sequence DLE
ETX.(where DLE is Data Link Escape, STX is Start of TeXt and ETX is End of TeXt.) This method
overcomes the drawbacks of the character count method. If the destination ever loses
synchronization, it only has to look for DLE STX and DLE ETX characters. If however, binary data is
being transmitted then there exists a possibility of the characters DLE STX and DLE ETX occurring in
the data. Since this can interfere with the framing, a technique called character stuffing is used. The
sender's data link layer inserts an ASCII DLE character just before the DLE character in the data. The
receiver's data link layer removes this DLE before this data is given to the network layer. However
character stuffing is closely associated with 8-bit characters and this is a major hurdle in transmitting
arbitrary sized characters.
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int i=0,j=0,n;
char src[20],dest[50],rev[50];
dest[0]='D';
dest[1]='L';
dest[2]='E';
dest[3]='S';
dest[4]='T';
dest[5]='X';
while(i<n)//to copy to the dest loop execution ends with the consideration of length of the i/p string
if(src[i]=='d' && src[i+1]=='l' && src[i+2]=='e') // checking whether continuously dle occurs or not
dest[j]='d';
dest[j+1]='l';
dest[j+2]='e';
j=j+3;
i++;
j++;
dest[j]='D';
dest[j+1]='L';
dest[j+2]='E';
dest[j+3]='E';
dest[j+4]='T';
dest[j+5]='X';
dest[j+6]='\0';
printf("%s",dest);
n=strlen(dest);
for(i=6;i<n-6;i++)//to remove flag bits in rev frame loop will starts from 6th location and ends n-6
if(dest[i]=='d'&&dest[i+1]=='l'&&dest[i+2]=='e')
else
rev[j]='\0';
printf("%s",rev);
getch();
OUTPUT:
kmit
DLESTXkmitDLEETX
After destuffing
kmit
CRC
AIM:
Implement on a data set of characters the three CRC polynomials – CRC 12, CRC 16 and CRC CCIP .
THEORY:
PROGRAM:
#include<stdio.h>
void main()
int f[150],g[150],r[150],t[150],i,j,k,m,n,c=0;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&f[i]);
t[i]=f[i];
scanf("%d",&m);
for(i=0;i<m;i++)
scanf("%d",&g[i]);
for(i=n;i<n+m;i++)
t[i]=0;
for(i=0;i<n;i++)
k=i;
if(t[i]==1)
for(j=0;j<m;j++,k++)
if(t[k]==g[j])
t[k]=0;
else
t[k]=1;
for(i=n;i<m+n-1;i++)
printf(" %d ",t[i]);
f[i]=t[i];
printf("\n\nCodeword : ");
for(i=0;i<m+n-1;i++)
printf(" %d ",f[i]);
for(i=0;i<m+n-1;i++)
scanf("%d",&r[i]);
for(i=0;i<n;i++)
k=i;
if(r[i]==1)
for(j=0;j<m;j++,k++)
if(r[k]==g[j])
r[k]=0;
else
r[k]=1;
for(i=n;i<m+n-1;i++)
printf("%d",r[i]);
if(r[i]!=0)
c=1;
if(c==1)
printf("\nError ");
else
printf("\nNO error");
OUTPUT:
CRC – 4
Enter frame(dividend): 1 1 1 0
Enter g(divisor): 1 0 0 1 1
Check sum is : 0 0 0 1
Codeword : 1 1 1 0 0 0 0 1
11100001
0000
NO error
CRC-8
Enter g(divisor): 1 0 1 0 0 0 1 0 1
Check sum is : 0 1 1 1 1 0 0 1
Codeword : 1 1 1 0 0 1 1 1 1 0 0 1
111001111001
00000000
NO error
CRC-12
Enter frame(dividend): 1 1 1 0
Enter g(divisor): 1 1 1 1 0 0 1 0 1 0 1 0 0
Check sum is : 1 1 0 0 1 1 1 1 0 1 0 0
Codeword : 1 1 1 0 1 1 0 0 1 1 1 1 0 1 0 0
1110110011110100
000000000000
NO error
DVR
AIM:
Take an example subnet graph with weights indicating delay between nodes. Now obtain Routing
table art each node using distance vector routing algorithm
THEORY:
A distance-vector routing protocol in data networks determines the best route for data packets
based on distance. Distance-vector routing protocols measure the distance by the number of routers
a packet has to pass, one router counts as one hop.
PROGRAM:
#include<stdio.h>
#include<conio.h>
int adj[50][50],length[50][50],path[50][50],set[50],i,j,n,s,t,c;
printf("Enter No Of Routers\n");
scanf("%d",&n);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",&adj[i][j]);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
length[i][j]=INFINITY;
path[i][j]=0;
else
length[i][j]=adj[i][j];
path[i][j]=j;
if(i==j)
path[i][j]=131;
t=1;
while(t)
c=0;
for(s=0;s<n;s++)
for(j=0;j<n;j++)
{
if(adj[s][j])
for(i=0;i<n;i++)
if(length[s][j]+length[j][i]<length[s][i])
length[s][i]=length[s][j]+length[j][i];
path[s][i]=j;
for(s=0;s<n;s++)
for(i=0;i<n;i++)
if(length[s][i]==INFINITY)
c++;
if(c==0)
t=0;
else
t=1;
printf("\nRouting table\n\n");
for(i=65;i<(n+65);i++)
printf(" %c ",i);
printf("\n----------------------------------------------------\n");
for(i=0;i<n;i++)
printf(" l p");
for(i=0;i<n;i++)
printf("%c",i+65);
for(s=0;s<n;s++)
{
printf("\n");
getch();
OUTPUT:
Enter No Of Routers
0 9 0 0 8 10
7 0 6 0 0 15
050204
003050
12 0 0 4 0 12
11 16 4 0 10 0
Routing table
A B C D E F
----------------------------------------------------
l p l p l p l p l p l p
A 0 ─ | 7 A | 12 B | 15 C | 12 A | 11 A |
B 9 B | 0 ─ | 5 B | 8 C | 12 D | 9 C |
C 14 F | 6 C | 0 ─ | 3 C | 7 D | 4 C |
D 12 E | 8 C | 2 D | 0 ─ | 4 D | 6 C |
E 8 E | 15 A | 7 D | 5 E | 0 ─ | 10 E |
F 10 F | 10 C | 4 F | 7 C | 11 D | 0 ─ |
SHORTEST PATH
AIM:
THEORY:
Dijkstra's algorithm is an algorithm for finding the shortest paths between nodes in a graph, which
may represent, for example, road networks. It was conceived by computer scientist Edsger W.
Dijkstra in 1956 and published three years later.
The algorithm exists in many variants; Dijkstra's original variant found the shortest path between
two nodes, but a more common variant fixes a single node as the "source" node and finds shortest
paths from the source to all other nodes in the graph, producing a shortest-path tree.
PROGRAM:
#include<stdio.h>
#include<conio.h>
void main()
int gptr[20][20],set[20],path[20],length[20],s,i,j,k,n,m,temp,c;
printf("Enter No Of Vertexes\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
scanf("%d",&gptr[i][j]);
scanf("%d",&s);
for(i=1;i<=n;i++)
set[i]=0;
for(i=1;i<=n;i++)
if(gptr[s][i]==0)
{
length[i]=INFINITY;
path[i]=0;
else
length[i]=gptr[s][i];
path[i]=s;
set[s]=1;
length[s]=0;
temp=1;
while(temp)
c=0;
j=search_min(length,set,n);
set[j]=1;
for(i=1;i<=n;i++)
if(set[i]!=1)
if(gptr[i][j]!=0)
if(length[j]+gptr[i][j]<length[i])
length[i]=length[j]+gptr[i][j];
path[i]=j;
}}}}
for(i=1;i<=n;i++)
{
if(set[i]==0)
c++;
if(c==0)
temp=0;
else
temp=1;
printf("length\tpath\n");
for(i=1;i<=n;i++)
printf("%d\t%d\n",length[i],path[i]);
printf("\n-------------------------------------------------------\n");
printf("\tPath\t\tLength\tShortest path\n");
printf("----------------------\n");
printf("From(sourcevertex) To \n");
printf("--------------------------------------------------------\n");
printf("\t%d\n",s);
for(i=1;i<=n;i++)
if(i!=s)
printf("\t\t%4d\t%2d",i,length[i]);
j=i;
while(j!=s)
printf("\t%d->%d",j,path[j]);
j=path[j];
printf("\n");
getch();
}
search_min(int length[],int set[],int n)
int i,j,v,min=100;
for(i=1;i<=n;i++)
if(set[i]==0)
if(length[i]<min)
min=length[i];
v=i;
return v;
OUTPUT:
Enter No Of Vertexes
01600
10235
62042
03402
05220
length path
0 0
1 1
3 2
4 2
5 3
-------------------------------------------------------
----------------------
From(sourcevertex) To
--------------------------------------------------------
2 1 2->1
3 3 3->2 2->1
4 4 4->2 2->1