21 #include "ns3/propagation-loss-model.h"
22 #include "ns3/jakes-propagation-loss-model.h"
23 #include "ns3/constant-position-mobility-model.h"
25 #include "ns3/config.h"
26 #include "ns3/command-line.h"
27 #include "ns3/string.h"
28 #include "ns3/boolean.h"
29 #include "ns3/double.h"
30 #include "ns3/pointer.h"
31 #include "ns3/gnuplot.h"
32 #include "ns3/simulator.h"
40 static double dround (
double number,
double precision)
45 number = floor (number + 0.5);
49 number = ceil (number - 0.5);
67 double txPowerDbm = +20;
74 a->SetPosition (Vector (0.0, 0.0, 0.0));
76 for (
double distance = 0.0; distance < 2500.0; distance += 10.0)
78 b->SetPosition (Vector (distance, 0.0, 0.0));
81 double rxPowerDbm = model->
CalcRxPower (txPowerDbm, a, b);
83 dataset.
Add (distance, rxPowerDbm);
90 std::ostringstream os;
91 os <<
"txPower " << txPowerDbm <<
"dBm";
111 plot.
AppendExtra (
"set zlabel 'Probability' offset 0,+10");
120 double txPowerDbm = +20;
124 dataset.
SetStyle (
"with linespoints");
125 dataset.
SetExtra (
"pointtype 3 pointsize 0.5");
127 typedef std::map<double, unsigned int> rxPowerMapType;
132 a->SetPosition (Vector (0.0, 0.0, 0.0));
134 for (
double distance = 100.0; distance < 2500.0; distance += 100.0)
136 b->SetPosition (Vector (distance, 0.0, 0.0));
138 rxPowerMapType rxPowerMap;
140 for (
unsigned int samp = 0; samp < samples; ++samp)
143 double rxPowerDbm = model->
CalcRxPower (txPowerDbm, a, b);
144 rxPowerDbm =
dround (rxPowerDbm, 1.0);
146 rxPowerMap[ rxPowerDbm ]++;
152 for (rxPowerMapType::const_iterator i = rxPowerMap.begin ();
153 i != rxPowerMap.end (); ++i)
155 dataset.
Add (distance, i->first, (
double)i->second / (
double)samples);
161 std::ostringstream os;
162 os <<
"txPower " << txPowerDbm <<
"dBm";
174 double distance = 100.0)
185 double txPowerDbm = +20;
192 a->SetPosition (Vector (0.0, 0.0, 0.0));
193 b->SetPosition (Vector (distance, 0.0, 0.0));
199 double rxPowerDbm = model->
CalcRxPower (txPowerDbm, a, b);
209 std::ostringstream os;
210 os <<
"txPower " << txPowerDbm <<
"dBm";
220 int main (
int argc,
char *argv[])
223 cmd.Parse (argc, argv);
231 plot.
SetTitle (
"ns3::FriisPropagationLossModel (Default Parameters)");
232 gnuplots.AddPlot (plot);
240 plot.
SetTitle (
"ns3::LogDistancePropagationLossModel (Exponent = 2.5)");
241 gnuplots.AddPlot (plot);
247 random->SetAttribute (
"Variable",
PointerValue (expVar));
250 plot.
SetTitle (
"ns3::RandomPropagationLossModel with Exponential Distribution");
251 gnuplots.AddPlot (plot);
261 plot.
SetTitle (
"ns3::JakesPropagationLossModel (with 477.9 Hz shift and 1 millisec resolution)");
262 gnuplots.AddPlot (plot);
272 plot.
SetTitle (
"ns3::JakesPropagationLossModel (with 477.9 Hz shift and 0.1 millisec resolution)");
273 gnuplots.AddPlot (plot);
280 plot.
SetTitle (
"ns3::ThreeLogDistancePropagationLossModel (Defaults)");
281 gnuplots.AddPlot (plot);
287 log3->SetAttribute (
"Exponent0",
DoubleValue (1.0));
288 log3->SetAttribute (
"Exponent1",
DoubleValue (3.0));
289 log3->SetAttribute (
"Exponent2",
DoubleValue (10.0));
292 plot.
SetTitle (
"ns3::ThreeLogDistancePropagationLossModel (Exponents 1.0, 3.0 and 10.0)");
293 gnuplots.AddPlot (plot);
300 plot.
SetTitle (
"ns3::NakagamiPropagationLossModel (Default Parameters)");
301 gnuplots.AddPlot (plot);
311 plot.
SetTitle (
"ns3::ThreeLogDistancePropagationLossModel and ns3::NakagamiPropagationLossModel (Default Parameters)");
312 gnuplots.AddPlot (plot);
315 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(enum 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)
Hold objects of type Ptr<T>.
double CalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
Returns the Rx Power taking into account all the PropagationLossModel(s) chained to the current one.
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
static void Run(void)
Run the simulation.
static Time Now(void)
Return the current simulation virtual time.
Simulation virtual time values and global simulation resolution.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
void SetDefault(std::string name, const AttributeValue &value)
Time Seconds(double value)
Construct a Time in the indicated unit.
static Gnuplot TestDeterministicByTime(Ptr< PropagationLossModel > model, Time timeStep=Seconds(0.001), Time timeTotal=Seconds(1.0), double distance=100.0)
static Gnuplot TestProbabilistic(Ptr< PropagationLossModel > model, unsigned int samples=100000)
static Gnuplot TestDeterministic(Ptr< PropagationLossModel > model)
static double dround(double number, double precision)
Round a double number to the given precision.
Every class exported by the ns3 library is enclosed in the ns3 namespace.