nlsr.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2019, The University of Memphis,
4  * Regents of the University of California,
5  * Arizona Board of Regents.
6  *
7  * This file is part of NLSR (Named-data Link State Routing).
8  * See AUTHORS.md for complete list of NLSR authors and contributors.
9  *
10  * NLSR is free software: you can redistribute it and/or modify it under the terms
11  * of the GNU General Public License as published by the Free Software Foundation,
12  * either version 3 of the License, or (at your option) any later version.
13  *
14  * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16  * PURPOSE. See the GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along with
19  * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
20  **/
21 
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(ndn::Face& face, ndn::KeyChain& keyChain, ConfParameter& confParam)
43  : m_face(face)
44  , m_scheduler(face.getIoService())
45  , m_keyChain(keyChain)
46  , m_confParam(confParam)
47  , m_adjacencyList(confParam.getAdjacencyList())
48  , m_namePrefixList(confParam.getNamePrefixList())
49  , m_validator(m_confParam.getValidator())
50  , m_fib(m_face, m_scheduler, m_adjacencyList, m_confParam, m_keyChain)
51  , m_routingTable(m_scheduler, m_fib, m_lsdb, m_namePrefixTable, m_confParam)
52  , m_namePrefixTable(m_fib, m_routingTable, m_routingTable.afterRoutingChange)
53  , m_lsdb(m_face, m_keyChain, m_signingInfo,
54  m_confParam, m_namePrefixTable, m_routingTable)
55  , m_afterSegmentValidatedConnection(m_lsdb.afterSegmentValidatedSignal.connect(
56  std::bind(&Nlsr::afterFetcherSignalEmitted, this, _1)))
57  , m_onNewLsaConnection(m_lsdb.getSync().onNewLsa->connect(
58  [this] (const ndn::Name& updateName, uint64_t sequenceNumber,
59  const ndn::Name& originRouter) {
60  registerStrategyForCerts(originRouter);
61  }))
62  , m_dispatcher(m_face, m_keyChain)
63  , m_datasetHandler(m_dispatcher, m_lsdb, m_routingTable)
64  , m_helloProtocol(m_face, m_keyChain, m_signingInfo, confParam, m_routingTable, m_lsdb)
65  , m_certStore(m_confParam.getCertStore())
66  , m_controller(m_face, m_keyChain)
67  , m_faceDatasetController(m_face, m_keyChain)
68  , m_prefixUpdateProcessor(m_dispatcher,
69  m_confParam.getPrefixUpdateValidator(),
70  m_namePrefixList,
71  m_lsdb,
72  m_confParam.getConfFileNameDynamic())
73  , m_nfdRibCommandProcessor(m_dispatcher,
74  m_namePrefixList,
75  m_lsdb)
76  , m_statsCollector(m_lsdb, m_helloProtocol)
77  , m_faceMonitor(m_face)
78 {
79  m_faceMonitor.onNotification.connect(std::bind(&Nlsr::onFaceEventNotification, this, _1));
80  m_faceMonitor.start();
81 
82  setStrategies();
83 }
84 
85 void
86 Nlsr::registerStrategyForCerts(const ndn::Name& originRouter)
87 {
88  for (const ndn::Name& router : m_strategySetOnRouters) {
89  if (router == originRouter) {
90  // Have already set strategy for this router's certs once
91  return;
92  }
93  }
94 
95  m_strategySetOnRouters.push_back(originRouter);
96 
97  ndn::Name routerKey(originRouter);
98  routerKey.append("KEY");
99  ndn::Name instanceKey(originRouter);
100  instanceKey.append("nlsr").append("KEY");
101 
102  m_fib.setStrategy(routerKey, Fib::BEST_ROUTE_V2_STRATEGY, 0);
103  m_fib.setStrategy(instanceKey, Fib::BEST_ROUTE_V2_STRATEGY, 0);
104 
105  ndn::Name siteKey;
106  for (size_t i = 0; i < originRouter.size(); ++i) {
107  if (originRouter[i].toUri() == "%C1.Router") {
108  break;
109  }
110  siteKey.append(originRouter[i]);
111  }
112  ndn::Name opPrefix(siteKey);
113  siteKey.append("KEY");
114  m_fib.setStrategy(siteKey, Fib::BEST_ROUTE_V2_STRATEGY, 0);
115 
116  opPrefix.append(std::string("%C1.Operator"));
117  m_fib.setStrategy(opPrefix, Fib::BEST_ROUTE_V2_STRATEGY, 0);
118 }
119 
120 void
121 Nlsr::registrationFailed(const ndn::Name& name)
122 {
123  NLSR_LOG_ERROR("ERROR: Failed to register prefix in local hub's daemon");
124  BOOST_THROW_EXCEPTION(Error("Error: Prefix registration failed"));
125 }
126 
127 void
128 Nlsr::onRegistrationSuccess(const ndn::Name& name)
129 {
130  NLSR_LOG_DEBUG("Successfully registered prefix: " << name);
131 }
132 
133 void
135 {
136  ndn::Name name(m_confParam.getRouterPrefix());
137  name.append("nlsr");
138  name.append("INFO");
139 
140  NLSR_LOG_DEBUG("Setting interest filter for Hello interest: " << name);
141 
142  m_face.setInterestFilter(ndn::InterestFilter(name).allowLoopback(false),
143  std::bind(&HelloProtocol::processInterest, &m_helloProtocol, _1, _2),
144  std::bind(&Nlsr::onRegistrationSuccess, this, _1),
145  std::bind(&Nlsr::registrationFailed, this, _1),
146  m_signingInfo, ndn::nfd::ROUTE_FLAG_CAPTURE);
147 }
148 
149 void
151 {
152  ndn::Name name = m_confParam.getLsaPrefix();
153 
154  NLSR_LOG_DEBUG("Setting interest filter for LsaPrefix: " << name);
155 
156  m_face.setInterestFilter(ndn::InterestFilter(name).allowLoopback(false),
157  std::bind(&Lsdb::processInterest, &m_lsdb, _1, _2),
158  std::bind(&Nlsr::onRegistrationSuccess, this, _1),
159  std::bind(&Nlsr::registrationFailed, this, _1),
160  m_signingInfo, ndn::nfd::ROUTE_FLAG_CAPTURE);
161 }
162 
163 void
164 Nlsr::addDispatcherTopPrefix(const ndn::Name& topPrefix)
165 {
166  try {
167  // false since we want to have control over the registration process
168  m_dispatcher.addTopPrefix(topPrefix, false, m_signingInfo);
169  }
170  catch (const std::exception& e) {
171  NLSR_LOG_ERROR("Error setting top-level prefix in dispatcher: " << e.what() << "\n");
172  }
173 }
174 
175 void
177 {
178  m_fib.setStrategy(m_confParam.getLsaPrefix(), Fib::MULTICAST_STRATEGY, 0);
179  m_fib.setStrategy(m_confParam.getSyncPrefix(), Fib::MULTICAST_STRATEGY, 0);
180 }
181 
182 void
183 Nlsr::loadCertToPublish(const ndn::security::v2::Certificate& certificate)
184 {
185  NLSR_LOG_TRACE("Loading cert to publish.");
186  m_certStore.insert(certificate);
187  m_validator.loadAnchor("Authoritative-Certificate",
188  ndn::security::v2::Certificate(certificate));
189  m_prefixUpdateProcessor.getValidator().
190  loadAnchor("Authoritative-Certificate",
191  ndn::security::v2::Certificate(certificate));
192 }
193 
194 void
195 Nlsr::afterFetcherSignalEmitted(const ndn::Data& lsaSegment)
196 {
197  ndn::Name keyName = lsaSegment.getSignature().getKeyLocator().getName();
198  if (getCertificate(keyName) == nullptr) {
199  NLSR_LOG_TRACE("Publishing certificate for: " << keyName);
200  publishCertFromCache(keyName);
201  }
202  else {
203  NLSR_LOG_TRACE("Certificate is already in the store: " << keyName);
204  }
205 }
206 
207 void
208 Nlsr::publishCertFromCache(const ndn::Name& keyName)
209 {
210  const ndn::security::v2::Certificate* cert = m_validator.getUnverifiedCertCache()
211  .find(keyName);
212 
213  if (cert != nullptr) {
214  m_certStore.insert(*cert);
215  NLSR_LOG_TRACE(*cert);
216  ndn::Name certName = ndn::security::v2::extractKeyNameFromCertName(cert->getName());
217  NLSR_LOG_TRACE("Setting interest filter for: " << certName);
218  m_face.setInterestFilter(ndn::InterestFilter(certName).allowLoopback(false),
219  std::bind(&Nlsr::onKeyInterest, this, _1, _2),
220  std::bind(&Nlsr::onKeyPrefixRegSuccess, this, _1),
221  std::bind(&Nlsr::registrationFailed, this, _1),
222  m_signingInfo, ndn::nfd::ROUTE_FLAG_CAPTURE);
223 
224  if (!cert->getKeyName().equals(cert->getSignature().getKeyLocator().getName())) {
225  publishCertFromCache(cert->getSignature().getKeyLocator().getName());
226  }
227  }
228  else {
229  // Happens for root cert
230  NLSR_LOG_TRACE("Cert for " << keyName << " was not found in the Validator's cache. ");
231  }
232 }
233 
234 void
236 {
237  NLSR_LOG_DEBUG("Initializing Nlsr");
238 
239  // Logging start
240  m_adjacencyList.writeLog();
241  NLSR_LOG_DEBUG(m_namePrefixList);
242 
243  initializeKey();
244 
245  NLSR_LOG_DEBUG("Default NLSR identity: " << m_signingInfo.getSignerName());
246 
247  // Can be moved to HelloProtocol and Lsdb ctor if initializeKey is set
248  // earlier in the Nlsr constructor so as to set m_signingInfo
251 
252  // add top-level prefixes: router and localhost prefix
253  addDispatcherTopPrefix(ndn::Name(m_confParam.getRouterPrefix()).append("nlsr"));
255 
256  initializeFaces(std::bind(&Nlsr::processFaceDataset, this, _1),
257  std::bind(&Nlsr::onFaceDatasetFetchTimeout, this, _1, _2, 0));
258 
259  enableIncomingFaceIdIndication();
260 
261  m_lsdb.buildAndInstallOwnNameLsa();
262 
263  // Install coordinate LSAs if using HR or dry-run HR.
264  if (m_confParam.getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
265  m_lsdb.buildAndInstallOwnCoordinateLsa();
266  }
267 
268  registerKeyPrefix();
269  registerLocalhostPrefix();
270  registerRouterPrefix();
271 
272  m_helloProtocol.scheduleInterest(m_confParam.getFirstHelloInterval());
273 
274  // Need to set direct neighbors' costs to 0 for hyperbolic routing
275  if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON) {
276 
277  std::list<Adjacent>& neighbors = m_adjacencyList.getAdjList();
278 
279  for (std::list<Adjacent>::iterator it = neighbors.begin(); it != neighbors.end(); ++it) {
280  it->setLinkCost(0);
281  }
282  }
283 }
284 
285 void
287 {
288  NLSR_LOG_DEBUG("Initializing Key ...");
289 
290  ndn::Name nlsrInstanceName = m_confParam.getRouterPrefix();
291  nlsrInstanceName.append("nlsr");
292 
293  try {
294  m_keyChain.deleteIdentity(m_keyChain.getPib().getIdentity(nlsrInstanceName));
295  } catch (const std::exception& e) {
296  NLSR_LOG_WARN(e.what());
297  }
298 
299  auto nlsrInstanceIdentity = m_keyChain.createIdentity(nlsrInstanceName);
300  auto nlsrInstanceKey = nlsrInstanceIdentity.getDefaultKey();
301 
302  ndn::security::v2::Certificate certificate;
303 
304  ndn::Name certificateName = nlsrInstanceKey.getName();
305  certificateName.append("NA");
306  certificateName.appendVersion();
307  certificate.setName(certificateName);
308 
309  // set metainfo
310  certificate.setContentType(ndn::tlv::ContentType_Key);
311  certificate.setFreshnessPeriod(ndn::time::days(365));
312 
313  // set content
314  certificate.setContent(nlsrInstanceKey.getPublicKey().data(), nlsrInstanceKey.getPublicKey().size());
315 
316  // set signature-info
317  ndn::SignatureInfo signatureInfo;
318  signatureInfo.setValidityPeriod(ndn::security::ValidityPeriod(ndn::time::system_clock::TimePoint(),
319  ndn::time::system_clock::now()
320  + ndn::time::days(365)));
321  try {
322  m_keyChain.sign(certificate,
323  ndn::security::SigningInfo(m_keyChain.getPib().getIdentity(m_confParam.getRouterPrefix()))
324  .setSignatureInfo(signatureInfo));
325  }
326  catch (const std::exception& e) {
327  NLSR_LOG_WARN("ERROR: Router's " << e.what()
328  << "NLSR is running without security."
329  << " If security is enabled NLSR will not converge.");
330 
331  std::cerr << "Router's " << e.what() << ". NLSR is running without security "
332  << "(Only for testing, should not be used in production.)"
333  << " If security is enabled NLSR will not converge." << std::endl;
334  }
335 
336  m_signingInfo = ndn::security::SigningInfo(ndn::security::SigningInfo::SIGNER_TYPE_ID,
337  nlsrInstanceName);
338 
339  loadCertToPublish(certificate);
340 }
341 
342 void
343 Nlsr::registerKeyPrefix()
344 {
345  // Start listening for the interest of this router's NLSR certificate
346  ndn::Name nlsrKeyPrefix = m_confParam.getRouterPrefix();
347  nlsrKeyPrefix.append("nlsr");
348  nlsrKeyPrefix.append("KEY");
349 
350  m_face.setInterestFilter(ndn::InterestFilter(nlsrKeyPrefix).allowLoopback(false),
351  std::bind(&Nlsr::onKeyInterest, this, _1, _2),
352  std::bind(&Nlsr::onKeyPrefixRegSuccess, this, _1),
353  std::bind(&Nlsr::registrationFailed, this, _1),
354  m_signingInfo, ndn::nfd::ROUTE_FLAG_CAPTURE);
355 
356  // Start listening for the interest of this router's certificate
357  ndn::Name routerKeyPrefix = m_confParam.getRouterPrefix();
358  routerKeyPrefix.append("KEY");
359 
360  m_face.setInterestFilter(ndn::InterestFilter(routerKeyPrefix).allowLoopback(false),
361  std::bind(&Nlsr::onKeyInterest, this, _1, _2),
362  std::bind(&Nlsr::onKeyPrefixRegSuccess, this, _1),
363  std::bind(&Nlsr::registrationFailed, this, _1),
364  m_signingInfo, ndn::nfd::ROUTE_FLAG_CAPTURE);
365 
366  // Start listening for the interest of this router's operator's certificate
367  ndn::Name operatorKeyPrefix = m_confParam.getNetwork();
368  operatorKeyPrefix.append(m_confParam.getSiteName());
369  operatorKeyPrefix.append(std::string("%C1.Operator"));
370 
371  m_face.setInterestFilter(ndn::InterestFilter(operatorKeyPrefix).allowLoopback(false),
372  std::bind(&Nlsr::onKeyInterest, this, _1, _2),
373  std::bind(&Nlsr::onKeyPrefixRegSuccess, this, _1),
374  std::bind(&Nlsr::registrationFailed, this, _1),
375  m_signingInfo, ndn::nfd::ROUTE_FLAG_CAPTURE);
376 
377  // Start listening for the interest of this router's site's certificate
378  ndn::Name siteKeyPrefix = m_confParam.getNetwork();
379  siteKeyPrefix.append(m_confParam.getSiteName());
380  siteKeyPrefix.append("KEY");
381 
382  m_face.setInterestFilter(ndn::InterestFilter(siteKeyPrefix).allowLoopback(false),
383  std::bind(&Nlsr::onKeyInterest, this, _1, _2),
384  std::bind(&Nlsr::onKeyPrefixRegSuccess, this, _1),
385  std::bind(&Nlsr::registrationFailed, this, _1),
386  m_signingInfo, ndn::nfd::ROUTE_FLAG_CAPTURE);
387 }
388 
389 void
390 Nlsr::registerLocalhostPrefix()
391 {
392  m_face.registerPrefix(LOCALHOST_PREFIX,
393  std::bind(&Nlsr::onRegistrationSuccess, this, _1),
394  std::bind(&Nlsr::registrationFailed, this, _1));
395 }
396 
397 void
398 Nlsr::registerRouterPrefix()
399 {
400  m_face.registerPrefix(ndn::Name(m_confParam.getRouterPrefix()).append("nlsr"),
401  std::bind(&Nlsr::onRegistrationSuccess, this, _1),
402  std::bind(&Nlsr::registrationFailed, this, _1));
403 }
404 
405 void
406 Nlsr::onKeyInterest(const ndn::Name& name, const ndn::Interest& interest)
407 {
408  NLSR_LOG_DEBUG("Got interest for certificate. Interest: " << interest.getName());
409 
410  const ndn::Name& interestName = interest.getName();
411  const ndn::security::v2::Certificate* cert = getCertificate(interestName);
412 
413  if (cert == nullptr) {
414  NLSR_LOG_DEBUG("Certificate is not found for: " << interest);
415  return; // cert is not found
416  }
417 
418  m_face.put(*cert);
419 }
420 
421 void
422 Nlsr::onKeyPrefixRegSuccess(const ndn::Name& name)
423 {
424  NLSR_LOG_DEBUG("KEY prefix: " << name << " registration is successful.");
425 }
426 
427 void
428 Nlsr::onFaceEventNotification(const ndn::nfd::FaceEventNotification& faceEventNotification)
429 {
430  NLSR_LOG_TRACE("Nlsr::onFaceEventNotification called");
431 
432  switch (faceEventNotification.getKind()) {
433  case ndn::nfd::FACE_EVENT_DESTROYED: {
434  uint64_t faceId = faceEventNotification.getFaceId();
435 
436  auto adjacent = m_adjacencyList.findAdjacent(faceId);
437 
438  if (adjacent != m_adjacencyList.end()) {
439  NLSR_LOG_DEBUG("Face to " << adjacent->getName() << " with face id: " << faceId << " destroyed");
440 
441  adjacent->setFaceId(0);
442 
443  // Only trigger an Adjacency LSA build if this node is changing
444  // from ACTIVE to INACTIVE since this rebuild will effectively
445  // cancel the previous Adjacency LSA refresh event and schedule
446  // a new one further in the future.
447  //
448  // Continuously scheduling the refresh in the future will block
449  // the router from refreshing its Adjacency LSA. Since other
450  // routers' Name prefixes' expiration times are updated when
451  // this router refreshes its Adjacency LSA, the other routers'
452  // prefixes will expire and be removed from the RIB.
453  //
454  // This check is required to fix Bug #2733 for now. This check
455  // would be unnecessary to fix Bug #2733 when Issue #2732 is
456  // completed, but the check also helps with optimization so it
457  // can remain even when Issue #2732 is implemented.
458  if (adjacent->getStatus() == Adjacent::STATUS_ACTIVE) {
459  adjacent->setStatus(Adjacent::STATUS_INACTIVE);
460 
461  // A new adjacency LSA cannot be built until the neighbor is marked INACTIVE and
462  // has met the HELLO retry threshold
463  adjacent->setInterestTimedOutNo(m_confParam.getInterestRetryNumber());
464 
465  if (m_confParam.getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
466  m_routingTable.scheduleRoutingTableCalculation();
467  }
468  else {
469  m_lsdb.scheduleAdjLsaBuild();
470  }
471  }
472  }
473  break;
474  }
475  case ndn::nfd::FACE_EVENT_CREATED: {
476  // Find the neighbor in our adjacency list
477  ndn::FaceUri faceUri;
478  try {
479  faceUri = ndn::FaceUri(faceEventNotification.getRemoteUri());
480  }
481  catch (const std::exception& e) {
482  NLSR_LOG_WARN(e.what());
483  return;
484  }
485  auto adjacent = m_adjacencyList.findAdjacent(faceUri);
486 
487  // If we have a neighbor by that FaceUri and it has no FaceId, we
488  // have a match.
489  if (adjacent != m_adjacencyList.end()) {
490  NLSR_LOG_DEBUG("Face creation event matches neighbor: " << adjacent->getName()
491  << ". New Face ID: " << faceEventNotification.getFaceId()
492  << ". Registering prefixes.");
493  adjacent->setFaceId(faceEventNotification.getFaceId());
494 
495  registerAdjacencyPrefixes(*adjacent, ndn::time::milliseconds::max());
496 
497  if (m_confParam.getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
498  m_routingTable.scheduleRoutingTableCalculation();
499  }
500  else {
501  m_lsdb.scheduleAdjLsaBuild();
502  }
503  }
504  break;
505  }
506  default:
507  break;
508  }
509 }
510 
511 void
513  const FetchDatasetTimeoutCallback& onFetchFailure)
514 {
515  NLSR_LOG_TRACE("Initializing Faces...");
516 
517  m_faceDatasetController.fetch<ndn::nfd::FaceDataset>(onFetchSuccess, onFetchFailure);
518 
519 }
520 
521 void
522 Nlsr::processFaceDataset(const std::vector<ndn::nfd::FaceStatus>& faces)
523 {
524  NLSR_LOG_DEBUG("Processing face dataset");
525 
526  // Iterate over each neighbor listed in nlsr.conf
527  for (auto& adjacent : m_adjacencyList.getAdjList()) {
528 
529  const std::string faceUriString = adjacent.getFaceUri().toString();
530  // Check the list of FaceStatus objects we got for a match
531  for (const ndn::nfd::FaceStatus& faceStatus : faces) {
532  // Set the adjacency FaceID if we find a URI match and it was
533  // previously unset. Change the boolean to true.
534  if (adjacent.getFaceId() == 0 && faceUriString == faceStatus.getRemoteUri()) {
535  NLSR_LOG_DEBUG("FaceUri: " << faceStatus.getRemoteUri() <<
536  " FaceId: "<< faceStatus.getFaceId());
537  adjacent.setFaceId(faceStatus.getFaceId());
538  // Register the prefixes for each neighbor
539  this->registerAdjacencyPrefixes(adjacent, ndn::time::milliseconds::max());
540  }
541  }
542  // If this adjacency has no information in this dataset, then one
543  // of two things is happening: 1. NFD is starting slowly and this
544  // Face wasn't ready yet, or 2. NFD is configured
545  // incorrectly and this Face isn't available.
546  if (adjacent.getFaceId() == 0) {
547  NLSR_LOG_WARN("The adjacency " << adjacent.getName() <<
548  " has no Face information in this dataset.");
549  }
550  }
551 
552  scheduleDatasetFetch();
553 }
554 
555 void
557  const ndn::time::milliseconds& timeout)
558 {
559  ndn::FaceUri faceUri = adj.getFaceUri();
560  double linkCost = adj.getLinkCost();
561  const ndn::Name& adjName = adj.getName();
562 
563  m_fib.registerPrefix(adjName, faceUri, linkCost,
564  timeout, ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
565 
566  m_fib.registerPrefix(m_confParam.getSyncPrefix(),
567  faceUri, linkCost, timeout,
568  ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
569 
570  m_fib.registerPrefix(m_confParam.getLsaPrefix(),
571  faceUri, linkCost, timeout,
572  ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
573 }
574 
575 void
577  const std::string& msg,
578  uint32_t nRetriesSoFar)
579 {
580  NLSR_LOG_DEBUG("onFaceDatasetFetchTimeout");
581  // If we have exceeded the maximum attempt count, do not try again.
582  if (nRetriesSoFar++ < m_confParam.getFaceDatasetFetchTries()) {
583  NLSR_LOG_DEBUG("Failed to fetch dataset: " << msg << ". Attempting retry #" << nRetriesSoFar);
584  m_faceDatasetController.fetch<ndn::nfd::FaceDataset>(std::bind(&Nlsr::processFaceDataset,
585  this, _1),
587  this, _1, _2, nRetriesSoFar));
588  }
589  else {
590  NLSR_LOG_ERROR("Failed to fetch dataset: " << msg << ". Exceeded limit of " <<
591  m_confParam.getFaceDatasetFetchTries() << ", so not trying again this time.");
592  // If we fail to fetch it, just do nothing until the next
593  // interval. Since this is a backup mechanism, we aren't as
594  // concerned with retrying.
595  scheduleDatasetFetch();
596  }
597 }
598 
599 void
600 Nlsr::scheduleDatasetFetch()
601 {
602  NLSR_LOG_DEBUG("Scheduling Dataset Fetch in " << m_confParam.getFaceDatasetFetchInterval());
603 
604  m_scheduler.schedule(m_confParam.getFaceDatasetFetchInterval(),
605  [this] {
606  this->initializeFaces(
607  [this] (const std::vector<ndn::nfd::FaceStatus>& faces) {
608  this->processFaceDataset(faces);
609  },
610  [this] (uint32_t code, const std::string& msg) {
611  this->onFaceDatasetFetchTimeout(code, msg, 0);
612  });
613  });
614 }
615 
616 void
617 Nlsr::enableIncomingFaceIdIndication()
618 {
619  NLSR_LOG_DEBUG("Enabling incoming face id indication for local face.");
620 
621  m_controller.start<ndn::nfd::FaceUpdateCommand>(
622  ndn::nfd::ControlParameters()
623  .setFlagBit(ndn::nfd::FaceFlagBit::BIT_LOCAL_FIELDS_ENABLED, true),
624  bind(&Nlsr::onFaceIdIndicationSuccess, this, _1),
625  bind(&Nlsr::onFaceIdIndicationFailure, this, _1));
626 }
627 
628 void
629 Nlsr::onFaceIdIndicationSuccess(const ndn::nfd::ControlParameters& cp)
630 {
631  NLSR_LOG_DEBUG("Successfully enabled incoming face id indication"
632  << "for face id " << cp.getFaceId());
633 }
634 
635 void
636 Nlsr::onFaceIdIndicationFailure(const ndn::nfd::ControlResponse& cr)
637 {
638  std::ostringstream os;
639  os << "Failed to enable incoming face id indication feature: " <<
640  "(code: " << cr.getCode() << ", reason: " << cr.getText() << ")";
641 
642  NLSR_LOG_DEBUG(os.str());
643 }
644 
645 } // namespace nlsr
void initializeFaces(const FetchDatasetCallback &onFetchSuccess, const FetchDatasetTimeoutCallback &onFetchFailure)
Initializes neighbors&#39; Faces using information from NFD.
Definition: nlsr.cpp:512
void onFaceDatasetFetchTimeout(uint32_t code, const std::string &reason, uint32_t nRetriesSoFar)
Definition: nlsr.cpp:576
#define NLSR_LOG_WARN(x)
Definition: logger.hpp:40
A class to house all the configuration parameters for NLSR.
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
Definition: tlv-nlsr.hpp:28
void initialize()
Definition: nlsr.cpp:235
std::function< void(uint32_t, const std::string &)> FetchDatasetTimeoutCallback
Definition: nlsr.hpp:71
const ndn::FaceUri & getFaceUri() const
Definition: adjacent.hpp:69
static const std::string MULTICAST_STRATEGY
Definition: fib.hpp:241
void setStrategies()
Definition: nlsr.cpp:176
const std::string & getConfFileNameDynamic() const
void scheduleRoutingTableCalculation()
Schedules a calculation event in the event scheduler only if one isn&#39;t already scheduled.
#define NLSR_LOG_DEBUG(x)
Definition: logger.hpp:38
ndn::security::ValidatorConfig & getPrefixUpdateValidator()
const ndn::Name & getRouterPrefix() const
STL namespace.
std::function< void(const std::vector< ndn::nfd::FaceStatus > &)> FetchDatasetCallback
Definition: nlsr.hpp:70
Nlsr(ndn::Face &face, ndn::KeyChain &keyChain, ConfParameter &confParam)
Definition: nlsr.cpp:42
void setStrategy(const ndn::Name &name, const std::string &strategy, uint32_t count)
Definition: fib.cpp:307
static const std::string BEST_ROUTE_V2_STRATEGY
Definition: fib.hpp:242
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California.
void setLsaInterestFilter()
Definition: nlsr.cpp:150
void addDispatcherTopPrefix(const ndn::Name &topPrefix)
Add top level prefixes for Dispatcher.
Definition: nlsr.cpp:164
static const ndn::Name LOCALHOST_PREFIX
Definition: nlsr.hpp:263
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:556
#define INIT_LOGGER(name)
Definition: logger.hpp:35
const ndn::Name & getSyncPrefix() const
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 onRegistrationSuccess(const ndn::Name &name)
Definition: nlsr.cpp:128
void loadCertToPublish(const ndn::security::v2::Certificate &certificate)
Add a certificate NLSR claims to be authoritative for to the certificate store.
Definition: nlsr.cpp:183
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:208
void processInterest(const ndn::Name &name, const ndn::Interest &interest)
Processes a Hello Interest from a neighbor.
void setInfoInterestFilter()
Definition: nlsr.cpp:134
void afterFetcherSignalEmitted(const ndn::Data &lsaSegment)
Callback when SegmentFetcher retrieves a segment.
Definition: nlsr.cpp:195
void processInterest(const ndn::Name &name, const ndn::Interest &interest)
Definition: lsdb.cpp:1000
A neighbor reachable over a Face.
Definition: adjacent.hpp:38
void registerStrategyForCerts(const ndn::Name &originRouter)
Definition: nlsr.cpp:86
#define NLSR_LOG_ERROR(x)
Definition: logger.hpp:41
void registrationFailed(const ndn::Name &name)
Definition: nlsr.cpp:121
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
AdjacencyList::iterator findAdjacent(const ndn::Name &adjName)
security::CertificateStore & getCertStore()
uint32_t getFirstHelloInterval() const
uint32_t getFaceDatasetFetchTries() const
const ndn::Name & getNetwork() const
const ndn::security::v2::Certificate * getCertificate(const ndn::Name &certificateKeyName)
Find a certificate.
Definition: nlsr.hpp:193
int32_t getHyperbolicState() const
uint64_t getLinkCost() const
Definition: adjacent.hpp:81
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:522
const ndn::time::seconds getFaceDatasetFetchInterval() const
std::list< Adjacent > & getAdjList()
void initializeKey()
Definition: nlsr.cpp:286
#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:201