How to Simulate Internal Protocol Projects Using NS3

To simulate internal routing protocols in ns3 are protocols utilized for routing within an autonomous system (AS). This is also known as Interior Gateway Protocols (IGPs).

The samples of internal routing protocols have contained:

  • OSPF (Open Shortest Path First): A link-state routing protocol.
  • RIP (Routing Information Protocol): A distance-vector routing protocol.
  • EIGRP (Enhanced Interior Gateway Routing Protocol): A hybrid routing protocol.

In NS3, we can replicate internal routing protocols such as RIP and OSPF, since EIGRP isn’t natively supported and would needs a manual implementation. Here’s how we can simulate RIP and OSPF using NS3.

Steps to Simulate Internal Protocols in NS3 (RIP/OSPF)

  1. Install NS3: Ensure NS3 is installed on system.
  2. Understand Internal Routing Protocols:
    • RIP: A distance-vector protocol that utilizes hop count as a routing metric and updates routing tables at regular intervals.
    • OSPF: A link-state protocol that utilizes a more sophisticated method for regulating the shortest path using Dijkstra’s algorithm.
  3. Create a Network Topology: utilize NS3 to generate a set of nodes to denote routers and hosts in the network.
  4. Set Up Wired or Wireless Communication: Relying on network scenario, we can utilize point-to-point links (for wired) or Wi-Fi (for wireless) to associate the nodes.
  5. Configure the Internal Routing Protocol: Utilize the provided helpers in NS3 to setting up the routing protocols:
    • RipHelper for RIP.
    • OspfHelper for OSPF (OSPF isn’t natively supported; however it can be emulated via static routing or by integrating dynamic routes using the global routing helper).
  6. Assign IP Addresses: Allocate IP addresses to each node interface to permit interaction among them.
  7. Set Up Applications: Install applications such as UDP or TCP to create traffic and monitor on how the routing protocol manage data transmission.
  8. Run the Simulation: Execute the simulation, collect results, and measure the parameters like packet delivery ratio, end-to-end delay, throughput, and routing overhead.

Example Simulation for RIP (Distance-Vector Protocol) in NS3

Here’s an instance demonstrates on how to simulate RIP as an internal routing protocol using NS3.

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

#include “ns3/rip-helper.h”

#include “ns3/ipv4-global-routing-helper.h”

#include “ns3/point-to-point-module.h”

#include “ns3/applications-module.h”

using namespace ns3;

int main (int argc, char *argv[])

{

// Step 1: Create nodes (e.g., 6 nodes representing routers and hosts)

NodeContainer nodes;

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

// Step 2: Set up point-to-point links between nodes

PointToPointHelper p2p;

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

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

NetDeviceContainer devices01, devices12, devices23, devices34, devices45;

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

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

devices23 = p2p.Install (nodes.Get (2), nodes.Get (3));

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

devices45 = p2p.Install (nodes.Get (4), nodes.Get (5));

// Step 3: Install internet stack and RIP routing on all nodes

InternetStackHelper internet;

RipHelper ripRouting; // Use RIP as the routing protocol

Ipv4ListRoutingHelper list;

lst.Add (ripRouting, 0);

internet.SetRoutingHelper (list); // Set RIP as the routing protocol

internet.Install (nodes);

// Step 4: Assign IP addresses

Ipv4AddressHelper ipv4;

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

Ipv4InterfaceContainer ifc01 = ipv4.Assign (devices01);

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

Ipv4InterfaceContainer ifc12 = ipv4.Assign (devices12);

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

Ipv4InterfaceContainer ifc23 = ipv4.Assign (devices23);

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

Ipv4InterfaceContainer ifc34 = ipv4.Assign (devices34);

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

Ipv4InterfaceContainer ifc45 = ipv4.Assign (devices45);

// Step 5: Set up applications (e.g., UDP Echo application)

UdpEchoServerHelper echoServer (9);

ApplicationContainer serverApps = echoServer.Install (nodes.Get (5)); // Server on node 5

serverApps.Start (Seconds (1.0));

serverApps.Stop (Seconds (10.0));

UdpEchoClientHelper echoClient (ifc45.GetAddress (1), 9);

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

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

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

ApplicationContainer clientApps = echoClient.Install (nodes.Get (0)); // Client on node 0

clientApps.Start (Seconds (2.0));

clientApps.Stop (Seconds (10.0));

// Step 6: Enable global routing

Ipv4GlobalRoutingHelper::PopulateRoutingTables ();

// Step 7: Run the simulation

Simulator::Run ();

Simulator::Destroy ();

return 0;

}

