Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 88a0d81 | 2017-08-19 21:31:42 -0400 | [diff] [blame] | 2 | /* |
Junxiao Shi | 22f8568 | 2018-01-22 19:23:22 +0000 | [diff] [blame] | 3 | * Copyright (c) 2013-2018 Regents of the University of California. |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [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 | |
| 22 | #ifndef NDN_MGMT_NFD_CONTROL_PARAMETERS_HPP |
| 23 | #define NDN_MGMT_NFD_CONTROL_PARAMETERS_HPP |
| 24 | |
| 25 | #include "../../encoding/nfd-constants.hpp" |
| 26 | #include "../../name.hpp" |
| 27 | #include "../../util/time.hpp" |
| 28 | #include "../control-parameters.hpp" |
| 29 | |
| 30 | namespace ndn { |
| 31 | namespace nfd { |
| 32 | |
| 33 | /** |
| 34 | * \ingroup management |
| 35 | */ |
| 36 | enum ControlParameterField { |
| 37 | CONTROL_PARAMETER_NAME, |
| 38 | CONTROL_PARAMETER_FACE_ID, |
| 39 | CONTROL_PARAMETER_URI, |
Eric Newberry | d7f5b28 | 2017-03-28 19:55:20 -0700 | [diff] [blame] | 40 | CONTROL_PARAMETER_LOCAL_URI, |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 41 | CONTROL_PARAMETER_ORIGIN, |
| 42 | CONTROL_PARAMETER_COST, |
Junxiao Shi | 22f8568 | 2018-01-22 19:23:22 +0000 | [diff] [blame] | 43 | CONTROL_PARAMETER_CAPACITY, |
Davide Pesavento | 5e2ccca | 2018-03-06 19:00:15 -0500 | [diff] [blame] | 44 | CONTROL_PARAMETER_COUNT, |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 45 | CONTROL_PARAMETER_FLAGS, |
| 46 | CONTROL_PARAMETER_MASK, |
| 47 | CONTROL_PARAMETER_STRATEGY, |
| 48 | CONTROL_PARAMETER_EXPIRATION_PERIOD, |
| 49 | CONTROL_PARAMETER_FACE_PERSISTENCY, |
Eric Newberry | 07d05c9 | 2018-01-22 16:08:01 -0700 | [diff] [blame] | 50 | CONTROL_PARAMETER_BASE_CONGESTION_MARKING_INTERVAL, |
| 51 | CONTROL_PARAMETER_DEFAULT_CONGESTION_THRESHOLD, |
Eric Newberry | 3c9bc04 | 2018-06-02 17:58:10 -0700 | [diff] [blame] | 52 | CONTROL_PARAMETER_MTU, |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 53 | CONTROL_PARAMETER_UBOUND |
| 54 | }; |
| 55 | |
| 56 | const std::string CONTROL_PARAMETER_FIELD[CONTROL_PARAMETER_UBOUND] = { |
| 57 | "Name", |
| 58 | "FaceId", |
| 59 | "Uri", |
Eric Newberry | d7f5b28 | 2017-03-28 19:55:20 -0700 | [diff] [blame] | 60 | "LocalUri", |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 61 | "Origin", |
| 62 | "Cost", |
Junxiao Shi | 22f8568 | 2018-01-22 19:23:22 +0000 | [diff] [blame] | 63 | "Capacity", |
Davide Pesavento | 5e2ccca | 2018-03-06 19:00:15 -0500 | [diff] [blame] | 64 | "Count", |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 65 | "Flags", |
| 66 | "Mask", |
| 67 | "Strategy", |
| 68 | "ExpirationPeriod", |
Eric Newberry | 07d05c9 | 2018-01-22 16:08:01 -0700 | [diff] [blame] | 69 | "FacePersistency", |
| 70 | "BaseCongestionMarkingInterval", |
Eric Newberry | 3c9bc04 | 2018-06-02 17:58:10 -0700 | [diff] [blame] | 71 | "DefaultCongestionThreshold", |
| 72 | "Mtu" |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | /** |
| 76 | * \ingroup management |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 77 | * \brief represents parameters in a ControlCommand request or response |
Eric Newberry | d7f5b28 | 2017-03-28 19:55:20 -0700 | [diff] [blame] | 78 | * \sa https://redmine.named-data.net/projects/nfd/wiki/ControlCommand#ControlParameters |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 79 | * \details This type is copyable because it's an abstraction of a TLV type. |
| 80 | */ |
Davide Pesavento | 7f20d6e | 2017-01-16 14:43:58 -0500 | [diff] [blame] | 81 | class ControlParameters : public mgmt::ControlParameters |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 82 | { |
| 83 | public: |
| 84 | class Error : public tlv::Error |
| 85 | { |
| 86 | public: |
Junxiao Shi | 68b5385 | 2018-07-25 13:56:38 -0600 | [diff] [blame] | 87 | using tlv::Error::Error; |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | ControlParameters(); |
| 91 | |
| 92 | explicit |
| 93 | ControlParameters(const Block& block); |
| 94 | |
| 95 | template<encoding::Tag TAG> |
| 96 | size_t |
| 97 | wireEncode(EncodingImpl<TAG>& encoder) const; |
| 98 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 99 | Block |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 100 | wireEncode() const final; |
| 101 | |
Davide Pesavento | 57c07df | 2016-12-11 18:41:45 -0500 | [diff] [blame] | 102 | void |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 103 | wireDecode(const Block& wire) final; |
| 104 | |
| 105 | public: // getters & setters |
| 106 | bool |
| 107 | hasName() const |
| 108 | { |
| 109 | return m_hasFields[CONTROL_PARAMETER_NAME]; |
| 110 | } |
| 111 | |
| 112 | const Name& |
| 113 | getName() const |
| 114 | { |
| 115 | BOOST_ASSERT(this->hasName()); |
| 116 | return m_name; |
| 117 | } |
| 118 | |
| 119 | ControlParameters& |
| 120 | setName(const Name& name) |
| 121 | { |
| 122 | m_wire.reset(); |
| 123 | m_name = name; |
| 124 | m_hasFields[CONTROL_PARAMETER_NAME] = true; |
| 125 | return *this; |
| 126 | } |
| 127 | |
| 128 | ControlParameters& |
| 129 | unsetName() |
| 130 | { |
| 131 | m_wire.reset(); |
| 132 | m_hasFields[CONTROL_PARAMETER_NAME] = false; |
| 133 | return *this; |
| 134 | } |
| 135 | |
| 136 | bool |
| 137 | hasFaceId() const |
| 138 | { |
| 139 | return m_hasFields[CONTROL_PARAMETER_FACE_ID]; |
| 140 | } |
| 141 | |
| 142 | uint64_t |
| 143 | getFaceId() const |
| 144 | { |
| 145 | BOOST_ASSERT(this->hasFaceId()); |
| 146 | return m_faceId; |
| 147 | } |
| 148 | |
| 149 | ControlParameters& |
| 150 | setFaceId(uint64_t faceId) |
| 151 | { |
| 152 | m_wire.reset(); |
| 153 | m_faceId = faceId; |
| 154 | m_hasFields[CONTROL_PARAMETER_FACE_ID] = true; |
| 155 | return *this; |
| 156 | } |
| 157 | |
| 158 | ControlParameters& |
| 159 | unsetFaceId() |
| 160 | { |
| 161 | m_wire.reset(); |
| 162 | m_hasFields[CONTROL_PARAMETER_FACE_ID] = false; |
| 163 | return *this; |
| 164 | } |
| 165 | |
| 166 | bool |
| 167 | hasUri() const |
| 168 | { |
| 169 | return m_hasFields[CONTROL_PARAMETER_URI]; |
| 170 | } |
| 171 | |
| 172 | const std::string& |
| 173 | getUri() const |
| 174 | { |
| 175 | BOOST_ASSERT(this->hasUri()); |
| 176 | return m_uri; |
| 177 | } |
| 178 | |
| 179 | ControlParameters& |
| 180 | setUri(const std::string& uri) |
| 181 | { |
| 182 | m_wire.reset(); |
| 183 | m_uri = uri; |
| 184 | m_hasFields[CONTROL_PARAMETER_URI] = true; |
| 185 | return *this; |
| 186 | } |
| 187 | |
| 188 | ControlParameters& |
| 189 | unsetUri() |
| 190 | { |
| 191 | m_wire.reset(); |
| 192 | m_hasFields[CONTROL_PARAMETER_URI] = false; |
| 193 | return *this; |
| 194 | } |
| 195 | |
Eric Newberry | d7f5b28 | 2017-03-28 19:55:20 -0700 | [diff] [blame] | 196 | bool |
| 197 | hasLocalUri() const |
| 198 | { |
| 199 | return m_hasFields[CONTROL_PARAMETER_LOCAL_URI]; |
| 200 | } |
| 201 | |
| 202 | const std::string& |
| 203 | getLocalUri() const |
| 204 | { |
| 205 | BOOST_ASSERT(this->hasLocalUri()); |
| 206 | return m_localUri; |
| 207 | } |
| 208 | |
| 209 | ControlParameters& |
| 210 | setLocalUri(const std::string& localUri) |
| 211 | { |
| 212 | m_wire.reset(); |
| 213 | m_localUri = localUri; |
| 214 | m_hasFields[CONTROL_PARAMETER_LOCAL_URI] = true; |
| 215 | return *this; |
| 216 | } |
| 217 | |
| 218 | ControlParameters& |
| 219 | unsetLocalUri() |
| 220 | { |
| 221 | m_wire.reset(); |
| 222 | m_hasFields[CONTROL_PARAMETER_LOCAL_URI] = false; |
| 223 | return *this; |
| 224 | } |
| 225 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 226 | bool |
| 227 | hasOrigin() const |
| 228 | { |
| 229 | return m_hasFields[CONTROL_PARAMETER_ORIGIN]; |
| 230 | } |
| 231 | |
Davide Pesavento | e8e48c2 | 2017-04-13 00:35:33 -0400 | [diff] [blame] | 232 | RouteOrigin |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 233 | getOrigin() const |
| 234 | { |
| 235 | BOOST_ASSERT(this->hasOrigin()); |
| 236 | return m_origin; |
| 237 | } |
| 238 | |
| 239 | ControlParameters& |
Davide Pesavento | e8e48c2 | 2017-04-13 00:35:33 -0400 | [diff] [blame] | 240 | setOrigin(RouteOrigin origin) |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 241 | { |
| 242 | m_wire.reset(); |
| 243 | m_origin = origin; |
| 244 | m_hasFields[CONTROL_PARAMETER_ORIGIN] = true; |
| 245 | return *this; |
| 246 | } |
| 247 | |
| 248 | ControlParameters& |
| 249 | unsetOrigin() |
| 250 | { |
| 251 | m_wire.reset(); |
| 252 | m_hasFields[CONTROL_PARAMETER_ORIGIN] = false; |
| 253 | return *this; |
| 254 | } |
| 255 | |
| 256 | bool |
| 257 | hasCost() const |
| 258 | { |
| 259 | return m_hasFields[CONTROL_PARAMETER_COST]; |
| 260 | } |
| 261 | |
| 262 | uint64_t |
| 263 | getCost() const |
| 264 | { |
| 265 | BOOST_ASSERT(this->hasCost()); |
| 266 | return m_cost; |
| 267 | } |
| 268 | |
| 269 | ControlParameters& |
| 270 | setCost(uint64_t cost) |
| 271 | { |
| 272 | m_wire.reset(); |
| 273 | m_cost = cost; |
| 274 | m_hasFields[CONTROL_PARAMETER_COST] = true; |
| 275 | return *this; |
| 276 | } |
| 277 | |
| 278 | ControlParameters& |
| 279 | unsetCost() |
| 280 | { |
| 281 | m_wire.reset(); |
| 282 | m_hasFields[CONTROL_PARAMETER_COST] = false; |
| 283 | return *this; |
| 284 | } |
| 285 | |
| 286 | bool |
Junxiao Shi | 22f8568 | 2018-01-22 19:23:22 +0000 | [diff] [blame] | 287 | hasCapacity() const |
| 288 | { |
| 289 | return m_hasFields[CONTROL_PARAMETER_CAPACITY]; |
| 290 | } |
| 291 | |
| 292 | uint64_t |
| 293 | getCapacity() const |
| 294 | { |
| 295 | BOOST_ASSERT(this->hasCapacity()); |
| 296 | return m_capacity; |
| 297 | } |
| 298 | |
| 299 | ControlParameters& |
| 300 | setCapacity(uint64_t capacity) |
| 301 | { |
| 302 | m_wire.reset(); |
| 303 | m_capacity = capacity; |
| 304 | m_hasFields[CONTROL_PARAMETER_CAPACITY] = true; |
| 305 | return *this; |
| 306 | } |
| 307 | |
| 308 | ControlParameters& |
| 309 | unsetCapacity() |
| 310 | { |
| 311 | m_wire.reset(); |
| 312 | m_hasFields[CONTROL_PARAMETER_CAPACITY] = false; |
| 313 | return *this; |
| 314 | } |
| 315 | |
| 316 | bool |
Davide Pesavento | 5e2ccca | 2018-03-06 19:00:15 -0500 | [diff] [blame] | 317 | hasCount() const |
Junxiao Shi | df50538 | 2018-03-04 13:40:44 +0000 | [diff] [blame] | 318 | { |
Davide Pesavento | 5e2ccca | 2018-03-06 19:00:15 -0500 | [diff] [blame] | 319 | return m_hasFields[CONTROL_PARAMETER_COUNT]; |
Junxiao Shi | df50538 | 2018-03-04 13:40:44 +0000 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | uint64_t |
Davide Pesavento | 5e2ccca | 2018-03-06 19:00:15 -0500 | [diff] [blame] | 323 | getCount() const |
Junxiao Shi | df50538 | 2018-03-04 13:40:44 +0000 | [diff] [blame] | 324 | { |
Davide Pesavento | 5e2ccca | 2018-03-06 19:00:15 -0500 | [diff] [blame] | 325 | BOOST_ASSERT(this->hasCount()); |
| 326 | return m_count; |
Junxiao Shi | df50538 | 2018-03-04 13:40:44 +0000 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | ControlParameters& |
Davide Pesavento | 5e2ccca | 2018-03-06 19:00:15 -0500 | [diff] [blame] | 330 | setCount(uint64_t count) |
Junxiao Shi | df50538 | 2018-03-04 13:40:44 +0000 | [diff] [blame] | 331 | { |
| 332 | m_wire.reset(); |
Davide Pesavento | 5e2ccca | 2018-03-06 19:00:15 -0500 | [diff] [blame] | 333 | m_count = count; |
| 334 | m_hasFields[CONTROL_PARAMETER_COUNT] = true; |
Junxiao Shi | df50538 | 2018-03-04 13:40:44 +0000 | [diff] [blame] | 335 | return *this; |
| 336 | } |
| 337 | |
| 338 | ControlParameters& |
Davide Pesavento | 5e2ccca | 2018-03-06 19:00:15 -0500 | [diff] [blame] | 339 | unsetCount() |
Junxiao Shi | df50538 | 2018-03-04 13:40:44 +0000 | [diff] [blame] | 340 | { |
| 341 | m_wire.reset(); |
Davide Pesavento | 5e2ccca | 2018-03-06 19:00:15 -0500 | [diff] [blame] | 342 | m_hasFields[CONTROL_PARAMETER_COUNT] = false; |
Junxiao Shi | df50538 | 2018-03-04 13:40:44 +0000 | [diff] [blame] | 343 | return *this; |
| 344 | } |
| 345 | |
| 346 | bool |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 347 | hasFlags() const |
| 348 | { |
| 349 | return m_hasFields[CONTROL_PARAMETER_FLAGS]; |
| 350 | } |
| 351 | |
| 352 | uint64_t |
| 353 | getFlags() const |
| 354 | { |
| 355 | BOOST_ASSERT(this->hasFlags()); |
| 356 | return m_flags; |
| 357 | } |
| 358 | |
| 359 | ControlParameters& |
| 360 | setFlags(uint64_t flags) |
| 361 | { |
| 362 | m_wire.reset(); |
| 363 | m_flags = flags; |
| 364 | m_hasFields[CONTROL_PARAMETER_FLAGS] = true; |
| 365 | return *this; |
| 366 | } |
| 367 | |
| 368 | ControlParameters& |
| 369 | unsetFlags() |
| 370 | { |
| 371 | m_wire.reset(); |
| 372 | m_hasFields[CONTROL_PARAMETER_FLAGS] = false; |
| 373 | return *this; |
| 374 | } |
| 375 | |
| 376 | bool |
| 377 | hasMask() const |
| 378 | { |
| 379 | return m_hasFields[CONTROL_PARAMETER_MASK]; |
| 380 | } |
| 381 | |
| 382 | uint64_t |
| 383 | getMask() const |
| 384 | { |
| 385 | BOOST_ASSERT(this->hasMask()); |
| 386 | return m_mask; |
| 387 | } |
| 388 | |
| 389 | ControlParameters& |
| 390 | setMask(uint64_t mask) |
| 391 | { |
| 392 | m_wire.reset(); |
| 393 | m_mask = mask; |
| 394 | m_hasFields[CONTROL_PARAMETER_MASK] = true; |
| 395 | return *this; |
| 396 | } |
| 397 | |
| 398 | ControlParameters& |
| 399 | unsetMask() |
| 400 | { |
| 401 | m_wire.reset(); |
| 402 | m_hasFields[CONTROL_PARAMETER_MASK] = false; |
| 403 | return *this; |
| 404 | } |
| 405 | |
| 406 | bool |
| 407 | hasStrategy() const |
| 408 | { |
| 409 | return m_hasFields[CONTROL_PARAMETER_STRATEGY]; |
| 410 | } |
| 411 | |
| 412 | const Name& |
| 413 | getStrategy() const |
| 414 | { |
| 415 | BOOST_ASSERT(this->hasStrategy()); |
| 416 | return m_strategy; |
| 417 | } |
| 418 | |
| 419 | ControlParameters& |
| 420 | setStrategy(const Name& strategy) |
| 421 | { |
| 422 | m_wire.reset(); |
| 423 | m_strategy = strategy; |
| 424 | m_hasFields[CONTROL_PARAMETER_STRATEGY] = true; |
| 425 | return *this; |
| 426 | } |
| 427 | |
| 428 | ControlParameters& |
| 429 | unsetStrategy() |
| 430 | { |
| 431 | m_wire.reset(); |
| 432 | m_hasFields[CONTROL_PARAMETER_STRATEGY] = false; |
| 433 | return *this; |
| 434 | } |
| 435 | |
| 436 | bool |
| 437 | hasExpirationPeriod() const |
| 438 | { |
| 439 | return m_hasFields[CONTROL_PARAMETER_EXPIRATION_PERIOD]; |
| 440 | } |
| 441 | |
| 442 | const time::milliseconds& |
| 443 | getExpirationPeriod() const |
| 444 | { |
| 445 | BOOST_ASSERT(this->hasExpirationPeriod()); |
| 446 | return m_expirationPeriod; |
| 447 | } |
| 448 | |
| 449 | ControlParameters& |
| 450 | setExpirationPeriod(const time::milliseconds& expirationPeriod) |
| 451 | { |
| 452 | m_wire.reset(); |
| 453 | m_expirationPeriod = expirationPeriod; |
| 454 | m_hasFields[CONTROL_PARAMETER_EXPIRATION_PERIOD] = true; |
| 455 | return *this; |
| 456 | } |
| 457 | |
| 458 | ControlParameters& |
| 459 | unsetExpirationPeriod() |
| 460 | { |
| 461 | m_wire.reset(); |
| 462 | m_hasFields[CONTROL_PARAMETER_EXPIRATION_PERIOD] = false; |
| 463 | return *this; |
| 464 | } |
| 465 | |
| 466 | bool |
| 467 | hasFacePersistency() const |
| 468 | { |
| 469 | return m_hasFields[CONTROL_PARAMETER_FACE_PERSISTENCY]; |
| 470 | } |
| 471 | |
| 472 | FacePersistency |
| 473 | getFacePersistency() const |
| 474 | { |
| 475 | BOOST_ASSERT(this->hasFacePersistency()); |
| 476 | return m_facePersistency; |
| 477 | } |
| 478 | |
| 479 | ControlParameters& |
| 480 | setFacePersistency(FacePersistency persistency) |
| 481 | { |
| 482 | m_wire.reset(); |
| 483 | m_facePersistency = persistency; |
| 484 | m_hasFields[CONTROL_PARAMETER_FACE_PERSISTENCY] = true; |
| 485 | return *this; |
| 486 | } |
| 487 | |
| 488 | ControlParameters& |
| 489 | unsetFacePersistency() |
| 490 | { |
| 491 | m_wire.reset(); |
| 492 | m_hasFields[CONTROL_PARAMETER_FACE_PERSISTENCY] = false; |
| 493 | return *this; |
| 494 | } |
| 495 | |
Eric Newberry | 07d05c9 | 2018-01-22 16:08:01 -0700 | [diff] [blame] | 496 | bool |
| 497 | hasBaseCongestionMarkingInterval() const |
| 498 | { |
| 499 | return m_hasFields[CONTROL_PARAMETER_BASE_CONGESTION_MARKING_INTERVAL]; |
| 500 | } |
| 501 | |
| 502 | time::nanoseconds |
| 503 | getBaseCongestionMarkingInterval() const |
| 504 | { |
| 505 | BOOST_ASSERT(this->hasBaseCongestionMarkingInterval()); |
| 506 | return m_baseCongestionMarkingInterval; |
| 507 | } |
| 508 | |
| 509 | ControlParameters& |
| 510 | setBaseCongestionMarkingInterval(time::nanoseconds interval) |
| 511 | { |
| 512 | m_wire.reset(); |
| 513 | m_baseCongestionMarkingInterval = interval; |
| 514 | m_hasFields[CONTROL_PARAMETER_BASE_CONGESTION_MARKING_INTERVAL] = true; |
| 515 | return *this; |
| 516 | } |
| 517 | |
| 518 | ControlParameters& |
| 519 | unsetBaseCongestionMarkingInterval() |
| 520 | { |
| 521 | m_wire.reset(); |
| 522 | m_hasFields[CONTROL_PARAMETER_BASE_CONGESTION_MARKING_INTERVAL] = false; |
| 523 | return *this; |
| 524 | } |
| 525 | |
| 526 | bool |
| 527 | hasDefaultCongestionThreshold() const |
| 528 | { |
| 529 | return m_hasFields[CONTROL_PARAMETER_DEFAULT_CONGESTION_THRESHOLD]; |
| 530 | } |
| 531 | |
| 532 | /** \brief get default congestion threshold (measured in bytes) |
| 533 | */ |
| 534 | uint64_t |
| 535 | getDefaultCongestionThreshold() const |
| 536 | { |
| 537 | BOOST_ASSERT(this->hasDefaultCongestionThreshold()); |
| 538 | return m_defaultCongestionThreshold; |
| 539 | } |
| 540 | |
| 541 | /** \brief set default congestion threshold (measured in bytes) |
| 542 | */ |
| 543 | ControlParameters& |
| 544 | setDefaultCongestionThreshold(uint64_t threshold) |
| 545 | { |
| 546 | m_wire.reset(); |
| 547 | m_defaultCongestionThreshold = threshold; |
| 548 | m_hasFields[CONTROL_PARAMETER_DEFAULT_CONGESTION_THRESHOLD] = true; |
| 549 | return *this; |
| 550 | } |
| 551 | |
| 552 | ControlParameters& |
| 553 | unsetDefaultCongestionThreshold() |
| 554 | { |
| 555 | m_wire.reset(); |
| 556 | m_hasFields[CONTROL_PARAMETER_DEFAULT_CONGESTION_THRESHOLD] = false; |
| 557 | return *this; |
| 558 | } |
| 559 | |
Eric Newberry | 3c9bc04 | 2018-06-02 17:58:10 -0700 | [diff] [blame] | 560 | bool |
| 561 | hasMtu() const |
| 562 | { |
| 563 | return m_hasFields[CONTROL_PARAMETER_MTU]; |
| 564 | } |
| 565 | |
| 566 | /** \brief get MTU (measured in bytes) |
| 567 | * |
| 568 | * This value is capped at MAX_NDN_PACKET_SIZE, even if the MTU of the face is unlimited. |
| 569 | */ |
| 570 | uint64_t |
| 571 | getMtu() const |
| 572 | { |
| 573 | BOOST_ASSERT(this->hasMtu()); |
| 574 | return m_mtu; |
| 575 | } |
| 576 | |
| 577 | /** \brief set MTU (measured in bytes) |
| 578 | * |
| 579 | * This value is capped at MAX_NDN_PACKET_SIZE, even if the MTU of the face is unlimited. |
| 580 | */ |
| 581 | ControlParameters& |
| 582 | setMtu(uint64_t mtu) |
| 583 | { |
| 584 | m_wire.reset(); |
| 585 | m_mtu = mtu; |
| 586 | m_hasFields[CONTROL_PARAMETER_MTU] = true; |
| 587 | return *this; |
| 588 | } |
| 589 | |
| 590 | ControlParameters& |
| 591 | unsetMtu() |
| 592 | { |
| 593 | m_wire.reset(); |
| 594 | m_hasFields[CONTROL_PARAMETER_MTU] = false; |
| 595 | return *this; |
| 596 | } |
| 597 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 598 | const std::vector<bool>& |
| 599 | getPresentFields() const |
| 600 | { |
| 601 | return m_hasFields; |
| 602 | } |
| 603 | |
| 604 | public: // Flags and Mask helpers |
| 605 | /** |
| 606 | * \return whether bit is enabled in Mask |
| 607 | * \param bit bit position within range [0, 64) (least significant bit is 0) |
| 608 | */ |
| 609 | bool |
| 610 | hasFlagBit(size_t bit) const; |
| 611 | |
| 612 | /** |
| 613 | * \return bit at a position in Flags |
| 614 | * \param bit bit position within range [0, 64) (least significant bit is 0) |
| 615 | */ |
| 616 | bool |
| 617 | getFlagBit(size_t bit) const; |
| 618 | |
| 619 | /** |
| 620 | * \brief set a bit in Flags |
| 621 | * \param bit bit position within range [0, 64) (least significant bit is 0) |
| 622 | * \param value new value in Flags |
| 623 | * \param wantMask if true, enable the bit in Mask |
| 624 | */ |
| 625 | ControlParameters& |
| 626 | setFlagBit(size_t bit, bool value, bool wantMask = true); |
| 627 | |
| 628 | /** |
| 629 | * \brief disable a bit in Mask |
| 630 | * \param bit bit position within range [0, 64) (least significant bit is 0) |
| 631 | * \post If all bits are disabled, Flags and Mask fields are deleted. |
| 632 | */ |
| 633 | ControlParameters& |
| 634 | unsetFlagBit(size_t bit); |
| 635 | |
| 636 | private: // fields |
| 637 | std::vector<bool> m_hasFields; |
| 638 | |
| 639 | Name m_name; |
| 640 | uint64_t m_faceId; |
| 641 | std::string m_uri; |
Eric Newberry | d7f5b28 | 2017-03-28 19:55:20 -0700 | [diff] [blame] | 642 | std::string m_localUri; |
Davide Pesavento | e8e48c2 | 2017-04-13 00:35:33 -0400 | [diff] [blame] | 643 | RouteOrigin m_origin; |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 644 | uint64_t m_cost; |
Junxiao Shi | 22f8568 | 2018-01-22 19:23:22 +0000 | [diff] [blame] | 645 | uint64_t m_capacity; |
Davide Pesavento | 5e2ccca | 2018-03-06 19:00:15 -0500 | [diff] [blame] | 646 | uint64_t m_count; |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 647 | uint64_t m_flags; |
| 648 | uint64_t m_mask; |
| 649 | Name m_strategy; |
| 650 | time::milliseconds m_expirationPeriod; |
| 651 | FacePersistency m_facePersistency; |
Eric Newberry | 07d05c9 | 2018-01-22 16:08:01 -0700 | [diff] [blame] | 652 | time::nanoseconds m_baseCongestionMarkingInterval; |
| 653 | uint64_t m_defaultCongestionThreshold; |
Eric Newberry | 3c9bc04 | 2018-06-02 17:58:10 -0700 | [diff] [blame] | 654 | uint64_t m_mtu; |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 655 | |
| 656 | private: |
| 657 | mutable Block m_wire; |
| 658 | }; |
| 659 | |
Davide Pesavento | 88a0d81 | 2017-08-19 21:31:42 -0400 | [diff] [blame] | 660 | NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(ControlParameters); |
| 661 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 662 | std::ostream& |
| 663 | operator<<(std::ostream& os, const ControlParameters& parameters); |
| 664 | |
| 665 | } // namespace nfd |
| 666 | } // namespace ndn |
| 667 | |
| 668 | #endif // NDN_MGMT_NFD_CONTROL_PARAMETERS_HPP |