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