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
* 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
static
const
uint16_t
SIXLOWPAN_PROT_NUMBER
= 0xA0ED;
28
29
namespace
ns3
30
{
31
32
NS_OBJECT_ENSURE_REGISTERED
(UanHeaderCommon);
33
34
UanHeaderCommon::UanHeaderCommon
()
35
{
36
}
37
38
UanHeaderCommon::UanHeaderCommon
(
const
Mac8Address
src,
39
const
Mac8Address
dest,
40
uint8_t type,
41
uint8_t protocolNumber)
42
:
Header
(),
43
m_dest(dest),
44
m_src(src)
45
{
46
SetProtocolNumber
(protocolNumber);
47
m_uanProtocolBits
.
m_type
= type;
48
}
49
50
TypeId
51
UanHeaderCommon::GetTypeId
()
52
{
53
static
TypeId
tid =
TypeId
(
"ns3::UanHeaderCommon"
)
54
.
SetParent
<
Header
>()
55
.SetGroupName(
"Uan"
)
56
.AddConstructor<
UanHeaderCommon
>();
57
return
tid;
58
}
59
60
TypeId
61
UanHeaderCommon::GetInstanceTypeId
()
const
62
{
63
return
GetTypeId
();
64
}
65
66
UanHeaderCommon::~UanHeaderCommon
()
67
{
68
}
69
70
void
71
UanHeaderCommon::SetDest
(
Mac8Address
dest)
72
{
73
m_dest
= dest;
74
}
75
76
void
77
UanHeaderCommon::SetSrc
(
Mac8Address
src)
78
{
79
m_src
= src;
80
}
81
82
void
83
UanHeaderCommon::SetType
(uint8_t type)
84
{
85
m_uanProtocolBits
.
m_type
= type;
86
}
87
88
void
89
UanHeaderCommon::SetProtocolNumber
(uint16_t protocolNumber)
90
{
91
if
(protocolNumber == 0)
92
{
93
m_uanProtocolBits
.
m_protocolNumber
= 0;
94
}
95
else
if
(protocolNumber ==
IPV4_PROT_NUMBER
)
96
{
97
m_uanProtocolBits
.
m_protocolNumber
= 1;
98
}
99
else
if
(protocolNumber ==
ARP_PROT_NUMBER
)
100
{
101
m_uanProtocolBits
.
m_protocolNumber
= 2;
102
}
103
else
if
(protocolNumber ==
IPV6_PROT_NUMBER
)
104
{
105
m_uanProtocolBits
.
m_protocolNumber
= 3;
106
}
107
else
if
(protocolNumber ==
SIXLOWPAN_PROT_NUMBER
)
108
{
109
m_uanProtocolBits
.
m_protocolNumber
= 4;
110
}
111
else
112
{
113
NS_ASSERT_MSG
(
false
,
"UanHeaderCommon::SetProtocolNumber(): Protocol not supported"
);
114
}
115
}
116
117
Mac8Address
118
UanHeaderCommon::GetDest
()
const
119
{
120
return
m_dest
;
121
}
122
123
Mac8Address
124
UanHeaderCommon::GetSrc
()
const
125
{
126
return
m_src
;
127
}
128
129
uint8_t
130
UanHeaderCommon::GetType
()
const
131
{
132
return
m_uanProtocolBits
.
m_type
;
133
}
134
135
uint16_t
136
UanHeaderCommon::GetProtocolNumber
()
const
137
{
138
if
(
m_uanProtocolBits
.
m_protocolNumber
== 1)
139
{
140
return
IPV4_PROT_NUMBER
;
141
}
142
if
(
m_uanProtocolBits
.
m_protocolNumber
== 2)
143
{
144
return
ARP_PROT_NUMBER
;
145
}
146
if
(
m_uanProtocolBits
.
m_protocolNumber
== 3)
147
{
148
return
IPV6_PROT_NUMBER
;
149
}
150
if
(
m_uanProtocolBits
.
m_protocolNumber
== 4)
151
{
152
return
SIXLOWPAN_PROT_NUMBER
;
153
}
154
return
0;
155
}
156
157
// Inherited methods
158
159
uint32_t
160
UanHeaderCommon::GetSerializedSize
()
const
161
{
162
return
1 + 1 + 1;
163
}
164
165
void
166
UanHeaderCommon::Serialize
(
Buffer::Iterator
start)
const
167
{
168
uint8_t address = 0;
169
m_src
.
CopyTo
(&address);
170
start.WriteU8(address);
171
m_dest
.
CopyTo
(&address);
172
start.WriteU8(address);
173
char
tmp =
m_uanProtocolBits
.
m_type
;
174
tmp = tmp << 4;
175
tmp +=
m_uanProtocolBits
.
m_protocolNumber
;
176
start.WriteU8(tmp);
177
}
178
179
uint32_t
180
UanHeaderCommon::Deserialize
(
Buffer::Iterator
start)
181
{
182
Buffer::Iterator
rbuf = start;
183
184
m_src
=
Mac8Address
(rbuf.
ReadU8
());
185
m_dest
=
Mac8Address
(rbuf.
ReadU8
());
186
char
tmp = rbuf.
ReadU8
();
187
m_uanProtocolBits
.
m_type
= tmp >> 4;
188
m_uanProtocolBits
.
m_protocolNumber
= tmp;
189
190
return
rbuf.
GetDistanceFrom
(start);
191
}
192
193
void
194
UanHeaderCommon::Print
(std::ostream& os)
const
195
{
196
os <<
"UAN src="
<<
m_src
<<
" dest="
<<
m_dest
197
<<
" type="
<< (
uint32_t
)
m_uanProtocolBits
.
m_type
198
<<
"Protocol Number="
<< (
uint32_t
)
m_uanProtocolBits
.
m_protocolNumber
;
199
}
200
201
}
// 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::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:932
ns3::UanHeaderCommon
Common packet header fields.
Definition:
uan-header-common.h:66
ns3::UanHeaderCommon::GetTypeId
static TypeId GetTypeId()
Register this type.
Definition:
uan-header-common.cc:51
ns3::UanHeaderCommon::SetSrc
void SetSrc(Mac8Address src)
Set the source address.
Definition:
uan-header-common.cc:77
ns3::UanHeaderCommon::Deserialize
uint32_t Deserialize(Buffer::Iterator start) override
Definition:
uan-header-common.cc:180
ns3::UanHeaderCommon::GetSerializedSize
uint32_t GetSerializedSize() const override
Definition:
uan-header-common.cc:160
ns3::UanHeaderCommon::m_dest
Mac8Address m_dest
The destination address.
Definition:
uan-header-common.h:152
ns3::UanHeaderCommon::GetType
uint8_t GetType() const
Get the header type value.
Definition:
uan-header-common.cc:130
ns3::UanHeaderCommon::m_src
Mac8Address m_src
The source address.
Definition:
uan-header-common.h:153
ns3::UanHeaderCommon::GetDest
Mac8Address GetDest() const
Get the destination address.
Definition:
uan-header-common.cc:118
ns3::UanHeaderCommon::UanHeaderCommon
UanHeaderCommon()
Default constructor.
Definition:
uan-header-common.cc:34
ns3::UanHeaderCommon::SetProtocolNumber
void SetProtocolNumber(uint16_t protocolNumber)
Set the packet type.
Definition:
uan-header-common.cc:89
ns3::UanHeaderCommon::Serialize
void Serialize(Buffer::Iterator start) const override
Definition:
uan-header-common.cc:166
ns3::UanHeaderCommon::GetSrc
Mac8Address GetSrc() const
Get the source address.
Definition:
uan-header-common.cc:124
ns3::UanHeaderCommon::m_uanProtocolBits
UanProtocolBits m_uanProtocolBits
The type and protocol bits.
Definition:
uan-header-common.h:154
ns3::UanHeaderCommon::SetDest
void SetDest(Mac8Address dest)
Set the destination address.
Definition:
uan-header-common.cc:71
ns3::UanHeaderCommon::SetType
void SetType(uint8_t type)
Set the header type.
Definition:
uan-header-common.cc:83
ns3::UanHeaderCommon::~UanHeaderCommon
~UanHeaderCommon() override
Destructor.
Definition:
uan-header-common.cc:66
ns3::UanHeaderCommon::Print
void Print(std::ostream &os) const override
Definition:
uan-header-common.cc:194
ns3::UanHeaderCommon::GetProtocolNumber
uint16_t GetProtocolNumber() const
Get the packet type value.
Definition:
uan-header-common.cc:136
ns3::UanHeaderCommon::GetInstanceTypeId
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition:
uan-header-common.cc:61
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:86
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition:
object-base.h:46
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: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
SIXLOWPAN_PROT_NUMBER
static const uint16_t SIXLOWPAN_PROT_NUMBER
Definition:
uan-header-common.cc:27
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 Tue May 28 2024 23:39:52 for ns-3 by
1.9.6