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
uan-header-common.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2009 University of Washington
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Leonard Tracy <lentracy@gmail.com>
7
*/
8
9
#include "
uan-header-common.h
"
10
11
#include "ns3/mac8-address.h"
12
13
static
const
uint16_t
ARP_PROT_NUMBER
= 0x0806;
14
static
const
uint16_t
IPV4_PROT_NUMBER
= 0x0800;
15
static
const
uint16_t
IPV6_PROT_NUMBER
= 0x86DD;
16
static
const
uint16_t
SIXLOWPAN_PROT_NUMBER
= 0xA0ED;
17
18
namespace
ns3
19
{
20
21
NS_OBJECT_ENSURE_REGISTERED
(UanHeaderCommon);
22
23
UanHeaderCommon::UanHeaderCommon
()
24
{
25
}
26
27
UanHeaderCommon::UanHeaderCommon
(
const
Mac8Address
src,
28
const
Mac8Address
dest,
29
uint8_t type,
30
uint8_t protocolNumber)
31
:
Header
(),
32
m_dest(dest),
33
m_src(src)
34
{
35
SetProtocolNumber
(protocolNumber);
36
m_uanProtocolBits
.
m_type
= type;
37
}
38
39
TypeId
40
UanHeaderCommon::GetTypeId
()
41
{
42
static
TypeId
tid =
TypeId
(
"ns3::UanHeaderCommon"
)
43
.
SetParent
<
Header
>()
44
.SetGroupName(
"Uan"
)
45
.AddConstructor<
UanHeaderCommon
>();
46
return
tid;
47
}
48
49
TypeId
50
UanHeaderCommon::GetInstanceTypeId
()
const
51
{
52
return
GetTypeId
();
53
}
54
55
UanHeaderCommon::~UanHeaderCommon
()
56
{
57
}
58
59
void
60
UanHeaderCommon::SetDest
(
Mac8Address
dest)
61
{
62
m_dest
= dest;
63
}
64
65
void
66
UanHeaderCommon::SetSrc
(
Mac8Address
src)
67
{
68
m_src
= src;
69
}
70
71
void
72
UanHeaderCommon::SetType
(uint8_t type)
73
{
74
m_uanProtocolBits
.
m_type
= type;
75
}
76
77
void
78
UanHeaderCommon::SetProtocolNumber
(uint16_t protocolNumber)
79
{
80
if
(protocolNumber == 0)
81
{
82
m_uanProtocolBits
.
m_protocolNumber
= 0;
83
}
84
else
if
(protocolNumber ==
IPV4_PROT_NUMBER
)
85
{
86
m_uanProtocolBits
.
m_protocolNumber
= 1;
87
}
88
else
if
(protocolNumber ==
ARP_PROT_NUMBER
)
89
{
90
m_uanProtocolBits
.
m_protocolNumber
= 2;
91
}
92
else
if
(protocolNumber ==
IPV6_PROT_NUMBER
)
93
{
94
m_uanProtocolBits
.
m_protocolNumber
= 3;
95
}
96
else
if
(protocolNumber ==
SIXLOWPAN_PROT_NUMBER
)
97
{
98
m_uanProtocolBits
.
m_protocolNumber
= 4;
99
}
100
else
101
{
102
NS_ASSERT_MSG
(
false
,
"UanHeaderCommon::SetProtocolNumber(): Protocol not supported"
);
103
}
104
}
105
106
Mac8Address
107
UanHeaderCommon::GetDest
()
const
108
{
109
return
m_dest
;
110
}
111
112
Mac8Address
113
UanHeaderCommon::GetSrc
()
const
114
{
115
return
m_src
;
116
}
117
118
uint8_t
119
UanHeaderCommon::GetType
()
const
120
{
121
return
m_uanProtocolBits
.
m_type
;
122
}
123
124
uint16_t
125
UanHeaderCommon::GetProtocolNumber
()
const
126
{
127
if
(
m_uanProtocolBits
.
m_protocolNumber
== 1)
128
{
129
return
IPV4_PROT_NUMBER
;
130
}
131
if
(
m_uanProtocolBits
.
m_protocolNumber
== 2)
132
{
133
return
ARP_PROT_NUMBER
;
134
}
135
if
(
m_uanProtocolBits
.
m_protocolNumber
== 3)
136
{
137
return
IPV6_PROT_NUMBER
;
138
}
139
if
(
m_uanProtocolBits
.
m_protocolNumber
== 4)
140
{
141
return
SIXLOWPAN_PROT_NUMBER
;
142
}
143
return
0;
144
}
145
146
// Inherited methods
147
148
uint32_t
149
UanHeaderCommon::GetSerializedSize
()
const
150
{
151
return
1 + 1 + 1;
152
}
153
154
void
155
UanHeaderCommon::Serialize
(
Buffer::Iterator
start)
const
156
{
157
uint8_t address = 0;
158
m_src
.
CopyTo
(&address);
159
start.WriteU8(address);
160
m_dest
.
CopyTo
(&address);
161
start.WriteU8(address);
162
char
tmp =
m_uanProtocolBits
.
m_type
;
163
tmp = tmp << 4;
164
tmp +=
m_uanProtocolBits
.
m_protocolNumber
;
165
start.WriteU8(tmp);
166
}
167
168
uint32_t
169
UanHeaderCommon::Deserialize
(
Buffer::Iterator
start)
170
{
171
Buffer::Iterator
rbuf = start;
172
173
m_src
=
Mac8Address
(rbuf.
ReadU8
());
174
m_dest
=
Mac8Address
(rbuf.
ReadU8
());
175
char
tmp = rbuf.
ReadU8
();
176
m_uanProtocolBits
.
m_type
= tmp >> 4;
177
m_uanProtocolBits
.
m_protocolNumber
= tmp;
178
179
return
rbuf.
GetDistanceFrom
(start);
180
}
181
182
void
183
UanHeaderCommon::Print
(std::ostream& os)
const
184
{
185
os <<
"UAN src="
<<
m_src
<<
" dest="
<<
m_dest
186
<<
" type="
<< (
uint32_t
)
m_uanProtocolBits
.
m_type
187
<<
"Protocol Number="
<< (
uint32_t
)
m_uanProtocolBits
.
m_protocolNumber
;
188
}
189
190
}
// namespace ns3
ns3::Buffer::Iterator
iterator in a Buffer instance
Definition
buffer.h:89
ns3::Buffer::Iterator::ReadU8
uint8_t ReadU8()
Definition
buffer.h:1016
ns3::Buffer::Iterator::GetDistanceFrom
uint32_t GetDistanceFrom(const Iterator &o) const
Definition
buffer.cc:769
ns3::Header
Protocol header serialization and deserialization.
Definition
header.h:33
ns3::Mac8Address
A class used for addressing MAC8 MAC's.
Definition
mac8-address.h:33
ns3::Mac8Address::CopyTo
void CopyTo(uint8_t *pBuffer) const
Writes address to buffer parameter.
Definition
mac8-address.cc:71
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::UanHeaderCommon
Common packet header fields.
Definition
uan-header-common.h:55
ns3::UanHeaderCommon::GetTypeId
static TypeId GetTypeId()
Register this type.
Definition
uan-header-common.cc:40
ns3::UanHeaderCommon::SetSrc
void SetSrc(Mac8Address src)
Set the source address.
Definition
uan-header-common.cc:66
ns3::UanHeaderCommon::Deserialize
uint32_t Deserialize(Buffer::Iterator start) override
Definition
uan-header-common.cc:169
ns3::UanHeaderCommon::GetSerializedSize
uint32_t GetSerializedSize() const override
Definition
uan-header-common.cc:149
ns3::UanHeaderCommon::m_dest
Mac8Address m_dest
The destination address.
Definition
uan-header-common.h:141
ns3::UanHeaderCommon::GetType
uint8_t GetType() const
Get the header type value.
Definition
uan-header-common.cc:119
ns3::UanHeaderCommon::m_src
Mac8Address m_src
The source address.
Definition
uan-header-common.h:142
ns3::UanHeaderCommon::GetDest
Mac8Address GetDest() const
Get the destination address.
Definition
uan-header-common.cc:107
ns3::UanHeaderCommon::UanHeaderCommon
UanHeaderCommon()
Default constructor.
Definition
uan-header-common.cc:23
ns3::UanHeaderCommon::SetProtocolNumber
void SetProtocolNumber(uint16_t protocolNumber)
Set the packet type.
Definition
uan-header-common.cc:78
ns3::UanHeaderCommon::Serialize
void Serialize(Buffer::Iterator start) const override
Definition
uan-header-common.cc:155
ns3::UanHeaderCommon::GetSrc
Mac8Address GetSrc() const
Get the source address.
Definition
uan-header-common.cc:113
ns3::UanHeaderCommon::m_uanProtocolBits
UanProtocolBits m_uanProtocolBits
The type and protocol bits.
Definition
uan-header-common.h:143
ns3::UanHeaderCommon::SetDest
void SetDest(Mac8Address dest)
Set the destination address.
Definition
uan-header-common.cc:60
ns3::UanHeaderCommon::SetType
void SetType(uint8_t type)
Set the header type.
Definition
uan-header-common.cc:72
ns3::UanHeaderCommon::~UanHeaderCommon
~UanHeaderCommon() override
Destructor.
Definition
uan-header-common.cc:55
ns3::UanHeaderCommon::Print
void Print(std::ostream &os) const override
Definition
uan-header-common.cc:183
ns3::UanHeaderCommon::GetProtocolNumber
uint16_t GetProtocolNumber() const
Get the packet type value.
Definition
uan-header-common.cc:125
ns3::UanHeaderCommon::GetInstanceTypeId
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition
uan-header-common.cc:50
uint32_t
NS_ASSERT_MSG
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition
assert.h:75
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition
object-base.h:35
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::UanProtocolBits::m_protocolNumber
uint8_t m_protocolNumber
protocol number (4 bits)
Definition
uan-header-common.h:28
ns3::UanProtocolBits::m_type
uint8_t m_type
type (4 bits)
Definition
uan-header-common.h:27
IPV4_PROT_NUMBER
static const uint16_t IPV4_PROT_NUMBER
Definition
uan-header-common.cc:14
SIXLOWPAN_PROT_NUMBER
static const uint16_t SIXLOWPAN_PROT_NUMBER
Definition
uan-header-common.cc:16
ARP_PROT_NUMBER
static const uint16_t ARP_PROT_NUMBER
Definition
uan-header-common.cc:13
IPV6_PROT_NUMBER
static const uint16_t IPV6_PROT_NUMBER
Definition
uan-header-common.cc:15
uan-header-common.h
src
uan
model
uan-header-common.cc
Generated on Fri Oct 11 2024 18:20:53 for ns-3 by
1.11.0