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

How to Implement Passive optical networks in ns3

To implement the passive optical networks (PONs) in ns3 has several steps to follow: initially we need to simulate the PON and the Optical Line Terminal (OLT) interacts with numerous Optical Network Units (ONUs) via passive splitters. The given below are the detailed procedures on how to implement the basic PON in ns3:

Step-by-Step Implementation:

Step 1: Setup ns3 Environment

Make sure ns3 is installed and properly configured.

git clone https://gitlab.com/nsnam/ns-3-dev.git

cd ns-3-dev

./waf configure

./waf build

Step 2: Create the PON Simulation Script

We will create a script that sets up an OLT, several ONUs, and the passive splitters that connect them.

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

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

#include “ns3/applications-module.h”

#include “ns3/flow-monitor-module.h”

using namespace ns3;

NS_LOG_COMPONENT_DEFINE(“PONExample”);

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

{

CommandLine cmd;

cmd.Parse(argc, argv);

// Create nodes

NodeContainer oltNode;

oltNode.Create(1); // Create OLT node

NodeContainer onuNodes;

onuNodes.Create(4); // Create 4 ONU nodes

// Create point-to-point links representing the optical fibers

PointToPointHelper p2p;

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

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

// Connect OLT to ONUs via point-to-point links through a splitter

NetDeviceContainer devices;

for (uint32_t i = 0; i < onuNodes.GetN(); ++i)

{

devices.Add(p2p.Install(oltNode.Get(0), onuNodes.Get(i)));

}

// Install the internet stack

InternetStackHelper stack;

stack.Install(oltNode);

stack.Install(onuNodes);

// Assign IP addresses

Ipv4AddressHelper address;

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

Ipv4InterfaceContainer interfaces = address.Assign(devices);

// Install applications to generate traffic

uint16_t port = 9;

// ONUs will send data to the OLT

OnOffHelper onoff(“ns3::UdpSocketFactory”, Address(InetSocketAddress(interfaces.GetAddress(0), port)));

onoff.SetConstantRate(DataRate(“500Mbps”));

ApplicationContainer apps;

for (uint32_t i = 0; i < onuNodes.GetN(); ++i)

{

apps.Add(onoff.Install(onuNodes.Get(i)));

}

apps.Start(Seconds(1.0));

apps.Stop(Seconds(10.0));

// Install packet sink on the OLT to receive packets

PacketSinkHelper sink(“ns3::UdpSocketFactory”, Address(InetSocketAddress(Ipv4Address::GetAny(), port)));

apps = sink.Install(oltNode.Get(0));

apps.Start(Seconds(0.0));

apps.Stop(Seconds(10.0));

// Enable FlowMonitor to measure performance metrics

FlowMonitorHelper flowmon;

Ptr<FlowMonitor> monitor = flowmon.InstallAll();

// Run the simulation

Simulator::Stop(Seconds(10.0));

Simulator::Run();

// Print per-flow statistics

monitor->CheckForLostPackets();

Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier>(flowmon.GetClassifier());

std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats();

for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator i = stats.begin(); i != stats.end(); ++i)

{

Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow(i->first);

NS_LOG_UNCOND(“Flow ” << i->first << ” (” << t.sourceAddress << ” -> ” << t.destinationAddress << “)”);

NS_LOG_UNCOND(”  Tx Packets: ” << i->second.txPackets);

NS_LOG_UNCOND(”  Tx Bytes:   ” << i->second.txBytes);

NS_LOG_UNCOND(”  Rx Packets: ” << i->second.rxPackets);

NS_LOG_UNCOND(”  Rx Bytes:   ” << i->second.rxBytes);

NS_LOG_UNCOND(”  Lost Packets: ” << i->second.lostPackets);

NS_LOG_UNCOND(“Throughput:”<<i->second.rxBytes*8.0/(i->second.timeLastRxPacket.GetSeconds() – i->second.timeFirstTxPacket.GetSeconds()) / 1024 / 1024 << ” Mbps”);

}

// Clean up

Simulator::Destroy();

return 0;

}

Step 3: Compile and Run the Simulation

  1. Compile the Simulation:

./waf configure –enable-examples

./waf build

Run the Simulation:

./waf –run scratch/pon-example

Step 4: Analyse Results

The simulation script sets up an OLT connected to multiple ONUs via optical fibers. FlowMonitor is used to collect and print out statistics about the traffic flows, such as packet loss, throughput, and delay.

Additional Considerations

To extend the functionality of your PON simulation, consider the following:

1.      Dynamic Bandwidth Allocation

Implement dynamic bandwidth allocation algorithms to manage the bandwidth distribution among ONUs based on demand.

2.      Quality of Service (QoS)

Implement QoS mechanisms to prioritize certain types of traffic and ensure that critical data flows receive the necessary bandwidth and low latency.

3.      Fault Tolerance

Simulate and analyse the network’s behaviour in case of failures and how it recovers, implementing protection mechanisms like redundancy and automatic switching.

4.      Performance Metrics

Collect and analyse additional metrics such as jitter, packet delay variation, and error rates to evaluate the network performance more comprehensively.

In this script, we successfully completed the implementation of passive optical networks (PONs) in ns3 framework that has creating the setup; generate the PON script that connect them with passive splitters and several ONUs then Analyse Results. If you need any other information related to the PON we will provide.

For assistance with implementing Passive Optical Networks in the ns3 tool, feel free to reach out to us for expert guidance on its application in your project. Our team can provide you with project ideas and help with its execution. We specialize in simulating the PON and the Optical Line Terminal (OLT), so please share your research details with us for further guidance.