49 , m_isLsaNew(isLsaNew)
57 if (m_syncSocket !=
nullptr) {
58 NLSR_LOG_WARN(
"Trying to create Sync socket, but Sync socket already exists");
62 m_syncPrefix = syncPrefix;
67 NLSR_LOG_DEBUG(
"Creating Sync socket. Sync Prefix: " << m_syncPrefix);
73 m_syncSocket = std::make_shared<chronosync::Socket>(m_syncPrefix, m_nameLsaUserPrefix, *facePtr,
77 m_syncSocket->addSyncNode(m_adjLsaUserPrefix);
80 m_syncSocket->addSyncNode(m_coorLsaUserPrefix);
89 for (
size_t i = 0; i < v.size(); i++){
90 ndn::Name updateName = v[i].session.getPrefix(-1);
92 NLSR_LOG_DEBUG(
"Update Name: " << updateName <<
" Seq no: " << v[i].high);
97 if (nlsrPosition < 0 || lsaPosition < 0) {
102 ndn::Name networkName = updateName.getSubName(1, nlsrPosition-1);
103 ndn::Name routerName = updateName.getSubName(lsaPosition + 1).getPrefix(-1);
105 ndn::Name originRouter = networkName;
106 originRouter.append(routerName);
108 processUpdateFromSync(originRouter, updateName, v[i].high);
113 SyncLogicHandler::processUpdateFromSync(
const ndn::Name& originRouter,
114 const ndn::Name& updateName,
const uint64_t& seqNo)
122 std::istringstream(updateName.get(updateName.size()-1).toUri()) >> lsaType;
125 <<
" sequence number than entry in LSDB");
127 if (m_isLsaNew(originRouter, lsaType, seqNo)) {
130 NLSR_LOG_ERROR(
"Got an update for adjacency LSA when hyperbolic routing" 131 <<
" is enabled. Not going to fetch.");
138 <<
" is enabled. Not going to fetch.");
141 (*onNewLsa)(updateName, seqNo);
149 if (m_syncSocket ==
nullptr) {
150 NLSR_LOG_FATAL(
"Cannot publish routing update; SyncSocket does not exist");
158 publishSyncUpdate(m_adjLsaUserPrefix, seqNo);
161 publishSyncUpdate(m_coorLsaUserPrefix, seqNo);
164 publishSyncUpdate(m_nameLsaUserPrefix, seqNo);
172 SyncLogicHandler::buildUpdatePrefix()
178 m_nameLsaUserPrefix = updatePrefix;
181 m_adjLsaUserPrefix = updatePrefix;
184 m_coorLsaUserPrefix = updatePrefix;
189 SyncLogicHandler::publishSyncUpdate(
const ndn::Name& updatePrefix, uint64_t seqNo)
191 NLSR_LOG_DEBUG(
"Publishing Sync Update. Prefix: " << updatePrefix <<
" Seq No: " << seqNo);
193 ndn::Name updateName(updatePrefix);
194 std::string data(
"NoData");
196 m_syncSocket->publishData(reinterpret_cast<const uint8_t*>(data.c_str()), data.size(),
197 ndn::time::milliseconds(1000), seqNo, updateName);
const std::string NLSR_COMPONENT
A class to house all the configuration parameters for NLSR.
Copyright (c) 2014-2017, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
SyncLogicHandler(ndn::Face &face, const IsLsaNew &isLsaNew, ConfParameter &conf)
#define NLSR_LOG_DEBUG(x)
ndn::util::Signal< SyncLogicHandler, const ndn::Name &, const uint64_t & > OnNewLsa
const ndn::Name & getRouterPrefix() const
Copyright (c) 2014-2017, 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-2017, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
const ndn::Name & getRouterName() const
int32_t getHyperbolicState() const
const std::string LSA_COMPONENT
void createSyncSocket(const ndn::Name &syncPrefix)
Create and configure a socket to enable ChronoSync for this NLSR.
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.