Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 2 | /** |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame] | 3 | * Copyright (c) 2013-2015 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #ifndef NDN_MANAGEMENT_NFD_LOCAL_CONTROL_HEADER_HPP |
| 23 | #define NDN_MANAGEMENT_NFD_LOCAL_CONTROL_HEADER_HPP |
| 24 | |
| 25 | #include "../encoding/encoding-buffer.hpp" |
| 26 | #include "../encoding/tlv-nfd.hpp" |
Alexander Afanasyev | 01065fb | 2014-10-02 13:01:46 -0700 | [diff] [blame] | 27 | #include "../encoding/block-helpers.hpp" |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 28 | |
| 29 | namespace ndn { |
| 30 | namespace nfd { |
| 31 | |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 32 | /** |
| 33 | * @ingroup management |
| 34 | * @brief Class to handle work with LocalControlHeader |
| 35 | * @sa http://redmine.named-data.net/projects/nfd/wiki/LocalControlHeader |
| 36 | */ |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 37 | class LocalControlHeader |
| 38 | { |
| 39 | public: |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 40 | class Error : public std::runtime_error |
| 41 | { |
| 42 | public: |
| 43 | explicit |
| 44 | Error(const std::string& what) |
| 45 | : std::runtime_error(what) |
| 46 | { |
| 47 | } |
| 48 | }; |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 49 | |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 50 | enum EncodeFlags : uint8_t { |
| 51 | ENCODE_NONE = 0, |
| 52 | ENCODE_INCOMING_FACE_ID = (1 << 0), |
| 53 | ENCODE_NEXT_HOP = (1 << 1), |
| 54 | ENCODE_CACHING_POLICY = (1 << 2), |
| 55 | ENCODE_ALL = 0xff |
| 56 | }; |
| 57 | |
| 58 | enum CachingPolicy : uint8_t { |
| 59 | INVALID_POLICY = 0, |
| 60 | NO_CACHE = 1 |
| 61 | }; |
| 62 | |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 63 | LocalControlHeader() |
| 64 | : m_incomingFaceId(INVALID_FACE_ID) |
| 65 | , m_nextHopFaceId(INVALID_FACE_ID) |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 66 | , m_cachingPolicy(CachingPolicy::INVALID_POLICY) |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 67 | { |
| 68 | } |
| 69 | |
| 70 | /** |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 71 | * @brief Create from wire encoding |
| 72 | * |
| 73 | * @sa wireDecode |
| 74 | */ |
| 75 | explicit |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 76 | LocalControlHeader(const Block& wire, uint8_t encodeMask = ENCODE_ALL) |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 77 | { |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 78 | wireDecode(wire, encodeMask); |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | /** |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 82 | * @brief Create wire encoding with options LocalControlHeader and the supplied item |
| 83 | * |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 84 | * The caller is responsible of checking whether LocalControlHeader contains |
| 85 | * any information. |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 86 | * |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 87 | * !It is an error to call this method if none of IncomingFaceId, NextHopFaceId and CachingPolicy |
| 88 | * are set, or neither of them are enabled. |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 89 | * |
| 90 | * @throws LocalControlHeader::Error when empty LocalControlHeader be produced |
| 91 | * |
| 92 | * @returns Block, containing LocalControlHeader. Top-level length field of the |
| 93 | * returned LocalControlHeader includes payload length, but the memory |
| 94 | * block is independent of the payload's wire buffer. It is expected |
| 95 | * that both LocalControlHeader's and payload's wire will be send out |
| 96 | * together within a single send call. |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 97 | * |
| 98 | * @see http://redmine.named-data.net/projects/nfd/wiki/LocalControlHeader |
| 99 | */ |
| 100 | template<class U> |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 101 | inline Block |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 102 | wireEncode(const U& payload, uint8_t encodeMask = ENCODE_ALL) const; |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 103 | |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 104 | /** |
| 105 | * @brief Decode from the wire format and set LocalControlHeader on the supplied item |
| 106 | * |
| 107 | * The supplied wire MUST contain LocalControlHeader. Determination whether the optional |
| 108 | * LocalControlHeader should be done before calling this method. |
| 109 | */ |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 110 | inline void |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 111 | wireDecode(const Block& wire, uint8_t encodeMask = ENCODE_ALL); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 112 | |
| 113 | inline static const Block& |
| 114 | getPayload(const Block& wire); |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 115 | |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 116 | /////////////////////////////////////////////////////////////////////////////// |
| 117 | /////////////////////////////////////////////////////////////////////////////// |
| 118 | /////////////////////////////////////////////////////////////////////////////// |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 119 | // Getters/setters |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 120 | |
| 121 | bool |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 122 | empty(uint8_t encodeMask) const |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 123 | { |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 124 | bool needIncomingFaceId = encodeMask & ENCODE_INCOMING_FACE_ID; |
| 125 | bool needNextHopFaceId = encodeMask & ENCODE_NEXT_HOP; |
| 126 | bool needCachingPolicy = encodeMask & ENCODE_CACHING_POLICY; |
| 127 | |
| 128 | return !((needIncomingFaceId && hasIncomingFaceId()) || |
| 129 | (needNextHopFaceId && hasNextHopFaceId()) || |
| 130 | (needCachingPolicy && hasCachingPolicy())); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 131 | } |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 132 | |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 133 | // |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 134 | |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 135 | bool |
| 136 | hasIncomingFaceId() const |
| 137 | { |
| 138 | return m_incomingFaceId != INVALID_FACE_ID; |
| 139 | } |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 140 | |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 141 | uint64_t |
| 142 | getIncomingFaceId() const |
| 143 | { |
| 144 | return m_incomingFaceId; |
| 145 | } |
| 146 | |
| 147 | void |
| 148 | setIncomingFaceId(uint64_t incomingFaceId) |
| 149 | { |
| 150 | m_incomingFaceId = incomingFaceId; |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | // |
| 154 | |
| 155 | bool |
| 156 | hasNextHopFaceId() const |
| 157 | { |
| 158 | return m_nextHopFaceId != INVALID_FACE_ID; |
| 159 | } |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 160 | |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 161 | uint64_t |
| 162 | getNextHopFaceId() const |
| 163 | { |
| 164 | return m_nextHopFaceId; |
| 165 | } |
| 166 | |
| 167 | void |
| 168 | setNextHopFaceId(uint64_t nextHopFaceId) |
| 169 | { |
| 170 | m_nextHopFaceId = nextHopFaceId; |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 171 | } |
| 172 | |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 173 | // |
| 174 | |
| 175 | bool |
| 176 | hasCachingPolicy() const |
| 177 | { |
| 178 | return m_cachingPolicy != CachingPolicy::INVALID_POLICY; |
| 179 | } |
| 180 | |
| 181 | CachingPolicy |
| 182 | getCachingPolicy() const |
| 183 | { |
| 184 | return m_cachingPolicy; |
| 185 | } |
| 186 | |
| 187 | void |
| 188 | setCachingPolicy(CachingPolicy cachingPolicy) |
| 189 | { |
| 190 | m_cachingPolicy = cachingPolicy; |
| 191 | } |
| 192 | |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 193 | private: |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame] | 194 | template<encoding::Tag TAG> |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 195 | inline size_t |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 196 | wireEncode(EncodingImpl<TAG>& block, size_t payloadSize, uint8_t encodeMask) const; |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 197 | |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 198 | private: |
| 199 | uint64_t m_incomingFaceId; |
| 200 | uint64_t m_nextHopFaceId; |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 201 | CachingPolicy m_cachingPolicy; |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 202 | }; |
| 203 | |
| 204 | |
| 205 | /** |
| 206 | * @brief Fast encoding or block size estimation |
| 207 | */ |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame] | 208 | template<encoding::Tag TAG> |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 209 | inline size_t |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame] | 210 | LocalControlHeader::wireEncode(EncodingImpl<TAG>& block, size_t payloadSize, |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 211 | uint8_t encodeMask) const |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 212 | { |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 213 | bool needIncomingFaceId = encodeMask & ENCODE_INCOMING_FACE_ID; |
| 214 | bool needNextHopFaceId = encodeMask & ENCODE_NEXT_HOP; |
| 215 | bool needCachingPolicy = encodeMask & ENCODE_CACHING_POLICY; |
| 216 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 217 | size_t totalLength = payloadSize; |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 218 | |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 219 | if (needIncomingFaceId && hasIncomingFaceId()) |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 220 | { |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 221 | totalLength += prependNonNegativeIntegerBlock(block, |
| 222 | tlv::nfd::IncomingFaceId, getIncomingFaceId()); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 223 | } |
| 224 | |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 225 | if (needNextHopFaceId && hasNextHopFaceId()) |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 226 | { |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 227 | totalLength += prependNonNegativeIntegerBlock(block, |
| 228 | tlv::nfd::NextHopFaceId, getNextHopFaceId()); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 229 | } |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 230 | |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 231 | if (needCachingPolicy && hasCachingPolicy()) |
| 232 | { |
| 233 | size_t cachingPolicyLength = 0; |
| 234 | cachingPolicyLength += block.prependVarNumber(0); |
| 235 | cachingPolicyLength += block.prependVarNumber(tlv::nfd::NoCache); |
| 236 | cachingPolicyLength += block.prependVarNumber(cachingPolicyLength); |
| 237 | cachingPolicyLength += block.prependVarNumber(tlv::nfd::CachingPolicy); |
| 238 | |
| 239 | totalLength += cachingPolicyLength; |
| 240 | } |
| 241 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 242 | totalLength += block.prependVarNumber(totalLength); |
| 243 | totalLength += block.prependVarNumber(tlv::nfd::LocalControlHeader); |
| 244 | return totalLength; |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | template<class U> |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 248 | inline Block |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 249 | LocalControlHeader::wireEncode(const U& payload, uint8_t encodeMask) const |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 250 | { |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 251 | /// @todo should this be BOOST_ASSERT instead? This is kind of unnecessary overhead |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 252 | if (empty(encodeMask)) |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 253 | throw Error("Requested wire for LocalControlHeader, but none of the fields are set or enabled"); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 254 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 255 | EncodingEstimator estimator; |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 256 | size_t length = wireEncode(estimator, payload.wireEncode().size(), encodeMask); |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 257 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 258 | EncodingBuffer buffer(length); |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 259 | wireEncode(buffer, payload.wireEncode().size(), encodeMask); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 260 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 261 | return buffer.block(false); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 262 | } |
| 263 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 264 | inline void |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 265 | LocalControlHeader::wireDecode(const Block& wire, uint8_t encodeMask) |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 266 | { |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 267 | bool needIncomingFaceId = encodeMask & ENCODE_INCOMING_FACE_ID; |
| 268 | bool needNextHopFaceId = encodeMask & ENCODE_NEXT_HOP; |
| 269 | bool needCachingPolicy = encodeMask & ENCODE_CACHING_POLICY; |
| 270 | |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 271 | BOOST_ASSERT(wire.type() == tlv::nfd::LocalControlHeader); |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 272 | wire.parse(); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 273 | |
| 274 | m_incomingFaceId = INVALID_FACE_ID; |
| 275 | m_nextHopFaceId = INVALID_FACE_ID; |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 276 | m_cachingPolicy = CachingPolicy::INVALID_POLICY; |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 277 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 278 | for (Block::element_const_iterator i = wire.elements_begin(); |
| 279 | i != wire.elements_end(); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 280 | ++i) |
| 281 | { |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 282 | switch (i->type()) |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 283 | { |
| 284 | case tlv::nfd::IncomingFaceId: |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 285 | if (needIncomingFaceId) |
Alexander Afanasyev | 37bb190 | 2014-02-19 23:57:23 -0800 | [diff] [blame] | 286 | m_incomingFaceId = readNonNegativeInteger(*i); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 287 | break; |
| 288 | case tlv::nfd::NextHopFaceId: |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 289 | if (needNextHopFaceId) |
Alexander Afanasyev | 37bb190 | 2014-02-19 23:57:23 -0800 | [diff] [blame] | 290 | m_nextHopFaceId = readNonNegativeInteger(*i); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 291 | break; |
Jiewen Tan | c759a20 | 2015-01-29 23:31:09 -0800 | [diff] [blame] | 292 | case tlv::nfd::CachingPolicy: |
| 293 | if (needCachingPolicy) { |
| 294 | i->parse(); |
| 295 | Block::element_const_iterator it = i->elements_begin(); |
| 296 | if (it != i->elements_end() && it->type() == tlv::nfd::NoCache) { |
| 297 | m_cachingPolicy = CachingPolicy::NO_CACHE; |
| 298 | } |
| 299 | else { |
| 300 | throw Error("CachingPolicy: Missing required NoCache field"); |
| 301 | } |
| 302 | } |
| 303 | break; |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 304 | default: |
| 305 | // ignore all unsupported |
| 306 | break; |
| 307 | } |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | inline const Block& |
| 312 | LocalControlHeader::getPayload(const Block& wire) |
| 313 | { |
| 314 | if (wire.type() == tlv::nfd::LocalControlHeader) |
| 315 | { |
| 316 | wire.parse(); |
| 317 | if (wire.elements_size() < 1) |
| 318 | return wire; // don't throw an error, but don't continue processing |
| 319 | |
| 320 | return wire.elements()[wire.elements().size()-1]; |
| 321 | } |
| 322 | else |
| 323 | { |
| 324 | return wire; |
| 325 | } |
| 326 | } |
| 327 | |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 328 | } // namespace nfd |
| 329 | } // namespace ndn |
| 330 | |
| 331 | #endif // NDN_MANAGEMENT_NFD_LOCAL_CONTROL_HEADER_HPP |