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>{16, 14, 12, 10, 8, 6, 4, 2});
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(869.525);
181 gwPhy->ResetReceptionPaths();
183 int receptionPaths = 0;
184 int maxReceptionPaths = 1;
185 while (receptionPaths < maxReceptionPaths)
190 gwPhy->AddFrequency(868.1);
204 channelHelper->AddSubBand(868, 868.6, 1, 14);
210 channelHelper->AddChannel(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>{16, 14, 12, 10, 8, 6, 4, 2});
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(869.525);
278 gwPhy->ResetReceptionPaths();
280 std::vector<double> frequencies;
281 frequencies.push_back(868.1);
282 frequencies.push_back(868.3);
283 frequencies.push_back(868.5);
285 for (
auto& f : frequencies)
287 gwPhy->AddFrequency(f);
290 int receptionPaths = 0;
291 int maxReceptionPaths = 8;
292 while (receptionPaths < maxReceptionPaths)
310 channelHelper->AddSubBand(868, 868.6, 0.01, 14);
311 channelHelper->AddSubBand(868.7, 869.2, 0.001, 14);
312 channelHelper->AddSubBand(869.4, 869.65, 0.1, 27);
320 channelHelper->AddChannel(lc1);
321 channelHelper->AddChannel(lc2);
322 channelHelper->AddChannel(lc3);
324 lorawanMac->SetLogicalLoraChannelHelper(channelHelper);
330 lorawanMac->SetSfForDataRate(std::vector<uint8_t>{12, 11, 10, 9, 8, 7, 7});
331 lorawanMac->SetBandwidthForDataRate(
332 std::vector<double>{125000, 125000, 125000, 125000, 125000, 125000, 250000});
333 lorawanMac->SetMaxAppPayloadForDataRate(
334 std::vector<uint32_t>{59, 59, 59, 123, 230, 230, 230, 230});
349 edMac->SetTxDbmForTxPower(std::vector<double>{16, 14, 12, 10, 8, 6, 4, 2});
355 {{1, 0, 0, 0, 0, 0}},
356 {{2, 1, 0, 0, 0, 0}},
357 {{3, 2, 1, 0, 0, 0}},
358 {{4, 3, 2, 1, 0, 0}},
359 {{5, 4, 3, 2, 1, 0}},
360 {{6, 5, 4, 3, 2, 1}},
361 {{7, 6, 5, 4, 3, 2}}}};
362 edMac->SetReplyDataRateMatrix(matrix);
367 edMac->SetNPreambleSymbols(8);
372 edMac->SetSecondReceiveWindowDataRate(0);
373 edMac->SetSecondReceiveWindowFrequency(869.525);
392 gwPhy->ResetReceptionPaths();
394 std::vector<double> frequencies;
395 frequencies.push_back(868.1);
397 for (
auto& f : frequencies)
399 gwPhy->AddFrequency(f);
402 int receptionPaths = 0;
403 int maxReceptionPaths = 8;
404 while (receptionPaths < maxReceptionPaths)
406 gwPhy->AddReceptionPath();
422 channelHelper->AddSubBand(868, 868.6, 0.01, 14);
423 channelHelper->AddSubBand(868.7, 869.2, 0.001, 14);
424 channelHelper->AddSubBand(869.4, 869.65, 0.1, 27);
430 channelHelper->AddChannel(lc1);
432 lorawanMac->SetLogicalLoraChannelHelper(channelHelper);
438 lorawanMac->SetSfForDataRate(std::vector<uint8_t>{12, 11, 10, 9, 8, 7, 7});
439 lorawanMac->SetBandwidthForDataRate(
440 std::vector<double>{125000, 125000, 125000, 125000, 125000, 125000, 250000});
441 lorawanMac->SetMaxAppPayloadForDataRate(
442 std::vector<uint32_t>{59, 59, 59, 123, 230, 230, 230, 230});
452 std::vector<int> sfQuantity(7, 0);
453 for (
auto j = endDevices.
Begin(); j != endDevices.
End(); ++j)
470 double highestRxPower = channel->GetRxPower(14, position, bestGatewayPosition);
472 for (
auto currentGw = gateways.
Begin() + 1; currentGw != gateways.
End(); ++currentGw)
477 double currentRxPower = channel->GetRxPower(14, position, currPosition);
479 if (currentRxPower > highestRxPower)
482 bestGatewayPosition = currPosition;
483 highestRxPower = currentRxPower;
488 double rxPower = highestRxPower;
494 if (rxPower > *edSensitivity)
497 sfQuantity[0] = sfQuantity[0] + 1;
499 else if (rxPower > *(edSensitivity + 1))
502 sfQuantity[1] = sfQuantity[1] + 1;
504 else if (rxPower > *(edSensitivity + 2))
507 sfQuantity[2] = sfQuantity[2] + 1;
509 else if (rxPower > *(edSensitivity + 3))
512 sfQuantity[3] = sfQuantity[3] + 1;
514 else if (rxPower > *(edSensitivity + 4))
517 sfQuantity[4] = sfQuantity[4] + 1;
519 else if (rxPower > *(edSensitivity + 5))
522 sfQuantity[5] = sfQuantity[5] + 1;
528 sfQuantity[6] = sfQuantity[6] + 1;
591 std::vector<double> distribution)
596 std::vector<int> sfQuantity(7, 0);
598 std::vector<double> cumdistr(6);
599 cumdistr[0] = distribution[0];
600 for (
int i = 1; i < 6; ++i)
602 cumdistr[i] = distribution[i] + cumdistr[i - 1];
605 NS_LOG_DEBUG(
"Distribution: " << distribution[0] <<
" " << distribution[1] <<
" "
606 << distribution[2] <<
" " << distribution[3] <<
" "
607 << distribution[4] <<
" " << distribution[5]);
608 NS_LOG_DEBUG(
"Cumulative distribution: " << cumdistr[0] <<
" " << cumdistr[1] <<
" "
609 << cumdistr[2] <<
" " << cumdistr[3] <<
" "
610 << cumdistr[4] <<
" " << cumdistr[5]);
612 for (
auto j = endDevices.
Begin(); j != endDevices.
End(); ++j)
624 double prob = uniformRV->GetValue(0, 1);
627 if (prob < cumdistr[0])
630 sfQuantity[0] = sfQuantity[0] + 1;
632 else if (prob > cumdistr[0] && prob < cumdistr[1])
635 sfQuantity[1] = sfQuantity[1] + 1;
637 else if (prob > cumdistr[1] && prob < cumdistr[2])
640 sfQuantity[2] = sfQuantity[2] + 1;
642 else if (prob > cumdistr[2] && prob < cumdistr[3])
645 sfQuantity[3] = sfQuantity[3] + 1;
647 else if (prob > cumdistr[3] && prob < cumdistr[4])
650 sfQuantity[4] = sfQuantity[4] + 1;
655 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.
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 ",...
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.