11#include "ns3/end-device-lora-phy.h"
12#include "ns3/gateway-lora-phy.h"
14#include "ns3/lora-net-device.h"
15#include "ns3/random-variable-stream.h"
69 mac->SetDevice(device);
138 edMac->SetTxDbmForTxPower(std::vector<double>{14, 12, 10, 8, 6, 4, 2, 0});
144 {{1, 0, 0, 0, 0, 0}},
145 {{2, 1, 0, 0, 0, 0}},
146 {{3, 2, 1, 0, 0, 0}},
147 {{4, 3, 2, 1, 0, 0}},
148 {{5, 4, 3, 2, 1, 0}},
149 {{6, 5, 4, 3, 2, 1}},
150 {{7, 6, 5, 4, 3, 2}}}};
151 edMac->SetReplyDataRateMatrix(matrix);
156 edMac->SetNPreambleSymbols(8);
161 edMac->SetSecondReceiveWindowDataRate(0);
162 edMac->SetSecondReceiveWindowFrequency(869525000);
181 gwPhy->ResetReceptionPaths();
183 int receptionPaths = 0;
184 int maxReceptionPaths = 1;
185 while (receptionPaths < maxReceptionPaths)
190 gwPhy->AddFrequency(868100000);
204 channelHelper->AddSubBand(
Create<SubBand>(868000000, 868600000, 1, 14));
210 channelHelper->SetChannel(0, lc1);
212 lorawanMac->SetLogicalLoraChannelHelper(channelHelper);
218 lorawanMac->SetSfForDataRate(std::vector<uint8_t>{12, 11, 10, 9, 8, 7, 7});
219 lorawanMac->SetBandwidthForDataRate(
220 std::vector<double>{125000, 125000, 125000, 125000, 125000, 125000, 250000});
221 lorawanMac->SetMaxAppPayloadForDataRate(
222 std::vector<uint32_t>{59, 59, 59, 123, 230, 230, 230, 230});
235 edMac->SetTxDbmForTxPower(std::vector<double>{14, 12, 10, 8, 6, 4, 2, 0});
241 {{1, 0, 0, 0, 0, 0}},
242 {{2, 1, 0, 0, 0, 0}},
243 {{3, 2, 1, 0, 0, 0}},
244 {{4, 3, 2, 1, 0, 0}},
245 {{5, 4, 3, 2, 1, 0}},
246 {{6, 5, 4, 3, 2, 1}},
247 {{7, 6, 5, 4, 3, 2}}}};
248 edMac->SetReplyDataRateMatrix(matrix);
253 edMac->SetNPreambleSymbols(8);
258 edMac->SetSecondReceiveWindowDataRate(0);
259 edMac->SetSecondReceiveWindowFrequency(869525000);
278 gwPhy->ResetReceptionPaths();
280 std::vector<uint32_t> frequencies;
281 frequencies.push_back(868100000);
282 frequencies.push_back(868300000);
283 frequencies.push_back(868500000);
285 for (
auto& f : frequencies)
287 gwPhy->AddFrequency(f);
290 int receptionPaths = 0;
291 int maxReceptionPaths = 8;
292 while (receptionPaths < maxReceptionPaths)
310 channelHelper->AddSubBand(
Create<SubBand>(863000000, 865000000, 0.001, 14));
311 channelHelper->AddSubBand(
Create<SubBand>(865000000, 868000000, 0.01, 14));
312 channelHelper->AddSubBand(
Create<SubBand>(868000000, 868600000, 0.01, 14));
313 channelHelper->AddSubBand(
Create<SubBand>(868700000, 869200000, 0.001, 14));
314 channelHelper->AddSubBand(
Create<SubBand>(869400000, 869650000, 0.1, 27));
315 channelHelper->AddSubBand(
Create<SubBand>(869700000, 870000000, 0.01, 14));
323 channelHelper->SetChannel(0, lc1);
324 channelHelper->SetChannel(1, lc2);
325 channelHelper->SetChannel(2, lc3);
327 lorawanMac->SetLogicalLoraChannelHelper(channelHelper);
333 lorawanMac->SetSfForDataRate(std::vector<uint8_t>{12, 11, 10, 9, 8, 7, 7});
334 lorawanMac->SetBandwidthForDataRate(
335 std::vector<double>{125000, 125000, 125000, 125000, 125000, 125000, 250000});
336 lorawanMac->SetMaxAppPayloadForDataRate(
337 std::vector<uint32_t>{59, 59, 59, 123, 230, 230, 230, 230});
352 edMac->SetTxDbmForTxPower(std::vector<double>{14, 12, 10, 8, 6, 4, 2, 0});
358 {{1, 0, 0, 0, 0, 0}},
359 {{2, 1, 0, 0, 0, 0}},
360 {{3, 2, 1, 0, 0, 0}},
361 {{4, 3, 2, 1, 0, 0}},
362 {{5, 4, 3, 2, 1, 0}},
363 {{6, 5, 4, 3, 2, 1}},
364 {{7, 6, 5, 4, 3, 2}}}};
365 edMac->SetReplyDataRateMatrix(matrix);
370 edMac->SetNPreambleSymbols(8);
375 edMac->SetSecondReceiveWindowDataRate(0);
376 edMac->SetSecondReceiveWindowFrequency(869525000);
395 gwPhy->ResetReceptionPaths();
397 std::vector<uint32_t> frequencies;
398 frequencies.push_back(868100000);
400 for (
auto& f : frequencies)
402 gwPhy->AddFrequency(f);
405 int receptionPaths = 0;
406 int maxReceptionPaths = 8;
407 while (receptionPaths < maxReceptionPaths)
409 gwPhy->AddReceptionPath();
425 channelHelper->AddSubBand(
Create<SubBand>(868000000, 868600000, 0.01, 14));
431 channelHelper->SetChannel(0, lc1);
433 lorawanMac->SetLogicalLoraChannelHelper(channelHelper);
439 lorawanMac->SetSfForDataRate(std::vector<uint8_t>{12, 11, 10, 9, 8, 7, 7});
440 lorawanMac->SetBandwidthForDataRate(
441 std::vector<double>{125000, 125000, 125000, 125000, 125000, 125000, 250000});
442 lorawanMac->SetMaxAppPayloadForDataRate(
443 std::vector<uint32_t>{59, 59, 59, 123, 230, 230, 230, 230});
453 std::vector<int> sfQuantity(7, 0);
454 for (
auto j = endDevices.
Begin(); j != endDevices.
End(); ++j)
471 double highestRxPower = channel->GetRxPower(14, position, bestGatewayPosition);
473 for (
auto currentGw = gateways.
Begin() + 1; currentGw != gateways.
End(); ++currentGw)
478 double currentRxPower = channel->GetRxPower(14, position, currPosition);
480 if (currentRxPower > highestRxPower)
483 bestGatewayPosition = currPosition;
484 highestRxPower = currentRxPower;
489 double rxPower = highestRxPower;
495 if (rxPower > *edSensitivity)
498 sfQuantity[0] = sfQuantity[0] + 1;
500 else if (rxPower > *(edSensitivity + 1))
503 sfQuantity[1] = sfQuantity[1] + 1;
505 else if (rxPower > *(edSensitivity + 2))
508 sfQuantity[2] = sfQuantity[2] + 1;
510 else if (rxPower > *(edSensitivity + 3))
513 sfQuantity[3] = sfQuantity[3] + 1;
515 else if (rxPower > *(edSensitivity + 4))
518 sfQuantity[4] = sfQuantity[4] + 1;
520 else if (rxPower > *(edSensitivity + 5))
523 sfQuantity[5] = sfQuantity[5] + 1;
529 sfQuantity[6] = sfQuantity[6] + 1;
592 std::vector<double> distribution)
597 std::vector<int> sfQuantity(7, 0);
599 std::vector<double> cumdistr(6);
600 cumdistr[0] = distribution[0];
601 for (
int i = 1; i < 6; ++i)
603 cumdistr[i] = distribution[i] + cumdistr[i - 1];
606 NS_LOG_DEBUG(
"Distribution: " << distribution[0] <<
" " << distribution[1] <<
" "
607 << distribution[2] <<
" " << distribution[3] <<
" "
608 << distribution[4] <<
" " << distribution[5]);
609 NS_LOG_DEBUG(
"Cumulative distribution: " << cumdistr[0] <<
" " << cumdistr[1] <<
" "
610 << cumdistr[2] <<
" " << cumdistr[3] <<
" "
611 << cumdistr[4] <<
" " << cumdistr[5]);
613 for (
auto j = endDevices.
Begin(); j != endDevices.
End(); ++j)
625 double prob = uniformRV->GetValue(0, 1);
628 if (prob < cumdistr[0])
631 sfQuantity[0] = sfQuantity[0] + 1;
633 else if (prob > cumdistr[0] && prob < cumdistr[1])
636 sfQuantity[1] = sfQuantity[1] + 1;
638 else if (prob > cumdistr[1] && prob < cumdistr[2])
641 sfQuantity[2] = sfQuantity[2] + 1;
643 else if (prob > cumdistr[2] && prob < cumdistr[3])
646 sfQuantity[3] = sfQuantity[3] + 1;
648 else if (prob > cumdistr[3] && prob < cumdistr[4])
651 sfQuantity[4] = sfQuantity[4] + 1;
656 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.
Smart pointer class similar to boost::intrusive_ptr.
static const double sensitivity[6]
The sensitivity vector of this device to different SFs.
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.
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...
Ptr< LorawanMac > Install(Ptr< Node > node, Ptr< NetDevice > device) const
Create the LorawanMac instance and connect it to a device.
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 ",...
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.