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