26#include <ns3/core-module.h>
27#include <ns3/gnuplot.h>
28#include <ns3/lr-wpan-module.h>
29#include <ns3/mobility-module.h>
30#include <ns3/network-module.h>
31#include <ns3/propagation-module.h>
32#include <ns3/spectrum-module.h>
53main(
int argc,
char* argv[])
57 std::ostringstream os;
58 std::ofstream perfile(
"802.15.4-per-vs-rxSignal.plt");
60 double minRxSignal = -111;
61 double maxRxSignal = -82;
62 double increment = 0.01;
63 int maxPackets = 1000;
67 double rxSensitivity = -106.58;
71 cmd.AddValue(
"txPower",
"transmit power (dBm)", txPower);
72 cmd.AddValue(
"packetSize",
"packet (MSDU) size (bytes)",
packetSize);
73 cmd.AddValue(
"channelNumber",
"channel number", channelNumber);
74 cmd.AddValue(
"rxSensitivity",
"the rx sensitivity (dBm)", rxSensitivity);
75 cmd.Parse(argc, argv);
91 channel->AddPropagationLossModel(propModel);
92 dev0->SetChannel(channel);
93 dev1->SetChannel(channel);
97 dev0->GetPhy()->SetMobility(mob0);
99 dev1->GetPhy()->SetMobility(mob1);
100 mob0->SetPosition(Vector(0, 0, 0));
101 mob1->SetPosition(Vector(0, 0, 0));
105 dev0->GetPhy()->SetTxPowerSpectralDensity(psd);
108 dev1->GetPhy()->SetRxSensitivity(rxSensitivity);
112 dev1->GetMac()->SetMcpsDataIndicationCallback(cb0);
119 double sensitivityExp = 0;
120 bool sensThreshold =
true;
122 for (
double j = minRxSignal; j < maxRxSignal; j += increment)
124 propModel->SetRss(j);
130 for (
int i = 0; i < maxPackets; i++)
148 std::cout <<
"Experimental Test || Signal: " << j <<
" dBm | Received " <<
g_packetsReceived
150 <<
"/" << maxPackets <<
" | PER " << per <<
" %\n";
152 if (per <= 1 && sensThreshold)
154 sensThreshold =
false;
157 perdatasetExperimental.Add(j, per);
172 double maxRxSensitivityW = (pow(10.0, -106.58 / 10.0) / 1000.0);
173 long double noiseFactor = (pow(10.0, rxSensitivity / 10.0) / 1000.0) / maxRxSensitivityW;
180 double sensitivityTheo = 0;
181 double perTheoretical = 0;
183 sensThreshold =
true;
185 for (
double j = minRxSignal; j < maxRxSignal; j += increment)
192 signal = pow(10.0, j / 10.0) / 1000.0;
193 snr = signal / noise;
198 perTheoretical = (1.0 - lrWpanError->GetChunkSuccessRate(snr, (
packetSize + 13) * 8)) * 100;
199 std::cout <<
"Theoretical Test || Signal: " << j <<
" dBm | SNR: " << snr <<
"| PER "
200 << perTheoretical <<
" % \n";
202 if (perTheoretical <= 1 && sensThreshold)
204 sensThreshold =
false;
207 perdatasetTheoretical.Add(j, perTheoretical);
210 std::cout <<
"_____________________________________________________________________________\n";
211 std::cout <<
"Experimental Test || Receiving with a current sensitivity of " << sensitivityExp
213 std::cout <<
"Theoretical Test || Receiving with a current sensitivity of " << sensitivityTheo
215 std::cout <<
"Gnu plot generated.";
217 os <<
"Pkt Payload (MSDU) size = " <<
packetSize <<
" bytes | "
218 <<
"Tx power = " << txPower <<
" dBm | "
219 <<
"Rx Sensitivity (Theo) = " << sensitivityTheo <<
" dBm";
225 perplot.
SetTerminal(
"postscript eps color enh \"Times-BoldItalic\"");
226 perplot.
SetLegend(
"Rx signal (dBm)",
"Packet Error Rate (%)");
227 perplot.
SetExtra(
"set xrange [-110:-82]\n\
229 set yrange [0.000000000001:120]\n\
232 set style line 1 linewidth 5\n\
233 set style line 2 linewidth 3\n\
234 set style increment user\n\
235 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.
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 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.
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.