27 #include <ndn-cxx/encoding/nfd-constants.hpp>
37 , m_scheduler(m_face.getIoService())
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 ndn::Interest& interest,
const ndn::lp::Nack& nack)
77 NDN_LOG_TRACE(
"Received Nack with reason: " << nack.getReason());
78 NDN_LOG_TRACE(
"Will treat as timeout in " << 2 * seconds <<
" seconds");
79 m_scheduler.schedule(ndn::time::seconds(2 * seconds),
80 [
this, interest] { processInterestTimedOut(interest); });
82 std::bind(&HelloProtocol::processInterestTimedOut,
this, _1));
93 if (adjacent == m_adjacencyList.
end()) {
98 if(adjacent->getFaceId() != 0) {
100 ndn::Name interestName = adjacent->getName() ;
103 interestName.append(ndn::tlv::GenericNameComponent, m_confParam.
getRouterPrefix().wireEncode());
109 [
this, neighbor] { sendHelloInterest(neighbor); });
114 const ndn::Interest& interest)
117 const ndn::Name interestName = interest.getName();
124 NLSR_LOG_DEBUG(
"INFO_COMPONENT not found or interestName: " << interestName
125 <<
" does not match expression");
130 neighbor.wireDecode(interestName.get(-1).blockFromValue());
133 std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>();
134 data->setName(ndn::Name(interest.getName()).appendVersion());
135 data->setFreshnessPeriod(ndn::time::seconds(10));
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());
151 if(adjacent->getFaceId() != 0){
153 ndn::Name interestName(neighbor);
156 interestName.append(ndn::tlv::GenericNameComponent, m_confParam.
getRouterPrefix().wireEncode());
164 HelloProtocol::processInterestTimedOut(
const ndn::Interest& interest)
167 const ndn::Name interestName(interest.getName());
172 ndn::Name neighbor = interestName.getPrefix(-3);
180 NLSR_LOG_DEBUG(
"Info Interest Timed out: " << infoIntTimedOutCount);
183 ndn::Name interestName(neighbor);
186 interestName.append(ndn::tlv::GenericNameComponent, m_confParam.
getRouterPrefix().wireEncode());
193 NLSR_LOG_DEBUG(
"Neighbor: " << neighbor <<
" status changed to INACTIVE");
208 HelloProtocol::onContent(
const ndn::Interest& interest,
const ndn::Data& data)
210 NLSR_LOG_DEBUG(
"Received data for INFO(name): " << data.getName());
211 auto kl = data.getKeyLocator();
212 if (kl && kl->getType() == ndn::tlv::Name) {
216 std::bind(&HelloProtocol::onContentValidated,
this, _1),
217 std::bind(&HelloProtocol::onContentValidationFailed,
222 HelloProtocol::onContentValidated(
const ndn::Data& data)
225 ndn::Name dataName = data.getName();
226 NLSR_LOG_DEBUG(
"Data validation successful for INFO(name): " << dataName);
229 ndn::Name neighbor = dataName.getPrefix(-4);
237 NLSR_LOG_DEBUG(
"Old Status: " << oldStatus <<
" New Status: " << newStatus);
239 if ((oldStatus - newStatus) != 0) {
254 HelloProtocol::onContentValidationFailed(
const ndn::Data& data,
255 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
int32_t getHyperbolicState() const
uint32_t getInterestRetryNumber() const
const ndn::Name & getRouterPrefix() const
uint32_t getInterestResendTime() const
ndn::security::ValidatorConfig & getValidator()
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.
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::util::Signal< HelloProtocol, const ndn::Name & > onInitialHelloDataValidated
ndn::util::Signal< HelloProtocol, Statistics::PacketType > hpIncrementSignal
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.