How to Simulate On demand Protocol Projects Using MATLAB

To simulate on-demand routing protocols like Ad hoc On-Demand Distance Vector Routing (AODV) or Dynamic Source Routing (DSR) in MATLAB has includes to configure a wireless ad hoc network, executing the route discovery process (RREQ and RREP), and replicating data packet transmission. On-demand protocols construct routes only when required, reducing overhead however it needs more time for route discovery.

Here’s a comprehensive guide to replicate on-demand routing protocols in MATLAB:

Steps to Simulate On-Demand Routing Protocols

  1. Network Initialization:
  • Describe the network topology (randomly or pre-configured), in which nodes are shared over a certain area.
  • Each node has a certain communication range to create the network.

% Parameters

num_nodes = 20;             % Number of nodes

area_size = 100;            % Area size (100×100 units)

communication_range = 30;   % Communication range of each node

nodes = area_size * rand(num_nodes, 2); % Random (x, y) coordinates for nodes

% Plot network topology

scatter(nodes(:, 1), nodes(:, 2), ‘filled’);

xlabel(‘X coordinate’);

ylabel(‘Y coordinate’);

title(‘Wireless Ad Hoc Network’);

grid on;

  1. Identify Neighboring Nodes:
  • Estimate the distance among each pair of nodes and regulate the neighbouring nodes according to the communication range.

% Calculate distance between all node pairs

distances = pdist2(nodes, nodes);

% Adjacency matrix based on communication range

adjacency_matrix = distances <= communication_range & distances > 0;

% Visualize connections

hold on;

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

  1. Route Discovery (AODV Example):

AODV utilizes Route Request (RREQ) and Route Reply (RREP) messages to introduce routes only when required. Here’s how we can replicate a simple route discovery process in AODV.

% Source and destination nodes

source = 1;

destination = num_nodes;

% Route request (RREQ) initiated by source

routing_table = cell(num_nodes, 1);  % Stores the path for each node

routing_table{source} = [source];    % Start route discovery from source

% A queue to process nodes during route discovery

queue = source;

found_route = false;

while ~isempty(queue)

current_node = queue(1); % Get first node from the queue

queue(1) = [];           % Remove the node from the queue

% Broadcast RREQ to all 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 neighbor to the queue

% If destination is found, stop route discovery

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

  1. Route Maintenance:

In AODV, if a link beside the route disruptions in the period of data transmission, the nodes has contained to start route error (RERR) messages. In the simulation, we can establish random link failures and modernize the routes dynamically.

  1. Data Transmission:

Once the route is introduced, replicate the transmission of data packets among the origin and destination alongside the discovered route.

if found_route

route = routing_table{destination};

fprintf(‘Transmitting data from Node %d to Node %d\n’, source, destination);

for i = 1:length(route)-1

current_node = route(i);

next_node = route(i+1);

fprintf(‘Data forwarded from Node %d to Node %d\n’, current_node, next_node);

end

else

disp(‘No route available for data transmission.’);

end

  1. Energy Model (Optional):

To replicate realistic ad hoc networks, that contains an energy consumption model for each node. Energy is used in the period of transmission and reception of data.

% Energy consumption parameters

E_tx = 50e-9; % Energy to transmit per bit (in joules)

E_rx = 50e-9; % Energy to receive per bit (in joules)

packet_size = 4000; % Packet size in bits

% Initialize energy levels for each node

energy = ones(1, num_nodes);  % Initial energy of 1 joule per node

% Calculate the energy consumed during transmission along the route

if found_route

for i = 1:length(route)-1

current_node = route(i);

next_node = route(i+1);

% Calculate distance between nodes

distance = sqrt(sum((nodes(current_node, 🙂 – nodes(next_node, :)).^2));

% Update energy of current and next nodes

energy(current_node) = energy(current_node) – E_tx * packet_size * distance;

energy(next_node) = energy(next_node) – E_rx * packet_size;

end

end

% Display remaining energy levels

disp(‘Remaining energy of nodes:’);

disp(energy);

  1. Routing Metrics and Performance Analysis:

We can measure different key parameter like:

  • Packet Delivery Ratio: Ratio of successfully delivered packets to the total amount of packets transmitted.
  • Average Latency: Average time it takes for a packet to move from origin to destination.
  • Energy Consumption: Total energy used by the network.
  • Route Discovery Time: Time taken to identify a route to the destination.

Example of plotting remaining energy after the simulation:

figure;

bar(energy);

xlabel(‘Node ID’);

ylabel(‘Remaining Energy (Joules)’);

title(‘Energy Levels After Simulation’);

  1. Loop over Multiple Rounds (Optional):

For a more all-inclusive replication, we can reiteration the process over several rounds, in which each round consist diverse source-destination pairs or even node mobility.

rounds = 100;

for round = 1:rounds

% Random source and destination for each round

source = randi(num_nodes);

destination = randi(num_nodes);

% Perform route discovery and data transmission (steps 3-6)

% You can encapsulate those steps in a function and call it here.

end

Simulating Other On-Demand Protocols:

  • DSR (Dynamic Source Routing):
    • In DSR, the origin node has contained the entire path to the destination in the packet header. Route discovery is same as to AODV; however route maintenance and caching differ.
    • Adapt the route discovery to accumulation the whole path in the routing table.
  • TORA (Temporally-Ordered Routing Algorithm):
    • TORA is a distributed, multi-hop routing protocol intended for highly dynamic mobile ad hoc networks (MANETs). It generates routes only when required and sustains multiple paths.
    • Executing TORA would need additional route maintenance and failure management.

Enhancements:

  • Mobility: we can replicate node mobility using random waypoint mobility designs and recalculate routes when nodes transmit.
  • Link Failures: Establish random link failures and replicate route error messages (RERR).
  • Packet Loss and Delays: Incorporate packet loss design or propagation latency to make the replication more realistic.

Throughout this report, you can completely concentrate on how to implement the on-demand routing protocols in the network with the help of MATLAB by defining the routing protocol into the simulation. You can refer the instances and snippet codes for references.

To receive optimal simulation support for your On-demand Protocol Projects utilizing the MATLAB tool, we kindly request that you send us the details of your project via email. We are fully equipped to provide you with the best assistance possible. Our expertise includes configuring wireless ad hoc networks and implementing routing protocols such as Ad hoc On-Demand Distance Vector Routing (AODV) and Dynamic Source Routing (DSR). We can assist you in executing the route discovery process (RREQ and RREP) and simulating data packet transmission based on your specific requirements. Let us help you achieve the desired performance for your project.

Opening Time

9:00am

Lunch Time

12:30pm

Break Time

4:00pm

Closing Time

6:30pm

  • award1
  • award2