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