A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lorawan-mac-header.cc
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
10
11#include <bitset>
12
13namespace ns3
14{
15namespace lorawan
16{
17
18NS_LOG_COMPONENT_DEFINE("LorawanMacHeader");
19
24
28
31{
32 static TypeId tid =
33 TypeId("LorawanMacHeader").SetParent<Header>().AddConstructor<LorawanMacHeader>();
34 return tid;
35}
36
42
45{
47
48 return 1; // This header only consists in 8 bits
49}
50
51void
53{
55
56 // The header we need to fill
57 uint8_t header = 0;
58
59 // The MType
60 header |= m_mtype << 5;
61
62 // Do nothing for the bits that are RFU
63
64 // The major version bits
65 header |= m_major;
66
67 // Write the byte
68 start.WriteU8(header);
69
70 NS_LOG_DEBUG("Serialization of MAC header: " << std::bitset<8>(header));
71}
72
75{
77
78 // Save the byte on a temporary variable
79 uint8_t byte;
80 byte = start.ReadU8();
81
82 // Get the 2 least significant bits to have the Major
83 m_major = byte & 0b11;
84
85 // Move the three most significant bits to the least significant positions
86 // to get the MType
87 m_mtype = byte >> 5;
88
89 return 1; // the number of bytes consumed.
90}
91
92void
93LorawanMacHeader::Print(std::ostream& os) const
94{
95 os << "MessageType=" << unsigned(m_mtype);
96 os << ", Major=" << unsigned(m_major);
97}
98
99void
101{
102 NS_LOG_FUNCTION(this << mtype);
103
104 m_mtype = mtype;
105}
106
107uint8_t
109{
111
112 return m_mtype;
113}
114
115void
117{
119
120 NS_ASSERT(0 <= major && major < 4);
121
122 m_major = major;
123}
124
125uint8_t
127{
129
130 return m_major;
131}
132
133bool
141
142bool
149
150} // namespace lorawan
151} // namespace ns3
iterator in a Buffer instance
Definition buffer.h:89
Protocol header serialization and deserialization.
Definition header.h:36
a unique identifier for an interface.
Definition type-id.h:50
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:999
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.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:194
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:260
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.