lorawan-mac-command.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_COMMAND_H
24 #define LORAWAN_MAC_COMMAND_H
25 
26 #include <ns3/buffer.h>
27 #include <ns3/nstime.h>
28 #include <ns3/object.h>
29 
30 namespace ns3
31 {
32 
37 {
57 };
58 
66 class LorawanMacCommand : public Object
67 {
68  public:
69  static TypeId GetTypeId(void);
70 
72  virtual ~LorawanMacCommand();
73 
80  virtual void Serialize(Buffer::Iterator& start) const = 0;
81 
88  virtual uint8_t Deserialize(Buffer::Iterator& start) = 0;
89 
95  virtual void Print(std::ostream& os) const = 0;
96 
102  virtual uint8_t GetSerializedSize(void) const;
103 
109  virtual enum MacCommandType GetCommandType(void) const;
110 
116  static uint8_t GetCIDFromLorawanMacCommand(enum MacCommandType commandType);
117 
118  protected:
123 
128 };
129 
136 {
137  public:
138  LinkCheckReq();
139  ~LinkCheckReq();
140  virtual void Serialize(Buffer::Iterator& start) const;
141  virtual uint8_t Deserialize(Buffer::Iterator& start);
142  virtual void Print(std::ostream& os) const;
143 };
144 
152 {
153  public:
154  LinkCheckAns();
155  LinkCheckAns(uint8_t margin, uint8_t gwCnt);
156 
157  virtual void Serialize(Buffer::Iterator& start) const;
158  virtual uint8_t Deserialize(Buffer::Iterator& start);
159  virtual void Print(std::ostream& os) const;
160 
166  void SetMargin(uint8_t margin);
167 
173  uint8_t GetMargin(void) const;
174 
180  void SetGwCnt(uint8_t gwCnt);
181 
187  uint8_t GetGwCnt(void) const;
188 
192  void IncrementGwCnt(void);
193 
194  private:
198  uint8_t m_margin;
199 
203  uint8_t m_gwCnt;
204 };
205 
214 {
215  public:
216  LinkAdrReq();
217 
218  LinkAdrReq(uint8_t dataRate,
219  uint8_t txPower,
220  uint16_t channelMask,
221  uint8_t chMaskCntl,
222  uint8_t nbRep);
223 
224  virtual void Serialize(Buffer::Iterator& start) const;
225  virtual uint8_t Deserialize(Buffer::Iterator& start);
226  virtual void Print(std::ostream& os) const;
227 
233  uint8_t GetDataRate(void);
234 
244  uint8_t GetTxPower(void);
245 
252  std::list<int> GetEnabledChannelsList(void);
253 
259  int GetRepetitions(void);
260 
261  private:
262  uint8_t m_dataRate;
263  uint8_t m_txPower;
264  uint16_t m_channelMask;
265  uint8_t m_chMaskCntl;
266  uint8_t m_nbRep;
267 };
268 
275 {
276  public:
277  LinkAdrAns();
278 
279  LinkAdrAns(bool powerAck, bool dataRateAck, bool channelMaskAck);
280 
281  virtual void Serialize(Buffer::Iterator& start) const;
282  virtual uint8_t Deserialize(Buffer::Iterator& start);
283  virtual void Print(std::ostream& os) const;
284 
285  private:
289 };
290 
299 {
300  public:
301  DutyCycleReq();
307  DutyCycleReq(uint8_t dutyCycle);
308 
309  virtual void Serialize(Buffer::Iterator& start) const;
310  virtual uint8_t Deserialize(Buffer::Iterator& start);
311  virtual void Print(std::ostream& os) const;
312 
318  double GetMaximumAllowedDutyCycle(void) const;
319 
320  private:
321  uint8_t m_maxDCycle;
322 };
323 
330 {
331  public:
332  DutyCycleAns();
333 
334  virtual void Serialize(Buffer::Iterator& start) const;
335  virtual uint8_t Deserialize(Buffer::Iterator& start);
336  virtual void Print(std::ostream& os) const;
337 };
338 
343 {
344  public:
345  RxParamSetupReq();
346 
354  RxParamSetupReq(uint8_t rx1DrOffset, uint8_t rx2DataRate, double frequency);
355 
356  virtual void Serialize(Buffer::Iterator& start) const;
357  virtual uint8_t Deserialize(Buffer::Iterator& start);
358  virtual void Print(std::ostream& os) const;
359 
365  uint8_t GetRx1DrOffset(void);
366 
372  uint8_t GetRx2DataRate(void);
373 
379  double GetFrequency(void);
380 
381  private:
382  uint8_t m_rx1DrOffset;
383  uint8_t m_rx2DataRate;
384  double m_frequency;
385 };
386 
391 {
392  public:
393  RxParamSetupAns();
401  RxParamSetupAns(bool rx1DrOffsetAck, bool rx2DataRateAck, bool channelAck);
402 
403  virtual void Serialize(Buffer::Iterator& start) const;
404  virtual uint8_t Deserialize(Buffer::Iterator& start);
405  virtual void Print(std::ostream& os) const;
406 
407  private:
411 };
412 
417 {
418  public:
419  DevStatusReq();
420 
421  virtual void Serialize(Buffer::Iterator& start) const;
422  virtual uint8_t Deserialize(Buffer::Iterator& start);
423  virtual void Print(std::ostream& os) const;
424 };
425 
430 {
431  public:
432  DevStatusAns();
439  DevStatusAns(uint8_t battery, uint8_t margin);
440 
441  virtual void Serialize(Buffer::Iterator& start) const;
442  virtual uint8_t Deserialize(Buffer::Iterator& start);
443  virtual void Print(std::ostream& os) const;
444 
450  uint8_t GetBattery(void);
451 
457  uint8_t GetMargin(void);
458 
459  private:
460  uint8_t m_battery;
461  uint8_t m_margin;
462 };
463 
468 {
469  public:
470  NewChannelReq();
471 
480  NewChannelReq(uint8_t chIndex, double frequency, uint8_t minDataRate, uint8_t maxDataRate);
481 
482  virtual void Serialize(Buffer::Iterator& start) const;
483  virtual uint8_t Deserialize(Buffer::Iterator& start);
484  virtual void Print(std::ostream& os) const;
485 
486  uint8_t GetChannelIndex(void);
487  double GetFrequency(void);
488  uint8_t GetMinDataRate(void);
489  uint8_t GetMaxDataRate(void);
490 
491  private:
492  uint8_t m_chIndex;
493  double m_frequency;
494  uint8_t m_minDataRate;
495  uint8_t m_maxDataRate;
496 };
497 
502 {
503  public:
504  NewChannelAns();
505 
514  NewChannelAns(bool dataRateRangeOk, bool channelFrequencyOk);
515 
516  virtual void Serialize(Buffer::Iterator& start) const;
517  virtual uint8_t Deserialize(Buffer::Iterator& start);
518  virtual void Print(std::ostream& os) const;
519 
520  private:
523 };
524 
529 {
530  public:
532 
538  RxTimingSetupReq(uint8_t delay);
539 
540  virtual void Serialize(Buffer::Iterator& start) const;
541  virtual uint8_t Deserialize(Buffer::Iterator& start);
542  virtual void Print(std::ostream& os) const;
543 
549  Time GetDelay(void);
550 
551  private:
552  uint8_t m_delay;
553 };
554 
561 {
562  public:
564 
565  virtual void Serialize(Buffer::Iterator& start) const;
566  virtual uint8_t Deserialize(Buffer::Iterator& start);
567  virtual void Print(std::ostream& os) const;
568 
569  private:
570 };
571 
576 {
577  public:
578  TxParamSetupAns();
579 
580  virtual void Serialize(Buffer::Iterator& start) const;
581  virtual uint8_t Deserialize(Buffer::Iterator& start);
582  virtual void Print(std::ostream& os) const;
583 
584  private:
585 };
586 
591 {
592  public:
593  TxParamSetupReq();
594 
595  virtual void Serialize(Buffer::Iterator& start) const;
596  virtual uint8_t Deserialize(Buffer::Iterator& start);
597  virtual void Print(std::ostream& os) const;
598 
599  private:
600 };
601 
606 {
607  public:
608  DlChannelAns();
609 
610  virtual void Serialize(Buffer::Iterator& start) const;
611  virtual uint8_t Deserialize(Buffer::Iterator& start);
612  virtual void Print(std::ostream& os) const;
613 
614  private:
615 };
616 
617 } // namespace ns3
618 
619 #endif /* LORAWAN_MAC_COMMAND_H */
Implementation of the DevStatusAns LoRaWAN MAC command.
virtual void Print(std::ostream &os) const
Print the contents of this MAC command in human-readable format.
uint8_t GetBattery(void)
Get the battery information contained in this MAC command.
virtual uint8_t Deserialize(Buffer::Iterator &start)
Deserialize the buffer into a MAC command.
uint8_t GetMargin(void)
Get the demodulation margin contained in this MAC command.
virtual void Serialize(Buffer::Iterator &start) const
Serialize the contents of this MAC command into a buffer, according to the LoRaWAN standard.
Implementation of the DevStatusReq LoRaWAN MAC command.
virtual uint8_t Deserialize(Buffer::Iterator &start)
Deserialize the buffer into a MAC command.
virtual void Print(std::ostream &os) const
Print the contents of this MAC command in human-readable format.
virtual void Serialize(Buffer::Iterator &start) const
Serialize the contents of this MAC command into a buffer, according to the LoRaWAN standard.
Implementation of the DlChannelAns LoRaWAN MAC command.
virtual void Print(std::ostream &os) const
Print the contents of this MAC command in human-readable format.
virtual uint8_t Deserialize(Buffer::Iterator &start)
Deserialize the buffer into a MAC command.
virtual void Serialize(Buffer::Iterator &start) const
Serialize the contents of this MAC command into a buffer, according to the LoRaWAN standard.
Implementation of the DutyCycleAns LoRaWAN MAC command.
virtual void Print(std::ostream &os) const
Print the contents of this MAC command in human-readable format.
virtual uint8_t Deserialize(Buffer::Iterator &start)
Deserialize the buffer into a MAC command.
virtual void Serialize(Buffer::Iterator &start) const
Serialize the contents of this MAC command into a buffer, according to the LoRaWAN standard.
Implementation of the DutyCycleReq LoRaWAN MAC command.
virtual void Serialize(Buffer::Iterator &start) const
Serialize the contents of this MAC command into a buffer, according to the LoRaWAN standard.
virtual void Print(std::ostream &os) const
Print the contents of this MAC command in human-readable format.
virtual uint8_t Deserialize(Buffer::Iterator &start)
Deserialize the buffer into a MAC command.
double GetMaximumAllowedDutyCycle(void) const
Get the maximum duty cycle prescribed by this Mac command, in fraction form.
This base class is used to represent a general MAC command.
static uint8_t GetCIDFromLorawanMacCommand(enum MacCommandType commandType)
Get the CID that corresponds to this MAC command.
virtual uint8_t Deserialize(Buffer::Iterator &start)=0
Deserialize the buffer into a MAC command.
enum MacCommandType m_commandType
The type of this command.
virtual uint8_t GetSerializedSize(void) const
Get serialized length of this MAC command.
virtual void Print(std::ostream &os) const =0
Print the contents of this MAC command in human-readable format.
static TypeId GetTypeId(void)
virtual enum MacCommandType GetCommandType(void) const
Get the commandType of this MAC command.
uint8_t m_serializedSize
This MAC command's serialized size.
virtual void Serialize(Buffer::Iterator &start) const =0
Serialize the contents of this MAC command into a buffer, according to the LoRaWAN standard.
Implementation of the NewChannelAns LoRaWAN MAC command.
virtual uint8_t Deserialize(Buffer::Iterator &start)
Deserialize the buffer into a MAC command.
virtual void Serialize(Buffer::Iterator &start) const
Serialize the contents of this MAC command into a buffer, according to the LoRaWAN standard.
virtual void Print(std::ostream &os) const
Print the contents of this MAC command in human-readable format.
Implementation of the NewChannelReq LoRaWAN MAC command.
virtual void Serialize(Buffer::Iterator &start) const
Serialize the contents of this MAC command into a buffer, according to the LoRaWAN standard.
virtual void Print(std::ostream &os) const
Print the contents of this MAC command in human-readable format.
uint8_t GetMinDataRate(void)
virtual uint8_t Deserialize(Buffer::Iterator &start)
Deserialize the buffer into a MAC command.
uint8_t GetChannelIndex(void)
uint8_t GetMaxDataRate(void)
Implementation of the RxParamSetupAns LoRaWAN MAC command.
virtual void Print(std::ostream &os) const
Print the contents of this MAC command in human-readable format.
virtual void Serialize(Buffer::Iterator &start) const
Serialize the contents of this MAC command into a buffer, according to the LoRaWAN standard.
virtual uint8_t Deserialize(Buffer::Iterator &start)
Deserialize the buffer into a MAC command.
Implementation of the RxParamSetupReq LoRaWAN MAC command.
double m_frequency
The frequency in Hz
uint8_t GetRx1DrOffset(void)
Get this command's Rx1DrOffset parameter.
virtual void Print(std::ostream &os) const
Print the contents of this MAC command in human-readable format.
uint8_t GetRx2DataRate(void)
Get this command's Rx2DataRate parameter.
virtual uint8_t Deserialize(Buffer::Iterator &start)
Deserialize the buffer into a MAC command.
virtual void Serialize(Buffer::Iterator &start) const
Serialize the contents of this MAC command into a buffer, according to the LoRaWAN standard.
double GetFrequency(void)
Get this command's frequency.
Implementation of the RxTimingSetupAns LoRaWAN MAC command.
virtual void Print(std::ostream &os) const
Print the contents of this MAC command in human-readable format.
virtual uint8_t Deserialize(Buffer::Iterator &start)
Deserialize the buffer into a MAC command.
virtual void Serialize(Buffer::Iterator &start) const
Serialize the contents of this MAC command into a buffer, according to the LoRaWAN standard.
Implementation of the RxTimingSetupReq LoRaWAN MAC command.
virtual void Serialize(Buffer::Iterator &start) const
Serialize the contents of this MAC command into a buffer, according to the LoRaWAN standard.
virtual uint8_t Deserialize(Buffer::Iterator &start)
Deserialize the buffer into a MAC command.
Time GetDelay(void)
Get the first window delay as a Time instance.
virtual void Print(std::ostream &os) const
Print the contents of this MAC command in human-readable format.
Implementation of the TxParamSetupAns LoRaWAN MAC command.
virtual void Serialize(Buffer::Iterator &start) const
Serialize the contents of this MAC command into a buffer, according to the LoRaWAN standard.
virtual void Print(std::ostream &os) const
Print the contents of this MAC command in human-readable format.
virtual uint8_t Deserialize(Buffer::Iterator &start)
Deserialize the buffer into a MAC command.
Implementation of the TxParamSetupReq LoRaWAN MAC command.
virtual void Serialize(Buffer::Iterator &start) const
Serialize the contents of this MAC command into a buffer, according to the LoRaWAN standard.
virtual void Print(std::ostream &os) const
Print the contents of this MAC command in human-readable format.
virtual uint8_t Deserialize(Buffer::Iterator &start)
Deserialize the buffer into a MAC command.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
MacCommandType
Enum for every possible command type.
@ TX_PARAM_SETUP_ANS
@ RX_TIMING_SETUP_REQ
@ RX_TIMING_SETUP_ANS
@ RX_PARAM_SETUP_REQ
@ RX_PARAM_SETUP_ANS
@ TX_PARAM_SETUP_REQ