2016-07-22 18:13:42 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2009 MIRKO BANCHI
|
|
|
|
|
* Copyright (c) 2015 University of Washington
|
|
|
|
|
*
|
2024-06-17 16:17:10 +02:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only
|
2016-07-22 18:13:42 -07:00
|
|
|
*
|
|
|
|
|
* Authors: Mirko Banchi <mk.banchi@gmail.com>
|
|
|
|
|
* Sebastien Deronne <sebastien.deronne@gmail.com>
|
|
|
|
|
* Tom Henderson <tomhend@u.washington.edu>
|
|
|
|
|
*
|
2019-07-17 15:35:33 +02:00
|
|
|
* Adapted from wifi-ht-network.cc example
|
2016-07-22 18:13:42 -07:00
|
|
|
*/
|
|
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
#include "ns3/boolean.h"
|
2018-04-13 23:08:35 +02:00
|
|
|
#include "ns3/command-line.h"
|
|
|
|
|
#include "ns3/config.h"
|
|
|
|
|
#include "ns3/double.h"
|
|
|
|
|
#include "ns3/internet-stack-helper.h"
|
|
|
|
|
#include "ns3/ipv4-address-helper.h"
|
|
|
|
|
#include "ns3/ipv4-global-routing-helper.h"
|
2022-10-07 20:08:35 +00:00
|
|
|
#include "ns3/log.h"
|
|
|
|
|
#include "ns3/mobility-helper.h"
|
2018-04-13 23:08:35 +02:00
|
|
|
#include "ns3/multi-model-spectrum-channel.h"
|
2022-10-07 20:08:35 +00:00
|
|
|
#include "ns3/on-off-helper.h"
|
|
|
|
|
#include "ns3/packet-sink-helper.h"
|
|
|
|
|
#include "ns3/packet-sink.h"
|
2018-04-13 23:08:35 +02:00
|
|
|
#include "ns3/propagation-loss-model.h"
|
2022-10-07 20:08:35 +00:00
|
|
|
#include "ns3/spectrum-wifi-helper.h"
|
|
|
|
|
#include "ns3/ssid.h"
|
|
|
|
|
#include "ns3/string.h"
|
|
|
|
|
#include "ns3/udp-client-server-helper.h"
|
2024-01-29 15:16:19 +00:00
|
|
|
#include "ns3/udp-server.h"
|
2022-10-07 20:08:35 +00:00
|
|
|
#include "ns3/uinteger.h"
|
|
|
|
|
#include "ns3/yans-wifi-channel.h"
|
|
|
|
|
#include "ns3/yans-wifi-helper.h"
|
|
|
|
|
|
|
|
|
|
#include <iomanip>
|
2016-07-22 18:13:42 -07:00
|
|
|
|
|
|
|
|
// This is a simple example of an IEEE 802.11n Wi-Fi network.
|
|
|
|
|
//
|
|
|
|
|
// The main use case is to enable and test SpectrumWifiPhy vs YansWifiPhy
|
|
|
|
|
// for packet error ratio
|
|
|
|
|
//
|
|
|
|
|
// Network topology:
|
|
|
|
|
//
|
|
|
|
|
// Wi-Fi 192.168.1.0
|
|
|
|
|
//
|
|
|
|
|
// STA AP
|
|
|
|
|
// * <-- distance --> *
|
|
|
|
|
// | |
|
|
|
|
|
// n1 n2
|
|
|
|
|
//
|
|
|
|
|
// Users may vary the following command-line arguments in addition to the
|
|
|
|
|
// attributes, global values, and default values typically available:
|
|
|
|
|
//
|
2024-02-27 22:39:01 +01:00
|
|
|
// --simulationTime: Simulation time [10s]
|
2016-07-22 18:13:42 -07:00
|
|
|
// --udp: UDP if set to 1, TCP otherwise [true]
|
|
|
|
|
// --distance: meters separation between nodes [50]
|
|
|
|
|
// --index: restrict index to single value between 0 and 31 [256]
|
|
|
|
|
// --wifiType: select ns3::SpectrumWifiPhy or ns3::YansWifiPhy [ns3::SpectrumWifiPhy]
|
2022-10-07 20:08:35 +00:00
|
|
|
// --errorModelType: select ns3::NistErrorRateModel or ns3::YansErrorRateModel
|
|
|
|
|
// [ns3::NistErrorRateModel]
|
2016-07-22 18:13:42 -07:00
|
|
|
// --enablePcap: enable pcap output [false]
|
|
|
|
|
//
|
|
|
|
|
// By default, the program will step through 32 index values, corresponding
|
|
|
|
|
// to the following MCS, channel width, and guard interval combinations:
|
|
|
|
|
// index 0-7: MCS 0-7, long guard interval, 20 MHz channel
|
|
|
|
|
// index 8-15: MCS 0-7, short guard interval, 20 MHz channel
|
|
|
|
|
// index 16-23: MCS 0-7, long guard interval, 40 MHz channel
|
|
|
|
|
// index 24-31: MCS 0-7, short guard interval, 40 MHz channel
|
2017-09-22 09:43:10 -07:00
|
|
|
// and send UDP for 10 seconds using each MCS, using the SpectrumWifiPhy and the
|
2016-07-22 18:13:42 -07:00
|
|
|
// NistErrorRateModel, at a distance of 50 meters. The program outputs
|
|
|
|
|
// results such as:
|
|
|
|
|
//
|
2017-09-22 09:43:10 -07:00
|
|
|
// wifiType: ns3::SpectrumWifiPhy distance: 50m; time: 10; TxPower: 1 dBm (1.3 mW)
|
|
|
|
|
// index MCS Rate (Mb/s) Tput (Mb/s) Received Signal (dBm) Noise (dBm) SNR (dB)
|
|
|
|
|
// 0 0 6.50 5.77 7414 -79.71 -93.97 14.25
|
|
|
|
|
// 1 1 13.00 11.58 14892 -79.71 -93.97 14.25
|
|
|
|
|
// 2 2 19.50 17.39 22358 -79.71 -93.97 14.25
|
|
|
|
|
// 3 3 26.00 22.96 29521 -79.71 -93.97 14.25
|
|
|
|
|
// ...
|
2016-07-22 18:13:42 -07:00
|
|
|
//
|
|
|
|
|
|
|
|
|
|
using namespace ns3;
|
|
|
|
|
|
|
|
|
|
// Global variables for use in callbacks.
|
2022-10-07 20:08:35 +00:00
|
|
|
double g_signalDbmAvg; //!< Average signal power [dBm]
|
|
|
|
|
double g_noiseDbmAvg; //!< Average noise power [dBm]
|
|
|
|
|
uint32_t g_samples; //!< Number of samples
|
2016-07-22 18:13:42 -07:00
|
|
|
|
2022-08-28 13:24:25 -05:00
|
|
|
/**
|
|
|
|
|
* Monitor sniffer Rx trace
|
|
|
|
|
*
|
2024-11-08 18:05:46 +00:00
|
|
|
* @param packet The sensed packet.
|
|
|
|
|
* @param channelFreqMhz The channel frequency [MHz].
|
|
|
|
|
* @param txVector The Tx vector.
|
|
|
|
|
* @param aMpdu The aMPDU.
|
|
|
|
|
* @param signalNoise The signal and noise dBm.
|
|
|
|
|
* @param staId The STA ID.
|
2022-08-28 13:24:25 -05:00
|
|
|
*/
|
2022-10-07 20:08:35 +00:00
|
|
|
void
|
|
|
|
|
MonitorSniffRx(Ptr<const Packet> packet,
|
|
|
|
|
uint16_t channelFreqMhz,
|
|
|
|
|
WifiTxVector txVector,
|
|
|
|
|
MpduInfo aMpdu,
|
|
|
|
|
SignalNoiseDbm signalNoise,
|
|
|
|
|
uint16_t staId)
|
2016-07-22 18:13:42 -07:00
|
|
|
|
|
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
g_samples++;
|
|
|
|
|
g_signalDbmAvg += ((signalNoise.signal - g_signalDbmAvg) / g_samples);
|
|
|
|
|
g_noiseDbmAvg += ((signalNoise.noise - g_noiseDbmAvg) / g_samples);
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
|
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
NS_LOG_COMPONENT_DEFINE("WifiSpectrumPerExample");
|
2016-07-22 18:13:42 -07:00
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
int
|
|
|
|
|
main(int argc, char* argv[])
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2024-02-27 22:39:01 +01:00
|
|
|
bool udp{true};
|
2024-06-13 20:40:24 +02:00
|
|
|
meter_u distance{50};
|
2024-02-27 22:39:01 +01:00
|
|
|
Time simulationTime{"10s"};
|
|
|
|
|
uint16_t index{256};
|
|
|
|
|
std::string wifiType{"ns3::SpectrumWifiPhy"};
|
|
|
|
|
std::string errorModelType{"ns3::NistErrorRateModel"};
|
|
|
|
|
bool enablePcap{false};
|
|
|
|
|
const uint32_t tcpPacketSize{1448};
|
2022-10-07 20:08:35 +00:00
|
|
|
|
|
|
|
|
CommandLine cmd(__FILE__);
|
2024-02-27 22:39:01 +01:00
|
|
|
cmd.AddValue("simulationTime", "Simulation time", simulationTime);
|
2022-10-07 20:08:35 +00:00
|
|
|
cmd.AddValue("udp", "UDP if set to 1, TCP otherwise", udp);
|
|
|
|
|
cmd.AddValue("distance", "meters separation between nodes", distance);
|
|
|
|
|
cmd.AddValue("index", "restrict index to single value between 0 and 31", index);
|
|
|
|
|
cmd.AddValue("wifiType", "select ns3::SpectrumWifiPhy or ns3::YansWifiPhy", wifiType);
|
|
|
|
|
cmd.AddValue("errorModelType",
|
|
|
|
|
"select ns3::NistErrorRateModel or ns3::YansErrorRateModel",
|
|
|
|
|
errorModelType);
|
|
|
|
|
cmd.AddValue("enablePcap", "enable pcap output", enablePcap);
|
|
|
|
|
cmd.Parse(argc, argv);
|
|
|
|
|
|
|
|
|
|
uint16_t startIndex = 0;
|
|
|
|
|
uint16_t stopIndex = 31;
|
|
|
|
|
if (index < 32)
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
startIndex = index;
|
|
|
|
|
stopIndex = index;
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
|
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
std::cout << "wifiType: " << wifiType << " distance: " << distance
|
|
|
|
|
<< "m; time: " << simulationTime << "; TxPower: 1 dBm (1.3 mW)" << std::endl;
|
|
|
|
|
std::cout << std::setw(5) << "index" << std::setw(6) << "MCS" << std::setw(13) << "Rate (Mb/s)"
|
|
|
|
|
<< std::setw(12) << "Tput (Mb/s)" << std::setw(10) << "Received " << std::setw(12)
|
|
|
|
|
<< "Signal (dBm)" << std::setw(12) << "Noise (dBm)" << std::setw(9) << "SNR (dB)"
|
|
|
|
|
<< std::endl;
|
|
|
|
|
for (uint16_t i = startIndex; i <= stopIndex; i++)
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
uint32_t payloadSize;
|
|
|
|
|
if (udp)
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
payloadSize = 972; // 1000 bytes IPv4
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
2022-10-07 20:08:35 +00:00
|
|
|
else
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
payloadSize = 1448; // 1500 bytes IPv6
|
|
|
|
|
Config::SetDefault("ns3::TcpSocket::SegmentSize", UintegerValue(payloadSize));
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
|
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
NodeContainer wifiStaNode;
|
|
|
|
|
wifiStaNode.Create(1);
|
|
|
|
|
NodeContainer wifiApNode;
|
|
|
|
|
wifiApNode.Create(1);
|
2016-07-22 18:13:42 -07:00
|
|
|
|
2024-06-25 11:56:20 +00:00
|
|
|
YansWifiPhyHelper yansPhy;
|
2022-10-07 20:08:35 +00:00
|
|
|
SpectrumWifiPhyHelper spectrumPhy;
|
|
|
|
|
if (wifiType == "ns3::YansWifiPhy")
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
YansWifiChannelHelper channel;
|
|
|
|
|
channel.AddPropagationLoss("ns3::FriisPropagationLossModel",
|
|
|
|
|
"Frequency",
|
|
|
|
|
DoubleValue(5.180e9));
|
|
|
|
|
channel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel");
|
2024-06-25 11:56:20 +00:00
|
|
|
yansPhy.SetChannel(channel.Create());
|
|
|
|
|
yansPhy.Set("TxPowerStart", DoubleValue(1)); // dBm (1.26 mW)
|
|
|
|
|
yansPhy.Set("TxPowerEnd", DoubleValue(1));
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
2022-10-07 20:08:35 +00:00
|
|
|
else if (wifiType == "ns3::SpectrumWifiPhy")
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
Ptr<MultiModelSpectrumChannel> spectrumChannel =
|
|
|
|
|
CreateObject<MultiModelSpectrumChannel>();
|
|
|
|
|
Ptr<FriisPropagationLossModel> lossModel = CreateObject<FriisPropagationLossModel>();
|
|
|
|
|
lossModel->SetFrequency(5.180e9);
|
|
|
|
|
spectrumChannel->AddPropagationLossModel(lossModel);
|
2016-07-22 18:13:42 -07:00
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
Ptr<ConstantSpeedPropagationDelayModel> delayModel =
|
|
|
|
|
CreateObject<ConstantSpeedPropagationDelayModel>();
|
|
|
|
|
spectrumChannel->SetPropagationDelayModel(delayModel);
|
2016-07-22 18:13:42 -07:00
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
spectrumPhy.SetChannel(spectrumChannel);
|
|
|
|
|
spectrumPhy.SetErrorRateModel(errorModelType);
|
|
|
|
|
spectrumPhy.Set("TxPowerStart", DoubleValue(1)); // dBm (1.26 mW)
|
|
|
|
|
spectrumPhy.Set("TxPowerEnd", DoubleValue(1));
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
2022-10-07 20:08:35 +00:00
|
|
|
else
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
NS_FATAL_ERROR("Unsupported WiFi type " << wifiType);
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
|
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
WifiHelper wifi;
|
|
|
|
|
wifi.SetStandard(WIFI_STANDARD_80211n);
|
|
|
|
|
WifiMacHelper mac;
|
2016-07-22 18:13:42 -07:00
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
Ssid ssid = Ssid("ns380211n");
|
2016-07-22 18:13:42 -07:00
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
double datarate = 0;
|
|
|
|
|
StringValue DataRate;
|
|
|
|
|
if (i == 0)
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
DataRate = StringValue("HtMcs0");
|
|
|
|
|
datarate = 6.5;
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
2022-10-07 20:08:35 +00:00
|
|
|
else if (i == 1)
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
DataRate = StringValue("HtMcs1");
|
|
|
|
|
datarate = 13;
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
2022-10-07 20:08:35 +00:00
|
|
|
else if (i == 2)
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
DataRate = StringValue("HtMcs2");
|
|
|
|
|
datarate = 19.5;
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
2022-10-07 20:08:35 +00:00
|
|
|
else if (i == 3)
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
DataRate = StringValue("HtMcs3");
|
|
|
|
|
datarate = 26;
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
2022-10-07 20:08:35 +00:00
|
|
|
else if (i == 4)
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
DataRate = StringValue("HtMcs4");
|
|
|
|
|
datarate = 39;
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
2022-10-07 20:08:35 +00:00
|
|
|
else if (i == 5)
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
DataRate = StringValue("HtMcs5");
|
|
|
|
|
datarate = 52;
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
2022-10-07 20:08:35 +00:00
|
|
|
else if (i == 6)
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
DataRate = StringValue("HtMcs6");
|
|
|
|
|
datarate = 58.5;
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
2022-10-07 20:08:35 +00:00
|
|
|
else if (i == 7)
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
DataRate = StringValue("HtMcs7");
|
|
|
|
|
datarate = 65;
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
2022-10-07 20:08:35 +00:00
|
|
|
else if (i == 8)
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
DataRate = StringValue("HtMcs0");
|
|
|
|
|
datarate = 7.2;
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
2022-10-07 20:08:35 +00:00
|
|
|
else if (i == 9)
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
DataRate = StringValue("HtMcs1");
|
|
|
|
|
datarate = 14.4;
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
2022-10-07 20:08:35 +00:00
|
|
|
else if (i == 10)
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
DataRate = StringValue("HtMcs2");
|
|
|
|
|
datarate = 21.7;
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
2022-10-07 20:08:35 +00:00
|
|
|
else if (i == 11)
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
DataRate = StringValue("HtMcs3");
|
|
|
|
|
datarate = 28.9;
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
2022-10-07 20:08:35 +00:00
|
|
|
else if (i == 12)
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
DataRate = StringValue("HtMcs4");
|
|
|
|
|
datarate = 43.3;
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
2022-10-07 20:08:35 +00:00
|
|
|
else if (i == 13)
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
DataRate = StringValue("HtMcs5");
|
|
|
|
|
datarate = 57.8;
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
2022-10-07 20:08:35 +00:00
|
|
|
else if (i == 14)
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
DataRate = StringValue("HtMcs6");
|
|
|
|
|
datarate = 65;
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
2022-10-07 20:08:35 +00:00
|
|
|
else if (i == 15)
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
DataRate = StringValue("HtMcs7");
|
|
|
|
|
datarate = 72.2;
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
2022-10-07 20:08:35 +00:00
|
|
|
else if (i == 16)
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
DataRate = StringValue("HtMcs0");
|
|
|
|
|
datarate = 13.5;
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
2022-10-07 20:08:35 +00:00
|
|
|
else if (i == 17)
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
DataRate = StringValue("HtMcs1");
|
|
|
|
|
datarate = 27;
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
2022-10-07 20:08:35 +00:00
|
|
|
else if (i == 18)
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
DataRate = StringValue("HtMcs2");
|
|
|
|
|
datarate = 40.5;
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
2022-10-07 20:08:35 +00:00
|
|
|
else if (i == 19)
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
DataRate = StringValue("HtMcs3");
|
|
|
|
|
datarate = 54;
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
2022-10-07 20:08:35 +00:00
|
|
|
else if (i == 20)
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
DataRate = StringValue("HtMcs4");
|
|
|
|
|
datarate = 81;
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
2022-10-07 20:08:35 +00:00
|
|
|
else if (i == 21)
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
DataRate = StringValue("HtMcs5");
|
|
|
|
|
datarate = 108;
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
2022-10-07 20:08:35 +00:00
|
|
|
else if (i == 22)
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
DataRate = StringValue("HtMcs6");
|
|
|
|
|
datarate = 121.5;
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
2022-10-07 20:08:35 +00:00
|
|
|
else if (i == 23)
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
DataRate = StringValue("HtMcs7");
|
|
|
|
|
datarate = 135;
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
2022-10-07 20:08:35 +00:00
|
|
|
else if (i == 24)
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
DataRate = StringValue("HtMcs0");
|
|
|
|
|
datarate = 15;
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
2022-10-07 20:08:35 +00:00
|
|
|
else if (i == 25)
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
DataRate = StringValue("HtMcs1");
|
|
|
|
|
datarate = 30;
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
2022-10-07 20:08:35 +00:00
|
|
|
else if (i == 26)
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
DataRate = StringValue("HtMcs2");
|
|
|
|
|
datarate = 45;
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
2022-10-07 20:08:35 +00:00
|
|
|
else if (i == 27)
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
DataRate = StringValue("HtMcs3");
|
|
|
|
|
datarate = 60;
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
2022-10-07 20:08:35 +00:00
|
|
|
else if (i == 28)
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
DataRate = StringValue("HtMcs4");
|
|
|
|
|
datarate = 90;
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
2022-10-07 20:08:35 +00:00
|
|
|
else if (i == 29)
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
DataRate = StringValue("HtMcs5");
|
|
|
|
|
datarate = 120;
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
2022-10-07 20:08:35 +00:00
|
|
|
else if (i == 30)
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
DataRate = StringValue("HtMcs6");
|
|
|
|
|
datarate = 135;
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
2022-10-07 20:08:35 +00:00
|
|
|
else
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
DataRate = StringValue("HtMcs7");
|
|
|
|
|
datarate = 150;
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
|
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager",
|
|
|
|
|
"DataMode",
|
|
|
|
|
DataRate,
|
|
|
|
|
"ControlMode",
|
|
|
|
|
DataRate);
|
2016-07-22 18:13:42 -07:00
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
NetDeviceContainer staDevice;
|
|
|
|
|
NetDeviceContainer apDevice;
|
2016-07-22 18:13:42 -07:00
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
if (wifiType == "ns3::YansWifiPhy")
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
mac.SetType("ns3::StaWifiMac", "Ssid", SsidValue(ssid));
|
2024-06-25 11:56:20 +00:00
|
|
|
yansPhy.Set(
|
|
|
|
|
"ChannelSettings",
|
|
|
|
|
StringValue(std::string("{0, ") + (i <= 15 ? "20" : "40") + ", BAND_5GHZ, 0}"));
|
|
|
|
|
staDevice = wifi.Install(yansPhy, mac, wifiStaNode);
|
2022-10-07 20:08:35 +00:00
|
|
|
mac.SetType("ns3::ApWifiMac", "Ssid", SsidValue(ssid));
|
2024-06-25 11:56:20 +00:00
|
|
|
apDevice = wifi.Install(yansPhy, mac, wifiApNode);
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
2022-10-07 20:08:35 +00:00
|
|
|
else if (wifiType == "ns3::SpectrumWifiPhy")
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
mac.SetType("ns3::StaWifiMac", "Ssid", SsidValue(ssid));
|
2024-06-25 11:56:20 +00:00
|
|
|
spectrumPhy.Set(
|
|
|
|
|
"ChannelSettings",
|
|
|
|
|
StringValue(std::string("{0, ") + (i <= 15 ? "20" : "40") + ", BAND_5GHZ, 0}"));
|
2022-10-07 20:08:35 +00:00
|
|
|
staDevice = wifi.Install(spectrumPhy, mac, wifiStaNode);
|
|
|
|
|
mac.SetType("ns3::ApWifiMac", "Ssid", SsidValue(ssid));
|
|
|
|
|
apDevice = wifi.Install(spectrumPhy, mac, wifiApNode);
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
|
|
|
|
|
2024-05-11 02:56:07 +01:00
|
|
|
bool shortGuardIntervalSupported = (i > 7 && i <= 15) || (i > 23);
|
|
|
|
|
Config::Set("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/HtConfiguration/"
|
|
|
|
|
"ShortGuardIntervalSupported",
|
|
|
|
|
BooleanValue(shortGuardIntervalSupported));
|
2018-10-30 13:42:31 +01:00
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
// mobility.
|
|
|
|
|
MobilityHelper mobility;
|
|
|
|
|
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator>();
|
2016-07-22 18:13:42 -07:00
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
positionAlloc->Add(Vector(0.0, 0.0, 0.0));
|
|
|
|
|
positionAlloc->Add(Vector(distance, 0.0, 0.0));
|
|
|
|
|
mobility.SetPositionAllocator(positionAlloc);
|
2016-07-22 18:13:42 -07:00
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
|
2016-07-22 18:13:42 -07:00
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
mobility.Install(wifiApNode);
|
|
|
|
|
mobility.Install(wifiStaNode);
|
2016-07-22 18:13:42 -07:00
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
/* Internet stack*/
|
|
|
|
|
InternetStackHelper stack;
|
|
|
|
|
stack.Install(wifiApNode);
|
|
|
|
|
stack.Install(wifiStaNode);
|
2016-07-22 18:13:42 -07:00
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
Ipv4AddressHelper address;
|
|
|
|
|
address.SetBase("192.168.1.0", "255.255.255.0");
|
|
|
|
|
Ipv4InterfaceContainer staNodeInterface;
|
|
|
|
|
Ipv4InterfaceContainer apNodeInterface;
|
2016-07-22 18:13:42 -07:00
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
staNodeInterface = address.Assign(staDevice);
|
|
|
|
|
apNodeInterface = address.Assign(apDevice);
|
2016-07-22 18:13:42 -07:00
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
/* Setting applications */
|
|
|
|
|
ApplicationContainer serverApp;
|
|
|
|
|
if (udp)
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
// UDP flow
|
|
|
|
|
uint16_t port = 9;
|
|
|
|
|
UdpServerHelper server(port);
|
|
|
|
|
serverApp = server.Install(wifiStaNode.Get(0));
|
2024-11-08 18:01:13 +00:00
|
|
|
serverApp.Start(Seconds(0));
|
|
|
|
|
serverApp.Stop(simulationTime + Seconds(1));
|
2024-03-06 20:50:32 +01:00
|
|
|
const auto packetInterval = payloadSize * 8.0 / (datarate * 1e6);
|
2016-07-22 18:13:42 -07:00
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
UdpClientHelper client(staNodeInterface.GetAddress(0), port);
|
|
|
|
|
client.SetAttribute("MaxPackets", UintegerValue(4294967295U));
|
2024-03-06 20:50:32 +01:00
|
|
|
client.SetAttribute("Interval", TimeValue(Seconds(packetInterval)));
|
2022-10-07 20:08:35 +00:00
|
|
|
client.SetAttribute("PacketSize", UintegerValue(payloadSize));
|
|
|
|
|
ApplicationContainer clientApp = client.Install(wifiApNode.Get(0));
|
2024-11-08 18:01:13 +00:00
|
|
|
clientApp.Start(Seconds(1));
|
|
|
|
|
clientApp.Stop(simulationTime + Seconds(1));
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
2022-10-07 20:08:35 +00:00
|
|
|
else
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
// TCP flow
|
|
|
|
|
uint16_t port = 50000;
|
|
|
|
|
Address localAddress(InetSocketAddress(Ipv4Address::GetAny(), port));
|
|
|
|
|
PacketSinkHelper packetSinkHelper("ns3::TcpSocketFactory", localAddress);
|
|
|
|
|
serverApp = packetSinkHelper.Install(wifiStaNode.Get(0));
|
2024-11-08 18:01:13 +00:00
|
|
|
serverApp.Start(Seconds(0));
|
|
|
|
|
serverApp.Stop(simulationTime + Seconds(1));
|
2016-07-22 18:13:42 -07:00
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
OnOffHelper onoff("ns3::TcpSocketFactory", Ipv4Address::GetAny());
|
|
|
|
|
onoff.SetAttribute("OnTime", StringValue("ns3::ConstantRandomVariable[Constant=1]"));
|
|
|
|
|
onoff.SetAttribute("OffTime", StringValue("ns3::ConstantRandomVariable[Constant=0]"));
|
|
|
|
|
onoff.SetAttribute("PacketSize", UintegerValue(payloadSize));
|
2024-03-06 20:50:32 +01:00
|
|
|
onoff.SetAttribute("DataRate", DataRateValue(datarate * 1e6));
|
2022-10-07 20:08:35 +00:00
|
|
|
AddressValue remoteAddress(InetSocketAddress(staNodeInterface.GetAddress(0), port));
|
|
|
|
|
onoff.SetAttribute("Remote", remoteAddress);
|
|
|
|
|
ApplicationContainer clientApp = onoff.Install(wifiApNode.Get(0));
|
2024-11-08 18:01:13 +00:00
|
|
|
clientApp.Start(Seconds(1));
|
|
|
|
|
clientApp.Stop(simulationTime + Seconds(1));
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
|
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
Config::ConnectWithoutContext("/NodeList/0/DeviceList/*/Phy/MonitorSnifferRx",
|
|
|
|
|
MakeCallback(&MonitorSniffRx));
|
2016-07-22 18:13:42 -07:00
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
if (enablePcap)
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2024-06-25 11:56:20 +00:00
|
|
|
auto& phy = wifiType == "ns3::YansWifiPhy" ? dynamic_cast<WifiPhyHelper&>(yansPhy)
|
|
|
|
|
: dynamic_cast<WifiPhyHelper&>(spectrumPhy);
|
|
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
phy.SetPcapDataLinkType(WifiPhyHelper::DLT_IEEE802_11_RADIO);
|
|
|
|
|
std::stringstream ss;
|
|
|
|
|
ss << "wifi-spectrum-per-example-" << i;
|
|
|
|
|
phy.EnablePcap(ss.str(), apDevice);
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
2024-06-25 11:56:20 +00:00
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
g_signalDbmAvg = 0;
|
|
|
|
|
g_noiseDbmAvg = 0;
|
|
|
|
|
g_samples = 0;
|
2016-07-22 18:13:42 -07:00
|
|
|
|
2024-11-08 18:01:13 +00:00
|
|
|
Simulator::Stop(simulationTime + Seconds(1));
|
2022-10-07 20:08:35 +00:00
|
|
|
Simulator::Run();
|
2016-07-22 18:13:42 -07:00
|
|
|
|
2024-02-27 22:39:01 +01:00
|
|
|
auto throughput = 0.0;
|
2024-07-01 20:20:30 +01:00
|
|
|
uint64_t totalPacketsThrough = 0;
|
2022-10-07 20:08:35 +00:00
|
|
|
if (udp)
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
// UDP
|
|
|
|
|
totalPacketsThrough = DynamicCast<UdpServer>(serverApp.Get(0))->GetReceived();
|
|
|
|
|
throughput =
|
2024-02-27 22:39:01 +01:00
|
|
|
totalPacketsThrough * payloadSize * 8 / simulationTime.GetMicroSeconds(); // Mbit/s
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
2022-10-07 20:08:35 +00:00
|
|
|
else
|
2016-07-22 18:13:42 -07:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
// TCP
|
2024-02-27 22:39:01 +01:00
|
|
|
auto totalBytesRx = DynamicCast<PacketSink>(serverApp.Get(0))->GetTotalRx();
|
2024-07-01 20:20:30 +01:00
|
|
|
totalPacketsThrough = static_cast<uint64_t>(totalBytesRx / tcpPacketSize);
|
2024-02-27 22:39:01 +01:00
|
|
|
throughput = totalBytesRx * 8 / simulationTime.GetMicroSeconds(); // Mbit/s
|
2022-10-07 20:08:35 +00:00
|
|
|
}
|
|
|
|
|
std::cout << std::setw(5) << i << std::setw(6) << (i % 8) << std::setprecision(2)
|
|
|
|
|
<< std::fixed << std::setw(10) << datarate << std::setw(12) << throughput
|
|
|
|
|
<< std::setw(8) << totalPacketsThrough;
|
|
|
|
|
if (totalPacketsThrough > 0)
|
|
|
|
|
{
|
|
|
|
|
std::cout << std::setw(12) << g_signalDbmAvg << std::setw(12) << g_noiseDbmAvg
|
|
|
|
|
<< std::setw(12) << (g_signalDbmAvg - g_noiseDbmAvg) << std::endl;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
std::cout << std::setw(12) << "N/A" << std::setw(12) << "N/A" << std::setw(12) << "N/A"
|
|
|
|
|
<< std::endl;
|
|
|
|
|
}
|
|
|
|
|
Simulator::Destroy();
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|
2022-10-07 20:08:35 +00:00
|
|
|
return 0;
|
2016-07-22 18:13:42 -07:00
|
|
|
}
|