0% found this document useful (0 votes)
65 views19 pages

1a) Implement The Data Link Layer Framing Bit Stuffing Method

1. The program implements Dijkstra's algorithm to find the shortest path between nodes in a graph. It initializes data structures to track the parent node, distance and status of each node. It then iteratively finds the unvisited node with lowest distance and updates distances of neighboring nodes until the destination is reached. 2. The program implements distance vector routing to calculate routing tables at each node in a subnet. It takes input for the number of nodes, their names, delays between nodes and initializes the routing table. It then calculates the next hop and distance for each node by choosing the minimum of distances through different neighbors. 3. The output shows the routing table for node A, with distances and next hops to

Uploaded by

shahenaaz31655
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
0% found this document useful (0 votes)
65 views19 pages

1a) Implement The Data Link Layer Framing Bit Stuffing Method

1. The program implements Dijkstra's algorithm to find the shortest path between nodes in a graph. It initializes data structures to track the parent node, distance and status of each node. It then iteratively finds the unvisited node with lowest distance and updates distances of neighboring nodes until the destination is reached. 2. The program implements distance vector routing to calculate routing tables at each node in a subnet. It takes input for the number of nodes, their names, delays between nodes and initializes the routing table. It then calculates the next hop and distance for each node by choosing the minimum of distances through different neighbors. 3. The output shows the routing table for node A, with distances and next hops to

Uploaded by

shahenaaz31655
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/ 19

1a) Implement the data link layer framing bit stuffing method.

#include<stdio.h>
#include<conio.h>
void main()
{
int x=0,j=0,l,k=0,c=0,i,n,A[50],B[50],C[50];
clrscr();
printf("\nEnter the no. of bits-");
scanf("%d",&n);
l=n;
printf("\nEnter the bits [and press enter after every bit]-\n");
for(i=0;i<n;i++)
{
printf("\nEnter the bit-");
scanf("%d",&A[i]);
}
printf("\nEntered bits are-\n");
for(i=0;i<n;i++)
printf("%d",A[i]);
printf("\n***SENDER***\n");
for(i=0;i<n;i++)
{
if(A[i]==0)
{
B[k]=0;

k++;
c=0;
}
else
{
B[k]=1;
k++;
c++;
}
if(c==5)
{
B[k]=0;
k++;
c=0;
l++;
}
}
for(i=0;i<l;i++)
printf("%d",B[i]);
printf("\n***RECIEVER***\n");
for(i=0;i<l;i++)
{
if(x==5)
{
x=0;
}

else
{
if(B[i]==0)
{
C[j]=0;
j++;
x=0;
}
else
{
x++;
C[j]=1;
j++;
}
}
}

for(i=0;i<n;i++)
printf("%d",C[i]);
getch();
}

OUTPUT:

Enter no.of bits 10


Enter the bit [ and press enter after every bit]-

Enter the bit - 1


Enter the bit - 1
Enter the bit - 1
Enter the bit - 1
Enter the bit - 1
Enter the bit - 1
Enter the bit - 1
Enter the bit - 1
Enter the bit - 0
Enter the bit 0
Entered bits are
1111111100
*****SENDER*****
11111011100
*****RECEIVER*****
1111111100

1b) Implement the data link layer framing character stuffing method
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[50],A[50],B[50];
int i,j,m=0,n,l=0;
clrscr();
printf("\nEnter the string-\n");
scanf("%s",a);
n=strlen(a);
printf("\nEntered string is-\n");
printf("%s",a);
A[m]='D';
m++;
A[m]='L';
m++;
A[m]='E';
m++;
A[m]='S';
m++;
A[m]='T';
m++;
A[m]='X';

m++;
for(i=0;i<n;i++)
{
if(a[i]=='D'&&a[i+1]=='L'&&a[i+2]=='E')
{
A[m]='D';
m++;
A[m]='L';
m++;
A[m]='E';
m++;
A[m]='D';
m++;
A[m]='L';
m++;
A[m]='E';
m++;
i=i+2;
}
else
{
A[m]=a[i];
m++;
}
}

