// After we create a new Face, we need to set it up for use. This // function sets the controlling strategy, registers prefixes in // sync, broadcast, and LSA. void HelloProtocol::onRegistrationSuccess(const ndn::nfd::ControlParameters& commandSuccessResult, const ndn::Name& neighbor,const ndn::time::milliseconds& timeout) { Adjacent *adjacent = m_nlsr.getAdjacencyList().findAdjacent(neighbor); if (adjacent != 0) { adjacent->setFaceId(commandSuccessResult.getFaceId()); ndn::Name broadcastKeyPrefix = DEFAULT_BROADCAST_PREFIX; broadcastKeyPrefix.append("KEYS"); std::string faceUri = adjacent->getConnectingFaceUri(); double linkCost = adjacent->getLinkCost(); m_nlsr.getFib().registerPrefix(m_nlsr.getConfParameter().getChronosyncPrefix(), faceUri, linkCost, timeout, ndn::nfd::ROUTE_FLAG_CAPTURE, 0); m_nlsr.getFib().registerPrefix(m_nlsr.getConfParameter().getLsaPrefix(), faceUri, linkCost, timeout, ndn::nfd::ROUTE_FLAG_CAPTURE, 0); m_nlsr.getFib().registerPrefix(broadcastKeyPrefix, faceUri, linkCost, timeout, ndn::nfd::ROUTE_FLAG_CAPTURE, 0); // Sends a Hello Interest to determine status before the next scheduled. /* interest name: /<neighbor>/NLSR/INFO/<router> */ ndn::Name interestName(neighbor); interestName.append(NLSR_COMPONENT); interestName.append(INFO_COMPONENT); interestName.append(m_nlsr.getConfParameter().getRouterPrefix().wireEncode()); expressInterest(interestName, m_nlsr.getConfParameter().getInterestResendTime()); } }
void HelloProtocol::onRegistrationSuccess(const ndn::nfd::ControlParameters& commandSuccessResult, const ndn::Name& neighbor) { Adjacent *adjacent = m_nlsr.getAdjacencyList().findAdjacent(neighbor); if (adjacent != 0) { adjacent->setFaceId(commandSuccessResult.getFaceId()); /* interest name: /<neighbor>/NLSR/INFO/<router> */ ndn::Name interestName(neighbor); interestName.append(NLSR_COMPONENT); interestName.append(INFO_COMPONENT); interestName.append(m_nlsr.getConfParameter().getRouterPrefix().wireEncode()); expressInterest(interestName, m_nlsr.getConfParameter().getInterestResendTime()); } }
void HelloProtocol::onRegistrationFailure(const ndn::nfd::ControlResponse& response, const ndn::Name& name) { _LOG_DEBUG(response.getText() << " (code: " << response.getCode() << ")"); /* * If NLSR can not create face for given faceUri then it will treat this * failure as one INFO interest timed out. So that NLSR can move on with * building Adj Lsa and calculate routing table. NLSR does not build Adj * Lsa unless all the neighbors are ACTIVE or DEAD. For considering the * missconfigured(link) neighbour dead this is required. */ Adjacent *adjacent = m_nlsr.getAdjacencyList().findAdjacent(name); if (adjacent != 0) { adjacent->setInterestTimedOutNo(adjacent->getInterestTimedOutNo() + 1); Adjacent::Status status = adjacent->getStatus(); uint32_t infoIntTimedOutCount = adjacent->getInterestTimedOutNo(); if (infoIntTimedOutCount == m_nlsr.getConfParameter().getInterestRetryNumber()) { if (status == Adjacent::STATUS_ACTIVE) { adjacent->setStatus(Adjacent::STATUS_INACTIVE); } m_nlsr.getLsdb().scheduleAdjLsaBuild(); } } }
void HelloProtocol::processInterest(const ndn::Name& name, const ndn::Interest& interest) { /* interest name: /<neighbor>/NLSR/INFO/<router> */ const ndn::Name interestName = interest.getName(); _LOG_DEBUG("Interest Received for Name: " << interestName); if (interestName.get(-2).toUri() != INFO_COMPONENT) { return; } ndn::Name neighbor; neighbor.wireDecode(interestName.get(-1).blockFromValue()); _LOG_DEBUG("Neighbor: " << neighbor); if (m_nlsr.getAdjacencyList().isNeighbor(neighbor)) { ndn::shared_ptr<ndn::Data> data = ndn::make_shared<ndn::Data>(); data->setName(ndn::Name(interest.getName()).appendVersion()); data->setFreshnessPeriod(ndn::time::seconds(10)); // 10 sec data->setContent(reinterpret_cast<const uint8_t*>(INFO_COMPONENT.c_str()), INFO_COMPONENT.size()); m_nlsr.getKeyChain().sign(*data, m_nlsr.getDefaultCertName()); _LOG_DEBUG("Sending out data for name: " << interest.getName()); m_nlsr.getNlsrFace().put(*data); Adjacent *adjacent = m_nlsr.getAdjacencyList().findAdjacent(neighbor); // If this neighbor was previously inactive, send our own hello interest, too if (adjacent->getStatus() == Adjacent::STATUS_INACTIVE) { // We can only do that if the neighbor currently has a face. if(adjacent->getFaceId() != 0){ /* interest name: /<neighbor>/NLSR/INFO/<router> */ ndn::Name interestName(neighbor); interestName.append(NLSR_COMPONENT); interestName.append(INFO_COMPONENT); interestName.append(m_nlsr.getConfParameter().getRouterPrefix().wireEncode()); expressInterest(interestName, m_nlsr.getConfParameter().getInterestResendTime()); } // If the originator of the Interest currently lacks a Face, we // need to give it one. else { registerPrefixes(adjacent->getName(), adjacent->getConnectingFaceUri(), adjacent->getLinkCost(), ndn::time::milliseconds::max()); } } } }
void HelloProtocol::processInterest(const ndn::Name& name, const ndn::Interest& interest) { /* interest name: /<neighbor>/NLSR/INFO/<router> */ const ndn::Name interestName = interest.getName(); _LOG_DEBUG("Interest Received for Name: " << interestName); if (interestName.get(-2).toUri() != INFO_COMPONENT) { return; } ndn::Name neighbor; neighbor.wireDecode(interestName.get(-1).blockFromValue()); _LOG_DEBUG("Neighbor: " << neighbor); if (m_nlsr.getAdjacencyList().isNeighbor(neighbor)) { ndn::shared_ptr<ndn::Data> data = ndn::make_shared<ndn::Data>(); data->setName(ndn::Name(interest.getName()).appendVersion()); data->setFreshnessPeriod(ndn::time::seconds(10)); // 10 sec data->setContent(reinterpret_cast<const uint8_t*>(INFO_COMPONENT.c_str()), INFO_COMPONENT.size()); m_nlsr.getKeyChain().sign(*data, m_nlsr.getDefaultCertName()); _LOG_DEBUG("Sending out data for name: " << interest.getName()); m_nlsr.getNlsrFace().put(*data); Adjacent *adjacent = m_nlsr.getAdjacencyList().findAdjacent(neighbor); if (adjacent->getStatus() == 0) { if(adjacent->getFaceId() != 0){ /* interest name: /<neighbor>/NLSR/INFO/<router> */ ndn::Name interestName(neighbor); interestName.append(NLSR_COMPONENT); interestName.append(INFO_COMPONENT); interestName.append(m_nlsr.getConfParameter().getRouterPrefix().wireEncode()); expressInterest(interestName, m_nlsr.getConfParameter().getInterestResendTime()); } else { registerPrefixes(adjacent->getName(), adjacent->getConnectingFaceUri(), adjacent->getLinkCost(), ndn::time::milliseconds::max()); } } } }