NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: 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 {
102 }
103 
104 void
106 {
107  this->ControlCommand::validateResponse(parameters);
108 
109  if (parameters.getFaceId() == 0) {
110  BOOST_THROW_EXCEPTION(ArgumentError("FaceId must not be zero"));
111  }
112 }
113 
115  : ControlCommand("faces", "destroy")
116 {
120 }
121 
122 void
124 {
125  this->ControlCommand::validateRequest(parameters);
126 
127  if (parameters.getFaceId() == 0) {
128  BOOST_THROW_EXCEPTION(ArgumentError("FaceId must not be zero"));
129  }
130 }
131 
132 void
134 {
135  this->validateRequest(parameters);
136 }
137 
139  : ControlCommand("faces", verb)
140 {
144 }
145 
146 void
148 {
149  this->ControlCommand::validateRequest(parameters);
150 
151  switch (parameters.getLocalControlFeature()) {
154  break;
155  default:
156  BOOST_THROW_EXCEPTION(ArgumentError("LocalControlFeature is invalid"));
157  }
158 }
159 
160 void
162 {
163  this->validateRequest(parameters);
164 }
165 
167  : FaceLocalControlCommand("enable-local-control")
168 {
169 }
170 
172  : FaceLocalControlCommand("disable-local-control")
173 {
174 }
175 
177  : ControlCommand("fib", "add-nexthop")
178 {
187 }
188 
189 void
191 {
192  if (!parameters.hasFaceId()) {
193  parameters.setFaceId(0);
194  }
195  if (!parameters.hasCost()) {
196  parameters.setCost(0);
197  }
198 }
199 
200 void
202 {
203  this->ControlCommand::validateResponse(parameters);
204 
205  if (parameters.getFaceId() == 0) {
206  BOOST_THROW_EXCEPTION(ArgumentError("FaceId must not be zero"));
207  }
208 }
209 
211  : ControlCommand("fib", "remove-nexthop")
212 {
219 }
220 
221 void
223 {
224  if (!parameters.hasFaceId()) {
225  parameters.setFaceId(0);
226  }
227 }
228 
229 void
231 {
232  this->ControlCommand::validateResponse(parameters);
233 
234  if (parameters.getFaceId() == 0) {
235  BOOST_THROW_EXCEPTION(ArgumentError("FaceId must not be zero"));
236  }
237 }
238 
240  : ControlCommand("strategy-choice", "set")
241 {
246 }
247 
249  : ControlCommand("strategy-choice", "unset")
250 {
254 }
255 
256 void
258 {
259  this->ControlCommand::validateRequest(parameters);
260 
261  if (parameters.getName().size() == 0) {
262  BOOST_THROW_EXCEPTION(ArgumentError("Name must not be ndn:/"));
263  }
264 }
265 
266 void
268 {
269  this->validateRequest(parameters);
270 }
271 
273  : ControlCommand("rib", "register")
274 {
289 }
290 
291 void
293 {
294  if (!parameters.hasFaceId()) {
295  parameters.setFaceId(0);
296  }
297  if (!parameters.hasOrigin()) {
298  parameters.setOrigin(ROUTE_ORIGIN_APP);
299  }
300  if (!parameters.hasCost()) {
301  parameters.setCost(0);
302  }
303  if (!parameters.hasFlags()) {
305  }
306 }
307 
308 void
310 {
311  this->ControlCommand::validateResponse(parameters);
312 
313  if (parameters.getFaceId() == 0) {
314  BOOST_THROW_EXCEPTION(ArgumentError("FaceId must not be zero"));
315  }
316 }
317 
319  : ControlCommand("rib", "unregister")
320 {
329 }
330 
331 void
333 {
334  if (!parameters.hasFaceId()) {
335  parameters.setFaceId(0);
336  }
337  if (!parameters.hasOrigin()) {
338  parameters.setOrigin(ROUTE_ORIGIN_APP);
339  }
340 }
341 
342 void
344 {
345  this->ControlCommand::validateResponse(parameters);
346 
347  if (parameters.getFaceId() == 0) {
348  BOOST_THROW_EXCEPTION(ArgumentError("FaceId must not be zero"));
349  }
350 }
351 
352 } // namespace nfd
353 } // 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.
ControlParameters & setOrigin(uint64_t origin)
represents an error in ControlParameters
LocalControlFeature getLocalControlFeature() const
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