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