36 #include <ndn-cxx/security/key-chain.hpp>
37 #include <ndn-cxx/util/signal.hpp>
38 #include <ndn-cxx/util/time.hpp>
39 #include <ndn-cxx/util/segment-fetcher.hpp>
40 #include <ndn-cxx/ims/in-memory-storage-persistent.hpp>
42 #include <boost/multi_index_container.hpp>
43 #include <boost/multi_index/hashed_index.hpp>
44 #include <boost/multi_index/composite_key.hpp>
46 #include <PSync/segment-publisher.hpp>
50 namespace bmi = boost::multi_index;
62 for (
const auto& sp : m_fetchers) {
72 return m_lsdb.get<
byName>().find(std::make_tuple(router, lsaType)) != m_lsdb.end();
108 return m_isBuildAdjLsaSheduled;
121 return std::static_pointer_cast<T>(
findLsa(router, T::type()));
127 return std::hash<ndn::Name>{}(name);
135 return static_cast<int>(t);
143 std::shared_ptr<Lsa>,
149 bmi::const_mem_fun<Lsa, ndn::Name, &Lsa::getOriginRouterCopy>,
150 bmi::const_mem_fun<Lsa, Lsa::Type, &Lsa::getType>
152 bmi::composite_key_hash<name_hash, enum_class_hash>
154 bmi::hashed_non_unique<
156 bmi::const_mem_fun<Lsa, Lsa::Type, &Lsa::getType>,
163 std::pair<LsaContainer::index<Lsdb::byType>::type::iterator,
164 LsaContainer::index<Lsdb::byType>::type::iterator>
167 return m_lsdb.get<
byType>().equal_range(T::type());
174 auto it = m_lsdb.get<byName>().find(std::make_tuple(router, lsaType));
175 return it != m_lsdb.end() ? *it :
nullptr;
179 incrementDataSentStats(
Lsa::Type lsaType) {
192 incrementInterestRcvdStats(
Lsa::Type lsaType) {
205 incrementInterestSentStats(
Lsa::Type lsaType) {
223 isLsaNew(
const ndn::Name& originRouter,
const Lsa::Type& lsaType, uint64_t lsSeqNo)
226 auto lsaPtr =
findLsa(originRouter, lsaType);
227 return lsaPtr ? lsaPtr->getSeqNo() < lsSeqNo :
true;
231 installLsa(std::shared_ptr<Lsa> lsa);
242 removeLsa(
const ndn::Name& router,
Lsa::Type lsaType);
256 buildAndInstallOwnAdjLsa();
262 ndn::scheduler::EventId
263 scheduleLsaExpiration(std::shared_ptr<Lsa> lsa, ndn::time::seconds expTime)
265 return m_scheduler.schedule(expTime +
GRACE_PERIOD, [
this, lsa] { expireOrRefreshLsa(lsa); });
272 expireOrRefreshLsa(std::shared_ptr<Lsa> lsa);
275 processInterestForLsa(
const ndn::Interest& interest,
const ndn::Name& originRouter,
279 expressInterest(
const ndn::Name& interestName, uint32_t timeoutCount,
280 ndn::time::steady_clock::TimePoint deadline = DEFAULT_LSA_RETRIEVAL_DEADLINE);
297 onFetchLsaError(uint32_t errorCode,
const std::string& msg,
298 const ndn::Name& interestName, uint32_t retransmitNo,
299 const ndn::time::steady_clock::TimePoint& deadline,
300 ndn::Name lsaName, uint64_t seqNo);
309 afterFetchLsa(
const ndn::ConstBufferPtr& bufferPtr,
const ndn::Name& interestName);
312 emitSegmentValidatedSignal(
const ndn::Data& data)
317 ndn::time::system_clock::TimePoint
318 getLsaExpirationTimePoint()
const
329 ndn::Scheduler m_scheduler;
339 ndn::time::seconds m_lsaRefreshTime;
340 ndn::time::seconds m_adjLsaBuildInterval;
341 const ndn::Name& m_thisRouterPrefix;
345 std::map<ndn::Name, uint64_t> m_highestSeqNo;
349 ndn::util::signal::ScopedConnection m_onNewLsaConnection;
351 std::set<std::shared_ptr<ndn::util::SegmentFetcher>> m_fetchers;
352 psync::SegmentPublisher m_segmentPublisher;
354 bool m_isBuildAdjLsaSheduled;
355 int64_t m_adjBuildCount;
356 ndn::scheduler::ScopedEventId m_scheduledAdjLsaBuild;
358 ndn::InMemoryStoragePersistent m_lsaStorage;
360 const ndn::Name::Component NAME_COMPONENT = ndn::Name::Component(
"lsdb");
361 static const ndn::time::steady_clock::TimePoint DEFAULT_LSA_RETRIEVAL_DEADLINE;
A class to house all the configuration parameters for NLSR.
uint32_t getRouterDeadInterval() const
std::shared_ptr< T > findLsa(const ndn::Name &router) const
bool doesLsaExist(const ndn::Name &router, Lsa::Type lsaType)
Returns whether the LSDB contains some LSA.
bool getIsBuildAdjLsaSheduled() const
std::pair< LsaContainer::index< Lsdb::byType >::type::iterator, LsaContainer::index< Lsdb::byType >::type::iterator > getLsdbIterator() const
void buildAndInstallOwnNameLsa()
Builds a name LSA for this router and then installs it into the LSDB.
boost::multi_index_container< std::shared_ptr< Lsa >, bmi::indexed_by< bmi::hashed_unique< bmi::tag< byName >, bmi::composite_key< Lsa, bmi::const_mem_fun< Lsa, ndn::Name, &Lsa::getOriginRouterCopy >, bmi::const_mem_fun< Lsa, Lsa::Type, &Lsa::getType > >, bmi::composite_key_hash< name_hash, enum_class_hash > >, bmi::hashed_non_unique< bmi::tag< byType >, bmi::const_mem_fun< Lsa, Lsa::Type, &Lsa::getType >, enum_class_hash > > > LsaContainer
void processInterest(const ndn::Name &name, const ndn::Interest &interest)
void buildAndInstallOwnCoordinateLsa()
Builds a cor. LSA for this router and installs it into the LSDB.
Lsdb(ndn::Face &face, ndn::KeyChain &keyChain, ConfParameter &confParam, NamePrefixTable &namePrefixTable, RoutingTable &routingTable)
void scheduleAdjLsaBuild()
Schedules a build of this router's LSA.
ndn::util::signal::Signal< Lsdb, const ndn::Data & > afterSegmentValidatedSignal
ndn::util::signal::Signal< Lsdb, Statistics::PacketType > lsaIncrementSignal
SyncLogicHandler & getSync()
@ SENT_COORD_LSA_INTEREST
NLSR-to-ChronoSync interaction point.
Copyright (c) 2014-2020, The University of Memphis, Regents of the University of California,...
static constexpr ndn::time::seconds GRACE_PERIOD
int operator()(T t) const
int operator()(const ndn::Name &name) const
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE