To implement the network slicing in ns3 has encompasses to make the virtual network then it work over a shared physical organization. An each and every slice needs to had an own configuration, quality of service (QoS) policies, and traffic management mechanisms. Now we are going to the brief procedure to execute the network slicing in ns3:
Step-by-Step Implementation:
Step 1: Setup ns3 Environment
Make certain ns3 is installed in the system.
Step 2: Include Necessary Modules
Include the necessary ns3 modules in the script:
#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/traffic-control-module.h”
#include “ns3/flow-monitor-module.h”
Step 3: Create the Simulation Script
- Setup Nodes and Network:using namespace ns3;
NS_LOG_COMPONENT_DEFINE (“NetworkSlicingExample”);
int main (int argc, char *argv[])
{
CommandLine cmd;
cmd.Parse (argc, argv);
// Create nodes
NodeContainer nodes;
nodes.Create (6);
// Create point-to-point links
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute (“DataRate”, StringValue (“10Mbps”));
pointToPoint.SetChannelAttribute (“Delay”, StringValue (“2ms”));
NetDeviceContainer devices;
devices = pointToPoint.Install (NodeContainer (nodes.Get (0), nodes.Get (1))));
devices.Add (pointToPoint.Install (NodeContainer (nodes.Get (1), nodes.Get (2))));
devices.Add (pointToPoint.Install (NodeContainer (nodes.Get (2), nodes.Get (3))));
devices.Add (pointToPoint.Install (NodeContainer (nodes.Get (3), nodes.Get (4))));
devices.Add (pointToPoint.Install (NodeContainer (nodes.Get (4), nodes.Get (5))));
// Install 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);
// Set up routing
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
// Set up applications for slice 1
uint16_t port1 = 9; // Discard port (RFC 863)
Address serverAddress1 (InetSocketAddress (Ipv4Address::GetAny (), port1));
PacketSinkHelper packetSinkHelper1 (“ns3::UdpSocketFactory”, serverAddress1);
ApplicationContainer sinkApps1 = packetSinkHelper1.Install (nodes.Get (5));
sinkApps1.Start (Seconds (1.0));
sinkApps1.Stop (Seconds (20.0));
OnOffHelper onoff1 (“ns3::UdpSocketFactory”, Address (InetSocketAddress (interfaces.GetAddress (5), port1)));
onoff1.SetConstantRate (DataRate (“1Mbps”));
ApplicationContainer apps1 = onoff1.Install (nodes.Get (0));
apps1.Start (Seconds (2.0));
apps1.Stop (Seconds (20.0));
// Set up applications for slice 2
uint16_t port2 = 10;
Address serverAddress2 (InetSocketAddress (Ipv4Address::GetAny (), port2));
PacketSinkHelper packetSinkHelper2 (“ns3::UdpSocketFactory”, serverAddress2);
ApplicationContainer sinkApps2 = packetSinkHelper2.Install (nodes.Get (5));
sinkApps2.Start (Seconds (1.0));
sinkApps2.Stop (Seconds (20.0));
OnOffHelper onoff2 (“ns3::UdpSocketFactory”, Address (InetSocketAddress (interfaces.GetAddress (5), port2)));
onoff2.SetConstantRate (DataRate (“2Mbps”));
ApplicationContainer apps2 = onoff2.Install (nodes.Get (1));
apps2.Start (Seconds (2.0));
apps2.Stop (Seconds (20.0));
// Enable pcap tracing for packet capture
pointToPoint.EnablePcapAll (“network-slicing”);
// Enable traffic control for slice 1
TrafficControlHelper tch1;
tch1.SetRootQueueDisc (“ns3::RedQueueDisc”);
tch1.Install (devices.Get (0));
tch1.Install (devices.Get (1));
// Enable traffic control for slice 2
TrafficControlHelper tch2;
tch2.SetRootQueueDisc (“ns3::PfifoFastQueueDisc”);
tch2.Install (devices.Get (2));
tch2.Install (devices.Get (3));
// Enable flow monitor
FlowMonitorHelper flowmon;
Ptr<FlowMonitor> monitor = flowmon.InstallAll ();
Simulator::Stop (Seconds (20.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);
std::cout << “Flow ” << i->first << ” (” << t.sourceAddress << ” -> ” << t.destinationAddress << “)\n”;
std::cout << ” Tx Bytes: ” << i->second.txBytes << “\n”;
std::cout << ” Rx Bytes: ” << i->second.rxBytes << “\n”;
std::cout << ” Tx Packets: ” << i->second.txPackets << “\n”;
std::cout << ” Rx Packets: ” << i->second.rxPackets << “\n”;
std::cout << ” Throughput: ” << i->second.rxBytes * 8.0 / (i->second.timeLastRxPacket.GetSeconds() – i->second.timeFirstTxPacket.GetSeconds()) / 1024 / 1024 << ” Mbps\n”;
}
Simulator::Destroy ();
return 0;
}
Explanation
- Node Creation: In the network we need generate nodes to signify numerous devices.
- Point-to-Point Links: Configure point-to-point links between nodes with specified data rates and delays.
- Internet Stack: Install the Internet stack on all nodes.
- IP Configuration: Assign IP addresses to the interfaces.
- Routing: Set up global routing to ensure packets can travel through the network.
- Applications for Slices: Set up numerous applications for each slice with numerous data rates and ports.
- Traffic Control: Apply numerous traffic control mechanisms for each slice. In this sample, RedQueueDisc is used for slice 1 and PfifoFastQueueDisc for slice 2.
- Packet Tracing: Enable pcap tracing to capture packets.
- Flow Monitor: Use the FlowMonitor module to collect and print statistics about the traffic flows.
Step 4: Run the Simulation
Compile and run your simulation script:
./waf configure
./waf build
./waf –run NetworkSlicingExample
Advanced Network Slicing Techniques
- Dynamic Slice Configuration:
To adjust resources allocated to each slice during runtime is need to execute the dynamic slice configuration.
Simulator::Schedule (Seconds (10.0), &TrafficControlHelper::SetRootQueueDisc, &tch1, devices.Get (0), “MaxPackets”, UintegerValue (50));
- QoS Policies:
Apply various QoS policies to slices to make certain that the bandwidth, latency, or jitter.
tch1.SetRootQueueDisc (“ns3::FqCoDelQueueDisc”);
tch1.Install (devices.Get (0));
- Traffic Isolation:
Guarantee traffic isolation among slices to avoid interference.
tch1.SetRootQueueDisc (“ns3::TbfQueueDisc”, “Rate”, DataRateValue (DataRate (“5Mbps”)));
tch1.Install (devices.Get (0));
- Monitoring and Analytics:
Use advanced monitoring and analytics tools to analyse the performance of each slice.
monitor->SerializeToXmlFile (“network-slicing-flowmon-results.xml”, true, true);
At the end, we talk about the network slicing that were very useful to maintain the Quality of Service, traffic management in the physical infrastructure by using the ns3 tool. We also offer how to network slicing will execute in other simulation tool.
We have undertaken the implementation of network slicing within the ns3 program and are here to assist you in utilizing this tool for your projects, including relevant topics. Our efforts have focused on configuration, quality of service (QoS) policies, and traffic management mechanisms.