diff --git a/rib/rib-manager.cpp b/rib/rib-manager.cpp index c0c6ce87..4408b039 100644 --- a/rib/rib-manager.cpp +++ b/rib/rib-manager.cpp @@ -318,41 +318,16 @@ RibManager::fetchActiveFaces() { NFD_LOG_DEBUG("Fetching active faces"); - Interest interest(FACES_LIST_DATASET_PREFIX); - interest.setChildSelector(1); - interest.setMustBeFresh(true); - - shared_ptr buffer = make_shared(); - - m_face.expressInterest(interest, - bind(&RibManager::fetchSegments, this, _2, buffer), - bind(&RibManager::onFetchFaceStatusTimeout, this)); + m_nfdController.fetch( + bind(&RibManager::removeInvalidFaces, this, _1), + bind(&RibManager::onFetchActiveFacesFailure, this, _1, _2), + ndn::nfd::CommandOptions()); } void -RibManager::fetchSegments(const Data& data, shared_ptr buffer) +RibManager::onFetchActiveFacesFailure(uint32_t code, const std::string& reason) { - buffer->write(reinterpret_cast(data.getContent().value()), - data.getContent().value_size()); - - uint64_t currentSegment = data.getName().get(-1).toSegment(); - - const name::Component& finalBlockId = data.getMetaInfo().getFinalBlockId(); - - if (finalBlockId.empty() || finalBlockId.toSegment() > currentSegment) { - m_face.expressInterest(data.getName().getPrefix(-1).appendSegment(currentSegment+1), - bind(&RibManager::fetchSegments, this, _2, buffer), - bind(&RibManager::onFetchFaceStatusTimeout, this)); - } - else { - removeInvalidFaces(buffer); - } -} - -void -RibManager::onFetchFaceStatusTimeout() -{ - std::cerr << "Face Status Dataset request timed out" << std::endl; + NFD_LOG_DEBUG("Face Status Dataset request failure " << code << " " << reason); scheduleActiveFaceFetch(ACTIVE_FACE_FETCH_INTERVAL); } @@ -373,34 +348,19 @@ RibManager::scheduleActiveFaceFetch(const time::seconds& timeToWait) } void -RibManager::removeInvalidFaces(shared_ptr buffer) +RibManager::removeInvalidFaces(const std::vector& activeFaces) { NFD_LOG_DEBUG("Checking for invalid face registrations"); - ndn::ConstBufferPtr buf = buffer->buf(); - - Block block; - size_t offset = 0; - FaceIdSet activeFaces; - - while (offset < buf->size()) { - bool isOk = false; - std::tie(isOk, block) = Block::fromBuffer(buf, offset); - if (!isOk) { - std::cerr << "ERROR: cannot decode FaceStatus TLV" << std::endl; - break; - } - - offset += block.size(); - - ndn::nfd::FaceStatus status(block); - activeFaces.insert(status.getFaceId()); + FaceIdSet activeFaceIds; + for (const ndn::nfd::FaceStatus& item : activeFaces) { + activeFaceIds.insert(item.getFaceId()); } // Look for face IDs that were registered but not active to find missed // face destroyed events for (auto&& faceId : m_registeredFaces) { - if (activeFaces.find(faceId) == activeFaces.end()) { + if (activeFaceIds.count(faceId) == 0) { NFD_LOG_DEBUG("Removing invalid face ID: " << faceId); scheduler::schedule(time::seconds(0), diff --git a/rib/rib-manager.hpp b/rib/rib-manager.hpp index 686ecd7d..99f5ccdf 100644 --- a/rib/rib-manager.hpp +++ b/rib/rib-manager.hpp @@ -115,10 +115,7 @@ private: // Face monitor fetchActiveFaces(); void - fetchSegments(const Data& data, shared_ptr buffer); - - void - onFetchFaceStatusTimeout(); + onFetchActiveFacesFailure(uint32_t code, const std::string& reason); void onFaceDestroyedEvent(uint64_t faceId); @@ -130,10 +127,10 @@ PUBLIC_WITH_TESTS_ELSE_PRIVATE: /** * @brief remove invalid faces * - * @param buffer Face dataset contents + * @param status Face dataset */ void - removeInvalidFaces(shared_ptr buffer); + removeInvalidFaces(const std::vector& activeFaces); /** * @brief response to face events diff --git a/tests/rib/rib-manager.t.cpp b/tests/rib/rib-manager.t.cpp index f3df261d..450016d5 100644 --- a/tests/rib/rib-manager.t.cpp +++ b/tests/rib/rib-manager.t.cpp @@ -570,15 +570,10 @@ BOOST_AUTO_TEST_CASE(RemoveInvalidFaces) ndn::nfd::FaceStatus status; status.setFaceId(1); + std::vector activeFaces; + activeFaces.push_back(status); - auto data = makeData("/localhost/nfd/faces/list"); - data->setContent(status.wireEncode()); - - auto buffer = make_shared(); - buffer->write(reinterpret_cast(data->getContent().value()), - data->getContent().value_size()); - - m_manager.removeInvalidFaces(buffer); + m_manager.removeInvalidFaces(activeFaces); advanceClocks(time::milliseconds(100)); BOOST_REQUIRE_EQUAL(m_rib.size(), 1);