1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 /* 3 * Copyright (c) 2014 Universita' di Firenze, Italy 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: Tommaso Pecorella <tommaso.pecorella@unifi.it> 19 */ 20 21 #ifndef RIPNG_HEADER_H 22 #define RIPNG_HEADER_H 23 24 #include <list> 25 #include "ns3/header.h" 26 #include "ns3/ipv6-address.h" 27 #include "ns3/packet.h" 28 #include "ns3/ipv6-header.h" 29 30 31 namespace ns3 { 32 33 /** 34 * \ingroup ripng 35 * 36 * \brief RipNg Routing Table Entry (RTE) - see \RFC{2080} 37 */ 38 class RipNgRte : public Header 39 { 40 public: 41 RipNgRte (void); 42 43 /** 44 * \brief Get the type ID. 45 * \return the object TypeId 46 */ 47 static TypeId GetTypeId (void); 48 49 /** 50 * \brief Return the instance type identifier. 51 * \return instance type ID 52 */ 53 virtual TypeId GetInstanceTypeId (void) const; 54 55 virtual void Print (std::ostream& os) const; 56 57 /** 58 * \brief Get the serialized size of the packet. 59 * \return size 60 */ 61 virtual uint32_t GetSerializedSize (void) const; 62 63 /** 64 * \brief Serialize the packet. 65 * \param start Buffer iterator 66 */ 67 virtual void Serialize (Buffer::Iterator start) const; 68 69 /** 70 * \brief Deserialize the packet. 71 * \param start Buffer iterator 72 * \return size of the packet 73 */ 74 virtual uint32_t Deserialize (Buffer::Iterator start); 75 76 /** 77 * \brief Set the prefix 78 * \param prefix the prefix 79 */ 80 void SetPrefix (Ipv6Address prefix); 81 82 /** 83 * \brief Get the prefix 84 * \returns the prefix 85 */ 86 Ipv6Address GetPrefix (void) const; 87 88 /** 89 * \brief Set the prefix length 90 * \param prefixLen the prefix length 91 */ 92 void SetPrefixLen (uint8_t prefixLen); 93 94 /** 95 * \brief Get the prefix length 96 * \returns the prefix length 97 */ 98 uint8_t GetPrefixLen (void) const; 99 100 /** 101 * \brief Set the route tag 102 * \param routeTag the route tag 103 */ 104 void SetRouteTag (uint16_t routeTag); 105 106 /** 107 * \brief Get the route tag 108 * \returns the route tag 109 */ 110 uint16_t GetRouteTag (void) const; 111 112 /** 113 * \brief Set the route metric 114 * \param routeMetric the route metric 115 */ 116 void SetRouteMetric (uint8_t routeMetric); 117 118 /** 119 * \brief Get the route metric 120 * \returns the route metric 121 */ 122 uint8_t GetRouteMetric (void) const; 123 124 125 private: 126 Ipv6Address m_prefix; //!< prefix 127 uint16_t m_tag; //!< route tag 128 uint8_t m_prefixLen; //!< prefix length 129 uint8_t m_metric; //!< route metric 130 }; 131 132 /** 133 * \brief Stream insertion operator. 134 * 135 * \param os the reference to the output stream 136 * \param h the Routing Table Entry 137 * \returns the reference to the output stream 138 */ 139 std::ostream & operator << (std::ostream & os, const RipNgRte & h); 140 141 /** 142 * \ingroup ripng 143 * 144 * \brief RipNgHeader - see \RFC{2080} 145 */ 146 class RipNgHeader : public Header 147 { 148 public: 149 RipNgHeader (void); 150 151 /** 152 * \brief Get the type ID. 153 * \return the object TypeId 154 */ 155 static TypeId GetTypeId (void); 156 157 /** 158 * \brief Return the instance type identifier. 159 * \return instance type ID 160 */ 161 virtual TypeId GetInstanceTypeId (void) const; 162 163 virtual void Print (std::ostream& os) const; 164 165 /** 166 * \brief Get the serialized size of the packet. 167 * \return size 168 */ 169 virtual uint32_t GetSerializedSize (void) const; 170 171 /** 172 * \brief Serialize the packet. 173 * \param start Buffer iterator 174 */ 175 virtual void Serialize (Buffer::Iterator start) const; 176 177 /** 178 * \brief Deserialize the packet. 179 * \param start Buffer iterator 180 * \return size of the packet 181 */ 182 virtual uint32_t Deserialize (Buffer::Iterator start); 183 184 /** 185 * Commands to be used in RipNg headers 186 */ 187 enum Command_e 188 { 189 REQUEST = 0x1, 190 RESPONSE = 0x2, 191 }; 192 193 /** 194 * \brief Set the command 195 * \param command the command 196 */ 197 void SetCommand (Command_e command); 198 199 /** 200 * \brief Get the command 201 * \returns the command 202 */ 203 Command_e GetCommand (void) const; 204 205 /** 206 * \brief Add a RTE to the message 207 * \param rte the RTE 208 */ 209 void AddRte (RipNgRte rte); 210 211 /** 212 * \brief Clear all the RTEs from the header 213 */ 214 void ClearRtes (); 215 216 /** 217 * \brief Get the number of RTE included in the message 218 * \returns the number of RTE in the message 219 */ 220 uint16_t GetRteNumber (void) const; 221 222 /** 223 * \brief Get the list of the RTEs included in the message 224 * \returns the list of the RTEs in the message 225 */ 226 std::list<RipNgRte> GetRteList (void) const; 227 228 private: 229 uint8_t m_command; //!< command type 230 std::list<RipNgRte> m_rteList; //!< list of the RTEs in the message 231 }; 232 233 /** 234 * \brief Stream insertion operator. 235 * 236 * \param os the reference to the output stream 237 * \param h the RIPng header 238 * \returns the reference to the output stream 239 */ 240 std::ostream & operator << (std::ostream & os, const RipNgHeader & h); 241 242 } 243 244 #endif /* RIPNG_HEADER_H */ 245 246