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
ripng-header.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2014 Universita' di Firenze, Italy
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
7
*/
8
9
#include "
ripng-header.h
"
10
11
#include "ns3/log.h"
12
13
namespace
ns3
14
{
15
16
/*
17
* RipNgRte
18
*/
19
NS_OBJECT_ENSURE_REGISTERED
(
RipNgRte
);
20
21
RipNgRte::RipNgRte
()
22
:
m_prefix
(
"::"
),
23
m_tag
(0),
24
m_prefixLen
(0),
25
m_metric
(16)
26
{
27
}
28
29
TypeId
30
RipNgRte::GetTypeId
()
31
{
32
static
TypeId
tid =
TypeId
(
"ns3::RipNgRte"
)
33
.
SetParent
<
Header
>()
34
.SetGroupName(
"Internet"
)
35
.AddConstructor<
RipNgRte
>();
36
return
tid;
37
}
38
39
TypeId
40
RipNgRte::GetInstanceTypeId
()
const
41
{
42
return
GetTypeId
();
43
}
44
45
void
46
RipNgRte::Print
(std::ostream& os)
const
47
{
48
os <<
"prefix "
<<
m_prefix
<<
"/"
<< int(
m_prefixLen
) <<
" Metric "
<< int(
m_metric
) <<
" Tag "
49
<< int(
m_tag
);
50
}
51
52
uint32_t
53
RipNgRte::GetSerializedSize
()
const
54
{
55
return
20;
56
}
57
58
void
59
RipNgRte::Serialize
(
Buffer::Iterator
i)
const
60
{
61
uint8_t tmp[16];
62
63
m_prefix
.Serialize(tmp);
64
i.
Write
(tmp, 16);
65
66
i.
WriteHtonU16
(
m_tag
);
67
i.
WriteU8
(
m_prefixLen
);
68
i.
WriteU8
(
m_metric
);
69
}
70
71
uint32_t
72
RipNgRte::Deserialize
(
Buffer::Iterator
i)
73
{
74
uint8_t tmp[16];
75
76
i.
Read
(tmp, 16);
77
m_prefix
.Set(tmp);
78
m_tag
= i.
ReadNtohU16
();
79
m_prefixLen
= i.
ReadU8
();
80
m_metric
= i.
ReadU8
();
81
82
return
GetSerializedSize
();
83
}
84
85
void
86
RipNgRte::SetPrefix
(
Ipv6Address
prefix)
87
{
88
m_prefix
= prefix;
89
}
90
91
Ipv6Address
92
RipNgRte::GetPrefix
()
const
93
{
94
return
m_prefix
;
95
}
96
97
void
98
RipNgRte::SetPrefixLen
(uint8_t prefixLen)
99
{
100
m_prefixLen
= prefixLen;
101
}
102
103
uint8_t
104
RipNgRte::GetPrefixLen
()
const
105
{
106
return
m_prefixLen
;
107
}
108
109
void
110
RipNgRte::SetRouteTag
(uint16_t routeTag)
111
{
112
m_tag
= routeTag;
113
}
114
115
uint16_t
116
RipNgRte::GetRouteTag
()
const
117
{
118
return
m_tag
;
119
}
120
121
void
122
RipNgRte::SetRouteMetric
(uint8_t routeMetric)
123
{
124
m_metric
= routeMetric;
125
}
126
127
uint8_t
128
RipNgRte::GetRouteMetric
()
const
129
{
130
return
m_metric
;
131
}
132
133
std::ostream&
134
operator<<
(std::ostream& os,
const
RipNgRte
& h)
135
{
136
h.
Print
(os);
137
return
os;
138
}
139
140
/*
141
* RipNgHeader
142
*/
143
NS_LOG_COMPONENT_DEFINE
(
"RipNgHeader"
);
144
NS_OBJECT_ENSURE_REGISTERED
(RipNgHeader);
145
146
RipNgHeader::RipNgHeader
()
147
:
m_command
(0)
148
{
149
}
150
151
TypeId
152
RipNgHeader::GetTypeId
()
153
{
154
static
TypeId
tid =
TypeId
(
"ns3::RipNgHeader"
)
155
.
SetParent
<
Header
>()
156
.SetGroupName(
"Internet"
)
157
.AddConstructor<
RipNgHeader
>();
158
return
tid;
159
}
160
161
TypeId
162
RipNgHeader::GetInstanceTypeId
()
const
163
{
164
return
GetTypeId
();
165
}
166
167
void
168
RipNgHeader::Print
(std::ostream& os)
const
169
{
170
os <<
"command "
<< int(
m_command
);
171
for
(
auto
iter =
m_rteList
.begin(); iter !=
m_rteList
.end(); iter++)
172
{
173
os <<
" | "
;
174
iter->Print(os);
175
}
176
}
177
178
uint32_t
179
RipNgHeader::GetSerializedSize
()
const
180
{
181
RipNgRte
rte;
182
return
4 +
m_rteList
.size() * rte.
GetSerializedSize
();
183
}
184
185
void
186
RipNgHeader::Serialize
(
Buffer::Iterator
start)
const
187
{
188
Buffer::Iterator
i = start;
189
190
i.
WriteU8
(uint8_t(
m_command
));
191
i.
WriteU8
(1);
192
i.
WriteU16
(0);
193
194
for
(
auto
iter =
m_rteList
.begin(); iter !=
m_rteList
.end(); iter++)
195
{
196
iter->Serialize(i);
197
i.
Next
(iter->GetSerializedSize());
198
}
199
}
200
201
uint32_t
202
RipNgHeader::Deserialize
(
Buffer::Iterator
start)
203
{
204
Buffer::Iterator
i = start;
205
206
uint8_t temp;
207
temp = i.
ReadU8
();
208
if
((temp ==
REQUEST
) || (temp ==
RESPONSE
))
209
{
210
m_command
= temp;
211
}
212
else
213
{
214
return
0;
215
}
216
217
if
(i.
ReadU8
() != 1)
218
{
219
NS_LOG_LOGIC
(
"RIP received a message with mismatch version, ignoring."
);
220
return
0;
221
}
222
223
if
(i.
ReadU16
() != 0)
224
{
225
NS_LOG_LOGIC
(
"RIP received a message with invalid filled flags, ignoring."
);
226
return
0;
227
}
228
229
uint8_t rteNumber = i.
GetRemainingSize
() / 20;
230
for
(uint8_t n = 0; n < rteNumber; n++)
231
{
232
RipNgRte
rte;
233
i.
Next
(rte.
Deserialize
(i));
234
m_rteList
.push_back(rte);
235
}
236
237
return
GetSerializedSize
();
238
}
239
240
void
241
RipNgHeader::SetCommand
(
RipNgHeader::Command_e
command)
242
{
243
m_command
= command;
244
}
245
246
RipNgHeader::Command_e
247
RipNgHeader::GetCommand
()
const
248
{
249
return
RipNgHeader::Command_e
(
m_command
);
250
}
251
252
void
253
RipNgHeader::AddRte
(
RipNgRte
rte)
254
{
255
m_rteList
.push_back(rte);
256
}
257
258
void
259
RipNgHeader::ClearRtes
()
260
{
261
m_rteList
.clear();
262
}
263
264
uint16_t
265
RipNgHeader::GetRteNumber
()
const
266
{
267
return
m_rteList
.size();
268
}
269
270
std::list<RipNgRte>
271
RipNgHeader::GetRteList
()
const
272
{
273
return
m_rteList
;
274
}
275
276
std::ostream&
277
operator<<
(std::ostream& os,
const
RipNgHeader
& h)
278
{
279
h.
Print
(os);
280
return
os;
281
}
282
283
}
// namespace ns3
ns3::Buffer::Iterator
iterator in a Buffer instance
Definition
buffer.h:89
ns3::Buffer::Iterator::GetRemainingSize
uint32_t GetRemainingSize() const
Definition
buffer.cc:1162
ns3::Buffer::Iterator::ReadU8
uint8_t ReadU8()
Definition
buffer.h:1016
ns3::Buffer::Iterator::WriteU8
void WriteU8(uint8_t data)
Definition
buffer.h:870
ns3::Buffer::Iterator::Write
void Write(const uint8_t *buffer, uint32_t size)
Definition
buffer.cc:937
ns3::Buffer::Iterator::WriteU16
void WriteU16(uint16_t data)
Definition
buffer.cc:848
ns3::Buffer::Iterator::Read
void Read(uint8_t *buffer, uint32_t size)
Definition
buffer.cc:1114
ns3::Buffer::Iterator::WriteHtonU16
void WriteHtonU16(uint16_t data)
Definition
buffer.h:904
ns3::Buffer::Iterator::ReadNtohU16
uint16_t ReadNtohU16()
Definition
buffer.h:943
ns3::Buffer::Iterator::ReadU16
uint16_t ReadU16()
Definition
buffer.h:1024
ns3::Buffer::Iterator::Next
void Next()
go forward by one byte
Definition
buffer.h:842
ns3::Header
Protocol header serialization and deserialization.
Definition
header.h:33
ns3::Ipv6Address
Describes an IPv6 address.
Definition
ipv6-address.h:38
ns3::RipNgHeader
RipNgHeader - see RFC 2080
Definition
ripng-header.h:136
ns3::RipNgHeader::m_command
uint8_t m_command
command type
Definition
ripng-header.h:218
ns3::RipNgHeader::SetCommand
void SetCommand(Command_e command)
Set the command.
Definition
ripng-header.cc:241
ns3::RipNgHeader::RipNgHeader
RipNgHeader()
Definition
ripng-header.cc:146
ns3::RipNgHeader::ClearRtes
void ClearRtes()
Clear all the RTEs from the header.
Definition
ripng-header.cc:259
ns3::RipNgHeader::GetRteNumber
uint16_t GetRteNumber() const
Get the number of RTE included in the message.
Definition
ripng-header.cc:265
ns3::RipNgHeader::GetTypeId
static TypeId GetTypeId()
Get the type ID.
Definition
ripng-header.cc:152
ns3::RipNgHeader::Serialize
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
Definition
ripng-header.cc:186
ns3::RipNgHeader::GetInstanceTypeId
TypeId GetInstanceTypeId() const override
Return the instance type identifier.
Definition
ripng-header.cc:162
ns3::RipNgHeader::m_rteList
std::list< RipNgRte > m_rteList
list of the RTEs in the message
Definition
ripng-header.h:219
ns3::RipNgHeader::Print
void Print(std::ostream &os) const override
Definition
ripng-header.cc:168
ns3::RipNgHeader::Deserialize
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
Definition
ripng-header.cc:202
ns3::RipNgHeader::Command_e
Command_e
Commands to be used in RipNg headers.
Definition
ripng-header.h:177
ns3::RipNgHeader::REQUEST
@ REQUEST
Definition
ripng-header.h:178
ns3::RipNgHeader::RESPONSE
@ RESPONSE
Definition
ripng-header.h:179
ns3::RipNgHeader::GetSerializedSize
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
Definition
ripng-header.cc:179
ns3::RipNgHeader::GetCommand
Command_e GetCommand() const
Get the command.
Definition
ripng-header.cc:247
ns3::RipNgHeader::GetRteList
std::list< RipNgRte > GetRteList() const
Get the list of the RTEs included in the message.
Definition
ripng-header.cc:271
ns3::RipNgHeader::AddRte
void AddRte(RipNgRte rte)
Add a RTE to the message.
Definition
ripng-header.cc:253
ns3::RipNgRte
RipNg Routing Table Entry (RTE) - see RFC 2080
Definition
ripng-header.h:29
ns3::RipNgRte::m_tag
uint16_t m_tag
route tag
Definition
ripng-header.h:116
ns3::RipNgRte::GetTypeId
static TypeId GetTypeId()
Get the type ID.
Definition
ripng-header.cc:30
ns3::RipNgRte::m_metric
uint8_t m_metric
route metric
Definition
ripng-header.h:118
ns3::RipNgRte::m_prefix
Ipv6Address m_prefix
prefix
Definition
ripng-header.h:115
ns3::RipNgRte::GetPrefix
Ipv6Address GetPrefix() const
Get the prefix.
Definition
ripng-header.cc:92
ns3::RipNgRte::GetRouteMetric
uint8_t GetRouteMetric() const
Get the route metric.
Definition
ripng-header.cc:128
ns3::RipNgRte::GetPrefixLen
uint8_t GetPrefixLen() const
Get the prefix length.
Definition
ripng-header.cc:104
ns3::RipNgRte::GetRouteTag
uint16_t GetRouteTag() const
Get the route tag.
Definition
ripng-header.cc:116
ns3::RipNgRte::m_prefixLen
uint8_t m_prefixLen
prefix length
Definition
ripng-header.h:117
ns3::RipNgRte::SetPrefix
void SetPrefix(Ipv6Address prefix)
Set the prefix.
Definition
ripng-header.cc:86
ns3::RipNgRte::Print
void Print(std::ostream &os) const override
Definition
ripng-header.cc:46
ns3::RipNgRte::Serialize
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
Definition
ripng-header.cc:59
ns3::RipNgRte::SetPrefixLen
void SetPrefixLen(uint8_t prefixLen)
Set the prefix length.
Definition
ripng-header.cc:98
ns3::RipNgRte::Deserialize
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
Definition
ripng-header.cc:72
ns3::RipNgRte::SetRouteMetric
void SetRouteMetric(uint8_t routeMetric)
Set the route metric.
Definition
ripng-header.cc:122
ns3::RipNgRte::GetInstanceTypeId
TypeId GetInstanceTypeId() const override
Return the instance type identifier.
Definition
ripng-header.cc:40
ns3::RipNgRte::GetSerializedSize
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
Definition
ripng-header.cc:53
ns3::RipNgRte::RipNgRte
RipNgRte()
Definition
ripng-header.cc:21
ns3::RipNgRte::SetRouteTag
void SetRouteTag(uint16_t routeTag)
Set the route tag.
Definition
ripng-header.cc:110
ns3::TypeId
a unique identifier for an interface.
Definition
type-id.h:49
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition
type-id.cc:1001
uint32_t
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:191
NS_LOG_LOGIC
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition
log.h:271
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::operator<<
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition
angles.cc:148
ripng-header.h
src
internet
model
ripng-header.cc
Generated on Wed Jun 11 2025 13:15:30 for ns-3 by
1.13.2