void Policy::setLimit(size_t nMaxEntries) { NFD_LOG_INFO("setLimit " << nMaxEntries); m_limit = nMaxEntries; this->evictEntries(); }
void Nfd::initialize() { configureLogging(); m_forwarder = make_unique<Forwarder>(); FaceTable& faceTable = m_forwarder->getFaceTable(); faceTable.addReserved(face::makeNullFace(), face::FACEID_NULL); faceTable.addReserved(face::makeNullFace(FaceUri("contentstore://")), face::FACEID_CONTENT_STORE); m_faceSystem = make_unique<face::FaceSystem>(faceTable, m_netmon); initializeManagement(); PrivilegeHelper::drop(); m_netmon->onNetworkStateChanged.connect([this] { // delay stages, so if multiple events are triggered in short sequence, // only one auto-detection procedure is triggered m_reloadConfigEvent = getScheduler().schedule(5_s, [this] { NFD_LOG_INFO("Network change detected, reloading face section of the config file..."); this->reloadConfigFileFaceSection(); }); }); }
void FibManager::addNextHop(const Name& topPrefix, const Interest& interest, ControlParameters parameters, const ndn::mgmt::CommandContinuation& done) { setFaceForSelfRegistration(interest, parameters); const Name& prefix = parameters.getName(); FaceId faceId = parameters.getFaceId(); uint64_t cost = parameters.getCost(); NFD_LOG_TRACE("add-nexthop prefix: " << prefix << " faceid: " << faceId << " cost: " << cost); auto face = m_getFace(faceId); if (static_cast<bool>(face)) { auto entry = m_fib.insert(prefix).first; entry->addNextHop(face, cost); NFD_LOG_DEBUG("add-nexthop result: OK" << " prefix:" << prefix << " faceid: " << faceId << " cost: " << cost); return done(ControlResponse(200, "Success").setBody(parameters.wireEncode())); } else { NFD_LOG_INFO("add-nexthop result: FAIL reason: unknown-faceid: " << faceId); return done(ControlResponse(410, "Face not found")); } }
void InternalFace::setInterestFilter(const Name& filter, OnInterest onInterest) { NFD_LOG_INFO("registering callback for " << filter); m_interestFilters[filter] = onInterest; }
void RibManager::unregisterEntry(const shared_ptr<const Interest>& request, ControlParameters& params) { ndn::nfd::RibUnregisterCommand command; // Passing all parameters gives error in validation, // so passing only the required arguments. ControlParameters parameters; parameters.setName(params.getName()); if (params.hasFaceId()) { parameters.setFaceId(params.getFaceId()); } if (params.hasOrigin()) { parameters.setOrigin(params.getOrigin()); } if (!validateParameters(command, parameters)) { NFD_LOG_DEBUG("unregister result: FAIL reason: malformed"); if (static_cast<bool>(request)) { sendResponse(request->getName(), 400, "Malformed command"); } return; } bool isSelfRegistration = (!parameters.hasFaceId() || parameters.getFaceId() == 0); if (isSelfRegistration) { shared_ptr<lp::IncomingFaceIdTag> incomingFaceIdTag = request->getTag<lp::IncomingFaceIdTag>(); if (incomingFaceIdTag == nullptr) { sendResponse(request->getName(), 503, "requested self-registration, but IncomingFaceId is unavailable"); return; } parameters.setFaceId(*incomingFaceIdTag); } // Respond since command is valid and authorized sendSuccessResponse(request, parameters); Route route; route.faceId = parameters.getFaceId(); route.origin = parameters.getOrigin(); NFD_LOG_INFO("Removing route " << parameters.getName() << " nexthop=" << route.faceId << " origin=" << route.origin); RibUpdate update; update.setAction(RibUpdate::UNREGISTER) .setName(parameters.getName()) .setRoute(route); m_managedRib.beginApplyUpdate(update, bind(&RibManager::onRibUpdateSuccess, this, update), bind(&RibManager::onRibUpdateFailure, this, update, _1, _2)); }
void Entry::setStrategy(shared_ptr<fw::Strategy> strategy) { BOOST_ASSERT(static_cast<bool>(strategy)); m_strategy = strategy; NFD_LOG_INFO("Set strategy " << strategy->getName() << " for " << m_prefix << " prefix"); }
void terminate(const boost::system::error_code& error, int signalNo) { if (error) return; NFD_LOG_INFO("Caught signal '" << ::strsignal(signalNo) << "', exiting..."); getGlobalIoService().stop(); }
void reload(const boost::system::error_code& error, int signalNo) { if (error) return; NFD_LOG_INFO("Caught signal '" << ::strsignal(signalNo) << "', reloading..."); m_nfd.reloadConfigFile(); m_reloadSignalSet.async_wait(bind(&NfdRunner::reload, this, _1, _2)); }
void RibManager::startListening(const Name& commandPrefix, const ndn::OnInterest& onRequest) { NFD_LOG_INFO("Listening on: " << commandPrefix); m_nfdController.start<ndn::nfd::FibAddNextHopCommand>( ControlParameters() .setName(commandPrefix) .setFaceId(0), bind(&RibManager::onNrdCommandPrefixAddNextHopSuccess, this, cref(commandPrefix), _1), bind(&RibManager::onNrdCommandPrefixAddNextHopError, this, cref(commandPrefix), _2)); m_face.setInterestFilter(commandPrefix, onRequest); }
void FaceTable::addImpl(shared_ptr<Face> face, FaceId faceId) { face->setId(faceId); m_faces[faceId] = face; NFD_LOG_INFO("Added face id=" << faceId << " remote=" << face->getRemoteUri() << " local=" << face->getLocalUri()); face->onReceiveInterest += bind(&Forwarder::onInterest, &m_forwarder, ref(*face), _1); face->onReceiveData += bind(&Forwarder::onData, &m_forwarder, ref(*face), _1); face->onFail += bind(&FaceTable::remove, this, face); this->onAdd(face); }
void RibManager::registerWithNfd() { //check whether the components of localhop and localhost prefixes are same BOOST_ASSERT(COMMAND_PREFIX.size() == REMOTE_COMMAND_PREFIX.size()); this->startListening(COMMAND_PREFIX, bind(&RibManager::onLocalhostRequest, this, _2)); if (m_isLocalhopEnabled) { this->startListening(REMOTE_COMMAND_PREFIX, bind(&RibManager::onLocalhopRequest, this, _2)); } NFD_LOG_INFO("Start monitoring face create/destroy events"); m_faceMonitor.onNotification.connect(bind(&RibManager::onNotification, this, _1)); m_faceMonitor.start(); scheduleActiveFaceFetch(ACTIVE_FACE_FETCH_INTERVAL); }
void FaceTable::remove(shared_ptr<Face> face) { this->onRemove(face); FaceId faceId = face->getId(); m_faces.erase(faceId); face->setId(INVALID_FACEID); NFD_LOG_INFO("Removed face id=" << faceId << " remote=" << face->getRemoteUri() << " local=" << face->getLocalUri()); // XXX This clears all subscriptions, because EventEmitter // does not support only removing Forwarder's subscription face->onReceiveInterest.clear(); face->onReceiveData .clear(); face->onSendInterest .clear(); face->onSendData .clear(); // don't clear onFail because other functions may need to execute m_forwarder.getFib().removeNextHopFromAllEntries(face); }
void MadmStrategy::afterReceiveInterest(const Face& inFace, const Interest& interest, shared_ptr<fib::Entry> fibEntry, shared_ptr<pit::Entry> pitEntry) { if (!initialized) { // Set initial cost for (auto n : fibEntry->getNextHops()) { costMap[n.getFace()->getId()].setCost(n.getCost()); } initialized = true; } Name currentPrefix; shared_ptr < MeasurementInfo > measurementInfo; std::tie(currentPrefix, measurementInfo) = StrategyHelper::findPrefixMeasurements(interest, this->getMeasurements()); // Prefix info not found, create new prefix measurements if (measurementInfo == nullptr) { NFD_LOG_INFO("New prefix " << interest.getName() << " from " << inFace.getId()); measurementInfo = StrategyHelper::addPrefixMeasurements(interest, this->getMeasurements()); measurementInfo->req.parseParameters( ownStrategyChoice.findEffectiveParameters(interest.getName())); NFD_LOG_INFO( "Requirements: " << measurementInfo->req.getLimit(RequirementType::DELAY) << ", " << measurementInfo->req.getLimit(RequirementType::LOSS) << ", " << measurementInfo->req.getLimit(RequirementType::COST)); } shared_ptr < Face > outFace = NULL; double maxtotalValue = -1; for (auto n : fibEntry->getNextHops()) { bool isWorkingFace = (n.getFace()->getId() == measurementInfo->currentWorkingFace); double totalValue = 0; for (auto currentType : measurementInfo->req.getOwnTypes()) { InterfaceEstimation ¤tFaceInfo = faceInfoTable[n.getFace()->getId()]; double currentReqValue; if (currentType == RequirementType::COST) { currentReqValue = costMap[n.getFace()->getId()].getCost(); } else { currentReqValue = currentFaceInfo.getCurrentValue(currentType); } double lowerLimit = measurementInfo->req.getLimits(currentType).first; double upperLimit = measurementInfo->req.getLimits(currentType).second; double localValue; if (currentType == RequirementType::BANDWIDTH && n.getFace()->getId() != measurementInfo->currentWorkingFace) { localValue = 0.5; } else { localValue = calculateValue(currentReqValue, lowerLimit, upperLimit, StrategyRequirements::isUpwardAttribute(currentType)); } if (localValue == 0) { totalValue = 0; break; } else { totalValue += localValue; } } if (isWorkingFace) { totalValue *= (1.0 + HYSTERESIS_PERCENTAGE); } if (totalValue >= maxtotalValue) { maxtotalValue = totalValue; outFace = n.getFace(); } } NFD_LOG_TRACE("Face: " << outFace->getId() << " value: " << maxtotalValue); if (helper.probingDue()) { probeInterests(outFace, interest, measurementInfo->req, fibEntry->getNextHops(), pitEntry); } faceInfoTable[outFace->getId()].addSentInterest(interest.getName().toUri()); if (outFace->getId() != measurementInfo->currentWorkingFace) { NFD_LOG_TRACE( "New current working face from " << measurementInfo->currentWorkingFace << " to " << outFace->getId()); measurementInfo->currentWorkingFace = outFace->getId(); } this->sendInterest(pitEntry, outFace); }
void RibManager::registerEntry(const shared_ptr<const Interest>& request, ControlParameters& parameters) { ndn::nfd::RibRegisterCommand command; if (!validateParameters(command, parameters)) { NFD_LOG_DEBUG("register result: FAIL reason: malformed"); if (static_cast<bool>(request)) { sendResponse(request->getName(), 400, "Malformed command"); } return; } bool isSelfRegistration = (!parameters.hasFaceId() || parameters.getFaceId() == 0); if (isSelfRegistration) { shared_ptr<lp::IncomingFaceIdTag> incomingFaceIdTag = request->getTag<lp::IncomingFaceIdTag>(); if (incomingFaceIdTag == nullptr) { sendResponse(request->getName(), 503, "requested self-registration, but IncomingFaceId is unavailable"); return; } parameters.setFaceId(*incomingFaceIdTag); } // Respond since command is valid and authorized sendSuccessResponse(request, parameters); Route route; route.faceId = parameters.getFaceId(); route.origin = parameters.getOrigin(); route.cost = parameters.getCost(); route.flags = parameters.getFlags(); if (parameters.hasExpirationPeriod() && parameters.getExpirationPeriod() != time::milliseconds::max()) { route.expires = time::steady_clock::now() + parameters.getExpirationPeriod(); // Schedule a new event, the old one will be cancelled during rib insertion. scheduler::EventId eventId = scheduler::schedule(parameters.getExpirationPeriod(), bind(&Rib::onRouteExpiration, &m_managedRib, parameters.getName(), route)); NFD_LOG_TRACE("Scheduled unregistration at: " << route.expires << " with EventId: " << eventId); // Set the NewEventId of this entry route.setExpirationEvent(eventId); } else { route.expires = time::steady_clock::TimePoint::max(); } NFD_LOG_INFO("Adding route " << parameters.getName() << " nexthop=" << route.faceId << " origin=" << route.origin << " cost=" << route.cost); RibUpdate update; update.setAction(RibUpdate::REGISTER) .setName(parameters.getName()) .setRoute(route); m_managedRib.beginApplyUpdate(update, bind(&RibManager::onRibUpdateSuccess, this, update), bind(&RibManager::onRibUpdateFailure, this, update, _1, _2)); m_registeredFaces.insert(route.faceId); }
void PickOneStrategy::afterReceiveInterest(const Face& inFace, const Interest& interest, shared_ptr<fib::Entry> fibEntry, shared_ptr<fib::Entry> sitEntry, shared_ptr<pit::Entry> pitEntry) { NFD_LOG_DEBUG("afterReceiveInterest interest=" << interest.getName()); int sdc = pitEntry->getFloodFlag(); uint32_t cost = 1; bool sent = false; if(fibEntry->hasNextHops()) { cost = fibEntry->getNextHops()[0].getCost(); } if(pitEntry->getDestinationFlag() && static_cast<bool>(sitEntry) /*&& sdc > 0*/) {//Destination Flag is set so follow a randomly picked nexthop in SIT const fib::NextHopList& nexthops = sitEntry->getNextHops(); // Ensure there is at least 1 Face is available for forwarding if (hasFaceForForwarding(nexthops, pitEntry)) { fib::NextHopList::const_iterator selected; do { boost::random::uniform_int_distribution<> dist(0, nexthops.size() - 1); const size_t randomIndex = dist(m_randomGenerator); uint64_t currentIndex = 0; for (selected = nexthops.begin(); selected != nexthops.end() && currentIndex != randomIndex; ++selected, ++currentIndex) { } } while (!canForwardToNextHop(pitEntry, *selected)); sent = true; this->sendInterest(pitEntry, selected->getFace()); } } else if(!pitEntry->getDestinationFlag() && static_cast<bool>(sitEntry) && sdc > 0 && cost > 0) { //pick a random nexthop from SIT if possible and send a search packet const fib::NextHopList& nexthops = sitEntry->getNextHops(); // Ensure there is at least 1 Face is available for forwarding if (hasFaceForForwarding(nexthops, pitEntry)) { fib::NextHopList::const_iterator selected; do { boost::random::uniform_int_distribution<> dist(0, nexthops.size() - 1); const size_t randomIndex = dist(m_randomGenerator); uint64_t currentIndex = 0; for (selected = nexthops.begin(); selected != nexthops.end() && currentIndex != randomIndex; ++selected, ++currentIndex) { } } while (!canForwardToNextHop(pitEntry, *selected)); sdc--; pitEntry->setFloodFlag(sdc); sent = true; (*pitEntry).setDestinationFlag(); this->sendInterest(pitEntry, selected->getFace()); (*pitEntry).clearDestinationFlag(); } } if(!pitEntry->getDestinationFlag() && sdc > 0) { const fib::NextHopList& nexthops = fibEntry->getNextHops(); fib::NextHopList::const_iterator it = nexthops.end(); it = std::find_if(nexthops.begin(), nexthops.end(), bind(&predicate_NextHop_eligible, pitEntry, _1, inFace.getId(), false, time::steady_clock::TimePoint::min())); if (it == nexthops.end()) { NFD_LOG_DEBUG(interest << " from=" << inFace.getId() << " noNextHop"); NFD_LOG_INFO("Reject DF 0 (no eligible FIB next hop) interest=" << interest.getName()); } else { shared_ptr<Face> outFace = it->getFace(); sdc--; (*pitEntry).setFloodFlag(sdc); NFD_LOG_INFO("Forwarding DF 0 using FIB interest=" << interest.getName()); sent = true; this->sendInterest(pitEntry, outFace); NFD_LOG_DEBUG(interest << " from=" << inFace.getId() << " newPitEntry-to=" << outFace->getId()); } } //if sdc > 0 /*if (!sent) { this->rejectPendingInterest(pitEntry); }*/ }