A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
uan-header-common.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2009 University of Washington
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Author: Leonard Tracy <lentracy@gmail.com>
19
*/
20
21
#include "
uan-header-common.h
"
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
NS_OBJECT_ENSURE_REGISTERED
(UanHeaderCommon);
31
32
UanHeaderCommon::UanHeaderCommon
()
33
{
34
}
35
36
UanHeaderCommon::UanHeaderCommon
(
const
Mac8Address
src,
const
Mac8Address
dest, uint8_t type, uint8_t protocolNumber)
37
:
Header
(),
38
m_dest (dest),
39
m_src (src)
40
{
41
SetProtocolNumber
(protocolNumber);
42
m_uanProtocolBits
.
m_type
= type;
43
}
44
45
TypeId
46
UanHeaderCommon::GetTypeId
(
void
)
47
{
48
static
TypeId
tid =
TypeId
(
"ns3::UanHeaderCommon"
)
49
.
SetParent
<
Header
> ()
50
.SetGroupName (
"Uan"
)
51
.AddConstructor<
UanHeaderCommon
> ()
52
;
53
return
tid;
54
}
55
56
TypeId
57
UanHeaderCommon::GetInstanceTypeId
(
void
)
const
58
{
59
return
GetTypeId
();
60
}
61
UanHeaderCommon::~UanHeaderCommon
()
62
{
63
}
64
65
66
void
67
UanHeaderCommon::SetDest
(
Mac8Address
dest)
68
{
69
m_dest
= dest;
70
}
71
void
72
UanHeaderCommon::SetSrc
(
Mac8Address
src)
73
{
74
m_src
= src;
75
}
76
77
void
78
UanHeaderCommon::SetType
(uint8_t type)
79
{
80
m_uanProtocolBits
.
m_type
= type;
81
}
82
83
void
84
UanHeaderCommon::SetProtocolNumber
(uint16_t protocolNumber)
85
{
86
if
(protocolNumber == 0)
87
m_uanProtocolBits
.
m_protocolNumber
= 0;
88
else
if
(protocolNumber ==
IPV4_PROT_NUMBER
)
89
m_uanProtocolBits
.
m_protocolNumber
= 1;
90
else
if
(protocolNumber ==
ARP_PROT_NUMBER
)
91
m_uanProtocolBits
.
m_protocolNumber
= 2;
92
else
if
(protocolNumber ==
IPV6_PROT_NUMBER
)
93
m_uanProtocolBits
.
m_protocolNumber
= 3;
94
else
95
NS_ASSERT_MSG
(
false
,
"UanHeaderCommon::SetProtocolNumber(): Protocol not supported"
);
96
}
97
98
Mac8Address
99
UanHeaderCommon::GetDest
(
void
)
const
100
{
101
return
m_dest
;
102
}
103
Mac8Address
104
UanHeaderCommon::GetSrc
(
void
)
const
105
{
106
return
m_src
;
107
}
108
uint8_t
109
UanHeaderCommon::GetType
(
void
)
const
110
{
111
return
m_uanProtocolBits
.
m_type
;
112
}
113
114
uint16_t
115
UanHeaderCommon::GetProtocolNumber
(
void
)
const
116
{
117
if
(
m_uanProtocolBits
.
m_protocolNumber
== 1)
118
return
IPV4_PROT_NUMBER
;
119
if
(
m_uanProtocolBits
.
m_protocolNumber
== 2)
120
return
ARP_PROT_NUMBER
;
121
if
(
m_uanProtocolBits
.
m_protocolNumber
== 3)
122
return
IPV6_PROT_NUMBER
;
123
return
0;
124
}
125
126
// Inherrited methods
127
128
uint32_t
129
UanHeaderCommon::GetSerializedSize
(
void
)
const
130
{
131
return
1 + 1 + 1;
132
}
133
134
void
135
UanHeaderCommon::Serialize
(
Buffer::Iterator
start
)
const
136
{
137
uint8_t
address
= 0;
138
m_src
.
CopyTo
(&
address
);
139
start
.WriteU8 (
address
);
140
m_dest
.
CopyTo
(&
address
);
141
start
.WriteU8 (
address
);
142
char
tmp =
m_uanProtocolBits
.
m_type
;
143
tmp = tmp << 4;
144
tmp +=
m_uanProtocolBits
.
m_protocolNumber
;
145
start
.WriteU8 (tmp);
146
}
147
148
uint32_t
149
UanHeaderCommon::Deserialize
(
Buffer::Iterator
start
)
150
{
151
Buffer::Iterator
rbuf =
start
;
152
153
m_src
=
Mac8Address
(rbuf.
ReadU8
());
154
m_dest
=
Mac8Address
(rbuf.
ReadU8
());
155
char
tmp = rbuf.
ReadU8
();
156
m_uanProtocolBits
.
m_type
= tmp >> 4;
157
m_uanProtocolBits
.
m_protocolNumber
= tmp;
158
159
return
rbuf.
GetDistanceFrom
(
start
);
160
}
161
162
void
163
UanHeaderCommon::Print
(std::ostream &os)
const
164
{
165
os <<
"UAN src="
<<
m_src
<<
" dest="
<<
m_dest
<<
" type="
<< (uint32_t)
m_uanProtocolBits
.
m_type
<<
"Protocol Number="
<< (uint32_t)
m_uanProtocolBits
.
m_protocolNumber
;
166
}
167
168
169
170
171
}
// namespace ns3
ns3::Buffer::Iterator
iterator in a Buffer instance
Definition:
buffer.h:99
ns3::Buffer::Iterator::ReadU8
uint8_t ReadU8(void)
Definition:
buffer.h:1021
ns3::Buffer::Iterator::GetDistanceFrom
uint32_t GetDistanceFrom(Iterator const &o) const
Definition:
buffer.cc:788
ns3::Header
Protocol header serialization and deserialization.
Definition:
header.h:43
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:43
ns3::Mac8Address::CopyTo
void CopyTo(uint8_t *pBuffer) const
Writes address to buffer parameter.
Definition:
mac8-address.cc:80
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:922
ns3::UanHeaderCommon
Common packet header fields.
Definition:
uan-header-common.h:65
ns3::UanHeaderCommon::~UanHeaderCommon
virtual ~UanHeaderCommon()
Destructor.
Definition:
uan-header-common.cc:61
ns3::UanHeaderCommon::Print
virtual void Print(std::ostream &os) const
Definition:
uan-header-common.cc:163
ns3::UanHeaderCommon::SetSrc
void SetSrc(Mac8Address src)
Set the source address.
Definition:
uan-header-common.cc:72
ns3::UanHeaderCommon::GetType
uint8_t GetType(void) const
Get the header type value.
Definition:
uan-header-common.cc:109
ns3::UanHeaderCommon::Serialize
virtual void Serialize(Buffer::Iterator start) const
Definition:
uan-header-common.cc:135
ns3::UanHeaderCommon::m_dest
Mac8Address m_dest
The destination address.
Definition:
uan-header-common.h:147
ns3::UanHeaderCommon::GetTypeId
static TypeId GetTypeId(void)
Register this type.
Definition:
uan-header-common.cc:46
ns3::UanHeaderCommon::m_src
Mac8Address m_src
The source address.
Definition:
uan-header-common.h:148
ns3::UanHeaderCommon::UanHeaderCommon
UanHeaderCommon()
Default constructor.
Definition:
uan-header-common.cc:32
ns3::UanHeaderCommon::GetSerializedSize
virtual uint32_t GetSerializedSize(void) const
Definition:
uan-header-common.cc:129
ns3::UanHeaderCommon::GetSrc
Mac8Address GetSrc(void) const
Get the source address.
Definition:
uan-header-common.cc:104
ns3::UanHeaderCommon::GetDest
Mac8Address GetDest(void) const
Get the destination address.
Definition:
uan-header-common.cc:99
ns3::UanHeaderCommon::SetProtocolNumber
void SetProtocolNumber(uint16_t protocolNumber)
Set the packet type.
Definition:
uan-header-common.cc:84
ns3::UanHeaderCommon::m_uanProtocolBits
UanProtocolBits m_uanProtocolBits
The type and protocol bits.
Definition:
uan-header-common.h:149
ns3::UanHeaderCommon::SetDest
void SetDest(Mac8Address dest)
Set the destination address.
Definition:
uan-header-common.cc:67
ns3::UanHeaderCommon::SetType
void SetType(uint8_t type)
Set the header type.
Definition:
uan-header-common.cc:78
ns3::UanHeaderCommon::GetProtocolNumber
uint16_t GetProtocolNumber(void) const
Get the packet type value.
Definition:
uan-header-common.cc:115
ns3::UanHeaderCommon::GetInstanceTypeId
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
Definition:
uan-header-common.cc:57
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:88
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition:
object-base.h:45
first.address
address
Definition:
first.py:44
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
visualizer.core.start
def start()
Definition:
core.py:1853
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 Tue Feb 6 2024 19:21:28 for ns-3 by
1.9.1