Step by step BGP Algorithm

The number of nodes is obtained and stored in variable ‘n’

The distance between all nodes is accepted in the 4 two dimensional array ‘a’

It is values are printed back in the form of matrix

The shortest pat between any 2 nodes is found using the expression a[i][j]=a[i][k]+a[k][j]

The distance between nodes to itself is made ‘0’

The output Matrix is printed back to the user

Finally terminate Border Gateway protocol program

BGP Source code in C language programming CS1305- NETWORK LAB

#include<stdio.h>

main()

{

int i,n,j,k,a[10][10],b[10][10];

printf("ENTER THE NO OF NODES");

scanf("%d",&n);

for(i=0;i<n;i++)

{

for(j=0;j<n;j++)

{

printf("ENTER THE DISTANCE BETWEEN HOSTS %d,%d :",i+1,j+1);

scanf("%d",&a[i][j]);

}

}

printf("THE GIVEN INPUT\n");

for(i=0;i<n;i++)

{

for(j=0;j<n;j++)

{

printf("%d\t",a[i][j]);

}

printf("\n");

}

for(k=0;k<n;k++)

{

for(i=0;i<n;i++)

{

for(j=0;j<n;j++)

{

if(a[i][j]>a[i][k]+a[k][j])

{

a[i][j]=a[i][k]+a[k][j];

}

}

}

}

for(i=0;i<n;i++)

{

for(j=0;j<n;j++)

{

b[i][j]=a[i][j];

if(i==j)

b[i][j]=0;

}

}

printf("OUTPUT MATRIX \n");

for(i=0;i<n;i++)

{

for(j=0;j<n;j++)

{

printf("%d\t",b[i][j]);

}

printf("\n");

}

}

Output CS1305- NETWORK LAB

[it28@localhost studentwebsite]$cc protocol.c

[it28@localhost studentwebsite]$./a.out

Enter the no of nodes: 2

ENTER THE DISTANCE BETWEEN HOSTS 1 1:1

ENTER THE DISTANCE BETWEEN HOSTS 1 2:2

ENTER THE DISTANCE BETWEEN HOSTS 2 1:3

ENTER THE DISTANCE BETWEEN HOSTS 2 2:4

The given output

1 2

3 4

Output Matrix

0 2

3 0

Result

The shortest path between any two given nodes was found using BGP routing in CS1305- NETWORK LAB successfully.

The number of nodes is obtained and stored in variable ‘n’

The distance between all nodes is accepted in the 4 two dimensional array ‘a’

It is values are printed back in the form of matrix

The shortest pat between any 2 nodes is found using the expression a[i][j]=a[i][k]+a[k][j]

The distance between nodes to itself is made ‘0’

The output Matrix is printed back to the user

Finally terminate Border Gateway protocol program

BGP Source code in C language programming CS1305- NETWORK LAB

#include<stdio.h>

main()

{

int i,n,j,k,a[10][10],b[10][10];

printf("ENTER THE NO OF NODES");

scanf("%d",&n);

for(i=0;i<n;i++)

{

for(j=0;j<n;j++)

{

printf("ENTER THE DISTANCE BETWEEN HOSTS %d,%d :",i+1,j+1);

scanf("%d",&a[i][j]);

}

}

printf("THE GIVEN INPUT\n");

for(i=0;i<n;i++)

{

for(j=0;j<n;j++)

{

printf("%d\t",a[i][j]);

}

printf("\n");

}

for(k=0;k<n;k++)

{

for(i=0;i<n;i++)

{

for(j=0;j<n;j++)

{

if(a[i][j]>a[i][k]+a[k][j])

{

a[i][j]=a[i][k]+a[k][j];

}

}

}

}

for(i=0;i<n;i++)

{

for(j=0;j<n;j++)

{

b[i][j]=a[i][j];

if(i==j)

b[i][j]=0;

}

}

printf("OUTPUT MATRIX \n");

for(i=0;i<n;i++)

{

for(j=0;j<n;j++)

{

printf("%d\t",b[i][j]);

}

printf("\n");

}

}

Output CS1305- NETWORK LAB

[it28@localhost studentwebsite]$cc protocol.c

[it28@localhost studentwebsite]$./a.out

Enter the no of nodes: 2

ENTER THE DISTANCE BETWEEN HOSTS 1 1:1

ENTER THE DISTANCE BETWEEN HOSTS 1 2:2

ENTER THE DISTANCE BETWEEN HOSTS 2 1:3

ENTER THE DISTANCE BETWEEN HOSTS 2 2:4

The given output

1 2

3 4

Output Matrix

0 2

3 0

Result

The shortest path between any two given nodes was found using BGP routing in CS1305- NETWORK LAB successfully.

## No comments:

Write comments