21 #include "ns3/gnuplot.h"
22 #include "ns3/command-line.h"
23 #include "ns3/string.h"
25 #include "ns3/spectrum-helper.h"
26 #include "ns3/spectrum-wifi-helper.h"
27 #include "ns3/spectrum-analyzer-helper.h"
28 #include "ns3/spectrum-channel.h"
29 #include "ns3/mobility-helper.h"
51 sourceDevice->
Send (pkt, destination, 0);
54 int main (
int argc,
char** argv)
56 std::string standard =
"11a";
61 cmd.AddValue (
"standard",
62 "OFDM-based Wi-Fi standard [11a, 11p_10MHZ, 11p_5MHZ, 11n_2_4GHZ, 11n_5GHZ, 11ac, 11ax_2_4GHZ, 11ax_5GHZ]",
64 cmd.AddValue (
"bw",
"Bandwidth (consistent with standard, in MHz)", bw);
65 cmd.AddValue (
"txPower",
"Transmit power (dBm)", pow);
66 cmd.AddValue (
"verbose",
"Display log messages for WifiSpectrumValueHelper and SpectrumWifiPhy",
verbose);
67 cmd.Parse (argc,argv);
75 if (standard ==
"11a")
79 dataRate =
"OfdmRate6Mbps";
83 std::cout <<
"Bandwidth is not compatible with standard" << std::endl;
87 else if (standard ==
"11p_10MHZ")
91 dataRate =
"OfdmRate3MbpsBW10MHz";
97 std::cout <<
"Bandwidth is not compatible with standard" << std::endl;
101 else if (standard ==
"11p_5MHZ")
105 dataRate =
"OfdmRate1_5MbpsBW5MHz";
111 std::cout <<
"Bandwidth is not compatible with standard" << std::endl;
115 else if (standard ==
"11n_2_4GHZ")
120 freq = 2402 + (bw / 2);
123 if (bw != 20 && bw != 40)
125 std::cout <<
"Bandwidth is not compatible with standard" << std::endl;
129 else if (standard ==
"11n_5GHZ")
134 freq = 5170 + (bw / 2);
136 if (bw != 20 && bw != 40)
138 std::cout <<
"Bandwidth is not compatible with standard" << std::endl;
142 else if (standard ==
"11ac")
146 dataRate =
"VhtMcs0";
147 freq = 5170 + (bw / 2);
150 if (bw != 20 && bw != 40 && bw != 80 && bw != 160)
152 std::cout <<
"Bandwidth is not compatible with standard" << std::endl;
156 else if (standard ==
"11ax_2_4GHZ")
161 freq = 2402 + (bw / 2);
164 if (bw != 20 && bw != 40 && bw != 80)
166 std::cout <<
"Bandwidth is not compatible with standard" << std::endl;
170 else if (standard ==
"11ax_5GHZ")
175 freq = 5170 + (bw / 2);
178 if (bw != 20 && bw != 40 && bw != 80 && bw != 160)
180 std::cout <<
"Bandwidth is not compatible with standard" << std::endl;
186 std::cout <<
"Unknown OFDM standard (please refer to the listed possible values)" << std::endl;
202 spectrumAnalyzerNodes.
Create (1);
203 allNodes.
Add (wifiNodes);
204 allNodes.
Add (spectrumAnalyzerNodes);
208 wifiStaNode.
Add (wifiNodes.
Get (1));
212 channelHelper.
SetChannel (
"ns3::MultiModelSpectrumChannel");
229 wifi.SetRemoteStationManager (
"ns3::ConstantRateWifiManager",
"DataMode",
StringValue (dataRate),
232 mac.SetType (
"ns3::StaWifiMac",
236 mac.SetType (
"ns3::ApWifiMac",
243 nodePositionList->Add (Vector (0.0, 1.0, 0.0));
244 nodePositionList->Add (Vector (1.0, 0.0, 0.0));
245 nodePositionList->Add (Vector (0.0, 0.0, 0.0));
246 mobility.SetPositionAllocator (nodePositionList);
247 mobility.SetMobilityModel (
"ns3::ConstantPositionMobilityModel");
255 std::vector<double> freqs;
257 int band = (bw + margin);
258 for (
int i = 0; i < (4 * 10 * band); ++i)
260 freqs.push_back (i * 1e5 + (freq - 2 * band) * 1e6);
269 std::ostringstream ossFileName;
270 ossFileName <<
"spectrum-analyzer-wifi-" << standard <<
"-" << bw <<
"MHz";
280 ossFileName <<
"-2-0";
281 std::ostringstream ossPlt;
282 ossPlt << ossFileName.str () <<
".plt";
283 std::ofstream plotFile (ossPlt.str ());
284 std::ostringstream ossPng;
285 ossPng << ossFileName.str () <<
".png";
288 std::ostringstream ossExtra;
289 ossExtra <<
"file = '" << ossFileName.str () <<
"'";
303 plot.
AppendExtra (
"set ylabel \"freq (MHz)\" offset 15,0,0");
304 plot.
AppendExtra (
"set zlabel \"PSD (dBW/Hz)\" offset 15,0,0");
310 plot.
AppendExtra (
"set grid ytics mytics ztics mztics");
317 plot.
AppendExtra (
"splot filename using ($1*1000.0):($2/1e6):(10*log10($3/refW))");
324 std::cout <<
"Simulation done!" << std::endl;
325 std::cout <<
"See spectrum analyzer output file: " << ossFileName.str () <<
".tr" << std::endl;
326 std::cout <<
"To generate plot simply execute the following command: gnuplot " << ossFileName.str () <<
".plt" << std::endl;
a polymophic address class
AttributeValue implementation for Boolean.
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.
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)=0
virtual Address GetAddress(void) const =0
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(NodeContainer other)
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.
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static void Run(void)
Run the simulation.
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.
void SetChannel(std::string type, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
void AddSpectrumPropagationLoss(std::string name, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
static SpectrumChannelHelper Default()
Setup a default SpectrumChannel.
Ptr< SpectrumChannel > Create(void) const
Make it easy to create and manage PHY objects for the spectrum model.
void SetChannel(Ptr< SpectrumChannel > channel)
The IEEE 802.11 SSID Information Element.
AttributeValue implementation for Ssid.
Hold variables of type string.
Simulation virtual time values and global simulation resolution.
AttributeValue implementation for Time.
Hold an unsigned integer type.
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.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
@ LOG_LEVEL_ALL
Print everything.
@ LOG_PREFIX_ALL
All prefixes.
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
void LogComponentEnableAll(enum 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...