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