src/node/ipv6-header.h
author vincent@clarinet.u-strasbg.fr
Fri Nov 07 11:36:15 2008 -0800 (2008-11-07)
changeset 3852 9cf7ad0cac85
child 3857 6ed8e59690b2
permissions -rw-r--r--
Initial IPv6 capability
     1 /* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
     2 /*
     3  * Copyright (c) 2007-2008 Louis Pasteur University
     4  *
     5  * This program is free software; you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License version 2 as
     7  * published by the Free Software Foundation;
     8  *
     9  * This program is distributed in the hope that it will be useful,
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  * GNU General Public License for more details.
    13  *
    14  * You should have received a copy of the GNU General Public License
    15  * along with this program; if not, write to the Free Software
    16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    17  *
    18  * Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
    19  */
    20 
    21 #ifndef IPV6_HEADER_H
    22 #define IPV6_HEADER_H
    23 
    24 #include "ns3/header.h"
    25 #include "ns3/ipv6-address.h"
    26 
    27 namespace ns3 {
    28 
    29 /**
    30  * \class Ipv6Header
    31  * \brief Packet header for IPv6
    32  */
    33 class Ipv6Header : public Header
    34 {
    35   public:
    36     /**
    37      * \enum NextHeader_e
    38      * \brief IPv6 next-header value
    39      */
    40     enum NextHeader_e
    41     {
    42       IPV6_EXT_HOP_BY_HOP=0,
    43       IPV6_IPV4=4,
    44       IPV6_TCP=6,
    45       IPV6_UDP=17,
    46       IPV6_IPV6=41,
    47       IPV6_EXT_ROUTING=43,
    48       IPV6_EXT_FRAGMENTATION=44,
    49       IPV6_EXT_CONFIDENTIALITY=50,
    50       IPV6_EXT_AUTHENTIFICATION,
    51       IPV6_ICMPV6=58,
    52       IPV6_EXT_END,
    53       IPV6_EXT_DESTINATION,
    54       IPV6_SCTP=135,
    55       IPV6_EXT_MOBILITY=135,
    56       IPV6_UDP_LITE,
    57     };
    58 
    59     /**
    60      * \brief Get the type identifier.
    61      * \return type identifier
    62      */
    63     static TypeId GetTypeId (void);
    64 
    65     /**
    66      * \brief Return the instance type identifier.
    67      * \return instance type ID
    68      */
    69     virtual TypeId GetInstanceTypeId (void) const;
    70 
    71     /**
    72      * \brief Constructor.
    73      */
    74     Ipv6Header (void);
    75 
    76     /**
    77      * \brief Set the "Traffic class" field.
    78      * \param traffic the 8-bit value
    79      */
    80     void SetTrafficClass (uint8_t traffic);
    81 
    82     /**
    83      * \brief Get the "Traffic class" field.
    84      * \return the traffic value
    85      */
    86     uint8_t GetTrafficClass (void) const;
    87 
    88     /**
    89      * \brief Set the "Flow label" field.
    90      * \param flow the 20-bit value
    91      */
    92     void SetFlowLabel (uint32_t flow);
    93 
    94     /**
    95      * \brief Get the "Flow label" field.
    96      * \return the flow label value
    97      */
    98     uint32_t GetFlowLabel (void) const;
    99 
   100     /**
   101      * \brief Set the "Payload length" field.
   102      * \param len the length of the payload in bytes
   103      */
   104     void SetPayloadLength (uint16_t len);
   105 
   106     /**
   107      * \brief Get the "Payload length" field.
   108      * \return the payload length
   109      */
   110     uint16_t GetPayloadLength (void) const;
   111 
   112     /**
   113      * \brief Set the "Next header" field.
   114      * \param next the next header number
   115      */
   116     void SetNextHeader (uint8_t next);
   117 
   118     /**
   119      * \brief Get the next header.
   120      * \return the next header number
   121      */
   122     uint8_t GetNextHeader (void) const;
   123 
   124     /**
   125      * \brief Set the "Hop limit" field (TTL).
   126      * \param limit the 8-bit value
   127      */
   128     void SetHopLimit (uint8_t limit);
   129 
   130     /**
   131      * \brief Get the "Hop limit" field (TTL).
   132      * \return the hop limit value
   133      */
   134     uint8_t GetHopLimit (void) const;
   135 
   136     /**
   137      * \brief Set the "Source address" field.
   138      * \param src the source address
   139      */
   140     void SetSourceAddress (Ipv6Address src);
   141 
   142     /**
   143      * \brief Get the "Source address" field.
   144      * \return the source address
   145      */
   146     Ipv6Address GetSourceAddress (void) const;
   147 
   148     /**
   149      * \brief Set the "Destination address" field.
   150      * \param dst the destination address
   151      */
   152     void SetDestinationAddress (Ipv6Address dst);
   153 
   154     /**
   155      * \brief Get the "Destination address" field.
   156      * \return the destination address
   157      */
   158     Ipv6Address GetDestinationAddress (void) const;
   159 
   160     /**
   161      * \brief Get the name.
   162      * \return the name
   163      */
   164     std::string GetName (void) const;
   165 
   166     /**
   167      * \brief Print some informations about the packet.
   168      * \param os output stream
   169      * \return info about this packet
   170      */
   171     virtual void Print (std::ostream& os) const;
   172 
   173     /**
   174      * \brief Get the serialized size of the packet.
   175      * \return size
   176      */
   177     virtual uint32_t GetSerializedSize (void) const;
   178 
   179     /**
   180      * \brief Serialize the packet.
   181      * \param start Buffer iterator
   182      */
   183     virtual void Serialize (Buffer::Iterator start) const;
   184 
   185     /**
   186      * \brief Deserialize the packet.
   187      * \param start Buffer iterator
   188      * \return size of the packet
   189      */
   190     virtual uint32_t Deserialize (Buffer::Iterator start);
   191 
   192   private:
   193     /**
   194      * \brief The version (always equal to 6).
   195      */
   196     uint32_t m_version : 4;
   197     /**
   198      * \brief The traffic class.
   199      */
   200     uint32_t m_trafficClass : 8;
   201 
   202     /**
   203      * \brief The flow label.
   204      * \note This is 20-bit value.
   205      */
   206     uint32_t m_flowLabel : 20;
   207 
   208     /**
   209      * \brief The payload length.
   210      */
   211     uint16_t m_payloadLength;
   212 
   213     /**
   214      * \brief The Next header number.
   215      */
   216     uint8_t m_nextHeader;
   217 
   218     /**
   219      * \brief The Hop limit value.
   220      */
   221     uint8_t m_hopLimit;
   222 
   223     /**
   224      * \brief The source address.
   225      */
   226     Ipv6Address m_sourceAddress;
   227 
   228     /**
   229      * \brief The destination address.
   230      */
   231     Ipv6Address m_destinationAddress;
   232 };
   233 
   234 } /* namespace ns3 */
   235 
   236 #endif /* IPV6_HEADER_H */
   237