rib: redesign of remote prefix registration
Change-Id: I8418de6d5bb9615af898df5dbf9ed4cc2cb6a43a
Refs: #3211, #2413
diff --git a/tests/rib/auto-prefix-propagator.t.cpp b/tests/rib/auto-prefix-propagator.t.cpp
new file mode 100644
index 0000000..67e7b1b
--- /dev/null
+++ b/tests/rib/auto-prefix-propagator.t.cpp
@@ -0,0 +1,671 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2015, 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/test-common.hpp"
+#include "tests/identity-management-fixture.hpp"
+#include <ndn-cxx/util/dummy-client-face.hpp>
+
+namespace nfd {
+namespace rib {
+namespace tests {
+
+NFD_LOG_INIT("AutoPrefixPropagatorTest");
+
+const Name TEST_LINK_LOCAL_NFD_PREFIX("/localhop/nfd");
+const time::milliseconds TEST_PREFIX_PROPAGATION_TIMEOUT(1000);
+
+class AutoPrefixPropagatorFixture : public nfd::tests::IdentityManagementFixture
+ , public nfd::tests::UnitTestTimeFixture
+{
+public:
+ AutoPrefixPropagatorFixture()
+ : m_face(ndn::util::makeDummyClientFace(nfd::tests::UnitTestTimeFixture::g_io, {true, true}))
+ , m_controller(*m_face, m_keyChain)
+ , m_propagator(m_controller, m_keyChain, 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()) {
+ NFD_LOG_INFO("RIB entry already exists: " << name);
+ 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()) {
+ NFD_LOG_INFO("RIB entry does not exist: " << name);
+ 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:
+ shared_ptr<ndn::util::DummyClientFace> m_face;
+ 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_AUTO_TEST_SUITE(Rib)
+
+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(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_SUITE(Helpers)
+
+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());
+
+ BOOST_CHECK_NO_THROW(m_keyChain.deleteIdentity("/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(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_END() // Helpers
+
+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(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(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(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(nullptr);
+ BOOST_REQUIRE(eraseEntryFromRib("/test/A/app"));
+ BOOST_CHECK(m_requests.empty());
+}
+
+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(1), 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(1), 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(1), 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(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(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(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(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(nullptr); // in PROPAGATE_FAIL state
+ testAfterRevokeSucceed("/test/A/app");
+ BOOST_CHECK(m_requests.empty());
+
+ m_entries["/test/A"].succeed(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
+BOOST_AUTO_TEST_SUITE_END() // Rib
+
+} // namespace tests
+} // namespace rib
+} // namespace nfd
diff --git a/tests/rib/propagated-entry.t.cpp b/tests/rib/propagated-entry.t.cpp
new file mode 100644
index 0000000..8c8b1d2
--- /dev/null
+++ b/tests/rib/propagated-entry.t.cpp
@@ -0,0 +1,88 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2015, 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_AUTO_TEST_SUITE(Rib)
+
+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)
+{
+ PropagatedEntry entry;
+ entry.succeed(nullptr);
+ BOOST_CHECK_EQUAL(PropagationStatus::PROPAGATED, entry.m_propagationStatus);
+ BOOST_CHECK(entry.isPropagated());
+}
+
+BOOST_AUTO_TEST_CASE(Fail)
+{
+ PropagatedEntry entry;
+ entry.fail(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
+BOOST_AUTO_TEST_SUITE_END() // Rib
+
+} // namespace tests
+} // namespace rib
+} // namespace nfd
diff --git a/tests/rib/remote-registrator.t.cpp b/tests/rib/remote-registrator.t.cpp
deleted file mode 100644
index dc41cda..0000000
--- a/tests/rib/remote-registrator.t.cpp
+++ /dev/null
@@ -1,520 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2015, 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/remote-registrator.hpp"
-
-#include "tests/limited-io.hpp"
-#include "tests/identity-management-fixture.hpp"
-#include <ndn-cxx/util/dummy-client-face.hpp>
-
-namespace nfd {
-namespace rib {
-namespace tests {
-
-class RemoteRegistratorFixture : public nfd::tests::IdentityManagementFixture
- , public nfd::tests::UnitTestTimeFixture
-{
-public:
- RemoteRegistratorFixture()
- : face(ndn::util::makeDummyClientFace(getGlobalIoService()))
- , controller(make_shared<ndn::nfd::Controller>(std::ref(*face), m_keyChain))
- , remoteRegistrator(make_shared<RemoteRegistrator>(std::ref(*controller),
- m_keyChain,
- rib))
- , COMMAND_PREFIX("/localhop/nfd/rib")
- , REGISTER_VERB("register")
- , UNREGISTER_VERB("unregister")
- {
- readConfig();
-
- remoteRegistrator->enable();
-
- advanceClocks(time::milliseconds(1));
- face->sentInterests.clear();
- }
-
- void
- readConfig(bool isSetRetry = false)
- {
- ConfigFile config;
- config.addSectionHandler("remote_register",
- bind(&RemoteRegistrator::loadConfig, remoteRegistrator, _1));
-
-
- if (isSetRetry) {
- const std::string CONFIG_STRING =
- "remote_register\n"
- "{\n"
- " cost 15\n"
- " timeout 1000\n"
- " retry 1\n"
- " refresh_interval 5\n"
- "}";
-
- config.parse(CONFIG_STRING, true, "test-remote-register");
- }
- else {
- const std::string CONFIG_STRING =
- "remote_register\n"
- "{\n"
- " cost 15\n"
- " timeout 100000\n"
- " retry 0\n"
- " refresh_interval 5\n"
- "}";
-
- config.parse(CONFIG_STRING, true, "test-remote-register");
- }
- }
-
- void
- waitForTimeout()
- {
- advanceClocks(time::milliseconds(100), time::seconds(1));
- }
-
- void
- insertEntryWithIdentity(Name identity,
- name::Component appName = DEFAULT_APP_NAME,
- uint64_t faceId = 0)
- {
- BOOST_CHECK_EQUAL(addIdentity(identity), true);
-
- Route route;
- route.faceId = faceId;
-
- rib.insert(identity.append(appName), route);
-
- advanceClocks(time::milliseconds(1));
- }
-
- void
- insertEntryWithoutIdentity(Name identity,
- name::Component appName = DEFAULT_APP_NAME,
- uint64_t faceId = 0)
- {
- Route route;
- route.faceId = faceId;
-
- rib.insert(identity.append(appName), route);
-
- advanceClocks(time::milliseconds(1));
- }
-
- void
- eraseEntryWithIdentity(Name identity,
- name::Component appName = DEFAULT_APP_NAME,
- uint64_t faceId = 0)
- {
- BOOST_CHECK_EQUAL(addIdentity(identity), true);
-
- Route route;
- route.faceId = faceId;
-
- rib.erase(identity.append(appName), route);
-
- advanceClocks(time::milliseconds(1));
- }
-
- void
- eraseEntryWithoutIdentity(Name identity,
- name::Component appName = DEFAULT_APP_NAME,
- uint64_t faceId = 0)
- {
- Route route;
- route.faceId = faceId;
-
- rib.erase(identity.append(appName), route);
-
- advanceClocks(time::milliseconds(1));
- }
-
- void
- eraseFace(uint64_t faceId)
- {
- for (const Rib::NameAndRoute& item : rib.findRoutesWithFaceId(faceId)) {
- rib.erase(item.first, item.second);
- }
-
- advanceClocks(time::milliseconds(1));
- }
-
- void
- connectToHub()
- {
- rib.insert(Name("/localhop/nfd"), Route());
-
- advanceClocks(time::milliseconds(1));
- }
-
- void
- disconnectToHub()
- {
- rib.erase(Name("/localhop/nfd"), Route());
-
- advanceClocks(time::milliseconds(1));
- }
-
- void
- extractParameters(Interest& interest, Name::Component& verb,
- ndn::nfd::ControlParameters& extractedParameters)
- {
- const Name& name = interest.getName();
- verb = name[COMMAND_PREFIX.size()];
- const Name::Component& parameterComponent = name[COMMAND_PREFIX.size() + 1];
-
- Block rawParameters = parameterComponent.blockFromValue();
- extractedParameters.wireDecode(rawParameters);
- }
-
-public:
- Rib rib;
- shared_ptr<ndn::util::DummyClientFace> face;
- shared_ptr<ndn::nfd::Controller> controller;
- shared_ptr<RemoteRegistrator> remoteRegistrator;
-
- const Name COMMAND_PREFIX;
- const name::Component REGISTER_VERB;
- const name::Component UNREGISTER_VERB;
-
- static const name::Component DEFAULT_APP_NAME;
-};
-
-const name::Component RemoteRegistratorFixture::DEFAULT_APP_NAME("app");
-
-BOOST_FIXTURE_TEST_SUITE(TestRemoteRegistrator, RemoteRegistratorFixture)
-
-BOOST_FIXTURE_TEST_CASE(AutoTest, RemoteRegistratorFixture)
-{
- BOOST_REQUIRE_EQUAL(1, 1);
-}
-
-BOOST_FIXTURE_TEST_CASE(RegisterWithoutConnection, RemoteRegistratorFixture)
-{
- insertEntryWithIdentity("/remote/register");
-
- BOOST_REQUIRE_EQUAL(face->sentInterests.size(), 0);
-}
-
-BOOST_FIXTURE_TEST_CASE(RegisterWithoutIdentity, RemoteRegistratorFixture)
-{
- connectToHub();
-
- insertEntryWithoutIdentity("/remote/register");
-
- BOOST_REQUIRE_EQUAL(face->sentInterests.size(), 0);
-}
-
-BOOST_FIXTURE_TEST_CASE(RegisterWithHubPrefix, RemoteRegistratorFixture)
-{
- connectToHub();
-
- BOOST_REQUIRE_EQUAL(face->sentInterests.size(), 0);
-}
-
-BOOST_FIXTURE_TEST_CASE(RegisterWithLocalPrefix, RemoteRegistratorFixture)
-{
- connectToHub();
-
- insertEntryWithIdentity("/localhost/prefix");
-
- BOOST_REQUIRE_EQUAL(face->sentInterests.size(), 0);
-}
-
-BOOST_FIXTURE_TEST_CASE(RegisterBasic, RemoteRegistratorFixture)
-{
- connectToHub();
-
- Name identity("/remote/register");
- insertEntryWithIdentity(identity);
-
- BOOST_REQUIRE_EQUAL(face->sentInterests.size(), 1);
-
- Interest& request = face->sentInterests[0];
-
- ndn::nfd::ControlParameters extractedParameters;
- Name::Component verb;
- extractParameters(request, verb, extractedParameters);
-
- BOOST_CHECK_EQUAL(verb, REGISTER_VERB);
- BOOST_CHECK_EQUAL(extractedParameters.getName(), identity);
-}
-
-BOOST_FIXTURE_TEST_CASE(RegisterAdvanced, RemoteRegistratorFixture)
-{
- connectToHub();
-
- Name identity("/remote/register");
- Name identityAddRib("/remote/register/rib");
- insertEntryWithIdentity(identityAddRib);
-
- BOOST_REQUIRE_EQUAL(face->sentInterests.size(), 1);
-
- Interest& request = face->sentInterests[0];
-
- ndn::nfd::ControlParameters extractedParameters;
- Name::Component verb;
- extractParameters(request, verb, extractedParameters);
-
- BOOST_CHECK_EQUAL(verb, REGISTER_VERB);
- BOOST_CHECK_EQUAL(extractedParameters.getName(), identity);
-}
-
-BOOST_FIXTURE_TEST_CASE(RegisterWithRedundantCallback, RemoteRegistratorFixture)
-{
- remoteRegistrator->enable();
-
- connectToHub();
-
- Name identity("/remote/register");
- insertEntryWithIdentity(identity);
-
- BOOST_REQUIRE_EQUAL(face->sentInterests.size(), 1);
-
- Interest& request = face->sentInterests[0];
-
- ndn::nfd::ControlParameters extractedParameters;
- Name::Component verb;
- extractParameters(request, verb, extractedParameters);
-
- BOOST_CHECK_EQUAL(verb, REGISTER_VERB);
- BOOST_CHECK_EQUAL(extractedParameters.getName(), identity);
-}
-
-BOOST_FIXTURE_TEST_CASE(RegisterRetry, RemoteRegistratorFixture)
-{
- // setRetry
- readConfig(true);
-
- connectToHub();
-
- Name identity("/remote/register");
- insertEntryWithIdentity(identity);
-
- waitForTimeout();
-
- BOOST_REQUIRE_EQUAL(face->sentInterests.size(), 2);
-
- Interest& requestFirst = face->sentInterests[0];
- Interest& requestSecond = face->sentInterests[1];
-
- ndn::nfd::ControlParameters extractedParametersFirst, extractedParametersSecond;
- Name::Component verbFirst, verbSecond;
- extractParameters(requestFirst, verbFirst, extractedParametersFirst);
- extractParameters(requestSecond, verbSecond, extractedParametersSecond);
-
- BOOST_CHECK_EQUAL(verbFirst, REGISTER_VERB);
- BOOST_CHECK_EQUAL(verbSecond, REGISTER_VERB);
- BOOST_CHECK_EQUAL(extractedParametersFirst.getName(), identity);
- BOOST_CHECK_EQUAL(extractedParametersSecond.getName(), identity);
-}
-
-BOOST_FIXTURE_TEST_CASE(UnregisterWithoutInsert, RemoteRegistratorFixture)
-{
- connectToHub();
-
- eraseEntryWithIdentity("/remote/register");
-
- BOOST_REQUIRE_EQUAL(face->sentInterests.size(), 0);
-}
-
-BOOST_FIXTURE_TEST_CASE(UnregisterWithoutConnection, RemoteRegistratorFixture)
-{
- connectToHub();
-
- disconnectToHub();
-
- Name indentity("/remote/register");
- remoteRegistrator->m_regEntries.insert(
- nfd::rib::RemoteRegistrator::RegisteredEntry(indentity, scheduler::EventId()));
-
- eraseEntryWithIdentity(indentity);
-
- BOOST_REQUIRE_EQUAL(face->sentInterests.size(), 0);
-}
-
-BOOST_FIXTURE_TEST_CASE(UnregisterWithoutSuccessfullRegistration,
- RemoteRegistratorFixture)
-{
- connectToHub();
-
- Name identity("/remote/register");
-
- insertEntryWithIdentity(identity);
-
- eraseEntryWithIdentity(identity);
-
- BOOST_REQUIRE_EQUAL(face->sentInterests.size(), 1);
-
- Interest& request = face->sentInterests[0];
-
- ndn::nfd::ControlParameters extractedParameters;
- Name::Component verb;
- extractParameters(request, verb, extractedParameters);
-
- BOOST_CHECK_EQUAL(verb, REGISTER_VERB);
- BOOST_CHECK_EQUAL(extractedParameters.getName(), identity);
-}
-
-BOOST_FIXTURE_TEST_CASE(UnregisterBasic, RemoteRegistratorFixture)
-{
- connectToHub();
-
- Name identity("/remote/register");
-
- insertEntryWithIdentity(identity);
-
- scheduler::EventId event;
-
- remoteRegistrator->m_regEntries.insert(
- nfd::rib::RemoteRegistrator::RegisteredEntry(identity, event));
-
- eraseEntryWithIdentity(identity);
-
- BOOST_REQUIRE_EQUAL(face->sentInterests.size(), 2);
-
- Interest& request = face->sentInterests[1];
-
- ndn::nfd::ControlParameters extractedParameters;
- Name::Component verb;
- extractParameters(request, verb, extractedParameters);
-
- BOOST_CHECK_EQUAL(verb, UNREGISTER_VERB);
- BOOST_CHECK_EQUAL(extractedParameters.getName(), identity);
-}
-
-BOOST_FIXTURE_TEST_CASE(UnregisterAdvanced, RemoteRegistratorFixture)
-{
- connectToHub();
-
- Name identityShort("/remote/register");
- Name identityLong("/remote/register/long");
-
- scheduler::EventId eventShort;
- scheduler::EventId eventLong;
-
- insertEntryWithIdentity(identityShort, name::Component("appA"));
-
- remoteRegistrator->m_regEntries.insert(
- nfd::rib::RemoteRegistrator::RegisteredEntry(identityShort,
- eventShort));
-
- insertEntryWithIdentity(identityShort, name::Component("appB"));
-
- insertEntryWithIdentity(identityLong);
-
- remoteRegistrator->m_regEntries.insert(
- nfd::rib::RemoteRegistrator::RegisteredEntry(identityLong,
- eventLong));
-
- // two registration commands are generated for identityShort and identityLong
- BOOST_REQUIRE_EQUAL(face->sentInterests.size(), 2);
-
- eraseEntryWithIdentity(identityShort, name::Component("appA"));
-
- // no unregistration command is generated as appB also exists
- BOOST_REQUIRE_EQUAL(face->sentInterests.size(), 2);
-
- eraseEntryWithIdentity(identityShort, name::Component("appB"));
-
- // one unregistration command is generated for identityShort
- BOOST_REQUIRE_EQUAL(face->sentInterests.size(), 3);
-
- Interest& request = face->sentInterests[2];
-
- ndn::nfd::ControlParameters extractedParameters;
- Name::Component verb;
- extractParameters(request, verb, extractedParameters);
-
- BOOST_CHECK_EQUAL(verb, UNREGISTER_VERB);
- BOOST_CHECK_EQUAL(extractedParameters.getName(), identityShort);
-}
-
-BOOST_FIXTURE_TEST_CASE(EraseFace, RemoteRegistratorFixture)
-{
- connectToHub();
-
- Name identity("/remote/register");
- uint64_t faceId = 517;
-
- insertEntryWithIdentity(identity, DEFAULT_APP_NAME, faceId);
-
- scheduler::EventId event;
-
- remoteRegistrator->m_regEntries.insert(
- nfd::rib::RemoteRegistrator::RegisteredEntry(identity, event));
-
- eraseFace(faceId);
-
- BOOST_REQUIRE_EQUAL(face->sentInterests.size(), 2);
-
- Interest& request = face->sentInterests[1];
-
- ndn::nfd::ControlParameters extractedParameters;
- Name::Component verb;
- extractParameters(request, verb, extractedParameters);
-
- BOOST_CHECK_EQUAL(verb, UNREGISTER_VERB);
- BOOST_CHECK_EQUAL(extractedParameters.getName(), identity);
-}
-
-BOOST_FIXTURE_TEST_CASE(RebuildConnection, RemoteRegistratorFixture)
-{
- connectToHub();
-
- Name identity("/remote/register");
-
- insertEntryWithIdentity(identity);
-
- scheduler::EventId event;
-
- remoteRegistrator->m_regEntries.insert(
- nfd::rib::RemoteRegistrator::RegisteredEntry(identity, event));
-
- disconnectToHub();
-
- connectToHub();
-
- BOOST_REQUIRE_EQUAL(face->sentInterests.size(), 2);
-
- Interest& request1 = face->sentInterests[0];
- Interest& request2 = face->sentInterests[1];
-
- ndn::nfd::ControlParameters extractedParameters1, extractedParameters2;
- Name::Component verb1, verb2;
- extractParameters(request1, verb1, extractedParameters1);
- extractParameters(request2, verb2, extractedParameters2);
-
- BOOST_CHECK_EQUAL(verb1, REGISTER_VERB);
- BOOST_CHECK_EQUAL(verb2, REGISTER_VERB);
- BOOST_CHECK_EQUAL(extractedParameters1.getName(),
- extractedParameters2.getName());
-}
-
-BOOST_AUTO_TEST_SUITE_END()
-
-} // namespace tests
-} // namespace rib
-} // namespace nfd