NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
rib-manager.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #include "rib-manager.hpp"
27 #include "core/global-io.hpp"
28 #include "core/logger.hpp"
29 #include "core/scheduler.hpp"
30 #include <ndn-cxx/management/nfd-face-status.hpp>
31 
32 namespace nfd {
33 namespace rib {
34 
35 NFD_LOG_INIT("RibManager");
36 
37 const Name RibManager::COMMAND_PREFIX = "/localhost/nfd/rib";
38 const Name RibManager::REMOTE_COMMAND_PREFIX = "/localhop/nfd/rib";
39 const Name RibManager::FACES_LIST_DATASET_PREFIX = "/localhost/nfd/faces/list";
40 
41 const size_t RibManager::COMMAND_UNSIGNED_NCOMPS =
42  RibManager::COMMAND_PREFIX.size() +
43  1 + // verb
44  1; // verb options
45 
46 const size_t RibManager::COMMAND_SIGNED_NCOMPS =
47  RibManager::COMMAND_UNSIGNED_NCOMPS +
48  4; // (timestamp, nonce, signed info tlv, signature tlv)
49 
50 const RibManager::SignedVerbAndProcessor RibManager::SIGNED_COMMAND_VERBS[] =
51  {
52  SignedVerbAndProcessor(
53  Name::Component("register"),
54  &RibManager::registerEntry
55  ),
56 
57  SignedVerbAndProcessor(
58  Name::Component("unregister"),
59  &RibManager::unregisterEntry
60  ),
61  };
62 
63 const RibManager::UnsignedVerbAndProcessor RibManager::UNSIGNED_COMMAND_VERBS[] =
64  {
65  UnsignedVerbAndProcessor(
66  Name::Component("list"),
67  &RibManager::listEntries
68  ),
69  };
70 
71 const Name RibManager::LIST_COMMAND_PREFIX("/localhost/nfd/rib/list");
72 const size_t RibManager::LIST_COMMAND_NCOMPS = LIST_COMMAND_PREFIX.size();
73 
74 const time::seconds RibManager::ACTIVE_FACE_FETCH_INTERVAL = time::seconds(300);
75 
76 RibManager::RibManager(ndn::Face& face, ndn::KeyChain& keyChain)
77  : m_face(face)
78  , m_keyChain(keyChain)
79  , m_nfdController(m_face, m_keyChain)
80  , m_localhostValidator(m_face)
81  , m_localhopValidator(m_face)
82  , m_faceMonitor(m_face)
83  , m_isLocalhopEnabled(false)
84  , m_remoteRegistrator(m_nfdController, m_keyChain, m_managedRib)
85  , m_ribStatusPublisher(m_managedRib, face, LIST_COMMAND_PREFIX, m_keyChain)
86  , m_fibUpdater(m_managedRib, m_nfdController)
87  , m_signedVerbDispatch(SIGNED_COMMAND_VERBS,
88  SIGNED_COMMAND_VERBS +
89  (sizeof(SIGNED_COMMAND_VERBS) / sizeof(SignedVerbAndProcessor)))
90  , m_unsignedVerbDispatch(UNSIGNED_COMMAND_VERBS,
91  UNSIGNED_COMMAND_VERBS +
92  (sizeof(UNSIGNED_COMMAND_VERBS) / sizeof(UnsignedVerbAndProcessor)))
93 {
94 }
95 
97 {
98  scheduler::cancel(m_activeFaceFetchEvent);
99 }
100 
101 void
102 RibManager::startListening(const Name& commandPrefix, const ndn::OnInterest& onRequest)
103 {
104  NFD_LOG_INFO("Listening on: " << commandPrefix);
105 
106  m_nfdController.start<ndn::nfd::FibAddNextHopCommand>(
108  .setName(commandPrefix)
109  .setFaceId(0),
110  bind(&RibManager::onNrdCommandPrefixAddNextHopSuccess, this, cref(commandPrefix), _1),
111  bind(&RibManager::onNrdCommandPrefixAddNextHopError, this, cref(commandPrefix), _2));
112 
113  m_face.setInterestFilter(commandPrefix, onRequest);
114 }
115 
116 void
118 {
119  //check whether the components of localhop and localhost prefixes are same
120  BOOST_ASSERT(COMMAND_PREFIX.size() == REMOTE_COMMAND_PREFIX.size());
121 
122  this->startListening(COMMAND_PREFIX, bind(&RibManager::onLocalhostRequest, this, _2));
123 
124  if (m_isLocalhopEnabled) {
125  this->startListening(REMOTE_COMMAND_PREFIX,
126  bind(&RibManager::onLocalhopRequest, this, _2));
127  }
128 
129  NFD_LOG_INFO("Start monitoring face create/destroy events");
130  m_faceMonitor.onNotification.connect(bind(&RibManager::onNotification, this, _1));
131  m_faceMonitor.start();
132 
133  scheduleActiveFaceFetch(ACTIVE_FACE_FETCH_INTERVAL);
134 }
135 
136 void
138 {
139  configFile.addSectionHandler("rib",
140  bind(&RibManager::onConfig, this, _1, _2, _3));
141 }
142 
143 void
144 RibManager::onConfig(const ConfigSection& configSection,
145  bool isDryRun,
146  const std::string& filename)
147 {
148  bool isRemoteRegisterEnabled = false;
149 
150  for (const auto& item : configSection) {
151  if (item.first == "localhost_security") {
152  m_localhostValidator.load(item.second, filename);
153  }
154  else if (item.first == "localhop_security") {
155  m_localhopValidator.load(item.second, filename);
156  m_isLocalhopEnabled = true;
157  }
158  else if (item.first == "remote_register") {
159  m_remoteRegistrator.loadConfig(item.second);
160  isRemoteRegisterEnabled = true;
161 
162  // Avoid other actions when isDryRun == true
163  if (isDryRun) {
164  continue;
165  }
166 
167  m_remoteRegistrator.enable();
168  }
169  else {
170  BOOST_THROW_EXCEPTION(Error("Unrecognized rib property: " + item.first));
171  }
172  }
173 
174  if (!isRemoteRegisterEnabled) {
175  m_remoteRegistrator.disable();
176  }
177 }
178 
179 void
180 RibManager::sendResponse(const Name& name,
181  const ControlResponse& response)
182 {
183  const Block& encodedControl = response.wireEncode();
184 
185  shared_ptr<Data> responseData = make_shared<Data>(name);
186  responseData->setContent(encodedControl);
187 
188  m_keyChain.sign(*responseData);
189  m_face.put(*responseData);
190 }
191 
192 void
193 RibManager::sendResponse(const Name& name,
194  uint32_t code,
195  const std::string& text)
196 {
197  ControlResponse response(code, text);
198  sendResponse(name, response);
199 }
200 
201 void
202 RibManager::onLocalhostRequest(const Interest& request)
203 {
204  const Name& command = request.getName();
205  const Name::Component& verb = command.get(COMMAND_PREFIX.size());
206 
207  UnsignedVerbDispatchTable::const_iterator unsignedVerbProcessor = m_unsignedVerbDispatch.find(verb);
208 
209  if (unsignedVerbProcessor != m_unsignedVerbDispatch.end()) {
210  NFD_LOG_DEBUG("command result: processing unsigned verb: " << verb);
211  (unsignedVerbProcessor->second)(this, request);
212  }
213  else {
214  m_localhostValidator.validate(request,
215  bind(&RibManager::onCommandValidated, this, _1),
216  bind(&RibManager::onCommandValidationFailed, this, _1, _2));
217  }
218 }
219 
220 void
221 RibManager::onLocalhopRequest(const Interest& request)
222 {
223  m_localhopValidator.validate(request,
224  bind(&RibManager::onCommandValidated, this, _1),
225  bind(&RibManager::onCommandValidationFailed, this, _1, _2));
226 }
227 
228 void
229 RibManager::onCommandValidated(const shared_ptr<const Interest>& request)
230 {
231  // REMOTE_COMMAND_PREFIX number of componenets are same as
232  // NRD_COMMAND_PREFIX's so no extra checks are required.
233 
234  const Name& command = request->getName();
235  const Name::Component& verb = command[COMMAND_PREFIX.size()];
236  const Name::Component& parameterComponent = command[COMMAND_PREFIX.size() + 1];
237 
238  SignedVerbDispatchTable::const_iterator verbProcessor = m_signedVerbDispatch.find(verb);
239 
240  if (verbProcessor != m_signedVerbDispatch.end()) {
241 
242  ControlParameters parameters;
243  if (!extractParameters(parameterComponent, parameters)) {
244  NFD_LOG_DEBUG("command result: malformed verb: " << verb);
245 
246  if (static_cast<bool>(request)) {
247  sendResponse(command, 400, "Malformed command");
248  }
249 
250  return;
251  }
252 
253  NFD_LOG_DEBUG("command result: processing verb: " << verb);
254  (verbProcessor->second)(this, request, parameters);
255  }
256  else {
257  NFD_LOG_DEBUG("Unsupported command: " << verb);
258 
259  if (static_cast<bool>(request)) {
260  sendResponse(request->getName(), 501, "Unsupported command");
261  }
262  }
263 }
264 
265 void
266 RibManager::registerEntry(const shared_ptr<const Interest>& request,
267  ControlParameters& parameters)
268 {
270 
271  if (!validateParameters(command, parameters)) {
272  NFD_LOG_DEBUG("register result: FAIL reason: malformed");
273 
274  if (static_cast<bool>(request)) {
275  sendResponse(request->getName(), 400, "Malformed command");
276  }
277 
278  return;
279  }
280 
281  bool isSelfRegistration = (!parameters.hasFaceId() || parameters.getFaceId() == 0);
282  if (isSelfRegistration) {
283  parameters.setFaceId(request->getIncomingFaceId());
284  }
285 
286  // Respond since command is valid and authorized
287  sendSuccessResponse(request, parameters);
288 
289  Route route;
290  route.faceId = parameters.getFaceId();
291  route.origin = parameters.getOrigin();
292  route.cost = parameters.getCost();
293  route.flags = parameters.getFlags();
294 
295  if (parameters.hasExpirationPeriod() &&
296  parameters.getExpirationPeriod() != time::milliseconds::max())
297  {
298  route.expires = time::steady_clock::now() + parameters.getExpirationPeriod();
299 
300  // Schedule a new event, the old one will be cancelled during rib insertion.
302  bind(&Rib::onRouteExpiration, &m_managedRib, parameters.getName(), route));
303 
304  NFD_LOG_TRACE("Scheduled unregistration at: " << route.expires <<
305  " with EventId: " << eventId);
306 
307  // Set the NewEventId of this entry
308  route.setExpirationEvent(eventId);
309  }
310  else {
311  route.expires = time::steady_clock::TimePoint::max();
312  }
313 
314  NFD_LOG_INFO("Adding route " << parameters.getName() << " nexthop=" << route.faceId
315  << " origin=" << route.origin
316  << " cost=" << route.cost);
317 
318  RibUpdate update;
320  .setName(parameters.getName())
321  .setRoute(route);
322 
323  m_managedRib.beginApplyUpdate(update,
324  bind(&RibManager::onRibUpdateSuccess, this, update),
325  bind(&RibManager::onRibUpdateFailure, this, update, _1, _2));
326 
327  m_registeredFaces.insert(route.faceId);
328 }
329 
330 void
331 RibManager::unregisterEntry(const shared_ptr<const Interest>& request,
332  ControlParameters& params)
333 {
335 
336  // Passing all parameters gives error in validation,
337  // so passing only the required arguments.
338  ControlParameters parameters;
339  parameters.setName(params.getName());
340 
341  if (params.hasFaceId()) {
342  parameters.setFaceId(params.getFaceId());
343  }
344 
345  if (params.hasOrigin()) {
346  parameters.setOrigin(params.getOrigin());
347  }
348 
349  if (!validateParameters(command, parameters)) {
350  NFD_LOG_DEBUG("unregister result: FAIL reason: malformed");
351 
352  if (static_cast<bool>(request)) {
353  sendResponse(request->getName(), 400, "Malformed command");
354  }
355 
356  return;
357  }
358 
359  bool isSelfRegistration = (!parameters.hasFaceId() || parameters.getFaceId() == 0);
360  if (isSelfRegistration) {
361  parameters.setFaceId(request->getIncomingFaceId());
362  }
363 
364  // Respond since command is valid and authorized
365  sendSuccessResponse(request, parameters);
366 
367  Route route;
368  route.faceId = parameters.getFaceId();
369  route.origin = parameters.getOrigin();
370 
371  NFD_LOG_INFO("Removing route " << parameters.getName() << " nexthop=" << route.faceId
372  << " origin=" << route.origin);
373 
374  RibUpdate update;
376  .setName(parameters.getName())
377  .setRoute(route);
378 
379  m_managedRib.beginApplyUpdate(update,
380  bind(&RibManager::onRibUpdateSuccess, this, update),
381  bind(&RibManager::onRibUpdateFailure, this, update, _1, _2));
382 }
383 
384 void
385 RibManager::onCommandValidationFailed(const shared_ptr<const Interest>& request,
386  const std::string& failureInfo)
387 {
388  NFD_LOG_DEBUG("RibRequestValidationFailed: " << failureInfo);
389 
390  if (static_cast<bool>(request)) {
391  sendResponse(request->getName(), 403, failureInfo);
392  }
393 }
394 
395 
396 bool
397 RibManager::extractParameters(const Name::Component& parameterComponent,
398  ControlParameters& extractedParameters)
399 {
400  try {
401  Block rawParameters = parameterComponent.blockFromValue();
402  extractedParameters.wireDecode(rawParameters);
403  }
404  catch (const tlv::Error&) {
405  return false;
406  }
407 
408  NFD_LOG_DEBUG("Parameters parsed OK");
409  return true;
410 }
411 
412 bool
413 RibManager::validateParameters(const ControlCommand& command,
414  ControlParameters& parameters)
415 {
416  try {
417  command.validateRequest(parameters);
418  }
419  catch (const ControlCommand::ArgumentError&) {
420  return false;
421  }
422 
423  command.applyDefaultsToRequest(parameters);
424 
425  return true;
426 }
427 
428 void
429 RibManager::onCommandError(uint32_t code, const std::string& error,
430  const shared_ptr<const Interest>& request,
431  const Route& route)
432 {
433  NFD_LOG_ERROR("NFD returned an error: " << error << " (code: " << code << ")");
434 
435  ControlResponse response;
436 
437  if (code == 404) {
438  response.setCode(code);
439  response.setText(error);
440  }
441  else {
442  response.setCode(533);
443  std::ostringstream os;
444  os << "Failure to update NFD " << "(NFD Error: " << code << " " << error << ")";
445  response.setText(os.str());
446  }
447 
448  if (static_cast<bool>(request)) {
449  sendResponse(request->getName(), response);
450  }
451 }
452 
453 void
454 RibManager::onRegSuccess(const shared_ptr<const Interest>& request,
455  const ControlParameters& parameters,
456  const Route& route)
457 {
458  ControlResponse response;
459 
460  response.setCode(200);
461  response.setText("Success");
462  response.setBody(parameters.wireEncode());
463 
464  NFD_LOG_TRACE("onRegSuccess: registered " << route);
465 
466  if (static_cast<bool>(request)) {
467  sendResponse(request->getName(), response);
468  }
469 }
470 
471 
472 void
473 RibManager::onUnRegSuccess(const shared_ptr<const Interest>& request,
474  const ControlParameters& parameters,
475  const Route& route)
476 {
477  ControlResponse response;
478 
479  response.setCode(200);
480  response.setText("Success");
481  response.setBody(parameters.wireEncode());
482 
483  NFD_LOG_TRACE("onUnRegSuccess: unregistered " << route);
484 
485  if (static_cast<bool>(request)) {
486  sendResponse(request->getName(), response);
487  }
488 }
489 
490 void
491 RibManager::sendSuccessResponse(const shared_ptr<const Interest>& request,
492  const ControlParameters& parameters)
493 {
494  if (!static_cast<bool>(request)) {
495  return;
496  }
497 
498  ControlResponse response;
499 
500  response.setCode(200);
501  response.setText("Success");
502  response.setBody(parameters.wireEncode());
503 
504  if (static_cast<bool>(request)) {
505  sendResponse(request->getName(), response);
506  }
507 }
508 
509 void
510 RibManager::sendErrorResponse(uint32_t code, const std::string& error,
511  const shared_ptr<const Interest>& request)
512 {
513  NFD_LOG_ERROR("NFD returned an error: " << error << " (code: " << code << ")");
514 
515  if (!static_cast<bool>(request)) {
516  return;
517  }
518 
519  ControlResponse response;
520 
521  if (code == 404) {
522  response.setCode(code);
523  response.setText(error);
524  }
525  else {
526  response.setCode(533);
527  std::ostringstream os;
528  os << "Failure to update NFD " << "(NFD Error: " << code << " " << error << ")";
529  response.setText(os.str());
530  }
531 
532  if (static_cast<bool>(request)) {
533  sendResponse(request->getName(), response);
534  }
535 }
536 
537 void
539 {
540  NFD_LOG_DEBUG("RIB update succeeded for " << update);
541 }
542 
543 void
544 RibManager::onRibUpdateFailure(const RibUpdate& update, uint32_t code, const std::string& error)
545 {
546  NFD_LOG_DEBUG("RIB update failed for " << update << " (code: " << code
547  << ", error: " << error << ")");
548 
549  // Since the FIB rejected the update, clean up invalid routes
550  scheduleActiveFaceFetch(time::seconds(1));
551 }
552 
553 void
554 RibManager::onNrdCommandPrefixAddNextHopSuccess(const Name& prefix,
555  const ndn::nfd::ControlParameters& result)
556 {
557  NFD_LOG_DEBUG("Successfully registered " + prefix.toUri() + " with NFD");
558 
559  // Routes must be inserted into the RIB so route flags can be applied
560  Route route;
561  route.faceId = result.getFaceId();
562  route.origin = ndn::nfd::ROUTE_ORIGIN_APP;
563  route.expires = time::steady_clock::TimePoint::max();
565 
566  m_managedRib.insert(prefix, route);
567 
568  m_registeredFaces.insert(route.faceId);
569 }
570 
571 void
572 RibManager::onNrdCommandPrefixAddNextHopError(const Name& name, const std::string& msg)
573 {
574  BOOST_THROW_EXCEPTION(Error("Error in setting interest filter (" + name.toUri() + "): " + msg));
575 }
576 
577 void
578 RibManager::onControlHeaderSuccess()
579 {
580  NFD_LOG_DEBUG("Local control header enabled");
581 }
582 
583 void
584 RibManager::onControlHeaderError(uint32_t code, const std::string& reason)
585 {
586  std::ostringstream os;
587  os << "Couldn't enable local control header "
588  << "(code: " << code << ", info: " << reason << ")";
589  BOOST_THROW_EXCEPTION(Error(os.str()));
590 }
591 
592 void
594 {
597  .setLocalControlFeature(ndn::nfd::LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID),
598  bind(&RibManager::onControlHeaderSuccess, this),
599  bind(&RibManager::onControlHeaderError, this, _1, _2));
600 }
601 
602 void
603 RibManager::onNotification(const FaceEventNotification& notification)
604 {
605  NFD_LOG_TRACE("onNotification: " << notification);
606 
607  if (notification.getKind() == ndn::nfd::FACE_EVENT_DESTROYED) {
608  NFD_LOG_DEBUG("Received notification for destroyed faceId: " << notification.getFaceId());
609 
610  scheduler::schedule(time::seconds(0),
611  bind(&RibManager::onFaceDestroyedEvent, this, notification.getFaceId()));
612  }
613 }
614 
615 void
616 RibManager::onFaceDestroyedEvent(uint64_t faceId)
617 {
618  m_managedRib.beginRemoveFace(faceId);
619  m_registeredFaces.erase(faceId);
620 }
621 
622 void
623 RibManager::listEntries(const Interest& request)
624 {
625  const Name& command = request.getName();
626  const size_t commandNComps = command.size();
627 
628  if (commandNComps < LIST_COMMAND_NCOMPS || !LIST_COMMAND_PREFIX.isPrefixOf(command)) {
629  NFD_LOG_DEBUG("command result: malformed");
630 
631  sendResponse(command, 400, "Malformed command");
632  return;
633  }
634 
635  m_ribStatusPublisher.publish();
636 }
637 
638 void
639 RibManager::scheduleActiveFaceFetch(const time::seconds& timeToWait)
640 {
641  scheduler::cancel(m_activeFaceFetchEvent);
642 
643  m_activeFaceFetchEvent = scheduler::schedule(timeToWait,
644  bind(&RibManager::fetchActiveFaces, this));
645 }
646 
647 void
648 RibManager::fetchActiveFaces()
649 {
650  NFD_LOG_DEBUG("Fetching active faces");
651 
652  Interest interest(FACES_LIST_DATASET_PREFIX);
653  interest.setChildSelector(1);
654  interest.setMustBeFresh(true);
655 
656  shared_ptr<ndn::OBufferStream> buffer = make_shared<ndn::OBufferStream>();
657 
658  m_face.expressInterest(interest,
659  bind(&RibManager::fetchSegments, this, _2, buffer),
660  bind(&RibManager::onFetchFaceStatusTimeout, this));
661 }
662 
663 void
664 RibManager::fetchSegments(const Data& data, shared_ptr<ndn::OBufferStream> buffer)
665 {
666  buffer->write(reinterpret_cast<const char*>(data.getContent().value()),
667  data.getContent().value_size());
668 
669  uint64_t currentSegment = data.getName().get(-1).toSegment();
670 
671  const name::Component& finalBlockId = data.getMetaInfo().getFinalBlockId();
672 
673  if (finalBlockId.empty() || finalBlockId.toSegment() > currentSegment) {
674  m_face.expressInterest(data.getName().getPrefix(-1).appendSegment(currentSegment+1),
675  bind(&RibManager::fetchSegments, this, _2, buffer),
676  bind(&RibManager::onFetchFaceStatusTimeout, this));
677  }
678  else {
679  removeInvalidFaces(buffer);
680  }
681 }
682 
683 void
684 RibManager::removeInvalidFaces(shared_ptr<ndn::OBufferStream> buffer)
685 {
686  NFD_LOG_DEBUG("Checking for invalid face registrations");
687 
688  ndn::ConstBufferPtr buf = buffer->buf();
689 
690  Block block;
691  size_t offset = 0;
692  FaceIdSet activeFaces;
693 
694  while (offset < buf->size()) {
695  bool isOk = false;
696  std::tie(isOk, block) = Block::fromBuffer(buf, offset);
697  if (!isOk) {
698  std::cerr << "ERROR: cannot decode FaceStatus TLV" << std::endl;
699  break;
700  }
701 
702  offset += block.size();
703 
704  ndn::nfd::FaceStatus status(block);
705  activeFaces.insert(status.getFaceId());
706  }
707 
708  // Look for face IDs that were registered but not active to find missed
709  // face destroyed events
710  for (uint64_t faceId : m_registeredFaces) {
711  if (activeFaces.find(faceId) == activeFaces.end()) {
712  NFD_LOG_DEBUG("Removing invalid face ID: " << faceId);
713 
714  scheduler::schedule(time::seconds(0),
715  bind(&RibManager::onFaceDestroyedEvent, this, faceId));
716  }
717  }
718 
719  // Reschedule the check for future clean up
720  scheduleActiveFaceFetch(ACTIVE_FACE_FETCH_INTERVAL);
721 }
722 
723 void
724 RibManager::onFetchFaceStatusTimeout()
725 {
726  std::cerr << "Face Status Dataset request timed out" << std::endl;
727  scheduleActiveFaceFetch(ACTIVE_FACE_FETCH_INTERVAL);
728 }
729 
730 } // namespace rib
731 } // namespace nfd
void start(const ControlParameters &parameters, const CommandSucceedCallback &onSuccess, const CommandFailCallback &onFailure, const CommandOptions &options=CommandOptions())
start command execution
ControlParameters & setFaceId(uint64_t faceId)
virtual void wireDecode(const Block &wire) final
const Name & getName() const
Definition: interest.hpp:216
void load(const std::string &filename)
#define NFD_LOG_DEBUG(expression)
Definition: logger.hpp:36
static std::tuple< bool, Block > fromBuffer(ConstBufferPtr buffer, size_t offset)
Try to construct block from Buffer.
Definition: block.cpp:253
represents a fib/add-nexthop command
void setExpirationEvent(const scheduler::EventId eid)
Definition: route.hpp:55
void beginApplyUpdate(const RibUpdate &update, const UpdateSuccessCallback &onSuccess, const UpdateFailureCallback &onFailure)
passes the provided RibUpdateBatch to FibUpdater to calculate and send FibUpdates.
Definition: rib.cpp:338
RibManager(ndn::Face &face, ndn::KeyChain &keyChain)
Definition: rib-manager.cpp:76
Interest & setMustBeFresh(bool mustBeFresh)
Definition: interest.hpp:418
represents parameters in a ControlCommand request or response
time::steady_clock::TimePoint expires
Definition: route.hpp:83
void cancel(const EventId &eventId)
cancel a scheduled event
Definition: scheduler.cpp:58
static time_point now() noexcept
Definition: time.cpp:79
void disable()
disable remote registration/unregistration.
base class of NFD ControlCommand
void loadConfig(const ConfigSection &configSection)
load the "remote_register" section from config file
virtual void validateRequest(const ControlParameters &parameters) const
validate request parameters
represents a Face status change notification
uint64_t cost
Definition: route.hpp:82
uint64_t faceId
Definition: route.hpp:79
Class representing a wire element of NDN-TLV packet format.
Definition: block.hpp:43
represents an Interest packet
Definition: interest.hpp:45
#define NFD_LOG_ERROR(expression)
Definition: logger.hpp:38
void start()
start or resume receiving notifications
function< void(const InterestFilter &, const Interest &)> OnInterest
Callback called when incoming Interest matches the specified InterestFilter.
Definition: face.hpp:75
std::shared_ptr< ns3::EventId > EventId
Definition: scheduler.hpp:39
void onRibUpdateSuccess(const RibUpdate &update)
const MetaInfo & getMetaInfo() const
Get MetaInfo block from Data packet.
Definition: data.hpp:349
signal::Signal< NotificationSubscriber, Notification > onNotification
fires when a Notification is received
const Name & getName() const
Get name of the Data packet.
Definition: data.hpp:343
represents a faces/enable-local-control command
size_t size() const
Definition: block.cpp:504
std::string toUri() const
Encode this name as a URI.
Definition: name.cpp:183
size_t wireEncode(EncodingImpl< TAG > &encoder) const
ndn::mgmt::ControlResponse ControlResponse
void insert(const Name &prefix, const Route &route)
Definition: rib.cpp:84
#define NFD_LOG_INFO(expression)
Definition: logger.hpp:37
void validate(const Data &data, const OnDataValidated &onValidated, const OnDataValidationFailed &onValidationFailed)
Validate Data and call either onValidated or onValidationFailed.
Definition: validator.hpp:82
Block blockFromValue() const
Definition: block.cpp:437
uint64_t toSegment() const
Interpret as segment number component using NDN naming conventions.
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:38
void addSectionHandler(const std::string &sectionName, ConfigSectionHandler subscriber)
setup notification of configuration file sections
Definition: config-file.cpp:61
const RegisteredPrefixId * setInterestFilter(const InterestFilter &interestFilter, const OnInterest &onInterest, const RegisterPrefixFailureCallback &onFailure, const security::SigningInfo &signingInfo=security::SigningInfo(), uint64_t flags=nfd::ROUTE_FLAG_CHILD_INHERIT)
Set InterestFilter to dispatch incoming matching interest to onInterest callback and register the fil...
Definition: face.cpp:121
Interest & setChildSelector(int childSelector)
Definition: interest.hpp:404
Name & appendSegment(uint64_t segmentNo)
Append segment number (sequential) using NDN naming conventions.
Definition: name.cpp:232
uint64_t origin
Definition: route.hpp:80
RibUpdate & setAction(Action action)
Definition: rib-update.hpp:81
represents a route for a name prefix
Definition: route.hpp:37
Abstraction to communicate with local or remote NDN forwarder.
Definition: face.hpp:100
represents Face status
uint64_t getFaceId() const
size_t size() const
Get the number of components.
Definition: name.hpp:408
boost::property_tree::ptree ConfigSection
EventId schedule(const time::nanoseconds &after, const std::function< void()> &event)
schedule an event
Definition: scheduler.cpp:50
Name abstraction to represent an absolute name.
Definition: name.hpp:46
const PendingInterestId * expressInterest(const Interest &interest, const OnData &onData, const OnTimeout &onTimeout=OnTimeout())
Express Interest.
Definition: face.cpp:63
size_t value_size() const
Definition: block.cpp:529
represents a rib/unregister command
void beginRemoveFace(uint64_t faceId)
starts the FIB update process when a face has been destroyed
Definition: rib.cpp:350
represents a rib/register command
ControlResponse & setText(const std::string &text)
Component holds a read-only name component value.
ControlResponse & setBody(const Block &body)
const time::milliseconds & getExpirationPeriod() const
void enable()
enable remote registration/unregistration.
#define NFD_LOG_INIT(name)
Definition: logger.hpp:33
uint64_t flags
Definition: route.hpp:81
const Block & getContent() const
Get content Block.
Definition: data.cpp:230
RibUpdate & setName(const Name &name)
Definition: rib-update.hpp:94
ControlParameters & setOrigin(uint64_t origin)
#define NFD_LOG_TRACE(expression)
Definition: logger.hpp:35
ControlParameters & setName(const Name &name)
void onRouteExpiration(const Name &prefix, const Route &route)
Definition: rib.cpp:187
bool isPrefixOf(const Name &name) const
Check if the N components of this name are the same as the first N components of the given name...
Definition: name.cpp:320
const uint8_t * value() const
Definition: block.cpp:520
PartialName getPrefix(ssize_t nComponents) const
Extract a prefix (PartialName) of the name, containing first nComponents components.
Definition: name.hpp:249
virtual void applyDefaultsToRequest(ControlParameters &parameters) const
apply default values to missing fields in request
represents an error in ControlParameters
shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:33
represents a Data packet
Definition: data.hpp:39
void onRibUpdateFailure(const RibUpdate &update, uint32_t code, const std::string &error)
const name::Component & getFinalBlockId() const
Definition: meta-info.hpp:214
const Component & get(ssize_t i) const
Get the component at the given index.
Definition: name.hpp:419
ControlResponse & setCode(uint32_t code)
represents an error in TLV encoding or decoding
Definition: tlv.hpp:50
void put(const Data &data)
Publish data packet.
Definition: face.cpp:87
void setConfigFile(ConfigFile &configFile)