A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lorawan-mac.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: Davide Magrin <magrinda@dei.unipd.it>
7 */
8
9#ifndef LORAWAN_MAC_H
10#define LORAWAN_MAC_H
11
13
14#include "ns3/net-device.h"
15#include "ns3/object.h"
16#include "ns3/packet.h"
17#include "ns3/traced-callback.h"
18
19namespace ns3
20{
21namespace lorawan
22{
23
24class LoraPhy;
25
26/**
27 * @ingroup lorawan
28 *
29 * Class representing the LoRaWAN MAC layer.
30 *
31 * This class is meant to be extended differently based on whether the layer
32 * belongs to an end device or a gateway, while holding some functionality that
33 * is common to both.
34 */
35class LorawanMac : public Object
36{
37 public:
38 /**
39 * Register this type.
40 * @return The object TypeId.
41 */
42 static TypeId GetTypeId();
43
44 LorawanMac(); //!< Default constructor
45 ~LorawanMac() override; //!< Destructor
46
47 /**
48 * Matrix structure to store possible data rate value to be used by a LoRaWAN end device for
49 * listening during the RX1 receive window. It is a function of the uplink data rate and the
50 * RX1DROffset [0:5].
51 */
52 typedef std::array<std::array<uint8_t, 6>, 8> ReplyDataRateMatrix;
53
54 /**
55 * Set the underlying PHY layer.
56 *
57 * @param phy The phy layer.
58 */
59 void SetPhy(Ptr<LoraPhy> phy);
60
61 /**
62 * Get the underlying PHY layer.
63 *
64 * @return The PHY layer that this MAC is connected to.
65 */
67
68 /**
69 * Send a packet.
70 *
71 * @param packet The packet to send.
72 */
73 virtual void Send(Ptr<Packet> packet) = 0;
74
75 /**
76 * Receive a packet from the lower layer.
77 *
78 * @param packet The received packet.
79 */
80 virtual void Receive(Ptr<const Packet> packet) = 0;
81
82 /**
83 * Function called by lower layers to inform this layer that reception of a
84 * packet we were locked on failed.
85 *
86 * @param packet The packet we failed to receive.
87 */
88 virtual void FailedReception(Ptr<const Packet> packet) = 0;
89
90 /**
91 * Perform actions after sending a packet.
92 *
93 * @param packet The packet that just finished transmission.
94 */
95 virtual void TxFinished(Ptr<const Packet> packet) = 0;
96
97 /**
98 * Set the device this MAC layer is installed on.
99 *
100 * @param device The NetDevice this MAC layer will refer to.
101 */
102 void SetDevice(Ptr<NetDevice> device);
103
104 /**
105 * Get the device this MAC layer is installed on.
106 *
107 * @return The NetDevice this MAC layer will refer to.
108 */
110
111 /**
112 * Get the logical lora channel helper associated with this MAC.
113 *
114 * @return A Ptr to the instance of LogicalLoraChannelHelper that this MAC is using.
115 */
117
118 /**
119 * Set the LogicalLoraChannelHelper this MAC instance will use.
120 *
121 * @param helper A Ptr to the instance of the helper to use.
122 */
124
125 /**
126 * Get the spreading factor corresponding to a data rate, based on this MAC's region.
127 *
128 * @param dataRate The data rate we need to convert to a Spreading Factor
129 * value.
130 * @return The spreading factor that corresponds to a data rate in this MAC's region, or 0
131 * if the dataRate is not valid.
132 */
133 uint8_t GetSfFromDataRate(uint8_t dataRate);
134
135 /**
136 * Get the bandwidth corresponding to a data rate, based on this MAC's region.
137 *
138 * @param dataRate The data rate we need to convert to a bandwidth value.
139 * @return The bandwidth that corresponds to the parameter data rate in this
140 * MAC's region, or 0 if the dataRate is not valid.
141 */
142 double GetBandwidthFromDataRate(uint8_t dataRate);
143
144 /**
145 * Get the transmission power in dBm that corresponds, in this region, to the
146 * encoded 8-bit txPower.
147 *
148 * @param txPower The 8-bit encoded txPower to convert.
149 *
150 * @return The corresponding transmission power in dBm ERP, or -1 if the encoded
151 * power was not recognized as valid.
152 */
153 double GetDbmForTxPower(uint8_t txPower);
154
155 /**
156 * Set the vector to use to check up correspondence between spreading factor and data rate.
157 *
158 * @param sfForDataRate A vector that contains at position i the spreading factor that
159 * should correspond to data rate i.
160 */
161 void SetSfForDataRate(std::vector<uint8_t> sfForDataRate);
162
163 /**
164 * Set the vector to use to check up correspondence between bandwidth and
165 * data rate.
166 *
167 * @param bandwidthForDataRate A vector that contains at position i the
168 * bandwidth that should correspond to data rate i in this MAC's region.
169 */
170 void SetBandwidthForDataRate(std::vector<double> bandwidthForDataRate);
171
172 /**
173 * Set the maximum LoRaWAN MACPayload size for a set data rate.
174 *
175 * @param maxMacPayloadForDataRate A vector that contains at position i the
176 * maximum LoRaWAN MACPayload that should correspond to data rate i in this
177 * MAC's region. See, LoRaWAN RP002-1.0.4
178 */
179 void SetMaxMacPayloadForDataRate(std::vector<uint32_t> maxMacPayloadForDataRate);
180
181 /**
182 * Set the vector to use to check up which transmission power in Dbm
183 * corresponds to a certain TxPower value in this MAC's region.
184 *
185 * @param txDbmForTxPower A vector that contains at position i the
186 * transmission power in dBm that should correspond to a TXPOWER value of i in
187 * this MAC's region.
188 */
189 void SetTxDbmForTxPower(std::vector<double> txDbmForTxPower);
190
191 /**
192 * Set the matrix to use when deciding with which data rate to respond. Region
193 * based.
194 *
195 * @param replyDataRateMatrix A matrix containing the reply DataRates, based
196 * on the sending data rate and on the value of the RX1DROffset parameter.
197 */
198 void SetReplyDataRateMatrix(ReplyDataRateMatrix replyDataRateMatrix);
199
200 /**
201 * Set the number of PHY preamble symbols this MAC is set to use.
202 *
203 * @param nPreambleSymbols The number of preamble symbols to use (typically 8).
204 */
205 void SetNPreambleSymbols(int nPreambleSymbols);
206
207 /**
208 * Get the number of PHY preamble symbols this MAC is set to use.
209 *
210 * @return The number of preamble symbols to use (typically 8).
211 */
212 int GetNPreambleSymbols() const;
213
214 protected:
215 /**
216 * The trace source that is fired when a packet cannot be sent because of duty
217 * cycle limitations.
218 */
220
221 /**
222 * Trace source that is fired when a packet reaches the MAC layer.
223 */
225
226 /**
227 * Trace source that is fired when a new APP layer packet arrives at the MAC
228 * layer.
229 */
231
232 /**
233 * The PHY instance that sits under this MAC layer.
234 */
236
237 /**
238 * The device this MAC layer is installed on.
239 */
241
242 /**
243 * The LogicalLoraChannelHelper instance that is assigned to this MAC.
244 */
246
247 /**
248 * A vector holding the spreading factor each data rate corresponds to.
249 */
250 std::vector<uint8_t> m_sfForDataRate;
251
252 /**
253 * A vector holding the bandwidth each data rate corresponds to.
254 */
255 std::vector<double> m_bandwidthForDataRate;
256
257 /**
258 * A vector holding the maximum MACPayload size that corresponds to a
259 * certain data rate. See, LoRaWAN RP002-1.0.4
260 */
261 std::vector<uint32_t> m_maxMacPayloadForDataRate;
262
263 /**
264 * The number of symbols to use in the PHY preamble.
265 */
267
268 /**
269 * A vector holding the power that corresponds to a certain TxPower value.
270 */
271 std::vector<double> m_txDbmForTxPower;
272
273 /**
274 * The matrix that decides the data rate the gateway will use in a reply based on the end
275 * device's sending data rate and on the value of the RX1DROffset parameter.
276 */
278};
279
280} // namespace lorawan
281} // namespace ns3
282
283#endif /* LORAWAN_MAC_H */
Object()
Caller graph was not generated because of its size.
Definition object.cc:93
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition type-id.h:50
Base class for PHY layers implementing the LoRa modulation scheme.
Definition lora-phy.h:81
std::vector< double > m_txDbmForTxPower
A vector holding the power that corresponds to a certain TxPower value.
TracedCallback< Ptr< const Packet > > m_cannotSendBecauseDutyCycle
The trace source that is fired when a packet cannot be sent because of duty cycle limitations.
std::vector< uint8_t > m_sfForDataRate
A vector holding the spreading factor each data rate corresponds to.
void SetSfForDataRate(std::vector< uint8_t > sfForDataRate)
Set the vector to use to check up correspondence between spreading factor and data rate.
LorawanMac()
Default constructor.
TracedCallback< Ptr< const Packet > > m_receivedPacket
Trace source that is fired when a packet reaches the MAC layer.
void SetDevice(Ptr< NetDevice > device)
Set the device this MAC layer is installed on.
virtual void FailedReception(Ptr< const Packet > packet)=0
Function called by lower layers to inform this layer that reception of a packet we were locked on fai...
void SetMaxMacPayloadForDataRate(std::vector< uint32_t > maxMacPayloadForDataRate)
Set the maximum LoRaWAN MACPayload size for a set data rate.
Ptr< LogicalLoraChannelHelper > GetLogicalLoraChannelHelper()
Get the logical lora channel helper associated with this MAC.
~LorawanMac() override
Destructor.
double GetDbmForTxPower(uint8_t txPower)
Get the transmission power in dBm that corresponds, in this region, to the encoded 8-bit txPower.
void SetPhy(Ptr< LoraPhy > phy)
Set the underlying PHY layer.
uint8_t GetSfFromDataRate(uint8_t dataRate)
Get the spreading factor corresponding to a data rate, based on this MAC's region.
double GetBandwidthFromDataRate(uint8_t dataRate)
Get the bandwidth corresponding to a data rate, based on this MAC's region.
void SetTxDbmForTxPower(std::vector< double > txDbmForTxPower)
Set the vector to use to check up which transmission power in Dbm corresponds to a certain TxPower va...
virtual void Send(Ptr< Packet > packet)=0
Send a packet.
ReplyDataRateMatrix m_replyDataRateMatrix
The matrix that decides the data rate the gateway will use in a reply based on the end device's sendi...
std::vector< uint32_t > m_maxMacPayloadForDataRate
A vector holding the maximum MACPayload size that corresponds to a certain data rate.
static TypeId GetTypeId()
Register this type.
virtual void Receive(Ptr< const Packet > packet)=0
Receive a packet from the lower layer.
void SetLogicalLoraChannelHelper(Ptr< LogicalLoraChannelHelper > helper)
Set the LogicalLoraChannelHelper this MAC instance will use.
Ptr< LogicalLoraChannelHelper > m_channelHelper
The LogicalLoraChannelHelper instance that is assigned to this MAC.
int GetNPreambleSymbols() const
Get the number of PHY preamble symbols this MAC is set to use.
Ptr< LoraPhy > GetPhy()
Get the underlying PHY layer.
virtual void TxFinished(Ptr< const Packet > packet)=0
Perform actions after sending a packet.
TracedCallback< Ptr< const Packet > > m_sentNewPacket
Trace source that is fired when a new APP layer packet arrives at the MAC layer.
Ptr< LoraPhy > m_phy
The PHY instance that sits under this MAC layer.
std::vector< double > m_bandwidthForDataRate
A vector holding the bandwidth each data rate corresponds to.
void SetNPreambleSymbols(int nPreambleSymbols)
Set the number of PHY preamble symbols this MAC is set to use.
void SetReplyDataRateMatrix(ReplyDataRateMatrix replyDataRateMatrix)
Set the matrix to use when deciding with which data rate to respond.
void SetBandwidthForDataRate(std::vector< double > bandwidthForDataRate)
Set the vector to use to check up correspondence between bandwidth and data rate.
Ptr< NetDevice > m_device
The device this MAC layer is installed on.
int m_nPreambleSymbols
The number of symbols to use in the PHY preamble.
Ptr< NetDevice > GetDevice()
Get the device this MAC layer is installed on.
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...
Definition lorawan-mac.h:52
Every class exported by the ns3 library is enclosed in the ns3 namespace.