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
* 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
#include "
lorawan-mac-header.h
"
21
22
#include "ns3/log.h"
23
24
#include <bitset>
25
26
namespace
ns3
27
{
28
namespace
lorawan
29
{
30
31
NS_LOG_COMPONENT_DEFINE
(
"LorawanMacHeader"
);
32
33
LorawanMacHeader::LorawanMacHeader
()
34
: m_major(0)
35
{
36
}
37
38
LorawanMacHeader::~LorawanMacHeader
()
39
{
40
}
41
42
TypeId
43
LorawanMacHeader::GetTypeId
()
44
{
45
static
TypeId
tid =
46
TypeId
(
"LorawanMacHeader"
).
SetParent
<
Header
>().AddConstructor<LorawanMacHeader>();
47
return
tid;
48
}
49
50
TypeId
51
LorawanMacHeader::GetInstanceTypeId
()
const
52
{
53
return
GetTypeId
();
54
}
55
56
uint32_t
57
LorawanMacHeader::GetSerializedSize
()
const
58
{
59
NS_LOG_FUNCTION_NOARGS
();
60
61
return
1;
// This header only consists in 8 bits
62
}
63
64
void
65
LorawanMacHeader::Serialize
(
Buffer::Iterator
start)
const
66
{
67
NS_LOG_FUNCTION_NOARGS
();
68
69
// The header we need to fill
70
uint8_t header = 0;
71
72
// The MType
73
header |=
m_mtype
<< 5;
74
75
// Do nothing for the bits that are RFU
76
77
// The major version bits
78
header |=
m_major
;
79
80
// Write the byte
81
start.WriteU8(header);
82
83
NS_LOG_DEBUG
(
"Serialization of MAC header: "
<< std::bitset<8>(header));
84
}
85
86
uint32_t
87
LorawanMacHeader::Deserialize
(
Buffer::Iterator
start)
88
{
89
NS_LOG_FUNCTION_NOARGS
();
90
91
// Save the byte on a temporary variable
92
uint8_t byte;
93
byte
= start.ReadU8();
94
95
// Get the 2 least significant bits to have the Major
96
m_major
=
byte
& 0b11;
97
98
// Move the three most significant bits to the least significant positions
99
// to get the MType
100
m_mtype
=
byte
>> 5;
101
102
return
1;
// the number of bytes consumed.
103
}
104
105
void
106
LorawanMacHeader::Print
(std::ostream& os)
const
107
{
108
os <<
"MessageType="
<< unsigned(
m_mtype
) << std::endl;
109
os <<
"Major="
<< unsigned(
m_major
) << std::endl;
110
}
111
112
void
113
LorawanMacHeader::SetMType
(
enum
MType
mtype)
114
{
115
NS_LOG_FUNCTION
(
this
<< mtype);
116
117
m_mtype
= mtype;
118
}
119
120
uint8_t
121
LorawanMacHeader::GetMType
()
const
122
{
123
NS_LOG_FUNCTION_NOARGS
();
124
125
return
m_mtype
;
126
}
127
128
void
129
LorawanMacHeader::SetMajor
(uint8_t major)
130
{
131
NS_LOG_FUNCTION_NOARGS
();
132
133
NS_ASSERT
(0 <= major && major < 4);
134
135
m_major
= major;
136
}
137
138
uint8_t
139
LorawanMacHeader::GetMajor
()
const
140
{
141
NS_LOG_FUNCTION_NOARGS
();
142
143
return
m_major
;
144
}
145
146
bool
147
LorawanMacHeader::IsUplink
()
const
148
{
149
NS_LOG_FUNCTION_NOARGS
();
150
151
return
(
m_mtype
==
JOIN_REQUEST
) || (
m_mtype
==
UNCONFIRMED_DATA_UP
) ||
152
(
m_mtype
==
CONFIRMED_DATA_UP
);
153
}
154
155
bool
156
LorawanMacHeader::IsConfirmed
()
const
157
{
158
NS_LOG_FUNCTION_NOARGS
();
159
160
return
(
m_mtype
==
CONFIRMED_DATA_DOWN
) || (
m_mtype
==
CONFIRMED_DATA_UP
);
161
}
162
}
// namespace lorawan
163
}
// namespace ns3
ns3::Buffer::Iterator
iterator in a Buffer instance
Definition:
buffer.h:100
ns3::Header
Protocol header serialization and deserialization.
Definition:
header.h:44
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:59
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition:
type-id.cc:932
ns3::lorawan::LorawanMacHeader::GetInstanceTypeId
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition:
lorawan-mac-header.cc:51
ns3::lorawan::LorawanMacHeader::SetMajor
void SetMajor(uint8_t major)
Set the major version of this header.
Definition:
lorawan-mac-header.cc:129
ns3::lorawan::LorawanMacHeader::Deserialize
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the header.
Definition:
lorawan-mac-header.cc:87
ns3::lorawan::LorawanMacHeader::GetMType
uint8_t GetMType() const
Get the message type from the header.
Definition:
lorawan-mac-header.cc:121
ns3::lorawan::LorawanMacHeader::IsUplink
bool IsUplink() const
Check whether this header is for an uplink message.
Definition:
lorawan-mac-header.cc:147
ns3::lorawan::LorawanMacHeader::LorawanMacHeader
LorawanMacHeader()
Default constructor.
Definition:
lorawan-mac-header.cc:33
ns3::lorawan::LorawanMacHeader::~LorawanMacHeader
~LorawanMacHeader() override
Destructor.
Definition:
lorawan-mac-header.cc:38
ns3::lorawan::LorawanMacHeader::m_major
uint8_t m_major
The major version this header is using.
Definition:
lorawan-mac-header.h:146
ns3::lorawan::LorawanMacHeader::GetTypeId
static TypeId GetTypeId()
Register this type.
Definition:
lorawan-mac-header.cc:43
ns3::lorawan::LorawanMacHeader::Print
void Print(std::ostream &os) const override
Print the header in a human readable format.
Definition:
lorawan-mac-header.cc:106
ns3::lorawan::LorawanMacHeader::m_mtype
uint8_t m_mtype
The Message Type.
Definition:
lorawan-mac-header.h:141
ns3::lorawan::LorawanMacHeader::Serialize
void Serialize(Buffer::Iterator start) const override
Serialize the header.
Definition:
lorawan-mac-header.cc:65
ns3::lorawan::LorawanMacHeader::IsConfirmed
bool IsConfirmed() const
Check whether this header is for a confirmed message, i.e.
Definition:
lorawan-mac-header.cc:156
ns3::lorawan::LorawanMacHeader::SetMType
void SetMType(enum MType mtype)
Set the message type.
Definition:
lorawan-mac-header.cc:113
ns3::lorawan::LorawanMacHeader::GetSerializedSize
uint32_t GetSerializedSize() const override
Definition:
lorawan-mac-header.cc:57
ns3::lorawan::LorawanMacHeader::GetMajor
uint8_t GetMajor() const
Get the major version from the header.
Definition:
lorawan-mac-header.cc:139
ns3::lorawan::LorawanMacHeader::MType
MType
The message type.
Definition:
lorawan-mac-header.h:45
ns3::lorawan::LorawanMacHeader::JOIN_REQUEST
@ JOIN_REQUEST
Definition:
lorawan-mac-header.h:46
ns3::lorawan::LorawanMacHeader::CONFIRMED_DATA_UP
@ CONFIRMED_DATA_UP
Definition:
lorawan-mac-header.h:50
ns3::lorawan::LorawanMacHeader::CONFIRMED_DATA_DOWN
@ CONFIRMED_DATA_DOWN
Definition:
lorawan-mac-header.h:51
ns3::lorawan::LorawanMacHeader::UNCONFIRMED_DATA_UP
@ UNCONFIRMED_DATA_UP
Definition:
lorawan-mac-header.h:48
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:66
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:202
NS_LOG_DEBUG
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition:
log.h:268
NS_LOG_FUNCTION_NOARGS
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Definition:
log-macros-enabled.h:206
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:240
lorawan-mac-header.h
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
lorawan
model
lorawan-mac-header.cc
Generated on Mon Aug 12 2024 11:16:15 for ns-3 by
1.9.6