9#include "ns3/command-line.h"
10#include "ns3/gnuplot.h"
11#include "ns3/mobility-helper.h"
12#include "ns3/spectrum-analyzer-helper.h"
13#include "ns3/spectrum-channel.h"
14#include "ns3/spectrum-helper.h"
15#include "ns3/spectrum-wifi-helper.h"
17#include "ns3/string.h"
39 sourceDevice->Send(pkt, destination, 0);
43main(
int argc,
char** argv)
45 std::string standardStr =
"11a";
50 cmd.AddValue(
"standard",
51 "OFDM-based Wi-Fi standard [11a, 11p_10MHZ, 11p_5MHZ, 11n_2_4GHZ, 11n_5GHZ, 11ac, "
52 "11ax_2_4GHZ, 11ax_5GHZ]",
54 cmd.AddValue(
"bw",
"Bandwidth (consistent with standard, in MHz)", bw);
55 cmd.AddValue(
"txPower",
"Transmit power (dBm)", pow);
56 cmd.AddValue(
"verbose",
57 "Display log messages for WifiSpectrumValueHelper and SpectrumWifiPhy",
59 cmd.Parse(argc, argv);
69 WifiStandard standard{WifiStandard::WIFI_STANDARD_UNSPECIFIED};
71 std::string channelBand;
72 if (standardStr ==
"11a")
76 channelBand =
"BAND_5GHZ";
78 dataRate =
"OfdmRate6Mbps";
82 std::cout <<
"Bandwidth is not compatible with standard" << std::endl;
86 else if (standardStr ==
"11p_10MHZ")
90 channelBand =
"BAND_5GHZ";
92 dataRate =
"OfdmRate3MbpsBW10MHz";
98 std::cout <<
"Bandwidth is not compatible with standard" << std::endl;
102 else if (standardStr ==
"11p_5MHZ")
106 channelBand =
"BAND_5GHZ";
108 dataRate =
"OfdmRate1_5MbpsBW5MHz";
114 std::cout <<
"Bandwidth is not compatible with standard" << std::endl;
118 else if (standardStr ==
"11n_2_4GHZ")
122 channelBand =
"BAND_2_4GHZ";
125 freq = 2402 + (bw / 2);
128 if (bw != 20 && bw != 40)
130 std::cout <<
"Bandwidth is not compatible with standard" << std::endl;
134 else if (standardStr ==
"11n_5GHZ")
138 channelBand =
"BAND_5GHZ";
141 freq = 5170 + (bw / 2);
143 if (bw != 20 && bw != 40)
145 std::cout <<
"Bandwidth is not compatible with standard" << std::endl;
149 else if (standardStr ==
"11ac")
153 channelBand =
"BAND_5GHZ";
155 dataRate =
"VhtMcs0";
156 freq = 5170 + (bw / 2);
159 if (bw != 20 && bw != 40 && bw != 80 && bw != 160)
161 std::cout <<
"Bandwidth is not compatible with standard" << std::endl;
165 else if (standardStr ==
"11ax_2_4GHZ")
169 channelBand =
"BAND_2_4GHZ";
172 freq = 2402 + (bw / 2);
175 if (bw != 20 && bw != 40 && bw != 80)
177 std::cout <<
"Bandwidth is not compatible with standard" << std::endl;
181 else if (standardStr ==
"11ax_5GHZ")
185 channelBand =
"BAND_5GHZ";
188 freq = 5170 + (bw / 2);
191 if (bw != 20 && bw != 40 && bw != 80 && bw != 160)
193 std::cout <<
"Bandwidth is not compatible with standard" << std::endl;
199 std::cout <<
"Unknown OFDM standard (please refer to the listed possible values)"
216 spectrumAnalyzerNodes.
Create(1);
217 allNodes.
Add(wifiNodes);
218 allNodes.
Add(spectrumAnalyzerNodes);
222 wifiStaNode.
Add(wifiNodes.
Get(1));
226 channelHelper.
SetChannel(
"ns3::MultiModelSpectrumChannel");
240 std::ostringstream channelSettings;
241 channelSettings <<
"{" << +channelNumber <<
", " << bw <<
", " << channelBand <<
", 0}";
242 spectrumPhy.
Set(
"ChannelSettings",
StringValue(channelSettings.str()));
245 wifi.SetStandard(standard);
246 wifi.SetRemoteStationManager(
"ns3::ConstantRateWifiManager",
254 mac.SetType(
"ns3::ApWifiMac",
257 "EnableBeaconJitter",
263 nodePositionList->Add(Vector(0.0, 1.0, 0.0));
264 nodePositionList->Add(Vector(1.0, 0.0, 0.0));
265 nodePositionList->Add(Vector(0.0, 0.0, 0.0));
266 mobility.SetPositionAllocator(nodePositionList);
267 mobility.SetMobilityModel(
"ns3::ConstantPositionMobilityModel");
277 staDevice.
Get(0)->GetAddress());
280 std::vector<double> freqs;
282 int band = (bw + margin);
283 freqs.reserve(4 * 10 * band);
284 for (
int i = 0; i < (4 * 10 * band); ++i)
286 freqs.push_back(i * 1e5 + (freq - 2 * band) * 1e6);
298 std::ostringstream ossFileName;
299 ossFileName <<
"spectrum-analyzer-wifi-" << standardStr <<
"-" << bw <<
"MHz";
302 spectrumAnalyzerHelper.
Install(spectrumAnalyzerNodes);
311 ossFileName <<
"-2-0";
312 std::ostringstream ossPlt;
313 ossPlt << ossFileName.str() <<
".plt";
314 std::ofstream plotFile(ossPlt.str());
315 std::ostringstream ossPng;
316 ossPng << ossFileName.str() <<
".png";
319 std::ostringstream ossExtra;
320 ossExtra <<
"file = '" << ossFileName.str() <<
"'";
334 plot.
AppendExtra(
"set ylabel \"freq (MHz)\" offset 15,0,0");
335 plot.
AppendExtra(
"set zlabel \"PSD (dBW/Hz)\" offset 15,0,0");
341 plot.
AppendExtra(
"set grid ytics mytics ztics mztics");
348 plot.
AppendExtra(
"splot filename using ($1*1000.0):($2/1e6):(10*log10($3/refW))");
355 std::cout <<
"Simulation done!" << std::endl;
356 std::cout <<
"See spectrum analyzer output file: " << ossFileName.str() <<
".tr" << std::endl;
357 std::cout <<
"To generate plot simply execute the following command: gnuplot "
358 << ossFileName.str() <<
".plt" << std::endl;
a polymophic address class
Parse command-line arguments.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
void AppendExtra(const std::string &extra)
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
void SetExtra(const std::string &extra)
Helper class used to assign positions and mobility models to nodes.
holds a vector of ns3::NetDevice pointers
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
void Add(const NodeContainer &nc)
Append the contents of another NodeContainer to the end of this container.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static void Run()
Run the simulation.
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Class to allow the Spectrum Analysis.
NetDeviceContainer Install(NodeContainer c) const
void SetPhyAttribute(std::string name, const AttributeValue &v)
void SetChannel(Ptr< SpectrumChannel > channel)
Set the SpectrumChannel that will be used by SpectrumPhy instances created by this helper.
void EnableAsciiAll(std::string prefix)
Enable ASCII output.
void SetRxSpectrumModel(Ptr< SpectrumModel > m)
Set the spectrum model used by the created SpectrumAnalyzer instances to represent incoming signals.
Ptr< SpectrumChannel > Create() const
static SpectrumChannelHelper Default()
Setup a default SpectrumChannel.
void AddSpectrumPropagationLoss(std::string name, Ts &&... args)
void SetChannel(std::string type, Ts &&... args)
Make it easy to create and manage PHY objects for the spectrum model.
void SetChannel(const Ptr< SpectrumChannel > channel)
The IEEE 802.11 SSID Information Element.
Hold variables of type string.
Simulation virtual time values and global simulation resolution.
helps to create WifiNetDevice objects
create MAC layers for a ns3::WifiNetDevice.
void Set(std::string name, const AttributeValue &v)
void SetErrorRateModel(std::string type, Args &&... args)
Helper function used to set the error rate model.
static ConstIterator FindFirst(uint8_t number, MHz_u frequency, MHz_u width, WifiStandard standard, WifiPhyBand band, ConstIterator start=m_frequencyChannels.begin())
Find the first frequency segment matching the specified parameters.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
WifiStandard
Identifies the IEEE 802.11 specifications that a Wifi device can be configured to use.
WifiPhyBand
Identifies the PHY band.
@ WIFI_PHY_BAND_UNSPECIFIED
Unspecified.
@ WIFI_PHY_BAND_2_4GHZ
The 2.4 GHz band.
@ WIFI_PHY_BAND_5GHZ
The 5 GHz band.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void LogComponentEnable(const std::string &name, LogLevel level)
Enable the logging output associated with that log component.
@ LOG_LEVEL_ALL
Print everything.
@ LOG_PREFIX_ALL
All prefixes.
void LogComponentEnableAll(LogLevel level)
Enable the logging output for all registered log components.
void SendPacket(Ptr< NetDevice > sourceDevice, Address &destination)
This example (inspired from tv-trans-example) enables to generate the transmitted spectra of Wi-Fi st...