Distance Vector Routing Algorithm | Distance vector routing algorithm in c | Obtain Routing Table

NAME OF EXPERIMENT : Distance Vector Routing



AIM: Obtain Routing table at each node using distance vector routing algorithm  for a given set


HARDWARE REQUIREMENTS: Intel-based Desktop PC:- RAM of 512 MP

SOFTWARE REQUIREMENTS: Turbo C / Borland C

THEORY: 
  Distance Vector routing algorithm in computer networks is also called as Automatic or Adaptive Routing. No need of manual configuration(unlike static routing ).  Routing decisions or selecting the best path is done by routers with the help of routing protocols.  Admin configures routing protocols e.g. RIP, EIGRP, OSPF etc.  This distance vector routing algorithm is ideal for medium or large sized networks or organizations.  They change their routing decisions if there is change is a topology, traffic (Updated the topology changes dynamically).each router continuously checks network status (Learns about other networks via advertisement) communicating with neighbors (Advertisement of routing information).  Administrative work is reduced.

ALGORITHM:
Begin
Step1: Create struct node unsigned dist[20],unsigned from[20],rt[10]
Step2: initialize int dmat[20][20], n,i,j,k,count=0,
Step3: write "the number of nodes "
Step4: read the number of nodes "n"
Step5: write" the cost matrix :"
Step6: intialize i=0
Step7: repeat until i<n
Step8: increment i
Step9: initialize j=0
Step10:repeat Step(10-16)until j<n
Step11: increment j
Step12:read dmat[i][j]
Step13:intialize dmat[i][j]=0
Step14:intialize rt[i].dist[j]=dmat[i][j]
Step15:intialize rt[i].from[j]=j
Step16:end
Step17:start do loop Step (17-33)until
Step18:intilialize count =0
Step19:initialize i=0
Step20:repeat until i<n
Step21:increment i
Step22:initialize j=0
Step23:repeat until j<n
Step24:increment j
Step25:initialize k=0
Step26:repeat until k<n
Step27:increment k
Step28:if repeat Step(28-32) until rt[i].dist[j]>dmat[i][k]+rt[k].dist[j]
Step29:intialize rt[i].dist[j]=rt[i].dist[k]+rt[k].dist[j]
Step30:intialize rt[i].from[j]=k;
Step31:increment count
Step32:end if 
Step33:end do stmt
Step34:while (count!=0)
Step 35: Initialize i=0
Step36:repeat Steps(36-44)until i<n
Step37:increment i
Step38:write ' state values for router',i+1
Step39:initialize j=0
Step40:repeat Steps ( 40-43)until j<n
Step41:increment j
Step42:write 'node %d via %d distance % ',j+1,rt[i].from[j]+1,rt[i].dist[j]
Step43:end
Step44:end

end

SOURCE CODE:

/*
Distance Vector Routing in this program is implemented using Bellman Ford Algorithm:-
*/
#include<stdio.h>
struct node
{
    unsigned dist[20];
    unsigned from[20];
}rt[10];
int main()
{
    int costmat[20][20];
    int nodes,i,j,k,count=0;
    printf("\n Enter the number of nodes : ");
scanf("%d",&nodes);//Enter the nodes
    printf("\n Enter the cost matrix :\n");
    for(i=0;i<nodes;i++)
    {
        for(j=0;j<nodes;j++)
        {
scanf("%d",&costmat[i][j]);
costmat[i][i]=0;
rt[i].dist[j]=costmat[i][j];//initialise the distance equal to cost matrix
rt[i].from[j]=j;
        }
    }
        do
        {
            count=0;
            for(i=0;i<nodes;i++)//We choose arbitary vertex k and we calculate the direct distance from the node i to k using the cost matrix
            //and add the distance from k to node j
            for(j=0;j<nodes;j++)
            for(k=0;k<nodes;k++)
                if(rt[i].dist[j]>costmat[i][k]+rt[k].dist[j])
                {//We calculate the minimum distance
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<nodes;i++)
        {
         printf("\n\nState value for router %d\n",i+1);
            for(j=0;j<nodes;j++)
            {
               printf("\t\n\tnode %d via %d Distance %d ",j+1,rt[i].from[j]+1,rt[i].dist[j]);
            }
        }
    printf("\n\n");
getch();
return 0;
}

OUTPUT:


Comments

Search related post on google