A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
ipv6-header.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2007-2008 Louis Pasteur University
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: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
19
*/
20
21
#include "ns3/assert.h"
22
#include "ns3/log.h"
23
#include "ns3/header.h"
24
25
#include "ns3/address-utils.h"
26
#include "
ipv6-header.h
"
27
28
namespace
ns3
{
29
30
NS_LOG_COMPONENT_DEFINE
(
"Ipv6Header"
);
31
32
NS_OBJECT_ENSURE_REGISTERED
(Ipv6Header);
33
34
Ipv6Header::Ipv6Header
()
35
: m_version (6),
36
m_trafficClass (0),
37
m_flowLabel (1),
38
m_payloadLength (0),
39
m_nextHeader (0),
40
m_hopLimit (0)
41
{
42
SetSourceAddress
(
Ipv6Address
(
"::"
));
43
SetDestinationAddress
(
Ipv6Address
(
"::"
));
44
}
45
46
void
Ipv6Header::SetTrafficClass
(uint8_t traffic)
47
{
48
m_trafficClass
= traffic;
49
}
50
51
uint8_t
Ipv6Header::GetTrafficClass
()
const
52
{
53
return
m_trafficClass
;
54
}
55
56
void
Ipv6Header::SetFlowLabel
(uint32_t flow)
57
{
58
m_flowLabel
= flow;
59
}
60
61
uint32_t
Ipv6Header::GetFlowLabel
()
const
62
{
63
return
m_flowLabel
;
64
}
65
66
void
Ipv6Header::SetPayloadLength
(uint16_t len)
67
{
68
m_payloadLength
= len;
69
}
70
71
uint16_t
Ipv6Header::GetPayloadLength
()
const
72
{
73
return
m_payloadLength
;
74
}
75
76
void
Ipv6Header::SetNextHeader
(uint8_t next)
77
{
78
m_nextHeader
= next;
79
}
80
81
uint8_t
Ipv6Header::GetNextHeader
()
const
82
{
83
return
m_nextHeader
;
84
}
85
86
void
Ipv6Header::SetHopLimit
(uint8_t limit)
87
{
88
m_hopLimit
= limit;
89
}
90
91
uint8_t
Ipv6Header::GetHopLimit
()
const
92
{
93
return
m_hopLimit
;
94
}
95
96
void
Ipv6Header::SetSourceAddress
(
Ipv6Address
src)
97
{
98
m_sourceAddress
= src;
99
}
100
101
Ipv6Address
Ipv6Header::GetSourceAddress
()
const
102
{
103
return
m_sourceAddress
;
104
}
105
106
void
Ipv6Header::SetDestinationAddress
(
Ipv6Address
dst)
107
{
108
m_destinationAddress
= dst;
109
}
110
111
Ipv6Address
Ipv6Header::GetDestinationAddress
()
const
112
{
113
return
m_destinationAddress
;
114
}
115
116
TypeId
Ipv6Header::GetTypeId
(
void
)
117
{
118
static
TypeId
tid =
TypeId
(
"ns3::Ipv6Header"
)
119
.
SetParent
<
Header
> ()
120
.SetGroupName (
"Internet"
)
121
.AddConstructor<
Ipv6Header
> ()
122
;
123
return
tid;
124
}
125
126
TypeId
Ipv6Header::GetInstanceTypeId
(
void
)
const
127
{
128
return
GetTypeId
();
129
}
130
131
void
Ipv6Header::Print
(std::ostream& os)
const
132
{
133
os <<
"("
134
"Version "
<<
m_version
<<
" "
135
<<
"Traffic class 0x"
<< std::hex <<
m_trafficClass
<< std::dec <<
" "
136
<<
"Flow Label 0x"
<< std::hex <<
m_flowLabel
<< std::dec <<
" "
137
<<
"Payload Length "
<<
m_payloadLength
<<
" "
138
<<
"Next Header "
<< std::dec << (uint32_t)
m_nextHeader
<<
" "
139
<<
"Hop Limit "
<< std::dec << (uint32_t)
m_hopLimit
<<
" )"
140
<<
m_sourceAddress
<<
" > "
<<
m_destinationAddress
141
;
142
}
143
144
uint32_t
Ipv6Header::GetSerializedSize
()
const
145
{
146
return
10 * 4;
147
}
148
149
void
Ipv6Header::Serialize
(
Buffer::Iterator
start
)
const
150
{
151
Buffer::Iterator
i =
start
;
152
uint32_t vTcFl = 0;
/* version, Traffic Class and Flow Label fields */
153
154
vTcFl= (6 << 28) | (
m_trafficClass
<< 20) | (
m_flowLabel
);
155
156
i.
WriteHtonU32
(vTcFl);
157
i.
WriteHtonU16
(
m_payloadLength
);
158
i.
WriteU8
(
m_nextHeader
);
159
i.
WriteU8
(
m_hopLimit
);
160
161
WriteTo
(i,
m_sourceAddress
);
162
WriteTo
(i,
m_destinationAddress
);
163
}
164
165
uint32_t
Ipv6Header::Deserialize
(
Buffer::Iterator
start
)
166
{
167
Buffer::Iterator
i =
start
;
168
uint32_t vTcFl = 0;
169
170
vTcFl = i.
ReadNtohU32
();
171
m_version
= vTcFl >> 28;
172
173
NS_ASSERT
((
m_version
) == 6);
174
175
m_trafficClass
= (uint8_t)((vTcFl >> 20) & 0x000000ff);
176
m_flowLabel
= vTcFl & 0xfff00000;
177
m_payloadLength
= i.
ReadNtohU16
();
178
m_nextHeader
= i.
ReadU8
();
179
m_hopLimit
= i.
ReadU8
();
180
181
ReadFrom
(i,
m_sourceAddress
);
182
ReadFrom
(i,
m_destinationAddress
);
183
184
return
GetSerializedSize
();
185
}
186
187
}
/* namespace ns3 */
188
ns3::Header
Protocol header serialization and deserialization.
Definition:
header.h:42
ns3::Ipv6Header::GetTrafficClass
uint8_t GetTrafficClass(void) const
Get the "Traffic class" field.
Definition:
ipv6-header.cc:51
ns3::Ipv6Header::GetSerializedSize
virtual uint32_t GetSerializedSize(void) const
Get the serialized size of the packet.
Definition:
ipv6-header.cc:144
ns3::Ipv6Header::GetNextHeader
uint8_t GetNextHeader(void) const
Get the next header.
Definition:
ipv6-header.cc:81
ns3::Ipv6Header::SetPayloadLength
void SetPayloadLength(uint16_t len)
Set the "Payload length" field.
Definition:
ipv6-header.cc:66
ns3::Ipv6Header::m_flowLabel
uint32_t m_flowLabel
The flow label.
Definition:
ipv6-header.h:200
ns3::Ipv6Header
Introspection did not find any typical Config paths.
Definition:
ipv6-header.h:33
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition:
object-base.h:44
ns3::Ipv6Header::m_version
uint32_t m_version
The version (always equal to 6).
Definition:
ipv6-header.h:190
ns3::ReadFrom
void ReadFrom(Buffer::Iterator &i, Ipv4Address &ad)
Read an Ipv4Address from a Buffer.
Definition:
address-utils.cc:70
visualizer.core.start
def start()
Definition:
core.py:1482
ns3::Ipv6Header::m_trafficClass
uint32_t m_trafficClass
The traffic class.
Definition:
ipv6-header.h:194
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:67
ns3::WriteTo
void WriteTo(Buffer::Iterator &i, Ipv4Address ad)
Write an Ipv4Address to a Buffer.
Definition:
address-utils.cc:28
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:201
ns3::Ipv6Header::SetNextHeader
void SetNextHeader(uint8_t next)
Set the "Next header" field.
Definition:
ipv6-header.cc:76
ns3::Ipv6Header::m_sourceAddress
Ipv6Address m_sourceAddress
The source address.
Definition:
ipv6-header.h:220
ns3::Ipv6Header::GetInstanceTypeId
virtual TypeId GetInstanceTypeId(void) const
Return the instance type identifier.
Definition:
ipv6-header.cc:126
ns3::Buffer::Iterator::ReadNtohU32
uint32_t ReadNtohU32(void)
Definition:
buffer.h:977
ns3::Buffer::Iterator
iterator in a Buffer instance
Definition:
buffer.h:98
ns3::Ipv6Header::m_destinationAddress
Ipv6Address m_destinationAddress
The destination address.
Definition:
ipv6-header.h:225
ns3::Buffer::Iterator::WriteHtonU16
void WriteHtonU16(uint16_t data)
Definition:
buffer.h:912
ns3::Ipv6Header::GetFlowLabel
uint32_t GetFlowLabel(void) const
Get the "Flow label" field.
Definition:
ipv6-header.cc:61
ns3::Ipv6Header::Deserialize
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
Definition:
ipv6-header.cc:165
ipv6-header.h
ns3::Ipv6Header::GetHopLimit
uint8_t GetHopLimit(void) const
Get the "Hop limit" field (TTL).
Definition:
ipv6-header.cc:91
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Ipv6Header::Print
virtual void Print(std::ostream &os) const
Print some informations about the packet.
Definition:
ipv6-header.cc:131
ns3::Ipv6Header::GetPayloadLength
uint16_t GetPayloadLength(void) const
Get the "Payload length" field.
Definition:
ipv6-header.cc:71
ns3::Buffer::Iterator::WriteHtonU32
void WriteHtonU32(uint32_t data)
Definition:
buffer.h:931
ns3::Ipv6Header::Ipv6Header
Ipv6Header(void)
Constructor.
Definition:
ipv6-header.cc:34
ns3::Ipv6Header::GetTypeId
static TypeId GetTypeId(void)
Get the type identifier.
Definition:
ipv6-header.cc:116
ns3::Ipv6Header::SetSourceAddress
void SetSourceAddress(Ipv6Address src)
Set the "Source address" field.
Definition:
ipv6-header.cc:96
ns3::Ipv6Address
Describes an IPv6 address.
Definition:
ipv6-address.h:47
ns3::Ipv6Header::Serialize
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
Definition:
ipv6-header.cc:149
ns3::Ipv6Header::SetHopLimit
void SetHopLimit(uint8_t limit)
Set the "Hop limit" field (TTL).
Definition:
ipv6-header.cc:86
ns3::Buffer::Iterator::WriteU8
void WriteU8(uint8_t data)
Definition:
buffer.h:876
ns3::Ipv6Header::GetSourceAddress
Ipv6Address GetSourceAddress(void) const
Get the "Source address" field.
Definition:
ipv6-header.cc:101
ns3::Ipv6Header::SetFlowLabel
void SetFlowLabel(uint32_t flow)
Set the "Flow label" field.
Definition:
ipv6-header.cc:56
ns3::Ipv6Header::m_payloadLength
uint16_t m_payloadLength
The payload length.
Definition:
ipv6-header.h:205
ns3::Buffer::Iterator::ReadU8
uint8_t ReadU8(void)
Definition:
buffer.h:1028
ns3::Ipv6Header::SetTrafficClass
void SetTrafficClass(uint8_t traffic)
Set the "Traffic class" field.
Definition:
ipv6-header.cc:46
ns3::Ipv6Header::m_hopLimit
uint8_t m_hopLimit
The Hop limit value.
Definition:
ipv6-header.h:215
ns3::Ipv6Header::m_nextHeader
uint8_t m_nextHeader
The Next header number.
Definition:
ipv6-header.h:210
ns3::Buffer::Iterator::ReadNtohU16
uint16_t ReadNtohU16(void)
Definition:
buffer.h:953
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:57
ns3::Ipv6Header::SetDestinationAddress
void SetDestinationAddress(Ipv6Address dst)
Set the "Destination address" field.
Definition:
ipv6-header.cc:106
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Definition:
type-id.cc:638
ns3::Ipv6Header::GetDestinationAddress
Ipv6Address GetDestinationAddress(void) const
Get the "Destination address" field.
Definition:
ipv6-header.cc:111
src
internet
model
ipv6-header.cc
Generated on Wed May 13 2015 14:59:17 for ns-3 by
1.8.9.1