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