NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
control-command.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2019 Regents of the University of California.
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 
23 
24 namespace ndn {
25 namespace nfd {
26 
27 ControlCommand::ControlCommand(const std::string& module, const std::string& verb)
28  : m_module(module)
29  , m_verb(verb)
30 {
31 }
32 
34 
35 void
37 {
38  m_requestValidator.validate(parameters);
39 }
40 
41 void
43 {
44 }
45 
46 void
48 {
49  m_responseValidator.validate(parameters);
50 }
51 
52 void
54 {
55 }
56 
57 Name
58 ControlCommand::getRequestName(const Name& commandPrefix,
59  const ControlParameters& parameters) const
60 {
61  this->validateRequest(parameters);
62 
63  Name name = commandPrefix;
64  name.append(m_module).append(m_verb);
65  name.append(parameters.wireEncode());
66  return name;
67 }
68 
70  : m_required(CONTROL_PARAMETER_UBOUND)
71  , m_optional(CONTROL_PARAMETER_UBOUND)
72 {
73 }
74 
75 void
77 {
78  const std::vector<bool>& presentFields = parameters.getPresentFields();
79 
80  for (size_t i = 0; i < CONTROL_PARAMETER_UBOUND; ++i) {
81  bool isPresent = presentFields[i];
82  if (m_required[i]) {
83  if (!isPresent) {
84  NDN_THROW(ArgumentError(CONTROL_PARAMETER_FIELD[i] + " is required but missing"));
85  }
86  }
87  else if (isPresent && !m_optional[i]) {
88  NDN_THROW(ArgumentError(CONTROL_PARAMETER_FIELD[i] + " is forbidden but present"));
89  }
90  }
91 
92  if (m_optional[CONTROL_PARAMETER_FLAGS] && m_optional[CONTROL_PARAMETER_MASK]) {
93  if (parameters.hasFlags() != parameters.hasMask()) {
94  NDN_THROW(ArgumentError("Flags must be accompanied by Mask"));
95  }
96  }
97 }
98 
100  : ControlCommand("faces", "create")
101 {
120 }
121 
122 void
124 {
125  if (!parameters.hasFacePersistency()) {
127  }
128 }
129 
130 void
132 {
133  this->ControlCommand::validateResponse(parameters);
134 
135  if (parameters.getFaceId() == INVALID_FACE_ID) {
136  NDN_THROW(ArgumentError("FaceId must be valid"));
137  }
138 }
139 
141  : ControlCommand("faces", "update")
142 {
156 }
157 
158 void
160 {
161  if (!parameters.hasFaceId()) {
162  parameters.setFaceId(0);
163  }
164 }
165 
166 void
168 {
169  this->ControlCommand::validateResponse(parameters);
170 
171  if (parameters.getFaceId() == INVALID_FACE_ID) {
172  NDN_THROW(ArgumentError("FaceId must be valid"));
173  }
174 }
175 
177  : ControlCommand("faces", "destroy")
178 {
182 }
183 
184 void
186 {
187  this->ControlCommand::validateRequest(parameters);
188 
189  if (parameters.getFaceId() == INVALID_FACE_ID) {
190  NDN_THROW(ArgumentError("FaceId must be valid"));
191  }
192 }
193 
194 void
196 {
197  this->validateRequest(parameters);
198 }
199 
201  : ControlCommand("fib", "add-nexthop")
202 {
211 }
212 
213 void
215 {
216  if (!parameters.hasFaceId()) {
217  parameters.setFaceId(0);
218  }
219  if (!parameters.hasCost()) {
220  parameters.setCost(0);
221  }
222 }
223 
224 void
226 {
227  this->ControlCommand::validateResponse(parameters);
228 
229  if (parameters.getFaceId() == INVALID_FACE_ID) {
230  NDN_THROW(ArgumentError("FaceId must be valid"));
231  }
232 }
233 
235  : ControlCommand("fib", "remove-nexthop")
236 {
243 }
244 
245 void
247 {
248  if (!parameters.hasFaceId()) {
249  parameters.setFaceId(0);
250  }
251 }
252 
253 void
255 {
256  this->ControlCommand::validateResponse(parameters);
257 
258  if (parameters.getFaceId() == INVALID_FACE_ID) {
259  NDN_THROW(ArgumentError("FaceId must be valid"));
260  }
261 }
262 
264  : ControlCommand("cs", "config")
265 {
273 }
274 
276  : ControlCommand("cs", "erase")
277 {
285 }
286 
287 void
289 {
290  this->ControlCommand::validateRequest(parameters);
291 
292  if (parameters.hasCount() && parameters.getCount() == 0) {
293  NDN_THROW(ArgumentError("Count must be positive"));
294  }
295 }
296 
297 void
299 {
300  this->ControlCommand::validateResponse(parameters);
301 
302  if (parameters.hasCapacity() && parameters.getCapacity() == 0) {
303  NDN_THROW(ArgumentError("Capacity must be positive"));
304  }
305 }
306 
308  : ControlCommand("strategy-choice", "set")
309 {
314 }
315 
317  : ControlCommand("strategy-choice", "unset")
318 {
322 }
323 
324 void
326 {
327  this->ControlCommand::validateRequest(parameters);
328 
329  if (parameters.getName().size() == 0) {
330  NDN_THROW(ArgumentError("Name must not be ndn:/"));
331  }
332 }
333 
334 void
336 {
337  this->validateRequest(parameters);
338 }
339 
341  : ControlCommand("rib", "register")
342 {
357 }
358 
359 void
361 {
362  if (!parameters.hasFaceId()) {
363  parameters.setFaceId(0);
364  }
365  if (!parameters.hasOrigin()) {
366  parameters.setOrigin(ROUTE_ORIGIN_APP);
367  }
368  if (!parameters.hasCost()) {
369  parameters.setCost(0);
370  }
371  if (!parameters.hasFlags()) {
373  }
374 }
375 
376 void
378 {
379  this->ControlCommand::validateResponse(parameters);
380 
381  if (parameters.getFaceId() == INVALID_FACE_ID) {
382  NDN_THROW(ArgumentError("FaceId must be valid"));
383  }
384 }
385 
387  : ControlCommand("rib", "unregister")
388 {
397 }
398 
399 void
401 {
402  if (!parameters.hasFaceId()) {
403  parameters.setFaceId(0);
404  }
405  if (!parameters.hasOrigin()) {
406  parameters.setOrigin(ROUTE_ORIGIN_APP);
407  }
408 }
409 
410 void
412 {
413  this->ControlCommand::validateResponse(parameters);
414 
415  if (parameters.getFaceId() == INVALID_FACE_ID) {
416  NDN_THROW(ArgumentError("FaceId must be valid"));
417  }
418 }
419 
420 } // namespace nfd
421 } // namespace ndn
ndn::nfd::CONTROL_PARAMETER_BASE_CONGESTION_MARKING_INTERVAL
@ CONTROL_PARAMETER_BASE_CONGESTION_MARKING_INTERVAL
Definition: control-parameters.hpp:50
ndn::nfd::CONTROL_PARAMETER_ORIGIN
@ CONTROL_PARAMETER_ORIGIN
Definition: control-parameters.hpp:41
ndn::nfd::CONTROL_PARAMETER_URI
@ CONTROL_PARAMETER_URI
Definition: control-parameters.hpp:39
ndn::nfd::CONTROL_PARAMETER_COST
@ CONTROL_PARAMETER_COST
Definition: control-parameters.hpp:42
ndn::nfd::ControlParameters::setFacePersistency
ControlParameters & setFacePersistency(FacePersistency persistency)
Definition: control-parameters.hpp:480
ndn::nfd::ROUTE_ORIGIN_APP
@ ROUTE_ORIGIN_APP
Definition: nfd-constants.hpp:101
ndn::nfd::CONTROL_PARAMETER_DEFAULT_CONGESTION_THRESHOLD
@ CONTROL_PARAMETER_DEFAULT_CONGESTION_THRESHOLD
Definition: control-parameters.hpp:51
ndn::nfd::CONTROL_PARAMETER_MTU
@ CONTROL_PARAMETER_MTU
Definition: control-parameters.hpp:52
ndn::nfd::ControlCommand::FieldValidator::FieldValidator
FieldValidator()
Definition: control-command.cpp:69
ndn::nfd::CsEraseCommand::CsEraseCommand
CsEraseCommand()
Definition: control-command.cpp:275
ndn::nfd::ControlParameters::setFlags
ControlParameters & setFlags(uint64_t flags)
Definition: control-parameters.hpp:360
ndn::nfd::CONTROL_PARAMETER_LOCAL_URI
@ CONTROL_PARAMETER_LOCAL_URI
Definition: control-parameters.hpp:40
ndn::Name::size
size_t size() const
Returns the number of components.
Definition: name.hpp:153
ndn::nfd::FaceUpdateCommand::applyDefaultsToRequest
void applyDefaultsToRequest(ControlParameters &parameters) const override
apply default values to missing fields in request
Definition: control-command.cpp:159
ndn::nfd::CONTROL_PARAMETER_NAME
@ CONTROL_PARAMETER_NAME
Definition: control-parameters.hpp:37
ndn::nfd::ControlCommand::applyDefaultsToResponse
virtual void applyDefaultsToResponse(ControlParameters &parameters) const
apply default values to missing fields in response
Definition: control-command.cpp:53
control-command.hpp
ndn::nfd::StrategyChoiceUnsetCommand::validateResponse
void validateResponse(const ControlParameters &parameters) const override
validate response parameters
Definition: control-command.cpp:335
ndn::nfd::CsEraseCommand::validateRequest
void validateRequest(const ControlParameters &parameters) const override
validate request parameters
Definition: control-command.cpp:288
ndn::nfd::FaceDestroyCommand::FaceDestroyCommand
FaceDestroyCommand()
Definition: control-command.cpp:176
ndn::nfd::RibRegisterCommand::RibRegisterCommand
RibRegisterCommand()
Definition: control-command.cpp:340
ndn::nfd::CONTROL_PARAMETER_FACE_PERSISTENCY
@ CONTROL_PARAMETER_FACE_PERSISTENCY
Definition: control-parameters.hpp:49
ndn::nfd::FibRemoveNextHopCommand::FibRemoveNextHopCommand
FibRemoveNextHopCommand()
Definition: control-command.cpp:234
ndn::nfd::FibAddNextHopCommand::FibAddNextHopCommand
FibAddNextHopCommand()
Definition: control-command.cpp:200
ndn::nfd::ControlCommand::getRequestName
Name getRequestName(const Name &commandPrefix, const ControlParameters &parameters) const
construct the Name for a request Interest
Definition: control-command.cpp:58
ndn::nfd::CONTROL_PARAMETER_FIELD
const std::string CONTROL_PARAMETER_FIELD[CONTROL_PARAMETER_UBOUND]
Definition: control-parameters.hpp:56
ndn::nfd::FibRemoveNextHopCommand::validateResponse
void validateResponse(const ControlParameters &parameters) const override
validate response parameters
Definition: control-command.cpp:254
ndn::nfd::ControlCommand::ArgumentError
represents an error in ControlParameters
Definition: control-command.hpp:41
ndn::nfd::RibRegisterCommand::applyDefaultsToRequest
void applyDefaultsToRequest(ControlParameters &parameters) const override
apply default values to missing fields in request
Definition: control-command.cpp:360
ndn::nfd::CONTROL_PARAMETER_FLAGS
@ CONTROL_PARAMETER_FLAGS
Definition: control-parameters.hpp:45
ndn::nfd::ControlCommand::validateResponse
virtual void validateResponse(const ControlParameters &parameters) const
validate response parameters
Definition: control-command.cpp:47
ndn::nfd::RibUnregisterCommand::applyDefaultsToRequest
void applyDefaultsToRequest(ControlParameters &parameters) const override
apply default values to missing fields in request
Definition: control-command.cpp:400
ndn::nfd::CONTROL_PARAMETER_UBOUND
@ CONTROL_PARAMETER_UBOUND
Definition: control-parameters.hpp:53
ndn::nfd::CONTROL_PARAMETER_MASK
@ CONTROL_PARAMETER_MASK
Definition: control-parameters.hpp:46
ndn::nfd::CONTROL_PARAMETER_FACE_ID
@ CONTROL_PARAMETER_FACE_ID
Definition: control-parameters.hpp:38
ndn::nfd::ControlParameters::getPresentFields
const std::vector< bool > & getPresentFields() const
Definition: control-parameters.hpp:599
ndn::nfd::ControlParameters::hasOrigin
bool hasOrigin() const
Definition: control-parameters.hpp:227
ndn::nfd::FaceCreateCommand::validateResponse
void validateResponse(const ControlParameters &parameters) const override
validate response parameters
Definition: control-command.cpp:131
ndn::Name
Represents an absolute name.
Definition: name.hpp:44
ndn::nfd::ControlParameters::getCount
uint64_t getCount() const
Definition: control-parameters.hpp:323
nfd
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
ndn::nfd::CONTROL_PARAMETER_COUNT
@ CONTROL_PARAMETER_COUNT
Definition: control-parameters.hpp:44
ndn::nfd::CsConfigCommand::CsConfigCommand
CsConfigCommand()
Definition: control-command.cpp:263
ndn::nfd::CONTROL_PARAMETER_STRATEGY
@ CONTROL_PARAMETER_STRATEGY
Definition: control-parameters.hpp:47
ndn::nfd::RibUnregisterCommand::validateResponse
void validateResponse(const ControlParameters &parameters) const override
validate response parameters
Definition: control-command.cpp:411
ndn::nfd::ControlCommand::~ControlCommand
virtual ~ControlCommand()
ndn::nfd::FaceUpdateCommand::FaceUpdateCommand
FaceUpdateCommand()
Definition: control-command.cpp:140
ndn::nfd::FaceCreateCommand::applyDefaultsToRequest
void applyDefaultsToRequest(ControlParameters &parameters) const override
apply default values to missing fields in request
Definition: control-command.cpp:123
ndn::nfd::ControlCommand::m_requestValidator
FieldValidator m_requestValidator
FieldValidator for request ControlParameters.
Definition: control-command.hpp:124
NDN_THROW
#define NDN_THROW(e)
Definition: exception.hpp:61
ndn::nfd::ControlParameters::setFaceId
ControlParameters & setFaceId(uint64_t faceId)
Definition: control-parameters.hpp:150
ndn::nfd::ControlCommand::FieldValidator::validate
void validate(const ControlParameters &parameters) const
verify that all required fields are present, and all present fields are either required or optional
Definition: control-command.cpp:76
ndn::nfd::ControlParameters::wireEncode
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Definition: control-parameters.cpp:50
ndn::nfd::ControlParameters::hasCount
bool hasCount() const
Definition: control-parameters.hpp:317
ndn::nfd::ControlParameters::hasCapacity
bool hasCapacity() const
Definition: control-parameters.hpp:287
ndn::nfd::ControlParameters::setOrigin
ControlParameters & setOrigin(RouteOrigin origin)
Definition: control-parameters.hpp:240
ndn::nfd::FibAddNextHopCommand::applyDefaultsToRequest
void applyDefaultsToRequest(ControlParameters &parameters) const override
apply default values to missing fields in request
Definition: control-command.cpp:214
ndn::nfd::CONTROL_PARAMETER_CAPACITY
@ CONTROL_PARAMETER_CAPACITY
Definition: control-parameters.hpp:43
ndn::nfd::CONTROL_PARAMETER_EXPIRATION_PERIOD
@ CONTROL_PARAMETER_EXPIRATION_PERIOD
Definition: control-parameters.hpp:48
ndn::nfd::FaceUpdateCommand::validateResponse
void validateResponse(const ControlParameters &parameters) const override
Definition: control-command.cpp:167
ndn::nfd::ControlParameters
represents parameters in a ControlCommand request or response
Definition: control-parameters.hpp:82
ndn::nfd::ControlCommand::FieldValidator::required
FieldValidator & required(ControlParameterField field)
declare a required field
Definition: control-command.hpp:92
ndn::nfd::ControlCommand::validateRequest
virtual void validateRequest(const ControlParameters &parameters) const
validate request parameters
Definition: control-command.cpp:36
ndn::nfd::INVALID_FACE_ID
const uint64_t INVALID_FACE_ID
Definition: nfd-constants.hpp:30
ndn::nfd::FaceCreateCommand::FaceCreateCommand
FaceCreateCommand()
Definition: control-command.cpp:99
ndn::nfd::ControlParameters::getName
const Name & getName() const
Definition: control-parameters.hpp:113
ndn::nfd::ControlCommand
base class of NFD ControlCommand
Definition: control-command.hpp:36
ndn::nfd::ControlParameters::setCost
ControlParameters & setCost(uint64_t cost)
Definition: control-parameters.hpp:270
ndn::nfd::ControlParameters::hasFaceId
bool hasFaceId() const
Definition: control-parameters.hpp:137
ndn::nfd::ControlParameters::hasCost
bool hasCost() const
Definition: control-parameters.hpp:257
ndn::nfd::ControlParameters::hasFacePersistency
bool hasFacePersistency() const
Definition: control-parameters.hpp:467
ndn::name
Definition: name-component-types.hpp:33
ndn::nfd::RibRegisterCommand::validateResponse
void validateResponse(const ControlParameters &parameters) const override
validate response parameters
Definition: control-command.cpp:377
ndn::nfd::ControlCommand::FieldValidator::optional
FieldValidator & optional(ControlParameterField field)
declare an optional field
Definition: control-command.hpp:101
ndn::nfd::ControlCommand::m_responseValidator
FieldValidator m_responseValidator
FieldValidator for response ControlParameters.
Definition: control-command.hpp:129
ndn::nfd::StrategyChoiceUnsetCommand::StrategyChoiceUnsetCommand
StrategyChoiceUnsetCommand()
Definition: control-command.cpp:316
ndn::nfd::ControlCommand::applyDefaultsToRequest
virtual void applyDefaultsToRequest(ControlParameters &parameters) const
apply default values to missing fields in request
Definition: control-command.cpp:42
ndn::nfd::ControlParameters::getCapacity
uint64_t getCapacity() const
Definition: control-parameters.hpp:293
ndn::nfd::FibRemoveNextHopCommand::applyDefaultsToRequest
void applyDefaultsToRequest(ControlParameters &parameters) const override
apply default values to missing fields in request
Definition: control-command.cpp:246
ndn::nfd::ControlParameters::getFaceId
uint64_t getFaceId() const
Definition: control-parameters.hpp:143
ndn::nfd::ControlParameters::hasMask
bool hasMask() const
Definition: control-parameters.hpp:377
ndn::nfd::RibUnregisterCommand::RibUnregisterCommand
RibUnregisterCommand()
Definition: control-command.cpp:386
ndn::nfd::FaceDestroyCommand::validateRequest
void validateRequest(const ControlParameters &parameters) const override
validate request parameters
Definition: control-command.cpp:185
ndn::nfd::ControlCommand::ControlCommand
ControlCommand(const std::string &module, const std::string &verb)
Definition: control-command.cpp:27
ndn::nfd::FibAddNextHopCommand::validateResponse
void validateResponse(const ControlParameters &parameters) const override
validate response parameters
Definition: control-command.cpp:225
ndn::nfd::FaceDestroyCommand::validateResponse
void validateResponse(const ControlParameters &parameters) const override
validate response parameters
Definition: control-command.cpp:195
ndn::nfd::StrategyChoiceUnsetCommand::validateRequest
void validateRequest(const ControlParameters &parameters) const override
validate request parameters
Definition: control-command.cpp:325
ndn::nfd::CsEraseCommand::validateResponse
void validateResponse(const ControlParameters &parameters) const override
validate response parameters
Definition: control-command.cpp:298
ndn::nfd::StrategyChoiceSetCommand::StrategyChoiceSetCommand
StrategyChoiceSetCommand()
Definition: control-command.cpp:307
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-strategy-choice-helper.hpp:34
ndn::nfd::ROUTE_FLAG_CHILD_INHERIT
@ ROUTE_FLAG_CHILD_INHERIT
Definition: nfd-constants.hpp:125
ndn::nfd::FACE_PERSISTENCY_PERSISTENT
@ FACE_PERSISTENCY_PERSISTENT
face is persistent
Definition: nfd-constants.hpp:47
ndn::nfd::ControlParameters::hasFlags
bool hasFlags() const
Definition: control-parameters.hpp:347