50 , m_isLsaNew(isLsaNew)
58 if (m_syncSocket !=
nullptr) {
59 NLSR_LOG_WARN(
"Trying to create Sync socket, but Sync socket already exists");
63 m_syncPrefix = syncPrefix;
68 NLSR_LOG_DEBUG(
"Creating Sync socket. Sync Prefix: " << m_syncPrefix);
74 const auto fixedSession = ndn::name::Component::fromNumber(0);
75 m_syncSocket = std::make_shared<chronosync::Socket>(m_syncPrefix, m_nameLsaUserPrefix, *facePtr,
77 chronosync::Socket::DEFAULT_NAME, chronosync::Socket::DEFAULT_VALIDATOR,
78 syncInterestLifetime, fixedSession);
81 m_syncSocket->addSyncNode(m_adjLsaUserPrefix, chronosync::Socket::DEFAULT_NAME, fixedSession);
84 m_syncSocket->addSyncNode(m_coorLsaUserPrefix, chronosync::Socket::DEFAULT_NAME, fixedSession);
87 m_syncSocket->addSyncNode(m_adjLsaUserPrefix, chronosync::Socket::DEFAULT_NAME, fixedSession);
88 m_syncSocket->addSyncNode(m_coorLsaUserPrefix, chronosync::Socket::DEFAULT_NAME, fixedSession);
97 for (
size_t i = 0; i < v.size(); i++){
98 ndn::Name updateName = v[i].session.getPrefix(-1);
100 NLSR_LOG_DEBUG(
"Update Name: " << updateName <<
" Seq no: " << v[i].high);
105 if (nlsrPosition < 0 || lsaPosition < 0) {
110 ndn::Name networkName = updateName.getSubName(1, nlsrPosition-1);
111 ndn::Name routerName = updateName.getSubName(lsaPosition + 1).getPrefix(-1);
113 ndn::Name originRouter = networkName;
114 originRouter.append(routerName);
116 processUpdateFromSync(originRouter, updateName, v[i].high);
121 SyncLogicHandler::processUpdateFromSync(
const ndn::Name& originRouter,
122 const ndn::Name& updateName,
const uint64_t& seqNo)
130 std::istringstream(updateName.get(updateName.size()-1).toUri()) >> lsaType;
133 <<
" sequence number than entry in LSDB");
135 if (m_isLsaNew(originRouter, lsaType, seqNo)) {
138 NLSR_LOG_ERROR(
"Got an update for adjacency LSA when hyperbolic routing" 139 <<
" is enabled. Not going to fetch.");
146 <<
" is enabled. Not going to fetch.");
149 (*onNewLsa)(updateName, seqNo);
157 if (m_syncSocket ==
nullptr) {
158 NLSR_LOG_FATAL(
"Cannot publish routing update; SyncSocket does not exist");
165 publishSyncUpdate(m_adjLsaUserPrefix, seqNo);
168 publishSyncUpdate(m_coorLsaUserPrefix, seqNo);
171 publishSyncUpdate(m_nameLsaUserPrefix, seqNo);
179 SyncLogicHandler::buildUpdatePrefix()
185 m_nameLsaUserPrefix = updatePrefix;
188 m_adjLsaUserPrefix = updatePrefix;
191 m_coorLsaUserPrefix = updatePrefix;
196 SyncLogicHandler::publishSyncUpdate(
const ndn::Name& updatePrefix, uint64_t seqNo)
198 NLSR_LOG_DEBUG(
"Publishing Sync Update. Prefix: " << updatePrefix <<
" Seq No: " << seqNo);
200 ndn::Name updateName(updatePrefix);
201 std::string data(
"NoData");
203 m_syncSocket->publishData(reinterpret_cast<const uint8_t*>(data.c_str()), data.size(),
204 ndn::time::milliseconds(1000), seqNo, updateName);
const std::string NLSR_COMPONENT
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.
#define NLSR_LOG_DEBUG(x)
ndn::util::Signal< SyncLogicHandler, const ndn::Name &, const uint64_t & > OnNewLsa
const ndn::Name & getRouterPrefix() const
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California.
#define INIT_LOGGER(name)
Copyright (c) 2014-2017, The University of Memphis, Regents of the University of California.
std::function< bool(const ndn::Name &, const Lsa::Type &lsaType, const uint64_t &)> IsLsaNew
const ndn::Name & getLsaPrefix() const
static int32_t getNameComponentPosition(const ndn::Name &name, const std::string &searchString)
search a name component in ndn::Name and return the position of the component
#define NLSR_LOG_ERROR(x)
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
void createSyncSocket(const ndn::Name &syncPrefix, const ndn::time::milliseconds &syncInterestLifetime=ndn::time::milliseconds(SYNC_INTEREST_LIFETIME_DEFAULT))
Create and configure a socket to enable ChronoSync for this NLSR.
const ndn::Name & getRouterName() const
int32_t getHyperbolicState() const
const std::string LSA_COMPONENT
SyncLogicHandler(ndn::Face &face, const IsLsaNew &isLsaNew, const ConfParameter &conf)
const ndn::Name & getSiteName() const
#define NLSR_LOG_FATAL(x)
void onChronoSyncUpdate(const std::vector< chronosync::MissingDataInfo > &v)
Hook function to call whenever sync detects new data.
void publishRoutingUpdate(const Lsa::Type &type, const uint64_t &seqNo)
Instruct ChronoSync to publish an update.