31 const std::string HelloProtocol::INFO_COMPONENT =
"INFO";
32 const std::string HelloProtocol::NLSR_COMPONENT =
"nlsr";
38 , m_scheduler(m_face.getIoService())
39 , m_keyChain(keyChain)
40 , m_signingInfo(confParam.getSigningInfo())
41 , m_confParam(confParam)
42 , m_routingTable(routingTable)
44 , m_adjacencyList(m_confParam.getAdjacencyList())
52 ndn::Interest interest(interestName);
53 interest.setInterestLifetime(ndn::time::seconds(seconds));
54 interest.setMustBeFresh(
true);
55 interest.setCanBePrefix(
true);
56 m_face.expressInterest(interest,
57 std::bind(&HelloProtocol::onContent,
this, _1, _2),
58 [
this, seconds] (
const ndn::Interest& interest,
const ndn::lp::Nack& nack)
60 NDN_LOG_TRACE(
"Received Nack with reason: " << nack.getReason());
61 NDN_LOG_TRACE(
"Will treat as timeout in " << 2 * seconds <<
" seconds");
62 m_scheduler.schedule(ndn::time::seconds(2 * seconds),
63 [
this, interest] { processInterestTimedOut(interest); });
65 std::bind(&HelloProtocol::processInterestTimedOut,
this, _1));
76 if (adjacent == m_adjacencyList.
end()) {
81 if(adjacent->getFaceId() != 0) {
83 ndn::Name interestName = adjacent->getName() ;
84 interestName.append(NLSR_COMPONENT);
85 interestName.append(INFO_COMPONENT);
97 const ndn::Interest& interest)
100 const ndn::Name interestName = interest.getName();
106 if (interestName.get(-2).toUri() != INFO_COMPONENT) {
107 NLSR_LOG_DEBUG(
"INFO_COMPONENT not found or interestName: " << interestName
108 <<
" does not match expression");
113 neighbor.wireDecode(interestName.get(-1).blockFromValue());
116 std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>();
117 data->setName(ndn::Name(interest.getName()).appendVersion());
118 data->setFreshnessPeriod(ndn::time::seconds(10));
119 data->setContent(reinterpret_cast<const uint8_t*>(INFO_COMPONENT.c_str()),
120 INFO_COMPONENT.size());
122 m_keyChain.sign(*data, m_signingInfo);
124 NLSR_LOG_DEBUG(
"Sending out data for name: " << interest.getName());
134 if(adjacent->getFaceId() != 0){
136 ndn::Name interestName(neighbor);
137 interestName.append(NLSR_COMPONENT);
138 interestName.append(INFO_COMPONENT);
147 HelloProtocol::processInterestTimedOut(
const ndn::Interest& interest)
150 const ndn::Name interestName(interest.getName());
152 if (interestName.get(-2).toUri() != INFO_COMPONENT) {
155 ndn::Name neighbor = interestName.getPrefix(-3);
163 NLSR_LOG_DEBUG(
"Info Interest Timed out: " << infoIntTimedOutCount);
166 ndn::Name interestName(neighbor);
167 interestName.append(NLSR_COMPONENT);
168 interestName.append(INFO_COMPONENT);
177 NLSR_LOG_DEBUG(
"Neighbor: " << neighbor <<
" status changed to INACTIVE");
187 HelloProtocol::onContent(
const ndn::Interest& interest,
const ndn::Data& data)
189 NLSR_LOG_DEBUG(
"Received data for INFO(name): " << data.getName());
190 if (data.getSignature().hasKeyLocator() &&
191 data.getSignature().getKeyLocator().getType() == ndn::tlv::Name) {
192 NLSR_LOG_DEBUG(
"Data signed with: " << data.getSignature().getKeyLocator().getName());
195 std::bind(&HelloProtocol::onContentValidated,
this, _1),
196 std::bind(&HelloProtocol::onContentValidationFailed,
201 HelloProtocol::onContentValidated(
const ndn::Data& data)
204 ndn::Name dataName = data.getName();
205 NLSR_LOG_DEBUG(
"Data validation successful for INFO(name): " << dataName);
207 if (dataName.get(-3).toUri() == INFO_COMPONENT) {
208 ndn::Name neighbor = dataName.getPrefix(-4);
216 NLSR_LOG_DEBUG(
"Old Status: " << oldStatus <<
" New Status: " << newStatus);
218 if ((oldStatus - newStatus) != 0) {
234 HelloProtocol::onContentValidationFailed(
const ndn::Data& data,
235 const ndn::security::v2::ValidationError& ve)
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.
bool isNeighbor(const ndn::Name &adjName) const
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.
#define NLSR_LOG_DEBUG(x)
const ndn::Name & getRouterPrefix() 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.
int32_t getTimedOutInterestCount(const ndn::Name &neighbor) const
#define INIT_LOGGER(name)
uint32_t getInterestRetryNumber() const
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.
Adjacent::Status getStatusOfNeighbor(const ndn::Name &neighbor) const
void sendHelloInterest(const ndn::Name &neighbor)
Sends Hello Interests to all neighbors.
int32_t getHyperbolicState() const
Copyright (c) 2014-2019, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
AdjacencyList::iterator findAdjacent(const ndn::Name &adjName)
const_iterator end() const
HelloProtocol(ndn::Face &face, ndn::KeyChain &keyChain, ConfParameter &confParam, RoutingTable &routingTable, Lsdb &lsdb)
uint32_t getInterestResendTime() const
void incrementTimedOutInterestCount(const ndn::Name &neighbor)
uint32_t getInfoInterestInterval() const
void setStatusOfNeighbor(const ndn::Name &neighbor, Adjacent::Status status)