Alexander Afanasyev | 6b997c5 | 2011-08-08 12:55:25 -0700 | [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 | */ |
Ilya Moiseenko | 08a98a4 | 2011-08-02 16:06:51 -0700 | [diff] [blame] | 20 | |
Alexander Afanasyev | 404c079 | 2011-08-09 17:09:59 -0700 | [diff] [blame] | 21 | #ifndef _INTEREST_PACKET_H_ |
| 22 | #define _INTEREST_PACKET_H_ |
Ilya Moiseenko | 08a98a4 | 2011-08-02 16:06:51 -0700 | [diff] [blame] | 23 | |
| 24 | //#define CCN_INTEREST_LIFETIME_SEC 4 |
| 25 | //#define CCN_INTEREST_LIFETIME_MICROSEC (CCN_INTEREST_LIFETIME_SEC * 1000000) |
| 26 | |
Alexander Afanasyev | 3a6ea5c | 2011-08-11 18:15:49 -0700 | [diff] [blame] | 27 | #include <ns3/integer.h> |
Alexander Afanasyev | 404c079 | 2011-08-09 17:09:59 -0700 | [diff] [blame] | 28 | #include <ns3/header.h> |
Ilya Moiseenko | 08a98a4 | 2011-08-02 16:06:51 -0700 | [diff] [blame] | 29 | #include <ns3/packet.h> |
Alexander Afanasyev | 3a6ea5c | 2011-08-11 18:15:49 -0700 | [diff] [blame] | 30 | |
Ilya Moiseenko | 5881eb1 | 2011-08-04 19:05:26 -0700 | [diff] [blame] | 31 | #include <string> |
Alexander Afanasyev | 3a6ea5c | 2011-08-11 18:15:49 -0700 | [diff] [blame] | 32 | #include <vector> |
| 33 | #include <list> |
| 34 | |
| 35 | #include "name-components.h" |
Ilya Moiseenko | 08a98a4 | 2011-08-02 16:06:51 -0700 | [diff] [blame] | 36 | |
| 37 | namespace ns3 |
| 38 | { |
Ilya Moiseenko | 5881eb1 | 2011-08-04 19:05:26 -0700 | [diff] [blame] | 39 | namespace NDNabstraction |
| 40 | { |
Alexander Afanasyev | 3a6ea5c | 2011-08-11 18:15:49 -0700 | [diff] [blame] | 41 | |
| 42 | /** |
| 43 | * CCNx 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 | NDN InterestPacket and routes 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 CCNx) |
| 129 | - InterestLifetime: not used if negative |
| 130 | - Nonce: 32 bit random integer. If value is 0, will not be serialized |
| 131 | */ |
| 132 | class InterestHeader : public Header |
| 133 | { |
| 134 | public: |
| 135 | /** |
| 136 | * Constructor |
| 137 | * |
| 138 | * Creates a null header |
| 139 | **/ |
| 140 | InterestHeader (); |
| 141 | |
| 142 | /** |
| 143 | * \brief Set interest name |
| 144 | * |
| 145 | * Sets name of the interest. For example, SetName( Name::Components("prefix")("postfix") ); |
| 146 | **/ |
| 147 | void |
| 148 | SetName (const Ptr<Name::Components> &name); |
| 149 | |
| 150 | const Name::Components& |
| 151 | GetName () const; |
| 152 | |
| 153 | void |
| 154 | SetMinSuffixComponents (int32_t value); |
| 155 | |
| 156 | int32_t |
| 157 | GetMinSuffixComponents () const; |
| 158 | |
| 159 | void |
| 160 | SetMaxSuffixComponents (int32_t value); |
| 161 | |
| 162 | int32_t |
| 163 | GetMaxSuffixComponents () const; |
| 164 | |
| 165 | /** |
| 166 | * \brief Set exclude filer |
| 167 | * |
| 168 | * For example, SetExclude (Name::Components("exclude1")("exclude2")("exclude3")) |
| 169 | **/ |
| 170 | void |
| 171 | SetExclude (const Ptr<Name::Components> &exclude); |
| 172 | |
| 173 | const Name::Components& |
| 174 | GetExclude () const; |
| 175 | |
| 176 | void |
| 177 | EnableChildSelector (); |
| 178 | |
| 179 | bool |
| 180 | IsEnabledChildSelector () const; |
| 181 | |
| 182 | void |
| 183 | EnableAnswerOriginKind (); |
| 184 | |
| 185 | bool |
| 186 | IsEnabledAnswerOriginKind () const; |
| 187 | |
| 188 | void |
| 189 | SetScope (int8_t scope); |
| 190 | |
| 191 | int8_t |
| 192 | GetScope () const; |
| 193 | |
| 194 | void |
| 195 | SetInterestLifetime (intmax_t lifetime); |
| 196 | |
| 197 | intmax_t |
| 198 | GetInterestLifetime () const; |
| 199 | |
| 200 | void |
| 201 | SetNonce (uint32_t nonce); |
| 202 | |
| 203 | uint32_t |
| 204 | GetNonce () const; |
| 205 | |
| 206 | ////////////////////////////////////////////////////////////////// |
| 207 | |
| 208 | static TypeId GetTypeId (void); |
| 209 | virtual TypeId GetInstanceTypeId (void) const; |
| 210 | virtual void Print (std::ostream &os) const; |
| 211 | virtual uint32_t GetSerializedSize (void) const; |
| 212 | virtual void Serialize (Buffer::Iterator start) const; |
| 213 | virtual uint32_t Deserialize (Buffer::Iterator start); |
| 214 | |
| 215 | private: |
| 216 | Ptr<Name::Components> m_name; |
| 217 | int32_t m_minSuffixComponents; ///< minimum suffix components. not used if negative |
| 218 | int32_t m_maxSuffixComponents; ///< maximum suffix components. not used if negative |
| 219 | Ptr<Name::Components> m_exclude; ///< exclude filter |
| 220 | bool m_childSelector; |
| 221 | bool m_answerOriginKind; |
| 222 | int8_t m_scope; ///< -1 not set, 0 local scope, 1 this host, 2 immediate neighborhood |
| 223 | intmax_t m_interestLifetime; ///< InterestLifetime in 2^{-12} (0.000244140625 sec). not used if negative |
| 224 | uint32_t m_nonce; ///< Nonce. not used if zero |
| 225 | }; |
| 226 | |
| 227 | |
| 228 | // Not sure that we need a separate NndPacket class. Everything useful will be inside (Interest|ContentObject)Header |
| 229 | // class NdnPacket : public Packet |
| 230 | // { |
| 231 | // public: |
| 232 | // NdnPacket( ) |
| 233 | // ; |
Alexander Afanasyev | 404c079 | 2011-08-09 17:09:59 -0700 | [diff] [blame] | 234 | // InterestPacket (const unsigned char *name, uint32_t size); |
| 235 | |
| 236 | |
| 237 | // uint32_t GetName (unsigned char *name); |
| 238 | |
| 239 | // void AddTimeout (uint32_t milliseconds); |
| 240 | // uint32_t GetTimeout (void); |
| 241 | // void RemoveTimeout (void); |
| 242 | |
| 243 | // void AddNonce (uint32_t nonce); |
| 244 | // uint32_t GetNonce (void); |
| 245 | // void RemoveNonce (void); |
| 246 | |
| 247 | // uint32_t maxNameLength; |
| 248 | |
Alexander Afanasyev | 3a6ea5c | 2011-08-11 18:15:49 -0700 | [diff] [blame] | 249 | // }; |
Alexander Afanasyev | f583ef2 | 2011-08-08 19:05:28 -0700 | [diff] [blame] | 250 | |
Ilya Moiseenko | 08a98a4 | 2011-08-02 16:06:51 -0700 | [diff] [blame] | 251 | } |
Ilya Moiseenko | 5881eb1 | 2011-08-04 19:05:26 -0700 | [diff] [blame] | 252 | } |
Ilya Moiseenko | 08a98a4 | 2011-08-02 16:06:51 -0700 | [diff] [blame] | 253 | |
Alexander Afanasyev | 404c079 | 2011-08-09 17:09:59 -0700 | [diff] [blame] | 254 | #endif // _NDN_PACKET_H_ |