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 | 2a5df20 | 2011-08-15 22:39:05 -0700 | [diff] [blame^] | 29 | #include "ns3/ccnx-coding-helper.h" |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 30 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 31 | NS_LOG_COMPONENT_DEFINE ("CcnxInterestHeader"); |
| 32 | |
| 33 | namespace ns3 |
| 34 | { |
| 35 | |
| 36 | NS_OBJECT_ENSURE_REGISTERED (CcnxInterestHeader); |
| 37 | |
| 38 | TypeId |
| 39 | CcnxInterestHeader::GetTypeId (void) |
| 40 | { |
| 41 | static TypeId tid = TypeId ("ns3::CcnxInterestHeader") |
| 42 | .SetParent<Header> () |
| 43 | .AddConstructor<CcnxInterestHeader> () |
| 44 | ; |
| 45 | return tid; |
| 46 | } |
| 47 | |
| 48 | |
| 49 | CcnxInterestHeader::CcnxInterestHeader () |
| 50 | : m_minSuffixComponents (-1) |
| 51 | , m_maxSuffixComponents (-1) |
| 52 | , m_childSelector (false) |
| 53 | , m_answerOriginKind (false) |
| 54 | , m_scope (-1) |
| 55 | , m_interestLifetime (-1) |
| 56 | , m_nonce (0) |
| 57 | { |
| 58 | } |
| 59 | |
| 60 | void |
| 61 | CcnxInterestHeader::SetName (const Ptr<Name::Components> &name) |
| 62 | { |
| 63 | m_name = name; |
| 64 | } |
| 65 | |
| 66 | const Name::Components& |
| 67 | CcnxInterestHeader::GetName () const |
| 68 | { |
| 69 | return *m_name; |
| 70 | } |
| 71 | |
| 72 | void |
| 73 | CcnxInterestHeader::SetMinSuffixComponents (int32_t value) |
| 74 | { |
| 75 | m_minSuffixComponents = value; |
| 76 | } |
| 77 | |
| 78 | int32_t |
| 79 | CcnxInterestHeader::GetMinSuffixComponents () const |
| 80 | { |
| 81 | return m_minSuffixComponents; |
| 82 | } |
| 83 | |
| 84 | void |
| 85 | CcnxInterestHeader::SetMaxSuffixComponents (int32_t value) |
| 86 | { |
| 87 | m_maxSuffixComponents = value; |
| 88 | } |
| 89 | |
| 90 | int32_t |
| 91 | CcnxInterestHeader::GetMaxSuffixComponents () const |
| 92 | { |
| 93 | return m_maxSuffixComponents; |
| 94 | } |
| 95 | |
| 96 | void |
| 97 | CcnxInterestHeader::SetExclude (const Ptr<Name::Components> &exclude) |
| 98 | { |
| 99 | m_exclude = exclude; |
| 100 | } |
| 101 | |
| 102 | const Name::Components& |
| 103 | CcnxInterestHeader::GetExclude () const |
| 104 | { |
| 105 | return *m_exclude; |
| 106 | } |
| 107 | |
| 108 | void |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 109 | CcnxInterestHeader::SetChildSelector (bool value) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 110 | { |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 111 | m_childSelector = value; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | bool |
| 115 | CcnxInterestHeader::IsEnabledChildSelector () const |
| 116 | { |
| 117 | return m_childSelector; |
| 118 | } |
| 119 | |
| 120 | void |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 121 | CcnxInterestHeader::SetAnswerOriginKind (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_answerOriginKind = value; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | bool |
| 127 | CcnxInterestHeader::IsEnabledAnswerOriginKind () const |
| 128 | { |
| 129 | return m_answerOriginKind; |
| 130 | } |
| 131 | |
| 132 | void |
| 133 | CcnxInterestHeader::SetScope (int8_t scope) |
| 134 | { |
| 135 | m_scope = scope; |
| 136 | } |
| 137 | |
| 138 | int8_t |
| 139 | CcnxInterestHeader::GetScope () const |
| 140 | { |
| 141 | return m_scope; |
| 142 | } |
| 143 | |
| 144 | void |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 145 | CcnxInterestHeader::SetInterestLifetime (Time lifetime) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 146 | { |
| 147 | m_interestLifetime = lifetime; |
| 148 | } |
| 149 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 150 | Time |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 151 | CcnxInterestHeader::GetInterestLifetime () const |
| 152 | { |
| 153 | return m_interestLifetime; |
| 154 | } |
| 155 | |
| 156 | void |
| 157 | CcnxInterestHeader::SetNonce (uint32_t nonce) |
| 158 | { |
| 159 | m_nonce = nonce; |
| 160 | } |
| 161 | |
| 162 | uint32_t |
| 163 | CcnxInterestHeader::GetNonce () const |
| 164 | { |
| 165 | return m_nonce; |
| 166 | } |
| 167 | |
| 168 | uint32_t |
| 169 | CcnxInterestHeader::GetSerializedSize (void) const |
| 170 | { |
Alexander Afanasyev | 2a5df20 | 2011-08-15 22:39:05 -0700 | [diff] [blame^] | 171 | // unfortunately, 2 serialization required... |
| 172 | Buffer tmp; |
| 173 | |
| 174 | return CcnxCodingHelper::Serialize (tmp.Begin(), *this); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | void |
| 178 | CcnxInterestHeader::Serialize (Buffer::Iterator start) const |
| 179 | { |
Alexander Afanasyev | 2a5df20 | 2011-08-15 22:39:05 -0700 | [diff] [blame^] | 180 | CcnxCodingHelper::Serialize (start, *this); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | uint32_t |
| 184 | CcnxInterestHeader::Deserialize (Buffer::Iterator start) |
| 185 | { |
Alexander Afanasyev | 2a5df20 | 2011-08-15 22:39:05 -0700 | [diff] [blame^] | 186 | return 0; // the most complicated part is here |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | TypeId |
| 190 | CcnxInterestHeader::GetInstanceTypeId (void) const |
| 191 | { |
| 192 | return GetTypeId (); |
| 193 | } |
| 194 | |
| 195 | void |
| 196 | CcnxInterestHeader::Print (std::ostream &os) const |
| 197 | { |
Alexander Afanasyev | 2a5df20 | 2011-08-15 22:39:05 -0700 | [diff] [blame^] | 198 | os << "<Interest><Name>" << *m_name << "</Name>"; |
| 199 | if (m_minSuffixComponents>=0) |
| 200 | os << "<MinSuffixComponents>" << m_minSuffixComponents << "</MinSuffixComponents>"; |
| 201 | if (m_maxSuffixComponents>=0) |
| 202 | os << "<MaxSuffixComponents>" << m_maxSuffixComponents << "</MaxSuffixComponents>"; |
| 203 | if (m_exclude->size()>0) |
| 204 | os << "<Exclude>" << *m_exclude << "</Exclude>"; |
| 205 | if (m_childSelector) |
| 206 | os << "<ChildSelector />"; |
| 207 | if (m_answerOriginKind) |
| 208 | os << "<AnswerOriginKind />"; |
| 209 | if (m_scope>=0) |
| 210 | os << "<Scope>" << m_scope << "</Scope>"; |
| 211 | if (!m_interestLifetime.IsZero()) |
| 212 | os << "<InterestLifetime>" << m_interestLifetime << "</InterestLifetime>"; |
| 213 | if (m_nonce>0) |
| 214 | os << "<Nonce>" << m_nonce << "</Nonce>"; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | } |