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