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