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 | |
| 33 | #include "name-components.h" |
| 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 | c74a602 | 2011-08-15 20:01:35 -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 | * |
| 141 | * Sets name of the interest. For example, SetName( Name::Components("prefix")("postfix") ); |
| 142 | **/ |
| 143 | void |
| 144 | SetName (const Ptr<Name::Components> &name); |
| 145 | |
| 146 | const Name::Components& |
| 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 | * |
| 164 | * For example, SetExclude (Name::Components("exclude1")("exclude2")("exclude3")) |
| 165 | **/ |
| 166 | void |
| 167 | SetExclude (const Ptr<Name::Components> &exclude); |
| 168 | |
| 169 | const Name::Components& |
| 170 | GetExclude () const; |
| 171 | |
| 172 | void |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 173 | SetChildSelector (bool value); |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 174 | |
| 175 | bool |
| 176 | IsEnabledChildSelector () const; |
| 177 | |
| 178 | void |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 179 | SetAnswerOriginKind (bool value); |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 180 | |
| 181 | bool |
| 182 | IsEnabledAnswerOriginKind () const; |
| 183 | |
| 184 | void |
| 185 | SetScope (int8_t scope); |
| 186 | |
| 187 | int8_t |
| 188 | GetScope () const; |
| 189 | |
| 190 | void |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 191 | SetInterestLifetime (Time time); |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 192 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 193 | Time |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 194 | GetInterestLifetime () const; |
| 195 | |
| 196 | void |
| 197 | SetNonce (uint32_t nonce); |
| 198 | |
| 199 | uint32_t |
| 200 | GetNonce () const; |
| 201 | |
| 202 | ////////////////////////////////////////////////////////////////// |
| 203 | |
| 204 | static TypeId GetTypeId (void); |
| 205 | virtual TypeId GetInstanceTypeId (void) const; |
| 206 | virtual void Print (std::ostream &os) const; |
| 207 | virtual uint32_t GetSerializedSize (void) const; |
| 208 | virtual void Serialize (Buffer::Iterator start) const; |
| 209 | virtual uint32_t Deserialize (Buffer::Iterator start); |
| 210 | |
| 211 | private: |
| 212 | Ptr<Name::Components> m_name; |
| 213 | int32_t m_minSuffixComponents; ///< minimum suffix components. not used if negative |
| 214 | int32_t m_maxSuffixComponents; ///< maximum suffix components. not used if negative |
| 215 | Ptr<Name::Components> m_exclude; ///< exclude filter |
| 216 | bool m_childSelector; |
| 217 | bool m_answerOriginKind; |
| 218 | 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] | 219 | Time m_interestLifetime; |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 220 | uint32_t m_nonce; ///< Nonce. not used if zero |
| 221 | }; |
| 222 | |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 223 | } // namespace ns3 |
| 224 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 225 | #endif // _CCNX_INTEREST_HEADER_H_ |