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