To simulate the Dynamic Source Routing (DSR) protocol using MATLAB, we need to create a design of the routing mechanism for mobile ad hoc networks (MANETs). The DSR protocol is a reactive routing protocol, which finds routes on-demand once a source requires interacting with a destination. It is depends on two key mechanisms:
- Route Discovery: Source node finds a route to the destination.
- Route Maintenance: Source node sustains the routes and repairs broken links as they happen.
Let’s know how to replicate the DSR using this guide in MATLAB:
Steps to Simulate DSR Protocol Projects in MATLAB
- Define Network Topology
Initially stage is describing the network topology that involves the nodes and the links among them. We can denote the network as a list of links or as an adjacency matrix amongst nodes.
Example: Define Network Topology
% Number of nodes
numNodes = 6;
% Define the adjacency matrix for the network (Inf represents no direct connection)
adjMatrix = [
0 1 Inf 3 Inf Inf; % Node 1 connections
1 0 2 Inf 4 Inf; % Node 2 connections
Inf 2 0 1 3 Inf; % Node 3 connections
3 Inf 1 0 Inf 2; % Node 4 connections
Inf 4 3 Inf 0 1; % Node 5 connections
Inf Inf Inf 2 1 0 % Node 6 connections
];
% Display the adjacency matrix
disp(‘Network Adjacency Matrix:’);
disp(adjMatrix);
- Route Discovery Mechanism
In DSR, the source node transmits a Route Request (RREQ) packet to its every neighbor to find a route to the destination. The neighbors then send this packet until it attains the destination, which gathering the path in the process.
Example: Route Request (RREQ) Propagation
% Function to perform Route Request (RREQ) propagation
function [path, found] = dsrRouteRequest(adjMatrix, sourceNode, destNode)
numNodes = size(adjMatrix, 1);
visited = zeros(1, numNodes); % Keep track of visited nodes
path = []; % The path from source to destination
queue = {sourceNode}; % Queue for BFS-like search
paths = {sourceNode}; % Store paths for each node
while ~isempty(queue)
currentNode = queue{1}; % Dequeue the first element
currentPath = paths{1}; % Get the current path
queue(1) = []; % Remove the current node from queue
paths(1) = []; % Remove the current path
if currentNode == destNode
path = currentPath; % Path found
found = true;
return;
end
% Visit neighbors
for neighbor = 1:numNodes
if adjMatrix(currentNode, neighbor) < Inf && visited(neighbor) == 0
queue{end+1} = neighbor; % Add neighbor to queue
paths{end+1} = [currentPath, neighbor]; % Add to path
visited(neighbor) = 1; % Mark as visited
end
end
end
path = []; % If no path is found
found = false;
end
% Source and destination nodes
sourceNode = 1;
destNode = 5;
% Perform route discovery (RREQ) from source to destination
[path, found] = dsrRouteRequest(adjMatrix, sourceNode, destNode);
% Display the discovered path
if found
disp([‘Route discovered from Node ‘, num2str(sourceNode), ‘ to Node ‘, num2str(destNode), ‘:’]);
disp(path);
else
disp([‘No route found from Node ‘, num2str(sourceNode), ‘ to Node ‘, num2str(destNode)]);
end
- Route Maintenance
In DSR, routes are sustained until the link breaks such as due to node mobility. If a link breakdowns then a Route Error (RERR) packet is transmitted again to the source, and the source introduces another route discovery.
Example: Route Maintenance with Link Failure
% Function to simulate link failure and route error propagation
function [newPath, found] = dsrRouteMaintenance(adjMatrix, brokenLink, sourceNode, destNode)
% Remove the broken link from the adjacency matrix
adjMatrix(brokenLink(1), brokenLink(2)) = Inf;
adjMatrix(brokenLink(2), brokenLink(1)) = Inf;
% Re-run route discovery to find a new path
[newPath, found] = dsrRouteRequest(adjMatrix, sourceNode, destNode);
end
% Simulate a link failure between nodes 2 and 5
brokenLink = [2, 5];
disp([‘Simulating link failure between Node ‘, num2str(brokenLink(1)), ‘ and Node ‘, num2str(brokenLink(2))]);
% Re-run route discovery after the link failure
[newPath, found] = dsrRouteMaintenance(adjMatrix, brokenLink, sourceNode, destNode);
% Display the new path after link failure
if found
disp([‘New route discovered from Node ‘, num2str(sourceNode), ‘ to Node ‘, num2str(destNode), ‘:’]);
disp(newPath);
else
disp([‘No route found from Node ‘, num2str(sourceNode), ‘ to Node ‘, num2str(destNode), ‘ after link failure’]);
end
- Caching Routes
In DSR, nodes cache routes which they understand for the period of the route discovery phase. It permits them to reuse routes for subsequent communications without requiring rediscovering them.
Example: Caching Routes
% Initialize a route cache (each node stores routes)
routeCache = cell(1, numNodes);
% Function to add a route to the route cache
function routeCache = cacheRoute(routeCache, sourceNode, destNode, path)
routeCache{sourceNode} = [routeCache{sourceNode}; {destNode, path}];
end
% Add discovered route to the cache
routeCache = cacheRoute(routeCache, sourceNode, destNode, path);
% Display the route cache for each node
disp(‘Route cache:’);
for node = 1:numNodes
disp([‘Node ‘, num2str(node), ‘:’]);
disp(routeCache{node});
end
- Simulating Mobility
In mobile ad hoc networks (MANETs), nodes can transfer which triggering the routes to break. We can replicate the mobility by arbitrarily modifying the connectivity (adjacency matrix) among nodes over time and then monitoring how DSR manages these alterations.
Example: Simulating Node Mobility
% Function to simulate node mobility by randomly changing connections
function adjMatrix = simulateMobility(adjMatrix, probChange)
numNodes = size(adjMatrix, 1);
for i = 1:numNodes
for j = i+1:numNodes
if rand < probChange
% Randomly add or remove a link between nodes
if adjMatrix(i, j) < Inf
adjMatrix(i, j) = Inf; % Remove link
adjMatrix(j, i) = Inf;
else
adjMatrix(i, j) = randi([1, 5]); % Add link with random cost
adjMatrix(j, i) = adjMatrix(i, j);
end
end
end
end
end
% Simulate mobility with a 20% chance of changing links
adjMatrix = simulateMobility(adjMatrix, 0.2);
% Display the updated network topology after mobility
disp(‘Updated Network Topology (Adjacency Matrix) after mobility:’);
disp(adjMatrix);
- Visualizing the Network Topology
Use utilizing MATLAB’s plotting functions to envision the network topology and the routes found by the DSR protocol.
Example: Visualizing the Network Topology and Routes
% Define positions of nodes for visualization
nodePositions = [
0 0; % Node 1
1 0; % Node 2
2 0; % Node 3
1 1; % Node 4
2 1; % Node 5
3 0 % Node 6
];
% Plot the network topology
figure;
hold on;
gplot(adjMatrix < Inf, nodePositions, ‘-o’);
for i = 1:numNodes
text(nodePositions(i, 1), nodePositions(i, 2), [‘Node ‘, num2str(i)], ‘FontSize’, 12);
end
title(‘Network Topology’);
xlabel(‘X Position’);
ylabel(‘Y Position’);
% Plot the discovered path (if found)
if found
for i = 1:length(path)-1
plot([nodePositions(path(i), 1), nodePositions(path(i+1), 1)], …
[nodePositions(path(i), 2), nodePositions(path(i+1), 2)], ‘r-‘, ‘LineWidth’, 2);
end
title(‘Network Topology with Discovered Route’);
end
hold off;
- Performance Metrics
We can assess the performance of DSR simulation utilizing parameters like:
- Route Discovery Latency: Duration to find a route.
- Route Maintenance Frequency: Frequency of route repairs by reason of link failures.
- Packet Delivery Ratio: Ratio of effectively delivered packets to the total packets IS transmitted.
Example Projects with DSR Simulation in MATLAB:
- DSR in MANETs with Node Mobility: Replicate DSR within a dynamic network along with node mobility and compute the protocol’s performance such as route discovery and maintenance.
- Energy-Aware DSR: Change the DSR protocol to integrate an energy metrics in which nodes have a preference to routes, which reduce energy consumption.
- Comparing DSR with Other Protocols: Relate the DSR with other ad hoc routing protocols such as AODV and OLSR like packet delivery ratio, latency, and overhead.
- Caching Performance in DSR: Examine the effect of route caching on the performance of DSR such as minimized route discovery time and enhanced efficiency.
We had given brief demonstration for you to simulate the Dynamic Source Routing (DSR) protocol projects and to evaluate its performance using procedure with coding snippets and sample projects ideas in MATLAB environment. We will also be offered advanced concepts of this project in another manual.
phdprime.com provide a range of project ideas and conduct performance analyses tailored to your specific interests. At phdprime.com, we are committed to being your premier partner for simulating DSR Protocol projects using MATLAB. Our expertise lies in mobile ad hoc networks (MANETs), where we offer top-notch research topics and innovative ideas to support your endeavors.