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 #include <list>
40 #include <stdint.h>
41 #include <vector>
42 
43 namespace ns3
44 {
45 
50 {
51  public:
52  static TypeId GetTypeId(void);
53 
55  LorawanMacEndDevice(Ptr<Node> node, uint32_t satId, uint32_t beamId);
56  virtual ~LorawanMacEndDevice();
57 
59  // Sending methods //
61 
69  virtual void Send(Ptr<Packet> packet);
70 
77  virtual void DoSend(Ptr<Packet> packet);
78 
84  virtual void SendToPhy(Ptr<Packet> packet);
85 
92  virtual void postponeTransmission(Time nextTxDelay, Ptr<Packet>);
93 
95  // Receiving methods //
97 
106  virtual void Receive(Ptr<Packet> packet) = 0;
107  virtual void Receive(SatPhy::PacketContainer_t packets, Ptr<SatSignalParameters> /*rxParams*/);
108 
109  virtual void FailedReception(Ptr<const Packet> packet);
110 
116  virtual void TxFinished();
117 
119  // Getters and Setters //
121 
125  virtual void resetRetransmissionParameters();
126 
132  void SetDataRateAdaptation(bool adapt);
133 
137  bool GetDataRateAdaptation(void);
138 
144  void SetMaxNumberOfTransmissions(uint8_t maxNumbTx);
145 
149  uint8_t GetMaxNumberOfTransmissions(void);
150 
158  void SetDataRate(uint8_t dataRate);
159 
165  uint8_t GetDataRate(void);
166 
172  virtual uint8_t GetTransmissionPower(void);
173 
179  void SetDeviceAddress(LoraDeviceAddress address);
180 
187 
197  // void SetRx1DrOffset (uint8_t rx1DrOffset);
198 
204  // uint8_t GetRx1DrOffset (void);
205 
212  double GetAggregatedDutyCycle(void);
213 
215  // MAC command methods //
217 
223  void ApplyNecessaryOptions(LoraFrameHeader& frameHeader);
224 
230  void ApplyNecessaryOptions(LorawanMacHeader& macHeader);
231 
235  void SetMType(LorawanMacHeader::MType mType);
236 
241 
245  void ParseCommands(LoraFrameHeader frameHeader);
246 
253  void OnLinkCheckAns(uint8_t margin, uint8_t gwCnt);
254 
263  void OnLinkAdrReq(uint8_t dataRate,
264  uint8_t txPower,
265  std::list<int> enabledChannels,
266  int repetitions);
267 
274  void OnDutyCycleReq(double dutyCycle);
275 
281  void OnRxParamSetupReq(Ptr<RxParamSetupReq> rxParamSetupReq);
282 
289  virtual void OnRxClassParamSetupReq(Ptr<RxParamSetupReq> rxParamSetupReq);
290 
294  void OnDevStatusReq(void);
295 
299  void OnNewChannelReq(uint8_t chIndex,
300  double frequency,
301  uint8_t minDataRate,
302  uint8_t maxDataRate);
303 
305  // Logical channel administration //
307 
313  void AddLogicalChannel(double frequency);
314 
323  void SetLogicalChannel(uint8_t chIndex,
324  double frequency,
325  uint8_t minDataRate,
326  uint8_t maxDataRate);
327 
333  void AddLogicalChannel(Ptr<LoraLogicalChannel> logicalChannel);
334 
343  void AddLoraSubBand(double startFrequency,
344  double endFrequency,
345  double dutyCycle,
346  double maxTxPowerDbm);
347 
352  void AddLorawanMacCommand(Ptr<LorawanMacCommand> macCommand);
353 
358  typedef Callback<void, Mac48Address> GatewayUpdateCallback;
359 
365 
370  typedef Callback<void, uint32_t, uint32_t> HandoverCallback;
371 
377 
381  typedef Callback<void, Ptr<Node>> UpdateAddressAndIdentifierCallback;
382 
389 
395  void SetGwAddress(Mac48Address gwAddress);
396 
402  void SetSatAddress(Mac48Address satAddress);
403 
409  void SetRegenerative(bool isRegenerative);
410 
416  void SetRaChannel(uint32_t raChannel);
417 
418  void SetPhyRx(Ptr<SatLoraPhyRx> phyRx);
419 
420  Ptr<SatLoraPhyRx> GetPhyRx();
421 
427  void ChangeBeam(uint32_t satId, uint32_t beamId);
428 
429  protected:
435  {
437  Ptr<Packet> packet = 0;
438  bool waitingAck = false;
439  uint8_t retxLeft;
440  };
441 
445  Ptr<Node> m_node;
446 
451 
455  uint8_t m_maxNumbTx;
456 
460  TracedValue<uint8_t> m_dataRate;
461 
465  TracedValue<double> m_txPower;
466 
470  uint8_t m_codingRate;
471 
476 
481 
487  bool CheckHandovers();
488 
493  virtual Time GetNextClassTransmissionDelay(Time waitingTime);
494 
500  Ptr<LoraLogicalChannel> GetChannelForTx(void);
501 
513 
517  std::list<Ptr<LorawanMacCommand>> m_macCommandList;
518 
519  /* Structure containing the retransmission parameters
520  * for this device.
521  */
523 
528  Ptr<UniformRandomVariable> m_uniformRV;
529 
531  // Callbacks //
533 
539  TracedCallback<uint8_t, bool, Time, Ptr<Packet>> m_requiredTxCallback;
540 
545 
549  Mac48Address m_gwAddress;
550 
554  uint32_t m_raChannel;
555 
559  Ptr<SatLoraPhyRx> m_phyRx;
560 
565 
566  private:
572  std::vector<Ptr<LoraLogicalChannel>> Shuffle(std::vector<Ptr<LoraLogicalChannel>> vector);
573 
577  Time GetNextTransmissionDelay(void);
578 
583 
590  EventId m_nextTx;
591 
599  EventId m_nextRetx;
600 
607  TracedValue<double> m_lastKnownLinkMargin;
608 
616  TracedValue<int> m_lastKnownGatewayCount;
617 
621  TracedValue<double> m_aggregatedDutyCycle;
622 
627 
628  uint16_t m_currentFCnt;
629 
634 
639 };
640 
641 } /* namespace ns3 */
642 
643 #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 SetSatAddress(Mac48Address satAddress)
Set address of the Lorawan GW (or its MAC) serving this UT.
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.
void SetHandoverCallback(LorawanMacEndDevice::HandoverCallback cb)
Method to set handover callback.
Callback< void, uint32_t, uint32_t > HandoverCallback
Callback to reconfigure physical layer during 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 SetRegenerative(bool isRegenerative)
Set if associated satellite is regenerative.
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.
Mac48Address m_gwAddress
Gateway address used in case of transparent satellite.
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.
void SetUpdateAddressAndIdentifierCallback(LorawanMacEndDevice::UpdateAddressAndIdentifierCallback cb)
Set the callback to update addresses in statistics helpers.
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.
Callback< void, Ptr< Node > > UpdateAddressAndIdentifierCallback
Callback to update addresses in statistics helpers.
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 ChangeBeam(uint32_t satId, uint32_t beamId)
Method handling beam handover.
Ptr< Node > m_node
Node containing this MAC.
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.
bool CheckHandovers()
Check for UT handovers and perform it if necessary.
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_isRegenerative
Tell if satellite is regenerative.
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.
LorawanMacEndDevice::UpdateAddressAndIdentifierCallback m_updateAddressAndIdentifierCallback
Callback to update addresses in statistics helpers.
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.
LorawanMacEndDevice::HandoverCallback m_handoverCallback
The physical layer handover callback.
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:49
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 representing the parameters that will be used in the retransmission procedure.