27 #include <ndn-cxx/encoding/nfd-constants.hpp>
37 , m_scheduler(m_face.getIoContext())
38 , m_keyChain(keyChain)
39 , m_signingInfo(confParam.getSigningInfo())
40 , m_confParam(confParam)
41 , m_routingTable(routingTable)
43 , m_adjacencyList(m_confParam.getAdjacencyList())
49 NLSR_LOG_DEBUG(
"Setting interest filter for Hello interest: " << name);
51 m_face.setInterestFilter(ndn::InterestFilter(name).allowLoopback(
false),
52 [
this] (
const auto& name,
const auto& interest) {
55 [] (
const auto& name) {
58 [] (
const auto& name,
const auto& resp) {
60 NDN_THROW(std::runtime_error(
"Failed to register hello prefix: " + resp));
62 m_signingInfo, ndn::nfd::ROUTE_FLAG_CAPTURE);
69 ndn::Interest interest(interestName);
70 interest.setInterestLifetime(ndn::time::seconds(seconds));
71 interest.setMustBeFresh(
true);
72 interest.setCanBePrefix(
true);
73 m_face.expressInterest(interest,
74 std::bind(&HelloProtocol::onContent,
this, _1, _2),
75 [
this, seconds] (
const auto& interest,
const auto& nack) {
76 NDN_LOG_TRACE(
"Received Nack with reason: " << nack.getReason());
77 NDN_LOG_TRACE(
"Will treat as timeout in " << 2 * seconds <<
" seconds");
78 m_scheduler.schedule(ndn::time::seconds(2 * seconds),
79 [
this, interest] { processInterestTimedOut(interest); });
81 std::bind(&HelloProtocol::processInterestTimedOut,
this, _1));
91 if (adjacent == m_adjacencyList.
end()) {
96 if(adjacent->getFaceId() != 0) {
98 ndn::Name interestName = adjacent->getName() ;
101 interestName.append(ndn::tlv::GenericNameComponent, m_confParam.
getRouterPrefix().wireEncode());
107 [
this, neighbor] { sendHelloInterest(neighbor); });
112 const ndn::Interest& interest)
115 const ndn::Name interestName = interest.getName();
122 NLSR_LOG_DEBUG(
"INFO_COMPONENT not found or Interest Name " << interestName
123 <<
" does not match expression");
127 ndn::Name neighbor(interestName.get(-1).blockFromValue());
130 auto data = std::make_shared<ndn::Data>();
131 data->setName(ndn::Name(interest.getName()).appendVersion());
135 data->setFreshnessPeriod(0_ms);
136 data->setContent(ndn::make_span(
reinterpret_cast<const uint8_t*
>(
INFO_COMPONENT.data()),
139 m_keyChain.sign(*data, m_signingInfo);
141 NLSR_LOG_DEBUG(
"Sending out data for name: " << interest.getName());
150 if (adjacent->getFaceId() != 0) {
152 ndn::Name interestName(neighbor);
155 interestName.append(ndn::tlv::GenericNameComponent, m_confParam.
getRouterPrefix().wireEncode());
163 HelloProtocol::processInterestTimedOut(
const ndn::Interest& interest)
166 const ndn::Name interestName(interest.getName());
171 ndn::Name neighbor = interestName.getPrefix(-3);
179 NLSR_LOG_DEBUG(
"Info Interest Timed out: " << infoIntTimedOutCount);
182 ndn::Name interestName(neighbor);
185 interestName.append(ndn::tlv::GenericNameComponent, m_confParam.
getRouterPrefix().wireEncode());
192 NLSR_LOG_DEBUG(
"Neighbor: " << neighbor <<
" status changed to INACTIVE");
207 HelloProtocol::onContent(
const ndn::Interest& interest,
const ndn::Data& data)
209 NLSR_LOG_DEBUG(
"Received data for INFO(name): " << data.getName());
210 auto kl = data.getKeyLocator();
211 if (kl && kl->getType() == ndn::tlv::Name) {
215 std::bind(&HelloProtocol::onContentValidated,
this, _1),
216 std::bind(&HelloProtocol::onContentValidationFailed,
221 HelloProtocol::onContentValidated(
const ndn::Data& data)
224 ndn::Name dataName = data.getName();
225 NLSR_LOG_DEBUG(
"Data validation successful for INFO(name): " << dataName);
228 ndn::Name neighbor = dataName.getPrefix(-4);
236 NLSR_LOG_DEBUG(
"Old Status: " << oldStatus <<
", New Status: " << newStatus);
238 if ((oldStatus - newStatus) != 0) {
253 HelloProtocol::onContentValidationFailed(
const ndn::Data& data,
254 const ndn::security::ValidationError& ve)
int32_t getTimedOutInterestCount(const ndn::Name &neighbor) const
void incrementTimedOutInterestCount(const ndn::Name &neighbor)
void setTimedOutInterestCount(const ndn::Name &neighbor, uint32_t count)
const_iterator end() const
Adjacent::Status getStatusOfNeighbor(const ndn::Name &neighbor) const
bool isNeighbor(const ndn::Name &adjName) const
void setStatusOfNeighbor(const ndn::Name &neighbor, Adjacent::Status status)
AdjacencyList::iterator findAdjacent(const ndn::Name &adjName)
A class to house all the configuration parameters for NLSR.
uint32_t getInfoInterestInterval() const
uint32_t getInterestRetryNumber() const
const ndn::Name & getRouterPrefix() const
uint32_t getInterestResendTime() const
ndn::security::ValidatorConfig & getValidator()
HyperbolicState getHyperbolicState() const
HelloProtocol(ndn::Face &face, ndn::KeyChain &keyChain, ConfParameter &confParam, RoutingTable &routingTable, Lsdb &lsdb)
void sendHelloInterest(const ndn::Name &neighbor)
Sends Hello Interests to all neighbors.
ndn::signal::Signal< HelloProtocol, Statistics::PacketType > hpIncrementSignal
static const std::string INFO_COMPONENT
static const std::string NLSR_COMPONENT
void processInterest(const ndn::Name &name, const ndn::Interest &interest)
Processes a Hello Interest from a neighbor.
void expressInterest(const ndn::Name &interestNamePrefix, uint32_t seconds)
Sends a Hello Interest packet.
ndn::signal::Signal< HelloProtocol, const ndn::Name & > onInitialHelloDataValidated
void scheduleAdjLsaBuild()
Schedules a build of this router's LSA.
void scheduleRoutingTableCalculation()
Schedules a calculation event in the event scheduler only if one isn't already scheduled.
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California.
#define NLSR_LOG_DEBUG(x)
#define INIT_LOGGER(name)
#define NLSR_LOG_ERROR(x)
Copyright (c) 2014-2020, The University of Memphis, Regents of the University of California.