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) |
| 57 | , m_interestLifetime (-1) |
| 58 | , m_nonce (0) |
| 59 | { |
| 60 | } |
| 61 | |
| 62 | void |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame] | 63 | CcnxInterestHeader::SetName (const Ptr<CcnxNameComponents> &name) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 64 | { |
| 65 | m_name = name; |
| 66 | } |
| 67 | |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame] | 68 | const CcnxNameComponents& |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 69 | CcnxInterestHeader::GetName () const |
| 70 | { |
| 71 | return *m_name; |
| 72 | } |
| 73 | |
| 74 | void |
| 75 | CcnxInterestHeader::SetMinSuffixComponents (int32_t value) |
| 76 | { |
| 77 | m_minSuffixComponents = value; |
| 78 | } |
| 79 | |
| 80 | int32_t |
| 81 | CcnxInterestHeader::GetMinSuffixComponents () const |
| 82 | { |
| 83 | return m_minSuffixComponents; |
| 84 | } |
| 85 | |
| 86 | void |
| 87 | CcnxInterestHeader::SetMaxSuffixComponents (int32_t value) |
| 88 | { |
| 89 | m_maxSuffixComponents = value; |
| 90 | } |
| 91 | |
| 92 | int32_t |
| 93 | CcnxInterestHeader::GetMaxSuffixComponents () const |
| 94 | { |
| 95 | return m_maxSuffixComponents; |
| 96 | } |
| 97 | |
| 98 | void |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame] | 99 | CcnxInterestHeader::SetExclude (const Ptr<CcnxNameComponents> &exclude) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 100 | { |
| 101 | m_exclude = exclude; |
| 102 | } |
| 103 | |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame] | 104 | const CcnxNameComponents& |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 105 | CcnxInterestHeader::GetExclude () const |
| 106 | { |
| 107 | return *m_exclude; |
| 108 | } |
| 109 | |
| 110 | void |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 111 | CcnxInterestHeader::SetChildSelector (bool value) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 112 | { |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 113 | m_childSelector = value; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | bool |
| 117 | CcnxInterestHeader::IsEnabledChildSelector () const |
| 118 | { |
| 119 | return m_childSelector; |
| 120 | } |
| 121 | |
| 122 | void |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 123 | CcnxInterestHeader::SetAnswerOriginKind (bool value) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 124 | { |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 125 | m_answerOriginKind = value; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | bool |
| 129 | CcnxInterestHeader::IsEnabledAnswerOriginKind () const |
| 130 | { |
| 131 | return m_answerOriginKind; |
| 132 | } |
| 133 | |
| 134 | void |
| 135 | CcnxInterestHeader::SetScope (int8_t scope) |
| 136 | { |
| 137 | m_scope = scope; |
| 138 | } |
| 139 | |
| 140 | int8_t |
| 141 | CcnxInterestHeader::GetScope () const |
| 142 | { |
| 143 | return m_scope; |
| 144 | } |
| 145 | |
| 146 | void |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 147 | CcnxInterestHeader::SetInterestLifetime (Time lifetime) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 148 | { |
| 149 | m_interestLifetime = lifetime; |
| 150 | } |
| 151 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 152 | Time |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 153 | CcnxInterestHeader::GetInterestLifetime () const |
| 154 | { |
| 155 | return m_interestLifetime; |
| 156 | } |
| 157 | |
| 158 | void |
| 159 | CcnxInterestHeader::SetNonce (uint32_t nonce) |
| 160 | { |
| 161 | m_nonce = nonce; |
| 162 | } |
| 163 | |
| 164 | uint32_t |
| 165 | CcnxInterestHeader::GetNonce () const |
| 166 | { |
| 167 | return m_nonce; |
| 168 | } |
| 169 | |
| 170 | uint32_t |
| 171 | CcnxInterestHeader::GetSerializedSize (void) const |
| 172 | { |
Alexander Afanasyev | 2a5df20 | 2011-08-15 22:39:05 -0700 | [diff] [blame] | 173 | // unfortunately, 2 serialization required... |
Alexander Afanasyev | ae0d652 | 2011-08-30 13:29:55 -0700 | [diff] [blame] | 174 | /// \todo This is totally wrong. Need to do some simple packet buffer estimation |
| 175 | Buffer tmp(2048); |
Alexander Afanasyev | 2a5df20 | 2011-08-15 22:39:05 -0700 | [diff] [blame] | 176 | |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 177 | return CcnxEncodingHelper::Serialize (tmp.Begin(), *this); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | void |
| 181 | CcnxInterestHeader::Serialize (Buffer::Iterator start) const |
| 182 | { |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 183 | CcnxEncodingHelper::Serialize (start, *this); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | uint32_t |
| 187 | CcnxInterestHeader::Deserialize (Buffer::Iterator start) |
| 188 | { |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 189 | return CcnxDecodingHelper::Deserialize (start, *this); // \todo Debugging is necessary |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | TypeId |
| 193 | CcnxInterestHeader::GetInstanceTypeId (void) const |
| 194 | { |
| 195 | return GetTypeId (); |
| 196 | } |
| 197 | |
| 198 | void |
| 199 | CcnxInterestHeader::Print (std::ostream &os) const |
| 200 | { |
Alexander Afanasyev | 2a5df20 | 2011-08-15 22:39:05 -0700 | [diff] [blame] | 201 | os << "<Interest><Name>" << *m_name << "</Name>"; |
| 202 | if (m_minSuffixComponents>=0) |
| 203 | os << "<MinSuffixComponents>" << m_minSuffixComponents << "</MinSuffixComponents>"; |
| 204 | if (m_maxSuffixComponents>=0) |
| 205 | os << "<MaxSuffixComponents>" << m_maxSuffixComponents << "</MaxSuffixComponents>"; |
| 206 | if (m_exclude->size()>0) |
| 207 | os << "<Exclude>" << *m_exclude << "</Exclude>"; |
| 208 | if (m_childSelector) |
| 209 | os << "<ChildSelector />"; |
| 210 | if (m_answerOriginKind) |
| 211 | os << "<AnswerOriginKind />"; |
| 212 | if (m_scope>=0) |
| 213 | os << "<Scope>" << m_scope << "</Scope>"; |
| 214 | if (!m_interestLifetime.IsZero()) |
| 215 | os << "<InterestLifetime>" << m_interestLifetime << "</InterestLifetime>"; |
| 216 | if (m_nonce>0) |
| 217 | os << "<Nonce>" << m_nonce << "</Nonce>"; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | } |