lorawan-mac-end-device.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  * Martina Capuzzo <capuzzom@dei.unipd.it>
20  *
21  * Modified by: Peggy Anderson <peggy.anderson@usask.ca>
22  * Bastien Tauran <bastien.tauran@viveris.fr>
23  */
24 
25 #ifndef LORAWAN_MAC_END_DEVICE_H
26 #define LORAWAN_MAC_END_DEVICE_H
27 
28 #include "lora-device-address.h"
29 #include "lora-frame-header.h"
31 #include "lora-logical-channel.h"
32 #include "lorawan-mac-header.h"
33 #include "lorawan-mac.h"
34 #include "satellite-ut-mac.h"
35 
36 #include <ns3/random-variable-stream.h>
37 #include <ns3/traced-value.h>
38 
39 namespace ns3
40 {
41 
46 {
47  public:
48  static TypeId GetTypeId(void);
49 
51  LorawanMacEndDevice(uint32_t satId, uint32_t beamId);
52  virtual ~LorawanMacEndDevice();
53 
55  // Sending methods //
57 
65  virtual void Send(Ptr<Packet> packet);
66 
73  virtual void DoSend(Ptr<Packet> packet);
74 
80  virtual void SendToPhy(Ptr<Packet> packet);
81 
88  virtual void postponeTransmission(Time nextTxDelay, Ptr<Packet>);
89 
91  // Receiving methods //
93 
102  virtual void Receive(Ptr<Packet> packet) = 0;
103  virtual void Receive(SatPhy::PacketContainer_t packets, Ptr<SatSignalParameters> /*rxParams*/);
104 
105  virtual void FailedReception(Ptr<const Packet> packet);
106 
112  virtual void TxFinished();
113 
115  // Getters and Setters //
117 
121  virtual void resetRetransmissionParameters();
122 
128  void SetDataRateAdaptation(bool adapt);
129 
133  bool GetDataRateAdaptation(void);
134 
140  void SetMaxNumberOfTransmissions(uint8_t maxNumbTx);
141 
145  uint8_t GetMaxNumberOfTransmissions(void);
146 
154  void SetDataRate(uint8_t dataRate);
155 
161  uint8_t GetDataRate(void);
162 
168  virtual uint8_t GetTransmissionPower(void);
169 
175  void SetDeviceAddress(LoraDeviceAddress address);
176 
183 
193  // void SetRx1DrOffset (uint8_t rx1DrOffset);
194 
200  // uint8_t GetRx1DrOffset (void);
201 
208  double GetAggregatedDutyCycle(void);
209 
211  // MAC command methods //
213 
219  void ApplyNecessaryOptions(LoraFrameHeader& frameHeader);
220 
226  void ApplyNecessaryOptions(LorawanMacHeader& macHeader);
227 
231  void SetMType(LorawanMacHeader::MType mType);
232 
237 
241  void ParseCommands(LoraFrameHeader frameHeader);
242 
249  void OnLinkCheckAns(uint8_t margin, uint8_t gwCnt);
250 
259  void OnLinkAdrReq(uint8_t dataRate,
260  uint8_t txPower,
261  std::list<int> enabledChannels,
262  int repetitions);
263 
270  void OnDutyCycleReq(double dutyCycle);
271 
277  void OnRxParamSetupReq(Ptr<RxParamSetupReq> rxParamSetupReq);
278 
285  virtual void OnRxClassParamSetupReq(Ptr<RxParamSetupReq> rxParamSetupReq);
286 
290  void OnDevStatusReq(void);
291 
295  void OnNewChannelReq(uint8_t chIndex,
296  double frequency,
297  uint8_t minDataRate,
298  uint8_t maxDataRate);
299 
301  // Logical channel administration //
303 
309  void AddLogicalChannel(double frequency);
310 
319  void SetLogicalChannel(uint8_t chIndex,
320  double frequency,
321  uint8_t minDataRate,
322  uint8_t maxDataRate);
323 
329  void AddLogicalChannel(Ptr<LoraLogicalChannel> logicalChannel);
330 
339  void AddLoraSubBand(double startFrequency,
340  double endFrequency,
341  double dutyCycle,
342  double maxTxPowerDbm);
343 
348  void AddLorawanMacCommand(Ptr<LorawanMacCommand> macCommand);
349 
354  typedef Callback<void, Mac48Address> GatewayUpdateCallback;
355 
361 
367  void SetGwAddress(Mac48Address gwAddress);
368 
374  void SetRaChannel(uint32_t raChannel);
375 
376  void SetPhyRx(Ptr<SatLoraPhyRx> phyRx);
377 
378  Ptr<SatLoraPhyRx> GetPhyRx();
379 
380  protected:
386  {
388  Ptr<Packet> packet = 0;
389  bool waitingAck = false;
390  uint8_t retxLeft;
391  };
392 
397 
401  uint8_t m_maxNumbTx;
402 
406  TracedValue<uint8_t> m_dataRate;
407 
411  TracedValue<double> m_txPower;
412 
416  uint8_t m_codingRate;
417 
422 
427 
432  virtual Time GetNextClassTransmissionDelay(Time waitingTime);
433 
439  Ptr<LoraLogicalChannel> GetChannelForTx(void);
440 
452 
456  std::list<Ptr<LorawanMacCommand>> m_macCommandList;
457 
458  /* Structure containing the retransmission parameters
459  * for this device.
460  */
462 
467  Ptr<UniformRandomVariable> m_uniformRV;
468 
470  // Callbacks //
472 
478  TracedCallback<uint8_t, bool, Time, Ptr<Packet>> m_requiredTxCallback;
479 
484 
485  Mac48Address m_gwAddress;
486 
490  uint32_t m_raChannel;
491 
495  Ptr<SatLoraPhyRx> m_phyRx;
496 
497  private:
503  std::vector<Ptr<LoraLogicalChannel>> Shuffle(std::vector<Ptr<LoraLogicalChannel>> vector);
504 
508  Time GetNextTransmissionDelay(void);
509 
514 
521  EventId m_nextTx;
522 
530  EventId m_nextRetx;
531 
538  TracedValue<double> m_lastKnownLinkMargin;
539 
547  TracedValue<int> m_lastKnownGatewayCount;
548 
552  TracedValue<double> m_aggregatedDutyCycle;
553 
558 
559  uint16_t m_currentFCnt;
560 };
561 
562 } /* namespace ns3 */
563 
564 #endif /* LORAWAN_MAC_END_DEVICE_H */
This class represents the device address of a LoraWAN End Device.
This class represents the Frame header (FHDR) used in a LoraWAN network.
Class representing the MAC layer of a LoRaWAN device.
void SetDeviceAddress(LoraDeviceAddress address)
Set the network address of this device.
Time GetNextTransmissionDelay(void)
Find the minimum waiting time before the next possible transmission.
std::list< Ptr< LorawanMacCommand > > m_macCommandList
List of the MAC commands that need to be applied to the next UL packet.
uint8_t GetDataRate(void)
Get the data rate this end device is set to use.
void OnNewChannelReq(uint8_t chIndex, double frequency, uint8_t minDataRate, uint8_t maxDataRate)
Perform the actions that need to be taken when receiving a NewChannelReq command.
uint8_t GetMaxNumberOfTransmissions(void)
Set the maximum number of transmissions allowed.
bool m_enableDRAdapt
Enable Data Rate adaptation during the retransmission procedure.
EventId m_nextTx
The event of retransmitting a packet in a consecutive moment if an ACK is not received.
virtual void FailedReception(Ptr< const Packet > packet)
Function called by lower layers to inform this layer that reception of a packet we were locked on fai...
TracedValue< double > m_txPower
The transmission power this device is using to transmit.
TracedCallback< uint8_t, bool, Time, Ptr< Packet > > m_requiredTxCallback
The trace source fired when the transmission procedure is finished.
LorawanMacHeader::MType m_mType
The message type to apply to packets sent with the Send method.
void OnLinkCheckAns(uint8_t margin, uint8_t gwCnt)
Perform the actions that need to be taken when receiving a LinkCheckAns command.
Callback< void, Mac48Address > GatewayUpdateCallback
Callback to update gateway address after handover.
LorawanMacHeader::MType GetMType(void)
Get the message type to send when the Send method is called.
virtual void DoSend(Ptr< Packet > packet)
Checking if we are performing the transmission of a new packet or a retransmission,...
void SetMType(LorawanMacHeader::MType mType)
Set the message type to send when the Send method is called.
bool GetDataRateAdaptation(void)
Get if data rate adaptation is enabled or not.
TracedValue< double > m_aggregatedDutyCycle
The aggregated duty cycle this device needs to respect across all sub-bands.
virtual void postponeTransmission(Time nextTxDelay, Ptr< Packet >)
Postpone transmission to the specified time and delete previously scheduled transmissions if present.
LorawanMacEndDevice::GatewayUpdateCallback m_gatewayUpdateCallback
Gateway address update callback.
void SetPhyRx(Ptr< SatLoraPhyRx > phyRx)
Ptr< LoraLogicalChannel > GetChannelForTx(void)
Find a suitable channel for transmission.
Ptr< SatLoraPhyRx > m_phyRx
Reception phy layer for Lora operations.
double GetAggregatedDutyCycle(void)
Set a value for the RX1DROffset parameter.
TracedValue< double > m_lastKnownLinkMargin
The last known link margin.
uint8_t m_receiveWindowDurationInSymbols
The duration of a receive window in number of symbols.
uint8_t m_maxNumbTx
Maximum number of transmission allowed.
bool m_controlDataRate
Whether this device's data rate should be controlled by the NS.
uint32_t m_raChannel
RA channel assigned to the UT.
virtual void SendToPhy(Ptr< Packet > packet)
Add headers and send a packet with the sending function of the physical layer.
uint8_t m_codingRate
The coding rate used by this device.
Ptr< SatLoraPhyRx > GetPhyRx()
void SetDataRateAdaptation(bool adapt)
Enable data rate adaptation in the retransmitting procedure.
void OnDevStatusReq(void)
Perform the actions that need to be taken when receiving a DevStatusReq command.
Ptr< UniformRandomVariable > m_uniformRV
An uniform random variable, used by the Shuffle method to randomly reorder the channel list.
virtual void Send(Ptr< Packet > packet)
Send a packet.
void SetDataRate(uint8_t dataRate)
Set the data rate this end device will use when transmitting.
void AddLogicalChannel(double frequency)
Add a logical channel to the helper.
void OnLinkAdrReq(uint8_t dataRate, uint8_t txPower, std::list< int > enabledChannels, int repetitions)
Perform the actions that need to be taken when receiving a LinkAdrReq command.
void AddLorawanMacCommand(Ptr< LorawanMacCommand > macCommand)
Add a MAC command to the list of those that will be sent out in the next packet.
void AddLoraSubBand(double startFrequency, double endFrequency, double dutyCycle, double maxTxPowerDbm)
Add a subband to the logical channel helper.
void SetLogicalChannel(uint8_t chIndex, double frequency, uint8_t minDataRate, uint8_t maxDataRate)
Set a new logical channel in the helper.
void SetRaChannel(uint32_t raChannel)
Set RA channel assigned for this UT.
TracedValue< uint8_t > m_dataRate
The DataRate this device is using to transmit.
LoraDeviceAddress GetDeviceAddress(void)
Get the network address of this device.
TracedValue< int > m_lastKnownGatewayCount
The last known gateway count (i.e., gateways that are in communication range with this end device)
virtual void TxFinished()
Perform the actions that are required after a packet send.
void ParseCommands(LoraFrameHeader frameHeader)
Parse and take action on the commands contained on this FrameHeader.
void SetGwAddress(Mac48Address gwAddress)
Set address of the GW (or its MAC) serving this UT.
std::vector< Ptr< LoraLogicalChannel > > Shuffle(std::vector< Ptr< LoraLogicalChannel >> vector)
Randomly shuffle a Ptr<LoraLogicalChannel> vector.
virtual void resetRetransmissionParameters()
Reset retransmission parameters contained in the structure LoraRetxParams.
virtual uint8_t GetTransmissionPower(void)
Get the transmission power this end device is set to use.
bool m_headerDisabled
Whether or not the header is disabled for communications by this device.
void SetGatewayUpdateCallback(LorawanMacEndDevice::GatewayUpdateCallback cb)
Method to set the gateway address update callback.
LoraDeviceAddress m_address
The address of this device.
struct LoraRetxParameters m_retxParams
void ApplyNecessaryOptions(LoraFrameHeader &frameHeader)
Add the necessary options and MAC commands to the LoraFrameHeader.
virtual void Receive(Ptr< Packet > packet)=0
Receive a packet.
virtual void OnRxClassParamSetupReq(Ptr< RxParamSetupReq > rxParamSetupReq)
Perform the actions that need to be taken when receiving a RxParamSetupReq command based on the Devic...
virtual Time GetNextClassTransmissionDelay(Time waitingTime)
Find the minimum waiting time before the next possible transmission based on End Device's Class Type.
void OnDutyCycleReq(double dutyCycle)
Perform the actions that need to be taken when receiving a DutyCycleReq command.
void OnRxParamSetupReq(Ptr< RxParamSetupReq > rxParamSetupReq)
Perform the actions that need to be taken when receiving a RxParamSetupReq command.
EventId m_nextRetx
The event of transmitting a packet in a consecutive moment, when the duty cycle let us transmit.
void SetMaxNumberOfTransmissions(uint8_t maxNumbTx)
Set the maximum number of transmissions allowed.
This class represents the Mac header of a LoRaWAN packet.
MType
The message type.
Class representing the LoRaWAN MAC layer.
Definition: lorawan-mac.h:47
SatSignalParameters::PacketsInBurst_t PacketContainer_t
Define PacketContainer in SatPhy.
Definition: satellite-phy.h:78
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
Structure representing the parameters that will be used in the retransmission procedure.