28 #include <ns3/callback.h>
29 #include <ns3/packet.h>
30 #include <ns3/simulator.h>
31 #include <ns3/lr-wpan-error-model.h>
32 #include <ns3/propagation-loss-model.h>
33 #include <ns3/lr-wpan-net-device.h>
34 #include <ns3/spectrum-value.h>
35 #include <ns3/lr-wpan-spectrum-value-helper.h>
36 #include <ns3/lr-wpan-mac.h>
38 #include <ns3/net-device.h>
39 #include <ns3/single-model-spectrum-channel.h>
40 #include <ns3/mac16-address.h>
41 #include <ns3/constant-position-mobility-model.h>
42 #include <ns3/uinteger.h>
43 #include <ns3/nstime.h>
44 #include <ns3/abort.h>
45 #include <ns3/command-line.h>
46 #include <ns3/gnuplot.h>
66 int main (
int argc,
char *argv[])
68 std::ostringstream os;
69 std::ofstream berfile (
"802.15.4-psr-distance.plt");
72 int maxDistance = 200;
74 int maxPackets = 1000;
77 uint32_t channelNumber = 11;
81 cmd.
AddValue (
"txPower",
"transmit power (dBm)", txPower);
82 cmd.
AddValue (
"packetSize",
"packet (MSDU) size (bytes)", packetSize);
83 cmd.
AddValue (
"channelNumber",
"channel number", channelNumber);
85 cmd.
Parse (argc, argv);
87 os <<
"Packet (MSDU) size = " << packetSize <<
" bytes; tx power = " << txPower <<
" dBm; channel = " << channelNumber;
101 dev0->SetChannel (channel);
102 dev1->SetChannel (channel);
104 n1->AddDevice (dev1);
106 dev0->GetPhy ()->SetMobility (mob0);
108 dev1->GetPhy ()->SetMobility (mob1);
112 dev0->GetPhy ()->SetTxPowerSpectralDensity (psd);
116 dev1->GetMac ()->SetMcpsDataIndicationCallback (cb0);
129 for (
int j = minDistance; j < maxDistance; )
131 for (
int i = 0; i < maxPackets; i++)
133 p = Create<Packet> (packetSize);
136 dev0->GetMac (), params, p);
149 psrplot.
SetTerminal (
"postscript eps color enh \"Times-BoldItalic\"");
150 psrplot.
SetLegend (
"distance (m)",
"Packet Success Rate (PSR)");
151 psrplot.
SetExtra (
"set xrange [0:200]\n\
154 set style line 1 linewidth 5\n\
155 set style increment user");
Class to represent a 2D points plot.
static void Run(void)
Run the simulation until one of:
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
void AddDataset(const GnuplotDataset &dataset)
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
virtual void AddPropagationLossModel(Ptr< PropagationLossModel > loss)
set the single-frequency propagation loss model to be used
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. ...
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
void SetTitle(const std::string &title)
This class defines all functions to create spectrum model for LrWpan.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
void Add(double x, double y)
Parse command-line arguments.
void SetLegend(const std::string &xLegend, const std::string &yLegend)
static void Destroy(void)
Every event scheduled by the Simulator::insertAtDestroy method is invoked.
LrWpanAddressMode m_srcAddrMode
LrWpanAddressMode m_dstAddrMode
This class can contain 16 bit addresses.
void SetExtra(const std::string &extra)
void SetPosition(const Vector &position)
static void LrWpanErrorDistanceCallback(McpsDataIndicationParams params, Ptr< Packet > p)
uint32_t AddDevice(Ptr< NetDevice > device)
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
Ptr< SpectrumValue > CreateTxPowerSpectralDensity(double txPower, uint32_t channel)
create spectrum value
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
int main(int argc, char *argv[])
void Parse(int argc, char *argv[])
Parse the program arguments.
void SetTerminal(const std::string &terminal)
static uint32_t g_received