37#include <ns3/core-module.h>
38#include <ns3/gnuplot.h>
39#include <ns3/lr-wpan-module.h>
40#include <ns3/mobility-module.h>
41#include <ns3/network-module.h>
42#include <ns3/propagation-module.h>
43#include <ns3/spectrum-module.h>
64main(
int argc,
char* argv[])
68 std::ostringstream os;
69 std::ofstream perfile(
"802.15.4-per-vs-rxSignal.plt");
71 double minRxSignal = -111;
72 double maxRxSignal = -82;
73 double increment = 0.01;
74 int maxPackets = 1000;
78 double rxSensitivity = -106.58;
82 cmd.AddValue(
"txPower",
"transmit power (dBm)", txPower);
83 cmd.AddValue(
"packetSize",
"packet (MSDU) size (bytes)",
packetSize);
84 cmd.AddValue(
"channelNumber",
"channel number", channelNumber);
85 cmd.AddValue(
"rxSensitivity",
"the rx sensitivity (dBm)", rxSensitivity);
86 cmd.Parse(argc, argv);
102 channel->AddPropagationLossModel(propModel);
103 dev0->SetChannel(channel);
104 dev1->SetChannel(channel);
108 dev0->GetPhy()->SetMobility(mob0);
110 dev1->GetPhy()->SetMobility(mob1);
111 mob0->SetPosition(Vector(0, 0, 0));
112 mob1->SetPosition(Vector(0, 0, 0));
116 dev0->GetPhy()->SetTxPowerSpectralDensity(psd);
119 dev1->GetPhy()->SetRxSensitivity(rxSensitivity);
123 dev1->GetMac()->SetMcpsDataIndicationCallback(cb0);
130 double sensitivityExp = 0;
131 bool sensThreshold =
true;
133 for (
double j = minRxSignal; j < maxRxSignal; j += increment)
135 propModel->SetRss(j);
141 for (
int i = 0; i < maxPackets; i++)
159 std::cout <<
"Experimental Test || Signal: " << j <<
" dBm | Received " <<
g_packetsReceived
161 <<
"/" << maxPackets <<
" | PER " << per <<
" %\n";
163 if (per <= 1 && sensThreshold)
165 sensThreshold =
false;
168 perdatasetExperimental.Add(j, per);
183 double maxRxSensitivityW = (pow(10.0, -106.58 / 10.0) / 1000.0);
184 long double noiseFactor = (pow(10.0, rxSensitivity / 10.0) / 1000.0) / maxRxSensitivityW;
191 double sensitivityTheo = 0;
192 double perTheoretical = 0;
194 sensThreshold =
true;
196 for (
double j = minRxSignal; j < maxRxSignal; j += increment)
203 signal = pow(10.0, j / 10.0) / 1000.0;
204 snr = signal / noise;
209 perTheoretical = (1.0 - lrWpanError->GetChunkSuccessRate(snr, (
packetSize + 13) * 8)) * 100;
210 std::cout <<
"Theoretical Test || Signal: " << j <<
" dBm | SNR: " << snr <<
"| PER "
211 << perTheoretical <<
" % \n";
213 if (perTheoretical <= 1 && sensThreshold)
215 sensThreshold =
false;
218 perdatasetTheoretical.Add(j, perTheoretical);
221 std::cout <<
"_____________________________________________________________________________\n";
222 std::cout <<
"Experimental Test || Receiving with a current sensitivity of " << sensitivityExp
224 std::cout <<
"Theoretical Test || Receiving with a current sensitivity of " << sensitivityTheo
226 std::cout <<
"Gnu plot generated.";
228 os <<
"Pkt Payload (MSDU) size = " <<
packetSize <<
" bytes | "
229 <<
"Tx power = " << txPower <<
" dBm | "
230 <<
"Rx Sensitivity (Theo) = " << sensitivityTheo <<
" dBm";
236 perplot.
SetTerminal(
"postscript eps color enh \"Times-BoldItalic\"");
237 perplot.
SetLegend(
"Rx signal (dBm)",
"Packet Error Rate (%)");
238 perplot.
SetExtra(
"set xrange [-110:-82]\n\
240 set yrange [0.000000000001:120]\n\
243 set style line 1 linewidth 5\n\
244 set style line 2 linewidth 3\n\
245 set style increment user\n\
246 set arrow from -110,1 to -82,1 nohead lc 'web-blue' front");
Parse command-line arguments.
Class to represent a 2D points plot.
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
void AddDataset(const GnuplotDataset &dataset)
void SetLegend(const std::string &xLegend, const std::string &yLegend)
void SetTerminal(const std::string &terminal)
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
void SetExtra(const std::string &extra)
void SetTitle(const std::string &title)
This class can contain 16 bit addresses.
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.
void McpsDataRequest(McpsDataRequestParams params, Ptr< Packet > p) override
IEEE 802.15.4-2006, section 7.1.1.1 MCPS-DATA.request Request to transfer a MSDU.
This class defines all functions to create spectrum model for LrWpan.
Ptr< SpectrumValue > CreateNoisePowerSpectralDensity(uint32_t channel)
create spectrum value for noise
static double TotalAvgPower(Ptr< const SpectrumValue > psd, uint32_t channel)
total average power of the signal is the integral of the PSD using the limits of the given channel
Ptr< SpectrumValue > CreateTxPowerSpectralDensity(double txPower, uint32_t channel)
create spectrum value
void SetNoiseFactor(double f)
Set the noise factor added to the thermal noise.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Time Seconds(double value)
Construct a Time in the indicated unit.
uint32_t g_packetsReceived
number of packets received
void PacketReceivedCallback(McpsDataIndicationParams params, Ptr< Packet > p)
Function called when a Data indication is invoked.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
LogLevel
Logging severity classes and levels.
@ LOG_PREFIX_FUNC
Prefix all trace prints with function.
@ LOG_PREFIX_TIME
Prefix all trace prints with simulation time.
@ LOG_PREFIX_NODE
Prefix all trace prints with simulation node.
void LogComponentEnableAll(LogLevel level)
Enable the logging output for all registered log components.
FtrParams params
Fit Fluctuating Two Ray model to the 3GPP TR 38.901 using the Anderson-Darling goodness-of-fit ##.
MCPS-DATA.indication params.
MCPS-DATA.request params.
static const uint32_t packetSize
Packet size generated at the AP.