27 #include <ndn-cxx/encoding/nfd-constants.hpp>
33 const std::string HelloProtocol::INFO_COMPONENT =
"INFO";
34 const std::string HelloProtocol::NLSR_COMPONENT =
"nlsr";
40 , m_scheduler(m_face.getIoService())
41 , m_keyChain(keyChain)
42 , m_signingInfo(confParam.getSigningInfo())
43 , m_confParam(confParam)
44 , m_routingTable(routingTable)
46 , m_adjacencyList(m_confParam.getAdjacencyList())
49 name.append(NLSR_COMPONENT);
50 name.append(INFO_COMPONENT);
52 NLSR_LOG_DEBUG(
"Setting interest filter for Hello interest: " << name);
54 m_face.setInterestFilter(ndn::InterestFilter(name).allowLoopback(
false),
55 [
this] (
const auto& name,
const auto& interest) {
58 [] (
const auto& name) {
61 [] (
const auto& name,
const auto& resp) {
63 NDN_THROW(std::runtime_error(
"Failed to register hello prefix: " + resp));
65 m_signingInfo, ndn::nfd::ROUTE_FLAG_CAPTURE);
72 ndn::Interest interest(interestName);
73 interest.setInterestLifetime(ndn::time::seconds(seconds));
74 interest.setMustBeFresh(
true);
75 interest.setCanBePrefix(
true);
76 m_face.expressInterest(interest,
77 std::bind(&HelloProtocol::onContent,
this, _1, _2),
78 [
this, seconds] (
const ndn::Interest& interest,
const ndn::lp::Nack& nack)
80 NDN_LOG_TRACE(
"Received Nack with reason: " << nack.getReason());
81 NDN_LOG_TRACE(
"Will treat as timeout in " << 2 * seconds <<
" seconds");
82 m_scheduler.schedule(ndn::time::seconds(2 * seconds),
83 [
this, interest] { processInterestTimedOut(interest); });
85 std::bind(&HelloProtocol::processInterestTimedOut,
this, _1));
96 if (adjacent == m_adjacencyList.
end()) {
101 if(adjacent->getFaceId() != 0) {
103 ndn::Name interestName = adjacent->getName() ;
104 interestName.append(NLSR_COMPONENT);
105 interestName.append(INFO_COMPONENT);
112 [
this, neighbor] { sendHelloInterest(neighbor); });
117 const ndn::Interest& interest)
120 const ndn::Name interestName = interest.getName();
126 if (interestName.get(-2).toUri() != INFO_COMPONENT) {
127 NLSR_LOG_DEBUG(
"INFO_COMPONENT not found or interestName: " << interestName
128 <<
" does not match expression");
133 neighbor.wireDecode(interestName.get(-1).blockFromValue());
136 std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>();
137 data->setName(ndn::Name(interest.getName()).appendVersion());
138 data->setFreshnessPeriod(ndn::time::seconds(10));
139 data->setContent(
reinterpret_cast<const uint8_t*
>(INFO_COMPONENT.c_str()),
140 INFO_COMPONENT.size());
142 m_keyChain.sign(*data, m_signingInfo);
144 NLSR_LOG_DEBUG(
"Sending out data for name: " << interest.getName());
154 if(adjacent->getFaceId() != 0){
156 ndn::Name interestName(neighbor);
157 interestName.append(NLSR_COMPONENT);
158 interestName.append(INFO_COMPONENT);
167 HelloProtocol::processInterestTimedOut(
const ndn::Interest& interest)
170 const ndn::Name interestName(interest.getName());
172 if (interestName.get(-2).toUri() != INFO_COMPONENT) {
175 ndn::Name neighbor = interestName.getPrefix(-3);
183 NLSR_LOG_DEBUG(
"Info Interest Timed out: " << infoIntTimedOutCount);
186 ndn::Name interestName(neighbor);
187 interestName.append(NLSR_COMPONENT);
188 interestName.append(INFO_COMPONENT);
196 NLSR_LOG_DEBUG(
"Neighbor: " << neighbor <<
" status changed to INACTIVE");
211 HelloProtocol::onContent(
const ndn::Interest& interest,
const ndn::Data& data)
213 NLSR_LOG_DEBUG(
"Received data for INFO(name): " << data.getName());
214 auto kl = data.getKeyLocator();
215 if (kl && kl->getType() == ndn::tlv::Name) {
219 std::bind(&HelloProtocol::onContentValidated,
this, _1),
220 std::bind(&HelloProtocol::onContentValidationFailed,
225 HelloProtocol::onContentValidated(
const ndn::Data& data)
228 ndn::Name dataName = data.getName();
229 NLSR_LOG_DEBUG(
"Data validation successful for INFO(name): " << dataName);
231 if (dataName.get(-3).toUri() == INFO_COMPONENT) {
232 ndn::Name neighbor = dataName.getPrefix(-4);
240 NLSR_LOG_DEBUG(
"Old Status: " << oldStatus <<
" New Status: " << newStatus);
242 if ((oldStatus - newStatus) != 0) {
258 HelloProtocol::onContentValidationFailed(
const ndn::Data& data,
259 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.
ndn::util::signal::Signal< HelloProtocol, Statistics::PacketType > hpIncrementSignal
ndn::util::Signal< HelloProtocol, const ndn::Name & > onHelloDataValidated
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.
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,...