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

How To Implement 5G Network Slicing In Ns3

Here we discover the fifth generation and their simulation process about network slicing in ns-3.

Initially, to implement 5G network slicing in ns-3 has to generate the one or more virtual networks on the shared physical organization and then each virtual network can be designed for their needs and use in different cases. At the same time 5G network slicing does not have the built-in support functionalities, however we simulate by an integration for ns-3 modules that make the separate network slices.

Now we suggest the procedure to set up the 5G network slicing simulation in ns-3 environment:

Prerequisites

  • ns-3 installed on your system.
  • Basic understanding of ns-3 and C++ programming.

Steps to Implement 5G Network Slicing in ns-3

Here we can see how the 5G Network Slicing implement in ns-3 environment;

  1. Install ns-3: Ensure you have ns-3 installed. You can download it from the official website and follow the installation instructions.

wget https://www.nsnam.org/release/ns-allinone-3.xx.tar.bz2

tar -xjf ns-allinone-3.xx.tar.bz2

cd ns-allinone-3.xx

./build.py –enable-examples –enable-tests

  1. Include Necessary Headers: Include the required headers for network modules, mobility, internet, and point-to-point links.

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/mobility-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”

  1. Create Network Topology: Create nodes representing the core network, base stations (gNBs), and user equipment (UEs).

NodeContainer coreNodes;

coreNodes.Create(1); // Create core network node

NodeContainer gnbNodes;

gnbNodes.Create(2); // Create two gNBs

NodeContainer ueNodes;

ueNodes.Create(4); // Create four UEs

  1. Set Up Mobility Model: Configure the mobility model to simulate the placement and movement of the nodes.

MobilityHelper mobility;

mobility.SetPositionAllocator(“ns3::GridPositionAllocator”,

                              “MinX”, DoubleValue(0.0),

                              “MinY”, DoubleValue(0.0),

                              “DeltaX”, DoubleValue(100.0),

                              “DeltaY”, DoubleValue(100.0),

                              “GridWidth”, UintegerValue(2),

                              “LayoutType”, StringValue(“RowFirst”));

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

mobility.Install(coreNodes);

mobility.Install(gnbNodes);

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

mobility.Install(ueNodes);

  1. Set Up Point-to-Point Links: Configure point-to-point links for the core network and base stations.

PointToPointHelper pointToPoint;

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

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

NetDeviceContainer coreGnbDevices;

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

    NetDeviceContainer link = pointToPoint.Install(NodeContainer(coreNodes.Get(0), gnbNodes.Get(i)));

    coreGnbDevices.Add(link);

}

  1. Install Internet Stack: Install the internet stack on the nodes.

InternetStackHelper internet;

internet.Install(coreNodes);

internet.Install(gnbNodes);

internet.Install(ueNodes);

Ipv4AddressHelper address;

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

Ipv4InterfaceContainer coreGnbInterfaces = address.Assign(coreGnbDevices);

  1. Set Up WiFi for UE to gNB Communication: Use WiFi to simulate the communication between UEs and gNBs.

YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default();

YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default();

wifiPhy.SetChannel(wifiChannel.Create());

WifiHelper wifi;

wifi.SetStandard(WIFI_PHY_STANDARD_80211n);

WifiMacHelper wifiMac;

Ssid ssid1 = Ssid(“ns-3-ssid-1”);

Ssid ssid2 = Ssid(“ns-3-ssid-2”);

wifiMac.SetType(“ns3::StaWifiMac”, “Ssid”, SsidValue(ssid1));

NetDeviceContainer ueDevices1 = wifi.Install(wifiPhy, wifiMac, ueNodes.Get(0));

ueDevices1.Add(wifi.Install(wifiPhy, wifiMac, ueNodes.Get(1)));

wifiMac.SetType(“ns3::StaWifiMac”, “Ssid”, SsidValue(ssid2));

NetDeviceContainer ueDevices2 = wifi.Install(wifiPhy, wifiMac, ueNodes.Get(2));

