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