How to Develop OSPF Routing Projects Using NS3

To develop the OSPF Routing utilized the NS-3. The Open Shortest Path First (OSPF) is a link-state routing protocol which use the Dijkstra’s procedures to establish the shortest path among their nodes. OSPF is generally used in intra-domain routing for large networks. By following these steps, we can simulate OSPF-based networks in ns3 and evaluate their performance.

OSPF in NS-3

  • The NS-3 cannot have a built-in OSPF execution.
  • Nevertheless, OSPF can be executed using:
    • Quagga routing suite (Best method)
    • Custom NS-3 component (Manually implementing OSPF)

Steps to Develop OSPF Routing Projects Using NS3

Approach 1: Implement OSPF Using Quagga (Best Method)

  1. Install and Set Up NS-3 with Quagga

Quagga is routing suites which encourage the OSPF, BGP, and RIP. In NS-3, it can be incorporated using NS-3 Direct Code Execution (DCE).

Install NS-3 with DCE

git clone

cd ns-3-dev

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

./ns3 build

  1. Define a Network Topology

It needs the OSPF several routers to modify the link-state information.

Example: 4 Routers in an OSPF Area

NodeContainer routers;

routers.Create(4);

Link the Routers Using Point-to-Point Links

PointToPointHelper p2p;

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

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

NetDeviceContainer devAB = p2p.Install(routers.Get(0), routers.Get(1));

NetDeviceContainer devBC = p2p.Install(routers.Get(1), routers.Get(2));

NetDeviceContainer devCD = p2p.Install(routers.Get(2), routers.Get(3));

NetDeviceContainer devDA = p2p.Install(routers.Get(3), routers.Get(0));

  1. We allot the IP Addresses for OSPF routing

InternetStackHelper stack;

stack.Install(routers);

Ipv4AddressHelper address;

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

Ipv4InterfaceContainer interfacesAB = address.Assign(devAB);

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

Ipv4InterfaceContainer interfacesBC = address.Assign(devBC);

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

Ipv4InterfaceContainer interfacesCD = address.Assign(devCD);

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

Ipv4InterfaceContainer interfacesDA = address.Assign(devDA);

  1. Enable OSPF Routing Using Quagga

Every router implements the process for Quagga’s in OSPF daemon (ospfd).

We setting the Quagga on Router 1

DceManagerHelper dceManager;

dceManager.Install(routers.Get(0));

QuaggaHelper quagga;

quagga.EnableOspf(routers.Get(0), “192.168.1.1”, “0”);

quagga.AddOspfNetwork(routers.Get(0), “192.168.1.0/24”, “0”);

quagga.AddOspfNetwork(routers.Get(0), “192.168.4.0/24”, “0”);

quagga.Install(routers);

Arrange the Quagga on Router 2

quagga.EnableOspf(routers.Get(1), “192.168.1.2”, “0”);

quagga.AddOspfNetwork(routers.Get(1), “192.168.1.0/24”, “0”);

quagga.AddOspfNetwork(routers.Get(1), “192.168.2.0/24”, “0”);

quagga.Install(routers);

Design for Quagga on Router 3

quagga.EnableOspf(routers.Get(2), “192.168.2.2”, “0”);

quagga.AddOspfNetwork(routers.Get(2), “192.168.2.0/24”, “0”);

quagga.AddOspfNetwork(routers.Get(2), “192.168.3.0/24”, “0”);

quagga.Install(routers);

Organize the Quagga on Router 4

quagga.EnableOspf(routers.Get(3), “192.168.3.2”, “0”);

quagga.AddOspfNetwork(routers.Get(3), “192.168.3.0/24”, “0”);

quagga.AddOspfNetwork(routers.Get(3), “192.168.4.0/24”, “0”);

quagga.Install(routers);

  1. We configure the congestion to validate the OSPF

UdpEchoServerHelper echoServer(9);

ApplicationContainer serverApps = echoServer.Install(routers.Get(3));

serverApps.Start(Seconds(1.0));

serverApps.Stop(Seconds(10.0));

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

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

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

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

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

clientApps.Start(Seconds(2.0));

clientApps.Stop(Seconds(10.0));

  1. Allow to tracing for Debugging

AsciiTraceHelper ascii;

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

p2p.EnablePcapAll(“ospf-routing”);

  1. Calculate the implementation process for replication

Simulator::Run();

Simulator::Destroy();

  1. Examine the outcomes for OSPF routing

Ensure for vision like NetAnim:

./waf –run ospf-routing

netanim

We verify the OSPF routes, use:

telnet 127.0.0.1 2604

Then, implement the OSPF routing:

show ip ospf

Approach 2: Implement a Custom OSPF Module in NS-3

We don’t require using Quagga; we can create a custom OSPF component through:

  1. Encompass the Ipv4RoutingProtocol class for manage the OSPF communication.
  2. Execute the Link-State Advertisements (LSAs) to modify the routing updates.
  3. Utilized for Dijkstra’s procedures for calculate the shortest-path.

(A) Generate a Custom OSPF Routing Class

class OspfRoutingProtocol : public Ipv4RoutingProtocol {

public:

void ComputeShortestPath(NodeContainer nodes);

};

(B) Execute a Dijkstra’s procedures for OSPF

void OspfRoutingProtocol::ComputeShortestPath(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;

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++) {

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(“Shortest path from Router to node ” << i << ” is ” << distance[i]);

}

}

We presented an example-driven simple methodology to open shortest path routing project that were simulated and executed successfully using ns3 tool including sample snippets. If you did like to know more details regarding this project we will offered it.