To implement IEEE 802.11 (Wi-Fi) in ns-3, we have to set up a wireless network using Wi-Fi protocols. ns-3 provides a wide range of Wi-Fi protocols by allowing us to simulate enormous Wi-Fi standards and configurations. Below are the steps to set up a basic Wi-Fi network scenario in ns3.
Steps to implement Wi-Fi in ns-3
- Set up your development environment
- Install ns-3 : Ensure that you have ns-3 installed in your computer. To install, follow the official ns-3 installation guide.
- Install required modules : Make sure that you have installed all the required ns-3 modules which includes Internet, mobility and Wi-Fi modules.
- Create a basic Wi-Fi simulation script
Here is a basic Wi-Fi scenario setup example script using ns-3 features. In this example, we simulate various Wi-Fi standards and configurations.
Example 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”
using namespace ns3;
NS_LOG_COMPONENT_DEFINE (“WifiExample”);
int main (int argc, char *argv[])
{
// Set simulation parameters
uint32_t numNodes = 2;
double simTime = 10.0; // Simulation time in seconds
double distance = 10.0; // Distance between nodes
CommandLine cmd;
cmd.AddValue(“numNodes”, “Number of Wi-Fi nodes”, numNodes);
cmd.AddValue(“simTime”, “Simulation time”, simTime);
cmd.AddValue(“distance”, “Distance between nodes”, distance);
cmd.Parse(argc, argv);
// Create nodes
NodeContainer wifiStaNodes;
wifiStaNodes.Create(numNodes);
NodeContainer wifiApNode = wifiStaNodes.Get(0);
// Set up Wi-Fi
YansWifiChannelHelper channel = YansWifiChannelHelper::Default();
YansWifiPhyHelper phy = YansWifiPhyHelper::Default();
phy.SetChannel(channel.Create());
WifiHelper wifi;
wifi.SetStandard(WIFI_PHY_STANDARD_80211n_5GHZ);
WifiMacHelper mac;
Ssid ssid = Ssid(“ns-3-ssid”);
mac.SetType(“ns3::StaWifiMac”,
“Ssid”, SsidValue(ssid),
“ActiveProbing”, BooleanValue(false));
NetDeviceContainer staDevices;
staDevices = wifi.Install(phy, mac, wifiStaNodes);
mac.SetType(“ns3::ApWifiMac”,
“Ssid”, SsidValue(ssid));
NetDeviceContainer apDevices;
apDevices = wifi.Install(phy, mac, wifiApNode);
// Set up mobility
MobilityHelper mobility;
mobility.SetPositionAllocator(“ns3::GridPositionAllocator”,
“MinX”, DoubleValue(0.0),
“MinY”, DoubleValue(0.0),
“DeltaX”, DoubleValue(distance),
“DeltaY”, DoubleValue(distance),
“GridWidth”, UintegerValue(3),
“LayoutType”, StringValue(“RowFirst”));
mobility.SetMobilityModel(“ns3::ConstantPositionMobilityModel”);
mobility.Install(wifiStaNodes);
// Install the Internet stack on the nodes
InternetStackHelper stack;
stack.Install(wifiStaNodes);
// Assign IP addresses to devices
Ipv4AddressHelper address;
address.SetBase(“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer staInterfaces;
staInterfaces = address.Assign(staDevices);
Ipv4InterfaceContainer apInterfaces;
apInterfaces = address.Assign(apDevices);
// Install applications
UdpEchoServerHelper echoServer(9);
ApplicationContainer serverApp = echoServer.Install(wifiApNode);
serverApp.Start(Seconds(1.0));
serverApp.Stop(Seconds(simTime));
UdpEchoClientHelper echoClient(apInterfaces.GetAddress(0), 9);
echoClient.SetAttribute(“MaxPackets”, UintegerValue(10));
echoClient.SetAttribute(“Interval”, TimeValue(Seconds(1.0)));
echoClient.SetAttribute(“PacketSize”, UintegerValue(1024));
ApplicationContainer clientApp = echoClient.Install(wifiStaNodes.Get(1));
clientApp.Start(Seconds(2.0));
clientApp.Stop(Seconds(simTime));
// Enable tracing
phy.EnablePcap(“wifi-example”, apDevices.Get(0));
// Run the simulation
Simulator::Stop(Seconds(simTime));
Simulator::Run();
Simulator::Destroy();
return 0;
}
Explanation of the script
In this set up, we had created a network with VLANs to segment traffic within the network using ns-3 features. Let’s have a detailed explanation on the script below:
- Include necessary headers : Include all the required headers for ns-3 core, network, internet, Wi-Fi, mobility and application modules.
- Set simulation Parameters : Define the nodes for Wi-Fi and also define the simulation time and distance between the nodes.
- Create nodes : Using NodeContainer, create nodes for Wi-Fi stations (STA) and access point (AP).
- Set up Wi-Fi : Using YansWifiChannelHelper and YansWifiPhyHelper Configure the Wi-Fi channel and physical layer. The Wi-Fi standard should be in 802.11n 5GHz, set the Wi-Fi standard using Also configure the MAC layer for both STAs and AP using WifiMacHelper.
- Set Up Mobility : Using MobilityHelper, define the positions and mobility models.
- Install internet stack : Using InternetStackHelper, install the internet stack on all the nodes.
- Assign IP addresses : Using Ipv4AddressHelper, assign IP addresses to the devices.
- Install applications : On the AP node, install the UDP echo server and on the STA nodes, install the UDP echo clients to simulate communications.
- Enable tracking : Capture packet traces using pcap tracing for analysis.
- Run the simulator : Define the simulation stopping time and run the simulator and cleanup using Simulator::Stop, Simulator::Run, and Simulator::Destroy.
Future enhancements
In future, we would like to enhance the mobility models, change the Wi-Fi standards, implement QoS etc.
- Advanced Mobility Models:
- Mobile node should include more realistic mobility models.
- Different Wi-Fi Standards:
- Change the Wi-Fi standard in the script by Experimenting with different Wi-Fi standards (e.g., 802.11a, 802.11b, 802.11g, 802.11ac).
- Quality of Service (QoS):
- Prioritize traffic by implementing QoS mechanisms and also ensure timely delivery.
- Network Performance Metrics:
- Collect and analyze performance metrics such as throughput, latency, packet delivery ratio, and resource utilization.
- Interference Modeling:
- Model interference from ambient light and other sources and evaluate it creates a great impact on network performance.
- Fault Tolerance and Resilience:
- Implement and evaluate fault tolerance mechanisms and resilience strategies for Wi-Fi communication.
Overall, we have learned on implementing IEEE 802.11 (Wi-Fi) in ns-3 using a wireless network with Wi-Fi protocols and simulated Wi-Fi standards and configurations using ns-3 features. Also, we provide more information on IEEE 802.11 (Wi-Fi).