fw: eliminate Forwarder::dispatchToStrategy()
Change-Id: Ia2e58c66548644fe3395f7e8c65e860554484fc8
diff --git a/daemon/fw/forwarder.cpp b/daemon/fw/forwarder.cpp
index 8301014..e5c0c20 100644
--- a/daemon/fw/forwarder.cpp
+++ b/daemon/fw/forwarder.cpp
@@ -211,11 +211,9 @@
return;
}
- // dispatch to strategy: after incoming Interest
- this->dispatchToStrategy(*pitEntry,
- [&] (auto& strategy) {
- strategy.afterReceiveInterest(FaceEndpoint(ingress.face, 0), interest, pitEntry);
- });
+ // dispatch to strategy: after receive Interest
+ m_strategyChoice.findEffectiveStrategy(*pitEntry)
+ .afterReceiveInterest(FaceEndpoint(ingress.face, 0), interest, pitEntry);
}
void
@@ -236,8 +234,7 @@
this->setExpiryTimer(pitEntry, 0_ms);
// dispatch to strategy: after Content Store hit
- this->dispatchToStrategy(*pitEntry,
- [&] (auto& strategy) { strategy.afterContentStoreHit(pitEntry, ingress, data); });
+ m_strategyChoice.findEffectiveStrategy(*pitEntry).afterContentStoreHit(pitEntry, ingress, data);
}
pit::OutRecord*
@@ -324,8 +321,7 @@
this->setExpiryTimer(pitEntry, 0_ms);
// trigger strategy: after receive Data
- this->dispatchToStrategy(*pitEntry,
- [&] (auto& strategy) { strategy.afterReceiveData(pitEntry, ingress, data); });
+ m_strategyChoice.findEffectiveStrategy(*pitEntry).afterReceiveData(pitEntry, ingress, data);
// mark PIT satisfied
pitEntry->isSatisfied = true;
@@ -357,8 +353,7 @@
this->setExpiryTimer(pitEntry, 0_ms);
// invoke PIT satisfy callback
- this->dispatchToStrategy(*pitEntry,
- [&] (auto& strategy) { strategy.beforeSatisfyInterest(pitEntry, ingress, data); });
+ m_strategyChoice.findEffectiveStrategy(*pitEntry).beforeSatisfyInterest(pitEntry, ingress, data);
// mark PIT satisfied
pitEntry->isSatisfied = true;
@@ -480,8 +475,7 @@
}
// trigger strategy: after receive NACK
- this->dispatchToStrategy(*pitEntry,
- [&] (auto& strategy) { strategy.afterReceiveNack(ingress, nack, pitEntry); });
+ m_strategyChoice.findEffectiveStrategy(*pitEntry).afterReceiveNack(ingress, nack, pitEntry);
}
bool
@@ -555,8 +549,7 @@
for (const auto& nte : affectedEntries) {
for (const auto& pitEntry : nte.getPitEntries()) {
- this->dispatchToStrategy(*pitEntry,
- [&] (auto& strategy) { strategy.afterNewNextHop(nextHop, pitEntry); });
+ m_strategyChoice.findEffectiveStrategy(*pitEntry).afterNewNextHop(nextHop, pitEntry);
}
}
}
diff --git a/daemon/fw/forwarder.hpp b/daemon/fw/forwarder.hpp
index aaef44c..6d4a068 100644
--- a/daemon/fw/forwarder.hpp
+++ b/daemon/fw/forwarder.hpp
@@ -237,20 +237,6 @@
NFD_VIRTUAL_WITH_TESTS void
insertDeadNonceList(pit::Entry& pitEntry, Face* upstream);
- /** \brief call trigger (method) on the effective strategy of pitEntry
- */
-#ifdef NFD_WITH_TESTS
- virtual void
- dispatchToStrategy(pit::Entry& pitEntry, std::function<void(fw::Strategy&)> trigger)
-#else
- template<class Function>
- void
- dispatchToStrategy(pit::Entry& pitEntry, Function&& trigger)
-#endif
- {
- trigger(m_strategyChoice.findEffectiveStrategy(pitEntry));
- }
-
private:
ForwarderCounters m_counters;
diff --git a/tests/daemon/fw/forwarder.t.cpp b/tests/daemon/fw/forwarder.t.cpp
index f3f7c63..e3b3a19 100644
--- a/tests/daemon/fw/forwarder.t.cpp
+++ b/tests/daemon/fw/forwarder.t.cpp
@@ -265,55 +265,36 @@
BOOST_CHECK_EQUAL(faceRemote->sentInterests.size(), 2);
}
-class ScopeLocalhostIncomingTestForwarder : public Forwarder
+BOOST_AUTO_TEST_CASE(ScopeLocalhostIncoming)
{
-public:
- using Forwarder::Forwarder;
+ auto face1 = addFace("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_LOCAL);
+ auto face2 = addFace(); // default is non-local
-protected:
- void
- dispatchToStrategy(pit::Entry&, std::function<void(fw::Strategy&)>) final
- {
- ++dispatchToStrategy_count;
- }
-
-public:
- int dispatchToStrategy_count = 0;
-};
-
-BOOST_FIXTURE_TEST_CASE(ScopeLocalhostIncoming, GlobalIoTimeFixture)
-{
- FaceTable faceTable;
- ScopeLocalhostIncomingTestForwarder forwarder(faceTable);
-
- auto face1 = make_shared<DummyFace>("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_LOCAL);
- auto face2 = make_shared<DummyFace>();
- faceTable.add(face1);
- faceTable.add(face2);
+ auto& strategy = choose<DummyStrategy>(forwarder, "/", DummyStrategy::getStrategyName());
// local face, /localhost: OK
- forwarder.dispatchToStrategy_count = 0;
+ strategy.afterReceiveInterest_count = 0;
auto i1 = makeInterest("/localhost/A1");
forwarder.onIncomingInterest(FaceEndpoint(*face1, 0), *i1);
- BOOST_CHECK_EQUAL(forwarder.dispatchToStrategy_count, 1);
+ BOOST_CHECK_EQUAL(strategy.afterReceiveInterest_count, 1);
// non-local face, /localhost: violate
- forwarder.dispatchToStrategy_count = 0;
+ strategy.afterReceiveInterest_count = 0;
auto i2 = makeInterest("/localhost/A2");
forwarder.onIncomingInterest(FaceEndpoint(*face2, 0), *i2);
- BOOST_CHECK_EQUAL(forwarder.dispatchToStrategy_count, 0);
+ BOOST_CHECK_EQUAL(strategy.afterReceiveInterest_count, 0);
// local face, non-/localhost: OK
- forwarder.dispatchToStrategy_count = 0;
+ strategy.afterReceiveInterest_count = 0;
auto i3 = makeInterest("/A3");
forwarder.onIncomingInterest(FaceEndpoint(*face1, 0), *i3);
- BOOST_CHECK_EQUAL(forwarder.dispatchToStrategy_count, 1);
+ BOOST_CHECK_EQUAL(strategy.afterReceiveInterest_count, 1);
// non-local face, non-/localhost: OK
- forwarder.dispatchToStrategy_count = 0;
+ strategy.afterReceiveInterest_count = 0;
auto i4 = makeInterest("/A4");
forwarder.onIncomingInterest(FaceEndpoint(*face2, 0), *i4);
- BOOST_CHECK_EQUAL(forwarder.dispatchToStrategy_count, 1);
+ BOOST_CHECK_EQUAL(strategy.afterReceiveInterest_count, 1);
BOOST_CHECK_EQUAL(forwarder.getCounters().nUnsolicitedData, 0);
@@ -322,7 +303,7 @@
forwarder.onIncomingData(FaceEndpoint(*face1, 0), *d1);
BOOST_CHECK_EQUAL(forwarder.getCounters().nUnsolicitedData, 1);
- // non-local face, /localhost: OK
+ // non-local face, /localhost: violate
auto d2 = makeData("/localhost/B2");
forwarder.onIncomingData(FaceEndpoint(*face2, 0), *d2);
BOOST_CHECK_EQUAL(forwarder.getCounters().nUnsolicitedData, 1);
@@ -349,31 +330,31 @@
auto interest1 = makeInterest("/A/1");
strategyA.afterReceiveInterest_count = 0;
strategyA.interestOutFace = face2;
- forwarder.startProcessInterest(FaceEndpoint(*face1, 0), *interest1);
+ forwarder.onIncomingInterest(FaceEndpoint(*face1, 0), *interest1);
BOOST_CHECK_EQUAL(strategyA.afterReceiveInterest_count, 1);
auto interest2 = makeInterest("/B/2", true);
strategyB.afterReceiveInterest_count = 0;
strategyB.interestOutFace = face2;
- forwarder.startProcessInterest(FaceEndpoint(*face1, 0), *interest2);
+ forwarder.onIncomingInterest(FaceEndpoint(*face1, 0), *interest2);
BOOST_CHECK_EQUAL(strategyB.afterReceiveInterest_count, 1);
this->advanceClocks(1_ms, 5_ms);
auto data1 = makeData("/A/1");
strategyA.beforeSatisfyInterest_count = 0;
- forwarder.startProcessData(FaceEndpoint(*face2, 0), *data1);
+ forwarder.onIncomingData(FaceEndpoint(*face2, 0), *data1);
BOOST_CHECK_EQUAL(strategyA.beforeSatisfyInterest_count, 1);
auto data2 = makeData("/B/2/b");
strategyB.beforeSatisfyInterest_count = 0;
- forwarder.startProcessData(FaceEndpoint(*face2, 0), *data2);
+ forwarder.onIncomingData(FaceEndpoint(*face2, 0), *data2);
BOOST_CHECK_EQUAL(strategyB.beforeSatisfyInterest_count, 1);
auto interest3 = makeInterest("/A/3", false, 30_ms);
- forwarder.startProcessInterest(FaceEndpoint(*face1, 0), *interest3);
+ forwarder.onIncomingInterest(FaceEndpoint(*face1, 0), *interest3);
auto interest4 = makeInterest("/B/4", false, 5_s);
- forwarder.startProcessInterest(FaceEndpoint(*face1, 0), *interest4);
+ forwarder.onIncomingInterest(FaceEndpoint(*face1, 0), *interest4);
}
BOOST_AUTO_TEST_CASE(IncomingData)
@@ -682,7 +663,7 @@
Pit& pit = forwarder.getPit();
BOOST_REQUIRE_EQUAL(pit.size(), 0);
- forwarder.startProcessInterest(FaceEndpoint(*face1, 0), *interest);
+ forwarder.onIncomingInterest(FaceEndpoint(*face1, 0), *interest);
this->advanceClocks(100_ms, 20_s);
BOOST_CHECK_EQUAL(pit.size(), 0);
}