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