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

How to Implement Network scheduling in ns3

To implement the network scheduling in ns3 has various steps to accomplish this process so initially describe and emulate how the packets are scheduled for transmission in a network. To manage the scheduling logic includes modifying or extending existing modules and creating custom applications.

The given below is the brief procedure to implement the network scheduling in ns3:

Step-by-Step Implementation:

Step 1: Setup ns3 Environment

Make certain ns3 is installed in the system and properly configured.

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

cd ns-3-dev

./waf configure

./waf build

Step 2: Understand ns3 Structure

The ns3 is modular, and network scheduling can be executed inside numerous layers (MAC, Network). The most relevant layers for scheduling are the MAC layer (e.g., WiFi, LTE).

Step 3: Create a Custom Scheduler

To implement a custom network scheduler, we need to generate or modify a MAC layer scheduler. Here, we’ll create a custom WiFi scheduler.

  1. Create a Custom WiFi Scheduler:

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/wifi-module.h”

#include “ns3/mobility-module.h”

#include “ns3/internet-module.h”

#include “ns3/applications-module.h”

using namespace ns3;

class CustomWifiMacScheduler : public RegularWifiMac

{

public:

static TypeId GetTypeId(void);

CustomWifiMacScheduler();

virtual ~CustomWifiMacScheduler();

void SetScheduleInterval(Time interval);

void AddPacket(Ptr<Packet> packet);

private:

virtual void StartApplication(void);

virtual void StopApplication(void);

void SchedulePackets(void);

Time m_scheduleInterval;

std::queue<Ptr<Packet>> m_packetQueue;

EventId m_scheduleEvent;

};

NS_OBJECT_ENSURE_REGISTERED(CustomWifiMacScheduler);

TypeId CustomWifiMacScheduler::GetTypeId(void)

{

static TypeId tid = TypeId(“CustomWifiMacScheduler”)

.SetParent<RegularWifiMac>()

.SetGroupName(“Wifi”)

.AddConstructor<CustomWifiMacScheduler>();

return tid;

}

CustomWifiMacScheduler::CustomWifiMacScheduler()

: m_scheduleInterval(Seconds(1.0))

{

}

CustomWifiMacScheduler::~CustomWifiMacScheduler()

{

}

void CustomWifiMacScheduler::SetScheduleInterval(Time interval)

{

m_scheduleInterval = interval;

}

void CustomWifiMacScheduler::AddPacket(Ptr<Packet> packet)

{

m_packetQueue.push(packet);

}

void CustomWifiMacScheduler::StartApplication(void)

{

m_scheduleEvent=Simulator::Schedule(m_scheduleInterval,&CustomWifiMacScheduler::SchedulePackets, this);

}

void CustomWifiMacScheduler::StopApplication(void)

{

Simulator::Cancel(m_scheduleEvent);

}

void CustomWifiMacScheduler::SchedulePackets(void)

{

if (!m_packetQueue.empty())

{

Ptr<Packet> packet = m_packetQueue.front();

m_packetQueue.pop();

RegularWifiMac::ForwardUp(packet, Mac48Address(), Mac48Address());

}

m_scheduleEvent = Simulator::Schedule(m_scheduleInterval, &CustomWifiMacScheduler::SchedulePackets, this);

}

Create a Helper Function:

class CustomWifiMacSchedulerHelper

{

public:

CustomWifiMacSchedulerHelper();

void Install(Ptr<Node> node, Time interval);

private:

Ptr<CustomWifiMacScheduler> m_scheduler;

};

CustomWifiMacSchedulerHelper::CustomWifiMacSchedulerHelper()

: m_scheduler(CreateObject<CustomWifiMacScheduler>())

{

}

void CustomWifiMacSchedulerHelper::Install(Ptr<Node> node, Time interval)

{

m_scheduler->SetScheduleInterval(interval);

node->AddApplication(m_scheduler);

m_scheduler->SetStartTime(Seconds(1.0));

m_scheduler->SetStopTime(Seconds(10.0));

}

Step 4: Modify Simulation Script

Integrate the custom scheduler into your simulation script.

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

#include “ns3/wifi-module.h”

#include “ns3/mobility-module.h”

#include “ns3/applications-module.h”

#include “custom-wifi-mac-scheduler-helper.h”

using namespace ns3;

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

{

NodeContainer wifiStaNodes;

wifiStaNodes.Create(1);

NodeContainer wifiApNode;

wifiApNode.Create(1);

YansWifiChannelHelper channel = YansWifiChannelHelper::Default();

YansWifiPhyHelper phy = YansWifiPhyHelper::Default();

phy.SetChannel(channel.Create());

WifiHelper wifi = WifiHelper::Default();

wifi.SetRemoteStationManager(“ns3::AarfWifiManager”);

WifiMacHelper mac;

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

mac.SetType(“ns3::StaWifiMac”, “Ssid”, SsidValue(ssid), “ActiveProbing”, BooleanValue(false));

NetDeviceContainer staDevices = wifi.Install(phy, mac, wifiStaNodes);

mac.SetType(“ns3::ApWifiMac”, “Ssid”, SsidValue(ssid));

NetDeviceContainer apDevices = wifi.Install(phy, mac, wifiApNode);

MobilityHelper mobility;

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

mobility.Install(wifiApNode);

mobility.Install(wifiStaNodes);

InternetStackHelper stack;

stack.Install(wifiApNode);

stack.Install(wifiStaNodes);

Ipv4AddressHelper address;

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

Ipv4InterfaceContainer apInterfaces = address.Assign(apDevices);

Ipv4InterfaceContainer staInterfaces = address.Assign(staDevices);

CustomWifiMacSchedulerHelper schedulerHelper;

schedulerHelper.Install(wifiStaNodes.Get(0), Seconds(1.0)); // Schedule packets every 1 second

Simulator::Stop(Seconds(10.0));

Simulator::Run();

Simulator::Destroy();

return 0;

}

Step 5: Run the Simulation

  1. Compile the Simulation:

./waf configure –enable-examples

./waf build

Run the Simulation:

./waf –run <your-simulation-script>

Step 6: Analyse Results

After running the simulation, analyse the results to evaluate the performance of your scheduling algorithm. we need to collect metrics such as packet delivery ratio, latency, throughput, and fairness.

At the last, we clearly understood how the network scheduling will perform and implemented in the network using the ns3 framework and also, we further provide the additional details on network scheduling.

To implement the network scheduling in ns3program for your research work , you can be in touch with us .We provide you best project performance results.