NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
nfd-control-command.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #include "nfd-control-command.hpp"
23 #include "nfd-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 
34 void
36 {
37  m_requestValidator.validate(parameters);
38 }
39 
40 void
42 {
43 }
44 
45 void
47 {
48  m_responseValidator.validate(parameters);
49 }
50 
51 void
53 {
54 }
55 
56 Name
57 ControlCommand::getRequestName(const Name& commandPrefix,
58  const ControlParameters& parameters) const
59 {
60  this->validateRequest(parameters);
61 
62  Name name = commandPrefix;
63  name.append(m_module).append(m_verb);
64  name.append(parameters.wireEncode());
65  return name;
66 }
67 
69  : m_required(CONTROL_PARAMETER_UBOUND)
70  , m_optional(CONTROL_PARAMETER_UBOUND)
71 {
72 }
73 
74 void
76 {
77  const std::vector<bool>& presentFields = parameters.getPresentFields();
78 
79  for (size_t i = 0; i < CONTROL_PARAMETER_UBOUND; ++i) {
80  bool isPresent = presentFields[i];
81  if (m_required[i]) {
82  if (!isPresent) {
83  BOOST_THROW_EXCEPTION(ArgumentError(CONTROL_PARAMETER_FIELD[i] + " is required but "
84  "missing"));
85  }
86  }
87  else if (isPresent && !m_optional[i]) {
88  BOOST_THROW_EXCEPTION(ArgumentError(CONTROL_PARAMETER_FIELD[i] + " is forbidden but "
89  "present"));
90  }
91  }
92 }
93 
95  : ControlCommand("faces", "create")
96 {
104 }
105 
106 void
108 {
109  if (!parameters.hasFacePersistency()) {
111  }
112 }
113 
114 void
116 {
117  this->ControlCommand::validateResponse(parameters);
118 
119  if (parameters.getFaceId() == 0) {
120  BOOST_THROW_EXCEPTION(ArgumentError("FaceId must not be zero"));
121  }
122 }
123 
125  : ControlCommand("faces", "destroy")
126 {
130 }
131 
132 void
134 {
135  this->ControlCommand::validateRequest(parameters);
136 
137  if (parameters.getFaceId() == 0) {
138  BOOST_THROW_EXCEPTION(ArgumentError("FaceId must not be zero"));
139  }
140 }
141 
142 void
144 {
145  this->validateRequest(parameters);
146 }
147 
149  : ControlCommand("faces", verb)
150 {
154 }
155 
156 void
158 {
159  this->ControlCommand::validateRequest(parameters);
160 
161  switch (parameters.getLocalControlFeature()) {
164  break;
165  default:
166  BOOST_THROW_EXCEPTION(ArgumentError("LocalControlFeature is invalid"));
167  }
168 }
169 
170 void
172 {
173  this->validateRequest(parameters);
174 }
175 
177  : FaceLocalControlCommand("enable-local-control")
178 {
179 }
180 
182  : FaceLocalControlCommand("disable-local-control")
183 {
184 }
185 
187  : ControlCommand("fib", "add-nexthop")
188 {
197 }
198 
199 void
201 {
202  if (!parameters.hasFaceId()) {
203  parameters.setFaceId(0);
204  }
205  if (!parameters.hasCost()) {
206  parameters.setCost(0);
207  }
208 }
209 
210 void
212 {
213  this->ControlCommand::validateResponse(parameters);
214 
215  if (parameters.getFaceId() == 0) {
216  BOOST_THROW_EXCEPTION(ArgumentError("FaceId must not be zero"));
217  }
218 }
219 
221  : ControlCommand("fib", "remove-nexthop")
222 {
229 }
230 
231 void
233 {
234  if (!parameters.hasFaceId()) {
235  parameters.setFaceId(0);
236  }
237 }
238 
239 void
241 {
242  this->ControlCommand::validateResponse(parameters);
243 
244  if (parameters.getFaceId() == 0) {
245  BOOST_THROW_EXCEPTION(ArgumentError("FaceId must not be zero"));
246  }
247 }
248 
250  : ControlCommand("strategy-choice", "set")
251 {
256 }
257 
259  : ControlCommand("strategy-choice", "unset")
260 {
264 }
265 
266 void
268 {
269  this->ControlCommand::validateRequest(parameters);
270 
271  if (parameters.getName().size() == 0) {
272  BOOST_THROW_EXCEPTION(ArgumentError("Name must not be ndn:/"));
273  }
274 }
275 
276 void
278 {
279  this->validateRequest(parameters);
280 }
281 
283  : ControlCommand("rib", "register")
284 {
299 }
300 
301 void
303 {
304  if (!parameters.hasFaceId()) {
305  parameters.setFaceId(0);
306  }
307  if (!parameters.hasOrigin()) {
308  parameters.setOrigin(ROUTE_ORIGIN_APP);
309  }
310  if (!parameters.hasCost()) {
311  parameters.setCost(0);
312  }
313  if (!parameters.hasFlags()) {
315  }
316 }
317 
318 void
320 {
321  this->ControlCommand::validateResponse(parameters);
322 
323  if (parameters.getFaceId() == 0) {
324  BOOST_THROW_EXCEPTION(ArgumentError("FaceId must not be zero"));
325  }
326 }
327 
329  : ControlCommand("rib", "unregister")
330 {
339 }
340 
341 void
343 {
344  if (!parameters.hasFaceId()) {
345  parameters.setFaceId(0);
346  }
347  if (!parameters.hasOrigin()) {
348  parameters.setOrigin(ROUTE_ORIGIN_APP);
349  }
350 }
351 
352 void
354 {
355  this->ControlCommand::validateResponse(parameters);
356 
357  if (parameters.getFaceId() == 0) {
358  BOOST_THROW_EXCEPTION(ArgumentError("FaceId must not be zero"));
359  }
360 }
361 
362 } // namespace nfd
363 } // namespace ndn
void validate(const ControlParameters &parameters) const
verify that all required fields are present, and all present fields are either required or optional ...
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 applyDefaultsToRequest(ControlParameters &parameters) const
apply default values to missing fields in request
virtual void applyDefaultsToRequest(ControlParameters &parameters) const
apply default values to missing fields in request
represents parameters in a ControlCommand request or response
virtual void validateRequest(const ControlParameters &parameters) const
validate request parameters
virtual void validateResponse(const ControlParameters &parameters) const
validate response parameters
size_t wireEncode(EncodingImpl< TAG > &encoder) const
virtual void validateResponse(const ControlParameters &parameters) const
validate response parameters
FieldValidator m_requestValidator
FieldValidator for request ControlParameters.
base class of NFD ControlCommand
virtual void validateResponse(const ControlParameters &parameters) const
validate response parameters
virtual void validateResponse(const ControlParameters &parameters) const
validate response parameters
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
ControlCommand(const std::string &module, const std::string &verb)
virtual void validateRequest(const ControlParameters &parameters) const
validate request 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
validate response parameters
FieldValidator & required(ControlParameterField field)
declare a required field
Name abstraction to represent an absolute name.
Definition: name.hpp:46
const std::string CONTROL_PARAMETER_FIELD[CONTROL_PARAMETER_UBOUND]
const std::vector< bool > & getPresentFields() const
virtual void validateResponse(const ControlParameters &parameters) const
validate response parameters
size_t size() const
Get the number of components.
Definition: name.hpp:408
virtual void validateResponse(const ControlParameters &parameters) const
validate response parameters
virtual void validateResponse(const ControlParameters &parameters) const
validate response parameters
virtual void applyDefaultsToRequest(ControlParameters &parameters) const
apply default values to missing fields in request
ControlParameters & setCost(uint64_t cost)
virtual void validateResponse(const ControlParameters &parameters) const
validate response parameters
Base class for faces/[*]-local-control commands.
Name & append(const uint8_t *value, size_t valueLength)
Append a new component, copying from value of length valueLength.
Definition: name.hpp:148
ControlParameters & setOrigin(uint64_t origin)
ControlParameters & setFacePersistency(FacePersistency persistency)
represents an error in ControlParameters
LocalControlFeature getLocalControlFeature() const
virtual void applyDefaultsToRequest(ControlParameters &parameters) const
apply default values to missing fields in request
virtual void applyDefaultsToRequest(ControlParameters &parameters) const
apply default values to missing fields in request
virtual void validateRequest(const ControlParameters &parameters) const
validate request parameters
FieldValidator & optional(ControlParameterField field)
declare an optional field