00001 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2007-2008 Louis Pasteur University 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation; 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 * 00018 * Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr> 00019 */ 00020 00021 #ifndef IPV6_HEADER_H 00022 #define IPV6_HEADER_H 00023 00024 #include "ns3/header.h" 00025 #include "ns3/ipv6-address.h" 00026 00027 namespace ns3 { 00028 00029 /** 00030 * \class Ipv6Header 00031 * \brief Packet header for IPv6 00032 */ 00033 class Ipv6Header : public Header 00034 { 00035 public: 00036 /** 00037 * \enum NextHeader_e 00038 * \brief IPv6 next-header value 00039 */ 00040 enum NextHeader_e 00041 { 00042 IPV6_EXT_HOP_BY_HOP=0, 00043 IPV6_IPV4=4, 00044 IPV6_TCP=6, 00045 IPV6_UDP=17, 00046 IPV6_IPV6=41, 00047 IPV6_EXT_ROUTING=43, 00048 IPV6_EXT_FRAGMENTATION=44, 00049 IPV6_EXT_CONFIDENTIALITY=50, 00050 IPV6_EXT_AUTHENTIFICATION, 00051 IPV6_ICMPV6=58, 00052 IPV6_EXT_END, 00053 IPV6_EXT_DESTINATION, 00054 IPV6_SCTP=135, 00055 IPV6_EXT_MOBILITY=135, 00056 IPV6_UDP_LITE, 00057 }; 00058 00059 /** 00060 * \brief Get the type identifier. 00061 * \return type identifier 00062 */ 00063 static TypeId GetTypeId (void); 00064 00065 /** 00066 * \brief Return the instance type identifier. 00067 * \return instance type ID 00068 */ 00069 virtual TypeId GetInstanceTypeId (void) const; 00070 00071 /** 00072 * \brief Constructor. 00073 */ 00074 Ipv6Header (void); 00075 00076 /** 00077 * \brief Set the "Traffic class" field. 00078 * \param traffic the 8-bit value 00079 */ 00080 void SetTrafficClass (uint8_t traffic); 00081 00082 /** 00083 * \brief Get the "Traffic class" field. 00084 * \return the traffic value 00085 */ 00086 uint8_t GetTrafficClass (void) const; 00087 00088 /** 00089 * \brief Set the "Flow label" field. 00090 * \param flow the 20-bit value 00091 */ 00092 void SetFlowLabel (uint32_t flow); 00093 00094 /** 00095 * \brief Get the "Flow label" field. 00096 * \return the flow label value 00097 */ 00098 uint32_t GetFlowLabel (void) const; 00099 00100 /** 00101 * \brief Set the "Payload length" field. 00102 * \param len the length of the payload in bytes 00103 */ 00104 void SetPayloadLength (uint16_t len); 00105 00106 /** 00107 * \brief Get the "Payload length" field. 00108 * \return the payload length 00109 */ 00110 uint16_t GetPayloadLength (void) const; 00111 00112 /** 00113 * \brief Set the "Next header" field. 00114 * \param next the next header number 00115 */ 00116 void SetNextHeader (uint8_t next); 00117 00118 /** 00119 * \brief Get the next header. 00120 * \return the next header number 00121 */ 00122 uint8_t GetNextHeader (void) const; 00123 00124 /** 00125 * \brief Set the "Hop limit" field (TTL). 00126 * \param limit the 8-bit value 00127 */ 00128 void SetHopLimit (uint8_t limit); 00129 00130 /** 00131 * \brief Get the "Hop limit" field (TTL). 00132 * \return the hop limit value 00133 */ 00134 uint8_t GetHopLimit (void) const; 00135 00136 /** 00137 * \brief Set the "Source address" field. 00138 * \param src the source address 00139 */ 00140 void SetSourceAddress (Ipv6Address src); 00141 00142 /** 00143 * \brief Get the "Source address" field. 00144 * \return the source address 00145 */ 00146 Ipv6Address GetSourceAddress (void) const; 00147 00148 /** 00149 * \brief Set the "Destination address" field. 00150 * \param dst the destination address 00151 */ 00152 void SetDestinationAddress (Ipv6Address dst); 00153 00154 /** 00155 * \brief Get the "Destination address" field. 00156 * \return the destination address 00157 */ 00158 Ipv6Address GetDestinationAddress (void) const; 00159 00160 /** 00161 * \brief Print some informations about the packet. 00162 * \param os output stream 00163 * \return info about this packet 00164 */ 00165 virtual void Print (std::ostream& os) const; 00166 00167 /** 00168 * \brief Get the serialized size of the packet. 00169 * \return size 00170 */ 00171 virtual uint32_t GetSerializedSize (void) const; 00172 00173 /** 00174 * \brief Serialize the packet. 00175 * \param start Buffer iterator 00176 */ 00177 virtual void Serialize (Buffer::Iterator start) const; 00178 00179 /** 00180 * \brief Deserialize the packet. 00181 * \param start Buffer iterator 00182 * \return size of the packet 00183 */ 00184 virtual uint32_t Deserialize (Buffer::Iterator start); 00185 00186 private: 00187 /** 00188 * \brief The version (always equal to 6). 00189 */ 00190 uint32_t m_version : 4; 00191 /** 00192 * \brief The traffic class. 00193 */ 00194 uint32_t m_trafficClass : 8; 00195 00196 /** 00197 * \brief The flow label. 00198 * \note This is 20-bit value. 00199 */ 00200 uint32_t m_flowLabel : 20; 00201 00202 /** 00203 * \brief The payload length. 00204 */ 00205 uint16_t m_payloadLength; 00206 00207 /** 00208 * \brief The Next header number. 00209 */ 00210 uint8_t m_nextHeader; 00211 00212 /** 00213 * \brief The Hop limit value. 00214 */ 00215 uint8_t m_hopLimit; 00216 00217 /** 00218 * \brief The source address. 00219 */ 00220 Ipv6Address m_sourceAddress; 00221 00222 /** 00223 * \brief The destination address. 00224 */ 00225 Ipv6Address m_destinationAddress; 00226 }; 00227 00228 } /* namespace ns3 */ 00229 00230 #endif /* IPV6_HEADER_H */ 00231