Professional Documents
Culture Documents
Distance Vector Routing and Link State Routing: Expt No:7 DATE:28/06/2021
Distance Vector Routing and Link State Routing: Expt No:7 DATE:28/06/2021
Distance Vector Routing and Link State Routing: Expt No:7 DATE:28/06/2021
To perform link state routing and distance vector routing for the given
number of nodes using matlab.
SOFTWARE REQUIREMENTS:
THEORY:
odes.
Consider router X , X will share it routing table to neighbors and neighbors
will share it routing table to it to X and distance from node X to destination
will be calculated using bellmen- ford equation.
Dx(y) = min { C(x,v) + Dv(y)} for each node y ∈ N
As we can see that distance will be less going from X to Z when Y is
intermediate node(hop) so it will be update in routing table X.
Similarly for Z also –
ALGORITHM:
1)Start the program
2)Get the number of nodes from the user using input function
3)Using the rand function the cost matrix is generated such that the cost
between the 2 nodes remains the same in the cost matrix.The matrix is
displayed
4)The upper triangular cost matrix is taken using triu function and the nodes
which are connected is found .
5)Using biograph the graph is displayed using the upper triangular cost matrix
8)The source node and the destination node value is taken from the user using
input function
9)Using find function and minimum function the best path from the source to
destination node is found and the path gets displayed using biogrpah function
clc;
clear all;
disp('Distance vector routing protocol');
node=input('Enter the no. of nodes: ');
over=0;
for i=1:node %initialize
for j=i:node
if(i==j)
matrix(i,j)=0;
else
matrix(i,j)=randint(1,1,9);
matrix(j,i)=matrix(i,j);
end
end
end
disp(matrix);
i=1;
x=1;
mat1=triu(matrix);
for i=1:node
for j=1:node
if(mat1(i,j)~=0)
mat(i,j)=x;
mat(j,i)=mat(i,j);
x=x+1;
end
end
end
view(biograph(triu(matrix),
[],'showarrows','off','ShowWeights','on','EdgeTextColor',[0 0 1]));
for from=1:node% fill initial matrix with via = to
for via=1:node
for to=1:node
if(from~=via&&from~=to)
if(via==to&&matrix(from,to)~=0)
go(to,via,from)=matrix(from,to);
else
go(to,via,from)=100;
end
else
go(to,via,from)=inf;
end
end
end
end
i=0;
while(i<2)
for from=1:node
for to=1:node
if(from~=to)
if(matrix(from,to)~=0)%calculate neighbour node
for x=1:node
for y=1:node
temp(x,y)=matrix(from,to)+min(go(y,:,to));
if(temp(x,y)<go(y,to,from)&&go(y,to,from)<inf)
go(y,to,from)=temp(x,y);
end
end
end
end
end
end
end
i=i+1;
end
disp(go);
choice='y';
while(choice=='y')
source=input('Enter the source node: ');
dest=input('Enter the destination node: ');
trace(1)=source;
j=2;
while(source~=dest)
[row,col]=find(go(dest,:,source)==min(go(dest,:,source)));
trace(j)=col;
source=col;
j=j+1;
end
k=1:j-1;
disp(trace(k));
bg=biograph(triu(matrix),
[],'showarrows','off','ShowWeights','on','EdgeTextColor',[0 0 1]);
for i=1:j-1
set(bg.nodes(trace(i)), 'color', [1 0 0]);
set(bg.nodes(trace(1)),'color',[0 1 0]);
if(i<j-1)
set(bg.edges(mat(trace(i+1),trace(i))),'linecolor',[1 0 0]);
end
end
view(bg);
choice=input('Do you want to try again (y/n):','s');
end
OUTPUT:
DISPLAYING NODES WITH WEIGHT:
EFFECTIVE PATH:
LINK STATE ROUTING:
Link state routing is a technique in which each router shares the knowledge of
its neighborhood with every other router in the internetwork.
Reliable Flooding
Route Calculation
Each node uses Dijkstra's algorithm on the graph to calculate the optimal
routes to all nodes.
ALGORITHM:
2)Get the number of nodes from the user using input function
3)Using the rand function the cost matrix is generated and the matrix is
displayed
4)The source node and the destination node value is taken from the user using
input function
5)The distance between the source and the other nodes is taken in a array
,here the distance between the source node to itself is made infinite
6)The node with minimum cost is made as the new source and the minimum
cost get stored in a array , this loop repeats until the source node is equal to
the destination
7)The values taken by the source node during each iteration gets displayed in
form of alphabets .This string denotes the path from source to destination.
8)The values in the minimum cost array gets summed up to give the total cost
of the path.
clc;
% Taking number of input nodes from user
n=input('Please enter the number of nodes = ');
% Checking for bad input
OUTPUT:
RESULT:
Thus the direction vector routing and link state routing are performed using
matlab and the results are verified.