rib: reimplement auto prefix propagation based on readvertise
Change-Id: I6c4d81b829cf78084d26121c81d977d0a86c9a0c
Refs: #3819
diff --git a/tests/rib/auto-prefix-propagator.t.cpp b/tests/rib/auto-prefix-propagator.t.cpp
deleted file mode 100644
index f33c7ae..0000000
--- a/tests/rib/auto-prefix-propagator.t.cpp
+++ /dev/null
@@ -1,684 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2014-2018, Regents of the University of California,
- * Arizona Board of Regents,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University,
- * Washington University in St. Louis,
- * Beijing Institute of Technology,
- * The University of Memphis.
- *
- * This file is part of NFD (Named Data Networking Forwarding Daemon).
- * See AUTHORS.md for complete list of NFD authors and contributors.
- *
- * NFD is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "rib/auto-prefix-propagator.hpp"
-
-#include "tests/identity-management-fixture.hpp"
-
-#include <ndn-cxx/security/pib/pib.hpp>
-#include <ndn-cxx/util/dummy-client-face.hpp>
-
-namespace nfd {
-namespace rib {
-namespace tests {
-
-using namespace nfd::tests;
-
-const Name TEST_LINK_LOCAL_NFD_PREFIX("/localhop/nfd");
-const time::milliseconds TEST_PREFIX_PROPAGATION_TIMEOUT(1000);
-
-class AutoPrefixPropagatorFixture : public IdentityManagementTimeFixture
-{
-public:
- AutoPrefixPropagatorFixture()
- : m_face(g_io, m_keyChain, {true, true})
- , m_scheduler(g_io)
- , m_controller(m_face, m_keyChain)
- , m_propagator(m_controller, m_keyChain, m_scheduler, m_rib)
- , m_requests(m_face.sentInterests)
- , m_entries(m_propagator.m_propagatedEntries)
- {
- m_propagator.enable();
- m_propagator.m_controlParameters
- .setCost(15)
- .setOrigin(ndn::nfd::ROUTE_ORIGIN_CLIENT)// set origin to client.
- .setFaceId(0);// the remote hub will take the input face as the faceId.
- m_propagator.m_commandOptions
- .setPrefix(TEST_LINK_LOCAL_NFD_PREFIX)
- .setTimeout(TEST_PREFIX_PROPAGATION_TIMEOUT);
- }
-
-public: // helpers for test
- bool
- insertEntryToRib(const Name& name, const uint64_t& faceId = 0)
- {
- if (m_rib.find(name) != m_rib.end()) {
- BOOST_TEST_MESSAGE("RIB entry already exists: " + name.toUri());
- return false;
- }
-
- Route route;
- route.faceId = faceId;
- m_rib.insert(name, route);
- advanceClocks(time::milliseconds(1));
-
- return m_rib.find(name) != m_rib.end(); // return whether afterInserEntry will be triggered
- }
-
- bool
- eraseEntryFromRib(const Name& name)
- {
- if (m_rib.find(name) == m_rib.end()) {
- BOOST_TEST_MESSAGE("RIB entry does not exist: " + name.toUri());
- return false;
- }
-
- std::vector<Route> routeList;
- std::copy(m_rib.find(name)->second->begin(), m_rib.find(name)->second->end(),
- std::back_inserter(routeList));
- for (auto&& route : routeList) {
- m_rib.erase(name, route);
- }
- advanceClocks(time::milliseconds(1));
-
- return m_rib.find(name) == m_rib.end(); // return whether afterEraseEntry will be triggered
- }
-
- void
- connectToHub()
- {
- insertEntryToRib("/localhop/nfd");
- }
-
- void
- disconnectFromHub()
- {
- eraseEntryFromRib("/localhop/nfd");
- }
-
-public: // helpers for check
- enum class CheckRequestResult {
- OK,
- OUT_OF_BOUNDARY,
- INVALID_N_COMPONENTS,
- WRONG_COMMAND_PREFIX,
- WRONG_VERB,
- INVALID_PARAMETERS,
- WRONG_REGISTERING_PREFIX
- };
-
- /**
- * @brief check a request at specified index
- *
- * @param idx the index of the specified request in m_requests
- * @param verb the expected verb of request
- * @param registeringPrefix the expected registering prefix of request
-
- * @retval OK the specified request has a valid name, the right verb, a valid ControlParameters
- * and the right registering prefix
- * @retval OUT_OF_BOUNDARY the specified index out of boundary
- * @retval INVALID_N_COMPONENTS the number of components of the request name is invalid
- * @retval WRONG_COMMAND_PREFIX the command prefix of the request is wrong
- * @retval WRONG_VERB the command verb of the request is wrong
- * @retval INVALID_PARAMETERS no valid parameters can be decoded from the request's name
- * @retval WRONG_REGISTERING_PREFIX the registering prefix of the request is wrong
- */
- CheckRequestResult
- checkRequest(size_t idx, const std::string& verb, const Name& registeringPrefix)
- {
- Name requestName;
- try {
- requestName = m_requests.at(idx).getName();
- }
- catch (const std::out_of_range&) {
- return CheckRequestResult::OUT_OF_BOUNDARY;
- }
-
- if (requestName.size() < 5) {
- return CheckRequestResult::INVALID_N_COMPONENTS;
- }
-
- if (requestName.getPrefix(2) != TEST_LINK_LOCAL_NFD_PREFIX) {
- return CheckRequestResult::WRONG_COMMAND_PREFIX;
- }
-
- if (requestName.get(3) != Name::Component(verb)) {
- return CheckRequestResult::WRONG_VERB;
- }
-
- ControlParameters parameters;
- try {
- parameters.wireDecode(requestName.get(4).blockFromValue());
- }
- catch (const tlv::Error&) {
- return CheckRequestResult::INVALID_PARAMETERS;
- }
-
- if (parameters.getName() != registeringPrefix) {
- return CheckRequestResult::WRONG_REGISTERING_PREFIX;
- }
-
- return CheckRequestResult::OK;
- }
-
-protected:
- ndn::util::DummyClientFace m_face;
- ndn::util::Scheduler m_scheduler;
- ndn::nfd::Controller m_controller;
- Rib m_rib;
- AutoPrefixPropagator m_propagator;
- std::vector<Interest>& m_requests; ///< store sent out requests
- AutoPrefixPropagator::PropagatedEntryList& m_entries; ///< store propagated entries
-};
-
-std::ostream&
-operator<<(std::ostream &os, const AutoPrefixPropagatorFixture::CheckRequestResult& result)
-{
- switch (result) {
- case AutoPrefixPropagatorFixture::CheckRequestResult::OK:
- os << "OK";
- break;
- case AutoPrefixPropagatorFixture::CheckRequestResult::OUT_OF_BOUNDARY:
- os << "OUT_OF_BOUNDARY";
- break;
- case AutoPrefixPropagatorFixture::CheckRequestResult::INVALID_N_COMPONENTS:
- os << "INVALID_N_COMPONENTS";
- break;
- case AutoPrefixPropagatorFixture::CheckRequestResult::WRONG_COMMAND_PREFIX:
- os << "WRONG_COMMAND_PREFIX";
- break;
- case AutoPrefixPropagatorFixture::CheckRequestResult::WRONG_VERB:
- os << "WRONG_VERB";
- break;
- case AutoPrefixPropagatorFixture::CheckRequestResult::INVALID_PARAMETERS:
- os << "INVALID_PARAMETERS";
- break;
- case AutoPrefixPropagatorFixture::CheckRequestResult::WRONG_REGISTERING_PREFIX:
- os << "WRONG_REGISTERING_PREFIX";
- break;
- default:
- break;
- }
-
- return os;
-}
-
-BOOST_FIXTURE_TEST_SUITE(TestAutoPrefixPropagator, AutoPrefixPropagatorFixture)
-
-BOOST_AUTO_TEST_CASE(EnableDisable)
-{
- connectToHub();
- BOOST_REQUIRE(addIdentity("/test/A"));
-
- auto testPropagateRevokeBasic = [this] () -> bool {
- m_propagator.m_propagatedEntries.clear();
-
- if (!insertEntryToRib("/test/A/app")) {
- return false;
- }
- m_entries["/test/A"].succeed(m_scheduler, nullptr);
- if (!eraseEntryFromRib("/test/A/app")) {
- return false;
- }
- return true;
- };
-
- m_propagator.disable();
- BOOST_REQUIRE(testPropagateRevokeBasic());
- BOOST_CHECK(m_requests.empty());
-
- m_propagator.enable();
- BOOST_REQUIRE(testPropagateRevokeBasic());
- BOOST_REQUIRE_EQUAL(m_requests.size(), 2);
- BOOST_CHECK_EQUAL(checkRequest(0, "register", "/test/A"), CheckRequestResult::OK);
- BOOST_CHECK_EQUAL(checkRequest(1, "unregister", "/test/A"), CheckRequestResult::OK);
-}
-
-BOOST_AUTO_TEST_CASE(LoadConfiguration)
-{
- ConfigFile config;
- config.addSectionHandler("auto_prefix_propagate",
- bind(&AutoPrefixPropagator::loadConfig, &m_propagator, _1));
-
- const std::string CONFIG_STRING =
- "auto_prefix_propagate\n"
- "{\n"
- " cost 11\n"
- " timeout 22\n"
- " refresh_interval 33\n"
- " base_retry_wait 44\n"
- " max_retry_wait 55\n"
- "}";
- config.parse(CONFIG_STRING, true, "test-auto-prefix-propagator");
-
- BOOST_CHECK_EQUAL(m_propagator.m_controlParameters.getCost(), 11);
- BOOST_CHECK_EQUAL(m_propagator.m_controlParameters.getOrigin(), ndn::nfd::ROUTE_ORIGIN_CLIENT);
- BOOST_CHECK_EQUAL(m_propagator.m_controlParameters.getFaceId(), 0);
-
- BOOST_CHECK_EQUAL(m_propagator.m_commandOptions.getPrefix(), TEST_LINK_LOCAL_NFD_PREFIX);
- BOOST_CHECK_EQUAL(m_propagator.m_commandOptions.getTimeout(), time::milliseconds(22));
-
- BOOST_CHECK_EQUAL(m_propagator.m_refreshInterval, time::seconds(33));
- BOOST_CHECK_EQUAL(m_propagator.m_baseRetryWait, time::seconds(44));
- BOOST_CHECK_EQUAL(m_propagator.m_maxRetryWait, time::seconds(55));
-}
-
-BOOST_AUTO_TEST_CASE(GetPrefixPropagationParameters)
-{
- BOOST_REQUIRE(addIdentity("/test/A"));
- BOOST_REQUIRE(addIdentity("/test/A/B"));
- BOOST_REQUIRE(addIdentity("/test/C/nrd"));
-
- auto parameters1 = m_propagator.getPrefixPropagationParameters("/none/A/B/app");
- auto parameters2 = m_propagator.getPrefixPropagationParameters("/test/A/B/app");
- auto parameters3 = m_propagator.getPrefixPropagationParameters("/test/C/D/app");
-
- BOOST_CHECK(!parameters1.isValid);
-
- BOOST_CHECK(parameters2.isValid);
- BOOST_CHECK_EQUAL(parameters2.parameters.getName(), "/test/A");
- BOOST_CHECK_EQUAL(parameters2.options.getSigningInfo().getSignerName(), "/test/A");
-
- BOOST_CHECK(parameters3.isValid);
- BOOST_CHECK_EQUAL(parameters3.parameters.getName(), "/test/C");
- BOOST_CHECK_EQUAL(parameters3.options.getSigningInfo().getSignerName(), "/test/C/nrd");
-}
-
-BOOST_AUTO_TEST_CASE(CheckCurrentPropagatedPrefix)
-{
- BOOST_REQUIRE(addIdentity("/test/A"));
- BOOST_REQUIRE(addIdentity("/test/B/nrd"));
- BOOST_REQUIRE(addIdentity("/test/A/B"));
-
- BOOST_CHECK(!m_propagator.doesCurrentPropagatedPrefixWork("/test/E")); // does not exist
- BOOST_CHECK(!m_propagator.doesCurrentPropagatedPrefixWork("/test/A/B")); // has a better option
- BOOST_CHECK(m_propagator.doesCurrentPropagatedPrefixWork("/test/A"));
- BOOST_CHECK(m_propagator.doesCurrentPropagatedPrefixWork("/test/B"));
-}
-
-BOOST_AUTO_TEST_CASE(RedoPropagation)
-{
- connectToHub();
- BOOST_REQUIRE(addIdentity("/test/A"));
- BOOST_REQUIRE(addIdentity("/test/B"));
- BOOST_REQUIRE(addIdentity("/test/B/C"));
- BOOST_REQUIRE(insertEntryToRib("/test/A/app"));
- BOOST_REQUIRE(insertEntryToRib("/test/B/C/app"));
- BOOST_REQUIRE(insertEntryToRib("/test/B/D/app"));
-
- auto testRedoPropagation = [this] (const Name& signingIdentity) {
- m_requests.clear();
-
- m_entries[signingIdentity].setSigningIdentity(signingIdentity);
-
- auto parameters = m_propagator.m_controlParameters;
- auto options = m_propagator.m_commandOptions;
- ndn::security::SigningInfo info(ndn::security::SigningInfo::SIGNER_TYPE_ID, signingIdentity);
- m_propagator.redoPropagation(m_entries.find(signingIdentity),
- parameters.setName(signingIdentity),
- options.setSigningInfo(info),
- time::seconds(0));
- advanceClocks(time::milliseconds(1));
- };
-
- testRedoPropagation("/test/A"); // current propagated prefix still works
- BOOST_REQUIRE_EQUAL(m_requests.size(), 1);
- BOOST_CHECK_EQUAL(checkRequest(0, "register", "/test/A"), CheckRequestResult::OK);
- BOOST_CHECK(m_entries.find("test/A") != m_entries.end());
-
- m_keyChain.deleteIdentity(m_keyChain.getPib().getIdentity("/test/B"));
- testRedoPropagation("/test/B"); // signingIdentity no longer exists
- BOOST_REQUIRE_EQUAL(m_requests.size(), 1);
- BOOST_CHECK_EQUAL(checkRequest(0, "register", "/test/B/C"), CheckRequestResult::OK);
- BOOST_CHECK(m_entries.find("/test/B") == m_entries.end());
- BOOST_CHECK(m_entries.find("/test/B/C") != m_entries.end());
-
- testRedoPropagation("/test/B"); // no alternative identity
- BOOST_CHECK(m_requests.empty());
- BOOST_CHECK(m_entries.find("/test/B") == m_entries.end());
-
- m_entries["/test/B/C"].succeed(m_scheduler, nullptr);
- testRedoPropagation("/test/B"); // alternative identity has been propagated
- BOOST_CHECK(m_requests.empty());
- BOOST_CHECK(m_entries.find("/test/B") == m_entries.end());
-
- BOOST_REQUIRE(addIdentity("/test/B/"));
- testRedoPropagation("/test/B/C"); // better option exists: /test/B
- BOOST_REQUIRE_EQUAL(m_requests.size(), 1);
- BOOST_CHECK_EQUAL(checkRequest(0, "register", "/test/B"), CheckRequestResult::OK);
- BOOST_CHECK(m_entries.find("test/B/C") == m_entries.end());
-}
-
-BOOST_AUTO_TEST_SUITE(PropagateRevokeSemantics)
-
-BOOST_AUTO_TEST_CASE(Basic)
-{
- connectToHub(); // ensure connectivity to the hub
- BOOST_REQUIRE(addIdentity("/test/A"));
-
- BOOST_REQUIRE(insertEntryToRib("/test/A/app")); // ensure afterInsertEntry signal emitted
- m_entries["/test/A"].succeed(m_scheduler, nullptr); // ensure there is a valid entry inserted
- BOOST_REQUIRE(eraseEntryFromRib("/test/A/app")); // ensure afterEraseEntry signal emitted
-
- BOOST_REQUIRE_EQUAL(m_requests.size(), 2);
- BOOST_CHECK_EQUAL(checkRequest(0, "register", "/test/A"), CheckRequestResult::OK);
- BOOST_CHECK_EQUAL(checkRequest(1, "unregister", "/test/A"), CheckRequestResult::OK);
-}
-
-BOOST_AUTO_TEST_CASE(LocalPrefix)
-{
- connectToHub();
- BOOST_REQUIRE(addIdentity("/localhost/A"));
-
- BOOST_REQUIRE(insertEntryToRib("/localhost/A/app"));
- BOOST_CHECK(m_requests.empty());
-
- m_propagator.m_propagatedEntries["/localhost/A"].succeed(m_scheduler, nullptr);
- BOOST_REQUIRE(eraseEntryFromRib("/localhost/A/app"));
- BOOST_CHECK(m_requests.empty());
-}
-
-BOOST_AUTO_TEST_CASE(InvalidPropagationParameters)
-{
- connectToHub();
-
- // no identity can be found
- BOOST_CHECK(!m_propagator.getPrefixPropagationParameters("/test/A/app").isValid);
-
- BOOST_REQUIRE(insertEntryToRib("/test/A/app"));
- BOOST_CHECK(m_requests.empty());
-
- m_entries["/test/A"].succeed(m_scheduler, nullptr);
- BOOST_REQUIRE(eraseEntryFromRib("/test/A/app"));
- BOOST_CHECK(m_requests.empty());
-}
-
-BOOST_AUTO_TEST_CASE(NoHubConnectivity)
-{
- BOOST_REQUIRE(addIdentity("/test/A"));
-
- BOOST_REQUIRE(insertEntryToRib("/test/A/app"));
- BOOST_CHECK(m_requests.empty());
-
- m_entries["/test/A"].succeed(m_scheduler, nullptr);
- BOOST_REQUIRE(eraseEntryFromRib("/test/A/app"));
- BOOST_CHECK(m_requests.empty());
-}
-
-BOOST_AUTO_TEST_CASE(ProcessSuspendedEntries)
-{
- BOOST_REQUIRE(addIdentity("/test/A"));
-
- BOOST_REQUIRE(insertEntryToRib("/test/A/app1"));
- BOOST_REQUIRE(insertEntryToRib("/test/A/app2"));
- BOOST_CHECK(m_requests.empty()); // no propagation because no hub is connected
- BOOST_CHECK_EQUAL(m_entries.size(), 1); // /test/A was suspended
-
- BOOST_REQUIRE(eraseEntryFromRib("/test/A/app2"));
- BOOST_CHECK_EQUAL(m_entries.size(), 1); // /test/A was kept for app1
-
- // repeat the scenario that leads to BUG 3362.
- // ensure there is no improper assertion.
- BOOST_REQUIRE(insertEntryToRib("/test/A/app2"));
-}
-
-BOOST_AUTO_TEST_CASE(PropagatedEntryExists)
-{
- connectToHub();
- BOOST_REQUIRE(addIdentity("/test/A"));
- BOOST_REQUIRE(insertEntryToRib("/test/A/app1"));
-
- m_requests.clear();
- BOOST_REQUIRE(insertEntryToRib("/test/A/app2")); // /test/A has been propagated by /test/A/app1
- BOOST_CHECK(m_requests.empty());
-}
-
-BOOST_AUTO_TEST_CASE(PropagatedEntryShouldKeep)
-{
- connectToHub();
- BOOST_REQUIRE(addIdentity("/test/A"));
- BOOST_REQUIRE(insertEntryToRib("/test/A/app1"));
- BOOST_REQUIRE(insertEntryToRib("/test/A/app2"));
-
- m_requests.clear();
- BOOST_REQUIRE(eraseEntryFromRib("/test/A/app2")); // /test/A should be kept for /test/A/app1
- BOOST_CHECK(m_requests.empty());
-}
-
-BOOST_AUTO_TEST_CASE(BackOffRetryPolicy)
-{
- m_propagator.m_commandOptions.setTimeout(time::milliseconds(1));
- m_propagator.m_baseRetryWait = time::seconds(1);
- m_propagator.m_maxRetryWait = time::seconds(2);
-
- connectToHub();
- BOOST_REQUIRE(addIdentity("/test/A"));
- BOOST_REQUIRE(insertEntryToRib("/test/A/app"));
-
- BOOST_REQUIRE_EQUAL(m_requests.size(), 1);
- BOOST_CHECK_EQUAL(checkRequest(0, "register", "/test/A"), CheckRequestResult::OK);
-
- advanceClocks(time::milliseconds(10), time::milliseconds(1050)); // wait for the 1st retry
- BOOST_REQUIRE_EQUAL(m_requests.size(), 2);
- BOOST_CHECK_EQUAL(checkRequest(1, "register", "/test/A"), CheckRequestResult::OK);
-
- advanceClocks(time::milliseconds(10), time::milliseconds(2050)); // wait for the 2nd retry, 2 times
- BOOST_REQUIRE_EQUAL(m_requests.size(), 3);
- BOOST_CHECK_EQUAL(checkRequest(2, "register", "/test/A"), CheckRequestResult::OK);
-
- advanceClocks(time::milliseconds(10), time::milliseconds(2050)); // wait for the 3rd retry, reach the upper bound
- BOOST_REQUIRE_EQUAL(m_requests.size(), 4);
- BOOST_CHECK_EQUAL(checkRequest(3, "register", "/test/A"), CheckRequestResult::OK);
-}
-
-BOOST_AUTO_TEST_SUITE_END() // PropagateRevokeSemantics
-
-BOOST_AUTO_TEST_SUITE(PropagatedEntryStateChanges)
-
-BOOST_AUTO_TEST_CASE(AfterRibInsert)
-{
- BOOST_REQUIRE(addIdentity("/test/A"));
-
- auto testAfterRibInsert = [this] (const Name& ribEntryPrefix) {
- m_requests.clear();
- m_propagator.m_propagatedEntries.clear(); // ensure entry does not exist
-
- auto propagateParameters = m_propagator.getPrefixPropagationParameters(ribEntryPrefix);
- m_propagator.afterRibInsert(propagateParameters.parameters, propagateParameters.options);
- advanceClocks(time::milliseconds(1));
- };
-
- testAfterRibInsert("/test/A/app1");
- BOOST_CHECK(m_requests.empty()); // no connectivity now
- BOOST_CHECK(m_entries.find("/test/A") != m_entries.end());
-
- connectToHub();
- testAfterRibInsert("/test/A/app2");
- BOOST_REQUIRE_EQUAL(m_requests.size(), 1);
- BOOST_CHECK_EQUAL(checkRequest(0, "register", "/test/A"), CheckRequestResult::OK);
- BOOST_CHECK(m_entries.find("/test/A") != m_entries.end());
-}
-
-BOOST_AUTO_TEST_CASE(AfterRibErase)
-{
- BOOST_REQUIRE(addIdentity("/test/A"));
-
- auto testAfterRibInsert = [this] (const Name& localUnregPrefix) {
- m_requests.clear();
-
- auto propagateParameters = m_propagator.getPrefixPropagationParameters(localUnregPrefix);
- m_propagator.afterRibErase(propagateParameters.parameters.unsetCost(),
- propagateParameters.options);
- advanceClocks(time::milliseconds(1));
- };
-
- m_entries["/test/A"].succeed(m_scheduler, nullptr);
- testAfterRibInsert("/test/A/app");
- BOOST_CHECK(m_requests.empty()); // no connectivity
- BOOST_CHECK(m_entries.find("/test/A") == m_entries.end()); // has been erased
-
- connectToHub();
- m_entries["/test/A"].fail(m_scheduler, nullptr);
- testAfterRibInsert("/test/A/app");
- BOOST_CHECK(m_requests.empty()); // previous propagation has not succeeded
- BOOST_CHECK(m_entries.find("/test/A") == m_entries.end()); // has been erased
-
- m_entries["/test/A"].succeed(m_scheduler, nullptr);
- testAfterRibInsert("/test/A/app");
- BOOST_REQUIRE_EQUAL(m_requests.size(), 1);
- BOOST_CHECK_EQUAL(checkRequest(0, "unregister", "/test/A"), CheckRequestResult::OK);
- BOOST_CHECK(m_entries.find("/test/A") == m_entries.end()); // has been erased
-}
-
-BOOST_AUTO_TEST_CASE(AfterHubConnectDisconnect)
-{
- BOOST_REQUIRE(addIdentity("/test/A"));
- BOOST_REQUIRE(addIdentity("/test/B"));
- BOOST_REQUIRE(addIdentity("/test/C"));
- BOOST_REQUIRE(insertEntryToRib("/test/A/app"));
- BOOST_REQUIRE(insertEntryToRib("/test/B/app"));
-
- // recorder the prefixes that will be propagated in order
- std::vector<Name> propagatedPrefixes;
-
- BOOST_CHECK(m_requests.empty()); // no request because there is no connectivity to the hub now
- BOOST_REQUIRE_EQUAL(m_entries.size(), 2); // valid entries will be kept
-
- connectToHub(); // 2 cached entries will be processed
- for (auto&& entry : m_entries) {
- propagatedPrefixes.push_back(entry.first);
- }
-
- BOOST_REQUIRE(insertEntryToRib("/test/C/app")); // will be processed directly
- propagatedPrefixes.push_back("/test/C");
- BOOST_REQUIRE_EQUAL(m_entries.size(), 3);
-
- BOOST_REQUIRE(m_entries["/test/A"].isPropagating());
- BOOST_REQUIRE(m_entries["/test/B"].isPropagating());
- BOOST_REQUIRE(m_entries["/test/C"].isPropagating());
-
- disconnectFromHub(); // all 3 entries are initialized
- BOOST_CHECK(m_entries["/test/A"].isNew());
- BOOST_CHECK(m_entries["/test/B"].isNew());
- BOOST_CHECK(m_entries["/test/C"].isNew());
-
- connectToHub(); // all 3 entries will be processed
- for (auto&& entry : m_entries) {
- propagatedPrefixes.push_back(entry.first);
- }
-
- BOOST_REQUIRE_EQUAL(m_requests.size(), 6);
- BOOST_REQUIRE_EQUAL(propagatedPrefixes.size(), 6);
- BOOST_CHECK_EQUAL(checkRequest(0, "register", propagatedPrefixes[0]), CheckRequestResult::OK);
- BOOST_CHECK_EQUAL(checkRequest(1, "register", propagatedPrefixes[1]), CheckRequestResult::OK);
- BOOST_CHECK_EQUAL(checkRequest(2, "register", propagatedPrefixes[2]), CheckRequestResult::OK);
- BOOST_CHECK_EQUAL(checkRequest(3, "register", propagatedPrefixes[3]), CheckRequestResult::OK);
- BOOST_CHECK_EQUAL(checkRequest(4, "register", propagatedPrefixes[4]), CheckRequestResult::OK);
- BOOST_CHECK_EQUAL(checkRequest(5, "register", propagatedPrefixes[5]), CheckRequestResult::OK);
-}
-
-BOOST_AUTO_TEST_CASE(AfterPropagateSucceed)
-{
- bool wasRefreshEventTriggered = false;
- auto testAfterPropagateSucceed = [&] (const Name& ribEntryPrefix) {
- m_requests.clear();
- wasRefreshEventTriggered = false;
-
- auto propagateParameters = m_propagator.getPrefixPropagationParameters(ribEntryPrefix);
- m_propagator.afterPropagateSucceed(propagateParameters.parameters, propagateParameters.options,
- [&]{ wasRefreshEventTriggered = true; });
- advanceClocks(time::milliseconds(1));
- };
-
- BOOST_REQUIRE(addIdentity("/test/A"));
- m_propagator.m_refreshInterval = time::seconds(0); // event will be executed at once
- m_entries["/test/A"].startPropagation(); // set to be in PROPAGATING state
-
- testAfterPropagateSucceed("/test/A/app"); // will trigger refresh event
- BOOST_CHECK(wasRefreshEventTriggered);
- BOOST_CHECK(m_requests.empty());
-
- m_entries.erase(m_entries.find("/test/A")); // set to be in RELEASED state
- testAfterPropagateSucceed("/test/A/app"); // will call startRevocation
- BOOST_CHECK(!wasRefreshEventTriggered);
- BOOST_REQUIRE_EQUAL(m_requests.size(), 1);
- BOOST_CHECK_EQUAL(checkRequest(0, "unregister", "/test/A"), CheckRequestResult::OK);
-}
-
-BOOST_AUTO_TEST_CASE(AfterPropagateFail)
-{
- bool wasRetryEventTriggered = false;
- auto testAfterPropagateFail = [&] (const Name& ribEntryPrefix) {
- m_requests.clear();
- wasRetryEventTriggered = false;
-
- auto propagateParameters = m_propagator.getPrefixPropagationParameters(ribEntryPrefix);
- m_propagator.afterPropagateFail(ndn::nfd::ControlResponse(400, "test"),
- propagateParameters.parameters, propagateParameters.options,
- time::seconds(0), [&] { wasRetryEventTriggered = true; });
- advanceClocks(time::milliseconds(1));
- };
-
- BOOST_REQUIRE(addIdentity("/test/A"));
- m_entries["/test/A"].startPropagation(); // set to be in PROPAGATING state
-
- testAfterPropagateFail("/test/A/app"); // will trigger retry event
- BOOST_CHECK(wasRetryEventTriggered);
- BOOST_CHECK(m_requests.empty());
-
- m_entries.erase(m_entries.find("/test/A")); // set to be in RELEASED state
- testAfterPropagateFail("/test/A/app"); // will do nothing
- BOOST_CHECK(!wasRetryEventTriggered);
- BOOST_CHECK(m_requests.empty());
-}
-
-BOOST_AUTO_TEST_CASE(AfterRevokeSucceed)
-{
- auto testAfterRevokeSucceed = [&] (const Name& ribEntryPrefix) {
- m_requests.clear();
- auto propagateParameters = m_propagator.getPrefixPropagationParameters(ribEntryPrefix);
- m_propagator.afterRevokeSucceed(propagateParameters.parameters,
- propagateParameters.options,
- time::seconds(0));
- advanceClocks(time::milliseconds(1));
- };
-
- BOOST_REQUIRE(addIdentity("/test/A"));
-
- testAfterRevokeSucceed("/test/A/app"); // in RELEASED state
- BOOST_CHECK(m_requests.empty());
-
- m_entries["/test/A"].fail(m_scheduler, nullptr); // in PROPAGATE_FAIL state
- testAfterRevokeSucceed("/test/A/app");
- BOOST_CHECK(m_requests.empty());
-
- m_entries["/test/A"].succeed(m_scheduler, nullptr); // in PROPAGATED state
- testAfterRevokeSucceed("/test/A/app");
- BOOST_REQUIRE_EQUAL(m_requests.size(), 1);
- BOOST_CHECK_EQUAL(checkRequest(0, "register", "/test/A"), CheckRequestResult::OK);
-
- m_entries["/test/A"].startPropagation(); // in PROPAGATING state
- testAfterRevokeSucceed("/test/A/app");
- BOOST_REQUIRE_EQUAL(m_requests.size(), 1);
- BOOST_CHECK_EQUAL(checkRequest(0, "register", "/test/A"), CheckRequestResult::OK);
-}
-
-BOOST_AUTO_TEST_SUITE_END() // PropagatedEntryStateChanges
-
-BOOST_AUTO_TEST_SUITE_END() // TestAutoPrefixPropagator
-
-} // namespace tests
-} // namespace rib
-} // namespace nfd
diff --git a/tests/rib/propagated-entry.t.cpp b/tests/rib/propagated-entry.t.cpp
deleted file mode 100644
index b03f153..0000000
--- a/tests/rib/propagated-entry.t.cpp
+++ /dev/null
@@ -1,88 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2014-2018, Regents of the University of California,
- * Arizona Board of Regents,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University,
- * Washington University in St. Louis,
- * Beijing Institute of Technology,
- * The University of Memphis.
- *
- * This file is part of NFD (Named Data Networking Forwarding Daemon).
- * See AUTHORS.md for complete list of NFD authors and contributors.
- *
- * NFD is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "rib/propagated-entry.hpp"
-
-#include "tests/test-common.hpp"
-
-namespace nfd {
-namespace rib {
-namespace tests {
-
-BOOST_FIXTURE_TEST_SUITE(TestPropagatedEntry, nfd::tests::BaseFixture)
-
-BOOST_AUTO_TEST_CASE(Identity)
-{
- PropagatedEntry entry;
- BOOST_CHECK(entry.m_signingIdentity.empty());
-
- entry.setSigningIdentity("/test");
- BOOST_CHECK_EQUAL(entry.m_signingIdentity, "/test");
- BOOST_CHECK_EQUAL(entry.getSigningIdentity(), "/test");
-}
-
-BOOST_AUTO_TEST_CASE(Start)
-{
- PropagatedEntry entry;
- BOOST_CHECK(!entry.isPropagating());
-
- entry.startPropagation();
- BOOST_CHECK_EQUAL(PropagationStatus::PROPAGATING, entry.m_propagationStatus);
- BOOST_CHECK(entry.isPropagating());
-}
-
-BOOST_AUTO_TEST_CASE(Succeed)
-{
- ndn::util::Scheduler scheduler(g_io);
- PropagatedEntry entry;
- entry.succeed(scheduler, nullptr);
- BOOST_CHECK_EQUAL(PropagationStatus::PROPAGATED, entry.m_propagationStatus);
- BOOST_CHECK(entry.isPropagated());
-}
-
-BOOST_AUTO_TEST_CASE(Fail)
-{
- ndn::util::Scheduler scheduler(g_io);
- PropagatedEntry entry;
- entry.fail(scheduler, nullptr);
- BOOST_CHECK_EQUAL(PropagationStatus::PROPAGATE_FAIL, entry.m_propagationStatus);
- BOOST_CHECK(entry.isPropagateFail());
-}
-
-BOOST_AUTO_TEST_CASE(Initialize)
-{
- PropagatedEntry entry;
- entry.startPropagation();
- BOOST_CHECK_EQUAL(PropagationStatus::PROPAGATING, entry.m_propagationStatus);
-
- entry.initialize();
- BOOST_CHECK_EQUAL(PropagationStatus::NEW, entry.m_propagationStatus);
-}
-
-BOOST_AUTO_TEST_SUITE_END() // TestPropagatedEntry
-
-} // namespace tests
-} // namespace rib
-} // namespace nfd
diff --git a/tests/rib/readvertise/host-to-gateway-readvertise-policy.t.cpp b/tests/rib/readvertise/host-to-gateway-readvertise-policy.t.cpp
new file mode 100644
index 0000000..1b357cb
--- /dev/null
+++ b/tests/rib/readvertise/host-to-gateway-readvertise-policy.t.cpp
@@ -0,0 +1,114 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2014-2018, Regents of the University of California,
+ * Arizona Board of Regents,
+ * Colorado State University,
+ * University Pierre & Marie Curie, Sorbonne University,
+ * Washington University in St. Louis,
+ * Beijing Institute of Technology,
+ * The University of Memphis.
+ *
+ * This file is part of NFD (Named Data Networking Forwarding Daemon).
+ * See AUTHORS.md for complete list of NFD authors and contributors.
+ *
+ * NFD is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "rib/readvertise/host-to-gateway-readvertise-policy.hpp"
+
+#include "tests/identity-management-fixture.hpp"
+
+#include <ndn-cxx/security/signing-helpers.hpp>
+
+namespace nfd {
+namespace rib {
+namespace tests {
+
+using namespace nfd::tests;
+
+class HostToGatewayReadvertisePolicyFixture : public IdentityManagementFixture
+{
+public:
+ RibRouteRef
+ makeNewRoute(const Name& prefix) {
+ auto entry = make_shared<RibEntry>();
+ entry->setName(prefix);
+
+ Route route;
+ auto routeIt = entry->insertRoute(route).first;
+ return RibRouteRef{entry, routeIt};
+ }
+
+ shared_ptr<HostToGatewayReadvertisePolicy>
+ makePolicy(const ConfigSection& section = ConfigSection())
+ {
+ return make_shared<HostToGatewayReadvertisePolicy>(m_keyChain, section);
+ }
+};
+
+BOOST_AUTO_TEST_SUITE(Readvertise)
+BOOST_FIXTURE_TEST_SUITE(TestHostToGatewayReadvertisePolicy,
+ HostToGatewayReadvertisePolicyFixture)
+
+BOOST_AUTO_TEST_CASE(PrefixToAdvertise)
+{
+ BOOST_REQUIRE(addIdentity("/A"));
+ BOOST_REQUIRE(addIdentity("/A/B"));
+ BOOST_REQUIRE(addIdentity("/C/nrd"));
+
+ auto test = [this] (Name routeName, optional<ReadvertiseAction> expectedAction) {
+ auto policy = makePolicy();
+ auto action = policy->handleNewRoute(makeNewRoute(routeName));
+
+ if (expectedAction) {
+ BOOST_REQUIRE(action);
+ BOOST_CHECK_EQUAL(action->prefix, expectedAction->prefix);
+ BOOST_REQUIRE_EQUAL(action->signer, expectedAction->signer);
+ }
+ else {
+ BOOST_REQUIRE(!action);
+ }
+ };
+
+ test("/D/app", nullopt);
+ test("/A/B/app", ReadvertiseAction{"/A", ndn::security::signingByIdentity("/A")});
+ test("/C/nrd", ReadvertiseAction{"/C", ndn::security::signingByIdentity("/C/nrd")});
+}
+
+BOOST_AUTO_TEST_CASE(DontReadvertise)
+{
+ auto policy = makePolicy();
+ BOOST_REQUIRE(!policy->handleNewRoute(makeNewRoute("/localhost/test")));
+ BOOST_REQUIRE(!policy->handleNewRoute(makeNewRoute("/localhop/nfd")));
+}
+
+BOOST_AUTO_TEST_CASE(LoadRefreshInterval)
+{
+ auto policy = makePolicy();
+ BOOST_CHECK_EQUAL(policy->getRefreshInterval(), time::seconds(25)); // default setting is 25
+
+ ConfigSection section;
+ section.put("refresh_interval_wrong", 10);
+ policy = makePolicy(section);
+ BOOST_CHECK_EQUAL(policy->getRefreshInterval(), time::seconds(25)); // wrong formate
+
+ section.put("refresh_interval", 10);
+ policy = makePolicy(section);
+ BOOST_CHECK_EQUAL(policy->getRefreshInterval(), time::seconds(10));
+}
+
+BOOST_AUTO_TEST_SUITE_END() // TestHostToGatewayReadvertisePolicy
+BOOST_AUTO_TEST_SUITE_END() // Readvertise
+
+} // namespace tests
+} // namespace rib
+} // namespace nfd
diff --git a/tests/rib/readvertise/nfd-rib-readvertise-destination.t.cpp b/tests/rib/readvertise/nfd-rib-readvertise-destination.t.cpp
index 483f94a..48164bd 100644
--- a/tests/rib/readvertise/nfd-rib-readvertise-destination.t.cpp
+++ b/tests/rib/readvertise/nfd-rib-readvertise-destination.t.cpp
@@ -46,9 +46,9 @@
, face(g_io, m_keyChain, {true, false})
, scheduler(g_io)
, controller(face, m_keyChain)
- , dest(controller, Name("/localhost/nlsr"), rib)
+ , dest(controller, rib, ndn::nfd::CommandOptions().setPrefix("/localhost/nlsr"))
, successCallback([this] { nSuccessCallbacks++; })
- , failureCallback([this] (const std::string&) { nFailureCallbacks++; })
+ , failureCallback([this] (const std::string& str) { nFailureCallbacks++; })
{
}