fw: register strategy with macro
refs #2410 Change-Id: Ifa79c194c58d0ebe1bca6236fc0a47debe2da05e
This commit is contained in:
1 parent
73b909a514
commit
faf3eb0823
11 files changed
+138
-96
No files matched your search
@@ -32,6 +32,7 @@ namespace fw {
|
||||
NFD_LOG_INIT("AccessStrategy");
|
||||
|
||||
const Name AccessStrategy::STRATEGY_NAME("ndn:/localhost/nfd/strategy/access/%FD%01");
|
||||
NFD_REGISTER_STRATEGY(AccessStrategy);
|
||||
|
||||
AccessStrategy::AccessStrategy(Forwarder& forwarder, const Name& name)
|
||||
: Strategy(forwarder, name)
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014 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
|
||||
*
|
||||
* 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/>.
|
||||
**/
|
||||
|
||||
#ifndef NFD_DAEMON_FW_AVAILABLE_STRATEGIES_HPP
|
||||
#define NFD_DAEMON_FW_AVAILABLE_STRATEGIES_HPP
|
||||
|
||||
#include "strategy.hpp"
|
||||
|
||||
namespace nfd {
|
||||
namespace fw {
|
||||
|
||||
shared_ptr<Strategy>
|
||||
makeDefaultStrategy(Forwarder& forwarder);
|
||||
|
||||
void
|
||||
installStrategies(Forwarder& forwarder);
|
||||
|
||||
} // namespace fw
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_DAEMON_FW_AVAILABLE_STRATEGIES_HPP
|
||||
@@ -1,12 +1,12 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014, 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
|
||||
* 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.
|
||||
@@ -29,6 +29,7 @@ namespace nfd {
|
||||
namespace fw {
|
||||
|
||||
const Name BestRouteStrategy::STRATEGY_NAME("ndn:/localhost/nfd/strategy/best-route/%FD%01");
|
||||
NFD_REGISTER_STRATEGY(BestRouteStrategy);
|
||||
|
||||
BestRouteStrategy::BestRouteStrategy(Forwarder& forwarder, const Name& name)
|
||||
: Strategy(forwarder, name)
|
||||
|
||||
@@ -32,6 +32,7 @@ namespace fw {
|
||||
NFD_LOG_INIT("BestRouteStrategy2");
|
||||
|
||||
const Name BestRouteStrategy2::STRATEGY_NAME("ndn:/localhost/nfd/strategy/best-route/%FD%02");
|
||||
NFD_REGISTER_STRATEGY(BestRouteStrategy2);
|
||||
|
||||
BestRouteStrategy2::BestRouteStrategy2(Forwarder& forwarder, const Name& name)
|
||||
: Strategy(forwarder, name)
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014, 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
|
||||
* 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.
|
||||
@@ -29,6 +29,7 @@ namespace nfd {
|
||||
namespace fw {
|
||||
|
||||
const Name BroadcastStrategy::STRATEGY_NAME("ndn:/localhost/nfd/strategy/broadcast/%FD%01");
|
||||
NFD_REGISTER_STRATEGY(BroadcastStrategy);
|
||||
|
||||
BroadcastStrategy::BroadcastStrategy(Forwarder& forwarder, const Name& name)
|
||||
: Strategy(forwarder, name)
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014, 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
|
||||
* 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.
|
||||
@@ -33,6 +33,7 @@ NFD_LOG_INIT("ClientControlStrategy");
|
||||
|
||||
const Name
|
||||
ClientControlStrategy::STRATEGY_NAME("ndn:/localhost/nfd/strategy/client-control/%FD%01");
|
||||
NFD_REGISTER_STRATEGY(ClientControlStrategy);
|
||||
|
||||
ClientControlStrategy::ClientControlStrategy(Forwarder& forwarder, const Name& name)
|
||||
: BestRouteStrategy(forwarder, name)
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014, 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
|
||||
* 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.
|
||||
@@ -26,7 +26,7 @@
|
||||
#include "forwarder.hpp"
|
||||
#include "core/logger.hpp"
|
||||
#include "core/random.hpp"
|
||||
#include "available-strategies.hpp"
|
||||
#include "strategy.hpp"
|
||||
#include <boost/random/uniform_int_distribution.hpp>
|
||||
|
||||
namespace nfd {
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace nfd {
|
||||
namespace fw {
|
||||
|
||||
const Name NccStrategy::STRATEGY_NAME("ndn:/localhost/nfd/strategy/ncc/%FD%01");
|
||||
NFD_REGISTER_STRATEGY(NccStrategy);
|
||||
|
||||
NccStrategy::NccStrategy(Forwarder& forwarder, const Name& name)
|
||||
: Strategy(forwarder, name)
|
||||
|
||||
@@ -23,12 +23,8 @@
|
||||
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "best-route-strategy.hpp"
|
||||
#include "broadcast-strategy.hpp"
|
||||
#include "client-control-strategy.hpp"
|
||||
#include "ncc-strategy.hpp"
|
||||
#include "strategy-registry.hpp"
|
||||
#include "best-route-strategy2.hpp"
|
||||
#include "access-strategy.hpp"
|
||||
|
||||
namespace nfd {
|
||||
namespace fw {
|
||||
@@ -39,25 +35,28 @@ makeDefaultStrategy(Forwarder& forwarder)
|
||||
return make_shared<BestRouteStrategy2>(ref(forwarder));
|
||||
}
|
||||
|
||||
template<typename S>
|
||||
inline void
|
||||
installStrategy(Forwarder& forwarder)
|
||||
static std::map<Name, StrategyCreateFunc>&
|
||||
getStrategyFactories()
|
||||
{
|
||||
StrategyChoice& strategyChoice = forwarder.getStrategyChoice();
|
||||
if (!strategyChoice.hasStrategy(S::STRATEGY_NAME)) {
|
||||
strategyChoice.install(make_shared<S>(ref(forwarder)));
|
||||
}
|
||||
static std::map<Name, StrategyCreateFunc> strategyFactories;
|
||||
return strategyFactories;
|
||||
}
|
||||
|
||||
void
|
||||
registerStrategyImpl(const Name& strategyName, const StrategyCreateFunc& createFunc)
|
||||
{
|
||||
getStrategyFactories().insert({strategyName, createFunc});
|
||||
}
|
||||
|
||||
void
|
||||
installStrategies(Forwarder& forwarder)
|
||||
{
|
||||
installStrategy<BestRouteStrategy>(forwarder);
|
||||
installStrategy<BroadcastStrategy>(forwarder);
|
||||
installStrategy<ClientControlStrategy>(forwarder);
|
||||
installStrategy<NccStrategy>(forwarder);
|
||||
installStrategy<BestRouteStrategy2>(forwarder);
|
||||
installStrategy<AccessStrategy>(forwarder);
|
||||
StrategyChoice& sc = forwarder.getStrategyChoice();
|
||||
for (const auto& pair : getStrategyFactories()) {
|
||||
if (!sc.hasStrategy(pair.first, true)) {
|
||||
sc.install(pair.second(forwarder));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace fw
|
||||
@@ -0,0 +1,78 @@
|
||||
/* -*- 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/>.
|
||||
*/
|
||||
|
||||
#ifndef NFD_DAEMON_FW_STRATEGY_REGISTRY_HPP
|
||||
#define NFD_DAEMON_FW_STRATEGY_REGISTRY_HPP
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
namespace nfd {
|
||||
|
||||
class Forwarder;
|
||||
|
||||
namespace fw {
|
||||
|
||||
class Strategy;
|
||||
|
||||
shared_ptr<Strategy>
|
||||
makeDefaultStrategy(Forwarder& forwarder);
|
||||
|
||||
void
|
||||
installStrategies(Forwarder& forwarder);
|
||||
|
||||
|
||||
typedef std::function<shared_ptr<Strategy>(Forwarder&)> StrategyCreateFunc;
|
||||
|
||||
void
|
||||
registerStrategyImpl(const Name& strategyName, const StrategyCreateFunc& createFunc);
|
||||
|
||||
/** \brief registers a strategy to be installed later
|
||||
*/
|
||||
template<typename S>
|
||||
void
|
||||
registerStrategy()
|
||||
{
|
||||
registerStrategyImpl(S::STRATEGY_NAME,
|
||||
[] (Forwarder& forwarder) { return make_shared<S>(ref(forwarder)); });
|
||||
}
|
||||
|
||||
/** \brief registers a built-in strategy
|
||||
*
|
||||
* This macro should appear once in .cpp of each built-in strategy.
|
||||
*/
|
||||
#define NFD_REGISTER_STRATEGY(StrategyType) \
|
||||
static class NfdAuto ## StrategyType ## StrategyRegistrationClass \
|
||||
{ \
|
||||
public: \
|
||||
NfdAuto ## StrategyType ## StrategyRegistrationClass() \
|
||||
{ \
|
||||
::nfd::fw::registerStrategy<StrategyType>(); \
|
||||
} \
|
||||
} g_nfdAuto ## StrategyType ## StrategyRegistrationVariable
|
||||
|
||||
} // namespace fw
|
||||
} // namespace nfd
|
||||
|
||||
#endif // NFD_DAEMON_FW_STRATEGY_REGISTRY_HPP
|
||||
@@ -1,12 +1,12 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014, 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
|
||||
* 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.
|
||||
@@ -27,6 +27,7 @@
|
||||
#define NFD_DAEMON_FW_STRATEGY_HPP
|
||||
|
||||
#include "forwarder.hpp"
|
||||
#include "strategy-registry.hpp"
|
||||
#include "table/measurements-accessor.hpp"
|
||||
|
||||
namespace nfd {
|
||||
|
||||
Reference in new issue
Block a user