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