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