A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
adr-component.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 University of Padova
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Matteo Perin <matteo.perin.2@studenti.unipd.2>
7 */
8
9#ifndef ADR_COMPONENT_H
10#define ADR_COMPONENT_H
11
12#include "end-device-status.h"
14
15namespace ns3
16{
17namespace lorawan
18{
19
20/**
21 * @ingroup lorawan
22 *
23 * LinkAdrRequest commands management
24 */
26{
27 /**
28 * Available policies for combining radio metrics in packet history.
29 */
36
37 public:
38 /**
39 * Register this type.
40 * @return The object TypeId.
41 */
42 static TypeId GetTypeId();
43
44 AdrComponent(); //!< Default constructor
45 ~AdrComponent() override; //!< Destructor
46
49 Ptr<NetworkStatus> networkStatus) override;
50
51 void BeforeSendingReply(Ptr<EndDeviceStatus> status, Ptr<NetworkStatus> networkStatus) override;
52
53 void OnFailedReply(Ptr<EndDeviceStatus> status, Ptr<NetworkStatus> networkStatus) override;
54
55 private:
56 /**
57 * Implementation of the default Adaptive Data Rate (ADR) procedure.
58 *
59 * ADR is meant to optimize radio modulation parameters of end devices to improve energy
60 * consuption and radio resource utilization. For more details see
61 * https://doi.org/10.1109/NOMS.2018.8406255 .
62 *
63 * @param newDataRate [out] new data rate value selected for the end device.
64 * @param newTxPower [out] new tx power [dBm] value selected for the end device.
65 * @param status State representation of the current end device.
66 */
67 void AdrImplementation(uint8_t* newDataRate, double* newTxPower, Ptr<EndDeviceStatus> status);
68
69 /**
70 * Convert spreading factor values [7:12] to respective data rate values [0:5].
71 *
72 * @param sf The spreading factor value.
73 * @return Value of the data rate as uint8_t.
74 */
75 uint8_t SfToDr(uint8_t sf);
76
77 /**
78 * Convert reception power values [dBm] to Signal to Noise Ratio (SNR) values [dB].
79 *
80 * The conversion comes from the formula \f$P_{rx}=-174+10\log_{10}(B)+SNR+NF\f$ where
81 * \f$P_{rx}\f$ is the received transmission power, \f$B\f$ is the transmission bandwidth and
82 * \f$NF\f$ is the noise figure of the receiver. The constant \f$-174\f$ is the thermal noise
83 * [dBm] in 1 Hz of bandwidth and is influenced the temperature of the receiver, assumed
84 * constant in this model. For more details see the SX1301 chip datasheet.
85 *
86 * @param transmissionPower Value of received transmission power.
87 * @return SNR value as double.
88 */
89 double RxPowerToSNR(double transmissionPower) const;
90
91 /**
92 * Get the min RSSI (dBm) among gateways receiving the same transmission.
93 *
94 * @param gwList List of gateways paired with reception information.
95 * @return Min RSSI of transmission as double.
96 */
98 /**
99 * Get the max RSSI (dBm) among gateways receiving the same transmission.
100 *
101 * @param gwList List of gateways paired with packet reception information.
102 * @return Max RSSI of transmission as double.
103 */
105 /**
106 * Get the average RSSI (dBm) of gateways receiving the same transmission.
107 *
108 * @param gwList List of gateways paired with packet reception information.
109 * @return Average RSSI of transmission as double.
110 */
112 /**
113 * Get RSSI metric for a transmission according to chosen gateway aggregation policy.
114 *
115 * @param gwList List of gateways paired with packet reception information.
116 * @return RSSI of tranmsmission as double.
117 */
119
120 /**
121 * Get the min Signal to Noise Ratio (SNR) of the receive packet history.
122 *
123 * @param packetList History of received packets with reception information.
124 * @param historyRange Number of packets to consider going back in time.
125 * @return Min SNR among packets as double.
126 */
128 /**
129 * Get the max Signal to Noise Ratio (SNR) of the receive packet history.
130 *
131 * @param packetList History of received packets with reception information.
132 * @param historyRange Number of packets to consider going back in time.
133 * @return Max SNR among packets as double.
134 */
136 /**
137 * Get the average Signal to Noise Ratio (SNR) of the received packet history.
138 *
139 * @param packetList History of received packets with reception information.
140 * @param historyRange Number of packets to consider going back in time.
141 * @return Average SNR of packets as double.
142 */
144
145 /**
146 * Get the LoRaWAN protocol TxPower parameter from the Equivalent Radiated Power (ERP) in dBm.
147 *
148 * @param txPower Transission ERP configuration [dBm].
149 * @return TxPower parameter value as uint8_t.
150 */
151 uint8_t GetTxPowerIndex(double txPower);
152
153 enum CombiningMethod tpAveraging; //!< TX power from gateways policy
154 int historyRange; //!< Number of previous packets to consider
155 enum CombiningMethod historyAveraging; //!< Received SNR history policy
156
157 const int min_spreadingFactor = 7; //!< Spreading factor lower limit
158 const int min_transmissionPower = 2; //!< Minimum transmission power (dBm) (Europe)
159 const int max_transmissionPower = 14; //!< Maximum transmission power (dBm) (Europe)
160 // const int offset = 10; //!< Device specific SNR margin (dB)
161 const int B = 125000; //!< Bandwidth (Hz)
162 const int NF = 6; //!< Noise Figure (dB)
163 double threshold[6] = {
164 -20.0,
165 -17.5,
166 -15.0,
167 -12.5,
168 -10.0,
169 -7.5}; //!< Vector containing the required SNR for the 6 allowed spreading factor
170 //!< levels ranging from 7 to 12 (the SNR values are in dB).
171
172 bool m_toggleTxPower; //!< Whether to control transmission power of end devices or not
173};
174
175} // namespace lorawan
176} // namespace ns3
177
178#endif /* ADR_COMPONENT_H */
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
a unique identifier for an interface.
Definition type-id.h:50
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 AdrImplementation(uint8_t *newDataRate, double *newTxPower, Ptr< EndDeviceStatus > status)
Implementation of the default Adaptive Data Rate (ADR) procedure.
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).
uint8_t GetTxPowerIndex(double txPower)
Get the LoRaWAN protocol TxPower parameter from the Equivalent Radiated Power (ERP) in dBm.
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.
CombiningMethod
Available policies for combining radio metrics in packet history.
static TypeId GetTypeId()
Register this type.
const int B
Bandwidth (Hz).
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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.