How to Develop Centralized Routing Projects Using NS3

To develop centralized routing within NS3, it depends on a central controller like an SDN controller or a central routing server for determining and delivering the routes into all nodes within a network. This differs with custom distributed routing in which every single node assesses their individual routes.

NS3 allows execute the centralized routing utilising:

  1. A global controller, which determines the best routes.
  2. A predefined routing table inserted from a central object.
  3. A Software-Defined Networking (SDN) mechanism, where a central controller processes the routing.

Steps to Develop a Centralized Routing Project in NS3

  1. Install and Set Up NS3

At first, we make sure that NS3 is installed on the system:

git clone cd ns-3-dev

./ns3 configure –enable-examples –enable-tests

./ns3 build

  1. Define a Network Topology

We will create a network with centralized routing mechanism is helpful for wired and wireless networks in which routes are determined at a central node.

Example: Create a 6-Node Network

NodeContainer nodes;

nodes.Create(6);  // Create 6 nodes

Connect Nodes Using Point-to-Point Links

PointToPointHelper p2p;

p2p.SetDeviceAttribute(“DataRate”, StringValue(“1Gbps”));

p2p.SetChannelAttribute(“Delay”, StringValue(“2ms”));

NetDeviceContainer devices01 = p2p.Install(nodes.Get(0), nodes.Get(1));

NetDeviceContainer devices12 = p2p.Install(nodes.Get(1), nodes.Get(2));

NetDeviceContainer devices13 = p2p.Install(nodes.Get(1), nodes.Get(3));

NetDeviceContainer devices34 = p2p.Install(nodes.Get(3), nodes.Get(4));

NetDeviceContainer devices35 = p2p.Install(nodes.Get(3), nodes.Get(5));

  1. Assign IP Addresses

InternetStackHelper stack;

stack.Install(nodes);

Ipv4AddressHelper address;

address.SetBase(“10.1.1.0”, “255.255.255.0”);

Ipv4InterfaceContainer interfaces01 = address.Assign(devices01);

address.SetBase(“10.1.2.0”, “255.255.255.0”);

Ipv4InterfaceContainer interfaces12 = address.Assign(devices12);

address.SetBase(“10.1.3.0”, “255.255.255.0”);

Ipv4InterfaceContainer interfaces13 = address.Assign(devices13);

address.SetBase(“10.1.4.0”, “255.255.255.0”);

Ipv4InterfaceContainer interfaces34 = address.Assign(devices34);

address.SetBase(“10.1.5.0”, “255.255.255.0”);

Ipv4InterfaceContainer interfaces35 = address.Assign(devices35);

  1. Implement Centralized Routing

Execute the global controller, which finds and delivers the routes for every node in Centralized Routing.

(A) We can generate a Centralized Controller Class

class CentralizedRouting : public Object {

public:

void ComputeRoutes(NodeContainer nodes);

};

(B) Execute the Centralized Route Calculation using Dijkstra’s Algorithm

void CentralizedRouting::ComputeRoutes(NodeContainer nodes) {

uint32_t numNodes = nodes.GetN();

std::vector<uint32_t> distance(numNodes, INT_MAX);

std::vector<uint32_t> previous(numNodes, -1);

std::vector<bool> visited(numNodes, false);

uint32_t source = 0; // Set node 0 as the routing controller

distance[source] = 0;

for (uint32_t i = 0; i < numNodes; i++) {

uint32_t minDist = INT_MAX, minNode = -1;

for (uint32_t j = 0; j < numNodes; j++) {

if (!visited[j] && distance[j] < minDist) {

minDist = distance[j];

minNode = j;

}

}

visited[minNode] = true;

for (uint32_t neighbor = 0; neighbor < numNodes; neighbor++) {

if (!visited[neighbor]) {

uint32_t linkCost = Simulator::Now().GetNanoSeconds() % 10 + 1;

if (distance[minNode] + linkCost < distance[neighbor]) {

distance[neighbor] = distance[minNode] + linkCost;

previous[neighbor] = minNode;

}

}

}

}

for (uint32_t i = 0; i < numNodes; i++) {

NS_LOG_UNCOND(“Centralized Routing: Shortest path from Controller to node ” << i << ” is ” << distance[i]);

}

}

(C) We need to use Centralized Routing

Ptr<CentralizedRouting> centralizedRouting = CreateObject<CentralizedRouting>();

centralizedRouting->ComputeRoutes(nodes)

  1. Setup Traffic Applications

UdpEchoServerHelper echoServer(9);

ApplicationContainer serverApps = echoServer.Install(nodes.Get(5));

serverApps.Start(Seconds(1.0));

serverApps.Stop(Seconds(10.0));

UdpEchoClientHelper echoClient(Ipv4Address(“10.1.5.2”), 9);

echoClient.SetAttribute(“MaxPackets”, UintegerValue(5));

echoClient.SetAttribute(“Interval”, TimeValue(Seconds(1.0)));

echoClient.SetAttribute(“PacketSize”, UintegerValue(512));

ApplicationContainer clientApps = echoClient.Install(nodes.Get(0));

clientApps.Start(Seconds(2.0));

clientApps.Stop(Seconds(10.0));

  1. Allow Tracing for Debugging

AsciiTraceHelper ascii;

p2p.EnableAsciiAll(ascii.CreateFileStream(“centralized-routing.tr”));

p2p.EnablePcapAll(“centralized-routing”);

  1. Then, execute the Simulation

Simulator::Run();

Simulator::Destroy();

  1. Analyze Results

Envision the performance outcomes using NetAnim:

./waf –run centralized-routing

netanim

Alternative Approach: SDN-Based Centralized Routing

For an SDN-based centralized routing, we have to utilise:

  • OpenFlow-based Controllers: Execute the OF-switch and OF-controller.
  • Custom SDN Controller: We leverage global network knowledge to dynamically adjust the packets.

(A) SDN Controller Example

class SDNController : public Application {

public:

void ManageRouting();

};

void SDNController::ManageRouting() {

NS_LOG_UNCOND(“SDN Controller Updating Routes”);

}

(B) Apply SDN-Based Routing

Ptr<SDNController> controller = CreateObject<SDNController>();

controller->ManageRouting();

  1. Extend with Advanced Features
  • QoS-based Routing: Compute the paths with the support of QoS metrics like delay, jitter, and bandwidth.
  • AI-Based Routing: Enhance the routing by applying reinforcement learning.
  • Security-Based Centralized Routing: Avoid attacks like man-in-the-middle and routing table poisoning.

In the manual, we presented implementation procedures and sample snippets to successfully execute the Centralized Routing Projects and examine the outcomes using NS3 simulation environment. Extra specific details regarding the Centralized Routing will be provided.