A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lr-wpan-error-distance-plot.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 The Boeing Company
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Tom Henderson <thomas.r.henderson@boeing.com>
18 */
19
20/*
21 This program produces a gnuplot file that plots the packet success rate
22 as a function of distance for the 802.15.4 models, assuming a default
23 LogDistance propagation loss model, the 2.4 GHz OQPSK error model, a
24 default transmit power of 0 dBm, and a default packet size of 20 bytes of
25 802.15.4 payload and a default rx sensitivity of -106.58 dBm.
26
27 Tx power of the transmitter node and the Rx sensitivity of the receiving node
28 as well as the transmitted packet size can be adjusted to obtain a different
29 distance plot.
30
31 Node1 Node2
32 (dev0) --------------------->(dev1)
33
34 Usage:
35
36 ./ns3 run "lr-wpan-error-distance-plot --txPower= 0 --rxSensitivity=-92"
37
38*/
39#include <ns3/abort.h>
40#include <ns3/callback.h>
41#include <ns3/command-line.h>
42#include <ns3/constant-position-mobility-model.h>
43#include <ns3/gnuplot.h>
44#include <ns3/log.h>
45#include <ns3/lr-wpan-error-model.h>
46#include <ns3/lr-wpan-mac.h>
47#include <ns3/lr-wpan-net-device.h>
48#include <ns3/lr-wpan-spectrum-value-helper.h>
49#include <ns3/mac16-address.h>
50#include <ns3/multi-model-spectrum-channel.h>
51#include <ns3/net-device.h>
52#include <ns3/node.h>
53#include <ns3/nstime.h>
54#include <ns3/packet.h>
55#include <ns3/propagation-loss-model.h>
56#include <ns3/simulator.h>
57#include <ns3/single-model-spectrum-channel.h>
58#include <ns3/spectrum-value.h>
59#include <ns3/test.h>
60#include <ns3/uinteger.h>
61
62#include <fstream>
63#include <iostream>
64#include <string>
65#include <vector>
66
67using namespace ns3;
68
70
71NS_LOG_COMPONENT_DEFINE("LrWpanErrorDistancePlot");
72
78void
80{
82}
83
84int
85main(int argc, char* argv[])
86{
87 std::ostringstream os;
88 std::ofstream berfile("802.15.4-psr-distance.plt");
89
90 int minDistance = 1;
91 int maxDistance = 200; // meters
92 int increment = 1;
93 int maxPackets = 1000;
94 int packetSize = 7; // PSDU = 20 bytes (11 bytes MAC header + 7 bytes MSDU )
95 double txPower = 0;
96 uint32_t channelNumber = 11;
97 double rxSensitivity = -106.58; // dBm
98
99 CommandLine cmd(__FILE__);
100
101 cmd.AddValue("txPower", "transmit power (dBm)", txPower);
102 cmd.AddValue("packetSize", "packet (MSDU) size (bytes)", packetSize);
103 cmd.AddValue("channelNumber", "channel number", channelNumber);
104 cmd.AddValue("rxSensitivity", "the rx sensitivity (dBm)", rxSensitivity);
105
106 cmd.Parse(argc, argv);
107
108 os << "Packet (MSDU) size = " << packetSize << " bytes; tx power = " << txPower
109 << " dBm; channel = " << channelNumber << "; Rx sensitivity = " << rxSensitivity << " dBm";
110
111 Gnuplot psrplot = Gnuplot("802.15.4-psr-distance.eps");
112 Gnuplot2dDataset psrdataset("802.15.4-psr-vs-distance");
113
114 Ptr<Node> n0 = CreateObject<Node>();
115 Ptr<Node> n1 = CreateObject<Node>();
116 Ptr<LrWpanNetDevice> dev0 = CreateObject<LrWpanNetDevice>();
117 Ptr<LrWpanNetDevice> dev1 = CreateObject<LrWpanNetDevice>();
118 dev0->SetAddress(Mac16Address("00:01"));
119 dev1->SetAddress(Mac16Address("00:02"));
120 Ptr<MultiModelSpectrumChannel> channel = CreateObject<MultiModelSpectrumChannel>();
121 Ptr<LogDistancePropagationLossModel> model = CreateObject<LogDistancePropagationLossModel>();
122 channel->AddPropagationLossModel(model);
123 dev0->SetChannel(channel);
124 dev1->SetChannel(channel);
125 n0->AddDevice(dev0);
126 n1->AddDevice(dev1);
127 Ptr<ConstantPositionMobilityModel> mob0 = CreateObject<ConstantPositionMobilityModel>();
128 dev0->GetPhy()->SetMobility(mob0);
129 Ptr<ConstantPositionMobilityModel> mob1 = CreateObject<ConstantPositionMobilityModel>();
130 dev1->GetPhy()->SetMobility(mob1);
131
133 Ptr<SpectrumValue> psd = svh.CreateTxPowerSpectralDensity(txPower, channelNumber);
134 dev0->GetPhy()->SetTxPowerSpectralDensity(psd);
135
136 // Set Rx sensitivity of the receiving device
137 dev1->GetPhy()->SetRxSensitivity(rxSensitivity);
138
141 dev1->GetMac()->SetMcpsDataIndicationCallback(cb0);
142
144 params.m_srcAddrMode = SHORT_ADDR;
145 params.m_dstAddrMode = SHORT_ADDR;
146 params.m_dstPanId = 0;
147 params.m_dstAddr = Mac16Address("00:02");
148 params.m_msduHandle = 0;
149 params.m_txOptions = 0;
150
151 Ptr<Packet> p;
152 mob0->SetPosition(Vector(0, 0, 0));
153 mob1->SetPosition(Vector(minDistance, 0, 0));
154 for (int j = minDistance; j < maxDistance; j += increment)
155 {
156 for (int i = 0; i < maxPackets; i++)
157 {
158 p = Create<Packet>(packetSize);
159 Simulator::Schedule(Seconds(i), &LrWpanMac::McpsDataRequest, dev0->GetMac(), params, p);
160 }
162 NS_LOG_DEBUG("Received " << g_packetsReceived << " packets for distance " << j);
163 psrdataset.Add(j, g_packetsReceived / 1000.0);
165
166 mob1->SetPosition(Vector(j, 0, 0));
167 }
168
169 psrplot.AddDataset(psrdataset);
170
171 psrplot.SetTitle(os.str());
172 psrplot.SetTerminal("postscript eps color enh \"Times-BoldItalic\"");
173 psrplot.SetLegend("distance (m)", "Packet Success Rate (PSR)");
174 psrplot.SetExtra("set xrange [0:200]\n\
175 set yrange [0:1]\n\
176 set grid\n\
177 set style line 1 linewidth 5\n\
178 set style increment user");
179 psrplot.GenerateOutput(berfile);
180 berfile.close();
181
183 return 0;
184}
Parse command-line arguments.
Definition: command-line.h:232
Class to represent a 2D points plot.
Definition: gnuplot.h:116
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
Definition: gnuplot.h:370
void AddDataset(const GnuplotDataset &dataset)
Definition: gnuplot.cc:796
void SetLegend(const std::string &xLegend, const std::string &yLegend)
Definition: gnuplot.cc:776
void SetTerminal(const std::string &terminal)
Definition: gnuplot.cc:764
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
Definition: gnuplot.cc:802
void SetExtra(const std::string &extra)
Definition: gnuplot.cc:783
void SetTitle(const std::string &title)
Definition: gnuplot.cc:770
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.
Definition: lr-wpan-mac.cc:349
This class defines all functions to create spectrum model for LrWpan.
Ptr< SpectrumValue > CreateTxPowerSpectralDensity(double txPower, uint32_t channel)
create spectrum value
This class can contain 16 bit addresses.
Definition: mac16-address.h:44
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:568
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:140
static void Run()
Run the simulation.
Definition: simulator.cc:176
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
@ SHORT_ADDR
Definition: lr-wpan-mac.h:156
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1336
void LrWpanErrorDistanceCallback(McpsDataIndicationParams params, Ptr< Packet > p)
Function called when a Data indication is invoked.
uint32_t g_packetsReceived
number of packets received
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...
Definition: callback.h:702
ns cmd
Definition: second.py:33
ns channel
Definition: third.py:81
FtrParams params
Fit Fluctuating Two Ray model to the 3GPP TR 38.901 using the Anderson-Darling goodness-of-fit ##.
MCPS-DATA.indication params.
Definition: lr-wpan-mac.h:430
MCPS-DATA.request params.
Definition: lr-wpan-mac.h:402
static const uint32_t packetSize
Packet size generated at the AP.