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 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Davide Magrin <magrinda@dei.unipd.it>
18 */
19
20#ifndef LORAWAN_MAC_HEADER_H
21#define LORAWAN_MAC_HEADER_H
22
23#include "ns3/header.h"
24
25namespace ns3
26{
27namespace lorawan
28{
29
30/**
31 * \ingroup lorawan
32 *
33 * This class represents the Mac header of a LoRaWAN packet.
34 */
36{
37 public:
38 /**
39 * The message type.
40 *
41 * The enum value corresponds to the value that will be written in the header
42 * by the Serialize method.
43 */
44 enum MType
45 {
52 PROPRIETARY = 7
53 };
54
55 /**
56 * Register this type.
57 * \return The object TypeId.
58 */
59 static TypeId GetTypeId();
60
61 LorawanMacHeader(); //!< Default constructor
62 ~LorawanMacHeader() override; //!< Destructor
63
64 // Pure virtual methods from Header that need to be implemented by this class
65 TypeId GetInstanceTypeId() const override;
66 uint32_t GetSerializedSize() const override;
67
68 /**
69 * Serialize the header.
70 *
71 * See Page 15 of LoRaWAN specification for a representation of fields.
72 *
73 * \param start A pointer to the buffer that will be filled with the
74 * serialization.
75 */
76 void Serialize(Buffer::Iterator start) const override;
77
78 /**
79 * Deserialize the header.
80 *
81 * \param start A pointer to the buffer we need to deserialize.
82 * \return The number of consumed bytes.
83 */
85
86 /**
87 * Print the header in a human readable format.
88 *
89 * \param os The std::ostream on which to print the header.
90 */
91 void Print(std::ostream& os) const override;
92
93 /**
94 * Set the message type.
95 *
96 * \param mtype The message type of this header.
97 */
98 void SetMType(enum MType mtype);
99
100 /**
101 * Get the message type from the header.
102 *
103 * \return The uint8_t corresponding to this header's message type.
104 */
105 uint8_t GetMType() const;
106
107 /**
108 * Set the major version of this header.
109 *
110 * \param major The uint8_t corresponding to this header's major version.
111 */
112 void SetMajor(uint8_t major);
113
114 /**
115 * Get the major version from the header.
116 *
117 * \return The uint8_t corresponding to this header's major version.
118 */
119 uint8_t GetMajor() const;
120
121 /**
122 * Check whether this header is for an uplink message.
123 *
124 * \return True if the message is meant to be sent from an end device to a gateway, false
125 * otherwise.
126 */
127 bool IsUplink() const;
128
129 /**
130 * Check whether this header is for a confirmed message, i.e. a message asking from
131 * reception acknowledgment from the received.
132 *
133 * \return True is the message MType is of the confirmed variant, false otherwise.
134 */
135 bool IsConfirmed() const;
136
137 private:
138 /**
139 * The Message Type.
140 */
141 uint8_t m_mtype;
142
143 /**
144 * The major version this header is using.
145 */
146 uint8_t m_major;
147};
148} // namespace lorawan
149
150} // namespace ns3
151#endif
iterator in a Buffer instance
Definition: buffer.h:100
Protocol header serialization and deserialization.
Definition: header.h:44
a unique identifier for an interface.
Definition: type-id.h:59
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.