To implement the optical fibers in ns3 has includes to utilize the optical network modules obtainable in the simulator and these modules were permit to mimic the features of optical network that contains WDM (Wavelength Division Multiplexing) networks. Below are the procedures on how to implement the optical fibers 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: Include Optical Network Module
Guarantee that the optical network module is encompassed in the ns3 installation. The waf build system should automatically include it if it’s available.
Step 3: Create the Optical Fiber Simulation Script
We will create a script that sets up nodes connected by optical fibers, simulates traffic, and collects performance metrics.
#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/optical-network-module.h”
using namespace ns3;
NS_LOG_COMPONENT_DEFINE(“OpticalFiberExample”);
int main(int argc, char *argv[])
{
CommandLine cmd;
cmd.Parse(argc, argv);
// Create nodes
NodeContainer nodes;
nodes.Create(4);
// Set up point-to-point links with optical fiber attributes
PointToPointHelper p2p;
p2p.SetDeviceAttribute(“DataRate”, StringValue(“10Gbps”));
p2p.SetChannelAttribute(“Delay”, StringValue(“1ms”));
NetDeviceContainer devices;
devices = p2p.Install(nodes.Get(0), nodes.Get(1));
devices.Add(p2p.Install(nodes.Get(1), nodes.Get(2)));
devices.Add(p2p.Install(nodes.Get(2), nodes.Get(3)));
// Install the internet stack
InternetStackHelper stack;
stack.Install(nodes);
// 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;
OnOffHelper onoff(“ns3::UdpSocketFactory”, Address(InetSocketAddress(interfaces.GetAddress(3), port)));
onoff.SetConstantRate(DataRate(“5Gbps”)); // Generate high traffic
ApplicationContainer apps = onoff.Install(nodes.Get(0));
apps.Start(Seconds(1.0));
apps.Stop(Seconds(10.0));
// Install packet sink on the last node to receive packets
PacketSinkHelper sink(“ns3::UdpSocketFactory”, Address(InetSocketAddress(Ipv4Address::GetAny(), port)));
apps = sink.Install(nodes.Get(3));
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 4: Compile and Run the Simulation
- Compile the Simulation:
./waf configure –enable-examples
./waf build
Run the Simulation:
./waf –run scratch/optical-fiber-example
Step 5: Analyse Results
The simulation script uses FlowMonitor to collect and print out statistics about the traffic flows. We need to investigate metrics like packet loss, throughput, and delay to understand the performance of the optical network.
Additional Considerations
To extend the functionality of your optical fiber simulation, consider the following:
1. Wavelength Division Multiplexing (WDM)
To simulate multiple wavelengths on a single optical fiber, increasing the network’s capacity is using WDM.
2. Advanced Traffic Patterns
Mimic diverse kinds of traffic patterns, for instance bursty traffic or varying data rates, to recognize their impact on the optical network.
3. Fault Tolerance
Implement and test fault tolerance mechanisms, like automatic protection switching, to see how the network recovers from failures.
4. Custom Topologies
Generate more complex network topologies, like rings or meshes, to mimic real-world optical networks.
5. Performance Metrics
Collect and analyse additional metrics such as jitter, packet delay variation, and error rates to evaluate the network performance more comprehensively.
In the end, we have executed the optical fibers in ns3 has sets up nodes then simulates traffic and finally compile outcomes by using the ns3 tool. Additional specifics details will be provided for optical fibers. Contact us for expert guidance on implementing Network Optical fibers ns3 program in your project. Our developers can help you achieve the best project performance. We also work on Optical networks with WDM for optimal outcomes.