To implement the network multiple access in the ns3, we could use various multiple access schemes like TDMA (Time Division Multiple Access), FDMA (Frequency Division Multiple Access), or CSMA/CA (Carrier Sense Multiple Access with Collision Avoidance) by configuring the network. The Network Multiple Access is implemented only by configuring the network Via Wi-Fi module, ns3 offers built-in support for some of these schemes specially CSMA/CA to use the various multiple access schemes. Here, we provide how you can implement various multiple access schemes in ns3 with an example:
Step-by-Step Implementation:
- Implementing CSMA/CA (Wi-Fi)
First, we have to set up the Wi-Fi network in the ns3 because CSMA/CA is commonly used in Wi-Fi networks. Here we offer how to set up the Wi-Fi networks:
Step 1: Include Necessary Modules
Make sure, your script contains the essential ns3 modules:
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/mobility-module.h”
#include “ns3/wifi-module.h”
#include “ns3/internet-module.h”
#include “ns3/applications-module.h”
Step 2: Set Up the Wi-Fi Network
In this step, we are setting up the nodes, devices and mobility models:
using namespace ns3;
int main (int argc, char *argv[])
{
NodeContainer wifiStaNodes;
wifiStaNodes.Create (2);
NodeContainer wifiApNode;
wifiApNode.Create (1);
YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
phy.SetChannel (channel.Create ());
WifiHelper wifi;
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.SetPositionAllocator (“ns3::GridPositionAllocator”,
“MinX”, DoubleValue (0.0),
“MinY”, DoubleValue (0.0),
“DeltaX”, DoubleValue (5.0),
“DeltaY”, DoubleValue (10.0),
“GridWidth”, UintegerValue (3),
“LayoutType”, StringValue (“RowFirst”));
mobility.SetMobilityModel (“ns3::ConstantPositionMobilityModel”);
mobility.Install (wifiApNode);
mobility.Install (wifiStaNodes);
InternetStackHelper stack;
stack.Install (wifiApNode);
stack.Install (wifiStaNodes);
Ipv4AddressHelper address;
address.SetBase (“10.1.3.0”, “255.255.255.0”);
Ipv4InterfaceContainer staInterfaces = address.Assign (staDevices);
Ipv4InterfaceContainer apInterface = address.Assign (apDevices);
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApp = echoServer.Install (wifiApNode.Get (0));
serverApp.Start (Seconds (1.0));
serverApp.Stop (Seconds (10.0));
UdpEchoClientHelper echoClient (apInterface.GetAddress (0), 9);
echoClient.SetAttribute (“MaxPackets”, UintegerValue (1));
echoClient.SetAttribute (“Interval”, TimeValue (Seconds (1.0)));
echoClient.SetAttribute (“PacketSize”, UintegerValue (1024));
ApplicationContainer clientApp = echoClient.Install (wifiStaNodes.Get (0));
clientApp.Start (Seconds (2.0));
clientApp.Stop (Seconds (10.0));
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
2. Implementing TDMA
In ns3, there is no integrated TDMA support so it requires custom implementation as ns3 Here’s a basic way to simulate TDMA behavior by scheduling transmissions in non-overlapping time slots.
Step 1: Define a TDMA Helper Class
Manage the time slots and node transmission by generating a helper class.
#include “ns3/application.h”
#include “ns3/address.h”
#include “ns3/ptr.h”
#include “ns3/socket.h”
#include “ns3/node.h”
#include “ns3/event-id.h”
#include “ns3/nstime.h”
#include “ns3/traced-callback.h”
#include “ns3/data-rate.h”
#include “ns3/packet.h”
#include “ns3/ipv4-address.h”
namespace ns3 {
class TdmaHelper : public Object
{
public:
TdmaHelper ();
void ScheduleTransmission (Ptr<Node> node, Time slotTime, uint32_t slotNumber);
void Transmit (Ptr<Node> node);
private:
Time m_slotTime;
};
TdmaHelper::TdmaHelper ()
: m_slotTime (Seconds (1.0))
{
}
void
TdmaHelper::ScheduleTransmission (Ptr<Node> node, Time slotTime, uint32_t slotNumber)
{
Simulator::Schedule (slotTime * slotNumber, &TdmaHelper::Transmit, this, node);
}
void
TdmaHelper::Transmit (Ptr<Node> node)
{
Ptr<Socket> socket = Socket::CreateSocket (node, TypeId::LookupByName (“ns3::UdpSocketFactory”));
InetSocketAddress remote = InetSocketAddress (Ipv4Address (“255.255.255.255”), 9);
socket->Connect (remote);
Ptr<Packet> packet = Create<Packet> (1024); // 1 KB packet
socket->Send (packet);
}
} // namespace ns3
Step 2: Use the TDMA Helper in Your Simulation Script
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/mobility-module.h”
#include “ns3/internet-module.h”
#include “tdma-helper.h”
using namespace ns3;
int main (int argc, char *argv[])
{
NodeContainer nodes;
nodes.Create (3);
InternetStackHelper stack;
stack.Install (nodes);
MobilityHelper mobility;
mobility.SetMobilityModel (“ns3::ConstantPositionMobilityModel”);
mobility.Install (nodes);
Ipv4AddressHelper address;
address.SetBase (“10.1.3.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces = address.Assign (NetDeviceContainer ());
TdmaHelper tdma;
Time slotTime = Seconds (1.0);
for (uint32_t i = 0; i < nodes.GetN (); ++i)
{
tdma.ScheduleTransmission (nodes.Get (i), slotTime, i);
}
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
3. Implementing FDMA
Based on the various users, FDMA allocates various frequency bands. Though ns3 does not have built-in support for FDMA, use different channels to simulate it.
Step 1: Configure Different Channels
Configure different channels for each node to simulate FDMA.
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/mobility-module.h”
#include “ns3/wifi-module.h”
#include “ns3/internet-module.h”
#include “ns3/applications-module.h”
using namespace ns3;
int main (int argc, char *argv[])
{
NodeContainer wifiStaNodes;
wifiStaNodes.Create (2);
NodeContainer wifiApNode;
wifiApNode.Create (1);
YansWifiChannelHelper channel1 = YansWifiChannelHelper::Default ();
YansWifiChannelHelper channel2 = YansWifiChannelHelper::Default ();
YansWifiPhyHelper phy1 = YansWifiPhyHelper::Default ();
phy1.SetChannel (channel1.Create ());
YansWifiPhyHelper phy2 = YansWifiPhyHelper::Default ();
phy2.SetChannel (channel2.Create ());
WifiHelper wifi;
wifi.SetRemoteStationManager (“ns3::AarfWifiManager”);
WifiMacHelper mac;
Ssid ssid1 = Ssid (“ns-3-ssid1”);
Ssid ssid2 = Ssid (“ns-3-ssid2”);
mac.SetType (“ns3::StaWifiMac”, “Ssid”, SsidValue (ssid1), “ActiveProbing”, BooleanValue (false));
NetDeviceContainer staDevices1 = wifi.Install (phy1, mac, wifiStaNodes.Get (0));
mac.SetType (“ns3::StaWifiMac”, “Ssid”, SsidValue (ssid2), “ActiveProbing”, BooleanValue (false));
NetDeviceContainer staDevices2 = wifi.Install (phy2, mac, wifiStaNodes.Get (1));
mac.SetType (“ns3::ApWifiMac”, “Ssid”, SsidValue (ssid1));
NetDeviceContainer apDevice1 = wifi.Install (phy1, mac, wifiApNode.Get (0));
mac.SetType (“ns3::ApWifiMac”, “Ssid”, SsidValue (ssid2));
NetDeviceContainer apDevice2 = wifi.Install (phy2, mac, wifiApNode.Get (0));
MobilityHelper mobility;
mobility.SetPositionAllocator (“ns3::GridPositionAllocator”,
“MinX”, DoubleValue (0.0),
“MinY”, DoubleValue (0.0),
“DeltaX”, DoubleValue (5.0),
“DeltaY”, DoubleValue (10.0),
“GridWidth”, UintegerValue (3),
“LayoutType”, StringValue (“RowFirst”));
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 staInterfaces1 = address.Assign (staDevices1);
Ipv4InterfaceContainer apInterface1 = address.Assign (apDevice1);
address.SetBase (“10.1.2.0”, “255.255.255.0”);
Ipv4InterfaceContainer staInterfaces2 = address.Assign (staDevices2);
Ipv4InterfaceContainer apInterface2 = address.Assign (apDevice2);
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApp1 = echoServer.Install (wifiApNode.Get (0));
serverApp1.Start (Seconds (1.0));
serverApp1.Stop (Seconds (10.0));
UdpEchoClientHelper echoClient1 (apInterface1.GetAddress (0), 9);
echoClient1.SetAttribute (“MaxPackets”, UintegerValue (1));
echoClient1.SetAttribute (“Interval”, TimeValue (Seconds (1.0)));
echoClient1.SetAttribute (“PacketSize”, UintegerValue (1024));
ApplicationContainer clientApp1 = echoClient1.Install (wifiStaNodes.Get (0));
clientApp1.Start (Seconds (2.0));
clientApp1.Stop (Seconds (10.0));
UdpEchoClientHelper echoClient2 (apInterface2.GetAddress (0), 9);
echoClient2.SetAttribute (“MaxPackets”, UintegerValue (1));
echoClient2.SetAttribute (“Interval”, TimeValue (Seconds (1.0)));
echoClient2.SetAttribute (“PacketSize”, UintegerValue (1024));
ApplicationContainer clientApp2 = echoClient2.Install (wifiStaNodes.Get (1));
clientApp2.Start (Seconds (2.0));
clientApp2.Stop (Seconds (10.0));
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
Overall, we utterly learned how to implement the network multiple access in the ns3 tool and how it works in the network simulation and how to execute them. For future references, we can offer the details of other helper modules as per your needs.
We have experience with TDMA (Time Division Multiple Access), FDMA (Frequency Division Multiple Access), and CSMA/CA (Carrier Sense Multiple Access with Collision Avoidance) network configurations. If you’re struggling to discover new topics on implementing Multiple Access in the ns3 tool, we are here to assist you.