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> 
   63main(
int argc, 
char* argv[])
 
   67    std::ostringstream os;
 
   68    std::ofstream perfile(
"802.15.4-per-vs-rxSignal.plt");
 
   70    double minRxSignal = -111; 
 
   71    double maxRxSignal = -82;  
 
   72    double increment = 0.01;
 
   73    int maxPackets = 1000;
 
   77    double rxSensitivity = -106.58; 
 
   81    cmd.AddValue(
"txPower", 
"transmit power (dBm)", txPower);
 
   82    cmd.AddValue(
"packetSize", 
"packet (MSDU) size (bytes)", 
packetSize);
 
   83    cmd.AddValue(
"channelNumber", 
"channel number", channelNumber);
 
   84    cmd.AddValue(
"rxSensitivity", 
"the rx sensitivity (dBm)", rxSensitivity);
 
   85    cmd.Parse(argc, argv);
 
  101    channel->AddPropagationLossModel(propModel);
 
  102    dev0->SetChannel(channel);
 
  103    dev1->SetChannel(channel);
 
  107    dev0->GetPhy()->SetMobility(mob0);
 
  109    dev1->GetPhy()->SetMobility(mob1);
 
  110    mob0->SetPosition(Vector(0, 0, 0));
 
  111    mob1->SetPosition(Vector(0, 0, 0));
 
  115    dev0->GetPhy()->SetTxPowerSpectralDensity(psd);
 
  118    dev1->GetPhy()->SetRxSensitivity(rxSensitivity);
 
  122    dev1->GetMac()->SetMcpsDataIndicationCallback(cb0);
 
  129    double sensitivityExp = 0;
 
  130    bool sensThreshold = 
true;
 
  132    for (
double j = minRxSignal; j < maxRxSignal; j += increment)
 
  134        propModel->SetRss(j);
 
  140        for (
int i = 0; i < maxPackets; i++)
 
  158        std::cout << 
"Experimental Test || Signal: " << j << 
" dBm | Received " << 
g_packetsReceived 
  160                  << 
"/" << maxPackets << 
" | PER " << per << 
" %\n";
 
  162        if (per <= 1 && sensThreshold)
 
  164            sensThreshold = 
false;
 
  167        perdatasetExperimental.Add(j, per);
 
  182    double maxRxSensitivityW = (pow(10.0, -106.58 / 10.0) / 1000.0);
 
  183    long double noiseFactor = (pow(10.0, rxSensitivity / 10.0) / 1000.0) / maxRxSensitivityW;
 
  190    double sensitivityTheo = 0;
 
  191    double perTheoretical = 0;
 
  193    sensThreshold = 
true;
 
  195    for (
double j = minRxSignal; j < maxRxSignal; j += increment)
 
  202        signal = pow(10.0, j / 10.0) / 1000.0; 
 
  203        snr = signal / noise;
 
  208        perTheoretical = (1.0 - lrWpanError->GetChunkSuccessRate(snr, (
packetSize + 13) * 8)) * 100;
 
  209        std::cout << 
"Theoretical Test || Signal: " << j << 
" dBm | SNR: " << snr << 
"| PER " 
  210                  << perTheoretical << 
" % \n";
 
  212        if (perTheoretical <= 1 && sensThreshold)
 
  214            sensThreshold = 
false;
 
  217        perdatasetTheorical.Add(j, perTheoretical);
 
  220    std::cout << 
"_____________________________________________________________________________\n";
 
  221    std::cout << 
"Experimental Test || Receiving with a current sensitivity of " << sensitivityExp
 
  223    std::cout << 
"Theoretical Test  || Receiving with a current sensitivity of " << sensitivityTheo
 
  225    std::cout << 
"Gnu plot generated.";
 
  227    os << 
"Pkt Payload (MSDU) size = " << 
packetSize << 
" bytes | " 
  228       << 
"Tx power = " << txPower << 
" dBm | " 
  229       << 
"Rx Sensitivity (Theo) = " << sensitivityTheo << 
" dBm";
 
  235    perplot.
SetTerminal(
"postscript eps color enh \"Times-BoldItalic\"");
 
  236    perplot.
SetLegend(
"Rx signal (dBm)", 
"Packet Error Rate (%)");
 
  237    perplot.
SetExtra(
"set xrange [-110:-82]\n\ 
  239                      set yrange [0.000000000001:120]\n\ 
  242                      set style line 1 linewidth 5\n\ 
  243                      set style line 2 linewidth 3\n\ 
  244                      set style increment user\n\ 
  245                      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)
void McpsDataRequest(McpsDataRequestParams params, Ptr< Packet > p)
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.
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.
#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.