A[m]='D';
m++;
A[m]='L';
m++;
A[m]='E';
m++;
A[m]='E';
m++;
A[m]='T';
m++;
A[m]='X';
m++;
A[m]='\0';
m++;
printf("\n\n***STUFFED***\n\n");
printf("%s",A);
m=m-6;
for(i=6;i<m;i++)
{
if(A[i]=='D'&&A[i+1]=='L'&&A[i+2]=='E')
{
i=i+3;
if(A[i]=='D'&&A[i+1]=='L'&&A[i+2]=='E')
{
B[l]='D';

l++;
B[l]='L';
l++;
B[l]='E';
l++;
i=i+2;
}
else
{
B[l]=A[i];
l++;
}
}
else
{
B[l]=A[i];
l++;
}
}
B[l-1]='\0';
printf("\n\n***Destuffed***\n\n");
printf("%s",B);
getch();
}

OUTPUT:
Enter the string
jntuDLEh
Entered string is
jntuDLEh
*****STUFFED*****
DLESTXjntuDLEDLEhDLEETX
*****DESTUFFED*****
jntuDLEh

2) Write a Program to implement the Cyclic Redundancy Check


#include<stdio.h>
#include<conio.h>
void main()
{
int a[20],c[20],d[20],aux[20],r,i,j,l,in,flag,choice,key;
clrscr();
printf("\n ENTER THE SIZE OF DATA WORD : ");
scanf("%d",&l);
printf("\n ENTER THE DATA WORD : ");
for(i=0; i<l; i++)
scanf("%d",&a[i]);
printf("\n ENTER THE NUMBER OF REDUNDANT BITS : ");
scanf("%d",&r);
printf("\n ENTER THE DIVISOR : ");
for(i=0; i<(r+1); i++)
scanf("%d",&d[i]);
for(i=0; i<(l+r); i++){
if(i<l) c[i]=a[i];
else c[i]=0;
}
printf("\n\n ... GENERATOR MODULE ... \n");
printf("\n\n THE INTERMEDIATE CODE WORD IS : ");
for(i=0; i<(l+r); i++)
printf("%d ",c[i]);
for(i=0; i<(l+r); i++)
aux[i]=c[i];
for(i=0; i<l; i++){
in=1;
if(c[i]==1){

for(j=i+1; j<(i+l); j++){


c[j]=c[j]^d[in];
in++;
}
}
else{
for(j=i+1; j<(i+l); j++)
c[j]=c[j]^0;
}
}
printf("\n\n THE REMAINDER AFTER DIVISION IS : ");
for(i=l; i<(l+r); i++)
printf("%d ",c[i]);
printf("\n\n SENDER CODE WORD : ");
for(i=0; i<(l+r); i++){
if(i<l) c[i]=aux[i];
printf("%d ",c[i]);
}
printf("\n\n\n PRESS 1 IF YOU WANT TO CHANGE A BIT OR 0 TO
CONTINUE : ");
scanf("%d",&choice);
if(choice==1){
printf("\n\n ENTER THE BIT YOU WANT TO CHANGE :");
scanf("%d",&key);
for(i=0; i<(l+r); i++){
if(i==(key-1)){
if(c[key-1]==0) c[key-1]=1;
else c[key-1]=0;
}
}
printf("\n\n\n CODE WORD AFTER ERROR : ");
for(i=0; i<(l+r); i++)

printf("%d ",c[i]);
}
else printf("\n\n\n NO ERROR INSERTED IN CODE WORD... ");
printf("\n\n\n\n ... CHECKER MODULE ... ");
for(i=0; i<l; i++){
in=1;
if(c[i]==1){
for(j=i+1; j<(i+l); j++){
c[j]=c[j]^d[in];
in++;
}
}
else{
for(j=i+1; j<(i+l); j++)
c[j]=c[j]^0;
}
}
printf("\n\n\n THE SYNDROME ARRAY IS : ");
for(i=l; i<(l+r); i++)
printf("%d ",c[i]);
flag=0;
for(i=l; i<(l+r); i++){
if(c[i]!=0){
flag=1;
break;
}
}
if(flag==1) printf("\n\n\n ERROR DETECTED !!!");
else printf("\n\n\n NO ERROR FOUND");
getch();
}

OUTPUT:
ENTER THE SIZE OF DATA WORD : 4
ENTER THE DATA WORD : 1 0 0 1
ENTER THE NUMBER OF REDUNDANT BITS : 3
ENTER THE DIVISOR : 1 0 1 1
.GENERATOR MODULE
TH INTERMEDIATE CODE WORD IS : 1 0 0 1 0 0 0
THE REMAINDER AFTER AFTER DIVISION IS : 110
SENDER CODE WORD : 1 0 0 1 1 1 0
PRESS 1 IF YOU WANT TO CHANGE A BIT OR 0 TO CONTINUE: 1
ENTER THE BIT YOU WANT TO CHANGE : 4
CODE WORD AFTER ERROR : 1 0 0 0 1 1 0
..CHECKER MODULE
THE SYNDROME ARRAY IS : 011
ERROR DETECTED !!!

3)Implement Dijkstras algorithm to compute the shortest path through a


