Distance Vector Routing Protocol Program in c
A distance-vector routing protocol is one of the foremost instructions of routing protocols in pc conversation principle for packet-switched networks. The hyperlink-nation protocol is the alternative foremost class.The Bellman-Ford set of rules is applied in a distance-vector routing protocol to calculate paths.
A distance-vector routing protocol calls for that a router notify its buddies on every occasion a community's topology adjustments or, in a few cases, on every occasion a alternate is detected.Distance-vector routing protocols have much less message overhead and computational complexity than hyperlink-nation protocols, which require a router to inform all community nodes of adjustments to the topology.
Routers are marketed as "vectors of distance and route" through Distance Vector.Direction is represented through the deal with of the following hop and the go out interface, while Distance is represented through metrics like hop count.
The whole course to a vacation spot is unknown to distance vector protocol routers.Rather, DV employs strategies:
Which route or interface a packet have to be despatched in.
distance from wherein it's far headed.
IGRP, the Routing Information Protocol Versions 1 and a pair of, and the Routing Information Protocol Versions 1 and a pair of are all distance-vector routing protocols. Since a distance-vector protocol most effective takes under consideration hyperlink charges whilst calculating routes, EGP and BGP aren't natural distance-vector routing protocols, while in BGP, for instance, the neighborhood direction choice fee takes priority over the hyperlink cost.
#include<stdio.h>
struct node {
unsigned dist[20];
unsigned from[20];
}rt[10];
int main() {
int dmat[20][20],n,i,j,k,count=0;
printf("\nEnter the number of nodes : ");
scanf("%d",&n);
printf("\nEnter the cost matrix :\n");
for(i=0;i<n;i++)
for(j=0;j<n;j++ ) {
scanf("%d",&dmat[i][j]);
dmat[i][i]=0;
rt[i].dist[j]=dmat[i][j];
rt[i].from[j]=j; }
do { count=0;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
for(k=0;k<n;k++)
if(rt[i].dist[j]>dmat[i][k]+rt[k].dist[j]) {
rt[i].dist[j]=rt[i].dist[k]+rt[k].dist[j];
rt[i].from[j]=k;
count++; }
}while(count!=0);
for(i=0;i<n;i++) {
printf("\n\nState value for router %d is \n",i+1);
for(j=0;j<n;j++) {
printf("\t\nnode %d via %d Distance%d",j+1,rt[i].from[j]+1,rt[i].dist[j]); }
printf("\n\n"); }
Output:
Enter the number of nodes :
3
Enter the cost matrix :
0 2 7
2 0 1
7 1 0
State value for router 1 is
node 1 via 1 Distance 0
node 2 via 2 Distance 2
node 3 via 3 Distance 3
State value for router 2 is
node 1 via 1 Distance 2
node 2 via 2 Distance 0
node 3 via 3 Distance 1
State value for router 3 is
node 1 via 1 Distance 3
node 2 via 2 Distance 1
node 3 via 3 Distance 0
algorithm:
Algorithms Used in Distance Vector Routing The Bellman-Ford algorithm serves as the basis for distance vector routing
This algorithm requires each node in the network to maintain a distance vector table that stores the distance between itself and its immediate neighbors in the link.
This algorithm can then be used to draw the following conclusions about the network's routing algorithm:
A routing table is used to share distance vectors between adjacent nodes
The latest network distance vector values are shared by each routing table
The distance vector over the nearest node is updated each time data from the routing table is shared across the network.
Advantages of Distance Vector Routing:
- Easy to set up and maintain compared to link-state routing.
Disadvantages of Distance Vector Routing:
- such as slower convergence than link-state routing.
- An infinite number of problems can hurt him.
- Hop count changes generate more traffic than link status because they must be propagated to and processed by all routers.
- Even if the network topology does not change, hop counts are updated frequently, so bandwidth-wasting broadcasts continue to occur
- Distance vector routing requires each router to know about every other router, creating a routing table larger than the link state of a large network.
- It can also cause congestion on WAN connections.
conclusion:
By completing the appropriate steps in the example, you have understood the need and basics of routing protocols in your network.
If you want to learn more about how routing protocols work in your network model and the different procedures for initializing and updating routing tables in your network nodes, take the Cyber ??Security Expert course from Simplilearn. and expand your knowledge
Do you have any questions about "What is distance vector routing?" If so, feel free to let us know in the comments section at the bottom of this page. We will help you solve your problem quickly.