#include "ns3/core-module.h"
#include "ns3/applications-module.h"
#include "ns3/wifi-module.h"
#include "ns3/mobility-module.h"
#include "ns3/internet-module.h"
#include "ns3/network-module.h"
#include "ns3/ipv4-global-routing-helper.h"
#include "ns3/he-configuration.h"
#include "ns3/netanim-module.h"
#include <iostream>
#include <fstream>
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("he-wifi-network");
int main (int argc, char *argv[])
{
int mcs = 9; //0 to 9
int channelWidth = 80;
int payloadSize;
double simulationTime = 10;
int frameCount = 64;
int nSta = 1;
double distance = 0;
NodeContainer wifiStaNode;
wifiStaNode.Create (nSta);
NodeContainer wifiApNode;
wifiApNode.Create (1);
payloadSize = 1472; //bytes
YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
phy.SetChannel (channel.Create ());
WifiMacHelper mac;
WifiHelper wifi;
wifi.SetStandard (WIFI_PHY_STANDARD_80211ac);
std::ostringstream oss;
oss << "VhtMcs" << mcs;
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager","DataMode", StringValue (oss.str ()),
"ControlMode", StringValue (oss.str ()));
Ssid ssid = Ssid ("ns3-80211ac");
mac.SetType ("ns3::StaWifiMac",
"Ssid", SsidValue (ssid),
"BE_MaxAmsduSize", UintegerValue (7991),
"BE_MaxAmpduSize", UintegerValue (4692480));
NetDeviceContainer staDevice;
staDevice = wifi.Install (phy, mac, wifiStaNode);
mac.SetType ("ns3::ApWifiMac",
"EnableBeaconJitter", BooleanValue (false),
"Ssid", SsidValue (ssid),
"BE_MaxAmsduSize", UintegerValue (7991),
"BE_MaxAmpduSize",UintegerValue (frameCount*7991)); //4692480
NetDeviceContainer apDevice;
apDevice = wifi.Install (phy, mac, wifiApNode);
Config::Set ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/ChannelWidth", UintegerValue (channelWidth));
// Mobility
MobilityHelper mobility;
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
positionAlloc->Add (Vector (0.0, 0.0, 0.0));
positionAlloc->Add (Vector (distance, 0.0, 0.0));
mobility.SetPositionAllocator (positionAlloc);
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (wifiApNode);
mobility.Install (wifiStaNode);
/* Internet stack*/
InternetStackHelper stack;
stack.Install (wifiApNode);
stack.Install (wifiStaNode);
Ipv4AddressHelper address;
address.SetBase ("192.168.1.0", "255.255.255.0");
Ipv4InterfaceContainer staNodeInterface;
Ipv4InterfaceContainer apNodeInterface;
staNodeInterface = address.Assign (staDevice);
apNodeInterface = address.Assign (apDevice);
ApplicationContainer serverApp;
ApplicationContainer serverApp1;
uint16_t port = 9;
UdpServerHelper server (port);
serverApp = server.Install (wifiStaNode.Get (0));
UdpClientHelper client (staNodeInterface.GetAddress (0), port);
client.SetAttribute ("MaxPackets", UintegerValue (4294967295u));
client.SetAttribute ("Interval", TimeValue (Time ("0.00001"))); //packets/s
client.SetAttribute ("PacketSize", UintegerValue (payloadSize));
ApplicationContainer clientApp = client.Install (wifiApNode.Get (0));
clientApp.Start (Seconds (1.0));
clientApp.Stop (Seconds (simulationTime + 1));
serverApp.Start (Seconds (0.0));
serverApp.Stop (Seconds (simulationTime+ 1));
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
Simulator::Stop (Seconds (simulationTime + 1));
phy.EnablePcap ("wifiSTA-network_packets.cc", wifiStaNode);
phy.EnablePcap ("wifiAP-network_packets.cc", wifiApNode);
Simulator::Run ();
Simulator::Destroy ();
uint64_t rxBytes = 0;
rxBytes = payloadSize * DynamicCast<UdpServer> (serverApp.Get (0))->GetReceived ();
double throughput = (rxBytes * 8) / (simulationTime * 1000000.0); //Mbit/s
return 0;
}