nlsr.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #include "nlsr.hpp"
23 #include "adjacent.hpp"
24 #include "logger.hpp"
25 
26 #include <cstdlib>
27 #include <string>
28 #include <sstream>
29 #include <cstdio>
30 #include <unistd.h>
31 #include <vector>
32 
33 #include <ndn-cxx/net/face-uri.hpp>
34 #include <ndn-cxx/signature.hpp>
35 
36 namespace nlsr {
37 
38 INIT_LOGGER(Nlsr);
39 
40 const ndn::Name Nlsr::LOCALHOST_PREFIX = ndn::Name("/localhost/nlsr");
41 
42 Nlsr::Nlsr(boost::asio::io_service& ioService, ndn::Scheduler& scheduler, ndn::Face& face, ndn::KeyChain& keyChain)
43  : m_nlsrFace(face)
44  , m_scheduler(scheduler)
45  , m_keyChain(keyChain)
46  , m_confParam()
47  , m_adjacencyList()
48  , m_namePrefixList()
49  , m_configFileName("nlsr.conf")
50  , m_nlsrLsdb(*this, scheduler)
51  , m_adjBuildCount(0)
52  , m_isBuildAdjLsaSheduled(false)
53  , m_isRouteCalculationScheduled(false)
54  , m_isRoutingTableCalculating(false)
55  , m_routingTable(scheduler)
56  , m_fib(m_nlsrFace, scheduler, m_adjacencyList, m_confParam, m_keyChain)
57  , m_namePrefixTable(*this, m_routingTable.afterRoutingChange)
58  , m_dispatcher(m_nlsrFace, m_keyChain)
59  , m_datasetHandler(m_nlsrLsdb,
60  m_routingTable,
61  m_dispatcher,
62  m_nlsrFace,
63  m_keyChain)
64  , m_helloProtocol(*this, scheduler)
65  , m_validator(ndn::make_unique<ndn::security::v2::CertificateFetcherDirectFetch>(m_nlsrFace))
66  , m_controller(m_nlsrFace, m_keyChain)
67  , m_faceDatasetController(m_nlsrFace, m_keyChain)
68  , m_prefixUpdateProcessor(m_dispatcher,
69  m_nlsrFace,
70  m_namePrefixList,
71  m_nlsrLsdb)
72  , m_nfdRibCommandProcessor(m_dispatcher,
73  m_namePrefixList,
74  m_nlsrLsdb)
75  , m_statsCollector(m_nlsrLsdb, m_helloProtocol)
76  , m_faceMonitor(m_nlsrFace)
77  , m_firstHelloInterval(FIRST_HELLO_INTERVAL_DEFAULT)
78 {
79  m_faceMonitor.onNotification.connect(std::bind(&Nlsr::onFaceEventNotification, this, _1));
80  m_faceMonitor.start();
81 }
82 
83 void
84 Nlsr::registrationFailed(const ndn::Name& name)
85 {
86  NLSR_LOG_ERROR("ERROR: Failed to register prefix in local hub's daemon");
87  BOOST_THROW_EXCEPTION(Error("Error: Prefix registration failed"));
88 }
89 
90 void
91 Nlsr::onRegistrationSuccess(const ndn::Name& name)
92 {
93  NLSR_LOG_DEBUG("Successfully registered prefix: " << name);
94 }
95 
96 void
98 {
99  ndn::Name name(m_confParam.getRouterPrefix());
100  name.append("NLSR");
101  name.append("INFO");
102 
103  NLSR_LOG_DEBUG("Setting interest filter for Hello interest: " << name);
104 
105  getNlsrFace().setInterestFilter(name,
107  &m_helloProtocol, _1, _2),
108  std::bind(&Nlsr::onRegistrationSuccess, this, _1),
109  std::bind(&Nlsr::registrationFailed, this, _1),
110  m_signingInfo,
111  ndn::nfd::ROUTE_FLAG_CAPTURE);
112 }
113 
114 void
116 {
117  ndn::Name name = m_confParam.getLsaPrefix();
118 
119  NLSR_LOG_DEBUG("Setting interest filter for LsaPrefix: " << name);
120 
121  getNlsrFace().setInterestFilter(name,
122  std::bind(&Lsdb::processInterest,
123  &m_nlsrLsdb, _1, _2),
124  std::bind(&Nlsr::onRegistrationSuccess, this, _1),
125  std::bind(&Nlsr::registrationFailed, this, _1),
126  m_signingInfo,
127  ndn::nfd::ROUTE_FLAG_CAPTURE);
128 }
129 
130 
131 void
132 Nlsr::addDispatcherTopPrefix(const ndn::Name& topPrefix)
133 {
134  try {
135  m_dispatcher.addTopPrefix(topPrefix, false, m_signingInfo);
136  }
137  catch (const std::exception& e) {
138  NLSR_LOG_ERROR("Error setting top-level prefix in dispatcher: " << e.what() << "\n");
139  }
140 }
141 
142 void
144 {
145  const std::string strategy("ndn:/localhost/nfd/strategy/multicast");
146 
147  m_fib.setStrategy(m_confParam.getLsaPrefix(), strategy, 0);
148  m_fib.setStrategy(m_confParam.getChronosyncPrefix(), strategy, 0);
149 }
150 
151 void
152 Nlsr::canonizeContinuation(std::list<Adjacent>::iterator iterator,
153  std::function<void(void)> finally)
154 {
155  canonizeNeighborUris(iterator, [this, finally] (std::list<Adjacent>::iterator iterator) {
156  canonizeContinuation(iterator, finally);
157  },
158  finally);
159 }
160 
161 void
162 Nlsr::canonizeNeighborUris(std::list<Adjacent>::iterator currentNeighbor,
163  std::function<void(std::list<Adjacent>::iterator)> then,
164  std::function<void(void)> finally)
165 {
166  if (currentNeighbor != m_adjacencyList.getAdjList().end()) {
167  ndn::FaceUri uri(currentNeighbor->getFaceUri());
168  uri.canonize([this, then, currentNeighbor] (ndn::FaceUri canonicalUri) {
169  NLSR_LOG_DEBUG("Canonized URI: " << currentNeighbor->getFaceUri()
170  << " to: " << canonicalUri);
171  currentNeighbor->setFaceUri(canonicalUri);
172  then(std::next(currentNeighbor));
173  },
174  [this, then, currentNeighbor] (const std::string& reason) {
175  NLSR_LOG_ERROR("Could not canonize URI: " << currentNeighbor->getFaceUri()
176  << " because: " << reason);
177  then(std::next(currentNeighbor));
178  },
179  m_nlsrFace.getIoService(),
181  }
182  // We have finished canonizing all neighbors, so call finally()
183  else {
184  finally();
185  }
186 }
187 
188 void
189 Nlsr::loadCertToPublish(const ndn::security::v2::Certificate& certificate)
190 {
191  NLSR_LOG_TRACE("Loading cert to publish.");
192  m_certStore.insert(certificate);
193  m_validator.loadAnchor("Authoritative-Certificate",
194  ndn::security::v2::Certificate(certificate));
195  m_prefixUpdateProcessor.getValidator().
196  loadAnchor("Authoritative-Certificate",
197  ndn::security::v2::Certificate(certificate));
198 }
199 
200 void
201 Nlsr::connectToFetcher(ndn::util::SegmentFetcher& fetcher)
202 {
203  NLSR_LOG_TRACE("NLSR: Connect to SegmentFetcher.");
204 
205  fetcher.afterSegmentValidated.connect(std::bind(&Nlsr::afterFetcherSignalEmitted,
206  this, _1));
207 }
208 
209 void
210 Nlsr::afterFetcherSignalEmitted(const ndn::Data& lsaSegment)
211 {
212  NLSR_LOG_TRACE("SegmentFetcher fetched a data segment. Start inserting cert to own cert store.");
213  ndn::Name keyName = lsaSegment.getSignature().getKeyLocator().getName();
214  if (getCertificate(keyName) == nullptr) {
215  publishCertFromCache(keyName);
216  }
217  else {
218  NLSR_LOG_TRACE("Certificate is already in the store: " << keyName);
219  }
220 }
221 
222 void
223 Nlsr::publishCertFromCache(const ndn::Name& keyName)
224 {
225  const ndn::security::v2::Certificate* cert = m_validator.getUnverifiedCertCache()
226  .find(keyName);
227  if (cert != nullptr) {
228  m_certStore.insert(*cert);
229  NLSR_LOG_TRACE(*cert);
230  NLSR_LOG_TRACE("Setting interest filter for: "
231  << ndn::security::v2::extractKeyNameFromCertName(cert->getName()));
232  m_nlsrFace.setInterestFilter(ndn::security::v2::extractKeyNameFromCertName(cert->getName()),
233  std::bind(&Nlsr::onKeyInterest,
234  this, _1, _2),
235  std::bind(&Nlsr::onKeyPrefixRegSuccess, this, _1),
236  std::bind(&Nlsr::registrationFailed, this, _1),
237  m_signingInfo,
238  ndn::nfd::ROUTE_FLAG_CAPTURE);
239 
240  if (!cert->getKeyName().equals(cert->getSignature().getKeyLocator().getName())) {
241  publishCertFromCache(cert->getSignature().getKeyLocator().getName());
242  }
243  }
244  else {
245  NLSR_LOG_TRACE("Cert for " << keyName << " was not found in the Validator's cache. ");
246  }
247 }
248 
249 void
251 {
252  NLSR_LOG_DEBUG("Initializing Nlsr");
253  m_confParam.buildRouterPrefix();
254  m_datasetHandler.setRouterNameCommandPrefix(m_confParam.getRouterPrefix());
255  m_nlsrLsdb.setLsaRefreshTime(ndn::time::seconds(m_confParam.getLsaRefreshTime()));
256  m_nlsrLsdb.setThisRouterPrefix(m_confParam.getRouterPrefix().toUri());
257  m_fib.setEntryRefreshTime(2 * m_confParam.getLsaRefreshTime());
258 
259  m_nlsrLsdb.getSequencingManager().setSeqFileDirectory(m_confParam.getSeqFileDir());
261 
262  m_nlsrLsdb.getSyncLogicHandler().createSyncSocket(m_confParam.getChronosyncPrefix(),
263  m_confParam.getSyncInterestLifetime());
264 
265  // Logging start
266  m_confParam.writeLog();
267  m_adjacencyList.writeLog();
268  NLSR_LOG_DEBUG(m_namePrefixList);
269  // Logging end
270 
271  initializeKey();
272  setStrategies();
273 
274  NLSR_LOG_DEBUG("Default NLSR identity: " << m_signingInfo.getSignerName());
275 
278 
279  // add top-level prefixes: router and localhost prefix
282 
283  initializeFaces(std::bind(&Nlsr::processFaceDataset, this, _1),
284  std::bind(&Nlsr::onFaceDatasetFetchTimeout, this, _1, _2, 0));
285 
286  enableIncomingFaceIdIndication();
287 
288  // Set event intervals
289  setFirstHelloInterval(m_confParam.getFirstHelloInterval());
290  m_nlsrLsdb.setAdjLsaBuildInterval(m_confParam.getAdjLsaBuildInterval());
291  m_routingTable.setRoutingCalcInterval(m_confParam.getRoutingCalcInterval());
292 
293  m_nlsrLsdb.buildAndInstallOwnNameLsa();
294 
295  // Install coordinate LSAs if using HR or dry-run HR.
296  if (m_confParam.getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
297  m_nlsrLsdb.buildAndInstallOwnCoordinateLsa();
298  }
299 
300  registerKeyPrefix();
301  registerLocalhostPrefix();
302 
303  m_helloProtocol.scheduleInterest(m_firstHelloInterval);
304 
305  // Need to set direct neighbors' costs to 0 for hyperbolic routing
306  if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON) {
307 
308  std::list<Adjacent>& neighbors = m_adjacencyList.getAdjList();
309 
310  for (std::list<Adjacent>::iterator it = neighbors.begin(); it != neighbors.end(); ++it) {
311  it->setLinkCost(0);
312  }
313  }
314 }
315 
316 void
318 {
319  NLSR_LOG_DEBUG("Initializing Key ...");
320 
321  ndn::Name nlsrInstanceName = m_confParam.getRouterPrefix();
322  nlsrInstanceName.append("NLSR");
323 
324  try {
325  m_keyChain.deleteIdentity(m_keyChain.getPib().getIdentity(nlsrInstanceName));
326  } catch (const std::exception& e) {
327  NLSR_LOG_WARN(e.what());
328  }
329 
330  auto nlsrInstanceIdentity = m_keyChain.createIdentity(nlsrInstanceName);
331  auto nlsrInstanceKey = nlsrInstanceIdentity.getDefaultKey();
332 
333  ndn::security::v2::Certificate certificate;
334 
335  ndn::Name certificateName = nlsrInstanceKey.getName();
336  certificateName.append("NA");
337  certificateName.appendVersion();
338  certificate.setName(certificateName);
339 
340  // set metainfo
341  certificate.setContentType(ndn::tlv::ContentType_Key);
342  certificate.setFreshnessPeriod(ndn::time::days(365));
343 
344  // set content
345  certificate.setContent(nlsrInstanceKey.getPublicKey().data(), nlsrInstanceKey.getPublicKey().size());
346 
347  // set signature-info
348  ndn::SignatureInfo signatureInfo;
349  signatureInfo.setValidityPeriod(ndn::security::ValidityPeriod(ndn::time::system_clock::TimePoint(),
350  ndn::time::system_clock::now()
351  + ndn::time::days(365)));
352  try {
353  m_keyChain.sign(certificate,
354  ndn::security::SigningInfo(m_keyChain.getPib().getIdentity(m_confParam.getRouterPrefix()))
355  .setSignatureInfo(signatureInfo));
356  }
357  catch (const std::exception& e) {
358  NLSR_LOG_WARN("ERROR: Router's " << e.what()
359  << "NLSR is running without security."
360  << " If security is enabled NLSR will not converge.");
361 
362  std::cerr << "Router's " << e.what() << ". NLSR is running without security "
363  << "(Only for testing, should not be used in production.)"
364  << " If security is enabled NLSR will not converge." << std::endl;
365  }
366 
367  m_signingInfo = ndn::security::SigningInfo(ndn::security::SigningInfo::SIGNER_TYPE_ID,
368  nlsrInstanceName);
369 
370  loadCertToPublish(certificate);
371 
372  m_defaultCertName = certificate.getName();
373 }
374 
375 void
376 Nlsr::registerKeyPrefix()
377 {
378  // Start listening for the interest of this router's NLSR certificate
379  ndn::Name nlsrKeyPrefix = getConfParameter().getRouterPrefix();
380  nlsrKeyPrefix.append("NLSR");
381  nlsrKeyPrefix.append("KEY");
382 
383  m_nlsrFace.setInterestFilter(nlsrKeyPrefix,
384  std::bind(&Nlsr::onKeyInterest,
385  this, _1, _2),
386  std::bind(&Nlsr::onKeyPrefixRegSuccess, this, _1),
387  std::bind(&Nlsr::registrationFailed, this, _1),
388  m_signingInfo,
389  ndn::nfd::ROUTE_FLAG_CAPTURE);
390 
391  // Start listening for the interest of this router's certificate
392  ndn::Name routerKeyPrefix = getConfParameter().getRouterPrefix();
393  routerKeyPrefix.append("KEY");
394 
395  m_nlsrFace.setInterestFilter(routerKeyPrefix,
396  std::bind(&Nlsr::onKeyInterest,
397  this, _1, _2),
398  std::bind(&Nlsr::onKeyPrefixRegSuccess, this, _1),
399  std::bind(&Nlsr::registrationFailed, this, _1),
400  m_signingInfo,
401  ndn::nfd::ROUTE_FLAG_CAPTURE);
402 
403  // Start listening for the interest of this router's operator's certificate
404  ndn::Name operatorKeyPrefix = getConfParameter().getNetwork();
405  operatorKeyPrefix.append(getConfParameter().getSiteName());
406  operatorKeyPrefix.append(std::string("%C1.Operator"));
407 
408  m_nlsrFace.setInterestFilter(operatorKeyPrefix,
409  std::bind(&Nlsr::onKeyInterest,
410  this, _1, _2),
411  std::bind(&Nlsr::onKeyPrefixRegSuccess, this, _1),
412  std::bind(&Nlsr::registrationFailed, this, _1),
413  m_signingInfo,
414  ndn::nfd::ROUTE_FLAG_CAPTURE);
415 
416  // Start listening for the interest of this router's site's certificate
417  ndn::Name siteKeyPrefix = getConfParameter().getNetwork();
418  siteKeyPrefix.append(getConfParameter().getSiteName());
419  siteKeyPrefix.append("KEY");
420 
421  m_nlsrFace.setInterestFilter(siteKeyPrefix,
422  std::bind(&Nlsr::onKeyInterest,
423  this, _1, _2),
424  std::bind(&Nlsr::onKeyPrefixRegSuccess, this, _1),
425  std::bind(&Nlsr::registrationFailed, this, _1),
426  m_signingInfo,
427  ndn::nfd::ROUTE_FLAG_CAPTURE);
428 }
429 
430 void
431 Nlsr::registerLocalhostPrefix()
432 {
433  m_nlsrFace.registerPrefix(LOCALHOST_PREFIX,
434  std::bind(&Nlsr::onRegistrationSuccess, this, _1),
435  std::bind(&Nlsr::registrationFailed, this, _1));
436 }
437 
438 void
439 Nlsr::onKeyInterest(const ndn::Name& name, const ndn::Interest& interest)
440 {
441  NLSR_LOG_DEBUG("Got interest for certificate. Interest: " << interest.getName());
442 
443  const ndn::Name& interestName = interest.getName();
444  const ndn::security::v2::Certificate* cert = getCertificate(interestName);
445 
446  if (cert == nullptr) {
447  NLSR_LOG_DEBUG("Certificate is not found for: " << interest);
448  return; // cert is not found
449  }
450 
451  m_nlsrFace.put(*cert);
452 }
453 
454 void
455 Nlsr::onKeyPrefixRegSuccess(const ndn::Name& name)
456 {
457  NLSR_LOG_DEBUG("KEY prefix: " << name << " registration is successful.");
458 }
459 
460 void
461 Nlsr::onFaceEventNotification(const ndn::nfd::FaceEventNotification& faceEventNotification)
462 {
463  NLSR_LOG_TRACE("Nlsr::onFaceEventNotification called");
464 
465  switch (faceEventNotification.getKind()) {
466  case ndn::nfd::FACE_EVENT_DESTROYED: {
467  uint64_t faceId = faceEventNotification.getFaceId();
468 
469  auto adjacent = m_adjacencyList.findAdjacent(faceId);
470 
471  if (adjacent != m_adjacencyList.end()) {
472  NLSR_LOG_DEBUG("Face to " << adjacent->getName() << " with face id: " << faceId << " destroyed");
473 
474  adjacent->setFaceId(0);
475 
476  // Only trigger an Adjacency LSA build if this node is changing
477  // from ACTIVE to INACTIVE since this rebuild will effectively
478  // cancel the previous Adjacency LSA refresh event and schedule
479  // a new one further in the future.
480  //
481  // Continuously scheduling the refresh in the future will block
482  // the router from refreshing its Adjacency LSA. Since other
483  // routers' Name prefixes' expiration times are updated when
484  // this router refreshes its Adjacency LSA, the other routers'
485  // prefixes will expire and be removed from the RIB.
486  //
487  // This check is required to fix Bug #2733 for now. This check
488  // would be unnecessary to fix Bug #2733 when Issue #2732 is
489  // completed, but the check also helps with optimization so it
490  // can remain even when Issue #2732 is implemented.
491  if (adjacent->getStatus() == Adjacent::STATUS_ACTIVE) {
492  adjacent->setStatus(Adjacent::STATUS_INACTIVE);
493 
494  // A new adjacency LSA cannot be built until the neighbor is marked INACTIVE and
495  // has met the HELLO retry threshold
496  adjacent->setInterestTimedOutNo(m_confParam.getInterestRetryNumber());
497 
498  if (m_confParam.getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
500  }
501  else {
502  m_nlsrLsdb.scheduleAdjLsaBuild();
503  }
504  }
505  }
506  break;
507  }
508  case ndn::nfd::FACE_EVENT_CREATED: {
509  // Find the neighbor in our adjacency list
510  ndn::FaceUri faceUri;
511  try {
512  faceUri = ndn::FaceUri(faceEventNotification.getRemoteUri());
513  }
514  catch (const std::exception& e) {
515  NLSR_LOG_WARN(e.what());
516  return;
517  }
518  auto adjacent = m_adjacencyList.findAdjacent(faceUri);
519 
520  // If we have a neighbor by that FaceUri and it has no FaceId, we
521  // have a match.
522  if (adjacent != m_adjacencyList.end()) {
523  NLSR_LOG_DEBUG("Face creation event matches neighbor: " << adjacent->getName()
524  << ". New Face ID: " << faceEventNotification.getFaceId()
525  << ". Registering prefixes.");
526  adjacent->setFaceId(faceEventNotification.getFaceId());
527 
528  registerAdjacencyPrefixes(*adjacent, ndn::time::milliseconds::max());
529 
530  if (m_confParam.getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
532  }
533  else {
534  m_nlsrLsdb.scheduleAdjLsaBuild();
535  }
536  }
537  break;
538  }
539  default:
540  break;
541  }
542 }
543 
544 void
546  const FetchDatasetTimeoutCallback& onFetchFailure)
547 {
548  NLSR_LOG_TRACE("Initializing Faces...");
549 
550  m_faceDatasetController.fetch<ndn::nfd::FaceDataset>(onFetchSuccess, onFetchFailure);
551 
552 }
553 
554 void
555 Nlsr::processFaceDataset(const std::vector<ndn::nfd::FaceStatus>& faces)
556 {
557  NLSR_LOG_DEBUG("Processing face dataset");
558 
559  // Iterate over each neighbor listed in nlsr.conf
560  for (auto& adjacent : m_adjacencyList.getAdjList()) {
561 
562  const std::string faceUriString = adjacent.getFaceUri().toString();
563  // Check the list of FaceStatus objects we got for a match
564  for (const ndn::nfd::FaceStatus& faceStatus : faces) {
565  // Set the adjacency FaceID if we find a URI match and it was
566  // previously unset. Change the boolean to true.
567  if (adjacent.getFaceId() == 0 && faceUriString == faceStatus.getRemoteUri()) {
568  NLSR_LOG_DEBUG("FaceUri: " << faceStatus.getRemoteUri() <<
569  " FaceId: "<< faceStatus.getFaceId());
570  adjacent.setFaceId(faceStatus.getFaceId());
571  // Register the prefixes for each neighbor
572  this->registerAdjacencyPrefixes(adjacent, ndn::time::milliseconds::max());
573  }
574  }
575  // If this adjacency has no information in this dataset, then one
576  // of two things is happening: 1. NFD is starting slowly and this
577  // Face wasn't ready yet, or 2. NFD is configured
578  // incorrectly and this Face isn't available.
579  if (adjacent.getFaceId() == 0) {
580  NLSR_LOG_WARN("The adjacency " << adjacent.getName() <<
581  " has no Face information in this dataset.");
582  }
583  }
584 
585  scheduleDatasetFetch();
586 }
587 
588 void
590  const ndn::time::milliseconds& timeout)
591 {
592  ndn::FaceUri faceUri = adj.getFaceUri();
593  double linkCost = adj.getLinkCost();
594  const ndn::Name& adjName = adj.getName();
595 
596  m_fib.registerPrefix(adjName, faceUri, linkCost,
597  timeout, ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
598 
599  m_fib.registerPrefix(m_confParam.getChronosyncPrefix(),
600  faceUri, linkCost, timeout,
601  ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
602 
603  m_fib.registerPrefix(m_confParam.getLsaPrefix(),
604  faceUri, linkCost, timeout,
605  ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
606 }
607 
608 void
610  const std::string& msg,
611  uint32_t nRetriesSoFar)
612 {
613  NLSR_LOG_DEBUG("onFaceDatasetFetchTimeout");
614  // If we have exceeded the maximum attempt count, do not try again.
615  if (nRetriesSoFar++ < m_confParam.getFaceDatasetFetchTries()) {
616  NLSR_LOG_DEBUG("Failed to fetch dataset: " << msg << ". Attempting retry #" << nRetriesSoFar);
617  m_faceDatasetController.fetch<ndn::nfd::FaceDataset>(std::bind(&Nlsr::processFaceDataset,
618  this, _1),
620  this, _1, _2, nRetriesSoFar));
621  }
622  else {
623  NLSR_LOG_ERROR("Failed to fetch dataset: " << msg << ". Exceeded limit of " <<
624  m_confParam.getFaceDatasetFetchTries() << ", so not trying again this time.");
625  // If we fail to fetch it, just do nothing until the next
626  // interval. Since this is a backup mechanism, we aren't as
627  // concerned with retrying.
628  scheduleDatasetFetch();
629  }
630 }
631 
632 void
633 Nlsr::scheduleDatasetFetch()
634 {
635  NLSR_LOG_DEBUG("Scheduling Dataset Fetch in " << m_confParam.getFaceDatasetFetchInterval());
636 
637  m_scheduler.scheduleEvent(m_confParam.getFaceDatasetFetchInterval(),
638  [this] {
639  this->initializeFaces(
640  [this] (const std::vector<ndn::nfd::FaceStatus>& faces) {
641  this->processFaceDataset(faces);
642  },
643  [this] (uint32_t code, const std::string& msg) {
644  this->onFaceDatasetFetchTimeout(code, msg, 0);
645  });
646  });
647 }
648 
649 void
650 Nlsr::enableIncomingFaceIdIndication()
651 {
652  NLSR_LOG_DEBUG("Enabling incoming face id indication for local face.");
653 
654  m_controller.start<ndn::nfd::FaceUpdateCommand>(
655  ndn::nfd::ControlParameters()
656  .setFlagBit(ndn::nfd::FaceFlagBit::BIT_LOCAL_FIELDS_ENABLED, true),
657  bind(&Nlsr::onFaceIdIndicationSuccess, this, _1),
658  bind(&Nlsr::onFaceIdIndicationFailure, this, _1));
659 }
660 
661 void
662 Nlsr::onFaceIdIndicationSuccess(const ndn::nfd::ControlParameters& cp)
663 {
664  NLSR_LOG_DEBUG("Successfully enabled incoming face id indication"
665  << "for face id " << cp.getFaceId());
666 }
667 
668 void
669 Nlsr::onFaceIdIndicationFailure(const ndn::nfd::ControlResponse& cr)
670 {
671  std::ostringstream os;
672  os << "Failed to enable incoming face id indication feature: " <<
673  "(code: " << cr.getCode() << ", reason: " << cr.getText() << ")";
674 
675  NLSR_LOG_DEBUG(os.str());
676 }
677 
678 void
680 {
681  m_nlsrFace.processEvents();
682 }
683 
684 } // namespace nlsr
void initializeFaces(const FetchDatasetCallback &onFetchSuccess, const FetchDatasetTimeoutCallback &onFetchFailure)
Initializes neighbors&#39; Faces using information from NFD.
Definition: nlsr.cpp:545
void onFaceDatasetFetchTimeout(uint32_t code, const std::string &reason, uint32_t nRetriesSoFar)
Definition: nlsr.cpp:609
#define NLSR_LOG_WARN(x)
Definition: logger.hpp:40
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
Definition: tlv-nlsr.hpp:27
const ndn::time::milliseconds & getSyncInterestLifetime() const
void initialize()
Definition: nlsr.cpp:250
void scheduleAdjLsaBuild()
Schedules a build of this router&#39;s LSA.
Definition: lsdb.cpp:599
std::function< void(uint32_t, const std::string &)> FetchDatasetTimeoutCallback
Definition: nlsr.hpp:71
ConfParameter & getConfParameter()
Definition: nlsr.hpp:121
void setAdjLsaBuildInterval(uint32_t interval)
Definition: lsdb.hpp:182
const ndn::FaceUri & getFaceUri() const
Definition: adjacent.hpp:69
void setStrategies()
Definition: nlsr.cpp:143
const std::string & getSeqFileDir() const
void connectToFetcher(ndn::util::SegmentFetcher &fetcher)
Definition: nlsr.cpp:201
#define NLSR_LOG_DEBUG(x)
Definition: logger.hpp:38
const ndn::Name & getRouterPrefix() const
std::function< void(const std::vector< ndn::nfd::FaceStatus > &)> FetchDatasetCallback
Definition: nlsr.hpp:70
void initiateSeqNoFromFile(int hypState)
void setStrategy(const ndn::Name &name, const std::string &strategy, uint32_t count)
Definition: fib.cpp:306
SyncLogicHandler & getSyncLogicHandler()
Definition: lsdb.hpp:49
RoutingTable & getRoutingTable()
Definition: nlsr.hpp:169
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California.
void setLsaInterestFilter()
Definition: nlsr.cpp:115
void addDispatcherTopPrefix(const ndn::Name &topPrefix)
Add top level prefixes for Dispatcher.
Definition: nlsr.cpp:132
static const ndn::Name LOCALHOST_PREFIX
Definition: nlsr.hpp:491
void scheduleInterest(uint32_t seconds)
Schedules a Hello Interest event.
void registerAdjacencyPrefixes(const Adjacent &adj, const ndn::time::milliseconds &timeout)
Registers NLSR-specific prefixes for a neighbor (Adjacent)
Definition: nlsr.cpp:589
#define INIT_LOGGER(name)
Definition: logger.hpp:35
void canonizeNeighborUris(std::list< Adjacent >::iterator currentNeighbor, std::function< void(std::list< Adjacent >::iterator)> then, std::function< void(void)> finally)
Canonize the URI for this and all proceeding neighbors in a list.
Definition: nlsr.cpp:162
uint32_t getInterestRetryNumber() const
ndn::security::ValidatorConfig & getValidator()
const ndn::Name & getName() const
Definition: adjacent.hpp:57
void insert(const ndn::security::v2::Certificate &certificate)
const ndn::Name & getLsaPrefix() const
void setLsaRefreshTime(const ndn::time::seconds &lsaRefreshTime)
Definition: lsdb.cpp:825
void scheduleRoutingTableCalculation(Nlsr &pnlsr)
Schedules a calculation event in the event scheduler only if one isn&#39;t already scheduled.
void onRegistrationSuccess(const ndn::Name &name)
Definition: nlsr.cpp:91
void setEntryRefreshTime(int32_t fert)
Definition: fib.hpp:107
void loadCertToPublish(const ndn::security::v2::Certificate &certificate)
Add a certificate NLSR claims to be authoritative for to the certificate store.
Definition: nlsr.cpp:189
void publishCertFromCache(const ndn::Name &keyName)
Retrieves the chain of certificates from Validator&#39;s cache and store them in Nlsr&#39;s own CertificateSt...
Definition: nlsr.cpp:223
void processInterest(const ndn::Name &name, const ndn::Interest &interest)
Processes a Hello Interest from a neighbor.
void setInfoInterestFilter()
Definition: nlsr.cpp:97
void afterFetcherSignalEmitted(const ndn::Data &lsaSegment)
Callback when SegmentFetcher retrieves a segment.
Definition: nlsr.cpp:210
SequencingManager & getSequencingManager()
Definition: lsdb.hpp:194
void processInterest(const ndn::Name &name, const ndn::Interest &interest)
Definition: lsdb.cpp:1041
uint32_t getLsaRefreshTime() const
void setRoutingCalcInterval(uint32_t interval)
const ndn::Name & getChronosyncPrefix() const
A neighbor reachable over a Face.
Definition: adjacent.hpp:38
#define NLSR_LOG_ERROR(x)
Definition: logger.hpp:41
void registrationFailed(const ndn::Name &name)
Definition: nlsr.cpp:84
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
uint32_t getAdjLsaBuildInterval() const
AdjacencyList::iterator findAdjacent(const ndn::Name &adjName)
const ndn::time::seconds TIME_ALLOWED_FOR_CANONIZATION
Definition: common.hpp:41
void setThisRouterPrefix(std::string trp)
Definition: lsdb.cpp:831
uint32_t getFirstHelloInterval() const
uint32_t getFaceDatasetFetchTries() const
const ndn::Name & getNetwork() const
void startEventLoop()
Definition: nlsr.cpp:679
const ndn::security::v2::Certificate * getCertificate(const ndn::Name &certificateKeyName)
Find a certificate.
Definition: nlsr.hpp:341
ndn::Face & getNlsrFace()
Definition: nlsr.hpp:157
Nlsr(boost::asio::io_service &ioService, ndn::Scheduler &scheduler, ndn::Face &face, ndn::KeyChain &keyChain)
Definition: nlsr.cpp:42
void setRouterNameCommandPrefix(const ndn::Name &routerName)
void createSyncSocket(const ndn::Name &syncPrefix, const ndn::time::milliseconds &syncInterestLifetime=ndn::time::milliseconds(SYNC_INTEREST_LIFETIME_DEFAULT))
Create and configure a socket to enable ChronoSync for this NLSR.
bool buildAndInstallOwnNameLsa()
Builds a name LSA for this router and then installs it into the LSDB.
Definition: lsdb.cpp:164
bool buildAndInstallOwnCoordinateLsa()
Builds a cor. LSA for this router and installs it into the LSDB.
Definition: lsdb.cpp:398
int32_t getHyperbolicState() const
uint64_t getLinkCost() const
Definition: adjacent.hpp:81
uint32_t getRoutingCalcInterval() const
void setSeqFileDirectory(std::string filePath)
Set the sequence file directory.
void processFaceDataset(const std::vector< ndn::nfd::FaceStatus > &faces)
Consumes a Face StatusDataset to configure NLSR neighbors.
Definition: nlsr.cpp:555
const ndn::time::seconds getFaceDatasetFetchInterval() const
std::list< Adjacent > & getAdjList()
void initializeKey()
Definition: nlsr.cpp:317
#define NLSR_LOG_TRACE(x)
Definition: logger.hpp:37
const_iterator end() const
void registerPrefix(const ndn::Name &namePrefix, const ndn::FaceUri &faceUri, uint64_t faceCost, const ndn::time::milliseconds &timeout, uint64_t flags, uint8_t times)
Inform NFD of a next-hop.
Definition: fib.cpp:199