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