To simulate Wide Area Network protocols (WAN) in MATLAB have includes generating a network topology which distances multiple routers and possibly diverse subnetworks, by the way of WANs usually associate geographically disseminated areas. WAN protocols can contain a variety of technologies such as Border Gateway Protocol (BGP) for inter-domain routing, Multiprotocol Label Switching (MPLS) for traffic engineering, or Frame Relay, Point-to-Point Protocol (PPP), etc. In this replication, we can concentrate on protocols such as BGP or MPLS while they are additional collective in WAN scenarios.
Here’s a step-by-step guide to simulate WAN protocols using MATLAB:
Steps to Simulate WAN Protocols in MATLAB
- Define the WAN Topology:
- Generate a wide area network with routers, links among routers, and probably various subnetworks. We can signify the network topology using an adjacency matrix or a graph.
Example:
% Define the number of routers in the WAN
num_routers = 8;
% Define the network topology using an adjacency matrix (link costs)
% 0 means no direct link, positive values represent link costs
adjacency_matrix = [0 2 0 0 0 0 4 0;
2 0 3 0 0 0 0 5;
0 3 0 2 0 0 0 0;
0 0 2 0 1 0 0 0;
0 0 0 1 0 3 0 0;
0 0 0 0 3 0 2 4;
4 0 0 0 0 2 0 3;
0 5 0 0 0 4 3 0];
% Define IP addresses for each router
ip_addresses = {‘10.0.0.1’, ‘10.0.0.2’, ‘10.0.0.3’, ‘10.0.0.4’, ‘10.0.0.5’, ‘10.0.0.6’, ‘10.0.0.7’, ‘10.0.0.8’};
% Plot the network topology
G = graph(adjacency_matrix, ip_addresses);
plot(G, ‘EdgeLabel’, G.Edges.Weight, ‘NodeLabel’, ip_addresses);
title(‘WAN Topology with Routers and Links’);
- Implement a WAN Protocol (BGP Simulation Example):
Border Gateway Protocol (BGP) is a vital WAN protocol utilized to transmit packets among various autonomous systems (AS). In a simple BGP replication, routers interchange routing information and construct a routing table according to the optimal paths among routers.
Example of BGP route discovery and updates:
% Initialize BGP routing table for each router
% Each router knows how to reach itself initially
bgp_routing_table = cell(num_routers, 1);
for i = 1:num_routers
bgp_routing_table{i} = {ip_addresses{i}, 0}; % {Destination IP, Hop Count}
end
% Simulate BGP route discovery
for round = 1:5 % Multiple rounds of route discovery
for i = 1:num_routers
for j = 1:num_routers
if adjacency_matrix(i, j) > 0
% Router i shares its routing table with Router j
fprintf(‘Router %d sends BGP update to Router %d\n’, i, j);
for k = 1:size(bgp_routing_table{i}, 1)
destination_ip = bgp_routing_table{i}{k, 1};
hop_count = bgp_routing_table{i}{k, 2} + 1; % Increment hop count
% Update Router j’s table if it finds a better path
if ~any(strcmp(bgp_routing_table{j}(:, 1), destination_ip)) || hop_count < bgp_routing_table{j}{strcmp(bgp_routing_table{j}(:, 1), destination_ip), 2}
bgp_routing_table{j} = [bgp_routing_table{j}; {destination_ip, hop_count}];
end
end
end
end
end
end
% Display the BGP routing table of each router
for i = 1:num_routers
fprintf(‘BGP Routing Table for Router %d:\n’, i);
disp(bgp_routing_table{i});
end
- Simulate MPLS for WAN (Optional):
Multiprotocol Label Switching (MPLS) can also be replicated in a WAN, specifically for traffic engineering purposes. In an MPLS-based WAN, packets are transmitted by using labels instead of IP addresses, enhancing efficiency.
Example of MPLS Label Distribution:
% Initialize LFIB (Label Forwarding Information Base) for each router
LFIB = cell(num_routers, 1);
% Example: Define LFIB entries for Router 1 (incoming/outgoing label mapping)
LFIB{1} = {
‘Incoming_Label’, ‘Outgoing_Label’, ‘Next_Hop’;
100, 101, 2;
200, 201, 3;
};
% MPLS Label Distribution Protocol (LDP) simulation to assign labels to routes
for source = 1:num_routers
for destination = 1:num_routers
if source ~= destination
% Find the shortest path using Dijkstra’s algorithm
[path, ~] = shortestpath(G, source, destination);
% Assign MPLS labels for each hop in the path
for hop = 1:length(path) – 1
current_router = path(hop);
next_router = path(hop + 1);
% Assign a label for this segment (incoming and outgoing labels)
incoming_label = randi([100, 200]);
outgoing_label = randi([201, 300]);
% Update the LFIB (Label Forwarding Information Base)
LFIB{current_router} = [LFIB{current_router}; {incoming_label, outgoing_label, next_router}];
end
end
end
end
% Display LFIB entries for each router
for i = 1:num_routers
fprintf(‘LFIB for Router %d:\n’, i);
disp(LFIB{i});
end
- Simulate Traffic Flow Between WAN Routers:
- After BGP or MPLS paths are introduced, replicate the forwarding of packets among routers according to the routing table or label-forwarding table (LFIB).
Example of packet forwarding using BGP routes:
% Source and destination routers
source = 1;
destination = 8;
% Find the path from source to destination using the BGP routing table
route = bgp_routing_table{source};
fprintf(‘Forwarding packet from Router %d to Router %d via route:\n’, source, destination);
% Forward the packet through the discovered BGP route
current_router = source;
while current_router ~= destination
% Find the next hop based on the routing table
next_hop_idx=strcmp(bgp_routing_table{current_router}(:,1), ip_addresses{destination});
if any(next_hop_idx)
next_router = find(next_hop_idx);
fprintf(‘Packet forwarded from Router %d to Router %d\n’, current_router, next_router);
current_router = next_router;
else
fprintf(‘No route found from Router %d to %d\n’, current_router, destination);
break;
end
end
- Performance Metrics:
Evaluate the key parameters such as:
- Packet Delivery Ratio: Ratio of successfully delivered packets to total transmitted packets.
- End-to-End Delay: Time taken for packets to send from origin to destination.
- Routing Overhead: Amount of control messages interchanged in the course of route discovery such as BGP updates.
Example of calculating end-to-end delay:
% Define hop delay (e.g., 2 ms per hop)
hop_delay = 0.002; % Example value in seconds
% Calculate the total number of hops in the discovered path
num_hops = length(path) – 1;
end_to_end_delay = num_hops * hop_delay;
fprintf(‘End-to-End Delay: %.4f seconds\n’, end_to_end_delay);
- Simulate WAN Link Failures (Optional):
- Replicate network failures by restricting particular links in the adjacency matrix and monitor on how the WAN protocol reacts by rerouting traffic via another paths.
Example:
% Replicate link failure among Router 1 and Router 2
adjacency_matrix(1, 2) = 0;
adjacency_matrix(2, 1) = 0;
% Recompute routes after link failure
G = graph(adjacency_matrix);
[path, ~] = shortestpath(G, source, destination);
disp(‘Recomputed path after link failure:’);
disp(path);
By following these steps, we can grasp the idea behind the simulation of Wide area networks in the MATLAB simulation and how to analyse it by utilizing the offered code snippets. We will deliver any other details of these Wide area networks steps, if needed.
If you want to simulate WAN Protocols Projects in MATLAB, just shoot us an email with your project details, and we’ll help you achieve great results. We promise to provide you with top-notch project ideas and topics. Our team is experienced in working with Border Gateway Protocol (BGP) for inter-domain routing, Multiprotocol Label Switching (MPLS) for traffic engineering, as well as Frame Relay, Point-to-Point Protocol (PPP), and more.