1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 /* 3 * Copyright (c) 2007-2009 Strasbourg 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 * Mehdi Benamor <benamor.mehdi@ensi.rnu.tn> 20 * David Gross <gdavid.devel@gmail.com> 21 */ 22 23 #ifndef ICMPV6_HEADER_H 24 #define ICMPV6_HEADER_H 25 26 #include "ns3/header.h" 27 #include "ns3/ipv6-address.h" 28 #include "ns3/packet.h" 29 30 namespace ns3 31 { 32 33 /** 34 * \ingroup icmpv6 35 * 36 * \brief ICMPv6 header. 37 */ 38 class Icmpv6Header : public Header 39 { 40 public: 41 /** 42 * \brief ICMPv6 type code. 43 */ 44 enum Type_e 45 { 46 ICMPV6_ERROR_DESTINATION_UNREACHABLE = 1, 47 ICMPV6_ERROR_PACKET_TOO_BIG, 48 ICMPV6_ERROR_TIME_EXCEEDED, 49 ICMPV6_ERROR_PARAMETER_ERROR, 50 ICMPV6_ECHO_REQUEST = 128, 51 ICMPV6_ECHO_REPLY, 52 ICMPV6_SUBSCRIBE_REQUEST, 53 ICMPV6_SUBSCRIBE_REPORT, 54 ICMPV6_SUBSCRIVE_END, 55 ICMPV6_ND_ROUTER_SOLICITATION, 56 ICMPV6_ND_ROUTER_ADVERTISEMENT, 57 ICMPV6_ND_NEIGHBOR_SOLICITATION, 58 ICMPV6_ND_NEIGHBOR_ADVERTISEMENT, 59 ICMPV6_ND_REDIRECTION, 60 ICMPV6_ROUTER_RENUMBER, 61 ICMPV6_INFORMATION_REQUEST, 62 ICMPV6_INFORMATION_RESPONSE, 63 ICMPV6_INVERSE_ND_SOLICITATION, 64 ICMPV6_INVERSE_ND_ADVERSTISEMENT, 65 ICMPV6_MLDV2_SUBSCRIBE_REPORT, 66 ICMPV6_MOBILITY_HA_DISCOVER_REQUEST, 67 ICMPV6_MOBILITY_HA_DISCOVER_RESPONSE, 68 ICMPV6_MOBILITY_MOBILE_PREFIX_SOLICITATION, 69 ICMPV6_SECURE_ND_CERTIFICATE_PATH_SOLICITATION, 70 ICMPV6_SECURE_ND_CERTIFICATE_PATH_ADVERTISEMENT, 71 ICMPV6_EXPERIMENTAL_MOBILITY 72 }; 73 74 /** 75 * \brief ICMPv6 Option type code. 76 */ 77 enum OptionType_e 78 { 79 ICMPV6_OPT_LINK_LAYER_SOURCE = 1, 80 ICMPV6_OPT_LINK_LAYER_TARGET, 81 ICMPV6_OPT_PREFIX, 82 ICMPV6_OPT_REDIRECTED, 83 ICMPV6_OPT_MTU 84 }; 85 86 /** 87 * \brief ICMPv6 error code : Destination Unreachable 88 */ 89 enum ErrorDestinationUnreachable_e 90 { 91 ICMPV6_NO_ROUTE = 0, 92 ICMPV6_ADM_PROHIBITED, 93 ICMPV6_NOT_NEIGHBOUR, 94 ICMPV6_ADDR_UNREACHABLE, 95 ICMPV6_PORT_UNREACHABLE 96 }; 97 98 /** 99 * \brief ICMPv6 error code : Time Exceeded 100 */ 101 enum ErrorTimeExceeded_e 102 { 103 ICMPV6_HOPLIMIT = 0, 104 ICMPV6_FRAGTIME 105 }; 106 107 /** 108 * \brief ICMPv6 error code : Parameter Error 109 */ 110 enum ErrorParameterError_e 111 { 112 ICMPV6_MALFORMED_HEADER = 0, 113 ICMPV6_UNKNOWN_NEXT_HEADER, 114 ICMPV6_UNKNOWN_OPTION 115 }; 116 117 /** 118 * \brief Get the UID of this class. 119 * \return UID 120 */ 121 static TypeId GetTypeId (); 122 123 /** 124 * \brief Get the instance type ID. 125 * \return instance type ID 126 */ 127 virtual TypeId GetInstanceTypeId () const; 128 129 /** 130 * \brief Constructor. 131 */ 132 Icmpv6Header (); 133 134 /** 135 * \brief Destructor. 136 */ 137 virtual ~Icmpv6Header (); 138 139 /** 140 * \brief Get the type field. 141 * \return type of ICMPv6 message 142 */ 143 uint8_t GetType () const; 144 145 /** 146 * \brief Set the type. 147 * \param type type to set 148 */ 149 void SetType (uint8_t type); 150 151 /** 152 * \brief Get the code field. 153 * \return code of ICMPv6 message 154 */ 155 uint8_t GetCode () const; 156 157 /** 158 * \brief Set the code field. 159 * \param code code to set 160 */ 161 void SetCode (uint8_t code); 162 163 /** 164 * \brief Get the checksum. 165 * \return checksum 166 */ 167 uint16_t GetChecksum () const; 168 169 /** 170 * \brief Set the checksum. 171 * \param checksum to set 172 */ 173 void SetChecksum (uint16_t checksum); 174 175 /** 176 * \brief Print information. 177 * \param os output stream 178 */ 179 virtual void Print (std::ostream& os) const; 180 181 /** 182 * \brief Get the serialized size. 183 * \return serialized size 184 */ 185 virtual uint32_t GetSerializedSize () const; 186 187 /** 188 * \brief Serialize the packet. 189 * \param start start offset 190 */ 191 virtual void Serialize (Buffer::Iterator start) const; 192 193 /** 194 * \brief Deserialize the packet. 195 * \param start start offset 196 * \return length of packet 197 */ 198 virtual uint32_t Deserialize (Buffer::Iterator start); 199 200 /** 201 * \brief Calculate pseudo header checksum for IPv6. 202 * \param src source address 203 * \param dst destination address 204 * \param length length 205 * \param protocol the protocol number to use in the 206 * underlying IPv6 packet. 207 */ 208 void CalculatePseudoHeaderChecksum (Ipv6Address src, Ipv6Address dst, uint16_t length, uint8_t protocol); 209 210 protected: 211 /** 212 * \brief Checksum enable or not. 213 */ 214 bool m_calcChecksum; 215 216 /** 217 * \brief The checksum. 218 */ 219 uint16_t m_checksum; 220 221 private: 222 /** 223 * \brief The type. 224 */ 225 uint8_t m_type; 226 227 /** 228 * \brief The code. 229 */ 230 uint8_t m_code; 231 }; 232 233 /** 234 * \ingroup icmpv6 235 * 236 * \brief ICMPv6 option header. 237 */ 238 class Icmpv6OptionHeader : public Header 239 { 240 public: 241 /** 242 * \brief Get the UID of this class. 243 * \return UID 244 */ 245 static TypeId GetTypeId (); 246 247 /** 248 * \brief Get the instance type ID. 249 * \return instance type ID 250 */ 251 virtual TypeId GetInstanceTypeId () const; 252 253 /** 254 * \brief Constructor. 255 */ 256 Icmpv6OptionHeader (); 257 258 /** 259 * \brief Destructor. 260 */ 261 virtual ~Icmpv6OptionHeader (); 262 263 /** 264 * \brief Get the type of the option. 265 * \return type 266 */ 267 uint8_t GetType () const; 268 269 /** 270 * \brief Set the type of the option. 271 * \param type the type to set 272 */ 273 void SetType (uint8_t type); 274 275 /** 276 * \brief Get the length of the option in 8 bytes unit. 277 * \return length of the option 278 */ 279 uint8_t GetLength () const; 280 281 /** 282 * \brief Set the length of the option. 283 * \param len length value to set 284 */ 285 void SetLength (uint8_t len); 286 287 /** 288 * \brief Print information. 289 * \param os output stream 290 */ 291 virtual void Print (std::ostream& os) const; 292 293 /** 294 * \brief Get the serialized size. 295 * \return serialized size 296 */ 297 virtual uint32_t GetSerializedSize () const; 298 299 /** 300 * \brief Serialize the packet. 301 * \param start start offset 302 */ 303 virtual void Serialize (Buffer::Iterator start) const; 304 305 /** 306 * \brief Deserialize the packet. 307 * \param start start offset 308 * \return length of packet 309 */ 310 virtual uint32_t Deserialize (Buffer::Iterator start); 311 312 private: 313 /** 314 * \brief The type. 315 */ 316 uint8_t m_type; 317 318 /** 319 * \brief The length. 320 */ 321 uint8_t m_len; 322 }; 323 324 /** 325 * \ingroup icmpv6 326 * 327 * \brief ICMPv6 Neighbor Solicitation header. 328 */ 329 class Icmpv6NS : public Icmpv6Header 330 { 331 public: 332 /** 333 * \brief Constructor. 334 * \param target target IPv6 address 335 */ 336 Icmpv6NS (Ipv6Address target); 337 338 /** 339 * \brief Constructor. 340 */ 341 Icmpv6NS (); 342 343 /** 344 * \brief Destructor. 345 */ 346 virtual ~Icmpv6NS (); 347 348 /** 349 * \brief Get the UID of this class. 350 * \return UID 351 */ 352 static TypeId GetTypeId (); 353 354 /** 355 * \brief Get the instance type ID. 356 * \return instance type ID 357 */ 358 virtual TypeId GetInstanceTypeId () const; 359 360 /** 361 * \brief Get the reserved field. 362 * \return reserved value 363 */ 364 uint32_t GetReserved () const; 365 366 /** 367 * \brief Set the reserved field. 368 * \param reserved the reserved value 369 */ 370 void SetReserved (uint32_t reserved); 371 372 /** 373 * \brief Get the IPv6 target field. 374 * \return IPv6 address 375 */ 376 Ipv6Address GetIpv6Target () const; 377 378 /** 379 * \brief Set the IPv6 target field. 380 * \param target IPv6 address 381 */ 382 void SetIpv6Target (Ipv6Address target); 383 384 /** 385 * \brief Print information. 386 * \param os output stream 387 */ 388 virtual void Print (std::ostream& os) const; 389 390 /** 391 * \brief Get the serialized size. 392 * \return serialized size 393 */ 394 virtual uint32_t GetSerializedSize () const; 395 396 /** 397 * \brief Serialize the packet. 398 * \param start start offset 399 */ 400 virtual void Serialize (Buffer::Iterator start) const; 401 402 /** 403 * \brief Deserialize the packet. 404 * \param start start offset 405 * \return length of packet 406 */ 407 virtual uint32_t Deserialize (Buffer::Iterator start); 408 409 private: 410 411 /** 412 * \brief The reserved value. 413 */ 414 uint32_t m_reserved; 415 416 /** 417 * \brief The IPv6 target address. 418 */ 419 Ipv6Address m_target; 420 }; 421 422 /** 423 * \ingroup icmpv6 424 * 425 * \brief ICMPv6 Neighbor Advertisement header. 426 */ 427 class Icmpv6NA : public Icmpv6Header 428 { 429 public: 430 /** 431 * \brief Constructor. 432 */ 433 Icmpv6NA (); 434 435 /** 436 * \brief Destructor. 437 */ 438 virtual ~Icmpv6NA (); 439 440 /** 441 * \brief Get the UID of this class. 442 * \return UID 443 */ 444 static TypeId GetTypeId (); 445 446 /** 447 * \brief Get the instance type ID. 448 * \return instance type ID 449 */ 450 virtual TypeId GetInstanceTypeId () const; 451 452 /** 453 * \brief Get the reserved field. 454 * \return reserved value 455 */ 456 uint32_t GetReserved () const; 457 458 /** 459 * \brief Set the reserved field. 460 * \param reserved the reserved value 461 */ 462 void SetReserved (uint32_t reserved); 463 464 /** 465 * \brief Get the IPv6 target field. 466 * \return IPv6 address 467 */ 468 Ipv6Address GetIpv6Target () const; 469 470 /** 471 * \brief Set the IPv6 target field. 472 * \param target IPv6 address 473 */ 474 void SetIpv6Target (Ipv6Address target); 475 476 /** 477 * \brief Get the R flag. 478 * \return R flag 479 */ 480 bool GetFlagR () const; 481 482 /** 483 * \brief Set the R flag. 484 * \param r value 485 */ 486 void SetFlagR (bool r); 487 488 /** 489 * \brief Get the S flag. 490 * \return S flag 491 */ 492 bool GetFlagS () const; 493 494 /** 495 * \brief Set the S flag. 496 * \param s value 497 */ 498 void SetFlagS (bool s); 499 500 /** 501 * \brief Get the O flag. 502 * \return O flag 503 */ 504 bool GetFlagO () const; 505 506 /** 507 * \brief Set the O flag. 508 * \param o value 509 */ 510 void SetFlagO (bool o); 511 512 /** 513 * \brief Print information. 514 * \param os output stream 515 */ 516 virtual void Print (std::ostream& os) const; 517 518 /** 519 * \brief Get the serialized size. 520 * \return serialized size 521 */ 522 virtual uint32_t GetSerializedSize () const; 523 524 /** 525 * \brief Serialize the packet. 526 * \param start start offset 527 */ 528 virtual void Serialize (Buffer::Iterator start) const; 529 530 /** 531 * \brief Deserialize the packet. 532 * \param start start offset 533 * \return length of packet 534 */ 535 virtual uint32_t Deserialize (Buffer::Iterator start); 536 537 private: 538 /** 539 * \brief The R flag. 540 */ 541 bool m_flagR; 542 543 /** 544 * \brief The O flag. 545 */ 546 bool m_flagS; 547 548 /** 549 * \brief The M flag. 550 */ 551 bool m_flagO; 552 553 /** 554 * \brief The reserved value. 555 */ 556 uint32_t m_reserved; 557 558 /** 559 * \brief The IPv6 target address. 560 */ 561 Ipv6Address m_target; 562 }; 563 564 /** 565 * \ingroup icmpv6 566 * 567 * \brief ICMPv6 Router Advertisement header. 568 */ 569 class Icmpv6RA : public Icmpv6Header 570 { 571 public: 572 /** 573 * \brief Constructor. 574 */ 575 Icmpv6RA (); 576 577 /** 578 * \brief Destructor. 579 */ 580 virtual ~Icmpv6RA (); 581 582 /** 583 * \brief Get the UID of this class. 584 * \return UID 585 */ 586 static TypeId GetTypeId (); 587 588 /** 589 * \brief Get the instance type ID. 590 * \return instance type ID 591 */ 592 virtual TypeId GetInstanceTypeId () const; 593 594 /** 595 * \brief Set the IPv6 maximum number of jumps. 596 * \param m maximum jumps 597 */ 598 void SetCurHopLimit (uint8_t m); 599 600 /** 601 * \brief Get the IPv6 maximum number of jumps. 602 * \return maximum jumps 603 */ 604 uint8_t GetCurHopLimit () const; 605 606 /** 607 * \brief Set the node Life time (Neighbor Discovery). 608 * \param l life time 609 */ 610 void SetLifeTime (uint16_t l); 611 612 /** 613 * \brief Get the node Life time (Neighbor Discovery). 614 * \return life time 615 */ 616 uint16_t GetLifeTime () const; 617 618 /** 619 * \brief Set the node Reachable time (Neighbor Discovery). 620 * \param r Reachable time 621 */ 622 void SetReachableTime (uint32_t r); 623 624 /** 625 * \brief Get the node Reachable time (Neighbor Discovery). 626 * \return reachable time 627 */ 628 uint32_t GetReachableTime () const; 629 630 /** 631 * \brief Set the node Retransmission time (Neighbor Discovery). 632 * \param r Retransmission time 633 */ 634 void SetRetransmissionTime (uint32_t r); 635 636 /** 637 * \brief Get the node Retransmission time (Neighbor Discovery). 638 * \return retransmission time 639 */ 640 uint32_t GetRetransmissionTime () const; 641 642 /** 643 * \brief Get the M flag. 644 * \return M flag 645 */ 646 bool GetFlagM () const; 647 648 /** 649 * \brief Set the M flag. 650 * \param m value 651 */ 652 void SetFlagM (bool m); 653 654 /** 655 * \brief Get the O flag. 656 * \return O flag 657 */ 658 bool GetFlagO () const; 659 660 /** 661 * \brief Set the O flag. 662 * \param o value 663 */ 664 void SetFlagO (bool o); 665 666 /** 667 * \brief Get the H flag. 668 * \return H flag 669 */ 670 bool GetFlagH () const; 671 672 /** 673 * \brief Set the H flag. 674 * \param h value 675 */ 676 void SetFlagH (bool h); 677 678 /** 679 * \brief Print information. 680 * \param os output stream 681 */ 682 virtual void Print (std::ostream& os) const; 683 684 /** 685 * \brief Getflags. 686 * \return the flags value 687 */ 688 NS_DEPRECATED_3_34 689 uint8_t GetFlags () const; 690 691 /** 692 * \brief Setflags. 693 * \param f the flags value 694 */ 695 NS_DEPRECATED_3_34 696 void SetFlags (uint8_t f); 697 698 /** 699 * \brief Get the serialized size. 700 * \return serialized size 701 */ 702 virtual uint32_t GetSerializedSize () const; 703 704 /** 705 * \brief Serialize the packet. 706 * \param start start offset 707 */ 708 virtual void Serialize (Buffer::Iterator start) const; 709 710 /** 711 * \brief Deserialize the packet. 712 * \param start start offset 713 * \return length of packet 714 */ 715 virtual uint32_t Deserialize (Buffer::Iterator start); 716 717 private: 718 /** 719 * \brief The M flag. 720 */ 721 bool m_flagM; 722 723 /** 724 * \brief The O flag. 725 */ 726 bool m_flagO; 727 728 /** 729 * \brief The H flag. 730 */ 731 bool m_flagH; 732 733 /** 734 * \brief The lifetime value. 735 */ 736 uint16_t m_LifeTime; 737 738 /** 739 * \brief The reachable time value. 740 */ 741 uint32_t m_ReachableTime; 742 743 /** 744 * \brief The retransmission timer. 745 */ 746 uint32_t m_RetransmissionTimer; 747 748 /** 749 * \brief The max jumps. 750 */ 751 uint8_t m_curHopLimit; 752 }; 753 754 /** 755 * \ingroup icmpv6 756 * 757 * \brief ICMPv6 Router Solicitation header. 758 */ 759 class Icmpv6RS : public Icmpv6Header 760 { 761 public: 762 /** 763 * \brief Constructor. 764 */ 765 Icmpv6RS (); 766 767 /** 768 * \brief Destructor. 769 */ 770 virtual ~Icmpv6RS (); 771 772 /** 773 * \brief Get the UID of this class. 774 * \return UID 775 */ 776 static TypeId GetTypeId (); 777 778 /** 779 * \brief Get the instance type ID. 780 * \return instance type ID 781 */ 782 virtual TypeId GetInstanceTypeId () const; 783 784 /** 785 * \brief Get the reserved field. 786 * \return reserved value 787 */ 788 uint32_t GetReserved () const; 789 790 /** 791 * \brief Set the reserved field. 792 * \param reserved the reserved value 793 */ 794 void SetReserved (uint32_t reserved); 795 796 /** 797 * \brief Print information. 798 * \param os output stream 799 */ 800 virtual void Print (std::ostream& os) const; 801 802 /** 803 * \brief Get the serialized size. 804 * \return serialized size 805 */ 806 virtual uint32_t GetSerializedSize () const; 807 808 /** 809 * \brief Serialize the packet. 810 * \param start start offset 811 */ 812 virtual void Serialize (Buffer::Iterator start) const; 813 814 /** 815 * \brief Deserialize the packet. 816 * \param start start offset 817 * \return length of packet 818 */ 819 virtual uint32_t Deserialize (Buffer::Iterator start); 820 821 private: 822 /** 823 * \brief The reserved value. 824 */ 825 uint32_t m_reserved; 826 }; 827 828 /** 829 * \ingroup icmpv6 830 * 831 * \brief ICMPv6 Redirection header. 832 */ 833 class Icmpv6Redirection : public Icmpv6Header 834 { 835 public: 836 /** 837 * \brief Constructor. 838 */ 839 Icmpv6Redirection (); 840 841 /** 842 * \brief Destructor. 843 */ 844 virtual ~Icmpv6Redirection (); 845 846 /** 847 * \brief Get the UID of this class. 848 * \return UID 849 */ 850 static TypeId GetTypeId (); 851 852 /** 853 * \brief Get the instance type ID. 854 * \return instance type ID 855 */ 856 virtual TypeId GetInstanceTypeId () const; 857 858 /** 859 * \brief Get the IPv6 target address. 860 * \return the IPv6 target address 861 */ 862 Ipv6Address GetTarget () const; 863 864 /** 865 * \brief Set the IPv6 target address. 866 * \param target IPv6 target address 867 */ 868 void SetTarget (Ipv6Address target); 869 870 /** 871 * \brief Get the IPv6 destination address. 872 * \return the IPv6 destination address 873 */ 874 Ipv6Address GetDestination () const; 875 876 /** 877 * \brief Set the IPv6 destination address. 878 * \param destination IPv6 destination address 879 */ 880 void SetDestination (Ipv6Address destination); 881 882 /** 883 * \brief Print information. 884 * \param os output stream 885 */ 886 virtual void Print (std::ostream& os) const; 887 888 /** 889 * \brief Get the serialized size. 890 * \return serialized size 891 */ 892 virtual uint32_t GetSerializedSize () const; 893 894 /** 895 * \brief Serialize the packet. 896 * \param start start offset 897 */ 898 virtual void Serialize (Buffer::Iterator start) const; 899 900 /** 901 * \brief Deserialize the packet. 902 * \param start start offset 903 * \return length of packet 904 */ 905 virtual uint32_t Deserialize (Buffer::Iterator start); 906 907 /** 908 * \brief Get the reserved field. 909 * \return reserved value 910 */ 911 uint32_t GetReserved () const; 912 913 /** 914 * \brief Set the reserved field. 915 * \param reserved the reserved value 916 */ 917 void SetReserved (uint32_t reserved); 918 919 private: 920 /** 921 * \brief IPv6 target address. 922 */ 923 Ipv6Address m_target; 924 925 /** 926 * \brief IPv6 destination address. 927 */ 928 Ipv6Address m_destination; 929 930 /** 931 * \brief Reserved value. 932 */ 933 uint32_t m_reserved; 934 }; 935 936 /** 937 * \ingroup icmpv6 938 * 939 * \brief ICMPv6 Echo message. 940 */ 941 class Icmpv6Echo : public Icmpv6Header 942 { 943 public: 944 /** 945 * \brief Get the UID of this class. 946 * \return UID 947 */ 948 static TypeId GetTypeId (); 949 950 /** 951 * \brief Get the instance type ID. 952 * \return instance type ID 953 */ 954 virtual TypeId GetInstanceTypeId () const; 955 956 /** 957 * \brief Default constructor. 958 */ 959 Icmpv6Echo (); 960 961 /** 962 * \brief Constructor. 963 * \param request request or reply message 964 */ 965 Icmpv6Echo (bool request); 966 967 /** 968 * \brief Destructor. 969 */ 970 virtual ~Icmpv6Echo (); 971 972 /** 973 * \brief Get the ID of the packet. 974 * \return id 975 */ 976 uint16_t GetId () const; 977 978 /** 979 * \brief Set the ID of the packet. 980 * \param id id to set 981 */ 982 void SetId (uint16_t id); 983 984 /** 985 * \brief Get the sequence number. 986 * \return sequence number 987 */ 988 uint16_t GetSeq () const; 989 990 /** 991 * \brief Set the sequence number. 992 * \param seq sequence to set 993 */ 994 void SetSeq (uint16_t seq); 995 996 /** 997 * \brief Print information. 998 * \param os output stream 999 */ 1000 virtual void Print (std::ostream& os) const; 1001 1002 /** 1003 * \brief Get the serialized size. 1004 * \return serialized size 1005 */ 1006 virtual uint32_t GetSerializedSize () const; 1007 1008 /** 1009 * \brief Serialize the packet. 1010 * \param start start offset 1011 */ 1012 virtual void Serialize (Buffer::Iterator start) const; 1013 1014 /** 1015 * \brief Deserialize the packet. 1016 * \param start start offset 1017 * \return length of packet 1018 */ 1019 virtual uint32_t Deserialize (Buffer::Iterator start); 1020 1021 private: 1022 /** 1023 * \brief ID of the packet (to distinguish response between many ping program). 1024 */ 1025 uint16_t m_id; 1026 1027 /** 1028 * \brief Sequence number (to distinguish response). 1029 */ 1030 uint16_t m_seq; 1031 }; 1032 1033 /** 1034 * \ingroup icmpv6 1035 * 1036 * \brief ICMPv6 Error Destination Unreachable header. 1037 */ 1038 class Icmpv6DestinationUnreachable : public Icmpv6Header 1039 { 1040 public: 1041 /** 1042 * \brief Constructor. 1043 */ 1044 Icmpv6DestinationUnreachable (); 1045 1046 /** 1047 * \brief Destructor. 1048 */ 1049 virtual ~Icmpv6DestinationUnreachable (); 1050 1051 /** 1052 * \brief Get the UID of this class. 1053 * \return UID 1054 */ 1055 static TypeId GetTypeId (); 1056 1057 /** 1058 * \brief Get the instance type ID. 1059 * \return instance type ID 1060 */ 1061 virtual TypeId GetInstanceTypeId () const; 1062 1063 /** 1064 * \brief Get the incorrect packet. 1065 * \return the incorrect packet 1066 */ 1067 Ptr<Packet> GetPacket () const; 1068 1069 /** 1070 * \brief Set the incorrect packet. 1071 * \param p the incorrect packet 1072 */ 1073 void SetPacket (Ptr<Packet> p); 1074 1075 /** 1076 * \brief Print information. 1077 * \param os output stream 1078 */ 1079 virtual void Print (std::ostream& os) const; 1080 1081 /** 1082 * \brief Get the serialized size. 1083 * \return serialized size 1084 */ 1085 virtual uint32_t GetSerializedSize () const; 1086 1087 /** 1088 * \brief Serialize the packet. 1089 * \param start start offset 1090 */ 1091 virtual void Serialize (Buffer::Iterator start) const; 1092 1093 /** 1094 * \brief Deserialize the packet. 1095 * \param start start offset 1096 * \return length of packet 1097 */ 1098 virtual uint32_t Deserialize (Buffer::Iterator start); 1099 1100 private: 1101 /** 1102 * \brief The incorrect Packet. 1103 */ 1104 Ptr<Packet> m_packet; 1105 }; 1106 1107 /** 1108 * \ingroup icmpv6 1109 * 1110 * \brief ICMPv6 Error Too Big header. 1111 */ 1112 class Icmpv6TooBig : public Icmpv6Header 1113 { 1114 public: 1115 /** 1116 * \brief Constructor. 1117 */ 1118 Icmpv6TooBig (); 1119 1120 /** 1121 * \brief Destructor. 1122 */ 1123 virtual ~Icmpv6TooBig (); 1124 1125 /** 1126 * \brief Get the UID of this class. 1127 * \return UID 1128 */ 1129 static TypeId GetTypeId (); 1130 1131 /** 1132 * \brief Get the instance type ID. 1133 * \return instance type ID 1134 */ 1135 virtual TypeId GetInstanceTypeId () const; 1136 1137 /** 1138 * \brief Get the incorrect packet. 1139 * \return the incorrect packet 1140 */ 1141 Ptr<Packet> GetPacket () const; 1142 1143 /** 1144 * \brief Set the incorrect packet. 1145 * \param p the incorrect packet 1146 */ 1147 void SetPacket (Ptr<Packet> p); 1148 1149 /** 1150 * \brief Get the MTU field. 1151 * \return MTU value 1152 */ 1153 uint32_t GetMtu () const; 1154 1155 /** 1156 * \brief Set the MTU. 1157 * \param mtu the MTU 1158 */ 1159 void SetMtu (uint32_t mtu); 1160 1161 /** 1162 * \brief Print information. 1163 * \param os output stream 1164 */ 1165 virtual void Print (std::ostream& os) const; 1166 1167 /** 1168 * \brief Get the serialized size. 1169 * \return serialized size 1170 */ 1171 virtual uint32_t GetSerializedSize () const; 1172 1173 /** 1174 * \brief Serialize the packet. 1175 * \param start start offset 1176 */ 1177 virtual void Serialize (Buffer::Iterator start) const; 1178 1179 /** 1180 * \brief Deserialize the packet. 1181 * \param start start offset 1182 * \return length of packet 1183 */ 1184 virtual uint32_t Deserialize (Buffer::Iterator start); 1185 1186 private: 1187 1188 /** 1189 * \brief the incorrect packet. 1190 */ 1191 Ptr<Packet> m_packet; 1192 1193 /** 1194 * \brief The MTU value. 1195 */ 1196 uint32_t m_mtu; 1197 }; 1198 1199 /** 1200 * \ingroup icmpv6 1201 * 1202 * \brief ICMPv6 Error Time Exceeded header. 1203 */ 1204 class Icmpv6TimeExceeded : public Icmpv6Header 1205 { 1206 public: 1207 /** 1208 * \brief Constructor. 1209 */ 1210 Icmpv6TimeExceeded (); 1211 1212 /** 1213 * \brief Destructor. 1214 */ 1215 virtual ~Icmpv6TimeExceeded (); 1216 1217 /** 1218 * \brief Get the UID of this class. 1219 * \return UID 1220 */ 1221 static TypeId GetTypeId (); 1222 1223 /** 1224 * \brief Get the instance type ID. 1225 * \return instance type ID 1226 */ 1227 virtual TypeId GetInstanceTypeId () const; 1228 1229 /** 1230 * \brief Get the incorrect packet. 1231 * \return the incorrect packet 1232 */ 1233 Ptr<Packet> GetPacket () const; 1234 1235 /** 1236 * \brief Set the incorrect packet. 1237 * \param p the incorrect packet 1238 */ 1239 void SetPacket (Ptr<Packet> p); 1240 1241 /** 1242 * \brief Print information. 1243 * \param os output stream 1244 */ 1245 virtual void Print (std::ostream& os) const; 1246 1247 /** 1248 * \brief Get the serialized size. 1249 * \return serialized size 1250 */ 1251 virtual uint32_t GetSerializedSize () const; 1252 1253 /** 1254 * \brief Serialize the packet. 1255 * \param start start offset 1256 */ 1257 virtual void Serialize (Buffer::Iterator start) const; 1258 1259 /** 1260 * \brief Deserialize the packet. 1261 * \param start start offset 1262 * \return length of packet 1263 */ 1264 virtual uint32_t Deserialize (Buffer::Iterator start); 1265 1266 private: 1267 1268 /** 1269 * \brief The incorrect packet. 1270 */ 1271 Ptr<Packet> m_packet; 1272 }; 1273 1274 /** 1275 * \ingroup icmpv6 1276 * 1277 * \brief ICMPv6 Error Parameter Error header. 1278 */ 1279 class Icmpv6ParameterError : public Icmpv6Header 1280 { 1281 public: 1282 /** 1283 * \brief Constructor. 1284 */ 1285 Icmpv6ParameterError (); 1286 1287 /** 1288 * \brief Destructor. 1289 */ 1290 virtual ~Icmpv6ParameterError (); 1291 1292 /** 1293 * \brief Get the UID of this class. 1294 * \return UID 1295 */ 1296 static TypeId GetTypeId (); 1297 1298 /** 1299 * \brief Get the instance type ID. 1300 * \return instance type ID 1301 */ 1302 virtual TypeId GetInstanceTypeId () const; 1303 1304 /** 1305 * \brief Get the incorrect packet. 1306 * \return the incorrect packet 1307 */ 1308 Ptr<Packet> GetPacket () const; 1309 1310 /** 1311 * \brief Set the incorrect packet. 1312 * \param p the incorrect packet 1313 */ 1314 void SetPacket (Ptr<Packet> p); 1315 1316 /** 1317 * \brief Get the pointer field. 1318 * \return pointer value 1319 */ 1320 uint32_t GetPtr () const; 1321 1322 /** 1323 * \brief Set the pointer field. 1324 * \param ptr byte where the error is located in the incorrect packet 1325 */ 1326 void SetPtr (uint32_t ptr); 1327 1328 /** 1329 * \brief Print information. 1330 * \param os output stream 1331 */ 1332 virtual void Print (std::ostream& os) const; 1333 1334 /** 1335 * \brief Get the serialized size. 1336 * \return serialized size 1337 */ 1338 virtual uint32_t GetSerializedSize () const; 1339 1340 /** 1341 * \brief Serialize the packet. 1342 * \param start start offset 1343 */ 1344 virtual void Serialize (Buffer::Iterator start) const; 1345 1346 /** 1347 * \brief Deserialize the packet. 1348 * \param start start offset 1349 * \return length of packet 1350 */ 1351 virtual uint32_t Deserialize (Buffer::Iterator start); 1352 1353 private: 1354 1355 /** 1356 * \brief The incorrect packet. 1357 */ 1358 Ptr<Packet> m_packet; 1359 1360 /** 1361 * \brief The pointer field. 1362 */ 1363 uint32_t m_ptr; 1364 }; 1365 1366 /** 1367 * \ingroup icmpv6 1368 * 1369 * \brief ICMPv6 MTU option. 1370 */ 1371 class Icmpv6OptionMtu : public Icmpv6OptionHeader 1372 { 1373 public: 1374 /** 1375 * \brief Constructor. 1376 */ 1377 Icmpv6OptionMtu (); 1378 1379 /** 1380 * \brief Constructor. 1381 * \param mtu MTU used. 1382 */ 1383 Icmpv6OptionMtu (uint32_t mtu); 1384 1385 /** 1386 * \brief Destructor. 1387 */ 1388 virtual ~Icmpv6OptionMtu (); 1389 1390 /** 1391 * \brief Get the UID of this class. 1392 * \return UID 1393 */ 1394 static TypeId GetTypeId (); 1395 1396 /** 1397 * \brief Get the instance type ID. 1398 * \return instance type ID 1399 */ 1400 virtual TypeId GetInstanceTypeId () const; 1401 1402 /** 1403 * \brief Get the reserved field. 1404 * \return the reserved value 1405 */ 1406 uint16_t GetReserved () const; 1407 1408 /** 1409 * \brief Set the reserved field. 1410 * \param reserved the reserved value 1411 */ 1412 void SetReserved (uint16_t reserved); 1413 1414 /** 1415 * \brief Get the MTU. 1416 * \return the MTU value 1417 */ 1418 uint32_t GetMtu () const; 1419 1420 /** 1421 * \brief Set the MTU. 1422 * \param mtu the MTU to set 1423 */ 1424 void SetMtu (uint32_t mtu); 1425 1426 /** 1427 * \brief Print information. 1428 * \param os output stream 1429 */ 1430 virtual void Print (std::ostream& os) const; 1431 1432 /** 1433 * \brief Get the serialized size. 1434 * \return serialized size 1435 */ 1436 virtual uint32_t GetSerializedSize () const; 1437 1438 /** 1439 * \brief Serialize the packet. 1440 * \param start start offset 1441 */ 1442 virtual void Serialize (Buffer::Iterator start) const; 1443 1444 /** 1445 * \brief Deserialize the packet. 1446 * \param start start offset 1447 * \return length of packet 1448 */ 1449 virtual uint32_t Deserialize (Buffer::Iterator start); 1450 1451 private: 1452 /** 1453 * \brief The reserved value 1454 */ 1455 uint16_t m_reserved; 1456 1457 /** 1458 * \brief The MTU value. 1459 */ 1460 uint32_t m_mtu; 1461 }; 1462 1463 /** 1464 * \ingroup icmpv6 1465 * 1466 * \brief ICMPv6 Option Prefix Information. 1467 */ 1468 class Icmpv6OptionPrefixInformation : public Icmpv6OptionHeader 1469 { 1470 public: 1471 /** 1472 * \brief Constructor. 1473 */ 1474 Icmpv6OptionPrefixInformation (); 1475 1476 /** 1477 * \brief Constructor. 1478 * \param network prefix 1479 * \param prefixlen prefix length 1480 */ 1481 Icmpv6OptionPrefixInformation (Ipv6Address network, uint8_t prefixlen); 1482 1483 /** 1484 * \brief Destructor. 1485 */ 1486 virtual ~Icmpv6OptionPrefixInformation (); 1487 1488 /** 1489 * \brief Get the UID of this class. 1490 * \return UID 1491 */ 1492 static TypeId GetTypeId (); 1493 1494 /** 1495 * \brief Get the instance type ID. 1496 * \return instance type ID 1497 */ 1498 virtual TypeId GetInstanceTypeId () const; 1499 1500 /** 1501 * \brief Icmpv6 Option Prefix Information flag field values 1502 */ 1503 typedef enum 1504 { 1505 NONE = 0, //!< No flags 1506 ROUTERADDR = 32, //!< Router Address 1507 AUTADDRCONF = 64, //!< Autonomous Address Configuration 1508 ONLINK = 128 //!< On-link 1509 } Flags_t; 1510 1511 /** 1512 * \brief Get the prefix length. 1513 * \return prefix length 1514 */ 1515 uint8_t GetPrefixLength () const; 1516 1517 /** 1518 * \brief Set the prefix length. 1519 * \param prefixLength the prefix length 1520 */ 1521 void SetPrefixLength (uint8_t prefixLength); 1522 1523 /** 1524 * \brief Get the flags. 1525 * \return the flags. 1526 */ 1527 uint8_t GetFlags () const; 1528 1529 /** 1530 * \brief Set the flags. 1531 * \param flags the flags to set 1532 */ 1533 void SetFlags (uint8_t flags); 1534 1535 /** 1536 * \brief Get the valid time of the information. 1537 * \return valid time 1538 */ 1539 uint32_t GetValidTime () const; 1540 1541 /** 1542 * \brief Set the valid time of the information. 1543 * \param validTime valid time 1544 */ 1545 void SetValidTime (uint32_t validTime); 1546 1547 /** 1548 * \brief Get the preferred time of the information. 1549 * \return preferred time 1550 */ 1551 uint32_t GetPreferredTime () const; 1552 1553 /** 1554 * \brief Set the preferred time of the information. 1555 * \param preferredTime preferred time 1556 */ 1557 void SetPreferredTime (uint32_t preferredTime); 1558 1559 /** 1560 * \brief Get the reserved field. 1561 * \return the reserved field (should be 0x00000000) 1562 */ 1563 uint32_t GetReserved () const; 1564 1565 /** 1566 * \brief Set the reserved field (normally it will be 0x00000000). 1567 * \param reserved reserved value 1568 */ 1569 void SetReserved (uint32_t reserved); 1570 1571 /** 1572 * \brief Get the IPv6 prefix. 1573 * \return IPv6 prefix 1574 */ 1575 Ipv6Address GetPrefix () const; 1576 1577 /** 1578 * \brief Set the IPv6 prefix. 1579 * \param prefix the IPv6 prefix 1580 */ 1581 void SetPrefix (Ipv6Address prefix); 1582 1583 /** 1584 * \brief Print information. 1585 * \param os output stream 1586 */ 1587 virtual void Print (std::ostream& os) const; 1588 1589 /** 1590 * \brief Get the serialized size. 1591 * \return serialized size 1592 */ 1593 virtual uint32_t GetSerializedSize () const; 1594 1595 /** 1596 * \brief Serialize the packet. 1597 * \param start start offset 1598 */ 1599 virtual void Serialize (Buffer::Iterator start) const; 1600 1601 /** 1602 * \brief Deserialize the packet. 1603 * \param start start offset 1604 * \return length of packet 1605 */ 1606 virtual uint32_t Deserialize (Buffer::Iterator start); 1607 1608 private: 1609 /** 1610 * \brief The prefix value. 1611 */ 1612 Ipv6Address m_prefix; 1613 1614 /** 1615 * \brief The length of the prefix. 1616 */ 1617 uint8_t m_prefixLength; 1618 1619 /** 1620 * \brief The flags. 1621 */ 1622 uint8_t m_flags; 1623 1624 /** 1625 * \brief The valid time. 1626 */ 1627 uint32_t m_validTime; 1628 1629 /** 1630 * \brief The preferred time. 1631 */ 1632 uint32_t m_preferredTime; 1633 1634 /** 1635 * \brief The reserved field. 1636 */ 1637 uint32_t m_reserved; 1638 }; 1639 1640 /** 1641 * \ingroup icmpv6 1642 * 1643 * \brief ICMPv6 link-layer address option. 1644 */ 1645 class Icmpv6OptionLinkLayerAddress : public Icmpv6OptionHeader 1646 { 1647 public: 1648 /** 1649 * \brief Constructor. 1650 * \param source source hardware address or target hardware address for the option 1651 */ 1652 Icmpv6OptionLinkLayerAddress (bool source); 1653 1654 /** 1655 * \brief Get the UID of this class. 1656 * \return UID 1657 */ 1658 static TypeId GetTypeId (); 1659 1660 /** 1661 * \brief Get the instance type ID. 1662 * \return instance type ID 1663 */ 1664 virtual TypeId GetInstanceTypeId (void) const; 1665 1666 /** 1667 * \brief Constructor. 1668 * \param source source hardware address or target hardware address for the option 1669 * \param addr hardware address 1670 */ 1671 Icmpv6OptionLinkLayerAddress (bool source, Address addr); 1672 1673 /** 1674 * \brief Constructor. 1675 */ 1676 Icmpv6OptionLinkLayerAddress (); 1677 1678 /** 1679 * \brief Destructor. 1680 */ 1681 virtual ~Icmpv6OptionLinkLayerAddress (); 1682 1683 /** 1684 * \brief Get the hardware address. 1685 * \return the hardware address 1686 */ 1687 Address GetAddress () const; 1688 1689 /** 1690 * \brief Set the hardware address. 1691 * \param addr the address to set 1692 */ 1693 void SetAddress (Address addr); 1694 1695 /** 1696 * \brief Print information. 1697 * \param os output stream 1698 */ 1699 virtual void Print (std::ostream& os) const; 1700 1701 /** 1702 * \brief Get the serialized size. 1703 * \return serialized size 1704 */ 1705 virtual uint32_t GetSerializedSize () const; 1706 1707 /** 1708 * \brief Serialize the packet. 1709 * \param start start offset 1710 */ 1711 virtual void Serialize (Buffer::Iterator start) const; 1712 1713 /** 1714 * \brief Deserialize the packet. 1715 * \param start start offset 1716 * \return length of packet 1717 */ 1718 virtual uint32_t Deserialize (Buffer::Iterator start); 1719 1720 private: 1721 /** 1722 * \brief The hardware address. 1723 */ 1724 Address m_addr; 1725 }; 1726 1727 /** 1728 * \ingroup icmpv6 1729 * 1730 * \brief ICMPv6 redirected option. 1731 */ 1732 class Icmpv6OptionRedirected : public Icmpv6OptionHeader 1733 { 1734 public: 1735 /** 1736 * \brief Get the UID of this class. 1737 * \return UID 1738 */ 1739 static TypeId GetTypeId (); 1740 1741 /** 1742 * \brief Get the instance type ID. 1743 * \return instance type ID 1744 */ 1745 virtual TypeId GetInstanceTypeId () const; 1746 1747 /** 1748 * \brief Constructor. 1749 */ 1750 Icmpv6OptionRedirected (); 1751 1752 /** 1753 * \brief Destructor. 1754 */ 1755 virtual ~Icmpv6OptionRedirected (); 1756 1757 /** 1758 * \brief Get the redirected packet. 1759 * \return the redirected packet 1760 */ 1761 Ptr<Packet> GetPacket () const; 1762 1763 /** 1764 * \brief Set the redirected packet. 1765 * \param packet the redirected packet 1766 */ 1767 void SetPacket (Ptr<Packet> packet); 1768 1769 /** 1770 * \brief Print information. 1771 * \param os output stream 1772 */ 1773 virtual void Print (std::ostream& os) const; 1774 1775 /** 1776 * \brief Get the serialized size. 1777 * \return serialized size 1778 */ 1779 virtual uint32_t GetSerializedSize () const; 1780 1781 /** 1782 * \brief Serialize the packet. 1783 * \param start start offset 1784 */ 1785 virtual void Serialize (Buffer::Iterator start) const; 1786 1787 /** 1788 * \brief Deserialize the packet. 1789 * \param start start offset 1790 * \return length of packet 1791 */ 1792 virtual uint32_t Deserialize (Buffer::Iterator start); 1793 1794 private: 1795 /** 1796 * \brief The redirected packet. 1797 */ 1798 Ptr<Packet> m_packet; 1799 }; 1800 1801 } /* namespace ns3 */ 1802 1803 #endif /* ICMPV6_HEADER_H */ 1804 1805