9#include "ns3/boolean.h" 
   10#include "ns3/command-line.h" 
   11#include "ns3/config.h" 
   12#include "ns3/constant-position-mobility-model.h" 
   13#include "ns3/double.h" 
   14#include "ns3/gnuplot.h" 
   15#include "ns3/jakes-propagation-loss-model.h" 
   16#include "ns3/pointer.h" 
   17#include "ns3/propagation-loss-model.h" 
   18#include "ns3/simulator.h" 
   19#include "ns3/string.h" 
   34dround(
double number, 
double precision)
 
   39        number = floor(number + 0.5);
 
   43        number = ceil(number - 0.5);
 
 
   69    double txPowerDbm = +20; 
 
   76        a->SetPosition(Vector(0.0, 0.0, 0.0));
 
   78        for (
double distance = 0.0; distance < targetDistance; distance += step)
 
   80            b->SetPosition(Vector(distance, 0.0, 0.0));
 
   83            double rxPowerDbm = model->CalcRxPower(txPowerDbm, a, b);
 
   85            dataset.
Add(distance, rxPowerDbm);
 
   92    std::ostringstream os;
 
   93    os << 
"txPower " << txPowerDbm << 
"dBm";
 
 
  114                  double targetDistance,
 
  116                  unsigned int samples)
 
  125    plot.
AppendExtra(
"set zlabel 'Probability' offset 0,+10");
 
  134    double txPowerDbm = +20; 
 
  138    dataset.
SetStyle(
"with linespoints");
 
  139    dataset.
SetExtra(
"pointtype 3 pointsize 0.5");
 
  141    typedef std::map<double, unsigned int> rxPowerMapType;
 
  146        a->SetPosition(Vector(0.0, 0.0, 0.0));
 
  148        for (
double distance = 100.0; distance < targetDistance; distance += step)
 
  150            b->SetPosition(Vector(distance, 0.0, 0.0));
 
  152            rxPowerMapType rxPowerMap;
 
  154            for (
unsigned int samp = 0; samp < samples; ++samp)
 
  157                double rxPowerDbm = model->CalcRxPower(txPowerDbm, a, b);
 
  158                rxPowerDbm = 
dround(rxPowerDbm, 1.0);
 
  160                rxPowerMap[rxPowerDbm]++;
 
  166            for (
auto i = rxPowerMap.begin(); i != rxPowerMap.end(); ++i)
 
  168                dataset.
Add(distance, i->first, (
double)i->second / (
double)samples);
 
  174    std::ostringstream os;
 
  175    os << 
"txPower " << txPowerDbm << 
"dBm";
 
 
  207    double txPowerDbm = +20; 
 
  214        a->SetPosition(Vector(0.0, 0.0, 0.0));
 
  215        b->SetPosition(Vector(distance, 0.0, 0.0));
 
  221            double rxPowerDbm = model->CalcRxPower(txPowerDbm, a, b);
 
  231    std::ostringstream os;
 
  232    os << 
"txPower " << txPowerDbm << 
"dBm";
 
 
  243main(
int argc, 
char* argv[])
 
  247    cmd.AddValue(
"test", 
"Run as a test, sample the models only once", 
test);
 
  248    cmd.Parse(argc, argv);
 
  250    double testDeterministicDistance = 2500.0;
 
  251    double testProbabilisticDistance = 2500.0;
 
  252    unsigned int testProbabilisticSamples = 100000;
 
  258        testDeterministicDistance = 10;
 
  259        testProbabilisticDistance = 200;
 
  260        testProbabilisticSamples = 1;
 
  261        testJakesTimeOneMsRes = 
Seconds(0.001);
 
  262        testJakesTimeZeroDotOneMsRes = 
Seconds(0.0001);
 
  271        plot.
SetTitle(
"ns3::FriisPropagationLossModel (Default Parameters)");
 
  272        gnuplots.AddPlot(plot);
 
  280        plot.
SetTitle(
"ns3::LogDistancePropagationLossModel (Exponent = 2.5)");
 
  281        gnuplots.AddPlot(plot);
 
  291        plot.
SetTitle(
"ns3::RandomPropagationLossModel with Exponential Distribution");
 
  292        gnuplots.AddPlot(plot);
 
  303            "ns3::JakesPropagationLossModel (with 477.9 Hz shift and 1 millisec resolution)");
 
  304        gnuplots.AddPlot(plot);
 
  320            "ns3::JakesPropagationLossModel (with 477.9 Hz shift and 0.1 millisec resolution)");
 
  321        gnuplots.AddPlot(plot);
 
  333        plot.
SetTitle(
"ns3::ThreeLogDistancePropagationLossModel (Defaults)");
 
  334        gnuplots.AddPlot(plot);
 
  343        log3->SetAttribute(
"Exponent2", 
DoubleValue(10.0));
 
  346        plot.
SetTitle(
"ns3::ThreeLogDistancePropagationLossModel (Exponents 1.0, 3.0 and 10.0)");
 
  347        gnuplots.AddPlot(plot);
 
  354            TestProbabilistic(nak, testProbabilisticDistance, 100.0, testProbabilisticSamples);
 
  355        plot.
SetTitle(
"ns3::NakagamiPropagationLossModel (Default Parameters)");
 
  356        gnuplots.AddPlot(plot);
 
  367            TestProbabilistic(log3, testProbabilisticDistance, 100.0, testProbabilisticSamples);
 
  368        plot.
SetTitle(
"ns3::ThreeLogDistancePropagationLossModel and " 
  369                      "ns3::NakagamiPropagationLossModel (Default Parameters)");
 
  370        gnuplots.AddPlot(plot);
 
  373    gnuplots.GenerateOutput(std::cout);
 
Parse command-line arguments.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Class to represent a 2D points plot.
void SetStyle(Style style)
void Add(double x, double y)
Class to represent a 2D function expression plot.
Class to represent a 3D points plot.
void AddEmptyLine()
Add an empty line in the data output sequence.
void Add(double x, double y, double z)
void SetStyle(const std::string &style)
a simple class to group together multiple gnuplots into one file, e.g.
void SetExtra(const std::string &extra)
Add extra formatting parameters to this dataset.
void SetTitle(const std::string &title)
Change line title.
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
void AddDataset(const GnuplotDataset &dataset)
void AppendExtra(const std::string &extra)
void SetTitle(const std::string &title)
AttributeValue implementation for Pointer.
Smart pointer class similar to boost::intrusive_ptr.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static Time Now()
Return the current simulation virtual time.
static void Run()
Run the simulation.
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Simulation virtual time values and global simulation resolution.
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
void SetDefault(std::string name, const AttributeValue &value)
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Ptr< T > CreateObjectWithAttributes(Args... args)
Allocate an Object on the heap and initialize with a set of attributes.
Time Seconds(double value)
Construct a Time in the indicated unit.
static double dround(double number, double precision)
Round a double number to the given precision.
static Gnuplot TestDeterministicByTime(Ptr< PropagationLossModel > model, Time timeStep, Time timeTotal, double distance)
Test the model by sampling over time.
static Gnuplot TestDeterministic(Ptr< PropagationLossModel > model, double targetDistance, double step)
Test the model by sampling over a distance.
static Gnuplot TestProbabilistic(Ptr< PropagationLossModel > model, double targetDistance, double step, unsigned int samples)
Test the model by sampling over a distance.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
-ns3 Test suite for the ns3 wrapper script