lorawan-mac.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2017 University of Padova
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Davide Magrin <magrinda@dei.unipd.it>
19  *
20  * Modified by: Bastien Tauran <bastien.tauran@viveris.fr>
21  */
22 
23 #ifndef LORAWAN_MAC_H
24 #define LORAWAN_MAC_H
25 
27 #include "satellite-lora-phy-rx.h"
28 #include "satellite-mac.h"
29 #include "satellite-phy.h"
30 
31 #include <ns3/object.h>
32 #include <ns3/packet.h>
33 
34 #include <array>
35 #include <stdint.h>
36 #include <vector>
37 
38 namespace ns3
39 {
40 
48 class LorawanMac : public SatMac
49 {
50  public:
51  static TypeId GetTypeId(void);
52 
53  LorawanMac();
54  LorawanMac(uint32_t satId, uint32_t beamId);
55  virtual ~LorawanMac();
56 
57  typedef std::array<std::array<uint8_t, 6>, 8> ReplyDataRateMatrix;
58 
64  Ptr<SatPhy> GetPhy(void);
65 
71  void SetPhy(Ptr<SatPhy> phy);
72 
78  Ptr<SatLoraPhyTx> GetPhyTx(void);
79 
85  void SetPhyTx(Ptr<SatLoraPhyTx> phyTx);
86 
92  virtual void Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
93 
99  virtual void Send(Ptr<Packet> packet) = 0;
100 
106  virtual void Receive(SatPhy::PacketContainer_t packets,
107  Ptr<SatSignalParameters> /*rxParams*/) = 0;
108 
115  virtual void FailedReception(Ptr<const Packet> packet) = 0;
116 
120  virtual void TxFinished() = 0;
121 
127  void SetDevice(Ptr<NetDevice> device);
128 
134  Ptr<NetDevice> GetDevice(void);
135 
142 
149 
158  uint8_t GetSfFromDataRate(uint8_t dataRate);
159 
167  double GetBandwidthFromDataRate(uint8_t dataRate);
168 
178  double GetDbmForTxPower(uint8_t txPower);
179 
192  Time GetOnAirTime(Ptr<Packet> packet, LoraTxParameters txParams);
193 
200  void SetSfForDataRate(std::vector<uint8_t> sfForDataRate);
201 
209  void SetBandwidthForDataRate(std::vector<double> bandwidthForDataRate);
210 
218  void SetMaxAppPayloadForDataRate(std::vector<uint32_t> maxAppPayloadForDataRate);
219 
228  void SetTxDbmForTxPower(std::vector<double> txDbmForTxPower);
229 
237  void SetReplyDataRateMatrix(ReplyDataRateMatrix replyDataRateMatrix);
238 
244  void SetNPreambleSymbols(int nPreambleSymbols);
245 
251  int GetNPreambleSymbols(void);
252 
256  void setRegenerative(bool isRegenerative);
257 
258  protected:
265  TracedCallback<Ptr<const Packet>> m_cannotSendBecauseDutyCycle;
266 
270  TracedCallback<Ptr<const Packet>> m_receivedPacket;
271 
276  TracedCallback<Ptr<const Packet>> m_sentNewPacket;
277 
281  Ptr<SatPhy> m_phy;
282 
286  Ptr<NetDevice> m_device;
287 
292 
296  std::vector<uint8_t> m_sfForDataRate;
297 
301  std::vector<double> m_bandwidthForDataRate;
302 
307  std::vector<uint32_t> m_maxAppPayloadForDataRate;
308 
313 
317  std::vector<double> m_txDbmForTxPower;
318 
324 
328  uint32_t m_beamId;
329 
334 };
335 
336 } /* namespace ns3 */
337 
338 #endif /* LORAWAN_MAC_H */
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:49
TracedCallback< Ptr< const Packet > > m_receivedPacket
Trace source that is fired when a packet reaches the MAC layer.
Definition: lorawan-mac.h:270
ReplyDataRateMatrix m_replyDataRateMatrix
The matrix that decides the DR the GW will use in a reply based on the ED's sending DR and on the val...
Definition: lorawan-mac.h:323
void SetReplyDataRateMatrix(ReplyDataRateMatrix replyDataRateMatrix)
Set the matrix to use when deciding with which DataRate to respond.
Definition: lorawan-mac.cc:256
virtual ~LorawanMac()
Definition: lorawan-mac.cc:76
virtual void Send(Ptr< Packet > packet)=0
Send a packet.
std::vector< uint32_t > m_maxAppPayloadForDataRate
A vector holding the maximum app payload size that corresponds to a certain DataRate.
Definition: lorawan-mac.h:307
std::vector< double > m_bandwidthForDataRate
A vector holding the bandwidth each Data Rate corresponds to.
Definition: lorawan-mac.h:301
int m_nPreambleSymbols
The number of symbols to use in the PHY preamble.
Definition: lorawan-mac.h:312
int GetNPreambleSymbols(void)
Get the number of PHY preamble symbols this MAC is set to use.
Definition: lorawan-mac.cc:243
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:231
Time GetOnAirTime(Ptr< Packet > packet, LoraTxParameters txParams)
Compute the time that a packet with certain characteristics will take to be transmitted.
Definition: lorawan-mac.cc:169
uint32_t m_beamId
ID of beam for UT.
Definition: lorawan-mac.h:328
Ptr< SatPhy > GetPhy(void)
Get the underlying PHY layer.
Definition: lorawan-mac.cc:100
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:265
bool m_isRegenerative
Indicates if satellite is regenerative on the link where this layer is sending packets.
Definition: lorawan-mac.h:333
Ptr< SatPhy > m_phy
The PHY instance that sits under this MAC layer.
Definition: lorawan-mac.h:281
virtual void Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
Send a packet.
Definition: lorawan-mac.cc:82
void SetBandwidthForDataRate(std::vector< double > bandwidthForDataRate)
Set the vector to use to check up correspondence between bandwidth and DataRate.
Definition: lorawan-mac.cc:219
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...
static TypeId GetTypeId(void)
Definition: lorawan-mac.cc:39
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:276
void SetSfForDataRate(std::vector< uint8_t > sfForDataRate)
Set the vector to use to check up correspondence between SF and DataRate.
Definition: lorawan-mac.cc:213
void SetMaxAppPayloadForDataRate(std::vector< uint32_t > maxAppPayloadForDataRate)
Set the maximum App layer payload for a set DataRate.
Definition: lorawan-mac.cc:225
uint8_t GetSfFromDataRate(uint8_t dataRate)
Get the SF corresponding to a data rate, based on this MAC's region.
Definition: lorawan-mac.cc:128
void SetPhyTx(Ptr< SatLoraPhyTx > phyTx)
Set the underlying PHY TX layer.
Ptr< NetDevice > GetDevice(void)
Get the device this MAC layer is installed on.
Definition: lorawan-mac.cc:94
Ptr< NetDevice > m_device
The device this MAC layer is installed on.
Definition: lorawan-mac.h:286
LoraLogicalChannelHelper GetLoraLogicalChannelHelper(void)
Get the logical lora channel helper associated with this MAC.
Definition: lorawan-mac.cc:116
std::vector< double > m_txDbmForTxPower
A vector holding the power that corresponds to a certain TxPower value.
Definition: lorawan-mac.h:317
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:156
virtual void Receive(SatPhy::PacketContainer_t packets, Ptr< SatSignalParameters >)=0
Receive a packet from the lower layer.
Ptr< SatLoraPhyTx > GetPhyTx(void)
Get the underlying PHY TX layer.
void SetNPreambleSymbols(int nPreambleSymbols)
Set the number of PHY preamble symbols this MAC is set to use.
Definition: lorawan-mac.cc:237
void SetLoraLogicalChannelHelper(LoraLogicalChannelHelper helper)
Set the LoraLogicalChannelHelper this MAC instance will use.
Definition: lorawan-mac.cc:122
void SetPhy(Ptr< SatPhy > phy)
Set the underlying PHY layer.
Definition: lorawan-mac.cc:106
void SetDevice(Ptr< NetDevice > device)
Set the device this MAC layer is installed on.
Definition: lorawan-mac.cc:88
LoraLogicalChannelHelper m_channelHelper
The LoraLogicalChannelHelper instance that is assigned to this MAC.
Definition: lorawan-mac.h:291
void setRegenerative(bool isRegenerative)
Indicates if the satellite is regenerative on the link this layer is sending packets.
Definition: lorawan-mac.cc:249
std::vector< uint8_t > m_sfForDataRate
A vector holding the SF each Data Rate corresponds to.
Definition: lorawan-mac.h:296
virtual void TxFinished()=0
Perform actions after sending a packet.
double GetBandwidthFromDataRate(uint8_t dataRate)
Get the BW corresponding to a data rate, based on this MAC's region.
Definition: lorawan-mac.cc:142
std::array< std::array< uint8_t, 6 >, 8 > ReplyDataRateMatrix
Definition: lorawan-mac.h:57
Base MAC class for SatNetDevices.
Definition: satellite-mac.h:57
SatSignalParameters::PacketsInBurst_t PacketContainer_t
Define PacketContainer in SatPhy.
Definition: satellite-phy.h:79
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
Structure to collect all parameters that are used to compute the duration of a packet (excluding payl...