A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv6-extension-header.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008-2009 Strasbourg University
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: David Gross <gdavid.devel@gmail.com>
7 */
8
9#ifndef IPV6_EXTENSION_HEADER_H
10#define IPV6_EXTENSION_HEADER_H
11
12#include "ipv6-option-header.h"
13
14#include "ns3/header.h"
15#include "ns3/ipv6-address.h"
16
17#include <list>
18#include <ostream>
19#include <vector>
20
21namespace ns3
22{
23
24/**
25 * @ingroup ipv6HeaderExt
26 *
27 * @brief Header for IPv6 Extension.
28 */
30{
31 public:
32 /**
33 * @brief Get the type identificator.
34 * @return type identificator
35 */
36 static TypeId GetTypeId();
37
38 /**
39 * @brief Get the instance type ID.
40 * @return instance type ID
41 */
42 TypeId GetInstanceTypeId() const override;
43
44 /**
45 * @brief Constructor.
46 */
48
49 /**
50 * @brief Destructor.
51 */
52 ~Ipv6ExtensionHeader() override;
53
54 /**
55 * @brief Set the "Next header" field.
56 * @param nextHeader the next header number
57 */
58 void SetNextHeader(uint8_t nextHeader);
59
60 /**
61 * @brief Get the next header.
62 * @return the next header number
63 */
64 uint8_t GetNextHeader() const;
65
66 /**
67 * brief Set the length of the extension.
68 * @param length the length of the extension in bytes
69 */
70 void SetLength(uint16_t length);
71
72 /**
73 * @brief Get the length of the extension.
74 * @return the length of the extension
75 */
76 uint16_t GetLength() const;
77
78 /**
79 * @brief Print some information about the packet.
80 * @param os output stream
81 */
82 void Print(std::ostream& os) const override;
83
84 /**
85 * @brief Get the serialized size of the packet.
86 * @return size
87 */
88 uint32_t GetSerializedSize() const override;
89
90 /**
91 * @brief Serialize the packet.
92 * @param start Buffer iterator
93 */
94 void Serialize(Buffer::Iterator start) const override;
95
96 /**
97 * @brief Deserialize the packet.
98 * @param start Buffer iterator
99 * @return size of the packet
100 */
101 uint32_t Deserialize(Buffer::Iterator start) override;
102
103 protected:
104 /**
105 * @brief The "length" field.
106 */
107 uint8_t m_length;
108
109 private:
110 /**
111 * @brief The "next header" field.
112 */
114
115 /**
116 * @brief The data of the extension.
117 */
119};
120
121/**
122 * @ingroup ipv6HeaderExt
123 *
124 * @brief Option field for an IPv6ExtensionHeader.
125 *
126 * Enables adding options to an IPv6ExtensionHeader.
127 *
128 * Implementor's note: Make sure to add the result of
129 * OptionField::GetSerializedSize () to your IPv6ExtensionHeader::GetSerializedSize ()
130 * return value. Call OptionField::Serialize and OptionField::Deserialize at the
131 * end of your corresponding IPv6ExtensionHeader methods.
132 */
134{
135 public:
136 /**
137 * @brief Constructor.
138 * @param optionsOffset option offset
139 */
140 OptionField(uint32_t optionsOffset);
141
142 /**
143 * @brief Destructor.
144 */
145 ~OptionField();
146
147 /**
148 * @brief Get the serialized size of the packet.
149 * @return size
150 */
152
153 /**
154 * @brief Serialize all added options.
155 * @param start Buffer iterator
156 */
157 void Serialize(Buffer::Iterator start) const;
158
159 /**
160 * @brief Deserialize the packet.
161 * @param start Buffer iterator
162 * @param length length
163 * @return size of the packet
164 */
166
167 /**
168 * @brief Serialize the option, prepending pad1 or padn option as necessary
169 * @param option the option header to serialize
170 */
171 void AddOption(const Ipv6OptionHeader& option);
172
173 /**
174 * @brief Get the offset where the options begin, measured from the start of
175 * the extension header.
176 * @return the offset from the start of the extension header
177 */
179
180 /**
181 * @brief Get the buffer.
182 * @return buffer
183 */
185
186 private:
187 /**
188 * @brief Calculate padding.
189 * @param alignment alignment
190 * @return the number of pad bytes
191 */
193
194 /**
195 * @brief Data payload.
196 */
198
199 /**
200 * @brief Offset.
201 */
203};
204
205/**
206 * @ingroup ipv6HeaderExt
207 *
208 * @brief Header of IPv6 Extension "Hop by Hop"
209 */
211{
212 public:
213 /**
214 * @brief Get the type identificator.
215 * @return type identificator
216 */
217 static TypeId GetTypeId();
218
219 /**
220 * @brief Get the instance type ID.
221 * @return instance type ID
222 */
223 TypeId GetInstanceTypeId() const override;
224
225 /**
226 * @brief Constructor.
227 */
229
230 /**
231 * @brief Destructor.
232 */
234
235 /**
236 * @brief Print some information about the packet.
237 * @param os output stream
238 */
239 void Print(std::ostream& os) const override;
240
241 /**
242 * @brief Get the serialized size of the packet.
243 * @return size
244 */
245 uint32_t GetSerializedSize() const override;
246
247 /**
248 * @brief Serialize the packet.
249 * @param start Buffer iterator
250 */
251 void Serialize(Buffer::Iterator start) const override;
252
253 /**
254 * @brief Deserialize the packet.
255 * @param start Buffer iterator
256 * @return size of the packet
257 */
258 uint32_t Deserialize(Buffer::Iterator start) override;
259};
260
261/**
262 * @ingroup ipv6HeaderExt
263 *
264 * @brief Header of IPv6 Extension Destination
265 */
267{
268 public:
269 /**
270 * @brief Get the type identificator.
271 * @return type identificator
272 */
273 static TypeId GetTypeId();
274
275 /**
276 * @brief Get the instance type ID.
277 * @return instance type ID
278 */
279 TypeId GetInstanceTypeId() const override;
280
281 /**
282 * @brief Constructor.
283 */
285
286 /**
287 * @brief Destructor.
288 */
290
291 /**
292 * @brief Print some information about the packet.
293 * @param os output stream
294 */
295 void Print(std::ostream& os) const override;
296
297 /**
298 * @brief Get the serialized size of the packet.
299 * @return size
300 */
301 uint32_t GetSerializedSize() const override;
302
303 /**
304 * @brief Serialize the packet.
305 * @param start Buffer iterator
306 */
307 void Serialize(Buffer::Iterator start) const override;
308
309 /**
310 * @brief Deserialize the packet.
311 * @param start Buffer iterator
312 * @return size of the packet
313 */
314 uint32_t Deserialize(Buffer::Iterator start) override;
315};
316
317/**
318 * @ingroup ipv6HeaderExt
319 *
320 * @brief Header of IPv6 Extension Fragment
321 */
323{
324 public:
325 /**
326 * @brief Get the type identificator.
327 * @return type identificator
328 */
329 static TypeId GetTypeId();
330
331 /**
332 * @brief Get the instance type ID.
333 * @return instance type ID
334 */
335 TypeId GetInstanceTypeId() const override;
336
337 /**
338 * @brief Constructor.
339 */
341
342 /**
343 * @brief Destructor.
344 */
346
347 /**
348 * @brief Set the "Offset" field.
349 * @param offset the offset of the fragment
350 */
351 void SetOffset(uint16_t offset);
352
353 /**
354 * @brief Get the field "Offset".
355 * @return the offset of the fragment
356 */
357 uint16_t GetOffset() const;
358
359 /**
360 * @brief Set the status of "More Fragment" bit.
361 * @param moreFragment the bit "More Fragment"
362 */
363 void SetMoreFragment(bool moreFragment);
364
365 /**
366 * @brief Get the status of "More Fragment" bit.
367 * @return the status of "More Fragment" bit.
368 */
369 bool GetMoreFragment() const;
370
371 /**
372 * @brief Set the "Identification" field.
373 * @param identification the identifier of the fragment
374 */
375 void SetIdentification(uint32_t identification);
376
377 /**
378 * @brief Get the field "Identification".
379 * @return the identifier of the fragment
380 */
382
383 /**
384 * @brief Print some information about the packet.
385 * @param os output stream
386 */
387 void Print(std::ostream& os) const override;
388
389 /**
390 * @brief Get the serialized size of the packet.
391 * @return size
392 */
393 uint32_t GetSerializedSize() const override;
394
395 /**
396 * @brief Serialize the packet.
397 * @param start Buffer iterator
398 */
399 void Serialize(Buffer::Iterator start) const override;
400
401 /**
402 * @brief Deserialize the packet.
403 * @param start Buffer iterator
404 * @return size of the packet
405 */
406 uint32_t Deserialize(Buffer::Iterator start) override;
407
408 private:
409 /**
410 * @brief Offset of the fragment and More Fragment bit.
411 */
412 uint16_t m_offset;
413
414 /**
415 * @brief Identifier of the packet.
416 */
418};
419
420/**
421 * @ingroup ipv6HeaderExt
422 *
423 * @brief Header of IPv6 Extension Routing
424 */
426{
427 public:
428 /**
429 * @brief Get the type identificator.
430 * @return type identificator
431 */
432 static TypeId GetTypeId();
433
434 /**
435 * @brief Get the instance type ID.
436 * @return instance type ID
437 */
438 TypeId GetInstanceTypeId() const override;
439
440 /**
441 * @brief Constructor.
442 */
444
445 /**
446 * @brief Destructor.
447 */
449
450 /**
451 * @brief Set the "Type of Routing" field.
452 * @param typeRouting the type of routing
453 */
454 void SetTypeRouting(uint8_t typeRouting);
455
456 /**
457 * @brief Get the field "Type of Routing".
458 * @return the type of routing
459 */
460 uint8_t GetTypeRouting() const;
461
462 /**
463 * @brief Set the "Segments left" field.
464 * @param segmentsLeft the number of segments left
465 */
466 void SetSegmentsLeft(uint8_t segmentsLeft);
467
468 /**
469 * @brief Get the field "Segments left".
470 * @return the number of segments left
471 */
472 uint8_t GetSegmentsLeft() const;
473
474 /**
475 * @brief Print some information about the packet.
476 * @param os output stream
477 */
478 void Print(std::ostream& os) const override;
479
480 /**
481 * @brief Get the serialized size of the packet.
482 * @return size
483 */
484 uint32_t GetSerializedSize() const override;
485
486 /**
487 * @brief Serialize the packet.
488 * @param start Buffer iterator
489 */
490 void Serialize(Buffer::Iterator start) const override;
491
492 /**
493 * @brief Deserialize the packet.
494 * @param start Buffer iterator
495 * @return size of the packet
496 */
497 uint32_t Deserialize(Buffer::Iterator start) override;
498
499 private:
500 /**
501 * @brief Type of routing.
502 */
504
505 /**
506 * @brief Number of left segments.
507 */
509};
510
511/**
512 * @ingroup ipv6HeaderExt
513 *
514 * @brief Header of IPv6 Extension Routing : Type 0 (Loose Routing)
515 */
517{
518 public:
519 /**
520 * @brief Get the type identificator.
521 * @return type identificator
522 */
523 static TypeId GetTypeId();
524
525 /**
526 * @brief Get the instance type ID.
527 * @return instance type ID
528 */
529 TypeId GetInstanceTypeId() const override;
530
531 /**
532 * @brief Constructor.
533 */
535
536 /**
537 * @brief Destructor.
538 */
540
541 /**
542 * @brief Set the number of routers' address.
543 * @param n the number of routers' address
544 */
545 void SetNumberAddress(uint8_t n);
546
547 /**
548 * @brief Set the vector of routers' address
549 * @param routersAddress the vector of routers's address
550 */
551 void SetRoutersAddress(std::vector<Ipv6Address> routersAddress);
552
553 /**
554 * @brief Get the vector of routers' address
555 * @return the vector of routers' address
556 */
557 std::vector<Ipv6Address> GetRoutersAddress() const;
558
559 /**
560 * @brief Set a Router IPv6 Address.
561 * @param index the index of the IPv6 Address
562 * @param addr the new IPv6 Address
563 */
564 void SetRouterAddress(uint8_t index, Ipv6Address addr);
565
566 /**
567 * @brief Get a Router IPv6 Address.
568 * @param index the index of the IPv6 Address
569 * @return the router IPv6 Address
570 */
571 Ipv6Address GetRouterAddress(uint8_t index) const;
572
573 /**
574 * @brief Print some information about the packet.
575 * @param os output stream
576 */
577 void Print(std::ostream& os) const override;
578
579 /**
580 * @brief Get the serialized size of the packet.
581 * @return size
582 */
583 uint32_t GetSerializedSize() const override;
584
585 /**
586 * @brief Serialize the packet.
587 * @param start Buffer iterator
588 */
589 void Serialize(Buffer::Iterator start) const override;
590
591 /**
592 * @brief Deserialize the packet.
593 * @param start Buffer iterator
594 * @return size of the packet
595 */
596 uint32_t Deserialize(Buffer::Iterator start) override;
597
598 private:
599 /**
600 * @brief A vector of IPv6 Address.
601 */
602 typedef std::vector<Ipv6Address> VectorIpv6Address_t;
603
604 /**
605 * @brief The vector of Routers' IPv6 Address.
606 */
608};
609
610/**
611 * @ingroup ipv6HeaderExt
612 *
613 * @brief Header of IPv6 Extension ESP
614 */
616{
617 public:
618 /**
619 * @brief Get the type identificator.
620 * @return type identificator
621 */
622 static TypeId GetTypeId();
623
624 /**
625 * @brief Get the instance type ID.
626 * @return instance type ID
627 */
628 TypeId GetInstanceTypeId() const override;
629
630 /**
631 * @brief Constructor.
632 */
634
635 /**
636 * @brief Destructor.
637 */
638 ~Ipv6ExtensionESPHeader() override;
639
640 /**
641 * @brief Print some information about the packet.
642 * @param os output stream
643 */
644 void Print(std::ostream& os) const override;
645
646 /**
647 * @brief Get the serialized size of the packet.
648 * @return size
649 */
650 uint32_t GetSerializedSize() const override;
651
652 /**
653 * @brief Serialize the packet.
654 * @param start Buffer iterator
655 */
656 void Serialize(Buffer::Iterator start) const override;
657
658 /**
659 * @brief Deserialize the packet.
660 * @param start Buffer iterator
661 * @return size of the packet
662 */
663 uint32_t Deserialize(Buffer::Iterator start) override;
664};
665
666/**
667 * @ingroup ipv6HeaderExt
668 *
669 * @brief Header of IPv6 Extension AH
670 */
672{
673 public:
674 /**
675 * @brief Get the type identificator.
676 * @return type identificator
677 */
678 static TypeId GetTypeId();
679
680 /**
681 * @brief Get the instance type ID.
682 * @return instance type ID
683 */
684 TypeId GetInstanceTypeId() const override;
685
686 /**
687 * @brief Constructor.
688 */
690
691 /**
692 * @brief Destructor.
693 */
694 ~Ipv6ExtensionAHHeader() override;
695
696 /**
697 * @brief Print some information about the packet.
698 * @param os output stream
699 */
700 void Print(std::ostream& os) const override;
701
702 /**
703 * @brief Get the serialized size of the packet.
704 * @return size
705 */
706 uint32_t GetSerializedSize() const override;
707
708 /**
709 * @brief Serialize the packet.
710 * @param start Buffer iterator
711 */
712 void Serialize(Buffer::Iterator start) const override;
713
714 /**
715 * @brief Deserialize the packet.
716 * @param start Buffer iterator
717 * @return size of the packet
718 */
719 uint32_t Deserialize(Buffer::Iterator start) override;
720};
721
722} // namespace ns3
723
724#endif /* IPV6_EXTENSION_HEADER_H */
iterator in a Buffer instance
Definition buffer.h:89
automatically resized byte buffer
Definition buffer.h:83
Protocol header serialization and deserialization.
Definition header.h:33
Describes an IPv6 address.
Header of IPv6 Extension AH.
TypeId GetInstanceTypeId() const override
Get the instance type ID.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
~Ipv6ExtensionAHHeader() override
Destructor.
static TypeId GetTypeId()
Get the type identificator.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
void Print(std::ostream &os) const override
Print some information about the packet.
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
Header of IPv6 Extension Destination.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
~Ipv6ExtensionDestinationHeader() override
Destructor.
void Print(std::ostream &os) const override
Print some information about the packet.
static TypeId GetTypeId()
Get the type identificator.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
TypeId GetInstanceTypeId() const override
Get the instance type ID.
Header of IPv6 Extension ESP.
static TypeId GetTypeId()
Get the type identificator.
TypeId GetInstanceTypeId() const override
Get the instance type ID.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
void Print(std::ostream &os) const override
Print some information about the packet.
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
~Ipv6ExtensionESPHeader() override
Destructor.
Header of IPv6 Extension Fragment.
static TypeId GetTypeId()
Get the type identificator.
void SetIdentification(uint32_t identification)
Set the "Identification" field.
void SetOffset(uint16_t offset)
Set the "Offset" field.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
uint32_t m_identification
Identifier of the packet.
TypeId GetInstanceTypeId() const override
Get the instance type ID.
void Print(std::ostream &os) const override
Print some information about the packet.
uint16_t m_offset
Offset of the fragment and More Fragment bit.
uint16_t GetOffset() const
Get the field "Offset".
bool GetMoreFragment() const
Get the status of "More Fragment" bit.
uint32_t GetIdentification() const
Get the field "Identification".
~Ipv6ExtensionFragmentHeader() override
Destructor.
void SetMoreFragment(bool moreFragment)
Set the status of "More Fragment" bit.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
Header for IPv6 Extension.
void Print(std::ostream &os) const override
Print some information about the packet.
uint8_t m_nextHeader
The "next header" field.
uint16_t GetLength() const
Get the length of the extension.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
static TypeId GetTypeId()
Get the type identificator.
void SetLength(uint16_t length)
brief Set the length of the extension.
Buffer m_data
The data of the extension.
TypeId GetInstanceTypeId() const override
Get the instance type ID.
~Ipv6ExtensionHeader() override
Destructor.
void SetNextHeader(uint8_t nextHeader)
Set the "Next header" field.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
uint8_t GetNextHeader() const
Get the next header.
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
uint8_t m_length
The "length" field.
Header of IPv6 Extension "Hop by Hop".
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
static TypeId GetTypeId()
Get the type identificator.
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
TypeId GetInstanceTypeId() const override
Get the instance type ID.
~Ipv6ExtensionHopByHopHeader() override
Destructor.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
void Print(std::ostream &os) const override
Print some information about the packet.
Header of IPv6 Extension Routing : Type 0 (Loose Routing)
void Print(std::ostream &os) const override
Print some information about the packet.
static TypeId GetTypeId()
Get the type identificator.
std::vector< Ipv6Address > GetRoutersAddress() const
Get the vector of routers' address.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
void SetRoutersAddress(std::vector< Ipv6Address > routersAddress)
Set the vector of routers' address.
std::vector< Ipv6Address > VectorIpv6Address_t
A vector of IPv6 Address.
VectorIpv6Address_t m_routersAddress
The vector of Routers' IPv6 Address.
Ipv6Address GetRouterAddress(uint8_t index) const
Get a Router IPv6 Address.
TypeId GetInstanceTypeId() const override
Get the instance type ID.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
void SetRouterAddress(uint8_t index, Ipv6Address addr)
Set a Router IPv6 Address.
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
void SetNumberAddress(uint8_t n)
Set the number of routers' address.
Header of IPv6 Extension Routing.
void SetTypeRouting(uint8_t typeRouting)
Set the "Type of Routing" field.
uint8_t GetTypeRouting() const
Get the field "Type of Routing".
uint8_t GetSegmentsLeft() const
Get the field "Segments left".
static TypeId GetTypeId()
Get the type identificator.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
void SetSegmentsLeft(uint8_t segmentsLeft)
Set the "Segments left" field.
uint8_t m_segmentsLeft
Number of left segments.
void Print(std::ostream &os) const override
Print some information about the packet.
~Ipv6ExtensionRoutingHeader() override
Destructor.
TypeId GetInstanceTypeId() const override
Get the instance type ID.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
Header for IPv6 Option.
Option field for an IPv6ExtensionHeader.
uint32_t GetSerializedSize() const
Get the serialized size of the packet.
uint32_t CalculatePad(Ipv6OptionHeader::Alignment alignment) const
Calculate padding.
void Serialize(Buffer::Iterator start) const
Serialize all added options.
uint32_t GetOptionsOffset() const
Get the offset where the options begin, measured from the start of the extension header.
uint32_t Deserialize(Buffer::Iterator start, uint32_t length)
Deserialize the packet.
Buffer GetOptionBuffer()
Get the buffer.
Buffer m_optionData
Data payload.
OptionField(uint32_t optionsOffset)
Constructor.
uint32_t m_optionsOffset
Offset.
void AddOption(const Ipv6OptionHeader &option)
Serialize the option, prepending pad1 or padn option as necessary.
a unique identifier for an interface.
Definition type-id.h:48
Every class exported by the ns3 library is enclosed in the ns3 namespace.
represents the alignment requirements of an option header