How to Start Centralized Routing Projects Using MATLAB

To start a Centralized Routing project in MATLAB, we want to replicate a network in which a centralized controller determines the optimal routing paths in the network for every node. Centralized routing is where a central authority or controller contains comprehensive understand of network topology and according to this data computes the best routes for each node.

Below is a simple procedure to execute a basic centralized routing protocol to utilise Dijkstra’s algorithm or similar method in which the controller finds the shortest path in the network for each node.

Steps to Start Centralized Routing Projects in MATLAB

  1. Understand the Centralized Routing Concept

In centralized routing:

  • A centralized controller accumulates data from every node like link states or distance vectors and calculates the best routes for all the nodes.
  • The network topology is normally denoted like a graph in which nodes signify network devices and edges denote the links among them including weights such as distance, cost, and bandwidth.
  • The central controller (which could be a server or master router) determines the optimal route from every source node to all other destination nodes.
  • This central controller modernizes the routing tables occasionally for the nodes.
  1. Define the Network Topology

In MATLAB, we will need to denote it like a graph to design the network. The graph will be contained nodes (routers) and edges (links between routers).

We can denote the network to utilise an adjacency matrix in which the rows and columns signify the nodes and the matrix values denote the distances or link costs.

Example of defining a simple 5-node network in MATLAB using an adjacency matrix:

% Define the adjacency matrix for the network

% Inf means no direct connection between the nodes

adjMatrix = [

0, 10, inf, 30, inf;  % Node 1 connected to Node 2 (cost 10) and Node 4 (cost 30)

10, 0, 50, inf, inf;  % Node 2 connected to Node 1 (cost 10) and Node 3 (cost 50)

inf, 50, 0, 10, 60;   % Node 3 connected to Node 2 (cost 50), Node 4 (cost 10), Node 5 (cost 60)

30, inf, 10, 0, 20;   % Node 4 connected to Node 1 (cost 30), Node 3 (cost 10), Node 5 (cost 20)

inf, inf, 60, 20, 0    % Node 5 connected to Node 3 (cost 60) and Node 4 (cost 20)

];

% Create the graph object for visualization

G = graph(adjMatrix);

plot(G, ‘Layout’, ‘force’);

title(‘Network Topology’);

This code defines a network of 5 nodes with specific link costs. The inf values represent that there is no direct connection between nodes.

  1. Implement the Centralized Routing Algorithm

We can utilise centralized controller, which calculates the best routing paths for each node for replicating centralized routing. A normal routing algorithm we can be utilised is Dijkstra’s Algorithm that determines the shortest path in a graph from a source node to every other nodes.

In this case, we will:

  1. Determine the shortest paths to utilise Dijkstra’s Algorithm for each node.
  2. Save the resulting routing paths for every node.
  3. The centralized controller will be calculated every path and deliver this data to the network.

Dijkstra’s Algorithm Implementation

This function shall determine the shortest path in the network from a source node to every other node.

function [distances, paths] = dijkstra(adjMatrix, sourceNode)

n = size(adjMatrix, 1);   % Number of nodes

distances = inf(1, n);     % Distance array initialized to infinity

distances(sourceNode) = 0; % Distance to source is 0

visited = false(1, n);     % Keep track of visited nodes

previous = NaN(1, n);      % To store the previous node in the shortest path

while true

% Find the unvisited node with the smallest tentative distance

[~, currentNode] = min(distances .* ~visited + inf(1, n) .* visited)

% If all nodes are visited or remaining distances are infinite, break

if distances(currentNode) == inf

break;

end

% Mark the current node as visited

visited(currentNode) = true;

% Update distances to neighboring nodes

for neighbor = 1:n

if adjMatrix(currentNode, neighbor) ~= inf && ~visited(neighbor)

% Calculate tentative distance to the neighbor node

newDist = distances(currentNode) + adjMatrix(currentNode, neighbor);

if newDist < distances(neighbor)

distances(neighbor) = newDist;

previous(neighbor) = currentNode;

end

end

end

end

% Reconstruct the shortest path

paths = NaN(1, n);

for i = 1:n

path = [];

currentNode = i;

while ~isnan(previous(currentNode))

path = [currentNode, path];

currentNode = previous(currentNode);

end

paths(i, 🙂 = [sourceNode, path];

end

end

  1. Centralized Controller

The centralized controller can be executed like function, which determines the shortest paths for every node to utilise Dijkstra’s algorithm for each node.

function [routingTable] = centralizedRouting(adjMatrix)

% Centralized routing function

n = size(adjMatrix, 1);  % Number of nodes

routingTable = cell(n, 1);  % To store routing tables for all nodes

% Compute shortest paths from each node to all other nodes

for sourceNode = 1:n

[distances, paths] = dijkstra(adjMatrix, sourceNode);

routingTable{sourceNode}.distances = distances;

routingTable{sourceNode}.paths = paths;

end

end

  1. Run the Centralized Routing Algorithm

Now, we can be executed the centralized routing algorithm for a provided network. The algorithm will be determined the shortest path to all other nodes within the network for each node.

% Run the centralized routing function

routingTable = centralizedRouting(adjMatrix);

% Display the routing tables for each node

for i = 1:length(routingTable)

fprintf(‘Routing table for Node %d:\n’, i);

disp(‘Distances:’);

disp(routingTable{i}.distances);

disp(‘Paths:’);

disp(routingTable{i}.paths);

end

The outcome will be indicated the distances and paths for each node, in the network to show the shortest path and the cost from the source node to every other node.

  1. Visualizing the Network and Routing Paths

We can utilise the graph plotting functions of MATLAB for envisioning the network and the computed routing paths. For instance, we can visualize the network and emphasize the paths determined by utilising routing algorithm.

Example:

% Visualize the network topology

G = graph(adjMatrix);

figure;

plot(G, ‘Layout’, ‘force’);

title(‘Network Topology’);

% Highlight the shortest path from Node 1 to Node 5

highlight(G, routingTable{1}.paths(5,:), ‘EdgeColor’, ‘r’, ‘LineWidth’, 2);

It will envision the network and indicate the shortest path from Node 1 to Node 5 within red color.

  1. Testing and Evaluation

We can experiment the centralized routing algorithm in various network topologies by means of changing the adjacency matrix. Deliberate to integrate a few other aspects to the project:

  • Network Changes: In the network, replicate the network modifications like link failures, added nodes and re-execute the routing calculation.
  • Performance Analysis: Examine the time complexity of the centralized controller and scalability for larger networks.
  • Dynamic Routing: Execute the periodic updates in which the controller modernizes the routing table within response to network modifications.
  1. Extend the Project with Features

When we contain simple functionality operating then we can prolong the project with aspects like:

  • Fault tolerance: Replicate and retrieve from link failures or node crashes.
  • Load balancing: Execute the processes for load balancing over several paths.
  • Energy-efficient routing: We deliberate power consumption whereas routing and execute the energy-aware routing mechanisms.
  • Routing Protocols: It helps to execute the general centralized routing protocols such as OSPF (Open Shortest Path First).

We had systematically offered the basic approach of Centralized Routing Projects that were simulated and executed using MATLAB tool and we are available to offer wide range of insights if needed.