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 
22 #include "control-command.hpp"
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 {
118 }
119 
120 void
122 {
123  if (!parameters.hasFacePersistency()) {
125  }
126 }
127 
128 void
130 {
131  this->ControlCommand::validateResponse(parameters);
132 
133  if (parameters.getFaceId() == INVALID_FACE_ID) {
134  BOOST_THROW_EXCEPTION(ArgumentError("FaceId must be valid"));
135  }
136 }
137 
139  : ControlCommand("faces", "update")
140 {
154 }
155 
156 void
158 {
159  if (!parameters.hasFaceId()) {
160  parameters.setFaceId(0);
161  }
162 }
163 
164 void
166 {
167  this->ControlCommand::validateResponse(parameters);
168 
169  if (parameters.getFaceId() == INVALID_FACE_ID) {
170  BOOST_THROW_EXCEPTION(ArgumentError("FaceId must be valid"));
171  }
172 }
173 
175  : ControlCommand("faces", "destroy")
176 {
180 }
181 
182 void
184 {
185  this->ControlCommand::validateRequest(parameters);
186 
187  if (parameters.getFaceId() == INVALID_FACE_ID) {
188  BOOST_THROW_EXCEPTION(ArgumentError("FaceId must be valid"));
189  }
190 }
191 
192 void
194 {
195  this->validateRequest(parameters);
196 }
197 
199  : ControlCommand("fib", "add-nexthop")
200 {
209 }
210 
211 void
213 {
214  if (!parameters.hasFaceId()) {
215  parameters.setFaceId(0);
216  }
217  if (!parameters.hasCost()) {
218  parameters.setCost(0);
219  }
220 }
221 
222 void
224 {
225  this->ControlCommand::validateResponse(parameters);
226 
227  if (parameters.getFaceId() == INVALID_FACE_ID) {
228  BOOST_THROW_EXCEPTION(ArgumentError("FaceId must be valid"));
229  }
230 }
231 
233  : ControlCommand("fib", "remove-nexthop")
234 {
241 }
242 
243 void
245 {
246  if (!parameters.hasFaceId()) {
247  parameters.setFaceId(0);
248  }
249 }
250 
251 void
253 {
254  this->ControlCommand::validateResponse(parameters);
255 
256  if (parameters.getFaceId() == INVALID_FACE_ID) {
257  BOOST_THROW_EXCEPTION(ArgumentError("FaceId must be valid"));
258  }
259 }
260 
262  : ControlCommand("cs", "config")
263 {
271 }
272 
274  : ControlCommand("cs", "erase")
275 {
283 }
284 
285 void
287 {
288  this->ControlCommand::validateRequest(parameters);
289 
290  if (parameters.hasCount() && parameters.getCount() == 0) {
291  BOOST_THROW_EXCEPTION(ArgumentError("Count must be positive"));
292  }
293 }
294 
295 void
297 {
298  this->ControlCommand::validateResponse(parameters);
299 
300  if (parameters.hasCapacity() && parameters.getCapacity() == 0) {
301  BOOST_THROW_EXCEPTION(ArgumentError("Capacity must be positive"));
302  }
303 }
304 
306  : ControlCommand("strategy-choice", "set")
307 {
312 }
313 
315  : ControlCommand("strategy-choice", "unset")
316 {
320 }
321 
322 void
324 {
325  this->ControlCommand::validateRequest(parameters);
326 
327  if (parameters.getName().size() == 0) {
328  BOOST_THROW_EXCEPTION(ArgumentError("Name must not be ndn:/"));
329  }
330 }
331 
332 void
334 {
335  this->validateRequest(parameters);
336 }
337 
339  : ControlCommand("rib", "register")
340 {
355 }
356 
357 void
359 {
360  if (!parameters.hasFaceId()) {
361  parameters.setFaceId(0);
362  }
363  if (!parameters.hasOrigin()) {
364  parameters.setOrigin(ROUTE_ORIGIN_APP);
365  }
366  if (!parameters.hasCost()) {
367  parameters.setCost(0);
368  }
369  if (!parameters.hasFlags()) {
371  }
372 }
373 
374 void
376 {
377  this->ControlCommand::validateResponse(parameters);
378 
379  if (parameters.getFaceId() == INVALID_FACE_ID) {
380  BOOST_THROW_EXCEPTION(ArgumentError("FaceId must be valid"));
381  }
382 }
383 
385  : ControlCommand("rib", "unregister")
386 {
395 }
396 
397 void
399 {
400  if (!parameters.hasFaceId()) {
401  parameters.setFaceId(0);
402  }
403  if (!parameters.hasOrigin()) {
404  parameters.setOrigin(ROUTE_ORIGIN_APP);
405  }
406 }
407 
408 void
410 {
411  this->ControlCommand::validateResponse(parameters);
412 
413  if (parameters.getFaceId() == INVALID_FACE_ID) {
414  BOOST_THROW_EXCEPTION(ArgumentError("FaceId must be valid"));
415  }
416 }
417 
418 } // namespace nfd
419 } // 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:42
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:154
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