22#include "ns3/end-device-lora-phy.h"
23#include "ns3/gateway-lora-phy.h"
25#include "ns3/lora-net-device.h"
26#include "ns3/random-variable-stream.h"
80 mac->SetDevice(device);
149 edMac->SetTxDbmForTxPower(std::vector<double>{16, 14, 12, 10, 8, 6, 4, 2});
155 {{1, 0, 0, 0, 0, 0}},
156 {{2, 1, 0, 0, 0, 0}},
157 {{3, 2, 1, 0, 0, 0}},
158 {{4, 3, 2, 1, 0, 0}},
159 {{5, 4, 3, 2, 1, 0}},
160 {{6, 5, 4, 3, 2, 1}},
161 {{7, 6, 5, 4, 3, 2}}}};
162 edMac->SetReplyDataRateMatrix(matrix);
167 edMac->SetNPreambleSymbols(8);
172 edMac->SetSecondReceiveWindowDataRate(0);
173 edMac->SetSecondReceiveWindowFrequency(869.525);
192 gwPhy->ResetReceptionPaths();
194 int receptionPaths = 0;
195 int maxReceptionPaths = 1;
196 while (receptionPaths < maxReceptionPaths)
201 gwPhy->AddFrequency(868.1);
223 lorawanMac->SetLogicalLoraChannelHelper(channelHelper);
229 lorawanMac->SetSfForDataRate(std::vector<uint8_t>{12, 11, 10, 9, 8, 7, 7});
230 lorawanMac->SetBandwidthForDataRate(
231 std::vector<double>{125000, 125000, 125000, 125000, 125000, 125000, 250000});
232 lorawanMac->SetMaxAppPayloadForDataRate(
233 std::vector<uint32_t>{59, 59, 59, 123, 230, 230, 230, 230});
246 edMac->SetTxDbmForTxPower(std::vector<double>{16, 14, 12, 10, 8, 6, 4, 2});
252 {{1, 0, 0, 0, 0, 0}},
253 {{2, 1, 0, 0, 0, 0}},
254 {{3, 2, 1, 0, 0, 0}},
255 {{4, 3, 2, 1, 0, 0}},
256 {{5, 4, 3, 2, 1, 0}},
257 {{6, 5, 4, 3, 2, 1}},
258 {{7, 6, 5, 4, 3, 2}}}};
259 edMac->SetReplyDataRateMatrix(matrix);
264 edMac->SetNPreambleSymbols(8);
269 edMac->SetSecondReceiveWindowDataRate(0);
270 edMac->SetSecondReceiveWindowFrequency(869.525);
289 gwPhy->ResetReceptionPaths();
291 std::vector<double> frequencies;
292 frequencies.push_back(868.1);
293 frequencies.push_back(868.3);
294 frequencies.push_back(868.5);
296 for (
auto& f : frequencies)
298 gwPhy->AddFrequency(f);
301 int receptionPaths = 0;
302 int maxReceptionPaths = 8;
303 while (receptionPaths < maxReceptionPaths)
321 channelHelper.
AddSubBand(868, 868.6, 0.01, 14);
322 channelHelper.
AddSubBand(868.7, 869.2, 0.001, 14);
323 channelHelper.
AddSubBand(869.4, 869.65, 0.1, 27);
335 lorawanMac->SetLogicalLoraChannelHelper(channelHelper);
341 lorawanMac->SetSfForDataRate(std::vector<uint8_t>{12, 11, 10, 9, 8, 7, 7});
342 lorawanMac->SetBandwidthForDataRate(
343 std::vector<double>{125000, 125000, 125000, 125000, 125000, 125000, 250000});
344 lorawanMac->SetMaxAppPayloadForDataRate(
345 std::vector<uint32_t>{59, 59, 59, 123, 230, 230, 230, 230});
360 edMac->SetTxDbmForTxPower(std::vector<double>{16, 14, 12, 10, 8, 6, 4, 2});
366 {{1, 0, 0, 0, 0, 0}},
367 {{2, 1, 0, 0, 0, 0}},
368 {{3, 2, 1, 0, 0, 0}},
369 {{4, 3, 2, 1, 0, 0}},
370 {{5, 4, 3, 2, 1, 0}},
371 {{6, 5, 4, 3, 2, 1}},
372 {{7, 6, 5, 4, 3, 2}}}};
373 edMac->SetReplyDataRateMatrix(matrix);
378 edMac->SetNPreambleSymbols(8);
383 edMac->SetSecondReceiveWindowDataRate(0);
384 edMac->SetSecondReceiveWindowFrequency(869.525);
403 gwPhy->ResetReceptionPaths();
405 std::vector<double> frequencies;
406 frequencies.push_back(868.1);
408 for (
auto& f : frequencies)
410 gwPhy->AddFrequency(f);
413 int receptionPaths = 0;
414 int maxReceptionPaths = 8;
415 while (receptionPaths < maxReceptionPaths)
433 channelHelper.
AddSubBand(868, 868.6, 0.01, 14);
434 channelHelper.
AddSubBand(868.7, 869.2, 0.001, 14);
435 channelHelper.
AddSubBand(869.4, 869.65, 0.1, 27);
443 lorawanMac->SetLogicalLoraChannelHelper(channelHelper);
449 lorawanMac->SetSfForDataRate(std::vector<uint8_t>{12, 11, 10, 9, 8, 7, 7});
450 lorawanMac->SetBandwidthForDataRate(
451 std::vector<double>{125000, 125000, 125000, 125000, 125000, 125000, 250000});
452 lorawanMac->SetMaxAppPayloadForDataRate(
453 std::vector<uint32_t>{59, 59, 59, 123, 230, 230, 230, 230});
463 std::vector<int> sfQuantity(7, 0);
464 for (
auto j = endDevices.
Begin(); j != endDevices.
End(); ++j)
481 double highestRxPower = channel->GetRxPower(14, position, bestGatewayPosition);
483 for (
auto currentGw = gateways.
Begin() + 1; currentGw != gateways.
End(); ++currentGw)
488 double currentRxPower = channel->GetRxPower(14, position, currPosition);
490 if (currentRxPower > highestRxPower)
494 highestRxPower = currentRxPower;
499 double rxPower = highestRxPower;
503 const double* edSensitivity = edPhy->sensitivity;
505 if (rxPower > *edSensitivity)
508 sfQuantity[0] = sfQuantity[0] + 1;
510 else if (rxPower > *(edSensitivity + 1))
513 sfQuantity[1] = sfQuantity[1] + 1;
515 else if (rxPower > *(edSensitivity + 2))
518 sfQuantity[2] = sfQuantity[2] + 1;
520 else if (rxPower > *(edSensitivity + 3))
523 sfQuantity[3] = sfQuantity[3] + 1;
525 else if (rxPower > *(edSensitivity + 4))
528 sfQuantity[4] = sfQuantity[4] + 1;
530 else if (rxPower > *(edSensitivity + 5))
533 sfQuantity[5] = sfQuantity[5] + 1;
539 sfQuantity[6] = sfQuantity[6] + 1;
602 std::vector<double> distribution)
607 std::vector<int> sfQuantity(7, 0);
609 std::vector<double> cumdistr(6);
610 cumdistr[0] = distribution[0];
611 for (
int i = 1; i < 6; ++i)
613 cumdistr[i] = distribution[i] + cumdistr[i - 1];
616 NS_LOG_DEBUG(
"Distribution: " << distribution[0] <<
" " << distribution[1] <<
" "
617 << distribution[2] <<
" " << distribution[3] <<
" "
618 << distribution[4] <<
" " << distribution[5]);
619 NS_LOG_DEBUG(
"Cumulative distribution: " << cumdistr[0] <<
" " << cumdistr[1] <<
" "
620 << cumdistr[2] <<
" " << cumdistr[3] <<
" "
621 << cumdistr[4] <<
" " << cumdistr[5]);
623 for (
auto j = endDevices.
Begin(); j != endDevices.
End(); ++j)
635 double prob = uniformRV->GetValue(0, 1);
638 if (prob < cumdistr[0])
641 sfQuantity[0] = sfQuantity[0] + 1;
643 else if (prob > cumdistr[0] && prob < cumdistr[1])
646 sfQuantity[1] = sfQuantity[1] + 1;
648 else if (prob > cumdistr[1] && prob < cumdistr[2])
651 sfQuantity[2] = sfQuantity[2] + 1;
653 else if (prob > cumdistr[2] && prob < cumdistr[3])
656 sfQuantity[3] = sfQuantity[3] + 1;
658 else if (prob > cumdistr[3] && prob < cumdistr[4])
661 sfQuantity[4] = sfQuantity[4] + 1;
666 sfQuantity[5] = sfQuantity[5] + 1;
Hold a value for an Attribute.
Keep track of the current position and velocity of an object.
keep track of a set of node pointers.
Iterator End() const
Get an iterator which indicates past-the-last Node in the container.
Iterator Begin() const
Get an iterator which refers to the first Node in the container.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Smart pointer class similar to boost::intrusive_ptr.
Class representing the MAC layer of a Class A LoRaWAN device.
Class representing a LoRa transceiver.
Class modeling a Lora SX1301 chip.
Class representing the MAC layer of a LoRaWAN gateway.
This class supports LorawanMac instances by managing a list of the logical channels that the device i...
void AddSubBand(double firstFrequency, double lastFrequency, double dutyCycle, double maxTxPowerDbm)
Add a new SubBand to this helper.
void AddChannel(double frequency)
Add a new channel to the list.
Hold together all LoRa related objects.
Helper class for configuring and installing the LorawanMac class on devices and gateways.
void ConfigureForAlohaRegion(Ptr< ClassAEndDeviceLorawanMac > edMac) const
Perform region-specific configurations for the ALOHA band.
LorawanMacHelper()
Default constructor.
void SetDeviceType(enum DeviceType dt)
Set the kind of MAC this helper will create.
void SetAddressGenerator(Ptr< LoraDeviceAddressGenerator > addrGen)
Set the address generator to use for creation of these nodes.
static std::vector< int > SetSpreadingFactorsUp(NodeContainer endDevices, NodeContainer gateways, Ptr< LoraChannel > channel)
Initialize the end devices' data rate parameter.
void ApplyCommonEuConfigurations(Ptr< LorawanMac > lorawanMac) const
Apply configurations that are common both for the GatewayLorawanMac and the ClassAEndDeviceLorawanMac...
enum Regions m_region
The region in which the device will operate.
Regions
Define the operational region.
void SetRegion(enum Regions region)
Set the region in which the device is to operate.
void Set(std::string name, const AttributeValue &v)
Set an attribute of the underlying MAC object.
ObjectFactory m_mac
MAC-layer object factory.
Ptr< LorawanMac > Create(Ptr< Node > node, Ptr< NetDevice > device) const
Create the LorawanMac instance and connect it to a device.
static std::vector< int > SetSpreadingFactorsGivenDistribution(NodeContainer endDevices, NodeContainer gateways, std::vector< double > distribution)
Randomly initialize the end devices' data rate parameter according to the given distribution.
Ptr< LoraDeviceAddressGenerator > m_addrGen
Pointer to the address generator to use.
void ConfigureForSingleChannelRegion(Ptr< ClassAEndDeviceLorawanMac > edMac) const
Perform region-specific configurations for the SINGLECHANNEL band.
void ApplyCommonSingleChannelConfigurations(Ptr< LorawanMac > lorawanMac) const
Apply configurations that are common both for the GatewayLorawanMac and the ClassAEndDeviceLorawanMac...
DeviceType
Define the kind of device.
void ApplyCommonAlohaConfigurations(Ptr< LorawanMac > lorawanMac) const
Apply configurations that are common both for the GatewayLorawanMac and the ClassAEndDeviceLorawanMac...
enum DeviceType m_deviceType
The kind of device to install.
void ConfigureForEuRegion(Ptr< ClassAEndDeviceLorawanMac > edMac) const
Perform region-specific configurations for the 868 MHz EU band.
Class representing the LoRaWAN MAC layer.
std::array< std::array< uint8_t, 6 >, 8 > ReplyDataRateMatrix
Matrix structure to store possible data rate value to be used by a LoRaWAN end device for listening d...
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.