Ns3 Projects for B.E/B.Tech M.E/M.Tech PhD Scholars.  Phone-Number:9790238391   E-mail: ns3simulation@gmail.com

How to Implement Fiber Optic Topology in ns3

To implement a fiber optic topology in ns3, a network has to be created that uses point-to-point links which has high data rates and low latency. In that network nodes are communicate over fiber optic links.

If you face any difficulties in implementation after going through the below staps then feel free to contact us.

The Steps for implementing the Fiber optic Topology in ns3 is given below:

Step-by-step to implement Fiber optic Topology in ns3.

Step 1: Install ns3

Make sure ns3 is installed on the system.

Step 2: Create a New Simulation Script

Create a new C++ script for the simulation.

Step 3: Include Necessary Headers

In the script, include the necessary ns3 headers:

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

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

#include “ns3/mobility-module.h”

#include “ns3/applications-module.h”

Step 4: Set Up the Fiber Optic Topology

Here is an example of setting up a simple fiber optic topology with several nodes:

using namespace ns3;

NS_LOG_COMPONENT_DEFINE (“FiberOpticTopology”);

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

{

// Configure command line parameters

CommandLine cmd;

cmd.Parse (argc, argv);

// Create nodes

NodeContainer nodes;

nodes.Create (4); // Create 4 nodes for the fiber optic network

// Set up point-to-point links to simulate fiber optic links

PointToPointHelper pointToPoint;

pointToPoint.SetDeviceAttribute (“DataRate”, StringValue (“10Gbps”));

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

NetDeviceContainer devices;

devices = pointToPoint.Install (nodes.Get (0), nodes.Get (1));

devices = pointToPoint.Install (nodes.Get (1), nodes.Get (2));

devices = pointToPoint.Install (nodes.Get (2), nodes.Get (3));

// Install the internet stack

InternetStackHelper stack;

stack.Install (nodes);

Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();

positionAlloc->Add (Vector (50.0, 50.0, 0.0)); // Node 1 position

positionAlloc->Add (Vector (100.0, 50.0, 0.0)); // Node 2 position

positionAlloc->Add (Vector (150.0, 50.0, 0.0)); // Node 3 position

positionAlloc->Add (Vector (200.0, 50.0, 0.0)); // Node 4 position

mobility.SetPositionAllocator (positionAlloc);  // Assign IP addresses to the devices

Ipv4AddressHelper address;

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

Ipv4InterfaceContainer interfaces = address.Assign (devices);

// Configure mobility (optional)

MobilityHelper mobility;

mobility.SetMobilityModel (“ns3::ConstantPositionMobilityModel”);

mobility.Install (nodes);

// Set up applications (e.g., UDP echo server and client)

uint16_t port = 9; // Port number for applications

// Install UDP Echo Server on node 0

UdpEchoServerHelper echoServer (port);

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

serverApps.Start (Seconds (1.0));

serverApps.Stop (Seconds (10.0));

// Install UDP Echo Clients on other nodes to communicate with node 0

for (uint32_t i = 1; i < nodes.GetN (); ++i)

{

UdpEchoClientHelper echoClient (interfaces.GetAddress (0), port);

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

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

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

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

clientApps.Start (Seconds (2.0 + i)); // Stagger start times

clientApps.Stop (Seconds (10.0));

}

// Run simulation

Simulator::Stop (Seconds (10.0));

Simulator::Run ();

Simulator::Destroy ();

return 0;

}

Step 5: Build and Run the Simulation

  1. Save the script as fiber-optic-topology.cc.
  2. Build the script using waf:

./waf configure –enable-examples

./waf build

  1. Run the simulation:

./waf –run scratch/fiber-optic-topology

Explanation of the Script

  • Node Creation: Creates four nodes for the fiber optic network.
  • Point-to-Point Links: Configures point-to-point links to simulate fiber optic links with a high data rate and low latency.
  • Internet Stack: Installs the internet stack on all nodes.
  • IP Addressing: Assigns IP addresses to the devices.
  • Mobility Model: (Optional) Sets the position of nodes using ListPositionAllocator and ConstantPositionMobilityModel.
  • Applications: Sets up a UDP echo server on the first node and UDP echo clients on the other nodes to demonstrate communication between nodes.

The implementation of Fiber Optic Topology is successfully done by creating a network with high data rates and low latency and using UDP files for the nodes communication.