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) |
Ilya Moiseenko | 75d9bf5 | 2011-10-28 13:18:32 -0700 | [diff] [blame] | 59 | , m_nack (false) |
| 60 | , m_congested (false) |
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 |
| 181 | CcnxInterestHeader::SetNack (bool isNack) |
| 182 | { |
| 183 | m_nack = isNack; |
| 184 | } |
| 185 | |
| 186 | bool |
| 187 | CcnxInterestHeader::IsNack () const |
| 188 | { |
| 189 | return m_nack; |
| 190 | } |
| 191 | |
| 192 | void |
| 193 | CcnxInterestHeader::SetCongested (bool IsCongested) |
| 194 | { |
| 195 | m_congested = IsCongested; |
| 196 | } |
| 197 | |
| 198 | bool |
| 199 | CcnxInterestHeader::IsCongested () const |
| 200 | { |
| 201 | return m_congested; |
| 202 | } |
| 203 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 204 | uint32_t |
| 205 | CcnxInterestHeader::GetSerializedSize (void) const |
| 206 | { |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 207 | // unfortunately, we don't know exact header size in advance |
| 208 | return CcnxEncodingHelper::GetSerializedSize (*this); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | void |
| 212 | CcnxInterestHeader::Serialize (Buffer::Iterator start) const |
| 213 | { |
Alexander Afanasyev | 3b8c50c | 2011-11-15 23:49:55 -0800 | [diff] [blame] | 214 | size_t size __attribute__ ((__unused__)) = CcnxEncodingHelper::Serialize (start, *this); |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 215 | |
| 216 | NS_LOG_INFO ("Serialize size = " << size); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | uint32_t |
| 220 | CcnxInterestHeader::Deserialize (Buffer::Iterator start) |
| 221 | { |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 222 | return CcnxDecodingHelper::Deserialize (start, *this); // \todo Debugging is necessary |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | TypeId |
| 226 | CcnxInterestHeader::GetInstanceTypeId (void) const |
| 227 | { |
| 228 | return GetTypeId (); |
| 229 | } |
| 230 | |
| 231 | void |
| 232 | CcnxInterestHeader::Print (std::ostream &os) const |
| 233 | { |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 234 | os << "<Interest>\n <Name>" << GetName () << "</Name>\n"; |
Ilya Moiseenko | 75d9bf5 | 2011-10-28 13:18:32 -0700 | [diff] [blame] | 235 | if (IsNack ()) |
| 236 | os << " <NACK />\n"; |
Ilya Moiseenko | 19dbcf3 | 2011-11-16 14:32:14 -0800 | [diff] [blame^] | 237 | if(IsCongested()) |
| 238 | os << " <CONGESTED />\n"; |
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 | } |