table: MeasurementsAccessor uses StrategyChoice
This commit also deletes fib::Entry::set/getStrategy attribute.
refs #1276
Change-Id: I57dfe842a8024e0ad9908ba8a9c415d5f4ac1bbe
diff --git a/daemon/fw/strategy.cpp b/daemon/fw/strategy.cpp
index 2d95492..d41786d 100644
--- a/daemon/fw/strategy.cpp
+++ b/daemon/fw/strategy.cpp
@@ -6,7 +6,6 @@
#include "strategy.hpp"
#include "forwarder.hpp"
-#include "core/logger.hpp"
namespace nfd {
namespace fw {
@@ -16,7 +15,8 @@
Strategy::Strategy(Forwarder& forwarder, const Name& name)
: m_name(name)
, m_forwarder(forwarder)
- , m_measurements(m_forwarder.getMeasurements(), m_forwarder.getFib(), this)
+ , m_measurements(m_forwarder.getMeasurements(),
+ m_forwarder.getStrategyChoice(), this)
{
}
diff --git a/daemon/table/fib-entry.cpp b/daemon/table/fib-entry.cpp
index 733782b..6a9b686 100644
--- a/daemon/table/fib-entry.cpp
+++ b/daemon/table/fib-entry.cpp
@@ -38,9 +38,9 @@
it = m_nextHops.end() - 1;
}
// now it refers to the NextHop for face
-
+
it->setCost(cost);
-
+
this->sortNextHops();
}
@@ -53,7 +53,7 @@
if (it == m_nextHops.end()) {
return;
}
-
+
m_nextHops.erase(it);
}
@@ -69,12 +69,6 @@
std::sort(m_nextHops.begin(), m_nextHops.end(), &compare_NextHop_cost);
}
-void
-Entry::setStrategy(shared_ptr<fw::Strategy> strategy)
-{
- m_strategy = strategy;
-}
-
} // namespace fib
} // namespace nfd
diff --git a/daemon/table/fib-entry.hpp b/daemon/table/fib-entry.hpp
index f5c0fae..aac8fc5 100644
--- a/daemon/table/fib-entry.hpp
+++ b/daemon/table/fib-entry.hpp
@@ -11,10 +11,6 @@
namespace nfd {
-namespace fw {
-class Strategy;
-}
-
namespace fib {
/** \class NextHopList
@@ -34,29 +30,23 @@
public:
explicit
Entry(const Name& prefix);
-
+
const Name&
getPrefix() const;
-
+
const NextHopList&
getNextHops() const;
-
+
bool
hasNextHop(shared_ptr<Face> face) const;
-
+
/// adds a nexthop
void
addNextHop(shared_ptr<Face> face, int32_t cost);
-
+
/// removes a nexthop
void
removeNextHop(shared_ptr<Face> face);
-
- const fw::Strategy&
- getStrategy() const;
-
- void
- setStrategy(shared_ptr<fw::Strategy> strategy);
private:
/// sorts the nexthop list
@@ -66,7 +56,6 @@
private:
Name m_prefix;
NextHopList m_nextHops;
- shared_ptr<fw::Strategy> m_strategy;
};
@@ -82,13 +71,6 @@
return m_nextHops;
}
-inline const fw::Strategy&
-Entry::getStrategy() const
-{
- BOOST_ASSERT(static_cast<bool>(m_strategy));
- return *m_strategy;
-}
-
} // namespace fib
} // namespace nfd
diff --git a/daemon/table/measurements-accessor.cpp b/daemon/table/measurements-accessor.cpp
index 97a913b..d1f08de 100644
--- a/daemon/table/measurements-accessor.cpp
+++ b/daemon/table/measurements-accessor.cpp
@@ -5,14 +5,16 @@
*/
#include "measurements-accessor.hpp"
-#include "fw/strategy.hpp"
namespace nfd {
+using fw::Strategy;
+
MeasurementsAccessor::MeasurementsAccessor(Measurements& measurements,
- Fib& fib, fw::Strategy* strategy)
+ StrategyChoice& strategyChoice,
+ Strategy* strategy)
: m_measurements(measurements)
- , m_fib(fib)
+ , m_strategyChoice(strategyChoice)
, m_strategy(strategy)
{
}
@@ -28,9 +30,8 @@
return entry;
}
- shared_ptr<fib::Entry> fibEntry = m_fib.findLongestPrefixMatch(*entry);
- BOOST_ASSERT(static_cast<bool>(fibEntry));
- if (&fibEntry->getStrategy() == m_strategy) {
+ Strategy& effectiveStrategy = m_strategyChoice.findEffectiveStrategy(*entry);
+ if (&effectiveStrategy == m_strategy) {
return entry;
}
return shared_ptr<measurements::Entry>();
diff --git a/daemon/table/measurements-accessor.hpp b/daemon/table/measurements-accessor.hpp
index 26a6d38..53b30d4 100644
--- a/daemon/table/measurements-accessor.hpp
+++ b/daemon/table/measurements-accessor.hpp
@@ -8,7 +8,7 @@
#define NFD_TABLE_MEASUREMENTS_ACCESSOR_HPP
#include "measurements.hpp"
-#include "fib.hpp"
+#include "strategy-choice.hpp"
namespace nfd {
@@ -21,7 +21,8 @@
class MeasurementsAccessor : noncopyable
{
public:
- MeasurementsAccessor(Measurements& measurements, Fib& fib, fw::Strategy* strategy);
+ MeasurementsAccessor(Measurements& measurements, StrategyChoice& strategyChoice,
+ fw::Strategy* strategy);
~MeasurementsAccessor();
@@ -44,14 +45,6 @@
shared_ptr<measurements::Entry>
getParent(shared_ptr<measurements::Entry> child);
-// /// perform a longest prefix match
-// shared_ptr<fib::Entry>
-// findLongestPrefixMatch(const Name& name) const;
-//
-// /// perform an exact match
-// shared_ptr<fib::Entry>
-// findExactMatch(const Name& name) const;
-
/** \brief extend lifetime of an entry
*
* The entry will be kept until at least now()+lifetime.
@@ -69,7 +62,7 @@
private:
Measurements& m_measurements;
- Fib& m_fib;
+ StrategyChoice& m_strategyChoice;
fw::Strategy* m_strategy;
};
@@ -82,10 +75,7 @@
inline shared_ptr<measurements::Entry>
MeasurementsAccessor::get(const fib::Entry& fibEntry)
{
- if (&fibEntry.getStrategy() == m_strategy) {
- return m_measurements.get(fibEntry);
- }
- return shared_ptr<measurements::Entry>();
+ return this->filter(m_measurements.get(fibEntry));
}
inline shared_ptr<measurements::Entry>
@@ -100,18 +90,6 @@
return this->filter(m_measurements.getParent(child));
}
-//inline shared_ptr<fib::Entry>
-//MeasurementsAccessor::findLongestPrefixMatch(const Name& name) const
-//{
-// return this->filter(m_measurements.findLongestPrefixMatch(name));
-//}
-//
-//inline shared_ptr<fib::Entry>
-//MeasurementsAccessor::findExactMatch(const Name& name) const
-//{
-// return this->filter(m_measurements.findExactMatch(name));
-//}
-
inline void
MeasurementsAccessor::extendLifetime(measurements::Entry& entry, const time::Duration& lifetime)
{
diff --git a/daemon/table/strategy-choice.cpp b/daemon/table/strategy-choice.cpp
index 9e5cb37..c24a5b0 100644
--- a/daemon/table/strategy-choice.cpp
+++ b/daemon/table/strategy-choice.cpp
@@ -7,6 +7,7 @@
#include "strategy-choice.hpp"
#include "fw/strategy.hpp"
#include "pit-entry.hpp"
+#include "measurements-entry.hpp"
namespace nfd {
@@ -137,6 +138,12 @@
return this->findEffectiveStrategy(pitEntry.getName());
}
+Strategy&
+StrategyChoice::findEffectiveStrategy(const measurements::Entry& measurementsEntry) const
+{
+ return this->findEffectiveStrategy(measurementsEntry.getName());
+}
+
shared_ptr<fw::Strategy>
StrategyChoice::getStrategy(const Name& strategyName)
{
diff --git a/daemon/table/strategy-choice.hpp b/daemon/table/strategy-choice.hpp
index 7624dd4..9d45f15 100644
--- a/daemon/table/strategy-choice.hpp
+++ b/daemon/table/strategy-choice.hpp
@@ -59,6 +59,10 @@
fw::Strategy&
findEffectiveStrategy(const pit::Entry& pitEntry) const;
+ /// get effective strategy for measurementsEntry
+ fw::Strategy&
+ findEffectiveStrategy(const measurements::Entry& measurementsEntry) const;
+
/// number of entries stored
size_t
size() const;
diff --git a/tests/fw/ncc-strategy.cpp b/tests/fw/ncc-strategy.cpp
index 2709913..bb3f640 100644
--- a/tests/fw/ncc-strategy.cpp
+++ b/tests/fw/ncc-strategy.cpp
@@ -37,10 +37,13 @@
Fib& fib = forwarder.getFib();
shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first;
- fibEntry->setStrategy(strategy);
fibEntry->addNextHop(face1, 10);
fibEntry->addNextHop(face2, 20);
+ StrategyChoice& strategyChoice = forwarder.getStrategyChoice();
+ strategyChoice.install(strategy);
+ strategyChoice.insert(Name(), strategy->getName());
+
Pit& pit = forwarder.getPit();
// first Interest: strategy knows nothing and follows routing
diff --git a/tests/table/measurements-accessor.cpp b/tests/table/measurements-accessor.cpp
index 77f0526..caeb6d4 100644
--- a/tests/table/measurements-accessor.cpp
+++ b/tests/table/measurements-accessor.cpp
@@ -17,9 +17,8 @@
class MeasurementsAccessorTestStrategy : public fw::Strategy
{
public:
- explicit
- MeasurementsAccessorTestStrategy(Forwarder& forwarder)
- : Strategy(forwarder, "ndn:/MeasurementsAccessorTestStrategy")
+ MeasurementsAccessorTestStrategy(Forwarder& forwarder, const Name& name)
+ : Strategy(forwarder, name)
{
}
@@ -51,9 +50,9 @@
Forwarder forwarder;
shared_ptr<MeasurementsAccessorTestStrategy> strategy1 =
- make_shared<MeasurementsAccessorTestStrategy>(boost::ref(forwarder));
+ make_shared<MeasurementsAccessorTestStrategy>(boost::ref(forwarder), "ndn:/strategy1");
shared_ptr<MeasurementsAccessorTestStrategy> strategy2 =
- make_shared<MeasurementsAccessorTestStrategy>(boost::ref(forwarder));
+ make_shared<MeasurementsAccessorTestStrategy>(boost::ref(forwarder), "ndn:/strategy2");
Name nameRoot("ndn:/");
Name nameA ("ndn:/A");
@@ -61,10 +60,12 @@
Name nameABC ("ndn:/A/B/C");
Name nameAD ("ndn:/A/D");
- Fib& fib = forwarder.getFib();
- fib.insert(nameRoot).first->setStrategy(strategy1);
- fib.insert(nameA ).first->setStrategy(strategy2);
- fib.insert(nameAB ).first->setStrategy(strategy1);
+ StrategyChoice& strategyChoice = forwarder.getStrategyChoice();
+ strategyChoice.install(strategy1);
+ strategyChoice.install(strategy2);
+ strategyChoice.insert(nameRoot, strategy1->getName());
+ strategyChoice.insert(nameA , strategy2->getName());
+ strategyChoice.insert(nameAB , strategy1->getName());
MeasurementsAccessor& accessor1 = strategy1->getMeasurements_accessor();
MeasurementsAccessor& accessor2 = strategy2->getMeasurements_accessor();