How to Start DSR Routing Projects Using MATLAB
To start Dynamic Source Routing (DSR) using MATLAB which is a reactive routing protocol that used for wireless ad hoc networks and MANETs. It launches routes on-request and utilises source routing with entire path within packet headers.
Steps to Start DSR (Dynamic Source Routing) Project in MATLAB
- Understand DSR
- Key Features:
- Route Discovery: Determines paths dynamically as required.
- Route Maintenance: It manages link failures and invalid routes.
- Source Routing: Packets transmit the complete route within its header.
- Advantages:
- Efficient for dynamic and small networks.
- It has no periodic updates or routing tables.
- Phases:
- Route Discovery: It determines the routes to utilise Route Request (RREQ) and Route Reply (RREP).
- Route Maintenance: Identifies broken links and transmits the Route Error (RERR) messages.
- Set Project Objectives
- Replicate the DSR’s route discovery and maintenance executions.
- Envision the routes and then manage topology modifications like link failures.
- Measure the performance parameters such as delay, overhead, and route availability.
- Define Network Topology
Specify the network like a graph to utilise MATLAB.
Example: Adjacency Matrix
% Define adjacency matrix for a 5-node network
adjMatrix = [
0 1 0 1 0;
1 0 1 0 0;
0 1 0 1 1;
1 0 1 0 1;
0 0 1 1 0
];
% Visualize the network
G = graph(adjMatrix);
plot(G, ‘EdgeLabel’, G.Edges.Weight);
title(‘Network Topology for DSR’);
- Implement DSR Route Discovery
Make use of RREQ and RREP to generate a function for route discovery.
MATLAB Implementation:
function path = dsrRouteDiscovery(adjMatrix, src, dest)
% Perform breadth-first search (BFS) for route discovery
numNodes = size(adjMatrix, 1);
visited = false(1, numNodes);
queue = {src}; % Start with the source node
paths = {src}; % Track paths
while ~isempty(queue)
currentNode = queue{1};
currentPath = paths{1};
queue(1) = [];
paths(1) = [];
visited(currentNode) = true;
if currentNode == dest
path = currentPath;
return;
end
neighbors = find(adjMatrix(currentNode, 🙂 > 0);
for neighbor = neighbors
if ~visited(neighbor)
queue{end+1} = neighbor;
paths{end+1} = [currentPath, neighbor];
end
end
end
path = []; % No path found
end
- Simulate Route Discovery
Compute a path among source and destination nodes to utilise the route discovery function.
Example:
matlab
Copy code
% Define source and destination nodes
srcNode = 1;
destNode = 5;
% Perform route discovery
path = dsrRouteDiscovery(adjMatrix, srcNode, destNode);
% Display the discovered route
if isempty(path)
fprintf(‘No route found from Node %d to Node %d.\n’, srcNode, destNode);
else
fprintf(‘Route from Node %d to Node %d: %s\n’, srcNode, destNode, mat2str(path));
end
- Implement Route Maintenance
Identify and manage the link failures by means of eliminating invalid routes and activating RERR messages.
MATLAB Implementation:
function adjMatrix = dsrRouteMaintenance(adjMatrix, brokenLink)
% Remove the broken link from the adjacency matrix
adjMatrix(brokenLink(1), brokenLink(2)) = 0;
adjMatrix(brokenLink(2), brokenLink(1)) = 0;
end
Example:
% Simulate a link failure between Node 3 and Node 5
brokenLink = [3, 5];
adjMatrix = dsrRouteMaintenance(adjMatrix, brokenLink);
fprintf(‘Updated adjacency matrix after link failure:\n’);
disp(adjMatrix);
- Visualize Routes
Envision the determined route at network graph.
Example:
% Highlight the discovered path
plot(G, ‘EdgeLabel’, G.Edges.Weight);
if ~isempty(path)
highlight(plot(G), path, ‘EdgeColor’, ‘r’, ‘LineWidth’, 2);
end
title(‘DSR Route Visualization’);
- Evaluate Performance
Examine the performance parameters like:
- Routing Overhead: Measure the amount of control messages such as RREQ, RREP, RERR.
- Route Availability: Compute the rate of route that is effectively determined.
- Hop Count: In the discovered routes, we estimate the volume of hops.
- Extend the Project
- Multiple Traffic Flows: It mimics several source-destination pairs.
- Dynamic Topology: Launch the node mobility or arbitrary link failures.
- Caching: Execute the route caching for rapid advance route.
Complete MATLAB Code Example
Below is an incorporated DSR simulation:
% Define adjacency matrix
adjMatrix = [
0 1 0 1 0;
1 0 1 0 0;
0 1 0 1 1;
1 0 1 0 1;
0 0 1 1 0
];
% Visualize the network
G = graph(adjMatrix);
plot(G, ‘EdgeLabel’, G.Edges.Weight);
title(‘Network Topology for DSR’);
% Perform route discovery
srcNode = 1;
destNode = 5;
path = dsrRouteDiscovery(adjMatrix, srcNode, destNode);
% Display the route
if isempty(path)
fprintf(‘No route found from Node %d to Node %d.\n’, srcNode, destNode);
else
fprintf(‘Route from Node %d to Node %d: %s\n’, srcNode, destNode, mat2str(path));
end
% Simulate a link failure
brokenLink = [3, 5];
adjMatrix = dsrRouteMaintenance(adjMatrix, brokenLink);
fprintf(‘Updated adjacency matrix after link failure:\n’);
disp(adjMatrix);
% Visualize the route
plot(G, ‘EdgeLabel’, G.Edges.Weight);
if ~isempty(path)
highlight(plot(G), path, ‘EdgeColor’, ‘r’, ‘LineWidth’, 2);
end
title(‘DSR Route Visualization’);
% Supporting Functions
function path = dsrRouteDiscovery(adjMatrix, src, dest)
numNodes = size(adjMatrix, 1);
visited = false(1, numNodes);
queue = {src};
paths = {src};
while ~isempty(queue)
currentNode = queue{1};
currentPath = paths{1};
queue(1) = [];
paths(1) = [];
visited(currentNode) = true;
if currentNode == dest
path = currentPath;
return;
end
neighbors = find(adjMatrix(currentNode, 🙂 > 0);
for neighbor = neighbors
if ~visited(neighbor)
queue{end+1} = neighbor;
paths{end+1} = [currentPath, neighbor];
end
end
end
path = [];
end
function adjMatrix = dsrRouteMaintenance(adjMatrix, brokenLink)
adjMatrix(brokenLink(1), brokenLink(2)) = 0;
adjMatrix(brokenLink(2), brokenLink(1)) = 0;
end
Conclusion
This project offers basic procedure to replicate and execute the DSR using MATLAB. If you need any help to discover further aspects such as route caching, mobility models, or performance analysis, we will guide you.