NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: 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; -*- */
22 #include "control-command.hpp"
23 #include "command-options.hpp" // only used in deprecated functions
24 
25 namespace ndn {
26 namespace nfd {
27 
28 ControlCommand::ControlCommand(const std::string& module, const std::string& verb)
29  : m_module(module)
30  , m_verb(verb)
31 {
32 }
33 
35 
36 void
38 {
39  m_requestValidator.validate(parameters);
40 }
41 
42 void
44 {
45 }
46 
47 void
49 {
50  m_responseValidator.validate(parameters);
51 }
52 
53 void
55 {
56 }
57 
58 Name
59 ControlCommand::getRequestName(const Name& commandPrefix,
60  const ControlParameters& parameters) const
61 {
62  this->validateRequest(parameters);
63 
64  Name name = commandPrefix;
65  name.append(m_module).append(m_verb);
66  name.append(parameters.wireEncode());
67  return name;
68 }
69 
71  : m_required(CONTROL_PARAMETER_UBOUND)
72  , m_optional(CONTROL_PARAMETER_UBOUND)
73 {
74 }
75 
76 void
78 {
79  const std::vector<bool>& presentFields = parameters.getPresentFields();
80 
81  for (size_t i = 0; i < CONTROL_PARAMETER_UBOUND; ++i) {
82  bool isPresent = presentFields[i];
83  if (m_required[i]) {
84  if (!isPresent) {
85  BOOST_THROW_EXCEPTION(ArgumentError(CONTROL_PARAMETER_FIELD[i] + " is required but "
86  "missing"));
87  }
88  }
89  else if (isPresent && !m_optional[i]) {
90  BOOST_THROW_EXCEPTION(ArgumentError(CONTROL_PARAMETER_FIELD[i] + " is forbidden but "
91  "present"));
92  }
93  }
94 }
95 
97  : ControlCommand("faces", "create")
98 {
109 }
110 
111 void
113 {
114  parameters.setFaceId(0);
115 
116  if (!parameters.hasFacePersistency()) {
118  }
119 }
120 
121 void
123 {
124  this->ControlCommand::validateRequest(parameters);
125 
126  if (parameters.hasFlags() != parameters.hasMask()) {
127  BOOST_THROW_EXCEPTION(ArgumentError("Flags must be accompanied by Mask"));
128  }
129 }
130 
131 void
133 {
134  this->ControlCommand::validateResponse(parameters);
135 
136  if (parameters.getFaceId() == 0) {
137  BOOST_THROW_EXCEPTION(ArgumentError("FaceId must not be zero"));
138  }
139 }
140 
142  : ControlCommand("faces", "update")
143 {
153 }
154 
155 void
157 {
158  if (!parameters.hasFaceId()) {
159  parameters.setFaceId(0);
160  }
161 }
162 
163 void
165 {
166  this->ControlCommand::validateRequest(parameters);
167 
168  if (parameters.hasFlags() != parameters.hasMask()) {
169  BOOST_THROW_EXCEPTION(ArgumentError("Flags must be accompanied by Mask"));
170  }
171 }
172 
173 void
175 {
176  this->ControlCommand::validateResponse(parameters);
177 
178  if (parameters.getFaceId() == 0) {
179  BOOST_THROW_EXCEPTION(ArgumentError("FaceId must not be zero"));
180  }
181 }
182 
184  : ControlCommand("faces", "destroy")
185 {
189 }
190 
191 void
193 {
194  this->ControlCommand::validateRequest(parameters);
195 
196  if (parameters.getFaceId() == 0) {
197  BOOST_THROW_EXCEPTION(ArgumentError("FaceId must not be zero"));
198  }
199 }
200 
201 void
203 {
204  this->validateRequest(parameters);
205 }
206 
208  : ControlCommand("faces", verb)
209 {
213 }
214 
215 void
217 {
218  this->ControlCommand::validateRequest(parameters);
219 
220  switch (parameters.getLocalControlFeature()) {
223  break;
224  default:
225  BOOST_THROW_EXCEPTION(ArgumentError("LocalControlFeature is invalid"));
226  }
227 }
228 
229 void
231 {
232  this->validateRequest(parameters);
233 }
234 
236  : FaceLocalControlCommand("enable-local-control")
237 {
238 }
239 
241  : FaceLocalControlCommand("disable-local-control")
242 {
243 }
244 
246  : ControlCommand("fib", "add-nexthop")
247 {
256 }
257 
258 void
260 {
261  if (!parameters.hasFaceId()) {
262  parameters.setFaceId(0);
263  }
264  if (!parameters.hasCost()) {
265  parameters.setCost(0);
266  }
267 }
268 
269 void
271 {
272  this->ControlCommand::validateResponse(parameters);
273 
274  if (parameters.getFaceId() == 0) {
275  BOOST_THROW_EXCEPTION(ArgumentError("FaceId must not be zero"));
276  }
277 }
278 
280  : ControlCommand("fib", "remove-nexthop")
281 {
288 }
289 
290 void
292 {
293  if (!parameters.hasFaceId()) {
294  parameters.setFaceId(0);
295  }
296 }
297 
298 void
300 {
301  this->ControlCommand::validateResponse(parameters);
302 
303  if (parameters.getFaceId() == 0) {
304  BOOST_THROW_EXCEPTION(ArgumentError("FaceId must not be zero"));
305  }
306 }
307 
309  : ControlCommand("strategy-choice", "set")
310 {
315 }
316 
318  : ControlCommand("strategy-choice", "unset")
319 {
323 }
324 
325 void
327 {
328  this->ControlCommand::validateRequest(parameters);
329 
330  if (parameters.getName().size() == 0) {
331  BOOST_THROW_EXCEPTION(ArgumentError("Name must not be ndn:/"));
332  }
333 }
334 
335 void
337 {
338  this->validateRequest(parameters);
339 }
340 
342  : ControlCommand("rib", "register")
343 {
358 }
359 
360 void
362 {
363  if (!parameters.hasFaceId()) {
364  parameters.setFaceId(0);
365  }
366  if (!parameters.hasOrigin()) {
367  parameters.setOrigin(ROUTE_ORIGIN_APP);
368  }
369  if (!parameters.hasCost()) {
370  parameters.setCost(0);
371  }
372  if (!parameters.hasFlags()) {
374  }
375 }
376 
377 void
379 {
380  this->ControlCommand::validateResponse(parameters);
381 
382  if (parameters.getFaceId() == 0) {
383  BOOST_THROW_EXCEPTION(ArgumentError("FaceId must not be zero"));
384  }
385 }
386 
388  : ControlCommand("rib", "unregister")
389 {
398 }
399 
400 void
402 {
403  if (!parameters.hasFaceId()) {
404  parameters.setFaceId(0);
405  }
406  if (!parameters.hasOrigin()) {
407  parameters.setOrigin(ROUTE_ORIGIN_APP);
408  }
409 }
410 
411 void
413 {
414  this->ControlCommand::validateResponse(parameters);
415 
416  if (parameters.getFaceId() == 0) {
417  BOOST_THROW_EXCEPTION(ArgumentError("FaceId must not be zero"));
418  }
419 }
420 
421 } // namespace nfd
422 } // namespace ndn
void validate(const ControlParameters &parameters) const
verify that all required fields are present, and all present fields are either required or optional ...
virtual 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.
virtual void validateRequest(const ControlParameters &parameters) const override
validate request parameters
virtual void applyDefaultsToRequest(ControlParameters &parameters) const override
apply default values to missing fields in request
virtual 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
virtual void applyDefaultsToRequest(ControlParameters &parameters) const override
apply default values to missing fields in request
FieldValidator m_requestValidator
FieldValidator for request ControlParameters.
virtual void applyDefaultsToRequest(ControlParameters &parameters) const override
apply default values to missing fields in request
base class of NFD ControlCommand
virtual 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 validateRequest(const ControlParameters &parameters) const override
validate request parameters
virtual void applyDefaultsToRequest(ControlParameters &parameters) const
apply default values to missing fields in request
ControlCommand(const std::string &module, const std::string &verb)
virtual void validateResponse(const ControlParameters &parameters) const override
validate response parameters
virtual void validateRequest(const ControlParameters &parameters) const override
validate request parameters
virtual void validateResponse(const ControlParameters &parameters) const override
validate response parameters
virtual void validateResponse(const ControlParameters &parameters) const override
validate response parameters
FaceLocalControlCommand(const std::string &verb)
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
virtual void validateResponse(const ControlParameters &parameters) const override
validate response parameters
FieldValidator & required(ControlParameterField field)
declare a required field
virtual void validateResponse(const ControlParameters &parameters) const override
validate response parameters
virtual void validateResponse(const ControlParameters &parameters) const override
validate response parameters
Name abstraction to represent an absolute name.
Definition: name.hpp:46
const std::string CONTROL_PARAMETER_FIELD[CONTROL_PARAMETER_UBOUND]
virtual void validateResponse(const ControlParameters &parameters) const override
virtual void validateRequest(const ControlParameters &parameters) const override
validate request parameters
const std::vector< bool > & getPresentFields() const
size_t size() const
Get the number of components.
Definition: name.hpp:400
virtual void validateRequest(const ControlParameters &parameters) const override
validate request parameters
ControlParameters & setCost(uint64_t cost)
Base class for faces/[*]-local-control commands.
virtual void applyDefaultsToRequest(ControlParameters &parameters) const override
apply default values to missing fields in request
Name & append(const uint8_t *value, size_t valueLength)
Append a new component, copying from value of length valueLength.
Definition: name.hpp:140
ControlParameters & setOrigin(uint64_t origin)
ControlParameters & setFacePersistency(FacePersistency persistency)
represents an error in ControlParameters
LocalControlFeature getLocalControlFeature() const
virtual void validateResponse(const ControlParameters &parameters) const override
validate response parameters
FieldValidator & optional(ControlParameterField field)
declare an optional field