Explanation of the Code:

  1. Node Creation:
    • Six nodes are created to signify the routers and hosts.
  2. Point-to-Point Links:
    • Point-to-point links are utilized to associate the nodes that replicated wired connections among routers.
  3. RIP Routing Setup:
    • The RipHelper is used to install RIP as the routing protocol on all nodes.
    • The Ipv4ListRoutingHelper permits you to set RIP as the preferred routing protocol.
  4. IP Address Assignment:
    • IP addresses are allocated to the nodes for each link using the Ipv4AddressHelper.
  5. UDP Echo Application:
    • A UDP Echo server is installed on node 5, and a UDP Echo client is installed on node 0, replicating interaction among the nodes.
  6. Run the Simulation:
    • The simulation is executed, and the routing behaviour is managed by RIP.

Example Simulation for OSPF Protocol in NS3

OSPF isn’t natively available as a helper in NS3. But, we can approximate OSPF behaviour using GlobalRouting that performs similarly to link-state routing or by physically setting up static routes.

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

#include “ns3/ipv4-global-routing-helper.h”

#include “ns3/point-to-point-module.h”

#include “ns3/applications-module.h”

using namespace ns3;

int main (int argc, char *argv[])

{

// Step 1: Create nodes

NodeContainer nodes;

nodes.Create (6); // Create 6 nodes (representing routers/hosts)

// Step 2: Set up point-to-point links

PointToPointHelper p2p;

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

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 devices23 = p2p.Install (nodes.Get (2), nodes.Get (3));

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

NetDeviceContainer devices45 = p2p.Install (nodes.Get (4), nodes.Get (5));

// Step 3: Install internet stack

InternetStackHelper internet;

internet.Install (nodes);

// Step 4: Assign IP addresses

Ipv4AddressHelper ipv4;

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

Ipv4InterfaceContainer ifc01 = ipv4.Assign (devices01);

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

Ipv4InterfaceContainer ifc12 = ipv4.Assign (devices12);

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

Ipv4InterfaceContainer ifc23 = ipv4.Assign (devices23);

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

Ipv4InterfaceContainer ifc34 = ipv4.Assign (devices34);

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

Ipv4InterfaceContainer ifc45 = ipv4.Assign (devices45);

// Step 5: Set up applications

UdpEchoServerHelper echoServer (9);

ApplicationContainer serverApps = echoServer.Install (nodes.Get (5)); // Server on node 5

serverApps.Start (Seconds (1.0));

serverApps.Stop (Seconds (10.0));

UdpEchoClientHelper echoClient (ifc45.GetAddress (1), 9);

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

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

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

ApplicationContainer clientApps = echoClient.Install (nodes.Get (0)); // Client on node 0

clientApps.Start (Seconds (2.0));

clientApps.Stop (Seconds (10.0));

// Step 6: Enable global routing

Ipv4GlobalRoutingHelper::PopulateRoutingTables ();

// Step 7: Run the simulation

Simulator::Run ();

Simulator::Destroy ();

return 0;

}

In this sample, we replicate the behaviour of link-state routing using global routing, that closely resembles OSPF.

Running the Simulation:

  1. Build the NS3 Script:

./waf configure

./waf build

./waf –run <your-script-name>

Analysing Performance:

Key parameters to assess for internal routing protocols that contain:

  • Packet Delivery Ratio (PDR): The ratio of packets successfully delivered to the destination.
  • End-to-End Delay: The time taken for a packet to travel from the source to the destination.
  • Routing Overhead: The amount of control traffic such as RIP updates or OSPF link-state advertisements.
  • Throughput: The rate of successful message delivery over a communication channel.

Using the above discussed techniques, we clearly explained the essential information and shown examples of how to execute internal routing protocols in ns3. We will deliver more information according to your needs. Contact phdprime.com, our developers assist you in simulating internal protocol projects and offer you the best research ideas and topics. We can complete your project performance using the NS3 tool. Let our staff complete an impeccable paper.

Opening Time

9:00am

Lunch Time

12:30pm

Break Time

4:00pm

Closing Time

6:30pm

  • award1
  • award2