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 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Matteo Perin <matteo.perin.2@studenti.unipd.2>
18 */
19
20#ifndef ADR_COMPONENT_H
21#define ADR_COMPONENT_H
22
24#include "network-status.h"
25
26#include "ns3/log.h"
27#include "ns3/object.h"
28#include "ns3/packet.h"
29
30namespace ns3
31{
32namespace lorawan
33{
34
35/**
36 * \ingroup lorawan
37 *
38 * LinkAdrRequest commands management
39 */
41{
42 /**
43 * Available policies for combining radio metrics in packet history.
44 */
46 {
50 };
51
52 public:
53 /**
54 * Register this type.
55 * \return The object TypeId.
56 */
57 static TypeId GetTypeId();
58
59 AdrComponent(); //!< Default constructor
60 ~AdrComponent() override; //!< Destructor
61
64 Ptr<NetworkStatus> networkStatus) override;
65
66 void BeforeSendingReply(Ptr<EndDeviceStatus> status, Ptr<NetworkStatus> networkStatus) override;
67
68 void OnFailedReply(Ptr<EndDeviceStatus> status, Ptr<NetworkStatus> networkStatus) override;
69
70 private:
71 /**
72 * Implementation of the default Adaptive Data Rate (ADR) procedure.
73 *
74 * ADR is meant to optimize radio modulation parameters of end devices to improve energy
75 * consuption and radio resource utilization. For more details see
76 * https://doi.org/10.1109/NOMS.2018.8406255 .
77 *
78 * \param newDataRate [out] new data rate value selected for the end device.
79 * \param newTxPower [out] new tx power value selected for the end device.
80 * \param status State representation of the current end device.
81 */
82 void AdrImplementation(uint8_t* newDataRate, uint8_t* newTxPower, Ptr<EndDeviceStatus> status);
83
84 /**
85 * Convert spreading factor values [7:12] to respective data rate values [0:5].
86 *
87 * \param sf The spreading factor value.
88 * \return Value of the data rate as uint8_t.
89 */
90 uint8_t SfToDr(uint8_t sf);
91
92 /**
93 * Convert reception power values [dBm] to Signal to Noise Ratio (SNR) values [dB].
94 *
95 * The conversion comes from the formula \f$P_{rx}=-174+10\log_{10}(B)+SNR+NF\f$ where
96 * \f$P_{rx}\f$ is the received transmission power, \f$B\f$ is the transmission bandwidth and
97 * \f$NF\f$ is the noise figure of the receiver. The constant \f$-174\f$ is the thermal noise
98 * [dBm] in 1 Hz of bandwidth and is influenced the temperature of the receiver, assumed
99 * constant in this model. For more details see the SX1301 chip datasheet.
100 *
101 * \param transmissionPower Value of received transmission power.
102 * \return SNR value as double.
103 */
104 double RxPowerToSNR(double transmissionPower) const;
105
106 /**
107 * Get the min RSSI (dBm) among gateways receiving the same transmission.
108 *
109 * \param gwList List of gateways paired with reception information.
110 * \return Min RSSI of transmission as double.
111 */
113 /**
114 * Get the max RSSI (dBm) among gateways receiving the same transmission.
115 *
116 * \param gwList List of gateways paired with packet reception information.
117 * \return Max RSSI of transmission as double.
118 */
120 /**
121 * Get the average RSSI (dBm) of gateways receiving the same transmission.
122 *
123 * \param gwList List of gateways paired with packet reception information.
124 * \return Average RSSI of transmission as double.
125 */
127 /**
128 * Get RSSI metric for a transmission according to chosen gateway aggregation policy.
129 *
130 * \param gwList List of gateways paired with packet reception information.
131 * \return RSSI of tranmsmission as double.
132 */
134
135 /**
136 * Get the min Signal to Noise Ratio (SNR) of the receive packet history.
137 *
138 * \param packetList History of received packets with reception information.
139 * \param historyRange Number of packets to consider going back in time.
140 * \return Min SNR among packets as double.
141 */
143 /**
144 * Get the max Signal to Noise Ratio (SNR) of the receive packet history.
145 *
146 * \param packetList History of received packets with reception information.
147 * \param historyRange Number of packets to consider going back in time.
148 * \return Max SNR among packets as double.
149 */
151 /**
152 * Get the average Signal to Noise Ratio (SNR) of the received packet history.
153 *
154 * \param packetList History of received packets with reception information.
155 * \param historyRange Number of packets to consider going back in time.
156 * \return Average SNR of packets as double.
157 */
159
160 /**
161 * Get the LoRaWAN protocol TXPower configuration index from the Equivalent Isotropically
162 * Radiated Power (EIRP) in dBm.
163 *
164 * \param txPower Transission EIRP configuration.
165 * \return TXPower index as int.
166 */
167 int GetTxPowerIndex(int txPower);
168
169 enum CombiningMethod tpAveraging; //!< TX power from gateways policy
170 int historyRange; //!< Number of previous packets to consider
171 enum CombiningMethod historyAveraging; //!< Received SNR history policy
172
173 const int min_spreadingFactor = 7; //!< Spreading factor lower limit
174 const int min_transmissionPower = 2; //!< Minimum transmission power (dBm) (Europe)
175 const int max_transmissionPower = 14; //!< Maximum transmission power (dBm) (Europe)
176 // const int offset = 10; //!< Device specific SNR margin (dB)
177 const int B = 125000; //!< Bandwidth (Hz)
178 const int NF = 6; //!< Noise Figure (dB)
179 double threshold[6] = {
180 -20.0,
181 -17.5,
182 -15.0,
183 -12.5,
184 -10.0,
185 -7.5}; //!< Vector containing the required SNR for the 6 allowed spreading factor
186 //!< levels ranging from 7 to 12 (the SNR values are in dB).
187
188 bool m_toggleTxPower; //!< Whether to control transmission power of end devices or not
189};
190} // namespace lorawan
191} // namespace ns3
192
193#endif
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
a unique identifier for an interface.
Definition: type-id.h:59
LinkAdrRequest commands management.
Definition: adr-component.h:41
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.
CombiningMethod
Available policies for combining radio metrics in packet history.
Definition: adr-component.h:46
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.
Generic class describing a component of the NetworkController.
Every class exported by the ns3 library is enclosed in the ns3 namespace.