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_confParam, m_namePrefixTable, m_routingTable)
54 , m_helloProtocol(m_face, m_keyChain, confParam, m_routingTable, m_lsdb)
55 , m_onNewLsaConnection(m_lsdb.getSync().onNewLsa->connect(
56 [this] (const
ndn::Name& updateName, uint64_t sequenceNumber,
57 const
ndn::Name& originRouter) {
61 [
this] (
const ndn::Name& name) {
62 m_helloProtocol.sendHelloInterest(name);
65 [
this] (
const ndn::Name& neighbor) {
66 auto it = m_adjacencyList.findAdjacent(neighbor);
67 if (it != m_adjacencyList.end()) {
68 m_fib.registerPrefix(m_confParam.getSyncPrefix(), it->getFaceUri(), it->getLinkCost(),
69 ndn::time::milliseconds::max(), ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
72 , m_dispatcher(m_face, m_keyChain)
73 , m_datasetHandler(m_dispatcher, m_lsdb, m_routingTable)
74 , m_controller(m_face, m_keyChain)
75 , m_faceDatasetController(m_face, m_keyChain)
76 , m_prefixUpdateProcessor(m_dispatcher,
77 m_confParam.getPrefixUpdateValidator(),
80 m_confParam.getConfFileNameDynamic())
81 , m_nfdRibCommandProcessor(m_dispatcher,
84 , m_statsCollector(m_lsdb, m_helloProtocol)
85 , m_faceMonitor(m_face)
89 m_faceMonitor.onNotification.connect(std::bind(&Nlsr::onFaceEventNotification,
this, _1));
90 m_faceMonitor.start();
97 NLSR_LOG_DEBUG(
"Default NLSR identity: " << m_confParam.getSigningInfo().getSignerName());
101 setInfoInterestFilter();
102 setLsaInterestFilter();
105 addDispatcherTopPrefix(ndn::Name(m_confParam.getRouterPrefix()).append(
"nlsr"));
106 addDispatcherTopPrefix(LOCALHOST_PREFIX);
108 enableIncomingFaceIdIndication();
110 registerLocalhostPrefix();
111 registerRouterPrefix();
123 for (
const ndn::Name& router : m_strategySetOnRouters) {
124 if (router == originRouter) {
130 m_strategySetOnRouters.push_back(originRouter);
132 ndn::Name routerKey(originRouter);
133 routerKey.append(
"KEY");
134 ndn::Name instanceKey(originRouter);
135 instanceKey.append(
"nlsr").append(
"KEY");
141 for (
size_t i = 0; i < originRouter.size(); ++i) {
142 if (originRouter[i].toUri() ==
"%C1.Router") {
145 siteKey.append(originRouter[i]);
147 ndn::Name opPrefix(siteKey);
148 siteKey.append(
"KEY");
151 opPrefix.append(std::string(
"%C1.Operator"));
158 NLSR_LOG_ERROR(
"ERROR: Failed to register prefix " << name <<
" in local hub's daemon");
159 BOOST_THROW_EXCEPTION(
Error(
"Error: Prefix registration failed"));
175 NLSR_LOG_DEBUG(
"Setting interest filter for Hello interest: " << name);
177 m_face.setInterestFilter(ndn::InterestFilter(name).allowLoopback(
false),
189 NLSR_LOG_DEBUG(
"Setting interest filter for LsaPrefix: " << name);
191 m_face.setInterestFilter(ndn::InterestFilter(name).allowLoopback(
false),
203 m_dispatcher.addTopPrefix(topPrefix,
false, m_confParam.
getSigningInfo());
205 catch (
const std::exception& e) {
206 NLSR_LOG_ERROR(
"Error setting top-level prefix in dispatcher: " << e.what() <<
"\n");
224 m_lsdb.buildAndInstallOwnNameLsa();
228 m_lsdb.buildAndInstallOwnCoordinateLsa();
233 for (
auto&& neighbor : m_adjacencyList.
getAdjList()) {
234 neighbor.setLinkCost(0);
240 Nlsr::registerLocalhostPrefix()
248 Nlsr::registerRouterPrefix()
250 m_face.registerPrefix(ndn::Name(m_confParam.
getRouterPrefix()).append(
"nlsr"),
256 Nlsr::onFaceEventNotification(
const ndn::nfd::FaceEventNotification& faceEventNotification)
260 switch (faceEventNotification.getKind()) {
261 case ndn::nfd::FACE_EVENT_DESTROYED: {
262 uint64_t faceId = faceEventNotification.getFaceId();
266 if (adjacent != m_adjacencyList.
end()) {
267 NLSR_LOG_DEBUG(
"Face to " << adjacent->getName() <<
" with face id: " << faceId <<
" destroyed");
269 adjacent->setFaceId(0);
297 m_lsdb.scheduleAdjLsaBuild();
303 case ndn::nfd::FACE_EVENT_CREATED: {
305 ndn::FaceUri faceUri;
307 faceUri = ndn::FaceUri(faceEventNotification.getRemoteUri());
309 catch (
const std::exception& e) {
314 uint64_t faceId = faceEventNotification.getFaceId();
318 if (adjacent != m_adjacencyList.
end() &&
319 (adjacent->getFaceId() == 0 || adjacent->getFaceId() != faceId))
321 NLSR_LOG_DEBUG(
"Face creation event matches neighbor: " << adjacent->getName()
322 <<
". New Face ID: " << faceId <<
". Registering prefixes.");
323 adjacent->setFaceId(faceId);
331 m_lsdb.scheduleAdjLsaBuild();
347 m_faceDatasetController.fetch<ndn::nfd::FaceDataset>(onFetchSuccess, onFetchFailure);
357 for (
auto&& adjacent : m_adjacencyList.
getAdjList()) {
359 const std::string& faceUriString = adjacent.getFaceUri().toString();
361 for (
const auto& faceStatus : faces) {
364 if (adjacent.getFaceId() == 0 && faceUriString == faceStatus.getRemoteUri()) {
366 " FaceId: "<< faceStatus.getFaceId());
367 adjacent.setFaceId(faceStatus.getFaceId());
376 if (adjacent.getFaceId() == 0) {
378 " has no Face information in this dataset.");
382 scheduleDatasetFetch();
387 const ndn::time::milliseconds& timeout)
391 const ndn::Name& adjName = adj.
getName();
394 timeout, ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
397 faceUri, linkCost, timeout,
398 ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
403 const std::string& msg,
404 uint32_t nRetriesSoFar)
409 NLSR_LOG_DEBUG(
"Failed to fetch dataset: " << msg <<
". Attempting retry #" << nRetriesSoFar);
413 this, _1, _2, nRetriesSoFar));
416 NLSR_LOG_ERROR(
"Failed to fetch dataset: " << msg <<
". Exceeded limit of " <<
421 scheduleDatasetFetch();
426 Nlsr::scheduleDatasetFetch()
433 [
this] (
const std::vector<ndn::nfd::FaceStatus>& faces) {
436 [
this] (uint32_t code,
const std::string& msg) {
443 Nlsr::enableIncomingFaceIdIndication()
445 NLSR_LOG_DEBUG(
"Enabling incoming face id indication for local face.");
447 m_controller.start<ndn::nfd::FaceUpdateCommand>(
448 ndn::nfd::ControlParameters()
449 .setFlagBit(ndn::nfd::FaceFlagBit::BIT_LOCAL_FIELDS_ENABLED,
true),
450 bind(&Nlsr::onFaceIdIndicationSuccess,
this, _1),
451 bind(&Nlsr::onFaceIdIndicationFailure,
this, _1));
455 Nlsr::onFaceIdIndicationSuccess(
const ndn::nfd::ControlParameters& cp)
458 <<
"for face id " << cp.getFaceId());
462 Nlsr::onFaceIdIndicationFailure(
const ndn::nfd::ControlResponse& cr)
464 std::ostringstream os;
465 os <<
"Failed to enable incoming face id indication feature: " <<
466 "(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.
const ndn::FaceUri & getFaceUri() const
std::function< void(uint32_t, const std::string &)> FetchDatasetTimeoutCallback
const ndn::Name & getName() const
static const std::string MULTICAST_STRATEGY
void scheduleRoutingTableCalculation()
Schedules a calculation event in the event scheduler only if one isn't already scheduled.
const ndn::security::SigningInfo & getSigningInfo() const
#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)
static const std::string BEST_ROUTE_V2_STRATEGY
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 registerAdjacencyPrefixes(const Adjacent &adj, const ndn::time::milliseconds &timeout)
Registers NLSR-specific prefixes for a neighbor (Adjacent)
#define INIT_LOGGER(name)
uint32_t getInterestRetryNumber() const
ndn::util::Signal< HelloProtocol, const ndn::Name & > onHelloDataValidated
void onRegistrationSuccess(const ndn::Name &name)
uint32_t getFaceDatasetFetchTries() const
void processInterest(const ndn::Name &name, const ndn::Interest &interest)
Processes a Hello Interest from a neighbor.
void setInfoInterestFilter()
void processInterest(const ndn::Name &name, const ndn::Interest &interest)
const ndn::Name & getSyncPrefix() const
double getLinkCost() const
int32_t getHyperbolicState() const
A neighbor reachable over a Face.
void registerStrategyForCerts(const ndn::Name &originRouter)
#define NLSR_LOG_ERROR(x)
void registrationFailed(const ndn::Name &name)
Copyright (c) 2014-2019, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
AdjacencyList::iterator findAdjacent(const ndn::Name &adjName)
const ndn::time::seconds getFaceDatasetFetchInterval() const
const_iterator end() const
ndn::util::Signal< Fib, const ndn::Name & > onPrefixRegistrationSuccess
const ndn::Name & getLsaPrefix() const
void processFaceDataset(const std::vector< ndn::nfd::FaceStatus > &faces)
Consumes a Face StatusDataset to configure NLSR neighbors.
std::list< Adjacent > & getAdjList()
#define NLSR_LOG_TRACE(x)
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.