ueDevices2.Add(wifi.Install(wifiPhy, wifiMac, ueNodes.Get(3)));

wifiMac.SetType(“ns3::ApWifiMac”, “Ssid”, SsidValue(ssid1));

NetDeviceContainer gnbDevices1 = wifi.Install(wifiPhy, wifiMac, gnbNodes.Get(0));

wifiMac.SetType(“ns3::ApWifiMac”, “Ssid”, SsidValue(ssid2));

NetDeviceContainer gnbDevices2 = wifi.Install(wifiPhy, wifiMac, gnbNodes.Get(1));

  1. Assign IP Addresses to UE Devices: Assign IP addresses to the UE devices.

Ipv4InterfaceContainer ueInterfaces1 = address.Assign(ueDevices1);

Ipv4InterfaceContainer ueInterfaces2 = address.Assign(ueDevices2);

  1. Create Network Slices: Create applications to simulate different network slices with different QoS requirements.

uint16_t port1 = 8000;

uint16_t port2 = 8001;

OnOffHelper onoff1(“ns3::UdpSocketFactory”, Address(InetSocketAddress(ueInterfaces1.GetAddress(1), port1)));

onoff1.SetConstantRate(DataRate(“5Mbps”));

ApplicationContainer apps1 = onoff1.Install(ueNodes.Get(0));

apps1.Start(Seconds(1.0));

apps1.Stop(Seconds(10.0));

PacketSinkHelper sink1(“ns3::UdpSocketFactory”, Address(InetSocketAddress(Ipv4Address::GetAny(), port1)));

apps1 = sink1.Install(ueNodes.Get(1));

apps1.Start(Seconds(0.0));

apps1.Stop(Seconds(10.0));

OnOffHelper onoff2(“ns3::UdpSocketFactory”, Address(InetSocketAddress(ueInterfaces2.GetAddress(1), port2)));

onoff2.SetConstantRate(DataRate(“10Mbps”));

ApplicationContainer apps2 = onoff2.Install(ueNodes.Get(2));

apps2.Start(Seconds(1.0));

apps2.Stop(Seconds(10.0));

PacketSinkHelper sink2(“ns3::UdpSocketFactory”, Address(InetSocketAddress(Ipv4Address::GetAny(), port2)));

apps2 = sink2.Install(ueNodes.Get(3));

apps2.Start(Seconds(0.0));

apps2.Stop(Seconds(10.0));

  1. Run the Simulation: Finally, run the simulation and clean up.

Simulator::Stop(Seconds(10.0));

Simulator::Run();

Simulator::Destroy();

Example Complete Script

In this direction we provide the sample script for setting up the basic concepts of 5G network slicing emulation in ns-3 environment:

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/mobility-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;

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

{

    NodeContainer coreNodes;

    coreNodes.Create(1); // Create core network node

    NodeContainer gnbNodes;

    gnbNodes.Create(2); // Create two gNBs

    NodeContainer ueNodes;

    ueNodes.Create(4); // Create four UEs

    MobilityHelper mobility;

    mobility.SetPositionAllocator(“ns3::GridPositionAllocator”,

                                  “MinX”, DoubleValue(0.0),

                                  “MinY”, DoubleValue(0.0),

                                  “DeltaX”, DoubleValue(100.0),

                                  “DeltaY”, DoubleValue(100.0),

                                  “GridWidth”, UintegerValue(2),

                                  “LayoutType”, StringValue(“RowFirst”));

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

    mobility.Install(coreNodes);

    mobility.Install(gnbNodes);

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

    mobility.Install(ueNodes);

    PointToPointHelper pointToPoint;

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

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

    NetDeviceContainer coreGnbDevices;

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

        NetDeviceContainer link = pointToPoint.Install(NodeContainer(coreNodes.Get(0), gnbNodes.Get(i)));

        coreGnbDevices.Add(link);

    }

    InternetStackHelper internet;

    internet.Install(coreNodes);

    internet.Install(gnbNodes);

    internet.Install(ueNodes);

    Ipv4AddressHelper address;

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

    Ipv4InterfaceContainer coreGnbInterfaces = address.Assign(coreGnbDevices);

    YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default();

    YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default();    wifiPhy.SetChannel(wifiChannel.Create());

    WifiHelper wifi;    wifi.SetStandard(WIFI_PHY_STANDARD_80211n);

    WifiMacHelper wifiMac;

    Ssid ssid1 = Ssid(“ns-3-ssid-1”);

    Ssid ssid2 = Ssid(“ns-3-ssid-2”);    wifiMac.SetType(“ns3::StaWifiMac”, “Ssid”, SsidValue(ssid1));

    NetDeviceContainer ueDevices1 = wifi.Install(wifiPhy, wifiMac, ueNodes.Get(0));    ueDevices1.Add(wifi.Install(wifiPhy, wifiMac, ueNodes.Get(1)));

    wifiMac.SetType(“ns3::StaWifiMac”, “Ssid”, SsidValue(ssid2));

    NetDeviceContainer ueDevices2 = wifi.Install(wifiPhy, wifiMac, ueNodes.Get(2));    ueDevices2.Add(wifi.Install(wifiPhy, wifiMac, ueNodes.Get(3)));    wifiMac.SetType(“ns3::ApWifiMac”, “Ssid”, SsidValue(ssid1));

    NetDeviceContainer gnbDevices1 = wifi.Install(wifiPhy, wifiMac, gnbNodes.Get(0));    wifiMac.SetType(“ns3::ApWifiMac”, “Ssid”, SsidValue(ssid2));

    NetDeviceContainer gnbDevices2 = wifi.Install(wifiPhy, wifiMac, gnbNodes.Get(1));

    Ipv4InterfaceContainer ueInterfaces1 = address.Assign(ueDevices1);

    Ipv4InterfaceContainer ueInterfaces2 = address.Assign(ueDevices2);

    uint16_t port1 = 8000;

    uint16_t port2 = 8001;

    OnOffHelper onoff1(“ns3::UdpSocketFactory”, Address(InetSocketAddress(ueInterfaces1.GetAddress(1), port1)));    onoff1.SetConstantRate(DataRate(“5Mbps”));

    ApplicationContainer apps1 = onoff1.Install(ueNodes.Get(0));

    apps1.Start(Seconds(1.0));

    apps1.Stop(Seconds(10.0));

    PacketSinkHelper sink1(“ns3::UdpSocketFactory”, Address(InetSocketAddress(Ipv4Address::GetAny(), port1)));

    apps1 = sink1.Install(ueNodes.Get(1));

    apps1.Start(Seconds(0.0));

    apps1.Stop(Seconds(10.0));

    OnOffHelper onoff2(“ns3::UdpSocketFactory”, Address(InetSocketAddress(ueInterfaces2.GetAddress(1), port2)));    onoff2.SetConstantRate(DataRate(“10Mbps”));

    ApplicationContainer apps2 = onoff2.Install(ueNodes.Get(2));

    apps2.Start(Seconds(1.0));

    apps2.Stop(Seconds(10.0));

    PacketSinkHelper sink2(“ns3::UdpSocketFactory”, Address(InetSocketAddress(Ipv4Address::GetAny(), port2)));

    apps2 = sink2.Install(ueNodes.Get(3));

    apps2.Start(Seconds(0.0));

    apps2.Stop(Seconds(10.0));

    Simulator::Stop(Seconds(10.0));

    Simulator::Run();

    Simulator::Destroy();

 

    return 0;

}

Running the Script

Compile and run the script using the following commands:

./waf configure –enable-examples

./waf build

./waf –run <script-name>

As we discussed earlier the ns-3 environment can be very much helpful in 5G network slicing and we guarantee and support all the varieties of work based on the 5G networks.