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 | 08d984e | 2011-08-13 19:20:22 -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 | |
| 22 | ///< #CCN_PR_SCOPE0 (0x20) local scope, |
| 23 | ///< #CCN_PR_SCOPE1 (0x40) this host, |
| 24 | ///< #CCN_PR_SCOPE2 (0x80) immediate neighborhood |
| 25 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 26 | #include "ndn-interest-header.h" |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 27 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 28 | #include "ns3/log.h" |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 29 | #include "ns3/unused.h" |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 30 | #include "../helper/ndn-encoding-helper.h" |
| 31 | #include "../helper/ndn-decoding-helper.h" |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 32 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 33 | NS_LOG_COMPONENT_DEFINE ("ndn.InterestHeader"); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 34 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 35 | namespace ns3 { |
| 36 | namespace ndn { |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 37 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 38 | NS_OBJECT_ENSURE_REGISTERED (InterestHeader); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 39 | |
| 40 | TypeId |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 41 | InterestHeader::GetTypeId (void) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 42 | { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 43 | static TypeId tid = TypeId ("ns3::ndn::InterestHeader") |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 44 | .SetGroupName ("Ndn") |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 45 | .SetParent<Header> () |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 46 | .AddConstructor<InterestHeader> () |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 47 | ; |
| 48 | return tid; |
| 49 | } |
| 50 | |
| 51 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 52 | InterestHeader::InterestHeader () |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 53 | : m_minSuffixComponents (-1) |
| 54 | , m_maxSuffixComponents (-1) |
| 55 | , m_childSelector (false) |
| 56 | , m_answerOriginKind (false) |
| 57 | , m_scope (-1) |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 58 | , m_interestLifetime (Seconds (0)) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 59 | , m_nonce (0) |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 60 | , m_nackType (NORMAL_INTEREST) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 61 | { |
| 62 | } |
| 63 | |
| 64 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 65 | InterestHeader::SetName (const Ptr<NameComponents> &name) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 66 | { |
| 67 | m_name = name; |
| 68 | } |
| 69 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 70 | const NameComponents& |
| 71 | InterestHeader::GetName () const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 72 | { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 73 | if (m_name==0) throw InterestHeaderException(); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 74 | return *m_name; |
| 75 | } |
| 76 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 77 | Ptr<const NameComponents> |
| 78 | InterestHeader::GetNamePtr () const |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 79 | { |
| 80 | return m_name; |
| 81 | } |
| 82 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 83 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 84 | InterestHeader::SetMinSuffixComponents (int32_t value) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 85 | { |
| 86 | m_minSuffixComponents = value; |
| 87 | } |
| 88 | |
| 89 | int32_t |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 90 | InterestHeader::GetMinSuffixComponents () const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 91 | { |
| 92 | return m_minSuffixComponents; |
| 93 | } |
| 94 | |
| 95 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 96 | InterestHeader::SetMaxSuffixComponents (int32_t value) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 97 | { |
| 98 | m_maxSuffixComponents = value; |
| 99 | } |
| 100 | |
| 101 | int32_t |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 102 | InterestHeader::GetMaxSuffixComponents () const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 103 | { |
| 104 | return m_maxSuffixComponents; |
| 105 | } |
| 106 | |
| 107 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 108 | InterestHeader::SetExclude (const Ptr<NameComponents> &exclude) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 109 | { |
| 110 | m_exclude = exclude; |
| 111 | } |
| 112 | |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 113 | bool |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 114 | InterestHeader::IsEnabledExclude () const |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 115 | { |
| 116 | return m_exclude!=0; |
| 117 | } |
| 118 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 119 | const NameComponents& |
| 120 | InterestHeader::GetExclude () const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 121 | { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 122 | if (m_exclude==0) throw InterestHeaderException(); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 123 | return *m_exclude; |
| 124 | } |
| 125 | |
| 126 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 127 | InterestHeader::SetChildSelector (bool value) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 128 | { |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 129 | m_childSelector = value; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | bool |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 133 | InterestHeader::IsEnabledChildSelector () const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 134 | { |
| 135 | return m_childSelector; |
| 136 | } |
| 137 | |
| 138 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 139 | InterestHeader::SetAnswerOriginKind (bool value) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 140 | { |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 141 | m_answerOriginKind = value; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | bool |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 145 | InterestHeader::IsEnabledAnswerOriginKind () const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 146 | { |
| 147 | return m_answerOriginKind; |
| 148 | } |
| 149 | |
| 150 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 151 | InterestHeader::SetScope (int8_t scope) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 152 | { |
| 153 | m_scope = scope; |
| 154 | } |
| 155 | |
| 156 | int8_t |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 157 | InterestHeader::GetScope () const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 158 | { |
| 159 | return m_scope; |
| 160 | } |
| 161 | |
| 162 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 163 | InterestHeader::SetInterestLifetime (Time lifetime) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 164 | { |
| 165 | m_interestLifetime = lifetime; |
| 166 | } |
| 167 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 168 | Time |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 169 | InterestHeader::GetInterestLifetime () const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 170 | { |
| 171 | return m_interestLifetime; |
| 172 | } |
| 173 | |
| 174 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 175 | InterestHeader::SetNonce (uint32_t nonce) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 176 | { |
| 177 | m_nonce = nonce; |
| 178 | } |
| 179 | |
| 180 | uint32_t |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 181 | InterestHeader::GetNonce () const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 182 | { |
| 183 | return m_nonce; |
| 184 | } |
Ilya Moiseenko | 75d9bf5 | 2011-10-28 13:18:32 -0700 | [diff] [blame] | 185 | |
| 186 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 187 | InterestHeader::SetNack (uint32_t nackType) |
Ilya Moiseenko | 75d9bf5 | 2011-10-28 13:18:32 -0700 | [diff] [blame] | 188 | { |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 189 | m_nackType = nackType; |
Ilya Moiseenko | 75d9bf5 | 2011-10-28 13:18:32 -0700 | [diff] [blame] | 190 | } |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 191 | |
| 192 | uint32_t |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 193 | InterestHeader::GetNack () const |
Ilya Moiseenko | 75d9bf5 | 2011-10-28 13:18:32 -0700 | [diff] [blame] | 194 | { |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 195 | return m_nackType; |
Ilya Moiseenko | 75d9bf5 | 2011-10-28 13:18:32 -0700 | [diff] [blame] | 196 | } |
Ilya Moiseenko | 75d9bf5 | 2011-10-28 13:18:32 -0700 | [diff] [blame] | 197 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 198 | uint32_t |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 199 | InterestHeader::GetSerializedSize (void) const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 200 | { |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 201 | // unfortunately, we don't know exact header size in advance |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 202 | return EncodingHelper::GetSerializedSize (*this); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 206 | InterestHeader::Serialize (Buffer::Iterator start) const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 207 | { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 208 | size_t size = EncodingHelper::Serialize (start, *this); |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 209 | NS_UNUSED (size); |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 210 | NS_LOG_INFO ("Serialize size = " << size); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | uint32_t |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 214 | InterestHeader::Deserialize (Buffer::Iterator start) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 215 | { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 216 | return DecodingHelper::Deserialize (start, *this); // \todo Debugging is necessary |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | TypeId |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 220 | InterestHeader::GetInstanceTypeId (void) const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 221 | { |
| 222 | return GetTypeId (); |
| 223 | } |
| 224 | |
| 225 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 226 | InterestHeader::Print (std::ostream &os) const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 227 | { |
Alexander Afanasyev | 7f3e49e | 2012-04-30 00:17:07 -0700 | [diff] [blame] | 228 | os << "I: " << GetName (); |
| 229 | |
| 230 | return; |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 231 | os << "<Interest>\n <Name>" << GetName () << "</Name>\n"; |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 232 | if (GetNack ()>0) |
| 233 | { |
| 234 | os << " <NACK>"; |
| 235 | switch (GetNack ()) |
| 236 | { |
| 237 | case NACK_LOOP: |
| 238 | os << "loop"; |
| 239 | break; |
| 240 | case NACK_CONGESTION: |
| 241 | os << "congestion"; |
| 242 | break; |
| 243 | default: |
| 244 | os << "unknown"; |
| 245 | break; |
| 246 | } |
| 247 | os << "</NACK>\n"; |
| 248 | } |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 249 | if (GetMinSuffixComponents () >= 0) |
| 250 | os << " <MinSuffixComponents>" << GetMinSuffixComponents () << "</MinSuffixComponents>\n"; |
| 251 | if (GetMaxSuffixComponents () >= 0) |
| 252 | os << " <MaxSuffixComponents>" << m_maxSuffixComponents << "</MaxSuffixComponents>\n"; |
| 253 | if (IsEnabledExclude () && GetExclude ().size()>0) |
| 254 | os << " <Exclude>" << GetExclude () << "</Exclude>\n"; |
| 255 | if (IsEnabledChildSelector ()) |
| 256 | os << " <ChildSelector />\n"; |
| 257 | if (IsEnabledAnswerOriginKind ()) |
| 258 | os << " <AnswerOriginKind />\n"; |
| 259 | if (GetScope () >= 0) |
| 260 | os << " <Scope>" << GetScope () << "</Scope>\n"; |
| 261 | if ( !GetInterestLifetime ().IsZero() ) |
| 262 | os << " <InterestLifetime>" << GetInterestLifetime () << "</InterestLifetime>\n"; |
| 263 | if (GetNonce ()>0) |
| 264 | os << " <Nonce>" << GetNonce () << "</Nonce>\n"; |
| 265 | os << "</Interest>"; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 268 | } // namespace ndn |
| 269 | } // namespace ns3 |
| 270 | |