To simulate reactive routing protocols in MATLAB has includes executing the protocols which identifies the routes on demand like Ad hoc On-Demand Distance Vector Routing (AODV) or Dynamic Source Routing (DSR). In compare to proactive protocols which sustains routing tables, reactive protocols introduce routes only when a origin node needs to interact with a destination node, creating them effective for networks with dynamic topology, like Mobile Ad Hoc Networks (MANETs).
Here’s a brief step-by-step guide to mimic reactive routing protocols using MATLAB:
Steps to Simulate Reactive Routing Protocols in MATLAB
- Define the Network Topology:
- Initially, describe the network topology in which nodes like routers or mobile devices are shared over a specific area. We can signify this using an adjacency matrix in which a positive value signifies a link among nodes, and the value denotes the link cost such as hop count or distance.
Example:
% Number of nodes in the network
num_nodes = 10;
% Define the size of the simulation area
area_size = 100;
% Randomly generate positions for the nodes
nodes = area_size * rand(num_nodes, 2); % Random (x, y) coordinates
% Communication range of each node (distance threshold for neighbors)
comm_range = 30;
% Plot the network topology
scatter(nodes(:, 1), nodes(:, 2), ‘filled’);
xlabel(‘X coordinate’);
ylabel(‘Y coordinate’);
title(‘Network Topology with Random Node Placement’);
grid on;
hold on;
- Identify Neighboring Nodes:
- Estimate the distance among each pair of nodes and introduce links among nodes that are inside the communication range.
Example:
% Calculate pairwise distances between nodes
distances = pdist2(nodes, nodes);
% Create adjacency matrix based on the communication range
adjacency_matrix = distances <= comm_range & distances > 0;
% Visualize the connectivity between nodes
for i = 1:num_nodes
for j = i+1:num_nodes
if adjacency_matrix(i, j)
plot([nodes(i, 1), nodes(j, 1)], [nodes(i, 2), nodes(j, 2)], ‘k–‘);
end
end
end
- Implement the Routing Protocol:
- AODV (Ad hoc On-Demand Distance Vector Routing):
- In AODV, routes are discovered on-demand using Route Request (RREQ) and Route Reply (RREP) messages. While the destination is identified, a route is introduced, and packets are sending via this route.
Example of a simplified AODV route discovery process:
% Source and destination nodes
source = 1;
destination = num_nodes;
% Initialize routing table for each node
routing_table = cell(num_nodes, 1);
routing_table{source} = [source]; % Start route at the source node
% Simulate AODV route discovery (using a queue)
queue = source; % Start the queue with the source node
found_route = false;
while ~isempty(queue)
current_node = queue(1); % Dequeue the first node
queue(1) = []; % Remove the first node from the queue
% Broadcast RREQ to neighbors
for i = 1:num_nodes
if adjacency_matrix(current_node, i) && isempty(routing_table{i})
routing_table{i} = [routing_table{current_node}, i]; % Update route
queue = [queue, i]; % Add the neighbor to the queue
% If destination is found, stop the search
if i == destination
found_route = true;
break;
end
end
end
if found_route
break;
end
end
% Display the route if found
if found_route
disp(‘Route found:’);
disp(routing_table{destination});
else
disp(‘No route found.’);
end
- DSR (Dynamic Source Routing):
- In DSR, routes are sustained in the packet headers. The origin node has involves the complete route in the packet, enabling nodes beside the path to send the packet to the next hop.
Example of DSR route discovery:
% Route discovery process is similar to AODV, but the entire route is stored
if found_route
% Source node discovers and stores the entire route
route = routing_table{destination};
fprintf(‘Route from Node %d to Node %d: ‘, source, destination);
disp(route);
else
disp(‘No route found.’);
end
- Simulate Packet Forwarding:
- Once a route is identified by using AODV or DSR, replicate the process of transmitting packets from the origin to the destination beside the introduced route.
Example:
if found_route
route = routing_table{destination};
fprintf(‘Forwarding packet from Node %d to Node %d via route: ‘, source, destination);
disp(route);
% Forward the packet through the discovered route
for i = 1:length(route) – 1
current_node = route(i);
next_node = route(i + 1);
fprintf(‘Packet forwarded from Node %d to Node %d\n’, current_node, next_node);
end
else
disp(‘No route available for packet transmission.’);
end
- Mobility Models (Optional):
- In dynamic wireless networks like MANETs, nodes can move, that needs recalculating routes. We can replicate node mobility using designs like the Random Waypoint Mobility Model.
Example of adding mobility to the nodes:
% Random waypoint mobility model
for i = 1:num_nodes
% Update the position of each node with some random movement
nodes(i, 🙂 = nodes(i, 🙂 + randn(1, 2); % Update with random movement
end
% Recalculate distances and update adjacency matrix
distances = pdist2(nodes, nodes);
adjacency_matrix = distances <= comm_range & distances > 0;
% Repeat route discovery after node movement (simulate dynamic topology)
- Performance Metrics:
We can measure the performance of protocol by evaluating key parameters:
- Route Discovery Time: Time taken to identify the route.
- Packet Delivery Ratio: Ratio of successfully delivered packets to total packets transmitted.
- End-to-End Delay: Time taken for a packet to transmit from origin to destination.
- Routing Overhead: Amount of control messages interchanged such a RREQ, RREP.
Example of calculating end-to-end delay:
% Define packet transmission speed (in units per second)
transmission_speed = 1; % Example value
% Calculate end-to-end delay (based on the number of hops in the route)
num_hops = length(routing_table{destination}) – 1;
end_to_end_delay = num_hops / transmission_speed;
fprintf(‘End-to-End Delay: %.2f seconds\n’, end_to_end_delay);
- Simulate Multiple Rounds (Optional):
- For more dynamic replication, we can replicate the protocol over multiple rounds in which the routes are recalculated by the way of nodes transfer or new source-destination pairs are appropriated.
Example:
rounds = 100;
for round = 1:rounds
% Randomly select a new source and destination node
source = randi(num_nodes);
destination = randi(num_nodes);
% Perform route discovery and packet transmission (repeat the above steps)
end
Make use of the provided steps and instructions which make it easier for you to focus on the implementation of reactive routing protocols using MATLAB tool that has includes to generate a network topology then apply the routing protocol and visualized the outcomes. To receive the best help with your Reactive Protocol Projects using MATLAB, please send us your project details via email. We are fully equipped to provide you with excellent support. We work with Ad hoc On-Demand Distance Vector Routing (AODV) and Dynamic Source Routing (DSR) based on your needs. Let us handle your project performance.