A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lorawan-mac-header.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 University of Padova
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Davide Magrin <magrinda@dei.unipd.it>
7 */
8
9#ifndef LORAWAN_MAC_HEADER_H
10#define LORAWAN_MAC_HEADER_H
11
12#include "ns3/header.h"
13
14namespace ns3
15{
16namespace lorawan
17{
18
19/**
20 * \ingroup lorawan
21 *
22 * This class represents the Mac header of a LoRaWAN packet.
23 */
25{
26 public:
27 /**
28 * The message type.
29 *
30 * The enum value corresponds to the value that will be written in the header
31 * by the Serialize method.
32 */
43
44 /**
45 * Register this type.
46 * \return The object TypeId.
47 */
48 static TypeId GetTypeId();
49
50 LorawanMacHeader(); //!< Default constructor
51 ~LorawanMacHeader() override; //!< Destructor
52
53 // Pure virtual methods from Header that need to be implemented by this class
54 TypeId GetInstanceTypeId() const override;
55 uint32_t GetSerializedSize() const override;
56
57 /**
58 * Serialize the header.
59 *
60 * See Page 15 of LoRaWAN specification for a representation of fields.
61 *
62 * \param start A pointer to the buffer that will be filled with the
63 * serialization.
64 */
65 void Serialize(Buffer::Iterator start) const override;
66
67 /**
68 * Deserialize the header.
69 *
70 * \param start A pointer to the buffer we need to deserialize.
71 * \return The number of consumed bytes.
72 */
74
75 /**
76 * Print the header in a human readable format.
77 *
78 * \param os The std::ostream on which to print the header.
79 */
80 void Print(std::ostream& os) const override;
81
82 /**
83 * Set the message type.
84 *
85 * \param mtype The message type of this header.
86 */
87 void SetMType(enum MType mtype);
88
89 /**
90 * Get the message type from the header.
91 *
92 * \return The uint8_t corresponding to this header's message type.
93 */
94 uint8_t GetMType() const;
95
96 /**
97 * Set the major version of this header.
98 *
99 * \param major The uint8_t corresponding to this header's major version.
100 */
101 void SetMajor(uint8_t major);
102
103 /**
104 * Get the major version from the header.
105 *
106 * \return The uint8_t corresponding to this header's major version.
107 */
108 uint8_t GetMajor() const;
109
110 /**
111 * Check whether this header is for an uplink message.
112 *
113 * \return True if the message is meant to be sent from an end device to a gateway, false
114 * otherwise.
115 */
116 bool IsUplink() const;
117
118 /**
119 * Check whether this header is for a confirmed message, i.e. a message asking from
120 * reception acknowledgment from the received.
121 *
122 * \return True is the message MType is of the confirmed variant, false otherwise.
123 */
124 bool IsConfirmed() const;
125
126 private:
127 /**
128 * The Message Type.
129 */
130 uint8_t m_mtype;
131
132 /**
133 * The major version this header is using.
134 */
135 uint8_t m_major;
136};
137} // namespace lorawan
138
139} // namespace ns3
140#endif
iterator in a Buffer instance
Definition buffer.h:89
Protocol header serialization and deserialization.
Definition header.h:33
a unique identifier for an interface.
Definition type-id.h:48
This class represents the Mac header of a LoRaWAN packet.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
void SetMajor(uint8_t major)
Set the major version of this header.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the header.
uint8_t GetMType() const
Get the message type from the header.
bool IsUplink() const
Check whether this header is for an uplink message.
LorawanMacHeader()
Default constructor.
~LorawanMacHeader() override
Destructor.
uint8_t m_major
The major version this header is using.
static TypeId GetTypeId()
Register this type.
void Print(std::ostream &os) const override
Print the header in a human readable format.
uint8_t m_mtype
The Message Type.
void Serialize(Buffer::Iterator start) const override
Serialize the header.
bool IsConfirmed() const
Check whether this header is for a confirmed message, i.e.
void SetMType(enum MType mtype)
Set the message type.
uint32_t GetSerializedSize() const override
uint8_t GetMajor() const
Get the major version from the header.
Every class exported by the ns3 library is enclosed in the ns3 namespace.