To simulate the Dynamic Source Routing (DSR) protocol using MATLAB, we require designing 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 wants to interact with a destination. It is rely on two key mechanisms:
- Route Discovery: Source node finds a route to the destination.
- Route Maintenance: Origin node sustains routes and repairs broken links as they happen.
Following is a step-by-step instruction to simulating DSR in MATLAB:
Steps to Simulate DSR Protocol Projects in MATLAB
- Define Network Topology
Start by describing the network topology that involves nodes and the links amongst them. We can denote the network as an adjacency matrix or as a list of links among the 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 origin node transmits a Route Request (RREQ) packet to every its neighbors to find a route to the destination. The neighbors then send this packet until it attains the destination, which gathering the path within 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 like because of node mobility. If a link breaks then a Route Error (RERR) packet is transmitted again to the origin, 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 are cache routes, which they learn for the period of the route discovery phase. It permits them to use again routes for subsequent communications without requiring finding again 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 move that triggering the routes to break. We can replicate the mobility by arbitrarily modifying the connectivity (adjacency matrix) among the nodes over time and then monitoring how DSR manages these changes.
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 MATLAB’s plotting functions to examine the network topology and the routes determined 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 estimate the performance of DSR simulation utilizing the parameters like:
- Route Discovery Latency: Duration finding a route.
- Route Maintenance Frequency: Frequency of route repairs by reason of link failures.
- Packet Delivery Ratio: Ratio of efficiently delivered packets to the total packets is transmitted.
Example Projects with DSR Simulation in MATLAB:
- DSR in MANETs with Node Mobility: Replicate the DSR within a dynamic network with node mobility and calculate the protocol’s performance such as route discovery and maintenance.
- Energy-Aware DSR: Change the DSR protocol to integrate the energy metrics in which nodes prefer routes which reduce energy consumption.
- Comparing DSR with Other Protocols: Liken 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 the DSR such as minimized route discovery time and enhanced efficiency.
By utilizing MATLAB environment, we successfully executed the simulation process for DSR protocol projects that were replicated and estimated. We are furnished to provide more crucial details if necessary. phdprime.com is here to help you with the best network performance reports. If you want to complete your topics and simulations easily, just reach out to us for great results. We offer the right DSR Protocol Projects using MATLAB tailored to your needs. We will also give you step-by-step instructions for simulating DSR in MATLAB.