×

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.


Related Topics

How to create a node in C?

A node is a small concept taken from the graph theory, or a node is a fundamental unit of a data structure, like a tree data structure. Every graph contains...

3 minutes read.

How to open a C file on android mobile

A C file is a file that has a .c extension and contains code written in the C language. C is a computer programming language developed by Dennis Ritchie at...

4 minutes read.

Runtime vs compile time in C

In the C programming language, the often used terms in every step consist of compile time and runtime. The compile time is referred to the source code that will be...

4 minutes read.

Find reverse of an array in C using functions

Introduction: Here, we describe how to find the reverse array in C using functions. Suppose you have an array with n elements. I need to display the elements present in...

3 minutes read.

memcpy() in C

Introduction: Here we discuss about the memcpy() function in C. The memcpy() function is also called the Copy Memory Block function. Used to create a copy of a specific drawing...

4 minutes read.

Positioning of file in C

Positioning() function in c The fseek() function is utilized to change the document position of the stream . The fully extent of value from the source should be one of the...

3 minutes read.

Multithreading in C interview questions

Q1. What exactly is a thread? Ans: A thread is a brief sequence of instructions intended to be planned and carried out by the CPU apart from the parent process. Q2. Can...

4 minutes read.

Snake Game in C

Snake game in C is basic desktop console program which was created in 1970’s. It is an old classic game which was played by every child across the world. This...

4 minutes read.

Calendar application in C

Introduction to the calendar application We all are familiar with the calendar. It plays a crucial role in our daily life. We run toward the calendar whenever we want to know...

6 minutes read.

Isalnum() function in C

Introduction: The isalnum () is a function used in C programming language. This function checks the passing number or argument is an alphanumeric number or not. The alphanumeric number consists of the...

3 minutes read.

Error handling in C

Error handling in C: The C programming standard does not provide direct convenience for handling the errors. However, being a system programming language, it definitely will give access to handling...

4 minutes read.

Limitations of Inline Function in C

The compiler is unable to conduct inlining in two instances. It just accepts the inline definitions and produces space for the function in the same way it does for a...

3 minutes read.

Storage class in C

Storage class in C defines the scope, the visibility, and the lifetime of variables and functions. In other words, storage classes are used to describe the features of variables and...

3 minutes read.

Beep() function in C

Introduction: Beep is a function which is used in C programming language. The beep function uses to make a beep sound. In the C language, when we want to generate...

3 minutes read.

Data Structures And Algorithms in C

C language is one of the most flexible and simple languages. So, it is always better to learn any concept in C language compared to other languages. Let us look...

13 minutes read.

What is algorithm in C?

What is an algorithm? In computer programming languages, an algorithm is set of statement that solves a particular problem. In C, first step of every algorithm is Start and last step of...

3 minutes read.

Memory leak in C

What is memory leak in C? Memory leak occurs when we keep allocating memory in the heap without freeing it, i.e., the allocated memory in heap is not released back to...

3 minutes read.

C Array

An array is a collection of elements that are used to hold the fixed number of values of the same type. We cannot change the size and type of array...

2 minutes read.

Variable in C

Variable is an identifier that holds data in memory. It is used to identify input data in a program. The value of the variable can change at the time of...

2 minutes read.

How to use sine() function in C

What is Function? The function is a set of statements. It takes input and performs some computation to produce output. The process is a set of codes only achieved when it is...

3 minutes read.