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