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-2018 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  BOOST_THROW_EXCEPTION(ArgumentError(CONTROL_PARAMETER_FIELD[i] + " is required but missing"));
85  }
86  }
87  else if (isPresent && !m_optional[i]) {
88  BOOST_THROW_EXCEPTION(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  BOOST_THROW_EXCEPTION(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  BOOST_THROW_EXCEPTION(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  BOOST_THROW_EXCEPTION(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  BOOST_THROW_EXCEPTION(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  BOOST_THROW_EXCEPTION(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  BOOST_THROW_EXCEPTION(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  BOOST_THROW_EXCEPTION(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  BOOST_THROW_EXCEPTION(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  BOOST_THROW_EXCEPTION(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  BOOST_THROW_EXCEPTION(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  BOOST_THROW_EXCEPTION(ArgumentError("FaceId must be valid"));
417  }
418 }
419 
420 } // namespace nfd
421 } // namespace ndn
void validate(const ControlParameters &parameters) const
verify that all required fields are present, and all present fields are either required or optional
void validateResponse(const ControlParameters &parameters) const override
validate response parameters
ControlParameters & setFaceId(uint64_t faceId)
virtual void applyDefaultsToResponse(ControlParameters &parameters) const
apply default values to missing fields in response
Copyright (c) 2011-2015 Regents of the University of California.
void applyDefaultsToRequest(ControlParameters &parameters) const override
apply default values to missing fields in request
void applyDefaultsToRequest(ControlParameters &parameters) const override
apply default values to missing fields in request
represents parameters in a ControlCommand request or response
virtual void validateResponse(const ControlParameters &parameters) const
validate response parameters
size_t wireEncode(EncodingImpl< TAG > &encoder) const
void applyDefaultsToRequest(ControlParameters &parameters) const override
apply default values to missing fields in request
FieldValidator m_requestValidator
FieldValidator for request ControlParameters.
void applyDefaultsToRequest(ControlParameters &parameters) const override
apply default values to missing fields in request
base class of NFD ControlCommand
void applyDefaultsToRequest(ControlParameters &parameters) const override
apply default values to missing fields in request
ControlParameters & setFlags(uint64_t flags)
FieldValidator m_responseValidator
FieldValidator for response ControlParameters.
virtual void validateRequest(const ControlParameters &parameters) const
validate request parameters
virtual void applyDefaultsToRequest(ControlParameters &parameters) const
apply default values to missing fields in request
void validateResponse(const ControlParameters &parameters) const override
validate response parameters
ControlCommand(const std::string &module, const std::string &verb)
void validateResponse(const ControlParameters &parameters) const override
validate response parameters
void validateRequest(const ControlParameters &parameters) const override
validate request parameters
void validateResponse(const ControlParameters &parameters) const override
validate response parameters
void validateResponse(const ControlParameters &parameters) const override
validate response parameters
Name getRequestName(const Name &commandPrefix, const ControlParameters &parameters) const
construct the Name for a request Interest
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
void validateResponse(const ControlParameters &parameters) const override
validate response parameters
FieldValidator & required(ControlParameterField field)
declare a required field
void validateResponse(const ControlParameters &parameters) const override
validate response parameters
void validateResponse(const ControlParameters &parameters) const override
validate response parameters
Represents an absolute name.
Definition: name.hpp:43
const std::string CONTROL_PARAMETER_FIELD[CONTROL_PARAMETER_UBOUND]
void validateResponse(const ControlParameters &parameters) const override
void validateRequest(const ControlParameters &parameters) const override
validate request parameters
const std::vector< bool > & getPresentFields() const
size_t size() const
Get number of components.
Definition: name.hpp:147
ControlParameters & setCost(uint64_t cost)
void validateRequest(const ControlParameters &parameters) const override
validate request parameters
void applyDefaultsToRequest(ControlParameters &parameters) const override
apply default values to missing fields in request
ControlParameters & setFacePersistency(FacePersistency persistency)
ControlParameters & setOrigin(RouteOrigin origin)
represents an error in ControlParameters
const uint64_t INVALID_FACE_ID
FieldValidator & optional(ControlParameterField field)
declare an optional field