lora-frame-header.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 
21 #ifndef LORA_FRAME_HEADER_H
22 #define LORA_FRAME_HEADER_H
23 
24 #include "lora-device-address.h"
25 #include "lorawan-mac-command.h"
26 
27 #include <ns3/header.h>
28 
29 namespace ns3
30 {
31 
44 class LoraFrameHeader : public Header
45 {
46  public:
49 
50  // Methods inherited from Header
51  static TypeId GetTypeId(void);
52  virtual TypeId GetInstanceTypeId(void) const;
53 
59  virtual uint32_t GetSerializedSize(void) const;
60 
69  virtual void Serialize(Buffer::Iterator start) const;
70 
77  virtual uint32_t Deserialize(Buffer::Iterator start);
78 
84  virtual void Print(std::ostream& os) const;
85 
92  void SetAsUplink(void);
93 
100  void SetAsDownlink(void);
101 
107  void SetFPort(uint8_t fPort);
108 
114  uint8_t GetFPort(void) const;
115 
121  void SetAddress(LoraDeviceAddress address);
122 
128  LoraDeviceAddress GetAddress(void) const;
129 
135  void SetAdr(bool adr);
136 
142  bool GetAdr(void) const;
143 
149  void SetAdrAckReq(bool adrAckReq);
150 
156  bool GetAdrAckReq(void) const;
157 
163  void SetAck(bool ack);
164 
170  bool GetAck(void) const;
171 
177  void SetFPending(bool fPending);
178 
184  bool GetFPending(void) const;
185 
194  uint8_t GetFOptsLen(void) const;
195 
201  void SetFCnt(uint16_t fCnt);
207  uint16_t GetFCnt(void) const;
208 
213  template <typename T>
214  inline Ptr<T> GetLorawanMacCommand(void);
215 
219  void AddLinkCheckReq(void);
220 
227  void AddLinkCheckAns(uint8_t margin, uint8_t gwCnt);
228 
238  void AddLinkAdrReq(uint8_t dataRate,
239  uint8_t txPower,
240  std::list<int> enabledChannels,
241  int repetitions);
242 
251  void AddLinkAdrAns(bool powerAck, bool dataRateAck, bool channelMaskAck);
252 
262  void AddDutyCycleReq(uint8_t dutyCycle);
263 
267  void AddDutyCycleAns(void);
268 
276  void AddRxParamSetupReq(uint8_t rx1DrOffset, uint8_t rx2DataRate, double frequency);
277 
281  void AddRxParamSetupAns();
282 
286  void AddDevStatusReq();
287 
291  void AddNewChannelReq(uint8_t chIndex,
292  double frequency,
293  uint8_t minDataRate,
294  uint8_t maxDataRate);
295 
299  std::list<Ptr<LorawanMacCommand>> GetCommands(void);
300 
304  void AddCommand(Ptr<LorawanMacCommand> macCommand);
305 
306  private:
307  uint8_t m_fPort;
308 
310 
311  bool m_adr;
313  bool m_ack;
315  uint8_t m_fOptsLen;
316 
317  uint16_t m_fCnt;
318 
319  Buffer m_fOpts;
320 
325  std::list<Ptr<LorawanMacCommand>> m_macCommands;
326 
328 };
329 
330 template <typename T>
331 Ptr<T>
333 {
334  // Iterate on MAC commands and try casting
335  std::list<Ptr<LorawanMacCommand>>::const_iterator it;
336  for (it = m_macCommands.begin(); it != m_macCommands.end(); ++it)
337  {
338  if ((*it)->GetObject<T>() != nullptr)
339  {
340  return (*it)->GetObject<T>();
341  }
342  }
343 
344  // If no command was found, return 0
345  return 0;
346 }
347 } // namespace ns3
348 
349 #endif
This class represents the device address of a LoraWAN End Device.
This class represents the Frame header (FHDR) used in a LoraWAN network.
void SetAddress(LoraDeviceAddress address)
Set the address.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the contents of the buffer into a LoraFrameHeader object.
void AddDevStatusReq()
Add a DevStatusReq command.
virtual TypeId GetInstanceTypeId(void) const
void AddLinkAdrReq(uint8_t dataRate, uint8_t txPower, std::list< int > enabledChannels, int repetitions)
Add a LinkAdrReq command.
void SetAsUplink(void)
State that this is an uplink message.
void SetAck(bool ack)
Set the Ack bit.
bool GetFPending(void) const
Get the FPending value.
uint8_t GetFOptsLen(void) const
Get the FOptsLen value.
void AddCommand(Ptr< LorawanMacCommand > macCommand)
Add a predefined command to the list.
bool GetAdr(void) const
Get the Adr value.
void SetFCnt(uint16_t fCnt)
Set the FCnt value.
void SetAdrAckReq(bool adrAckReq)
Set the AdrAckReq value.
virtual void Serialize(Buffer::Iterator start) const
Serialize the header.
bool GetAck(void) const
Get the Ack bit value.
bool GetAdrAckReq(void) const
Get the AdrAckReq value.
void AddLinkAdrAns(bool powerAck, bool dataRateAck, bool channelMaskAck)
Add a LinkAdrAns command.
virtual void Print(std::ostream &os) const
Print the header in a human-readable format.
void SetFPending(bool fPending)
Set the FPending value.
static TypeId GetTypeId(void)
LoraDeviceAddress m_address
std::list< Ptr< LorawanMacCommand > > GetCommands(void)
Return a list of pointers to all the MAC commands saved in this header.
void AddLinkCheckReq(void)
Add a LinkCheckReq command.
uint8_t GetFPort(void) const
Get the FPort value.
void AddDutyCycleAns(void)
Add a DutyCycleAns command.
std::list< Ptr< LorawanMacCommand > > m_macCommands
List containing all the LorawanMacCommand instances that are contained in this LoraFrameHeader.
virtual uint32_t GetSerializedSize(void) const
Return the size required for serialization of this header.
void AddRxParamSetupAns()
Add a RxParamSetupAns command.
void SetAdr(bool adr)
Set the Adr value.
uint16_t GetFCnt(void) const
Get the FCnt value.
void AddNewChannelReq(uint8_t chIndex, double frequency, uint8_t minDataRate, uint8_t maxDataRate)
Add a NewChannelReq command.
void AddDutyCycleReq(uint8_t dutyCycle)
Add a DutyCycleReq command.
void SetFPort(uint8_t fPort)
Set the FPort value.
void SetAsDownlink(void)
State that this is a downlink message.
Ptr< T > GetLorawanMacCommand(void)
Return a pointer to a LorawanMacCommand, or 0 if the LorawanMacCommand does not exist in this header.
LoraDeviceAddress GetAddress(void) const
Get this header's device address value.
void AddRxParamSetupReq(uint8_t rx1DrOffset, uint8_t rx2DataRate, double frequency)
Add a RxParamSetupReq command.
void AddLinkCheckAns(uint8_t margin, uint8_t gwCnt)
Add a LinkCheckAns command.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.