To implement Orthogonal Frequency Division Multiplexing (OFDM) wireless communication in ns-3, we need to set up a wireless network that utilizes OFDM as its modulation scheme. In ns-3, the Wi-Fi module supports OFDM for IEEE 802.11a/g/n/ac standards. Here is a complete guide to implement OFDM wireless communication in ns-3.
Prerequisites
- Ns-3 should be installed on your system.
- You should have a basic understanding of ns-3 and C++ programming language.
Steps to Implement OFDM Wireless Communication in ns-3
Install ns-3 : make sure that you have ns-3 installed on your computer. If you don’t have ns-3 installed in your computer 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
Include Necessary Headers: Include the headers required for network modules, mobility, internet, and WIFI.
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/mobility-module.h”
#include “ns3/internet-module.h”
#include “ns3/wifi-module.h”
#include “ns3/applications-module.h”
Create Network Topology: Create nodes for the network.
NodeContainer wifiStaNodes;
wifiStaNodes.Create(2);
NodeContainer wifiApNode;
wifiApNode.Create(1);
Set Up WIFI Channel and Physical Layer: Configure the WIFI channel and physical layer to use OFDM.
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default();
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default();
wifiPhy.SetChannel(wifiChannel.Create());
wifiPhy.Set(“RxGain”, DoubleValue(0));
wifiPhy.Set(“TxGain”, DoubleValue(0));
Set Up WiFi Devices with OFDM: set the appropriate standard (e.g., 802.11a, 802.11g, 802.11n) to configure the WIFI devices with OFDM.
WifiHelper wifi;
wifi.SetStandard(WIFI_PHY_STANDARD_80211a); // Setting the standard to 802.11a which uses OFDM
WifiMacHelper wifiMac;
Ssid ssid = Ssid(“ns-3-ssid”);
wifiMac.SetType(“ns3::StaWifiMac”, “Ssid”, SsidValue(ssid), “ActiveProbing”, BooleanValue(false));
NetDeviceContainer staDevices = wifi.Install(wifiPhy, wifiMac, wifiStaNodes);
wifiMac.SetType(“ns3::ApWifiMac”, “Ssid”, SsidValue(ssid));
NetDeviceContainer apDevice = wifi.Install(wifiPhy, wifiMac, wifiApNode);
Set Up Mobility Model: Configure the mobility model to simulate the placement of the nodes.
MobilityHelper mobility;
mobility.SetPositionAllocator(“ns3::GridPositionAllocator”,
“MinX”, DoubleValue(0.0),
“MinY”, DoubleValue(0.0),
“DeltaX”, DoubleValue(5.0),
“DeltaY”, DoubleValue(5.0),
“GridWidth”, UintegerValue(3),
“LayoutType”, StringValue(“RowFirst”));
mobility.SetMobilityModel(“ns3::ConstantPositionMobilityModel”);
mobility.Install(wifiApNode);
mobility.SetMobilityModel(“ns3::ConstantPositionMobilityModel”);
mobility.Install(wifiStaNodes);
Install Internet Stack: Install the internet stack on the nodes.
InternetStackHelper stack;
stack.Install(wifiApNode);
stack.Install(wifiStaNodes);
Ipv4AddressHelper address;
address.SetBase(“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer apInterface = address.Assign(apDevice);
Ipv4InterfaceContainer staInterfaces = address.Assign(staDevices);
Create Applications: Install and create applications to simulate data transmission between the stations and the access point.
uint16_t port = 9;
OnOffHelper onoff(“ns3::UdpSocketFactory”, Address(InetSocketAddress(staInterfaces.GetAddress(0), port)));
onoff.SetConstantRate(DataRate(“54Mbps”));
ApplicationContainer apps = onoff.Install(wifiApNode.Get(0));
apps.Start(Seconds(1.0));
apps.Stop(Seconds(10.0));
PacketSinkHelper sink(“ns3::UdpSocketFactory”, Address(InetSocketAddress(Ipv4Address::GetAny(), port)));
apps = sink.Install(wifiStaNodes.Get(0));
apps.Start(Seconds(0.0));
apps.Stop(Seconds(10.0));
Run the Simulation: Define the simulation stop time and run the simulator.
Simulator::Stop(Seconds(10.0));
Simulator::Run();
Simulator::Destroy();
Example Script
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/mobility-module.h”
#include “ns3/internet-module.h”
#include “ns3/wifi-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 wifiChannel = YansWifiChannelHelper::Default();
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default();
wifiPhy.SetChannel(wifiChannel.Create());
wifiPhy.Set(“RxGain”, DoubleValue(0));
wifiPhy.Set(“TxGain”, DoubleValue(0));
WifiHelper wifi;
wifi.SetStandard(WIFI_PHY_STANDARD_80211a); // Setting the standard to 802.11a which uses OFDM
WifiMacHelper wifiMac;
Ssid ssid = Ssid(“ns-3-ssid”);
wifiMac.SetType(“ns3::StaWifiMac”, “Ssid”, SsidValue(ssid), “ActiveProbing”, BooleanValue(false));
NetDeviceContainer staDevices = wifi.Install(wifiPhy, wifiMac, wifiStaNodes);
wifiMac.SetType(“ns3::ApWifiMac”, “Ssid”, SsidValue(ssid));
NetDeviceContainer apDevice = wifi.Install(wifiPhy, wifiMac, wifiApNode);
MobilityHelper mobility;
mobility.SetPositionAllocator(“ns3::GridPositionAllocator”,
“MinX”, DoubleValue(0.0),
“MinY”, DoubleValue(0.0),
“DeltaX”, DoubleValue(5.0),
“DeltaY”, DoubleValue(5.0), “GridWidth”, UintegerValue(3), “LayoutType”, StringValue(“RowFirst”)); mobility.SetMobilityModel(“ns3::ConstantPositionMobilityModel”); mobility.Install(wifiApNode); mobility.SetMobilityModel(“ns3::ConstantPositionMobilityModel”);
mobility.Install(wifiStaNodes);
InternetStackHelper stack;
stack.Install(wifiApNode);
stack.Install(wifiStaNodes);
Ipv4AddressHelper address;
address.SetBase(“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer apInterface = address.Assign(apDevice);
Ipv4InterfaceContainer staInterfaces = address.Assign(staDevices);
uint16_t port = 9;
OnOffHelper onoff(“ns3::UdpSocketFactory”, Address(InetSocketAddress(staInterfaces.GetAddress(0), port)));
onoff.SetConstantRate(DataRate(“54Mbps”));
ApplicationContainer apps = onoff.Install(wifiApNode.Get(0));
apps.Start(Seconds(1.0));
apps.Stop(Seconds(10.0));
PacketSinkHelper sink(“ns3::UdpSocketFactory”, Address(InetSocketAddress(Ipv4Address::GetAny(), port)));
apps = sink.Install(wifiStaNodes.Get(0));
apps.Start(Seconds(0.0));
apps.Stop(Seconds(10.0));
Simulator::Stop(Seconds(10.0));
Simulator::Run();
Simulator::Destroy();
return 0;
}
Running the Script
Use the following commands to compile and run the script:
./waf configure –enable-examples
./waf build
./waf –run <script-name>
Get our support for all your project programming support , we follow the above procedures for a proper implementation.