Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 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 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 22 | #ifndef _CCNX_INTEREST_HEADER_H_ |
| 23 | #define _CCNX_INTEREST_HEADER_H_ |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 24 | |
Alexander Afanasyev | 2536e20 | 2011-08-12 14:13:10 -0700 | [diff] [blame] | 25 | #include "ns3/integer.h" |
| 26 | #include "ns3/header.h" |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 27 | #include "ns3/nstime.h" |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 28 | |
| 29 | #include <string> |
| 30 | #include <vector> |
| 31 | #include <list> |
| 32 | |
Ilya Moiseenko | d26e682 | 2011-08-23 17:48:38 -0700 | [diff] [blame] | 33 | #include "ccnx-name-components.h" |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 34 | |
| 35 | namespace ns3 |
| 36 | { |
Alexander Afanasyev | 2536e20 | 2011-08-12 14:13:10 -0700 | [diff] [blame] | 37 | |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 38 | /** |
| 39 | * CCNx XML definition of Interest |
| 40 | * |
| 41 | * Only few important fields are actually implemented in the simulation |
| 42 | * |
| 43 | * <xs:element name="Interest" type="InterestType"/> |
| 44 | * <xs:complexType name="InterestType"> |
| 45 | * <xs:sequence> |
| 46 | * <xs:element name="Name" type="NameType"/> |
| 47 | * <xs:element name="MinSuffixComponents" type="xs:nonNegativeInteger" |
| 48 | * minOccurs="0" maxOccurs="1"/> |
| 49 | * <xs:element name="MaxSuffixComponents" type="xs:nonNegativeInteger" |
| 50 | * minOccurs="0" maxOccurs="1"/> |
| 51 | * <xs:choice minOccurs="0" maxOccurs="1"> |
| 52 | * <xs:element name="PublisherPublicKeyDigest" type="DigestType"/> |
| 53 | * <xs:element name="PublisherCertificateDigest" type="DigestType"/> |
| 54 | * <xs:element name="PublisherIssuerKeyDigest" type="DigestType"/> |
| 55 | * <xs:element name="PublisherIssuerCertificateDigest" type="DigestType"/> |
| 56 | * </xs:choice> |
| 57 | * <xs:element name="Exclude" type="ExcludeType" |
| 58 | * minOccurs="0" maxOccurs="1"/> |
| 59 | * <xs:element name="ChildSelector" type="xs:nonNegativeInteger" |
| 60 | * minOccurs="0" maxOccurs="1"/> |
| 61 | * <xs:element name="AnswerOriginKind" type="xs:nonNegativeInteger" |
| 62 | * minOccurs="0" maxOccurs="1"/> |
| 63 | * <xs:element name="Scope" type="xs:nonNegativeInteger" |
| 64 | * minOccurs="0" maxOccurs="1"/> |
| 65 | * <xs:element name="InterestLifetime" type="FinegrainLifetimeType" |
| 66 | * minOccurs="0" maxOccurs="1"/> |
| 67 | * <xs:element name="Nonce" type="Base64BinaryType" |
| 68 | * minOccurs="0" maxOccurs="1"/> |
| 69 | * </xs:sequence> |
| 70 | * </xs:complexType> |
| 71 | * |
| 72 | * <xs:complexType name="NameType"> |
| 73 | * <xs:sequence> |
| 74 | * <xs:element name="Component" type="Base64BinaryType" |
| 75 | * minOccurs="0" maxOccurs="unbounded"/> |
| 76 | * </xs:sequence> |
| 77 | * </xs:complexType> |
| 78 | * |
| 79 | * <xs:complexType name="ExcludeType"> |
| 80 | * <xs:sequence> |
| 81 | * <xs:choice minOccurs="0" maxOccurs="1"> |
| 82 | * <xs:element name="Any" type="EmptyType"/> |
| 83 | * <xs:element name="Bloom" type="Base64BinaryType"/> <!-- Bloom is deprecated --!> |
| 84 | * </xs:choice> |
| 85 | * <xs:sequence minOccurs="0" maxOccurs="unbounded"> |
| 86 | * <xs:element name="Component" type="Base64BinaryType"/> |
| 87 | * <xs:choice minOccurs="0" maxOccurs="1"> |
| 88 | * <xs:element name="Any" type="EmptyType"/> |
| 89 | * <xs:element name="Bloom" type="Base64BinaryType"/> <!-- Bloom is deprecated --!> |
| 90 | * </xs:choice> |
| 91 | * </xs:sequence> |
| 92 | * </xs:sequence> |
| 93 | * </xs:complexType> |
| 94 | * |
| 95 | * <!-- Binary representation of time, Unix time epoch, units 2**-12 sec (0.000244140625 sec) --> |
| 96 | * <!-- The length limit limit of 6 bytes is not actually to be enforced, but |
| 97 | * it will be a loooooooong time before anyone cares. --> |
| 98 | * |
| 99 | * <!-- Binary representation of relative time, relative to "now" --> |
| 100 | * <xs:complexType name="FinegrainLifetimeType"> |
| 101 | * <xs:simpleContent> |
| 102 | * <xs:extension base="BinaryTime12"> |
| 103 | * <xs:attribute name="ccnbencoding" type="xs:string" fixed="base64Binary"/> |
| 104 | * </xs:extension> |
| 105 | * </xs:simpleContent> |
| 106 | * </xs:complexType> |
| 107 | * |
| 108 | * <xs:simpleType name="BinaryTime12"> |
| 109 | * <xs:restriction base="xs:base64Binary"> |
| 110 | * <xs:length value="6" fixed="true"/> |
| 111 | * </xs:restriction> |
| 112 | * </xs:simpleType> |
| 113 | * |
| 114 | **/ |
| 115 | |
| 116 | /** |
| 117 | NDN InterestHeader and routines to serialize/deserialize |
| 118 | |
| 119 | Simplifications: |
| 120 | - Name: binary name components are not supported |
| 121 | - MinSuffixComponents and MasSuffixComponents: if value is negative (default), will not be serialized |
| 122 | - ChildSelector, AnswerOriginKind: 0 - false, 1 - true, -1 not set |
| 123 | - Publisher* elements are not supported |
| 124 | - Exclude: only simple name matching is supported (Bloom support has been deprecated in CCNx) |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 125 | - InterestLifetime: ? |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 126 | - Nonce: 32 bit random integer. If value is 0, will not be serialized |
| 127 | */ |
Alexander Afanasyev | fccdb9e | 2011-08-22 19:27:14 -0700 | [diff] [blame] | 128 | class CcnxInterestHeader : public Header |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 129 | { |
| 130 | public: |
| 131 | /** |
| 132 | * Constructor |
| 133 | * |
| 134 | * Creates a null header |
| 135 | **/ |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 136 | CcnxInterestHeader (); |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 137 | |
| 138 | /** |
| 139 | * \brief Set interest name |
| 140 | * |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame] | 141 | * Sets name of the interest. For example, SetName( CcnxNameComponents("prefix")("postfix") ); |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 142 | **/ |
| 143 | void |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame] | 144 | SetName (const Ptr<CcnxNameComponents> &name); |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 145 | |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame] | 146 | const CcnxNameComponents& |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 147 | GetName () const; |
| 148 | |
| 149 | void |
| 150 | SetMinSuffixComponents (int32_t value); |
| 151 | |
| 152 | int32_t |
| 153 | GetMinSuffixComponents () const; |
| 154 | |
| 155 | void |
| 156 | SetMaxSuffixComponents (int32_t value); |
| 157 | |
| 158 | int32_t |
| 159 | GetMaxSuffixComponents () const; |
| 160 | |
| 161 | /** |
| 162 | * \brief Set exclude filer |
| 163 | * |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame] | 164 | * For example, SetExclude (CcnxNameComponents("exclude1")("exclude2")("exclude3")) |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 165 | **/ |
| 166 | void |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame] | 167 | SetExclude (const Ptr<CcnxNameComponents> &exclude); |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 168 | |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 169 | bool |
| 170 | IsEnabledExclude () const; |
| 171 | |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame] | 172 | const CcnxNameComponents& |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 173 | GetExclude () const; |
| 174 | |
| 175 | void |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 176 | SetChildSelector (bool value); |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 177 | |
| 178 | bool |
| 179 | IsEnabledChildSelector () const; |
| 180 | |
| 181 | void |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 182 | SetAnswerOriginKind (bool value); |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 183 | |
| 184 | bool |
| 185 | IsEnabledAnswerOriginKind () const; |
| 186 | |
| 187 | void |
| 188 | SetScope (int8_t scope); |
| 189 | |
| 190 | int8_t |
| 191 | GetScope () const; |
| 192 | |
| 193 | void |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 194 | SetInterestLifetime (Time time); |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 195 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 196 | Time |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 197 | GetInterestLifetime () const; |
| 198 | |
| 199 | void |
| 200 | SetNonce (uint32_t nonce); |
| 201 | |
| 202 | uint32_t |
| 203 | GetNonce () const; |
| 204 | |
| 205 | ////////////////////////////////////////////////////////////////// |
| 206 | |
| 207 | static TypeId GetTypeId (void); |
| 208 | virtual TypeId GetInstanceTypeId (void) const; |
| 209 | virtual void Print (std::ostream &os) const; |
| 210 | virtual uint32_t GetSerializedSize (void) const; |
| 211 | virtual void Serialize (Buffer::Iterator start) const; |
| 212 | virtual uint32_t Deserialize (Buffer::Iterator start); |
| 213 | |
| 214 | private: |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame] | 215 | Ptr<CcnxNameComponents> m_name; |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 216 | int32_t m_minSuffixComponents; ///< minimum suffix components. not used if negative |
| 217 | int32_t m_maxSuffixComponents; ///< maximum suffix components. not used if negative |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame] | 218 | Ptr<CcnxNameComponents> m_exclude; ///< exclude filter |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 219 | bool m_childSelector; |
| 220 | bool m_answerOriginKind; |
| 221 | int8_t m_scope; ///< -1 not set, 0 local scope, 1 this host, 2 immediate neighborhood |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 222 | Time m_interestLifetime; |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 223 | uint32_t m_nonce; ///< Nonce. not used if zero |
| 224 | }; |
| 225 | |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 226 | class CcnxInterestHeaderException {}; |
| 227 | |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 228 | } // namespace ns3 |
| 229 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 230 | #endif // _CCNX_INTEREST_HEADER_H_ |