A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
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
9
#include "
lorawan-mac-header.h
"
10
11
#include <bitset>
12
13
namespace
ns3
14
{
15
namespace
lorawan
16
{
17
18
NS_LOG_COMPONENT_DEFINE
(
"LorawanMacHeader"
);
19
20
LorawanMacHeader::LorawanMacHeader
()
21
:
m_major
(0)
22
{
23
}
24
25
LorawanMacHeader::~LorawanMacHeader
()
26
{
27
}
28
29
TypeId
30
LorawanMacHeader::GetTypeId
()
31
{
32
static
TypeId
tid =
33
TypeId
(
"LorawanMacHeader"
).
SetParent
<
Header
>().AddConstructor<LorawanMacHeader>();
34
return
tid;
35
}
36
37
TypeId
38
LorawanMacHeader::GetInstanceTypeId
()
const
39
{
40
return
GetTypeId
();
41
}
42
43
uint32_t
44
LorawanMacHeader::GetSerializedSize
()
const
45
{
46
NS_LOG_FUNCTION_NOARGS
();
47
48
return
1;
// This header only consists in 8 bits
49
}
50
51
void
52
LorawanMacHeader::Serialize
(
Buffer::Iterator
start)
const
53
{
54
NS_LOG_FUNCTION_NOARGS
();
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
73
uint32_t
74
LorawanMacHeader::Deserialize
(
Buffer::Iterator
start)
75
{
76
NS_LOG_FUNCTION_NOARGS
();
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
92
void
93
LorawanMacHeader::Print
(std::ostream& os)
const
94
{
95
os <<
"MessageType="
<< unsigned(
m_mtype
);
96
os <<
", Major="
<< unsigned(
m_major
);
97
}
98
99
void
100
LorawanMacHeader::SetMType
(
enum
MType
mtype)
101
{
102
NS_LOG_FUNCTION
(
this
<< mtype);
103
104
m_mtype
= mtype;
105
}
106
107
uint8_t
108
LorawanMacHeader::GetMType
()
const
109
{
110
NS_LOG_FUNCTION_NOARGS
();
111
112
return
m_mtype
;
113
}
114
115
void
116
LorawanMacHeader::SetMajor
(uint8_t major)
117
{
118
NS_LOG_FUNCTION_NOARGS
();
119
120
NS_ASSERT
(0 <= major && major < 4);
121
122
m_major
= major;
123
}
124
125
uint8_t
126
LorawanMacHeader::GetMajor
()
const
127
{
128
NS_LOG_FUNCTION_NOARGS
();
129
130
return
m_major
;
131
}
132
133
bool
134
LorawanMacHeader::IsUplink
()
const
135
{
136
NS_LOG_FUNCTION_NOARGS
();
137
138
return
(
m_mtype
==
JOIN_REQUEST
) || (
m_mtype
==
UNCONFIRMED_DATA_UP
) ||
139
(
m_mtype
==
CONFIRMED_DATA_UP
);
140
}
141
142
bool
143
LorawanMacHeader::IsConfirmed
()
const
144
{
145
NS_LOG_FUNCTION_NOARGS
();
146
147
return
(
m_mtype
==
CONFIRMED_DATA_DOWN
) || (
m_mtype
==
CONFIRMED_DATA_UP
);
148
}
149
150
}
// namespace lorawan
151
}
// namespace ns3
ns3::Buffer::Iterator
iterator in a Buffer instance
Definition
buffer.h:89
ns3::Header
Protocol header serialization and deserialization.
Definition
header.h:36
ns3::TypeId
a unique identifier for an interface.
Definition
type-id.h:50
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition
type-id.cc:999
ns3::lorawan::LorawanMacHeader::GetInstanceTypeId
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition
lorawan-mac-header.cc:38
ns3::lorawan::LorawanMacHeader::SetMajor
void SetMajor(uint8_t major)
Set the major version of this header.
Definition
lorawan-mac-header.cc:116
ns3::lorawan::LorawanMacHeader::Deserialize
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the header.
Definition
lorawan-mac-header.cc:74
ns3::lorawan::LorawanMacHeader::GetMType
uint8_t GetMType() const
Get the message type from the header.
Definition
lorawan-mac-header.cc:108
ns3::lorawan::LorawanMacHeader::IsUplink
bool IsUplink() const
Check whether this header is for an uplink message.
Definition
lorawan-mac-header.cc:134
ns3::lorawan::LorawanMacHeader::LorawanMacHeader
LorawanMacHeader()
Default constructor.
Definition
lorawan-mac-header.cc:20
ns3::lorawan::LorawanMacHeader::~LorawanMacHeader
~LorawanMacHeader() override
Destructor.
Definition
lorawan-mac-header.cc:25
ns3::lorawan::LorawanMacHeader::m_major
uint8_t m_major
The major version this header is using.
Definition
lorawan-mac-header.h:135
ns3::lorawan::LorawanMacHeader::GetTypeId
static TypeId GetTypeId()
Register this type.
Definition
lorawan-mac-header.cc:30
ns3::lorawan::LorawanMacHeader::Print
void Print(std::ostream &os) const override
Print the header in a human readable format.
Definition
lorawan-mac-header.cc:93
ns3::lorawan::LorawanMacHeader::m_mtype
uint8_t m_mtype
The Message Type.
Definition
lorawan-mac-header.h:130
ns3::lorawan::LorawanMacHeader::Serialize
void Serialize(Buffer::Iterator start) const override
Serialize the header.
Definition
lorawan-mac-header.cc:52
ns3::lorawan::LorawanMacHeader::IsConfirmed
bool IsConfirmed() const
Check whether this header is for a confirmed message, i.e.
Definition
lorawan-mac-header.cc:143
ns3::lorawan::LorawanMacHeader::SetMType
void SetMType(enum MType mtype)
Set the message type.
Definition
lorawan-mac-header.cc:100
ns3::lorawan::LorawanMacHeader::GetSerializedSize
uint32_t GetSerializedSize() const override
Definition
lorawan-mac-header.cc:44
ns3::lorawan::LorawanMacHeader::GetMajor
uint8_t GetMajor() const
Get the major version from the header.
Definition
lorawan-mac-header.cc:126
ns3::lorawan::LorawanMacHeader::MType
MType
The message type.
Definition
lorawan-mac-header.h:34
ns3::lorawan::LorawanMacHeader::JOIN_REQUEST
@ JOIN_REQUEST
Definition
lorawan-mac-header.h:35
ns3::lorawan::LorawanMacHeader::CONFIRMED_DATA_UP
@ CONFIRMED_DATA_UP
Definition
lorawan-mac-header.h:39
ns3::lorawan::LorawanMacHeader::CONFIRMED_DATA_DOWN
@ CONFIRMED_DATA_DOWN
Definition
lorawan-mac-header.h:40
ns3::lorawan::LorawanMacHeader::UNCONFIRMED_DATA_UP
@ UNCONFIRMED_DATA_UP
Definition
lorawan-mac-header.h:37
uint32_t
NS_ASSERT
#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
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:194
NS_LOG_DEBUG
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition
log.h:260
NS_LOG_FUNCTION_NOARGS
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Definition
log-macros-enabled.h:195
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition
log-macros-enabled.h:231
lorawan-mac-header.h
ns3::lorawan
Definition
forwarder-helper.cc:19
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
lorawan
model
lorawan-mac-header.cc
Generated on
for ns-3 by
1.15.0