graph:
PROGRAM
#include<stdio.h>
#define MAX 100
#define INFINITY 50
int n,dist[MAX][MAX],path[MAX],t,s;
void shortpath()
{
struct state
{
int pd;
int len;
enum {per,tent} label;
}state[MAX];
int i,k,min,j;
struct state *p;
for(p=&state[0];p<&state[n];p++)
{
p->pd=-1;
p->len=INFINITY;
p->label=tent;
}
state[t].len=0;
state[t].label=per;
k=t;
do{
for(i=0;i<n;i++)
{
if(dist[k][i]!=0&&state[i].label==tent)
{
if(state[k].len+dist[k][i]<state[i].len)
{
state[i].pd=k;
state[i].len=state[k].len+dist[k][i];
}
}

}
k=0;
min=INFINITY;
for(i=0;i<n;i++)
if(state[i].label==tent&&state[i].len<min)
{
min=state[i].len;
k=i;
}
state[k].label=per;
}while(k!=s);
i=0;k=s;
do{
path[i++]=k;
k=state[k].pd;
}while(k>=0);
printf("\npath is:");
for(j=0;j<i;j++)
printf(" %d",path[j]);
}
void main()
{
int i,j;
printf("enter no of nodes\n");
scanf("%d",&n);
printf("enter distarray\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&dist[i][j]);
}
}
printf("enter source node\n");
scanf("%d",&s);
printf("enter terminal node\n");
scanf("%d",&t);
shortpath();
}

Output:
Enter no of nodes
5
Enter dist array
05230
50403
24004
30000
03400
Enter source node
0
Enter terminal node
4
Path is : 0 2 4

4) Take an example subnet graph with weights indicating delay between


nodes. Now obtain routing table art each node using distance vector
routing algorithm:
#include<stdio.h>
void main()
{
int i,j,d[20],dt[50][50],min=0,mini=0,p,q,y=0,nd[30];
char r[30],n[30],l[30],x;
printf("enter number of nodes\n");
scanf("%d",&p);
printf("enter nodes\n");
for(i=1;i<=p;i++)
scanf(" %c",&r[i]);
printf("enter node for which you want to calculate routing table\n");
scanf(" %c",&x);
for(i=1;i<=p;i++)
{
if( x==r[i])
y=i;
}
nd[y]=0;
l[y]='-';
printf("enter number of neighbours are there for %c node\n",x);
scanf("%d",&q);
printf("enter neighbours of %c node\n",x);
for(i=1;i<=q;i++)
scanf(" %c",&n[i]);
printf("enter delays table\n");
for(i=1;i<=p;i++)
{
for(j=1;j<=q;j++)
{
scanf("%d",&dt[i][j]);
}
}
printf("enter delay from %c to each of its neighbour\n",x);
for(i=1;i<=q;i++)
scanf("%d",&d[i]);

for(i=1;i<=p;i++)
{
if(i!=y)
{
j=1;
min=dt[i][j]+d[j];
mini=j;
for(j=2;j<=q;j++)
{
if(min>(dt[i][j]+d[j]))
{
min=dt[i][j]+d[j];
mini=j;
}
}
nd[i]=min;
l[i]=n[mini];
}
}
printf(" routing vector table for %c is\n",x);
for(i=1;i<=p;i++)
{
printf("%d\t%c\n",nd[i],l[i]);
}
getch();
}
OUTPUT:
Enter number of nodes: 5
Enter nodes:
A
B
C
D
E
Enter node for which you want to calculate routing table: A
Enter number of neighbours are there for A nod: 4
Enter neighbours of A node
B
C
D
E
Enter delays table
2
5
8
4
8
5
4
2
6
1
3
4
2
3
5
4
5
9
2
7

Enter delay from A to each of its neighbour


5
8
4
6
routing vector table for A is
0 8 D
7 D
7 B
6 D

You might also like