39 TypeId(
"ns3::AdrComponent")
42 .SetParent<NetworkControllerComponent>()
43 .AddAttribute(
"MultipleGwCombiningMethod",
44 "Whether to average the received power of gateways or to use the maximum",
53 .AddAttribute(
"MultiplePacketsCombiningMethod",
54 "Whether to average SNRs from multiple packets or to use the maximum",
63 .AddAttribute(
"HistoryRange",
64 "Number of packets to use for averaging",
67 MakeIntegerChecker<int>(0, 100))
68 .AddAttribute(
"ChangeTransmissionPower",
69 "Whether to toggle the transmission power or not",
100 Ptr<Packet> myPacket = status->GetLastPacketReceivedFromDevice()->Copy();
104 myPacket->RemoveHeader(mHdr);
105 myPacket->RemoveHeader(fHdr);
110 if (
int(status->GetReceivedPacketList().size()) <
historyRange)
112 NS_LOG_ERROR(
"Not enough packets received by this device ("
113 << status->GetReceivedPacketList().size()
114 <<
") for the algorithm to work (need " <<
historyRange <<
")");
121 uint8_t spreadingFactor = status->GetFirstReceiveWindowSpreadingFactor();
124 uint8_t transmissionPower = status->GetMac()->GetTransmissionPower();
136 newTxPower = transmissionPower;
139 if (newDataRate !=
SfToDr(spreadingFactor) || newTxPower != transmissionPower)
142 int channels[] = {0, 1, 2};
143 std::list<int> enabledChannels(channels, channels +
sizeof(channels) /
sizeof(
int));
148 NS_LOG_DEBUG(
"Sending LinkAdrReq with DR = " << (
unsigned)newDataRate
149 <<
" and TP = " << (
unsigned)newTxPower
152 status->m_reply.frameHeader.AddLinkAdrReq(newDataRate,
156 status->m_reply.frameHeader.SetAsDownlink();
159 status->m_reply.needsReply =
true;
201 uint8_t spreadingFactor = status->GetFirstReceiveWindowSpreadingFactor();
211 double transmissionPower = status->GetMac()->GetTransmissionPower();
213 NS_LOG_DEBUG(
"Transmission Power = " << transmissionPower);
217 double margin_SNR = m_SNR - req_SNR;
223 int steps = std::floor(margin_SNR / 3);
244 transmissionPower -= 2;
250 transmissionPower += 2;
255 *newDataRate =
SfToDr(spreadingFactor);
256 *newTxPower = transmissionPower;
289 return transmissionPower + 174 - 10 * log10(
B) -
NF;
296 auto it = gwList.begin();
297 double min = it->second.rxPower;
299 for (; it != gwList.end(); it++)
301 if (it->second.rxPower < min)
303 min = it->second.rxPower;
314 auto it = gwList.begin();
315 double max = it->second.rxPower;
317 for (; it != gwList.end(); it++)
319 if (it->second.rxPower > max)
321 max = it->second.rxPower;
334 for (
auto it = gwList.begin(); it != gwList.end(); it++)
336 NS_LOG_DEBUG(
"Gateway at " << it->first <<
" has TP " << it->second.rxPower);
337 sum += it->second.rxPower;
340 double average = sum / gwList.size();
370 auto it = packetList.rbegin();
397 auto it = packetList.rbegin();
425 auto it = packetList.rbegin();
450 else if (txPower >= 14)
454 else if (txPower >= 12)
458 else if (txPower >= 10)
462 else if (txPower >= 8)
466 else if (txPower >= 6)
470 else if (txPower >= 4)
Hold variables of type enum.
Hold a signed integer type.
Smart pointer class similar to boost::intrusive_ptr.
a unique identifier for an interface.
TypeId AddConstructor()
Record in this TypeId the fact that the default constructor is accessible.
TypeId SetGroupName(std::string groupName)
Set the group name.
LinkAdrRequest commands management.
double GetAverageSNR(EndDeviceStatus::ReceivedPacketList packetList, int historyRange)
Get the average Signal to Noise Ratio (SNR) of the received packet history.
enum CombiningMethod historyAveraging
Received SNR history policy.
double GetMinSNR(EndDeviceStatus::ReceivedPacketList packetList, int historyRange)
Get the min Signal to Noise Ratio (SNR) of the receive packet history.
void OnReceivedPacket(Ptr< const Packet > packet, Ptr< EndDeviceStatus > status, Ptr< NetworkStatus > networkStatus) override
Function called as a new uplink packet is received by the NetworkServer application.
double threshold[6]
Vector containing the required SNR for the 6 allowed spreading factor levels ranging from 7 to 12 (th...
void OnFailedReply(Ptr< EndDeviceStatus > status, Ptr< NetworkStatus > networkStatus) override
Method that is called when a packet cannot be sent in the downlink.
AdrComponent()
Default constructor.
void BeforeSendingReply(Ptr< EndDeviceStatus > status, Ptr< NetworkStatus > networkStatus) override
Function called as a downlink reply is about to leave the NetworkServer application.
const int NF
Noise Figure (dB)
double GetMinTxFromGateways(EndDeviceStatus::GatewayList gwList)
Get the min RSSI (dBm) among gateways receiving the same transmission.
int historyRange
Number of previous packets to consider.
const int min_spreadingFactor
Spreading factor lower limit.
double GetMaxTxFromGateways(EndDeviceStatus::GatewayList gwList)
Get the max RSSI (dBm) among gateways receiving the same transmission.
enum CombiningMethod tpAveraging
TX power from gateways policy.
bool m_toggleTxPower
Whether to control transmission power of end devices or not.
double GetReceivedPower(EndDeviceStatus::GatewayList gwList)
Get RSSI metric for a transmission according to chosen gateway aggregation policy.
~AdrComponent() override
Destructor.
void AdrImplementation(uint8_t *newDataRate, uint8_t *newTxPower, Ptr< EndDeviceStatus > status)
Implementation of the default Adaptive Data Rate (ADR) procedure.
static TypeId GetTypeId()
Register this type.
const int B
Bandwidth (Hz)
int GetTxPowerIndex(int txPower)
Get the LoRaWAN protocol TXPower configuration index from the Equivalent Isotropically Radiated Power...
double GetMaxSNR(EndDeviceStatus::ReceivedPacketList packetList, int historyRange)
Get the max Signal to Noise Ratio (SNR) of the receive packet history.
double RxPowerToSNR(double transmissionPower) const
Convert reception power values [dBm] to Signal to Noise Ratio (SNR) values [dB].
double GetAverageTxFromGateways(EndDeviceStatus::GatewayList gwList)
Get the average RSSI (dBm) of gateways receiving the same transmission.
const int min_transmissionPower
Minimum transmission power (dBm) (Europe)
uint8_t SfToDr(uint8_t sf)
Convert spreading factor values [7:12] to respective data rate values [0:5].
const int max_transmissionPower
Maximum transmission power (dBm) (Europe)
std::list< std::pair< Ptr< const Packet >, ReceivedPacketInfo > > ReceivedPacketList
typedef of a list of packets paired to their reception info.
std::map< Address, PacketInfoPerGw > GatewayList
typedef of a list of gateways with relative reception information.
#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(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeBooleanChecker()
Ptr< const AttributeAccessor > MakeIntegerAccessor(T1 a1)
Ptr< const AttributeChecker > MakeEnumChecker(T v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)