Get throughput during simulation run in real time WiFi VHT

172 views
Skip to first unread message

Matan

unread,
Jan 26, 2020, 8:57:30 AM1/26/20
to ns-3-users
Hey,
I'm using NS3 to simulate Wifi VHT 802.11ac communication between a single AP and a single Station. 
The AP has a client app installed on it and the Station has server installed.

I'm able to read rxBytes of the server app (station) after simulation ends and from that calculate the throughput in Mbit/s

I have a simulation of 10 seconds and I want to to get the throughput each second or half a second in realtime while simulation runs, any idea of how to implement it?

Thanks for your help!

this is the code I'm using now:

#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;
}

Stefan Lenz

unread,
Jan 28, 2020, 10:19:12 AM1/28/20
to ns-3-users
Hey,

you could use the Tracing System to get updates about Tx packets of the AP and Rx packets of the station with these values you should be able to calculate the throughput.

I am not sure what you mean exactly by "every second or half a second". So if you are still unsure what to do you can elobrate on that.

Cheers, Stefan
Reply all
Reply to author
Forward
0 new messages