33 #include <ndn-cxx/net/face-uri.hpp> 34 #include <ndn-cxx/signature.hpp> 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_dispatcher(m_face, m_keyChain)
58 , m_datasetHandler(m_dispatcher, m_lsdb, m_routingTable)
59 , m_helloProtocol(m_face, m_keyChain, m_signingInfo, confParam, m_routingTable, m_lsdb)
60 , m_certStore(m_confParam.getCertStore())
61 , m_controller(m_face, m_keyChain)
62 , m_faceDatasetController(m_face, m_keyChain)
63 , m_prefixUpdateProcessor(m_dispatcher,
64 m_confParam.getPrefixUpdateValidator(),
67 m_confParam.getConfFileNameDynamic())
68 , m_nfdRibCommandProcessor(m_dispatcher,
71 , m_statsCollector(m_lsdb, m_helloProtocol)
72 , m_faceMonitor(m_face)
74 m_faceMonitor.onNotification.connect(std::bind(&Nlsr::onFaceEventNotification,
this, _1));
75 m_faceMonitor.start();
83 NLSR_LOG_ERROR(
"ERROR: Failed to register prefix in local hub's daemon");
84 BOOST_THROW_EXCEPTION(
Error(
"Error: Prefix registration failed"));
100 NLSR_LOG_DEBUG(
"Setting interest filter for Hello interest: " << name);
102 m_face.setInterestFilter(ndn::InterestFilter(name).allowLoopback(
false),
106 m_signingInfo, ndn::nfd::ROUTE_FLAG_CAPTURE);
114 NLSR_LOG_DEBUG(
"Setting interest filter for LsaPrefix: " << name);
116 m_face.setInterestFilter(ndn::InterestFilter(name).allowLoopback(
false),
120 m_signingInfo, ndn::nfd::ROUTE_FLAG_CAPTURE);
128 m_dispatcher.addTopPrefix(topPrefix,
false, m_signingInfo);
130 catch (
const std::exception& e) {
131 NLSR_LOG_ERROR(
"Error setting top-level prefix in dispatcher: " << e.what() <<
"\n");
138 const std::string strategy(
"ndn:/localhost/nfd/strategy/multicast");
148 m_certStore.
insert(certificate);
149 m_validator.loadAnchor(
"Authoritative-Certificate",
150 ndn::security::v2::Certificate(certificate));
152 loadAnchor(
"Authoritative-Certificate",
153 ndn::security::v2::Certificate(certificate));
159 NLSR_LOG_TRACE(
"SegmentFetcher fetched a data segment. Start inserting cert to own cert store.");
160 ndn::Name keyName = lsaSegment.getSignature().getKeyLocator().getName();
165 NLSR_LOG_TRACE(
"Certificate is already in the store: " << keyName);
172 const ndn::security::v2::Certificate* cert = m_validator.getUnverifiedCertCache()
174 if (cert !=
nullptr) {
175 m_certStore.
insert(*cert);
177 ndn::Name certName = ndn::security::v2::extractKeyNameFromCertName(cert->getName());
179 m_face.setInterestFilter(ndn::InterestFilter(certName).allowLoopback(
false),
180 std::bind(&Nlsr::onKeyInterest,
this, _1, _2),
181 std::bind(&Nlsr::onKeyPrefixRegSuccess,
this, _1),
183 m_signingInfo, ndn::nfd::ROUTE_FLAG_CAPTURE);
185 if (!cert->getKeyName().equals(cert->getSignature().getKeyLocator().getName())) {
190 NLSR_LOG_TRACE(
"Cert for " << keyName <<
" was not found in the Validator's cache. ");
205 NLSR_LOG_DEBUG(
"Default NLSR identity: " << m_signingInfo.getSignerName());
219 enableIncomingFaceIdIndication();
229 registerLocalhostPrefix();
230 registerRouterPrefix();
237 std::list<Adjacent>& neighbors = m_adjacencyList.
getAdjList();
239 for (std::list<Adjacent>::iterator it = neighbors.begin(); it != neighbors.end(); ++it) {
251 nlsrInstanceName.append(
"nlsr");
254 m_keyChain.deleteIdentity(m_keyChain.getPib().getIdentity(nlsrInstanceName));
255 }
catch (
const std::exception& e) {
259 auto nlsrInstanceIdentity = m_keyChain.createIdentity(nlsrInstanceName);
260 auto nlsrInstanceKey = nlsrInstanceIdentity.getDefaultKey();
262 ndn::security::v2::Certificate certificate;
264 ndn::Name certificateName = nlsrInstanceKey.getName();
265 certificateName.append(
"NA");
266 certificateName.appendVersion();
267 certificate.setName(certificateName);
270 certificate.setContentType(ndn::tlv::ContentType_Key);
271 certificate.setFreshnessPeriod(ndn::time::days(365));
274 certificate.setContent(nlsrInstanceKey.getPublicKey().data(), nlsrInstanceKey.getPublicKey().size());
277 ndn::SignatureInfo signatureInfo;
278 signatureInfo.setValidityPeriod(ndn::security::ValidityPeriod(ndn::time::system_clock::TimePoint(),
279 ndn::time::system_clock::now()
280 + ndn::time::days(365)));
282 m_keyChain.sign(certificate,
283 ndn::security::SigningInfo(m_keyChain.getPib().getIdentity(m_confParam.
getRouterPrefix()))
284 .setSignatureInfo(signatureInfo));
286 catch (
const std::exception& e) {
288 <<
"NLSR is running without security." 289 <<
" If security is enabled NLSR will not converge.");
291 std::cerr <<
"Router's " << e.what() <<
". NLSR is running without security " 292 <<
"(Only for testing, should not be used in production.)" 293 <<
" If security is enabled NLSR will not converge." << std::endl;
296 m_signingInfo = ndn::security::SigningInfo(ndn::security::SigningInfo::SIGNER_TYPE_ID,
303 Nlsr::registerKeyPrefix()
307 nlsrKeyPrefix.append(
"nlsr");
308 nlsrKeyPrefix.append(
"KEY");
310 m_face.setInterestFilter(ndn::InterestFilter(nlsrKeyPrefix).allowLoopback(
false),
311 std::bind(&Nlsr::onKeyInterest,
this, _1, _2),
312 std::bind(&Nlsr::onKeyPrefixRegSuccess,
this, _1),
314 m_signingInfo, ndn::nfd::ROUTE_FLAG_CAPTURE);
318 routerKeyPrefix.append(
"KEY");
320 m_face.setInterestFilter(ndn::InterestFilter(routerKeyPrefix).allowLoopback(
false),
321 std::bind(&Nlsr::onKeyInterest,
this, _1, _2),
322 std::bind(&Nlsr::onKeyPrefixRegSuccess,
this, _1),
324 m_signingInfo, ndn::nfd::ROUTE_FLAG_CAPTURE);
327 ndn::Name operatorKeyPrefix = m_confParam.
getNetwork();
328 operatorKeyPrefix.append(m_confParam.
getSiteName());
329 operatorKeyPrefix.append(std::string(
"%C1.Operator"));
331 m_face.setInterestFilter(ndn::InterestFilter(operatorKeyPrefix).allowLoopback(
false),
332 std::bind(&Nlsr::onKeyInterest,
this, _1, _2),
333 std::bind(&Nlsr::onKeyPrefixRegSuccess,
this, _1),
335 m_signingInfo, ndn::nfd::ROUTE_FLAG_CAPTURE);
338 ndn::Name siteKeyPrefix = m_confParam.
getNetwork();
340 siteKeyPrefix.append(
"KEY");
342 m_face.setInterestFilter(ndn::InterestFilter(siteKeyPrefix).allowLoopback(
false),
343 std::bind(&Nlsr::onKeyInterest,
this, _1, _2),
344 std::bind(&Nlsr::onKeyPrefixRegSuccess,
this, _1),
346 m_signingInfo, ndn::nfd::ROUTE_FLAG_CAPTURE);
350 Nlsr::registerLocalhostPrefix()
358 Nlsr::registerRouterPrefix()
360 m_face.registerPrefix(ndn::Name(m_confParam.
getRouterPrefix()).append(
"nlsr"),
366 Nlsr::onKeyInterest(
const ndn::Name& name,
const ndn::Interest& interest)
368 NLSR_LOG_DEBUG(
"Got interest for certificate. Interest: " << interest.getName());
370 const ndn::Name& interestName = interest.getName();
371 const ndn::security::v2::Certificate* cert =
getCertificate(interestName);
373 if (cert ==
nullptr) {
382 Nlsr::onKeyPrefixRegSuccess(
const ndn::Name& name)
384 NLSR_LOG_DEBUG(
"KEY prefix: " << name <<
" registration is successful.");
388 Nlsr::onFaceEventNotification(
const ndn::nfd::FaceEventNotification& faceEventNotification)
392 switch (faceEventNotification.getKind()) {
393 case ndn::nfd::FACE_EVENT_DESTROYED: {
394 uint64_t faceId = faceEventNotification.getFaceId();
398 if (adjacent != m_adjacencyList.
end()) {
399 NLSR_LOG_DEBUG(
"Face to " << adjacent->getName() <<
" with face id: " << faceId <<
" destroyed");
401 adjacent->setFaceId(0);
435 case ndn::nfd::FACE_EVENT_CREATED: {
437 ndn::FaceUri faceUri;
439 faceUri = ndn::FaceUri(faceEventNotification.getRemoteUri());
441 catch (
const std::exception& e) {
449 if (adjacent != m_adjacencyList.
end()) {
450 NLSR_LOG_DEBUG(
"Face creation event matches neighbor: " << adjacent->getName()
451 <<
". New Face ID: " << faceEventNotification.getFaceId()
452 <<
". Registering prefixes.");
453 adjacent->setFaceId(faceEventNotification.getFaceId());
477 m_faceDatasetController.fetch<ndn::nfd::FaceDataset>(onFetchSuccess, onFetchFailure);
487 for (
auto& adjacent : m_adjacencyList.
getAdjList()) {
489 const std::string faceUriString = adjacent.getFaceUri().toString();
491 for (
const ndn::nfd::FaceStatus& faceStatus : faces) {
494 if (adjacent.getFaceId() == 0 && faceUriString == faceStatus.getRemoteUri()) {
496 " FaceId: "<< faceStatus.getFaceId());
497 adjacent.setFaceId(faceStatus.getFaceId());
506 if (adjacent.getFaceId() == 0) {
508 " has no Face information in this dataset.");
512 scheduleDatasetFetch();
517 const ndn::time::milliseconds& timeout)
521 const ndn::Name& adjName = adj.
getName();
524 timeout, ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
527 faceUri, linkCost, timeout,
528 ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
531 faceUri, linkCost, timeout,
532 ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
537 const std::string& msg,
538 uint32_t nRetriesSoFar)
543 NLSR_LOG_DEBUG(
"Failed to fetch dataset: " << msg <<
". Attempting retry #" << nRetriesSoFar);
547 this, _1, _2, nRetriesSoFar));
550 NLSR_LOG_ERROR(
"Failed to fetch dataset: " << msg <<
". Exceeded limit of " <<
555 scheduleDatasetFetch();
560 Nlsr::scheduleDatasetFetch()
567 [
this] (
const std::vector<ndn::nfd::FaceStatus>& faces) {
570 [
this] (uint32_t code,
const std::string& msg) {
577 Nlsr::enableIncomingFaceIdIndication()
579 NLSR_LOG_DEBUG(
"Enabling incoming face id indication for local face.");
581 m_controller.start<ndn::nfd::FaceUpdateCommand>(
582 ndn::nfd::ControlParameters()
583 .setFlagBit(ndn::nfd::FaceFlagBit::BIT_LOCAL_FIELDS_ENABLED,
true),
584 bind(&Nlsr::onFaceIdIndicationSuccess,
this, _1),
585 bind(&Nlsr::onFaceIdIndicationFailure,
this, _1));
589 Nlsr::onFaceIdIndicationSuccess(
const ndn::nfd::ControlParameters& cp)
592 <<
"for face id " << cp.getFaceId());
596 Nlsr::onFaceIdIndicationFailure(
const ndn::nfd::ControlResponse& cr)
598 std::ostringstream os;
599 os <<
"Failed to enable incoming face id indication feature: " <<
600 "(code: " << cr.getCode() <<
", reason: " << cr.getText() <<
")";
void initializeFaces(const FetchDatasetCallback &onFetchSuccess, const FetchDatasetTimeoutCallback &onFetchFailure)
Initializes neighbors' Faces using information from NFD.
void onFaceDatasetFetchTimeout(uint32_t code, const std::string &reason, uint32_t nRetriesSoFar)
A class to house all the configuration parameters for NLSR.
void scheduleAdjLsaBuild()
Schedules a build of this router's LSA.
std::function< void(uint32_t, const std::string &)> FetchDatasetTimeoutCallback
const ndn::FaceUri & getFaceUri() const
void scheduleRoutingTableCalculation()
Schedules a calculation event in the event scheduler only if one isn't already scheduled.
#define NLSR_LOG_DEBUG(x)
const ndn::Name & getRouterPrefix() const
std::function< void(const std::vector< ndn::nfd::FaceStatus > &)> FetchDatasetCallback
Nlsr(ndn::Face &face, ndn::KeyChain &keyChain, ConfParameter &confParam)
void setStrategy(const ndn::Name &name, const std::string &strategy, uint32_t count)
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California.
void setLsaInterestFilter()
void addDispatcherTopPrefix(const ndn::Name &topPrefix)
Add top level prefixes for Dispatcher.
static const ndn::Name LOCALHOST_PREFIX
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)
#define INIT_LOGGER(name)
const ndn::Name & getSyncPrefix() const
uint32_t getInterestRetryNumber() const
ndn::security::ValidatorConfig & getValidator()
const ndn::Name & getName() const
void insert(const ndn::security::v2::Certificate &certificate)
const ndn::Name & getLsaPrefix() const
void onRegistrationSuccess(const ndn::Name &name)
void loadCertToPublish(const ndn::security::v2::Certificate &certificate)
Add a certificate NLSR claims to be authoritative for to the certificate store.
void publishCertFromCache(const ndn::Name &keyName)
Retrieves the chain of certificates from Validator's cache and store them in Nlsr's own CertificateSt...
void processInterest(const ndn::Name &name, const ndn::Interest &interest)
Processes a Hello Interest from a neighbor.
void setInfoInterestFilter()
void afterFetcherSignalEmitted(const ndn::Data &lsaSegment)
Callback when SegmentFetcher retrieves a segment.
void processInterest(const ndn::Name &name, const ndn::Interest &interest)
A neighbor reachable over a Face.
#define NLSR_LOG_ERROR(x)
void registrationFailed(const ndn::Name &name)
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)
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.
bool buildAndInstallOwnNameLsa()
Builds a name LSA for this router and then installs it into the LSDB.
bool buildAndInstallOwnCoordinateLsa()
Builds a cor. LSA for this router and installs it into the LSDB.
int32_t getHyperbolicState() const
uint64_t getLinkCost() const
const ndn::Name & getSiteName() const
void processFaceDataset(const std::vector< ndn::nfd::FaceStatus > &faces)
Consumes a Face StatusDataset to configure NLSR neighbors.
const ndn::time::seconds getFaceDatasetFetchInterval() const
std::list< Adjacent > & getAdjList()
#define NLSR_LOG_TRACE(x)
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.