32 const std::string HelloProtocol::INFO_COMPONENT =
"INFO";
33 const std::string HelloProtocol::NLSR_COMPONENT =
"nlsr";
36 ndn::security::SigningInfo& signingInfo,
40 , m_scheduler(m_face.getIoService())
41 , m_keyChain(keyChain)
42 , m_signingInfo(signingInfo)
43 , m_confParam(confParam)
44 , m_routingTable(routingTable)
53 ndn::Interest interest(interestName);
54 interest.setInterestLifetime(ndn::time::seconds(seconds));
55 interest.setMustBeFresh(
true);
56 interest.setCanBePrefix(
true);
57 m_face.expressInterest(interest,
58 std::bind(&HelloProtocol::onContent,
this, _1, _2),
59 [
this] (
const ndn::Interest& interest,
const ndn::lp::Nack& nack)
61 NDN_LOG_TRACE(
"Received Nack with reason " << nack.getReason());
62 NDN_LOG_TRACE(
"Treating as timeout");
63 processInterestTimedOut(interest);
65 std::bind(&HelloProtocol::processInterestTimedOut,
this, _1));
76 if(adjacent.getFaceId() != 0) {
78 ndn::Name interestName = adjacent.getName() ;
79 interestName.append(NLSR_COMPONENT);
80 interestName.append(INFO_COMPONENT);
92 NLSR_LOG_DEBUG(
"Scheduling HELLO Interests in " << ndn::time::seconds(seconds));
94 m_scheduler.scheduleEvent(ndn::time::seconds(seconds),
102 const ndn::Interest& interest)
105 const ndn::Name interestName = interest.getName();
111 if (interestName.get(-2).toUri() != INFO_COMPONENT) {
112 NLSR_LOG_DEBUG(
"INFO_COMPONENT not found or interestName: " << interestName
113 <<
" does not match expression");
118 neighbor.wireDecode(interestName.get(-1).blockFromValue());
121 std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>();
122 data->setName(ndn::Name(interest.getName()).appendVersion());
123 data->setFreshnessPeriod(ndn::time::seconds(10));
124 data->setContent(reinterpret_cast<const uint8_t*>(INFO_COMPONENT.c_str()),
125 INFO_COMPONENT.size());
127 m_keyChain.sign(*data, m_signingInfo);
129 NLSR_LOG_DEBUG(
"Sending out data for name: " << interest.getName());
139 if(adjacent->getFaceId() != 0){
141 ndn::Name interestName(neighbor);
142 interestName.append(NLSR_COMPONENT);
143 interestName.append(INFO_COMPONENT);
152 HelloProtocol::processInterestTimedOut(
const ndn::Interest& interest)
155 const ndn::Name interestName(interest.getName());
157 if (interestName.get(-2).toUri() != INFO_COMPONENT) {
160 ndn::Name neighbor = interestName.getPrefix(-3);
166 uint32_t infoIntTimedOutCount =
169 NLSR_LOG_DEBUG(
"Info Interest Timed out: " << infoIntTimedOutCount);
172 ndn::Name interestName(neighbor);
173 interestName.append(NLSR_COMPONENT);
174 interestName.append(INFO_COMPONENT);
183 NLSR_LOG_DEBUG(
"Neighbor: " << neighbor <<
" status changed to INACTIVE");
193 HelloProtocol::onContent(
const ndn::Interest& interest,
const ndn::Data& data)
195 NLSR_LOG_DEBUG(
"Received data for INFO(name): " << data.getName());
196 if (data.getSignature().hasKeyLocator()) {
197 if (data.getSignature().getKeyLocator().getType() == ndn::KeyLocator::KeyLocator_Name) {
198 NLSR_LOG_DEBUG(
"Data signed with: " << data.getSignature().getKeyLocator().getName());
202 std::bind(&HelloProtocol::onContentValidated,
this, _1),
203 std::bind(&HelloProtocol::onContentValidationFailed,
208 HelloProtocol::onContentValidated(
const ndn::Data& data)
211 ndn::Name dataName = data.getName();
212 NLSR_LOG_DEBUG(
"Data validation successful for INFO(name): " << dataName);
214 if (dataName.get(-3).toUri() == INFO_COMPONENT) {
215 ndn::Name neighbor = dataName.getPrefix(-4);
223 NLSR_LOG_DEBUG(
"Old Status: " << oldStatus <<
" New Status: " << newStatus);
225 if ((oldStatus - newStatus) != 0) {
239 HelloProtocol::onContentValidationFailed(
const ndn::Data& data,
240 const ndn::security::v2::ValidationError& ve)
uint32_t getInterestResendTime() const
void setTimedOutInterestCount(const ndn::Name &neighbor, uint32_t count)
ndn::security::ValidatorConfig & getValidator()
A class to house all the configuration parameters for NLSR.
void scheduleAdjLsaBuild()
Schedules a build of this router's LSA.
ndn::util::signal::Signal< HelloProtocol, Statistics::PacketType > hpIncrementSignal
void scheduleRoutingTableCalculation()
Schedules a calculation event in the event scheduler only if one isn't already scheduled.
bool isNeighbor(const ndn::Name &adjName) const
AdjacencyList & getAdjacencyList()
#define NLSR_LOG_DEBUG(x)
uint32_t getInfoInterestInterval() const
const ndn::Name & getRouterPrefix() const
Adjacent::Status getStatusOfNeighbor(const ndn::Name &neighbor) const
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California.
void expressInterest(const ndn::Name &interestNamePrefix, uint32_t seconds)
Sends a Hello Interest packet.
HelloProtocol(ndn::Face &face, ndn::KeyChain &keyChain, ndn::security::SigningInfo &signingInfo, ConfParameter &confParam, RoutingTable &routingTable, Lsdb &lsdb)
void scheduleInterest(uint32_t seconds)
Schedules a Hello Interest event.
#define INIT_LOGGER(name)
uint32_t getInterestRetryNumber() const
void processInterest(const ndn::Name &name, const ndn::Interest &interest)
Processes a Hello Interest from a neighbor.
int32_t getTimedOutInterestCount(const ndn::Name &neighbor) const
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
AdjacencyList::iterator findAdjacent(const ndn::Name &adjName)
int32_t getHyperbolicState() const
void sendScheduledInterest()
Sends Hello Interests to all neighbors.
void incrementTimedOutInterestCount(const ndn::Name &neighbor)
std::list< Adjacent > & getAdjList()
void setStatusOfNeighbor(const ndn::Name &neighbor, Adjacent::Status status)