Loading...
Searching...
No Matches
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#include <list>
30#include <ostream>
31#include <stdint.h>
32
33namespace ns3
34{
35
48class LoraFrameHeader : public Header
49{
50 public:
53
54 // Methods inherited from Header
55 static TypeId GetTypeId(void);
56 virtual TypeId GetInstanceTypeId(void) const;
57
63 virtual uint32_t GetSerializedSize(void) const;
64
73 virtual void Serialize(Buffer::Iterator start) const;
74
81 virtual uint32_t Deserialize(Buffer::Iterator start);
82
88 virtual void Print(std::ostream& os) const;
89
96 void SetAsUplink(void);
97
104 void SetAsDownlink(void);
105
111 void SetFPort(uint8_t fPort);
112
118 uint8_t GetFPort(void) const;
119
125 void SetAddress(LoraDeviceAddress address);
126
132 LoraDeviceAddress GetAddress(void) const;
133
139 void SetAdr(bool adr);
140
146 bool GetAdr(void) const;
147
153 void SetAdrAckReq(bool adrAckReq);
154
160 bool GetAdrAckReq(void) const;
161
167 void SetAck(bool ack);
168
174 bool GetAck(void) const;
175
181 void SetFPending(bool fPending);
182
188 bool GetFPending(void) const;
189
198 uint8_t GetFOptsLen(void) const;
199
205 void SetFCnt(uint16_t fCnt);
211 uint16_t GetFCnt(void) const;
212
217 template <typename T>
218 inline Ptr<T> GetLorawanMacCommand(void);
219
223 void AddLinkCheckReq(void);
224
231 void AddLinkCheckAns(uint8_t margin, uint8_t gwCnt);
232
242 void AddLinkAdrReq(uint8_t dataRate,
243 uint8_t txPower,
244 std::list<int> enabledChannels,
245 int repetitions);
246
255 void AddLinkAdrAns(bool powerAck, bool dataRateAck, bool channelMaskAck);
256
266 void AddDutyCycleReq(uint8_t dutyCycle);
267
271 void AddDutyCycleAns(void);
272
280 void AddRxParamSetupReq(uint8_t rx1DrOffset, uint8_t rx2DataRate, double frequency);
281
285 void AddRxParamSetupAns();
286
290 void AddDevStatusReq();
291
295 void AddNewChannelReq(uint8_t chIndex,
296 double frequency,
297 uint8_t minDataRate,
298 uint8_t maxDataRate);
299
303 std::list<Ptr<LorawanMacCommand>> GetCommands(void);
304
308 void AddCommand(Ptr<LorawanMacCommand> macCommand);
309
310 private:
311 uint8_t m_fPort;
312
314
315 bool m_adr;
317 bool m_ack;
319 uint8_t m_fOptsLen;
320
321 uint16_t m_fCnt;
322
323 Buffer m_fOpts;
324
329 std::list<Ptr<LorawanMacCommand>> m_macCommands;
330
332};
333
334template <typename T>
335Ptr<T>
337{
338 // Iterate on MAC commands and try casting
339 std::list<Ptr<LorawanMacCommand>>::const_iterator it;
340 for (it = m_macCommands.begin(); it != m_macCommands.end(); ++it)
341 {
342 if ((*it)->GetObject<T>() != nullptr)
343 {
344 return (*it)->GetObject<T>();
345 }
346 }
347
348 // If no command was found, return 0
349 return 0;
350}
351} // namespace ns3
352
353#endif
This class represents the device address of a LoraWAN End Device.
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.