Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame^] | 3 | * Copyright (c) 2013-2017 Regents of the University of California. |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 6 | * |
| 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. |
| 20 | */ |
| 21 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 22 | #include "face-status.hpp" |
Junxiao Shi | 65f1a71 | 2014-11-20 14:59:36 -0700 | [diff] [blame] | 23 | #include "encoding/block-helpers.hpp" |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame^] | 24 | #include "encoding/encoding-buffer.hpp" |
| 25 | #include "encoding/tlv-nfd.hpp" |
Junxiao Shi | 65f1a71 | 2014-11-20 14:59:36 -0700 | [diff] [blame] | 26 | #include "util/concepts.hpp" |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 27 | |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame^] | 28 | #include <iomanip> |
| 29 | |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 30 | namespace ndn { |
| 31 | namespace nfd { |
| 32 | |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame^] | 33 | BOOST_CONCEPT_ASSERT((StatusDatasetItem<FaceStatus>)); |
Junxiao Shi | 65f1a71 | 2014-11-20 14:59:36 -0700 | [diff] [blame] | 34 | |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 35 | FaceStatus::FaceStatus() |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame^] | 36 | : m_nInInterests(0) |
| 37 | , m_nInData(0) |
Eric Newberry | 95bd96a | 2015-09-04 23:34:22 -0700 | [diff] [blame] | 38 | , m_nInNacks(0) |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 39 | , m_nOutInterests(0) |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame^] | 40 | , m_nOutData(0) |
Eric Newberry | 95bd96a | 2015-09-04 23:34:22 -0700 | [diff] [blame] | 41 | , m_nOutNacks(0) |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 42 | , m_nInBytes(0) |
| 43 | , m_nOutBytes(0) |
| 44 | { |
| 45 | } |
| 46 | |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 47 | FaceStatus::FaceStatus(const Block& block) |
| 48 | { |
| 49 | this->wireDecode(block); |
| 50 | } |
| 51 | |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame] | 52 | template<encoding::Tag TAG> |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 53 | size_t |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame] | 54 | FaceStatus::wireEncode(EncodingImpl<TAG>& encoder) const |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 55 | { |
| 56 | size_t totalLength = 0; |
| 57 | |
| 58 | totalLength += prependNonNegativeIntegerBlock(encoder, |
Eric Newberry | 1ce8ab2 | 2016-09-24 11:57:21 -0700 | [diff] [blame] | 59 | tlv::nfd::Flags, m_flags); |
| 60 | totalLength += prependNonNegativeIntegerBlock(encoder, |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 61 | tlv::nfd::NOutBytes, m_nOutBytes); |
| 62 | totalLength += prependNonNegativeIntegerBlock(encoder, |
| 63 | tlv::nfd::NInBytes, m_nInBytes); |
| 64 | totalLength += prependNonNegativeIntegerBlock(encoder, |
Eric Newberry | 95bd96a | 2015-09-04 23:34:22 -0700 | [diff] [blame] | 65 | tlv::nfd::NOutNacks, m_nOutNacks); |
| 66 | totalLength += prependNonNegativeIntegerBlock(encoder, |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame^] | 67 | tlv::nfd::NOutDatas, m_nOutData); |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 68 | totalLength += prependNonNegativeIntegerBlock(encoder, |
| 69 | tlv::nfd::NOutInterests, m_nOutInterests); |
| 70 | totalLength += prependNonNegativeIntegerBlock(encoder, |
Eric Newberry | 95bd96a | 2015-09-04 23:34:22 -0700 | [diff] [blame] | 71 | tlv::nfd::NInNacks, m_nInNacks); |
| 72 | totalLength += prependNonNegativeIntegerBlock(encoder, |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame^] | 73 | tlv::nfd::NInDatas, m_nInData); |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 74 | totalLength += prependNonNegativeIntegerBlock(encoder, |
| 75 | tlv::nfd::NInInterests, m_nInInterests); |
| 76 | totalLength += prependNonNegativeIntegerBlock(encoder, |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 77 | tlv::nfd::LinkType, m_linkType); |
| 78 | totalLength += prependNonNegativeIntegerBlock(encoder, |
| 79 | tlv::nfd::FacePersistency, m_facePersistency); |
| 80 | totalLength += prependNonNegativeIntegerBlock(encoder, |
| 81 | tlv::nfd::FaceScope, m_faceScope); |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame^] | 82 | if (m_expirationPeriod) { |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 83 | totalLength += prependNonNegativeIntegerBlock(encoder, |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame^] | 84 | tlv::nfd::ExpirationPeriod, static_cast<uint64_t>(m_expirationPeriod->count())); |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 85 | } |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame] | 86 | totalLength += encoder.prependByteArrayBlock(tlv::nfd::LocalUri, |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame^] | 87 | reinterpret_cast<const uint8_t*>(m_localUri.data()), m_localUri.size()); |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame] | 88 | totalLength += encoder.prependByteArrayBlock(tlv::nfd::Uri, |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame^] | 89 | reinterpret_cast<const uint8_t*>(m_remoteUri.data()), m_remoteUri.size()); |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 90 | totalLength += prependNonNegativeIntegerBlock(encoder, |
| 91 | tlv::nfd::FaceId, m_faceId); |
| 92 | |
| 93 | totalLength += encoder.prependVarNumber(totalLength); |
| 94 | totalLength += encoder.prependVarNumber(tlv::nfd::FaceStatus); |
| 95 | return totalLength; |
| 96 | } |
| 97 | |
| 98 | template size_t |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame] | 99 | FaceStatus::wireEncode<encoding::EncoderTag>(EncodingImpl<encoding::EncoderTag>& block) const; |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 100 | |
| 101 | template size_t |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame] | 102 | FaceStatus::wireEncode<encoding::EstimatorTag>(EncodingImpl<encoding::EstimatorTag>& block) const; |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 103 | |
| 104 | const Block& |
| 105 | FaceStatus::wireEncode() const |
| 106 | { |
| 107 | if (m_wire.hasWire()) |
| 108 | return m_wire; |
| 109 | |
| 110 | EncodingEstimator estimator; |
| 111 | size_t estimatedSize = wireEncode(estimator); |
| 112 | |
| 113 | EncodingBuffer buffer(estimatedSize, 0); |
| 114 | wireEncode(buffer); |
| 115 | |
| 116 | m_wire = buffer.block(); |
| 117 | return m_wire; |
| 118 | } |
| 119 | |
| 120 | void |
| 121 | FaceStatus::wireDecode(const Block& block) |
| 122 | { |
| 123 | if (block.type() != tlv::nfd::FaceStatus) { |
Spyridon Mastorakis | 0d2ed2e | 2015-07-27 19:09:12 -0700 | [diff] [blame] | 124 | BOOST_THROW_EXCEPTION(Error("expecting FaceStatus block")); |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 125 | } |
| 126 | m_wire = block; |
| 127 | m_wire.parse(); |
| 128 | Block::element_const_iterator val = m_wire.elements_begin(); |
| 129 | |
| 130 | if (val != m_wire.elements_end() && val->type() == tlv::nfd::FaceId) { |
| 131 | m_faceId = readNonNegativeInteger(*val); |
| 132 | ++val; |
| 133 | } |
| 134 | else { |
Spyridon Mastorakis | 0d2ed2e | 2015-07-27 19:09:12 -0700 | [diff] [blame] | 135 | BOOST_THROW_EXCEPTION(Error("missing required FaceId field")); |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | if (val != m_wire.elements_end() && val->type() == tlv::nfd::Uri) { |
| 139 | m_remoteUri.assign(reinterpret_cast<const char*>(val->value()), val->value_size()); |
| 140 | ++val; |
| 141 | } |
| 142 | else { |
Spyridon Mastorakis | 0d2ed2e | 2015-07-27 19:09:12 -0700 | [diff] [blame] | 143 | BOOST_THROW_EXCEPTION(Error("missing required Uri field")); |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | if (val != m_wire.elements_end() && val->type() == tlv::nfd::LocalUri) { |
| 147 | m_localUri.assign(reinterpret_cast<const char*>(val->value()), val->value_size()); |
| 148 | ++val; |
| 149 | } |
| 150 | else { |
Spyridon Mastorakis | 0d2ed2e | 2015-07-27 19:09:12 -0700 | [diff] [blame] | 151 | BOOST_THROW_EXCEPTION(Error("missing required LocalUri field")); |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | if (val != m_wire.elements_end() && val->type() == tlv::nfd::ExpirationPeriod) { |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame^] | 155 | m_expirationPeriod.emplace(readNonNegativeInteger(*val)); |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 156 | ++val; |
| 157 | } |
| 158 | else { |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame^] | 159 | m_expirationPeriod = nullopt; |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 162 | if (val != m_wire.elements_end() && val->type() == tlv::nfd::FaceScope) { |
| 163 | m_faceScope = static_cast<FaceScope>(readNonNegativeInteger(*val)); |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 164 | ++val; |
| 165 | } |
| 166 | else { |
Spyridon Mastorakis | 0d2ed2e | 2015-07-27 19:09:12 -0700 | [diff] [blame] | 167 | BOOST_THROW_EXCEPTION(Error("missing required FaceScope field")); |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | if (val != m_wire.elements_end() && val->type() == tlv::nfd::FacePersistency) { |
| 171 | m_facePersistency = static_cast<FacePersistency>(readNonNegativeInteger(*val)); |
| 172 | ++val; |
| 173 | } |
| 174 | else { |
Spyridon Mastorakis | 0d2ed2e | 2015-07-27 19:09:12 -0700 | [diff] [blame] | 175 | BOOST_THROW_EXCEPTION(Error("missing required FacePersistency field")); |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | if (val != m_wire.elements_end() && val->type() == tlv::nfd::LinkType) { |
| 179 | m_linkType = static_cast<LinkType>(readNonNegativeInteger(*val)); |
| 180 | ++val; |
| 181 | } |
| 182 | else { |
Spyridon Mastorakis | 0d2ed2e | 2015-07-27 19:09:12 -0700 | [diff] [blame] | 183 | BOOST_THROW_EXCEPTION(Error("missing required LinkType field")); |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | if (val != m_wire.elements_end() && val->type() == tlv::nfd::NInInterests) { |
| 187 | m_nInInterests = readNonNegativeInteger(*val); |
| 188 | ++val; |
| 189 | } |
| 190 | else { |
Spyridon Mastorakis | 0d2ed2e | 2015-07-27 19:09:12 -0700 | [diff] [blame] | 191 | BOOST_THROW_EXCEPTION(Error("missing required NInInterests field")); |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | if (val != m_wire.elements_end() && val->type() == tlv::nfd::NInDatas) { |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame^] | 195 | m_nInData = readNonNegativeInteger(*val); |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 196 | ++val; |
| 197 | } |
| 198 | else { |
Spyridon Mastorakis | 0d2ed2e | 2015-07-27 19:09:12 -0700 | [diff] [blame] | 199 | BOOST_THROW_EXCEPTION(Error("missing required NInDatas field")); |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Eric Newberry | 95bd96a | 2015-09-04 23:34:22 -0700 | [diff] [blame] | 202 | if (val != m_wire.elements_end() && val->type() == tlv::nfd::NInNacks) { |
| 203 | m_nInNacks = readNonNegativeInteger(*val); |
| 204 | ++val; |
| 205 | } |
| 206 | else { |
| 207 | BOOST_THROW_EXCEPTION(Error("missing required NInNacks field")); |
| 208 | } |
| 209 | |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 210 | if (val != m_wire.elements_end() && val->type() == tlv::nfd::NOutInterests) { |
| 211 | m_nOutInterests = readNonNegativeInteger(*val); |
| 212 | ++val; |
| 213 | } |
| 214 | else { |
Spyridon Mastorakis | 0d2ed2e | 2015-07-27 19:09:12 -0700 | [diff] [blame] | 215 | BOOST_THROW_EXCEPTION(Error("missing required NOutInterests field")); |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | if (val != m_wire.elements_end() && val->type() == tlv::nfd::NOutDatas) { |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame^] | 219 | m_nOutData = readNonNegativeInteger(*val); |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 220 | ++val; |
| 221 | } |
| 222 | else { |
Spyridon Mastorakis | 0d2ed2e | 2015-07-27 19:09:12 -0700 | [diff] [blame] | 223 | BOOST_THROW_EXCEPTION(Error("missing required NOutDatas field")); |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Eric Newberry | 95bd96a | 2015-09-04 23:34:22 -0700 | [diff] [blame] | 226 | if (val != m_wire.elements_end() && val->type() == tlv::nfd::NOutNacks) { |
| 227 | m_nOutNacks = readNonNegativeInteger(*val); |
| 228 | ++val; |
| 229 | } |
| 230 | else { |
| 231 | BOOST_THROW_EXCEPTION(Error("missing required NOutNacks field")); |
| 232 | } |
| 233 | |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 234 | if (val != m_wire.elements_end() && val->type() == tlv::nfd::NInBytes) { |
| 235 | m_nInBytes = readNonNegativeInteger(*val); |
| 236 | ++val; |
| 237 | } |
| 238 | else { |
Spyridon Mastorakis | 0d2ed2e | 2015-07-27 19:09:12 -0700 | [diff] [blame] | 239 | BOOST_THROW_EXCEPTION(Error("missing required NInBytes field")); |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | if (val != m_wire.elements_end() && val->type() == tlv::nfd::NOutBytes) { |
| 243 | m_nOutBytes = readNonNegativeInteger(*val); |
| 244 | ++val; |
| 245 | } |
| 246 | else { |
Spyridon Mastorakis | 0d2ed2e | 2015-07-27 19:09:12 -0700 | [diff] [blame] | 247 | BOOST_THROW_EXCEPTION(Error("missing required NOutBytes field")); |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 248 | } |
Eric Newberry | 1ce8ab2 | 2016-09-24 11:57:21 -0700 | [diff] [blame] | 249 | |
| 250 | if (val != m_wire.elements_end() && val->type() == tlv::nfd::Flags) { |
| 251 | m_flags = readNonNegativeInteger(*val); |
| 252 | ++val; |
| 253 | } |
| 254 | else { |
| 255 | BOOST_THROW_EXCEPTION(Error("missing required Flags field")); |
| 256 | } |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 259 | FaceStatus& |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame^] | 260 | FaceStatus::setExpirationPeriod(time::milliseconds expirationPeriod) |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 261 | { |
| 262 | m_wire.reset(); |
| 263 | m_expirationPeriod = expirationPeriod; |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 264 | return *this; |
| 265 | } |
| 266 | |
| 267 | FaceStatus& |
| 268 | FaceStatus::setNInInterests(uint64_t nInInterests) |
| 269 | { |
| 270 | m_wire.reset(); |
| 271 | m_nInInterests = nInInterests; |
| 272 | return *this; |
| 273 | } |
| 274 | |
| 275 | FaceStatus& |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame^] | 276 | FaceStatus::setNInDatas(uint64_t nInData) |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 277 | { |
| 278 | m_wire.reset(); |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame^] | 279 | m_nInData = nInData; |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 280 | return *this; |
| 281 | } |
| 282 | |
| 283 | FaceStatus& |
Eric Newberry | 95bd96a | 2015-09-04 23:34:22 -0700 | [diff] [blame] | 284 | FaceStatus::setNInNacks(uint64_t nInNacks) |
| 285 | { |
| 286 | m_wire.reset(); |
| 287 | m_nInNacks = nInNacks; |
| 288 | return *this; |
| 289 | } |
| 290 | |
| 291 | FaceStatus& |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 292 | FaceStatus::setNOutInterests(uint64_t nOutInterests) |
| 293 | { |
| 294 | m_wire.reset(); |
| 295 | m_nOutInterests = nOutInterests; |
| 296 | return *this; |
| 297 | } |
| 298 | |
| 299 | FaceStatus& |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame^] | 300 | FaceStatus::setNOutDatas(uint64_t nOutData) |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 301 | { |
| 302 | m_wire.reset(); |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame^] | 303 | m_nOutData = nOutData; |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 304 | return *this; |
| 305 | } |
| 306 | |
| 307 | FaceStatus& |
Eric Newberry | 95bd96a | 2015-09-04 23:34:22 -0700 | [diff] [blame] | 308 | FaceStatus::setNOutNacks(uint64_t nOutNacks) |
| 309 | { |
| 310 | m_wire.reset(); |
| 311 | m_nOutNacks = nOutNacks; |
| 312 | return *this; |
| 313 | } |
| 314 | |
| 315 | FaceStatus& |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 316 | FaceStatus::setNInBytes(uint64_t nInBytes) |
| 317 | { |
| 318 | m_wire.reset(); |
| 319 | m_nInBytes = nInBytes; |
| 320 | return *this; |
| 321 | } |
| 322 | |
| 323 | FaceStatus& |
| 324 | FaceStatus::setNOutBytes(uint64_t nOutBytes) |
| 325 | { |
| 326 | m_wire.reset(); |
| 327 | m_nOutBytes = nOutBytes; |
| 328 | return *this; |
| 329 | } |
| 330 | |
| 331 | void |
| 332 | FaceStatus::wireReset() const |
| 333 | { |
| 334 | m_wire.reset(); |
| 335 | } |
| 336 | |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame^] | 337 | bool |
| 338 | operator==(const FaceStatus& a, const FaceStatus& b) |
| 339 | { |
| 340 | return a.getFaceId() == b.getFaceId() && |
| 341 | a.getRemoteUri() == b.getRemoteUri() && |
| 342 | a.getLocalUri() == b.getLocalUri() && |
| 343 | a.getFaceScope() == b.getFaceScope() && |
| 344 | a.getFacePersistency() == b.getFacePersistency() && |
| 345 | a.getLinkType() == b.getLinkType() && |
| 346 | a.getFlags() == b.getFlags() && |
| 347 | a.hasExpirationPeriod() == b.hasExpirationPeriod() && |
| 348 | (!a.hasExpirationPeriod() || a.getExpirationPeriod() == b.getExpirationPeriod()) && |
| 349 | a.getNInInterests() == b.getNInInterests() && |
| 350 | a.getNInDatas() == b.getNInDatas() && |
| 351 | a.getNInNacks() == b.getNInNacks() && |
| 352 | a.getNOutInterests() == b.getNOutInterests() && |
| 353 | a.getNOutDatas() == b.getNOutDatas() && |
| 354 | a.getNOutNacks() == b.getNOutNacks() && |
| 355 | a.getNInBytes() == b.getNInBytes() && |
| 356 | a.getNOutBytes() == b.getNOutBytes(); |
| 357 | } |
| 358 | |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 359 | std::ostream& |
| 360 | operator<<(std::ostream& os, const FaceStatus& status) |
| 361 | { |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame^] | 362 | os << "Face(FaceId: " << status.getFaceId() << ",\n" |
| 363 | << " RemoteUri: " << status.getRemoteUri() << ",\n" |
| 364 | << " LocalUri: " << status.getLocalUri() << ",\n"; |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 365 | |
| 366 | if (status.hasExpirationPeriod()) { |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame^] | 367 | os << " ExpirationPeriod: " << status.getExpirationPeriod() << ",\n"; |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 368 | } |
| 369 | else { |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame^] | 370 | os << " ExpirationPeriod: infinite,\n"; |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 371 | } |
| 372 | |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame^] | 373 | os << " FaceScope: " << status.getFaceScope() << ",\n" |
| 374 | << " FacePersistency: " << status.getFacePersistency() << ",\n" |
| 375 | << " LinkType: " << status.getLinkType() << ",\n"; |
Eric Newberry | 1ce8ab2 | 2016-09-24 11:57:21 -0700 | [diff] [blame] | 376 | |
| 377 | auto osFlags = os.flags(); |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame^] | 378 | // std::showbase doesn't work with number 0 |
| 379 | os << " Flags: 0x" << std::noshowbase << std::noshowpos << std::nouppercase |
| 380 | << std::hex << status.getFlags() << ",\n"; |
Eric Newberry | 1ce8ab2 | 2016-09-24 11:57:21 -0700 | [diff] [blame] | 381 | os.flags(osFlags); |
| 382 | |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame^] | 383 | os << " Counters: {Interests: {in: " << status.getNInInterests() << ", " |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 384 | << "out: " << status.getNOutInterests() << "},\n" |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame^] | 385 | << " Data: {in: " << status.getNInDatas() << ", " |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 386 | << "out: " << status.getNOutDatas() << "},\n" |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame^] | 387 | << " Nacks: {in: " << status.getNInNacks() << ", " |
Eric Newberry | 95bd96a | 2015-09-04 23:34:22 -0700 | [diff] [blame] | 388 | << "out: " << status.getNOutNacks() << "},\n" |
Davide Pesavento | 4ec7a5a | 2017-02-07 23:13:39 -0500 | [diff] [blame^] | 389 | << " bytes: {in: " << status.getNInBytes() << ", " |
| 390 | << "out: " << status.getNOutBytes() << "}}\n"; |
| 391 | |
| 392 | return os << " )"; |
Junxiao Shi | 13e637f | 2014-07-16 19:20:40 -0700 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | } // namespace nfd |
| 396 | } // namespace ndn |