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 
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 
94  : ControlCommand("faces", "create")
95 {
108 }
109 
110 void
112 {
113  if (!parameters.hasFacePersistency()) {
115  }
116 }
117 
118 void
120 {
121  this->ControlCommand::validateRequest(parameters);
122 
123  if (parameters.hasFlags() != parameters.hasMask()) {
124  BOOST_THROW_EXCEPTION(ArgumentError("Flags must be accompanied by Mask"));
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 {
150 }
151 
152 void
154 {
155  if (!parameters.hasFaceId()) {
156  parameters.setFaceId(0);
157  }
158 }
159 
160 void
162 {
163  this->ControlCommand::validateRequest(parameters);
164 
165  if (parameters.hasFlags() != parameters.hasMask()) {
166  BOOST_THROW_EXCEPTION(ArgumentError("Flags must be accompanied by Mask"));
167  }
168 }
169 
170 void
172 {
173  this->ControlCommand::validateResponse(parameters);
174 
175  if (parameters.getFaceId() == INVALID_FACE_ID) {
176  BOOST_THROW_EXCEPTION(ArgumentError("FaceId must be valid"));
177  }
178 }
179 
181  : ControlCommand("faces", "destroy")
182 {
186 }
187 
188 void
190 {
191  this->ControlCommand::validateRequest(parameters);
192 
193  if (parameters.getFaceId() == INVALID_FACE_ID) {
194  BOOST_THROW_EXCEPTION(ArgumentError("FaceId must be valid"));
195  }
196 }
197 
198 void
200 {
201  this->validateRequest(parameters);
202 }
203 
205  : ControlCommand("fib", "add-nexthop")
206 {
215 }
216 
217 void
219 {
220  if (!parameters.hasFaceId()) {
221  parameters.setFaceId(0);
222  }
223  if (!parameters.hasCost()) {
224  parameters.setCost(0);
225  }
226 }
227 
228 void
230 {
231  this->ControlCommand::validateResponse(parameters);
232 
233  if (parameters.getFaceId() == INVALID_FACE_ID) {
234  BOOST_THROW_EXCEPTION(ArgumentError("FaceId must be valid"));
235  }
236 }
237 
239  : ControlCommand("fib", "remove-nexthop")
240 {
247 }
248 
249 void
251 {
252  if (!parameters.hasFaceId()) {
253  parameters.setFaceId(0);
254  }
255 }
256 
257 void
259 {
260  this->ControlCommand::validateResponse(parameters);
261 
262  if (parameters.getFaceId() == INVALID_FACE_ID) {
263  BOOST_THROW_EXCEPTION(ArgumentError("FaceId must be valid"));
264  }
265 }
266 
268  : ControlCommand("strategy-choice", "set")
269 {
274 }
275 
277  : ControlCommand("strategy-choice", "unset")
278 {
282 }
283 
284 void
286 {
287  this->ControlCommand::validateRequest(parameters);
288 
289  if (parameters.getName().size() == 0) {
290  BOOST_THROW_EXCEPTION(ArgumentError("Name must not be ndn:/"));
291  }
292 }
293 
294 void
296 {
297  this->validateRequest(parameters);
298 }
299 
301  : ControlCommand("rib", "register")
302 {
317 }
318 
319 void
321 {
322  if (!parameters.hasFaceId()) {
323  parameters.setFaceId(0);
324  }
325  if (!parameters.hasOrigin()) {
326  parameters.setOrigin(ROUTE_ORIGIN_APP);
327  }
328  if (!parameters.hasCost()) {
329  parameters.setCost(0);
330  }
331  if (!parameters.hasFlags()) {
333  }
334 }
335 
336 void
338 {
339  this->ControlCommand::validateResponse(parameters);
340 
341  if (parameters.getFaceId() == INVALID_FACE_ID) {
342  BOOST_THROW_EXCEPTION(ArgumentError("FaceId must be valid"));
343  }
344 }
345 
347  : ControlCommand("rib", "unregister")
348 {
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 }
369 
370 void
372 {
373  this->ControlCommand::validateResponse(parameters);
374 
375  if (parameters.getFaceId() == INVALID_FACE_ID) {
376  BOOST_THROW_EXCEPTION(ArgumentError("FaceId must be valid"));
377  }
378 }
379 
380 } // namespace nfd
381 } // namespace ndn
void validateResponse(const ControlParameters &parameters) const override
validate response parameters
virtual void applyDefaultsToResponse(ControlParameters &parameters) const
apply default values to missing fields in response
ControlParameters & setFaceId(uint64_t faceId)
Copyright (c) 2011-2015 Regents of the University of California.
void validate(const ControlParameters &parameters) const
verify that all required fields are present, and all present fields are either required or optional ...
void validateRequest(const ControlParameters &parameters) const override
validate request parameters
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
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
virtual void validateResponse(const ControlParameters &parameters) const
validate response parameters
void applyDefaultsToRequest(ControlParameters &parameters) const override
apply default values to missing fields in request
virtual void validateRequest(const ControlParameters &parameters) const
validate request parameters
ControlParameters & setFlags(uint64_t flags)
FieldValidator m_responseValidator
FieldValidator for response ControlParameters.
Name & append(const Component &component)
Append a component.
Definition: name.hpp:256
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
const std::vector< bool > & getPresentFields() const
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
Name getRequestName(const Name &commandPrefix, const ControlParameters &parameters) const
construct the Name for a request Interest
void validateResponse(const ControlParameters &parameters) const override
validate response parameters
FieldValidator & required(ControlParameterField field)
declare a required field
size_t size() const
Get number of components.
Definition: name.hpp:154
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
void validateRequest(const ControlParameters &parameters) const override
validate request parameters
ControlParameters & setCost(uint64_t cost)
void applyDefaultsToRequest(ControlParameters &parameters) const override
apply default values to missing fields in request
ControlParameters & setFacePersistency(FacePersistency persistency)
ControlParameters & setOrigin(RouteOrigin origin)
virtual void applyDefaultsToRequest(ControlParameters &parameters) const
apply default values to missing fields in request
represents an error in ControlParameters
const uint64_t INVALID_FACE_ID
FieldValidator & optional(ControlParameterField field)
declare an optional field