Alexander Afanasyev | 5d79e68 | 2012-11-19 14:12:23 -0800 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2011 University of California, Los Angeles |
| 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: Ilya Moiseenko <iliamo@cs.ucla.edu> |
| 19 | * Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 20 | */ |
| 21 | |
| 22 | #ifndef _NDN_INTEREST_HEADER_CCNB_H_ |
| 23 | #define _NDN_INTEREST_HEADER_CCNB_H_ |
| 24 | |
| 25 | #include "ns3/integer.h" |
| 26 | #include "ns3/header.h" |
| 27 | #include "ns3/simple-ref-count.h" |
| 28 | #include "ns3/nstime.h" |
| 29 | |
| 30 | #include <string> |
| 31 | #include <vector> |
| 32 | #include <list> |
| 33 | |
| 34 | #include "ndn-name-components.h" |
| 35 | |
| 36 | namespace ns3 { |
| 37 | |
| 38 | class Packet; |
| 39 | |
| 40 | namespace ndn { |
| 41 | |
| 42 | /** |
| 43 | * Ndn XML definition of Interest |
| 44 | * |
| 45 | * Only few important fields are actually implemented in the simulation |
| 46 | * |
| 47 | * <xs:element name="Interest" type="InterestType"/> |
| 48 | * <xs:complexType name="InterestType"> |
| 49 | * <xs:sequence> |
| 50 | * <xs:element name="Name" type="NameType"/> |
| 51 | * <xs:element name="MinSuffixComponents" type="xs:nonNegativeInteger" |
| 52 | * minOccurs="0" maxOccurs="1"/> |
| 53 | * <xs:element name="MaxSuffixComponents" type="xs:nonNegativeInteger" |
| 54 | * minOccurs="0" maxOccurs="1"/> |
| 55 | * <xs:choice minOccurs="0" maxOccurs="1"> |
| 56 | * <xs:element name="PublisherPublicKeyDigest" type="DigestType"/> |
| 57 | * <xs:element name="PublisherCertificateDigest" type="DigestType"/> |
| 58 | * <xs:element name="PublisherIssuerKeyDigest" type="DigestType"/> |
| 59 | * <xs:element name="PublisherIssuerCertificateDigest" type="DigestType"/> |
| 60 | * </xs:choice> |
| 61 | * <xs:element name="Exclude" type="ExcludeType" |
| 62 | * minOccurs="0" maxOccurs="1"/> |
| 63 | * <xs:element name="ChildSelector" type="xs:nonNegativeInteger" |
| 64 | * minOccurs="0" maxOccurs="1"/> |
| 65 | * <xs:element name="AnswerOriginKind" type="xs:nonNegativeInteger" |
| 66 | * minOccurs="0" maxOccurs="1"/> |
| 67 | * <xs:element name="Scope" type="xs:nonNegativeInteger" |
| 68 | * minOccurs="0" maxOccurs="1"/> |
| 69 | * <xs:element name="InterestLifetime" type="FinegrainLifetimeType" |
| 70 | * minOccurs="0" maxOccurs="1"/> |
| 71 | * <xs:element name="Nonce" type="Base64BinaryType" |
| 72 | * minOccurs="0" maxOccurs="1"/> |
| 73 | * </xs:sequence> |
| 74 | * </xs:complexType> |
| 75 | * |
| 76 | * <xs:complexType name="NameType"> |
| 77 | * <xs:sequence> |
| 78 | * <xs:element name="Component" type="Base64BinaryType" |
| 79 | * minOccurs="0" maxOccurs="unbounded"/> |
| 80 | * </xs:sequence> |
| 81 | * </xs:complexType> |
| 82 | * |
| 83 | * <xs:complexType name="ExcludeType"> |
| 84 | * <xs:sequence> |
| 85 | * <xs:choice minOccurs="0" maxOccurs="1"> |
| 86 | * <xs:element name="Any" type="EmptyType"/> |
| 87 | * <xs:element name="Bloom" type="Base64BinaryType"/> <!-- Bloom is deprecated --!> |
| 88 | * </xs:choice> |
| 89 | * <xs:sequence minOccurs="0" maxOccurs="unbounded"> |
| 90 | * <xs:element name="Component" type="Base64BinaryType"/> |
| 91 | * <xs:choice minOccurs="0" maxOccurs="1"> |
| 92 | * <xs:element name="Any" type="EmptyType"/> |
| 93 | * <xs:element name="Bloom" type="Base64BinaryType"/> <!-- Bloom is deprecated --!> |
| 94 | * </xs:choice> |
| 95 | * </xs:sequence> |
| 96 | * </xs:sequence> |
| 97 | * </xs:complexType> |
| 98 | * |
| 99 | * <!-- Binary representation of time, Unix time epoch, units 2**-12 sec (0.000244140625 sec) --> |
| 100 | * <!-- The length limit limit of 6 bytes is not actually to be enforced, but |
| 101 | * it will be a loooooooong time before anyone cares. --> |
| 102 | * |
| 103 | * <!-- Binary representation of relative time, relative to "now" --> |
| 104 | * <xs:complexType name="FinegrainLifetimeType"> |
| 105 | * <xs:simpleContent> |
| 106 | * <xs:extension base="BinaryTime12"> |
| 107 | * <xs:attribute name="ccnbencoding" type="xs:string" fixed="base64Binary"/> |
| 108 | * </xs:extension> |
| 109 | * </xs:simpleContent> |
| 110 | * </xs:complexType> |
| 111 | * |
| 112 | * <xs:simpleType name="BinaryTime12"> |
| 113 | * <xs:restriction base="xs:base64Binary"> |
| 114 | * <xs:length value="6" fixed="true"/> |
| 115 | * </xs:restriction> |
| 116 | * </xs:simpleType> |
| 117 | * |
| 118 | **/ |
| 119 | |
| 120 | /** |
| 121 | * @brief NDN InterestHeader and routines to serialize/deserialize |
| 122 | * |
| 123 | * Simplifications: |
| 124 | * - Name: binary name components are not supported |
| 125 | * - MinSuffixComponents and MasSuffixComponents: if value is negative (default), will not be serialized |
| 126 | * - ChildSelector, AnswerOriginKind: 0 - false, 1 - true, -1 not set |
| 127 | * - Publisher* elements are not supported |
| 128 | * - Exclude: only simple name matching is supported (Bloom support has been deprecated in Ndn) |
| 129 | * - InterestLifetime: ? |
| 130 | * - Nonce: 32 bit random integer. If value is 0, will not be serialized |
| 131 | **/ |
| 132 | class InterestHeader : public SimpleRefCount<InterestHeader, Header> |
| 133 | { |
| 134 | public: |
| 135 | /** |
| 136 | * \brief Constructor |
| 137 | * |
| 138 | * Creates a null header |
| 139 | **/ |
| 140 | InterestHeader (); |
| 141 | |
| 142 | /** |
| 143 | * @brief Copy constructor |
| 144 | */ |
| 145 | InterestHeader (const InterestHeader &interest); |
| 146 | |
| 147 | /** |
| 148 | * \brief Set interest name |
| 149 | * |
| 150 | * Sets name of the interest. For example, SetName( ndnNameComponents("prefix")("postfix") ); |
| 151 | * @param[in] name const pointer to ndnNameComponents object that contains an interest name |
| 152 | **/ |
| 153 | void |
| 154 | SetName (Ptr<NameComponents> name); |
| 155 | |
| 156 | |
| 157 | /** |
| 158 | * \brief Get interest name |
| 159 | * |
| 160 | * Gets name of the interest. |
| 161 | **/ |
| 162 | const NameComponents& |
| 163 | GetName () const; |
| 164 | |
| 165 | /** |
| 166 | * @brief Get smart pointer to the interest name (to avoid extra memory usage) |
| 167 | */ |
| 168 | Ptr<const NameComponents> |
| 169 | GetNamePtr () const; |
| 170 | |
| 171 | /** |
| 172 | * \brief Set interest MinSuffixComponents |
| 173 | * |
| 174 | * MinSuffixComponents refer to the number of name components beyond those in the prefix, |
| 175 | * and counting the implicit digest, that may occur in the matching ContentObject. |
| 176 | * \see http://www.ndn.org/releases/latest/doc/technical/InterestMessage.html for more information. |
| 177 | * @param[in] value minimum length of suffix components |
| 178 | **/ |
| 179 | void |
| 180 | SetMinSuffixComponents (int32_t value); |
| 181 | |
| 182 | /** |
| 183 | * \brief Get interest MinSuffixComponents |
| 184 | * |
| 185 | * MinSuffixComponents refer to the number of name components beyond those in the prefix, |
| 186 | * and counting the implicit digest, that may occur in the matching ContentObject. |
| 187 | * For more information, see http://www.ndn.org/releases/latest/doc/technical/InterestMessage.html |
| 188 | **/ |
| 189 | int32_t |
| 190 | GetMinSuffixComponents () const; |
| 191 | |
| 192 | |
| 193 | /** |
| 194 | * \brief Set interest MaxSuffixComponents |
| 195 | * |
| 196 | * MaxSuffixComponents refer to the number of name components beyond those in the prefix, |
| 197 | * and counting the implicit digest, that may occur in the matching ContentObject. |
| 198 | * \see http://www.ndn.org/releases/latest/doc/technical/InterestMessage.html for more information. |
| 199 | * @param[in] value maximum length of suffix components |
| 200 | **/ |
| 201 | void |
| 202 | SetMaxSuffixComponents (int32_t value); |
| 203 | |
| 204 | /** |
| 205 | * \brief Get interest MaxSuffixComponents |
| 206 | * |
| 207 | * MaxSuffixComponents refer to the number of name components beyond those in the prefix, |
| 208 | * and counting the implicit digest, that may occur in the matching ContentObject. |
| 209 | * For more information, see http://www.ndn.org/releases/latest/doc/technical/InterestMessage.html |
| 210 | **/ |
| 211 | int32_t |
| 212 | GetMaxSuffixComponents () const; |
| 213 | |
| 214 | /** |
| 215 | * \brief Set exclude filer |
| 216 | * |
| 217 | * For example, SetExclude (ndnNameComponents("exclude1")("exclude2")("exclude3")) |
| 218 | * @param[in] exclude const pointer to ndnNameComponents to be excluded |
| 219 | **/ |
| 220 | void |
| 221 | SetExclude (Ptr<NameComponents> exclude); |
| 222 | |
| 223 | /** |
| 224 | * \brief Check if interest conatins exclude filter |
| 225 | * |
| 226 | */ |
| 227 | bool |
| 228 | IsEnabledExclude () const; |
| 229 | |
| 230 | /** |
| 231 | * \brief Get exclude filter |
| 232 | */ |
| 233 | const NameComponents& |
| 234 | GetExclude () const; |
| 235 | |
| 236 | /** |
| 237 | * \brief Set ChildSelector |
| 238 | * Often a given interest will match more than one ContentObject within a given content store. |
| 239 | * The ChildSelector provides a way of expressing a preference for which of these should be returned. |
| 240 | * If the value is false, the leftmost child is preferred. If true, the rightmost child is preferred. |
| 241 | * \see http://www.ndn.org/releases/latest/doc/technical/InterestMessage.html for more information. |
| 242 | * @param[in] value boolean ChildSelector value |
| 243 | */ |
| 244 | void |
| 245 | SetChildSelector (bool value); |
| 246 | |
| 247 | /** |
| 248 | * \brief Return ChildSelector value |
| 249 | * \see http://www.ndn.org/releases/latest/doc/technical/InterestMessage.html for more information. |
| 250 | * |
| 251 | */ |
| 252 | bool |
| 253 | IsEnabledChildSelector () const; |
| 254 | |
| 255 | /** |
| 256 | * \brief Set AnswerOriginKind |
| 257 | * Default value for AnswerOriginKind is false. |
| 258 | * @param[in] value boolean AnswerOriginKind value |
| 259 | */ |
| 260 | void |
| 261 | SetAnswerOriginKind (bool value); |
| 262 | |
| 263 | /** |
| 264 | * \brief Check the value of AnswerOriginKind |
| 265 | * |
| 266 | */ |
| 267 | bool |
| 268 | IsEnabledAnswerOriginKind () const; |
| 269 | |
| 270 | /** |
| 271 | * \brief Set Scope |
| 272 | * Scope limits where the Interest may propagate. |
| 273 | * Scope 0 prevents propagation beyond the local ccnd (even to other applications on the same host). |
| 274 | * Scope 1 limits propagation to the applications on the originating host. |
| 275 | * Scope 2 limits propagation to no further than the next host. |
| 276 | * Other values are not defined, and will cause the Interest message to be dropped. |
| 277 | * Note that this is not a hop count - the value is not decremented as the interest is forwarded. |
| 278 | * @param[in] scope interest scope |
| 279 | */ |
| 280 | void |
| 281 | SetScope (int8_t scope); |
| 282 | |
| 283 | /** |
| 284 | * \brief Get Scope value |
| 285 | * Scope limits where the Interest may propagate. |
| 286 | * Scope 0 prevents propagation beyond the local ccnd (even to other applications on the same host). |
| 287 | * Scope 1 limits propagation to the applications on the originating host. |
| 288 | * Scope 2 limits propagation to no further than the next host. |
| 289 | * Other values are not defined, and will cause the Interest message to be dropped. |
| 290 | * Note that this is not a hop count - the value is not decremented as the interest is forwarded. |
| 291 | */ |
| 292 | int8_t |
| 293 | GetScope () const; |
| 294 | |
| 295 | /** |
| 296 | * \brief Set InterestLifetime |
| 297 | * InterestLifetime indicates the (approximate) time remaining before the interest times out. |
| 298 | * The timeout is relative to the arrival time of the interest at the current node. |
| 299 | * \see http://www.ndn.org/releases/latest/doc/technical/InterestMessage.html for more information. |
| 300 | * @param[in] time interest lifetime |
| 301 | */ |
| 302 | void |
| 303 | SetInterestLifetime (Time time); |
| 304 | |
| 305 | /** |
| 306 | * \brief Get InterestLifetime value |
| 307 | * InterestLifetime indicates the (approximate) time remaining before the interest times out. |
| 308 | * The timeout is relative to the arrival time of the interest at the current node. |
| 309 | * \see http://www.ndn.org/releases/latest/doc/technical/InterestMessage.html for more information. |
| 310 | */ |
| 311 | Time |
| 312 | GetInterestLifetime () const; |
| 313 | |
| 314 | /** |
| 315 | * \brief Set Nonce |
| 316 | * Nonce carries a randomly-genenerated bytestring that is used to detect and discard duplicate Interest messages. |
| 317 | * @param[in] nonce Unique packet identification number |
| 318 | */ |
| 319 | void |
| 320 | SetNonce (uint32_t nonce); |
| 321 | |
| 322 | /** |
| 323 | * \brief Get Nonce value |
| 324 | * Nonce carries a randomly-genenerated bytestring that is used to detect and discard duplicate Interest messages. |
| 325 | * |
| 326 | */ |
| 327 | uint32_t |
| 328 | GetNonce () const; |
| 329 | |
| 330 | /** |
| 331 | * @brief NACK Type |
| 332 | * Specifies the type of Interest packet |
| 333 | */ |
| 334 | enum |
| 335 | { |
| 336 | NORMAL_INTEREST = 0, |
| 337 | NACK_LOOP = 10, |
| 338 | NACK_CONGESTION = 11, |
| 339 | NACK_GIVEUP_PIT = 12, |
| 340 | }; |
| 341 | |
| 342 | /** |
| 343 | * \brief Mark the Interest as a Negative Acknowledgement |
| 344 | * Three types of NACKs are supported |
| 345 | * 1. NACK_LOOP |
| 346 | * 2. NACK_CONGESTION |
| 347 | * 3. NACK_GIVEUP_PIT |
| 348 | * @param[in] nackType NACK_LOOP or NACK_CONGESTION or NACK_GIVEUP_PIT or NORMAL_INTEREST |
| 349 | */ |
| 350 | void |
| 351 | SetNack (uint32_t nackType); |
| 352 | |
| 353 | /** |
| 354 | * \brief Get NACK type |
| 355 | * Returns NACK_LOOP, NACK_CONGESTION or NACK_GIVEUP_PIT. |
| 356 | * Otherwise, in case of normal interest packet, returns NORMAL_INTEREST (equals 0). |
| 357 | */ |
| 358 | uint32_t |
| 359 | GetNack () const; |
| 360 | |
| 361 | ////////////////////////////////////////////////////////////////// |
| 362 | |
| 363 | static TypeId GetTypeId (void); ///< @brief Get TypeId of the class |
| 364 | virtual TypeId GetInstanceTypeId (void) const; ///< @brief Get TypeId of the instance |
| 365 | |
| 366 | /** |
| 367 | * \brief Print Interest packet |
| 368 | */ |
| 369 | virtual void Print (std::ostream &os) const; |
| 370 | |
| 371 | /** |
| 372 | * \brief Get the size of Interest packet |
| 373 | * Returns the Interest packet size after serialization |
| 374 | */ |
| 375 | virtual uint32_t GetSerializedSize (void) const; |
| 376 | |
| 377 | /** |
| 378 | * \brief Serialize Interest packet |
| 379 | * Serializes Interest packet into Buffer::Iterator |
| 380 | * @param[in] start buffer to contain serialized Interest packet |
| 381 | */ |
| 382 | virtual void Serialize (Buffer::Iterator start) const; |
| 383 | |
| 384 | /** |
| 385 | * \brief Deserialize Interest packet |
| 386 | * Deserializes Buffer::Iterator into Interest packet |
| 387 | * @param[in] start buffer that contains serialized Interest packet |
| 388 | */ |
| 389 | virtual uint32_t Deserialize (Buffer::Iterator start); |
| 390 | |
| 391 | /** |
| 392 | * @brief Cheat for python bindings |
| 393 | */ |
| 394 | static Ptr<InterestHeader> |
| 395 | GetInterest (Ptr<Packet> packet); |
| 396 | |
| 397 | private: |
| 398 | Ptr<NameComponents> m_name; ///< Interest name |
| 399 | int32_t m_minSuffixComponents; ///< Minimum suffix components. not used if negative |
| 400 | int32_t m_maxSuffixComponents; ///< Maximum suffix components. not used if negative |
| 401 | Ptr<NameComponents> m_exclude; ///< Exclude filter |
| 402 | bool m_childSelector; ///< Default value for ChildSelector is false |
| 403 | bool m_answerOriginKind; ///< Default value for AnswerOriginKind is false |
| 404 | int8_t m_scope; ///< -1 not set, 0 local scope, 1 this host, 2 immediate neighborhood |
| 405 | Time m_interestLifetime; ///< InterestLifetime |
| 406 | uint32_t m_nonce; ///< Nonce. not used if zero |
| 407 | uint32_t m_nackType; ///< Negative Acknowledgement type |
| 408 | }; |
| 409 | |
| 410 | /** |
| 411 | * @ingroup ndn-exceptions |
| 412 | * @brief Class for Interest parsing exception |
| 413 | */ |
| 414 | class InterestHeaderException {}; |
| 415 | |
| 416 | } // namespace ndn |
| 417 | } // namespace ns3 |
| 418 | |
| 419 | #endif // _NDN_INTEREST_HEADER_CCNB_H_ |