23 #include "ns3/core-module.h"
24 #include "ns3/wifi-module.h"
25 #include "ns3/mobility-module.h"
26 #include "ns3/spectrum-module.h"
27 #include "ns3/gnuplot.h"
49 sourceDevice->
Send (pkt, destination, 0);
52 int main (
int argc,
char** argv)
54 std::string standard =
"11a";
60 "OFDM-based Wi-Fi standard [11a, 11_10MHZ, 11_5MHZ, 11n_2_4GHZ, 11n_5GHZ, 11ac, 11ax_2_4GHZ, 11ax_5GHZ]",
62 cmd.
AddValue (
"bw",
"Bandwidth (consistent with standard, in MHz)", bw);
63 cmd.
AddValue (
"txPower",
"Transmit power (dBm)", pow);
64 cmd.
AddValue (
"verbose",
"Display log messages for WifiSpectrumValueHelper and SpectrumWifiPhy", verbose);
65 cmd.
Parse (argc,argv);
73 if (standard ==
"11a")
76 ssid =
Ssid (
"ns380211a");
77 dataRate =
"OfdmRate6Mbps";
81 std::cout <<
"Bandwidth is not compatible with standard" << std::endl;
85 else if (standard ==
"11_10MHZ")
88 ssid =
Ssid (
"ns380211_10MHZ");
89 dataRate =
"OfdmRate3MbpsBW10MHz";
95 std::cout <<
"Bandwidth is not compatible with standard" << std::endl;
99 else if (standard ==
"11_5MHZ")
102 ssid =
Ssid (
"ns380211_5MHZ");
103 dataRate =
"OfdmRate1_5MbpsBW5MHz";
109 std::cout <<
"Bandwidth is not compatible with standard" << std::endl;
113 else if (standard ==
"11n_2_4GHZ")
116 ssid =
Ssid (
"ns380211n_2_4GHZ");
118 freq = 2402 + (bw / 2);
121 if (bw != 20 && bw != 40)
123 std::cout <<
"Bandwidth is not compatible with standard" << std::endl;
127 else if (standard ==
"11n_5GHZ")
130 ssid =
Ssid (
"ns380211n_5GHZ");
132 freq = 5170 + (bw / 2);
134 if (bw != 20 && bw != 40)
136 std::cout <<
"Bandwidth is not compatible with standard" << std::endl;
140 else if (standard ==
"11ac")
143 ssid =
Ssid (
"ns380211ac");
144 dataRate =
"VhtMcs0";
145 freq = 5170 + (bw / 2);
148 if (bw != 20 && bw != 40 && bw != 80 && bw != 160)
150 std::cout <<
"Bandwidth is not compatible with standard" << std::endl;
154 else if (standard ==
"11ax_2_4GHZ")
157 ssid =
Ssid (
"ns380211ax_2_4GHZ");
159 freq = 2402 + (bw / 2);
162 if (bw != 20 && bw != 40 && bw != 80)
164 std::cout <<
"Bandwidth is not compatible with standard" << std::endl;
168 else if (standard ==
"11ax_5GHZ")
171 ssid =
Ssid (
"ns380211ax_5GHZ");
173 freq = 5170 + (bw / 2);
176 if (bw != 20 && bw != 40 && bw != 80 && bw != 160)
178 std::cout <<
"Bandwidth is not compatible with standard" << std::endl;
184 std::cout <<
"Unknown OFDM standard (please refer to the listed possible values)" << std::endl;
200 spectrumAnalyzerNodes.
Create (1);
201 allNodes.
Add (wifiNodes);
202 allNodes.
Add (spectrumAnalyzerNodes);
205 wifiApNode.
Add (wifiNodes.
Get (0));
206 wifiStaNode.
Add (wifiNodes.
Get (1));
210 channelHelper.
SetChannel (
"ns3::MultiModelSpectrumChannel");
230 mac.
SetType (
"ns3::StaWifiMac",
241 nodePositionList->
Add (Vector (0.0, 1.0, 0.0));
242 nodePositionList->
Add (Vector (1.0, 0.0, 0.0));
243 nodePositionList->
Add (Vector (0.0, 0.0, 0.0));
253 std::vector<double> freqs;
255 int band = (bw + margin);
256 for (
int i = 0; i < (4 * 10 * band); ++i)
258 freqs.push_back (i * 1e5 + (freq - 2 * band) * 1e6);
265 spectrumAnalyzerHelper.SetRxSpectrumModel (spectrumAnalyzerFreqModel);
267 std::ostringstream ossFileName;
268 ossFileName <<
"spectrum-analyzer-wifi-" << standard <<
"-" << bw <<
"MHz";
269 spectrumAnalyzerHelper.EnableAsciiAll (ossFileName.str ());
270 NetDeviceContainer spectrumAnalyzerDevices = spectrumAnalyzerHelper.Install (spectrumAnalyzerNodes);
278 ossFileName <<
"-2-0";
279 std::ostringstream ossPlt;
280 ossPlt << ossFileName.str () <<
".plt";
281 std::ofstream plotFile (ossPlt.str ());
282 std::ostringstream ossPng;
283 ossPng << ossFileName.str () <<
".png";
286 std::ostringstream ossExtra;
287 ossExtra <<
"file = '" << ossFileName.str () <<
"'";
301 plot.
AppendExtra (
"set ylabel \"freq (MHz)\" offset 15,0,0");
302 plot.
AppendExtra (
"set zlabel \"PSD (dBW/Hz)\" offset 15,0,0");
308 plot.
AppendExtra (
"set grid ytics mytics ztics mztics");
315 plot.
AppendExtra (
"splot filename using ($1*1000.0):($2/1e6):(10*log10($3/refW))");
322 std::cout <<
"Simulation done!" << std::endl;
323 std::cout <<
"See spectrum analyzer output file: " << ossFileName.str () <<
".tr" << std::endl;
324 std::cout <<
"To generate plot simply execute the following command: gnuplot " << ossFileName.str () <<
".plt" << std::endl;
Class to allow the Spectrum Analysis.
void Set(std::string name, const AttributeValue &v)
void AppendExtra(const std::string &extra)
Simulation virtual time values and global simulation resolution.
Smart pointer class similar to boost::intrusive_ptr.
OFDM PHY for the 5 GHz band (Clause 17 with 5 MHz channel bandwidth)
AttributeValue implementation for Boolean.
HT PHY for the 5 GHz band (clause 20)
void SetRemoteStationManager(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())
Hold variables of type string.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
static void Run(void)
Run the simulation.
Ptr< SpectrumChannel > Create(void) const
HE PHY for the 2.4 GHz band (clause 26)
OFDM PHY for the 5 GHz band (Clause 17 with 10 MHz channel bandwidth)
HT PHY for the 2.4 GHz band (clause 20)
helps to create WifiNetDevice objects
a polymophic address class
virtual void SetStandard(WifiPhyStandard standard)
HE PHY for the 5 GHz band (clause 26)
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
static SpectrumWifiPhyHelper Default(void)
Create a phy helper in a default working state.
AttributeValue implementation for Time.
void SetChannel(Ptr< SpectrumChannel > channel)
Hold an unsigned integer type.
holds a vector of ns3::NetDevice pointers
virtual NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer::Iterator first, NodeContainer::Iterator last) const
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
Parse command-line arguments.
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
void LogComponentEnableAll(enum LogLevel level)
Enable the logging output for all registered log components.
OFDM PHY for the 5 GHz band (Clause 17)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
void SetMobilityModel(std::string type, 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(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue())
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)=0
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())
create MAC layers for a ns3::WifiNetDevice.
void SetErrorRateModel(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())
void SetExtra(const std::string &extra)
The IEEE 802.11 SSID Information Element.
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())
void SendPacket(Ptr< NetDevice > sourceDevice, Address &destination)
This example (inspired from tv-trans-example) enables to generate the transmitted spectra of Wi-Fi st...
virtual void SetType(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(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue(), std::string n10="", const AttributeValue &v10=EmptyAttributeValue())
Helper class used to assign positions and mobility models to nodes.
static SpectrumChannelHelper Default()
Setup a default SpectrumChannel.
void Add(NodeContainer other)
Append the contents of another NodeContainer to the end of this container.
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
AttributeValue implementation for Ssid.
void Add(Vector v)
Add a position to the list of positions.
void SetChannel(Ptr< SpectrumChannel > channel)
Set the SpectrumChannel that will be used by SpectrumPhy instances created by this helper...
void Parse(int argc, char *argv[])
Parse the program arguments.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Make it easy to create and manage PHY objects for the spectrum model.