fw: instantiate strategy of next higher version
When an exact strategy version is unavailable, strategy registry now instantiates the next higher version which can offer backwards compatibility. All existing strategies do not support other versions. refs #3868 Change-Id: Id2cf9ae3a1fa078ce8be815eea9396f5aa81ecbb
This commit is contained in:
1 parent
b859031855
commit
91f6ee0c72
19 files changed
+221
-197
No files matched your search
@@ -42,6 +42,10 @@ AccessStrategy::AccessStrategy(Forwarder& forwarder, const Name& name)
|
||||
if (!parsed.parameters.empty()) {
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("AccessStrategy does not accept parameters"));
|
||||
}
|
||||
if (parsed.version && *parsed.version != getStrategyName()[-1].toVersion()) {
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument(
|
||||
"AccessStrategy does not support version " + std::to_string(*parsed.version)));
|
||||
}
|
||||
this->setInstanceName(makeInstanceName(name, getStrategyName()));
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,10 @@ AsfStrategy::AsfStrategy(Forwarder& forwarder, const Name& name)
|
||||
if (!parsed.parameters.empty()) {
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("AsfStrategy does not accept parameters"));
|
||||
}
|
||||
if (parsed.version && *parsed.version != getStrategyName()[-1].toVersion()) {
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument(
|
||||
"AsfStrategy does not support version " + std::to_string(*parsed.version)));
|
||||
}
|
||||
this->setInstanceName(makeInstanceName(name, getStrategyName()));
|
||||
}
|
||||
|
||||
|
||||
@@ -67,6 +67,10 @@ BestRouteStrategy::BestRouteStrategy(Forwarder& forwarder, const Name& name)
|
||||
if (!parsed.parameters.empty()) {
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("BestRouteStrategy does not accept parameters"));
|
||||
}
|
||||
if (parsed.version && *parsed.version != getStrategyName()[-1].toVersion()) {
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument(
|
||||
"BestRouteStrategy does not support version " + std::to_string(*parsed.version)));
|
||||
}
|
||||
this->setInstanceName(makeInstanceName(name, getStrategyName()));
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,10 @@ BestRouteStrategy2::BestRouteStrategy2(Forwarder& forwarder, const Name& name)
|
||||
if (!parsed.parameters.empty()) {
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("BestRouteStrategy2 does not accept parameters"));
|
||||
}
|
||||
if (parsed.version && *parsed.version != getStrategyName()[-1].toVersion()) {
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument(
|
||||
"BestRouteStrategy2 does not support version " + std::to_string(*parsed.version)));
|
||||
}
|
||||
this->setInstanceName(makeInstanceName(name, getStrategyName()));
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,10 @@ ClientControlStrategy::ClientControlStrategy(Forwarder& forwarder, const Name& n
|
||||
if (!parsed.parameters.empty()) {
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("ClientControlStrategy does not accept parameters"));
|
||||
}
|
||||
if (parsed.version && *parsed.version != getStrategyName()[-1].toVersion()) {
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument(
|
||||
"ClientControlStrategy does not support version " + std::to_string(*parsed.version)));
|
||||
}
|
||||
this->setInstanceName(makeInstanceName(name, getStrategyName()));
|
||||
|
||||
NFD_LOG_WARN("NextHopFaceId field is honored universally and "
|
||||
|
||||
@@ -38,6 +38,10 @@ MulticastStrategy::MulticastStrategy(Forwarder& forwarder, const Name& name)
|
||||
if (!parsed.parameters.empty()) {
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("MulticastStrategy does not accept parameters"));
|
||||
}
|
||||
if (parsed.version && *parsed.version != getStrategyName()[-1].toVersion()) {
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument(
|
||||
"MulticastStrategy does not support version " + std::to_string(*parsed.version)));
|
||||
}
|
||||
this->setInstanceName(makeInstanceName(name, getStrategyName()));
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,10 @@ NccStrategy::NccStrategy(Forwarder& forwarder, const Name& name)
|
||||
if (!parsed.parameters.empty()) {
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("NccStrategy does not accept parameters"));
|
||||
}
|
||||
if (parsed.version && *parsed.version != getStrategyName()[-1].toVersion()) {
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument(
|
||||
"NccStrategy does not support version " + std::to_string(*parsed.version)));
|
||||
}
|
||||
this->setInstanceName(makeInstanceName(name, getStrategyName()));
|
||||
}
|
||||
|
||||
|
||||
+25
-13
@@ -48,24 +48,36 @@ Strategy::find(const Name& instanceName)
|
||||
const Registry& registry = getRegistry();
|
||||
ParsedInstanceName parsed = parseInstanceName(instanceName);
|
||||
|
||||
///\todo #3868 accommodate parameters
|
||||
if (parsed.version) {
|
||||
NFD_LOG_TRACE("find " << instanceName <<
|
||||
" strategyName=" << parsed.strategyName << " versioned");
|
||||
///\todo #3868 if exact version unavailable, choose closest higher version
|
||||
return registry.find(parsed.strategyName);
|
||||
// specified version: find exact or next higher version
|
||||
|
||||
auto found = registry.lower_bound(parsed.strategyName);
|
||||
if (found != registry.end()) {
|
||||
if (parsed.strategyName.getPrefix(-1).isPrefixOf(found->first)) {
|
||||
NFD_LOG_TRACE("find " << instanceName << " versioned found=" << found->first);
|
||||
return found;
|
||||
}
|
||||
}
|
||||
|
||||
NFD_LOG_TRACE("find " << instanceName << " versioned not-found");
|
||||
return registry.end();
|
||||
}
|
||||
|
||||
NFD_LOG_TRACE("find " << instanceName <<
|
||||
" strategyName=" << parsed.strategyName << " unversioned");
|
||||
Registry::const_iterator candidate = registry.end();
|
||||
for (auto it = registry.lower_bound(parsed.strategyName);
|
||||
it != registry.end() && parsed.strategyName.isPrefixOf(it->first); ++it) {
|
||||
if (it->first.size() == parsed.strategyName.size() + 1) { // only one extra component: version
|
||||
candidate = it;
|
||||
// no version specified: find highest version
|
||||
|
||||
if (!parsed.strategyName.empty()) { // Name().getSuccessor() would be invalid
|
||||
auto found = registry.lower_bound(parsed.strategyName.getSuccessor());
|
||||
if (found != registry.begin()) {
|
||||
--found;
|
||||
if (parsed.strategyName.isPrefixOf(found->first)) {
|
||||
NFD_LOG_TRACE("find " << instanceName << " unversioned found=" << found->first);
|
||||
return found;
|
||||
}
|
||||
}
|
||||
}
|
||||
return candidate;
|
||||
|
||||
NFD_LOG_TRACE("find " << instanceName << " unversioned not-found");
|
||||
return registry.end();
|
||||
}
|
||||
|
||||
bool
|
||||
|
||||
@@ -47,6 +47,7 @@ public: // registry
|
||||
static void
|
||||
registerType(const Name& strategyName = S::getStrategyName())
|
||||
{
|
||||
BOOST_ASSERT(strategyName.size() > 1);
|
||||
BOOST_ASSERT(strategyName.at(-1).isVersion());
|
||||
Registry& registry = getRegistry();
|
||||
BOOST_ASSERT(registry.count(strategyName) == 0);
|
||||
|
||||
@@ -52,26 +52,6 @@ NFD_REGISTER_STRATEGY(AccessStrategyTester);
|
||||
// code style rule 3.25. This is necessary because some lines ends with '\' which
|
||||
// would cause "multi-line comment" compiler warning if '//' comments are used.
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(Fw)
|
||||
BOOST_FIXTURE_TEST_SUITE(TestAccessStrategy, UnitTestTimeFixture)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Registration)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(Strategy::listRegistered().count(AccessStrategy::getStrategyName()), 1);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(InstanceName)
|
||||
{
|
||||
Forwarder forwarder;
|
||||
BOOST_REQUIRE(AccessStrategy::getStrategyName().at(-1).isVersion());
|
||||
BOOST_CHECK_EQUAL(
|
||||
AccessStrategy(forwarder, AccessStrategy::getStrategyName().getPrefix(-1)).getInstanceName(),
|
||||
AccessStrategy::getStrategyName());
|
||||
BOOST_CHECK_THROW(
|
||||
AccessStrategy(forwarder, Name(AccessStrategy::getStrategyName()).append("param")),
|
||||
std::invalid_argument);
|
||||
}
|
||||
|
||||
class TwoLaptopsFixture : public UnitTestTimeFixture
|
||||
{
|
||||
protected:
|
||||
@@ -108,7 +88,10 @@ protected:
|
||||
shared_ptr<TopologyLink> linkB;
|
||||
};
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(OneProducer, TwoLaptopsFixture)
|
||||
BOOST_AUTO_TEST_SUITE(Fw)
|
||||
BOOST_FIXTURE_TEST_SUITE(TestAccessStrategy, TwoLaptopsFixture)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(OneProducer)
|
||||
{
|
||||
/*
|
||||
* /------------------\
|
||||
@@ -153,7 +136,7 @@ BOOST_FIXTURE_TEST_CASE(OneProducer, TwoLaptopsFixture)
|
||||
BOOST_CHECK_LE(linkB->getFace(router).getCounters().nOutInterests, 5);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(FastSlowProducer, TwoLaptopsFixture)
|
||||
BOOST_AUTO_TEST_CASE(FastSlowProducer)
|
||||
{
|
||||
/*
|
||||
* /------------------\
|
||||
@@ -200,7 +183,7 @@ BOOST_FIXTURE_TEST_CASE(FastSlowProducer, TwoLaptopsFixture)
|
||||
BOOST_CHECK_LE(linkB->getFace(router).getCounters().nOutInterests, 15);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(ProducerMobility, TwoLaptopsFixture)
|
||||
BOOST_AUTO_TEST_CASE(ProducerMobility)
|
||||
{
|
||||
/*
|
||||
* /------------------\ /------------------\
|
||||
@@ -259,7 +242,7 @@ BOOST_FIXTURE_TEST_CASE(ProducerMobility, TwoLaptopsFixture)
|
||||
BOOST_CHECK_GE(consumer->getForwarderFace().getCounters().nOutData, 97);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(Bidirectional, TwoLaptopsFixture)
|
||||
BOOST_AUTO_TEST_CASE(Bidirectional)
|
||||
{
|
||||
/*
|
||||
* /laptops << +--------+ >> /laptops
|
||||
@@ -305,7 +288,7 @@ BOOST_FIXTURE_TEST_CASE(Bidirectional, TwoLaptopsFixture)
|
||||
BOOST_CHECK_GE(consumerBA->getForwarderFace().getCounters().nOutData, 97);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(PacketLoss, TwoLaptopsFixture)
|
||||
BOOST_AUTO_TEST_CASE(PacketLoss)
|
||||
{
|
||||
/*
|
||||
* test case Interests
|
||||
@@ -377,7 +360,7 @@ BOOST_FIXTURE_TEST_CASE(PacketLoss, TwoLaptopsFixture)
|
||||
BOOST_CHECK_EQUAL(hasData2c, true);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(Bug2831, TwoLaptopsFixture)
|
||||
BOOST_AUTO_TEST_CASE(Bug2831)
|
||||
{
|
||||
// make a two-node loop
|
||||
topo.registerPrefix(laptopA, linkA->getFace(laptopA), "ndn:/net");
|
||||
|
||||
@@ -43,23 +43,6 @@ NFD_REGISTER_STRATEGY(AsfStrategyTester);
|
||||
BOOST_AUTO_TEST_SUITE(Fw)
|
||||
BOOST_FIXTURE_TEST_SUITE(TestAsfStrategy, UnitTestTimeFixture)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Registration)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(Strategy::listRegistered().count(AsfStrategy::getStrategyName()), 1);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(InstanceName)
|
||||
{
|
||||
Forwarder forwarder;
|
||||
BOOST_REQUIRE(AsfStrategy::getStrategyName().at(-1).isVersion());
|
||||
BOOST_CHECK_EQUAL(
|
||||
AsfStrategy(forwarder, AsfStrategy::getStrategyName().getPrefix(-1)).getInstanceName(),
|
||||
AsfStrategy::getStrategyName());
|
||||
BOOST_CHECK_THROW(
|
||||
AsfStrategy(forwarder, Name(AsfStrategy::getStrategyName()).append("param")),
|
||||
std::invalid_argument);
|
||||
}
|
||||
|
||||
class AsfGridFixture : public UnitTestTimeFixture
|
||||
{
|
||||
protected:
|
||||
|
||||
@@ -38,29 +38,6 @@ using namespace nfd::tests;
|
||||
typedef StrategyTester<BestRouteStrategy> BestRouteStrategyTester;
|
||||
NFD_REGISTER_STRATEGY(BestRouteStrategyTester);
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(Fw)
|
||||
BOOST_FIXTURE_TEST_SUITE(TestBestRouteStrategy, BaseFixture)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Registration)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(Strategy::listRegistered().count(BestRouteStrategy::getStrategyName()), 1);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(InstanceName)
|
||||
{
|
||||
Forwarder forwarder;
|
||||
BOOST_REQUIRE(BestRouteStrategy::getStrategyName().at(-1).isVersion());
|
||||
BOOST_CHECK_EQUAL(
|
||||
BestRouteStrategy(forwarder, BestRouteStrategy::getStrategyName().getPrefix(-1)).getInstanceName(),
|
||||
BestRouteStrategy::getStrategyName());
|
||||
BOOST_CHECK_THROW(
|
||||
BestRouteStrategy(forwarder, Name(BestRouteStrategy::getStrategyName()).append("param")),
|
||||
std::invalid_argument);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END() // TestBestRouteStrategy
|
||||
BOOST_AUTO_TEST_SUITE_END() // Fw
|
||||
|
||||
} // namespace tests
|
||||
} // namespace fw
|
||||
} // namespace nfd
|
||||
@@ -76,23 +76,6 @@ public:
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE(TestBestRouteStrategy2, BestRouteStrategy2Fixture)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Registration)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(Strategy::listRegistered().count(BestRouteStrategy2::getStrategyName()), 1);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(InstanceName)
|
||||
{
|
||||
Forwarder forwarder;
|
||||
BOOST_REQUIRE(BestRouteStrategy2::getStrategyName().at(-1).isVersion());
|
||||
BOOST_CHECK_EQUAL(
|
||||
BestRouteStrategy2(forwarder, BestRouteStrategy2::getStrategyName().getPrefix(-1)).getInstanceName(),
|
||||
BestRouteStrategy2::getStrategyName());
|
||||
BOOST_CHECK_THROW(
|
||||
BestRouteStrategy2(forwarder, Name(BestRouteStrategy2::getStrategyName()).append("param")),
|
||||
std::invalid_argument);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Forward)
|
||||
{
|
||||
fib::Entry& fibEntry = *fib.insert(Name()).first;
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2016, 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 "fw/client-control-strategy.hpp"
|
||||
|
||||
#include "tests/test-common.hpp"
|
||||
|
||||
namespace nfd {
|
||||
namespace fw {
|
||||
namespace tests {
|
||||
|
||||
using namespace nfd::tests;
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(Fw)
|
||||
BOOST_FIXTURE_TEST_SUITE(TestClientControlStrategy, BaseFixture)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Registration)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(Strategy::listRegistered().count(ClientControlStrategy::getStrategyName()), 1);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(InstanceName)
|
||||
{
|
||||
Forwarder forwarder;
|
||||
BOOST_REQUIRE(ClientControlStrategy::getStrategyName().at(-1).isVersion());
|
||||
BOOST_CHECK_EQUAL(
|
||||
ClientControlStrategy(forwarder, ClientControlStrategy::getStrategyName().getPrefix(-1)).getInstanceName(),
|
||||
ClientControlStrategy::getStrategyName());
|
||||
BOOST_CHECK_THROW(
|
||||
ClientControlStrategy(forwarder, Name(ClientControlStrategy::getStrategyName()).append("param")),
|
||||
std::invalid_argument);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END() // TestClientControlStrategy
|
||||
BOOST_AUTO_TEST_SUITE_END() // Fw
|
||||
|
||||
} // namespace tests
|
||||
} // namespace fw
|
||||
} // namespace nfd
|
||||
@@ -67,23 +67,6 @@ protected:
|
||||
BOOST_AUTO_TEST_SUITE(Fw)
|
||||
BOOST_FIXTURE_TEST_SUITE(TestMulticastStrategy, MulticastStrategyFixture)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Registration)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(Strategy::listRegistered().count(MulticastStrategy::getStrategyName()), 1);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(InstanceName)
|
||||
{
|
||||
Forwarder forwarder;
|
||||
BOOST_REQUIRE(MulticastStrategy::getStrategyName().at(-1).isVersion());
|
||||
BOOST_CHECK_EQUAL(
|
||||
MulticastStrategy(forwarder, MulticastStrategy::getStrategyName().getPrefix(-1)).getInstanceName(),
|
||||
MulticastStrategy::getStrategyName());
|
||||
BOOST_CHECK_THROW(
|
||||
MulticastStrategy(forwarder, Name(MulticastStrategy::getStrategyName()).append("param")),
|
||||
std::invalid_argument);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Forward2)
|
||||
{
|
||||
fib::Entry& fibEntry = *fib.insert(Name()).first;
|
||||
|
||||
@@ -43,23 +43,6 @@ NFD_REGISTER_STRATEGY(NccStrategyTester);
|
||||
BOOST_AUTO_TEST_SUITE(Fw)
|
||||
BOOST_FIXTURE_TEST_SUITE(TestNccStrategy, UnitTestTimeFixture)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Registration)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(Strategy::listRegistered().count(NccStrategy::getStrategyName()), 1);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(InstanceName)
|
||||
{
|
||||
Forwarder forwarder;
|
||||
BOOST_REQUIRE(NccStrategy::getStrategyName().at(-1).isVersion());
|
||||
BOOST_CHECK_EQUAL(
|
||||
NccStrategy(forwarder, NccStrategy::getStrategyName().getPrefix(-1)).getInstanceName(),
|
||||
NccStrategy::getStrategyName());
|
||||
BOOST_CHECK_THROW(
|
||||
NccStrategy(forwarder, Name(NccStrategy::getStrategyName()).append("param")),
|
||||
std::invalid_argument);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(FavorRespondingUpstream)
|
||||
{
|
||||
// NccStrategy is fairly complex.
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2016, 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/>.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* This test suite tests instantiation logic in strategies.
|
||||
*/
|
||||
|
||||
// All strategies, sorted alphabetically.
|
||||
#include "fw/access-strategy.hpp"
|
||||
#include "fw/asf-strategy.hpp"
|
||||
#include "fw/best-route-strategy.hpp"
|
||||
#include "fw/best-route-strategy2.hpp"
|
||||
#include "fw/client-control-strategy.hpp"
|
||||
#include "fw/multicast-strategy.hpp"
|
||||
#include "fw/ncc-strategy.hpp"
|
||||
|
||||
#include "tests/test-common.hpp"
|
||||
#include <boost/mpl/vector.hpp>
|
||||
|
||||
namespace nfd {
|
||||
namespace fw {
|
||||
namespace tests {
|
||||
|
||||
using namespace nfd::tests;
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(Fw)
|
||||
BOOST_AUTO_TEST_SUITE(TestStrategyInstantiation)
|
||||
|
||||
template<typename S, bool CanAcceptParameters, uint64_t MinVersion>
|
||||
class Test
|
||||
{
|
||||
public:
|
||||
using Strategy = S;
|
||||
|
||||
static bool
|
||||
canAcceptParameters()
|
||||
{
|
||||
return CanAcceptParameters;
|
||||
}
|
||||
|
||||
static uint64_t
|
||||
getMinVersion()
|
||||
{
|
||||
return MinVersion;
|
||||
}
|
||||
|
||||
static Name
|
||||
getVersionedStrategyName(uint64_t version)
|
||||
{
|
||||
return S::getStrategyName().getPrefix(-1).appendVersion(version);
|
||||
}
|
||||
};
|
||||
|
||||
using Tests = boost::mpl::vector<
|
||||
Test<AccessStrategy, false, 1>,
|
||||
Test<AsfStrategy, true, 1>,
|
||||
Test<BestRouteStrategy, false, 1>,
|
||||
Test<BestRouteStrategy2, false, 4>,
|
||||
Test<ClientControlStrategy, false, 2>,
|
||||
Test<MulticastStrategy, false, 1>,
|
||||
Test<NccStrategy, false, 1>
|
||||
>;
|
||||
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE(Registration, T, Tests)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(Strategy::listRegistered().count(T::Strategy::getStrategyName()), 1);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE(InstanceName, T, Tests)
|
||||
{
|
||||
BOOST_REQUIRE(T::Strategy::getStrategyName().at(-1).isVersion());
|
||||
uint64_t maxVersion = T::Strategy::getStrategyName().at(-1).toVersion();
|
||||
BOOST_REQUIRE_LE(T::getMinVersion(), maxVersion);
|
||||
|
||||
Forwarder forwarder;
|
||||
for (uint64_t version = T::getMinVersion(); version <= maxVersion; ++version) {
|
||||
Name versionedName = T::getVersionedStrategyName(version);
|
||||
unique_ptr<typename T::Strategy> instance;
|
||||
BOOST_CHECK_NO_THROW(instance = make_unique<typename T::Strategy>(forwarder, versionedName));
|
||||
BOOST_CHECK_EQUAL(instance->getInstanceName(), versionedName);
|
||||
|
||||
if (!T::canAcceptParameters()) {
|
||||
Name nameWithParameters = Name(versionedName).append("param");
|
||||
BOOST_CHECK_THROW(typename T::Strategy(forwarder, nameWithParameters), std::invalid_argument);
|
||||
}
|
||||
}
|
||||
|
||||
if (T::getMinVersion() > 0) {
|
||||
Name version0Name = T::getVersionedStrategyName(0);
|
||||
BOOST_CHECK_THROW(typename T::Strategy(forwarder, version0Name), std::invalid_argument);
|
||||
Name earlyVersionName = T::getVersionedStrategyName(T::getMinVersion() - 1);
|
||||
BOOST_CHECK_THROW(typename T::Strategy(forwarder, earlyVersionName), std::invalid_argument);
|
||||
}
|
||||
|
||||
if (maxVersion < std::numeric_limits<uint64_t>::max()) {
|
||||
Name versionMaxName = T::getVersionedStrategyName(std::numeric_limits<uint64_t>::max());
|
||||
BOOST_CHECK_THROW(typename T::Strategy(forwarder, versionMaxName), std::invalid_argument);
|
||||
Name lateVersionName = T::getVersionedStrategyName(maxVersion + 1);
|
||||
BOOST_CHECK_THROW(typename T::Strategy(forwarder, lateVersionName), std::invalid_argument);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END() // TestStrategyInstantiation
|
||||
BOOST_AUTO_TEST_SUITE_END() // Fw
|
||||
|
||||
} // namespace tests
|
||||
} // namespace fw
|
||||
} // namespace nfd
|
||||
@@ -41,6 +41,8 @@ using namespace nfd::tests;
|
||||
BOOST_AUTO_TEST_SUITE(Fw)
|
||||
BOOST_FIXTURE_TEST_SUITE(TestStrategy, BaseFixture)
|
||||
|
||||
// Strategy registry is tested in table/strategy-choice.t.cpp and strategy-instantiation.t.cpp
|
||||
|
||||
class FaceTableAccessTestStrategy : public DummyStrategy
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
namespace nfd {
|
||||
namespace tests {
|
||||
|
||||
using fw::Strategy;
|
||||
|
||||
class StrategyChoiceFixture : public BaseFixture
|
||||
{
|
||||
protected:
|
||||
@@ -43,10 +45,13 @@ protected:
|
||||
DummyStrategy::registerAs(strategyNameQ);
|
||||
}
|
||||
|
||||
/** \brief insert StrategyChoice entry at \p prefix for \p instanceName
|
||||
* \return constructed instance name
|
||||
*/
|
||||
Name
|
||||
insertAndGet(const Name& prefix, const Name& strategyName)
|
||||
insertAndGet(const Name& prefix, const Name& instanceName)
|
||||
{
|
||||
BOOST_REQUIRE(sc.insert(prefix, strategyName));
|
||||
BOOST_REQUIRE(sc.insert(prefix, instanceName));
|
||||
bool isFound;
|
||||
Name foundName;
|
||||
std::tie(isFound, foundName) = sc.get(prefix);
|
||||
@@ -54,6 +59,17 @@ protected:
|
||||
return foundName;
|
||||
}
|
||||
|
||||
/** \brief determine whether the effective strategy type at \p prefix is \p S
|
||||
* \tparam S expected strategy type
|
||||
*/
|
||||
template<typename S>
|
||||
bool
|
||||
isStrategyType(const Name& prefix)
|
||||
{
|
||||
Strategy& effectiveStrategy = sc.findEffectiveStrategy(prefix);
|
||||
return dynamic_cast<S*>(&effectiveStrategy) != nullptr;
|
||||
}
|
||||
|
||||
template<typename Q>
|
||||
Name
|
||||
findInstanceName(const Q& query)
|
||||
@@ -72,8 +88,6 @@ protected:
|
||||
BOOST_AUTO_TEST_SUITE(Table)
|
||||
BOOST_FIXTURE_TEST_SUITE(TestStrategyChoice, StrategyChoiceFixture)
|
||||
|
||||
using fw::Strategy;
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Versioning)
|
||||
{
|
||||
const Name strategyNameV("/strategy-choice-V");
|
||||
@@ -90,15 +104,21 @@ BOOST_AUTO_TEST_CASE(Versioning)
|
||||
|
||||
// unversioned: choose latest version
|
||||
BOOST_CHECK_EQUAL(this->insertAndGet("/A", strategyNameV), strategyNameV4);
|
||||
BOOST_CHECK(this->isStrategyType<VersionedDummyStrategy<4>>("/A"));
|
||||
|
||||
// exact version: choose same version
|
||||
BOOST_CHECK_EQUAL(this->insertAndGet("/B", strategyNameV1), strategyNameV1);
|
||||
BOOST_CHECK(this->isStrategyType<VersionedDummyStrategy<1>>("/B"));
|
||||
BOOST_CHECK_EQUAL(this->insertAndGet("/C", strategyNameV3), strategyNameV3);
|
||||
BOOST_CHECK(this->isStrategyType<VersionedDummyStrategy<3>>("/C"));
|
||||
BOOST_CHECK_EQUAL(this->insertAndGet("/D", strategyNameV4), strategyNameV4);
|
||||
BOOST_CHECK(this->isStrategyType<VersionedDummyStrategy<4>>("/D"));
|
||||
|
||||
// lower version: choose next higher version
|
||||
// BOOST_CHECK_EQUAL(this->insertAndGet("/E", strategyNameV0), strategyNameV1);
|
||||
// BOOST_CHECK_EQUAL(this->insertAndGet("/F", strategyNameV2), strategyNameV3);
|
||||
BOOST_CHECK_EQUAL(this->insertAndGet("/E", strategyNameV0), strategyNameV0);
|
||||
BOOST_CHECK(this->isStrategyType<VersionedDummyStrategy<1>>("/E"));
|
||||
BOOST_CHECK_EQUAL(this->insertAndGet("/F", strategyNameV2), strategyNameV2);
|
||||
BOOST_CHECK(this->isStrategyType<VersionedDummyStrategy<3>>("/F"));
|
||||
|
||||
// higher version: failure
|
||||
BOOST_CHECK_EQUAL(sc.insert("/G", strategyNameV5), false);
|
||||
|
||||
Reference in new issue
Block a user