To simulate Hybrid Wireless Mesh Protocol (HWMP) in MATLAB has several steps to follow and it is the defaulting routing protocol for IEEE 802.11s wireless mesh networks. It is a hybrid protocol which integrated both reactive and proactive routing approaches. In reactive mode, it identifies routes on-demand using Path Request (PREQ) and Path Reply (PREP) messages. In proactive mode, it intermittently sustains paths to a root node.
Here’s a detailed guide on how to replicate the HWMP protocol in MATLAB:
Steps to Simulate HWMP Protocol in MATLAB
- Define the Network Topology:
- Initially, describe a wireless mesh network in which the nodes are shared in a specified area. These nodes signify mesh routers, and the communication range among them regulates the links.
Example:
% Number of nodes in the wireless mesh network
num_nodes = 20;
% Define the simulation area size (e.g., 100×100 units)
area_size = 100;
% Randomly generate node positions
nodes = area_size * rand(num_nodes, 2); % Random (x, y) coordinates
% Define the communication range (e.g., 30 units)
comm_range = 30;
% Plot the network topology
figure;
scatter(nodes(:, 1), nodes(:, 2), ‘filled’);
xlabel(‘X coordinate’);
ylabel(‘Y coordinate’);
title(‘Wireless Mesh Network for HWMP Simulation’);
grid on;
hold on;
- Create the Adjacency Matrix:
- Estimate the pairwise distances among the nodes and introduce communication links for nodes in the communication range.
Example:
% Calculate the pairwise distances between nodes
distances = pdist2(nodes, nodes);
% Create adjacency matrix based on communication range
adjacency_matrix = distances <= comm_range & distances > 0;
% Plot the links between neighboring 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
- Initialize HWMP Tables:
- HWMP needs an each node to sustain a routing table which stores paths to destination nodes and a preq table for managing Path Request (PREQ) and Path Reply (PREP) messages.
Example:
% Initialize the routing table for each node (destination, next hop, metric)
routing_table = cell(num_nodes, 1);
% Initialize each node’s routing table as empty
for i = 1:num_nodes
routing_table{i} = {}; % Each entry will store {Destination, Next Hop, Metric}
end
- Reactive Route Discovery (PREQ and PREP):
- In reactive mode, an origin node floods the network with a Path Request (PREQ) when it requires a route to the destination. Intermediate nodes broadcast the PREQ until it reaches the destination that reacts with a Path Reply (PREP).
Example of Path Request (PREQ) and Path Reply (PREP):
% Function to perform path request (PREQ) in HWMP
function hwmp_preq(source, destination, adjacency_matrix, nodes)
% Queue to store nodes for breadth-first search (BFS)
queue = [source];
visited = zeros(1, num_nodes); % Mark visited nodes
visited(source) = 1;
% Parent structure to reconstruct the path
parent = cell(num_nodes, 1);
while ~isempty(queue)
current_node = queue(1); % Dequeue the first node
queue(1) = [];
% Get neighbors of the current node
neighbors = find(adjacency_matrix(current_node, :));
for i = 1:length(neighbors)
next_node = neighbors(i);
if ~visited(next_node)
visited(next_node) = 1;
queue = [queue, next_node]; % Enqueue the neighbor
% Record the parent node for path reconstruction
parent{next_node} = current_node;
% If destination is reached, send Path Reply (PREP)
if next_node == destination
fprintf(‘PREP: Path found from %d to %d\n’, source, destination);
% Reconstruct the path
path = [];
current = destination;
metric = 0; % Initialize metric (e.g., hop count)
while current ~= source
metric = metric + 1;
path = [current, path]; % Add current node to the path
prev_node = parent{current};
update_routing_table(prev_node, destination, current, metric);
current = prev_node;
end
path = [source, path]; % Add source to the path
disp([‘Path: ‘, num2str(path)]);
return;
end
end
end
end
end
% Function to update the routing table of a node
function update_routing_table(node, destination, next_hop, metric)
if isempty(routing_table{node})
routing_table{node} = {destination, next_hop, metric};
else
% Check if destination already exists, and update if the new path is better
for j = 1:size(routing_table{node}, 1)
if routing_table{node}{j, 1} == destination
if routing_table{node}{j, 3} > metric
routing_table{node}{j, 2} = next_hop;
routing_table{node}{j, 3} = metric;
end
return;
end
end
% Add new entry if destination does not exist
routing_table{node} = [routing_table{node}; {destination, next_hop, metric}];
end
end
% Example: Perform route discovery from Node 1 to Node 15
hwmp_preq(1, 15, adjacency_matrix, nodes);
- Proactive Routing (Proactive PREQ):
- In proactive mode, a root node intermittently transmit proactive PREQ messages to each nodes, enables them to sustain paths to the root node without need on-demand discovery.
Example:
% Function to perform proactive path request (PREQ) from root node
function hwmp_proactive_preq(root_node, adjacency_matrix, num_nodes)
% Flood the network with PREQ from the root node
visited = zeros(1, num_nodes);
queue = [root_node];
visited(root_node) = 1;
while ~isempty(queue)
current_node = queue(1); % Dequeue the first node
queue(1) = [];
% Get neighbors of the current node
neighbors = find(adjacency_matrix(current_node, :));
for i = 1:length(neighbors)
next_node = neighbors(i);
if ~visited(next_node)
visited(next_node) = 1;
queue = [queue, next_node]; % Enqueue the neighbor
% Update routing table to the root
metric = visited(current_node) + 1;
update_routing_table(next_node, root_node, current_node, metric);
% Set the visit distance (metric from the root)
visited(next_node) = metric;
end
end
end
end
% Example: Root node at Node 1 sending proactive PREQ to all nodes
hwmp_proactive_preq(1, adjacency_matrix, num_nodes);
- Simulate Packet Forwarding:
- Once the routes are introduced by using wheatear reactive or proactive mode, packets can be transmit from the origin to the destination according to the routing table.
Example of Packet Forwarding:
% Function to forward a packet from source to destination using routing table
function forward_packet(source, destination)
current_node = source;
% Continue forwarding until the destination is reached
while current_node ~= destination
% Check the routing table for the next hop
next_hop_entry = routing_table{current_node};
if isempty(next_hop_entry)
fprintf(‘No route found from Node %d to Node %d\n’, current_node, destination);
return;
end
% Select the next hop (simplified to choose the first entry)
next_hop = next_hop_entry{1, 2};
fprintf(‘Packet forwarded from Node %d to Node %d\n’, current_node, next_hop);
% Move to the next node
current_node = next_hop;
end
fprintf(‘Packet successfully delivered from Node %d to Node %d\n’, source, destination);
end
% Example: Forward a packet from Node 1 to Node 15
forward_packet(1, 15);
- Simulate Multiple Flows:
- Replicate multiple flows to track on how HWMP act as in diverse network conditions.
Example:
% Simulate multiple flows
num_flows = 5;
for flow = 1:num_flows
% Randomly select source and destination nodes
source_node = randi(num_nodes);
destination_node = randi(num_nodes);
fprintf(‘Flow %d: Forwarding packet from Node %d to Node %d\n’, flow, source_node, destination_node);
% Perform route discovery
hwmp_preq(source_node, destination_node, adjacency_matrix, nodes);
% Forward the packet after route discovery
forward_packet(source_node, destination_node);
end
- Performance Metrics:
- We can evaluate numerous key parameters like:
- Packet Delivery Ratio (PDR): The ratio of successfully delivered packets to the total amount of packets transmitted.
- End-to-End Delay: The time taken for packets to extent the destination.
- Routing Overhead: The amount of control messages (PREQ, PREP) interchanged.
Example of calculating end-to-end delay:
% Example of calculating end-to-end delay based on hop count
hop_count = 5; % Example value for the number of hops
transmission_delay = 0.002; % Example transmission delay per hop (2 ms)
% Calculate the total end-to-end delay
total_delay = hop_count * transmission_delay;
fprintf(‘End-to-End Delay: %.4f seconds\n’, total_delay);
Conclusion:
This procedure delivers an outline for replicating the Hybrid Wireless Mesh Protocol (HWMP) in MATLAB. HWMP utilizes hybrid techniques by integrating reactive route discovery with proactive routing to a root node.
Key steps that contain:
- Describing the network topology and adjacency matrix.
- Executing route discovery using Path Request (PREQ) and Path Reply (PREP).
- Replicating proactive routing from a root node.
- Sending packets using the introduced routes.
Through the above structured process, we have utterly presented the instruction with some examples regarding the simulation of Hybrid Wireless Mesh Protocol in the simulation set up using MATLAB. If you any doubts, lemma knows we will clarify it.
If you’re having a tough time finishing your HWMP Protocol Project simulation, our team at phdprime.com is here to help you achieve the best results. Just send us your project details via email, and we’ll guide you to success!