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