fw: Nack in pipelines and best-route strategy
* in PIT out-record, add last incoming Nack field
* create incoming Nack pipeline
* create outgoing Nack pipeline
* modify Interest loop pipeline to send Nack upon duplicate Nonce
* in strategy API, add after receive Nack trigger and send Nack action
* in best-route strategy, send Nack-NoRoute before rejecting pending Interest
* in best-route strategy, process incoming Nack
Other changes include:
* Pit::find
* StrategyTester saved arguments structs
* TopologyTester transmit at Transport level
refs #3156
Change-Id: I7868561c0838231083d471261200aeb280cc6e9d
diff --git a/tests/daemon/fw/access-strategy.t.cpp b/tests/daemon/fw/access-strategy.t.cpp
index ddc0092..fa211a6 100644
--- a/tests/daemon/fw/access-strategy.t.cpp
+++ b/tests/daemon/fw/access-strategy.t.cpp
@@ -47,7 +47,8 @@
// 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_FIXTURE_TEST_SUITE(FwAccessStrategy, UnitTestTimeFixture)
+BOOST_AUTO_TEST_SUITE(Fw)
+BOOST_FIXTURE_TEST_SUITE(TestAccessStrategy, UnitTestTimeFixture)
class TwoLaptopsFixture : public UnitTestTimeFixture
{
@@ -65,14 +66,14 @@
* +---------+ +---------+
*/
- router = topo.addForwarder();
- laptopA = topo.addForwarder();
- laptopB = topo.addForwarder();
+ router = topo.addForwarder("R");
+ laptopA = topo.addForwarder("A");
+ laptopB = topo.addForwarder("B");
topo.setStrategy<fw::AccessStrategy>(router);
- linkA = topo.addLink(time::milliseconds(10), {router, laptopA});
- linkB = topo.addLink(time::milliseconds(20), {router, laptopB});
+ linkA = topo.addLink("RA", time::milliseconds(10), {router, laptopA});
+ linkB = topo.addLink("RB", time::milliseconds(20), {router, laptopB});
}
protected:
@@ -115,19 +116,19 @@
topo.registerPrefix(router, linkA->getFace(router), "ndn:/laptops");
topo.registerPrefix(router, linkB->getFace(router), "ndn:/laptops");
- shared_ptr<TopologyAppLink> producer = topo.addAppFace(laptopA, "ndn:/laptops/A");
- topo.addEchoProducer(*producer->getClientFace());
+ shared_ptr<TopologyAppLink> producer = topo.addAppFace("p", laptopA, "ndn:/laptops/A");
+ topo.addEchoProducer(producer->getClientFace());
- shared_ptr<TopologyAppLink> consumer = topo.addAppFace(router);
- topo.addIntervalConsumer(*consumer->getClientFace(), "ndn:/laptops/A",
+ shared_ptr<TopologyAppLink> consumer = topo.addAppFace("c", router);
+ topo.addIntervalConsumer(consumer->getClientFace(), "ndn:/laptops/A",
time::milliseconds(100), 100);
this->advanceClocks(time::milliseconds(5), time::seconds(12));
// most Interests should be satisfied, and few Interests can go to wrong laptop
- BOOST_CHECK_GE(consumer->getForwarderFace()->m_sentDatas.size(), 97);
- BOOST_CHECK_GE(linkA->getFace(router)->m_sentInterests.size(), 97);
- BOOST_CHECK_LE(linkB->getFace(router)->m_sentInterests.size(), 5);
+ BOOST_CHECK_GE(consumer->getForwarderFace().getCounters().getNOutDatas(), 97);
+ BOOST_CHECK_GE(linkA->getFace(router).getCounters().getNOutInterests(), 97);
+ BOOST_CHECK_LE(linkB->getFace(router).getCounters().getNOutInterests(), 5);
}
BOOST_FIXTURE_TEST_CASE(FastSlowProducer, TwoLaptopsFixture)
@@ -160,21 +161,21 @@
topo.registerPrefix(router, linkA->getFace(router), "ndn:/laptops");
topo.registerPrefix(router, linkB->getFace(router), "ndn:/laptops");
- shared_ptr<TopologyAppLink> producerA = topo.addAppFace(laptopA, "ndn:/laptops/BOTH");
- topo.addEchoProducer(*producerA->getClientFace());
- shared_ptr<TopologyAppLink> producerB = topo.addAppFace(laptopB, "ndn:/laptops/BOTH");
- topo.addEchoProducer(*producerB->getClientFace());
+ shared_ptr<TopologyAppLink> producerA = topo.addAppFace("pA", laptopA, "ndn:/laptops/BOTH");
+ topo.addEchoProducer(producerA->getClientFace());
+ shared_ptr<TopologyAppLink> producerB = topo.addAppFace("pB", laptopB, "ndn:/laptops/BOTH");
+ topo.addEchoProducer(producerB->getClientFace());
- shared_ptr<TopologyAppLink> consumer = topo.addAppFace(router);
- topo.addIntervalConsumer(*consumer->getClientFace(), "ndn:/laptops/BOTH",
+ shared_ptr<TopologyAppLink> consumer = topo.addAppFace("c", router);
+ topo.addIntervalConsumer(consumer->getClientFace(), "ndn:/laptops/BOTH",
time::milliseconds(100), 100);
this->advanceClocks(time::milliseconds(5), time::seconds(12));
// most Interests should be satisfied, and few Interests can go to slower laptopB
- BOOST_CHECK_GE(consumer->getForwarderFace()->m_sentDatas.size(), 97);
- BOOST_CHECK_GE(linkA->getFace(router)->m_sentInterests.size(), 90);
- BOOST_CHECK_LE(linkB->getFace(router)->m_sentInterests.size(), 15);
+ BOOST_CHECK_GE(consumer->getForwarderFace().getCounters().getNOutDatas(), 97);
+ BOOST_CHECK_GE(linkA->getFace(router).getCounters().getNOutInterests(), 90);
+ BOOST_CHECK_LE(linkB->getFace(router).getCounters().getNOutInterests(), 15);
}
BOOST_FIXTURE_TEST_CASE(ProducerMobility, TwoLaptopsFixture)
@@ -207,13 +208,13 @@
topo.registerPrefix(router, linkA->getFace(router), "ndn:/laptops");
topo.registerPrefix(router, linkB->getFace(router), "ndn:/laptops");
- shared_ptr<TopologyAppLink> producerA = topo.addAppFace(laptopA, "ndn:/laptops/M");
- topo.addEchoProducer(*producerA->getClientFace());
- shared_ptr<TopologyAppLink> producerB = topo.addAppFace(laptopB, "ndn:/laptops/M");
- topo.addEchoProducer(*producerB->getClientFace());
+ shared_ptr<TopologyAppLink> producerA = topo.addAppFace("pA", laptopA, "ndn:/laptops/M");
+ topo.addEchoProducer(producerA->getClientFace());
+ shared_ptr<TopologyAppLink> producerB = topo.addAppFace("pB", laptopB, "ndn:/laptops/M");
+ topo.addEchoProducer(producerB->getClientFace());
- shared_ptr<TopologyAppLink> consumer = topo.addAppFace(router);
- topo.addIntervalConsumer(*consumer->getClientFace(), "ndn:/laptops/M",
+ shared_ptr<TopologyAppLink> consumer = topo.addAppFace("c", router);
+ topo.addIntervalConsumer(consumer->getClientFace(), "ndn:/laptops/M",
time::milliseconds(100), 100);
// producer is initially on laptopA
@@ -221,19 +222,19 @@
this->advanceClocks(time::milliseconds(5), time::seconds(6));
// few Interests can go to laptopB
- BOOST_CHECK_LE(linkB->getFace(router)->m_sentInterests.size(), 5);
+ BOOST_CHECK_LE(linkB->getFace(router).getCounters().getNOutInterests(), 5);
// producer moves to laptopB
producerA->fail();
producerB->recover();
- linkA->getFace(router)->m_sentInterests.clear();
+ const_cast<FaceCounters&>(linkA->getFace(router).getCounters()).getNOutInterests().set(0);
this->advanceClocks(time::milliseconds(5), time::seconds(6));
// few additional Interests can go to laptopA
- BOOST_CHECK_LE(linkA->getFace(router)->m_sentInterests.size(), 5);
+ BOOST_CHECK_LE(linkA->getFace(router).getCounters().getNOutInterests(), 5);
// most Interests should be satisfied
- BOOST_CHECK_GE(consumer->getForwarderFace()->m_sentDatas.size(), 97);
+ BOOST_CHECK_GE(consumer->getForwarderFace().getCounters().getNOutDatas(), 97);
}
BOOST_FIXTURE_TEST_CASE(Bidirectional, TwoLaptopsFixture)
@@ -263,23 +264,23 @@
topo.registerPrefix(router, linkA->getFace(router), "ndn:/laptops");
topo.registerPrefix(router, linkB->getFace(router), "ndn:/laptops");
- shared_ptr<TopologyAppLink> producerA = topo.addAppFace(laptopA, "ndn:/laptops/A");
- topo.addEchoProducer(*producerA->getClientFace());
- shared_ptr<TopologyAppLink> producerB = topo.addAppFace(laptopB, "ndn:/laptops/B");
- topo.addEchoProducer(*producerB->getClientFace());
+ shared_ptr<TopologyAppLink> producerA = topo.addAppFace("pA", laptopA, "ndn:/laptops/A");
+ topo.addEchoProducer(producerA->getClientFace());
+ shared_ptr<TopologyAppLink> producerB = topo.addAppFace("pB", laptopB, "ndn:/laptops/B");
+ topo.addEchoProducer(producerB->getClientFace());
- shared_ptr<TopologyAppLink> consumerAB = topo.addAppFace(laptopA);
- topo.addIntervalConsumer(*consumerAB->getClientFace(), "ndn:/laptops/B",
+ shared_ptr<TopologyAppLink> consumerAB = topo.addAppFace("cAB", laptopA);
+ topo.addIntervalConsumer(consumerAB->getClientFace(), "ndn:/laptops/B",
time::milliseconds(100), 100);
- shared_ptr<TopologyAppLink> consumerBA = topo.addAppFace(laptopB);
- topo.addIntervalConsumer(*consumerBA->getClientFace(), "ndn:/laptops/A",
+ shared_ptr<TopologyAppLink> consumerBA = topo.addAppFace("cBA", laptopB);
+ topo.addIntervalConsumer(consumerBA->getClientFace(), "ndn:/laptops/A",
time::milliseconds(100), 100);
this->advanceClocks(time::milliseconds(5), time::seconds(12));
// most Interests should be satisfied
- BOOST_CHECK_GE(consumerAB->getForwarderFace()->m_sentDatas.size(), 97);
- BOOST_CHECK_GE(consumerBA->getForwarderFace()->m_sentDatas.size(), 97);
+ BOOST_CHECK_GE(consumerAB->getForwarderFace().getCounters().getNOutDatas(), 97);
+ BOOST_CHECK_GE(consumerBA->getForwarderFace().getCounters().getNOutDatas(), 97);
}
BOOST_FIXTURE_TEST_CASE(PacketLoss, TwoLaptopsFixture)
@@ -308,25 +309,25 @@
// laptopA has prefix in router FIB; laptopB is unused in this test case
topo.registerPrefix(router, linkA->getFace(router), "ndn:/laptops");
- shared_ptr<TopologyAppLink> producerA = topo.addAppFace(laptopA, "ndn:/laptops/A");
- topo.addEchoProducer(*producerA->getClientFace());
+ shared_ptr<TopologyAppLink> producerA = topo.addAppFace("pA", laptopA, "ndn:/laptops/A");
+ topo.addEchoProducer(producerA->getClientFace());
- shared_ptr<TopologyAppLink> consumer = topo.addAppFace(router);
+ shared_ptr<TopologyAppLink> consumer = topo.addAppFace("c", router);
// Interest 1 completes normally
shared_ptr<Interest> interest1 = makeInterest("ndn:/laptops/A/1");
bool hasData1 = false;
- consumer->getClientFace()->expressInterest(*interest1,
- bind([&hasData1] { hasData1 = true; }));
+ consumer->getClientFace().expressInterest(*interest1,
+ bind([&hasData1] { hasData1 = true; }));
this->advanceClocks(time::milliseconds(5), time::seconds(1));
BOOST_CHECK_EQUAL(hasData1, true);
// Interest 2 experiences a packet loss on initial transmission
shared_ptr<Interest> interest2a = makeInterest("ndn:/laptops/A/2");
bool hasData2a = false, hasTimeout2a = false;
- consumer->getClientFace()->expressInterest(*interest2a,
- bind([&hasData2a] { hasData2a = true; }),
- bind([&hasTimeout2a] { hasTimeout2a = true; }));
+ consumer->getClientFace().expressInterest(*interest2a,
+ bind([&hasData2a] { hasData2a = true; }),
+ bind([&hasTimeout2a] { hasTimeout2a = true; }));
producerA->fail();
this->advanceClocks(time::milliseconds(5), time::milliseconds(60));
BOOST_CHECK_EQUAL(hasData2a, false);
@@ -335,8 +336,8 @@
// Interest 2 retransmission is suppressed
shared_ptr<Interest> interest2b = makeInterest("ndn:/laptops/A/2");
bool hasData2b = false;
- consumer->getClientFace()->expressInterest(*interest2b,
- bind([&hasData2b] { hasData2b = true; }));
+ consumer->getClientFace().expressInterest(*interest2b,
+ bind([&hasData2b] { hasData2b = true; }));
producerA->recover();
this->advanceClocks(time::milliseconds(5), time::seconds(1));
BOOST_CHECK_EQUAL(hasData2b, false);
@@ -344,8 +345,8 @@
// Interest 2 retransmission gets through, and is answered
shared_ptr<Interest> interest2c = makeInterest("ndn:/laptops/A/2");
bool hasData2c = false;
- consumer->getClientFace()->expressInterest(*interest2c,
- bind([&hasData2c] { hasData2c = true; }));
+ consumer->getClientFace().expressInterest(*interest2c,
+ bind([&hasData2c] { hasData2c = true; }));
this->advanceClocks(time::milliseconds(5), time::seconds(1));
BOOST_CHECK_EQUAL(hasData2c, true);
}
@@ -357,17 +358,18 @@
topo.registerPrefix(router, linkA->getFace(router), "ndn:/net");
// send Interests from laptopA to router
- shared_ptr<TopologyAppLink> consumer = topo.addAppFace(laptopA);
- topo.addIntervalConsumer(*consumer->getClientFace(), "ndn:/net",
+ shared_ptr<TopologyAppLink> consumer = topo.addAppFace("c", laptopA);
+ topo.addIntervalConsumer(consumer->getClientFace(), "ndn:/net",
time::milliseconds(100), 10);
this->advanceClocks(time::milliseconds(5), time::seconds(2));
// Interest shouldn't loop back from router
- BOOST_CHECK_EQUAL(linkA->getFace(router)->m_sentInterests.size(), 0);
+ BOOST_CHECK_EQUAL(linkA->getFace(router).getCounters().getNOutInterests(), 0);
}
-BOOST_AUTO_TEST_SUITE_END()
+BOOST_AUTO_TEST_SUITE_END() // TestAccessStrategy
+BOOST_AUTO_TEST_SUITE_END() // Fw
} // namespace tests
} // namespace fw
diff --git a/tests/daemon/fw/best-route-strategy2.t.cpp b/tests/daemon/fw/best-route-strategy2.t.cpp
index 8a2c3db..4ee43e9 100644
--- a/tests/daemon/fw/best-route-strategy2.t.cpp
+++ b/tests/daemon/fw/best-route-strategy2.t.cpp
@@ -24,10 +24,11 @@
*/
#include "fw/best-route-strategy2.hpp"
-#include "strategy-tester.hpp"
#include "tests/test-common.hpp"
#include "tests/daemon/face/dummy-face.hpp"
+#include "strategy-tester.hpp"
+#include "topology-tester.hpp"
namespace nfd {
namespace fw {
@@ -35,33 +36,51 @@
using namespace nfd::tests;
-BOOST_FIXTURE_TEST_SUITE(FwBestRouteStrategy2, UnitTestTimeFixture)
+BOOST_AUTO_TEST_SUITE(Fw)
+
+class BestRouteStrategy2Fixture : public UnitTestTimeFixture
+{
+protected:
+ BestRouteStrategy2Fixture()
+ : strategy(forwarder)
+ , fib(forwarder.getFib())
+ , pit(forwarder.getPit())
+ , face1(make_shared<DummyFace>())
+ , face2(make_shared<DummyFace>())
+ , face3(make_shared<DummyFace>())
+ , face4(make_shared<DummyFace>())
+ , face5(make_shared<DummyFace>())
+ {
+ forwarder.addFace(face1);
+ forwarder.addFace(face2);
+ forwarder.addFace(face3);
+ forwarder.addFace(face4);
+ forwarder.addFace(face5);
+ }
+
+public:
+ Forwarder forwarder;
+ StrategyTester<fw::BestRouteStrategy2> strategy;
+ Fib& fib;
+ Pit& pit;
+
+ shared_ptr<DummyFace> face1;
+ shared_ptr<DummyFace> face2;
+ shared_ptr<DummyFace> face3;
+ shared_ptr<DummyFace> face4;
+ shared_ptr<DummyFace> face5;
+};
+
+BOOST_FIXTURE_TEST_SUITE(TestBestRouteStrategy2, BestRouteStrategy2Fixture)
BOOST_AUTO_TEST_CASE(Forward)
{
- Forwarder forwarder;
- typedef StrategyTester<fw::BestRouteStrategy2> BestRouteStrategy2Tester;
- BestRouteStrategy2Tester strategy(forwarder);
-
- shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
- shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
- shared_ptr<DummyFace> face3 = make_shared<DummyFace>();
- shared_ptr<DummyFace> face4 = make_shared<DummyFace>();
- shared_ptr<DummyFace> face5 = make_shared<DummyFace>();
- forwarder.addFace(face1);
- forwarder.addFace(face2);
- forwarder.addFace(face3);
- forwarder.addFace(face4);
- forwarder.addFace(face5);
-
- Fib& fib = forwarder.getFib();
shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first;
fibEntry->addNextHop(face1, 10);
fibEntry->addNextHop(face2, 20);
fibEntry->addNextHop(face3, 30);
shared_ptr<Interest> interest = makeInterest("ndn:/BzgFBchqA");
- Pit& pit = forwarder.getPit();
shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
const time::nanoseconds TICK = time::duration_cast<time::nanoseconds>(
@@ -71,20 +90,20 @@
// however face1 is downstream so it cannot be used
pitEntry->insertOrUpdateInRecord(face1, *interest);
strategy.afterReceiveInterest(*face1, *interest, fibEntry, pitEntry);
- BOOST_REQUIRE_EQUAL(strategy.m_sendInterestHistory.size(), 1);
- BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.back().get<1>(), face2);
+ BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 1);
+ BOOST_CHECK_EQUAL(strategy.sendInterestHistory.back().outFaceId, face2->getId());
// downstream retransmits frequently, but the strategy should not send Interests
// more often than DEFAULT_MIN_RETX_INTERVAL
scheduler::EventId retxFrom4Evt;
- size_t nSentLast = strategy.m_sendInterestHistory.size();
+ size_t nSentLast = strategy.sendInterestHistory.size();
time::steady_clock::TimePoint timeSentLast = time::steady_clock::now();
function<void()> periodicalRetxFrom4; // let periodicalRetxFrom4 lambda capture itself
periodicalRetxFrom4 = [&] {
pitEntry->insertOrUpdateInRecord(face4, *interest);
strategy.afterReceiveInterest(*face4, *interest, fibEntry, pitEntry);
- size_t nSent = strategy.m_sendInterestHistory.size();
+ size_t nSent = strategy.sendInterestHistory.size();
if (nSent > nSentLast) {
BOOST_CHECK_EQUAL(nSent - nSentLast, 1);
time::steady_clock::TimePoint timeSent = time::steady_clock::now();
@@ -101,29 +120,346 @@
// nexthops for accepted retransmissions: follow FIB cost,
// later forward to an eligible upstream with earliest OutRecord
- BOOST_REQUIRE_GE(strategy.m_sendInterestHistory.size(), 6);
- BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory[1].get<1>(), face1);
- BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory[2].get<1>(), face3);
- BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory[3].get<1>(), face2);
- BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory[4].get<1>(), face1);
- BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory[5].get<1>(), face3);
+ BOOST_REQUIRE_GE(strategy.sendInterestHistory.size(), 6);
+ BOOST_CHECK_EQUAL(strategy.sendInterestHistory[1].outFaceId, face1->getId());
+ BOOST_CHECK_EQUAL(strategy.sendInterestHistory[2].outFaceId, face3->getId());
+ BOOST_CHECK_EQUAL(strategy.sendInterestHistory[3].outFaceId, face2->getId());
+ BOOST_CHECK_EQUAL(strategy.sendInterestHistory[4].outFaceId, face1->getId());
+ BOOST_CHECK_EQUAL(strategy.sendInterestHistory[5].outFaceId, face3->getId());
fibEntry->removeNextHop(face1);
- strategy.m_sendInterestHistory.clear();
+ strategy.sendInterestHistory.clear();
for (int i = 0; i < 3; ++i) {
this->advanceClocks(TICK, fw::RetxSuppressionExponential::DEFAULT_MAX_INTERVAL * 2);
pitEntry->insertOrUpdateInRecord(face5, *interest);
strategy.afterReceiveInterest(*face5, *interest, fibEntry, pitEntry);
}
- BOOST_REQUIRE_EQUAL(strategy.m_sendInterestHistory.size(), 3);
- BOOST_CHECK_NE(strategy.m_sendInterestHistory[0].get<1>(), face1);
- BOOST_CHECK_NE(strategy.m_sendInterestHistory[1].get<1>(), face1);
- BOOST_CHECK_NE(strategy.m_sendInterestHistory[2].get<1>(), face1);
+ BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 3);
+ BOOST_CHECK_NE(strategy.sendInterestHistory[0].outFaceId, face1->getId());
+ BOOST_CHECK_NE(strategy.sendInterestHistory[1].outFaceId, face1->getId());
+ BOOST_CHECK_NE(strategy.sendInterestHistory[2].outFaceId, face1->getId());
// face1 cannot be used because it's gone from FIB entry
}
-BOOST_AUTO_TEST_SUITE_END()
+BOOST_AUTO_TEST_SUITE(NoRouteNack) // send Nack-NoRoute if there's no usable FIB nexthop
+
+class EmptyNextHopList
+{
+public:
+ Name
+ getInterestName()
+ {
+ return "/P";
+ }
+
+ shared_ptr<fib::Entry>
+ makeFibEntry(BestRouteStrategy2Fixture* fixture)
+ {
+ return fixture->fib.insert(Name()).first;
+ }
+};
+
+class NextHopIsDownstream
+{
+public:
+ Name
+ getInterestName()
+ {
+ return "/P";
+ }
+
+ shared_ptr<fib::Entry>
+ makeFibEntry(BestRouteStrategy2Fixture* fixture)
+ {
+ shared_ptr<fib::Entry> fibEntry = fixture->fib.insert(Name()).first;
+ fibEntry->addNextHop(fixture->face1, 10);
+ return fibEntry;
+ }
+};
+
+class NextHopViolatesScope
+{
+public:
+ Name
+ getInterestName()
+ {
+ return "/localhop/P";
+ }
+
+ shared_ptr<fib::Entry>
+ makeFibEntry(BestRouteStrategy2Fixture* fixture)
+ {
+ shared_ptr<fib::Entry> fibEntry = fixture->fib.insert("/localhop").first;
+ fibEntry->addNextHop(fixture->face2, 10);
+ // face1 and face2 are both non-local; Interest from face1 cannot be forwarded to face2
+ return fibEntry;
+ }
+};
+
+typedef boost::mpl::vector<EmptyNextHopList, NextHopIsDownstream, NextHopViolatesScope> NoRouteScenarios;
+
+BOOST_AUTO_TEST_CASE_TEMPLATE(IncomingInterest, Scenario, NoRouteScenarios)
+{
+ Scenario scenario;
+
+ shared_ptr<Interest> interest = makeInterest(scenario.getInterestName());
+ shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
+ pitEntry->insertOrUpdateInRecord(face1, *interest);
+
+ shared_ptr<fib::Entry> fibEntry = scenario.makeFibEntry(this);
+
+ strategy.afterReceiveInterest(*face1, *interest, fibEntry, pitEntry);
+
+ BOOST_REQUIRE_EQUAL(strategy.rejectPendingInterestHistory.size(), 1);
+ BOOST_CHECK_EQUAL(strategy.rejectPendingInterestHistory[0].pitEntry, pitEntry);
+
+ BOOST_REQUIRE_EQUAL(strategy.sendNackHistory.size(), 1);
+ BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].pitEntry, pitEntry);
+ BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].outFaceId, face1->getId());
+ BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].header.getReason(), lp::NackReason::NO_ROUTE);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // NoRouteNack
+
+BOOST_AUTO_TEST_SUITE(IncomingNack)
+
+BOOST_AUTO_TEST_CASE(OneUpstream) // one upstream, send Nack when Nack arrives
+{
+ shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first;
+ fibEntry->addNextHop(face3, 10);
+ fibEntry->addNextHop(face4, 20);
+ fibEntry->addNextHop(face5, 30);
+
+ shared_ptr<Interest> interest1 = makeInterest("/McQYjMbm", 992);
+ shared_ptr<Interest> interest2 = makeInterest("/McQYjMbm", 114);
+ shared_ptr<pit::Entry> pitEntry = pit.insert(*interest1).first;
+ pitEntry->insertOrUpdateInRecord(face1, *interest1);
+ pitEntry->insertOrUpdateInRecord(face2, *interest2);
+ pitEntry->insertOrUpdateOutRecord(face3, *interest1);
+
+ lp::Nack nack3 = makeNack("/McQYjMbm", 992, lp::NackReason::CONGESTION);
+ pitEntry->getOutRecord(*face3)->setIncomingNack(nack3);
+ strategy.afterReceiveNack(*face3, nack3, fibEntry, pitEntry);
+
+ BOOST_REQUIRE_EQUAL(strategy.sendNackHistory.size(), 2);
+ BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].pitEntry, pitEntry);
+ BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].header.getReason(), lp::NackReason::CONGESTION);
+ BOOST_CHECK_EQUAL(strategy.sendNackHistory[1].pitEntry, pitEntry);
+ BOOST_CHECK_EQUAL(strategy.sendNackHistory[1].header.getReason(), lp::NackReason::CONGESTION);
+ std::unordered_set<FaceId> nackFaceIds{strategy.sendNackHistory[0].outFaceId,
+ strategy.sendNackHistory[1].outFaceId};
+ std::unordered_set<FaceId> expectedNackFaceIds{face1->getId(), face2->getId()};
+ BOOST_CHECK_EQUAL_COLLECTIONS(nackFaceIds.begin(), nackFaceIds.end(),
+ expectedNackFaceIds.begin(), expectedNackFaceIds.end());
+}
+
+BOOST_AUTO_TEST_CASE(TwoUpstreams) // two upstreams, send Nack when both Nacks arrive
+{
+ shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first;
+ fibEntry->addNextHop(face3, 10);
+ fibEntry->addNextHop(face4, 20);
+ fibEntry->addNextHop(face5, 30);
+
+ shared_ptr<Interest> interest1 = makeInterest("/aS9FAyUV19", 286);
+ shared_ptr<pit::Entry> pitEntry = pit.insert(*interest1).first;
+ pitEntry->insertOrUpdateInRecord(face1, *interest1);
+ pitEntry->insertOrUpdateOutRecord(face3, *interest1);
+ pitEntry->insertOrUpdateOutRecord(face4, *interest1);
+
+ lp::Nack nack3 = makeNack("/aS9FAyUV19", 286, lp::NackReason::CONGESTION);
+ pitEntry->getOutRecord(*face3)->setIncomingNack(nack3);
+ strategy.afterReceiveNack(*face3, nack3, fibEntry, pitEntry);
+
+ BOOST_CHECK_EQUAL(strategy.sendNackHistory.size(), 0); // don't send Nack until all upstreams have Nacked
+
+ lp::Nack nack4 = makeNack("/aS9FAyUV19", 286, lp::NackReason::CONGESTION);
+ pitEntry->getOutRecord(*face4)->setIncomingNack(nack4);
+ strategy.afterReceiveNack(*face4, nack4, fibEntry, pitEntry);
+
+ BOOST_REQUIRE_EQUAL(strategy.sendNackHistory.size(), 1);
+ BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].pitEntry, pitEntry);
+ BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].outFaceId, face1->getId());
+ BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].header.getReason(), lp::NackReason::CONGESTION);
+}
+
+BOOST_AUTO_TEST_CASE(Timeout) // two upstreams, one times out, don't send Nack
+{
+ shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first;
+ fibEntry->addNextHop(face3, 10);
+ fibEntry->addNextHop(face4, 20);
+ fibEntry->addNextHop(face5, 30);
+
+ shared_ptr<Interest> interest1 = makeInterest("/sIYw0TXWDj", 115);
+ interest1->setInterestLifetime(time::milliseconds(400));
+ shared_ptr<pit::Entry> pitEntry = pit.insert(*interest1).first;
+ pitEntry->insertOrUpdateInRecord(face1, *interest1);
+ pitEntry->insertOrUpdateOutRecord(face3, *interest1);
+
+ this->advanceClocks(time::milliseconds(300));
+ shared_ptr<Interest> interest2 = makeInterest("/sIYw0TXWDj", 223);
+ pitEntry->insertOrUpdateInRecord(face1, *interest2);
+ pitEntry->insertOrUpdateOutRecord(face4, *interest2);
+
+ this->advanceClocks(time::milliseconds(200)); // face3 has timed out
+
+ lp::Nack nack4 = makeNack("/sIYw0TXWDj", 223, lp::NackReason::CONGESTION);
+ pitEntry->getOutRecord(*face4)->setIncomingNack(nack4);
+ strategy.afterReceiveNack(*face4, nack4, fibEntry, pitEntry);
+
+ BOOST_CHECK_EQUAL(strategy.sendNackHistory.size(), 0);
+}
+
+BOOST_FIXTURE_TEST_CASE(LiveDeadlock, UnitTestTimeFixture) // #3033 note-7
+{
+ /*
+ * /----------\
+ * | producer |
+ * \----------/
+ * |
+ * +---+
+ * | P |
+ * +---+
+ * |
+ * failed link
+ * |
+ * +---+
+ * | R |
+ * +---+
+ * ^ ^
+ * / \
+ * / \
+ * +---+ +---+
+ * | B | <---> | C |
+ * +---+ +---+
+ * ^ ^
+ * | |
+ * | |
+ * +---+ +---+
+ * | A | | D |
+ * +---+ +---+
+ * ^ ^
+ * | |
+ * /----------\ /----------\
+ * | consumer | | consumer |
+ * \----------/ \----------/
+ */
+
+ TopologyTester topo;
+ TopologyNode nodeP = topo.addForwarder("P"),
+ nodeR = topo.addForwarder("R"),
+ nodeA = topo.addForwarder("A"),
+ nodeB = topo.addForwarder("B"),
+ nodeC = topo.addForwarder("C"),
+ nodeD = topo.addForwarder("D");
+
+ for (TopologyNode node : {nodeP, nodeR, nodeA, nodeB, nodeC, nodeD}) {
+ topo.setStrategy<BestRouteStrategy2>(node);
+ }
+
+ const time::milliseconds LINK_DELAY(10);
+ shared_ptr<TopologyLink> linkPR = topo.addLink("PR", LINK_DELAY, {nodeP, nodeR}),
+ linkRB = topo.addLink("RB", LINK_DELAY, {nodeR, nodeB}),
+ linkRC = topo.addLink("RC", LINK_DELAY, {nodeR, nodeC}),
+ linkBC = topo.addLink("BC", LINK_DELAY, {nodeB, nodeC}),
+ linkBA = topo.addLink("BA", LINK_DELAY, {nodeB, nodeA}),
+ linkCD = topo.addLink("CD", LINK_DELAY, {nodeC, nodeD});
+
+ // TODO register the prefix on R->P but then set the face DOWN
+ // topo.registerPrefix(nodeR, linkPR->getFace(nodeR), "ndn:/P", 10);
+ topo.registerPrefix(nodeB, linkRB->getFace(nodeB), "ndn:/P", 20);
+ topo.registerPrefix(nodeB, linkBC->getFace(nodeB), "ndn:/P", 30);
+ topo.registerPrefix(nodeC, linkRC->getFace(nodeC), "ndn:/P", 20);
+ topo.registerPrefix(nodeC, linkBC->getFace(nodeC), "ndn:/P", 30);
+ topo.registerPrefix(nodeA, linkBA->getFace(nodeA), "ndn:/P", 30);
+ topo.registerPrefix(nodeD, linkCD->getFace(nodeD), "ndn:/P", 30);
+
+ ndn::Face& appA = topo.addAppFace("A", nodeA)->getClientFace();
+ ndn::Face& appD = topo.addAppFace("D", nodeD)->getClientFace();
+
+ int nNacksA = 0, nNacksD = 0;
+ appA.expressInterest(Interest("/P/1"), bind([]{}), bind([&nNacksA]{ ++nNacksA; }), bind([]{}));
+ appD.expressInterest(Interest("/P/1"), bind([]{}), bind([&nNacksD]{ ++nNacksD; }), bind([]{}));
+ this->advanceClocks(time::milliseconds(1), time::milliseconds(5));
+ appA.expressInterest(Interest("/P/1"), bind([]{}), bind([&nNacksA]{ ++nNacksA; }), bind([]{}));
+ appD.expressInterest(Interest("/P/1"), bind([]{}), bind([&nNacksD]{ ++nNacksD; }), bind([]{}));
+ this->advanceClocks(time::milliseconds(1), time::milliseconds(100));
+
+ // As long as at least one Nack arrives at each client, strategy behavior is correct.
+ // Whether both Interests are Nacked is a client face behavior, not strategy behavior.
+ BOOST_CHECK_GT(nNacksA, 0);
+ BOOST_CHECK_GT(nNacksD, 0);
+}
+
+template<lp::NackReason X, lp::NackReason Y, lp::NackReason R>
+struct NackReasonCombination
+{
+ lp::NackReason
+ getX() const
+ {
+ return X;
+ }
+
+ lp::NackReason
+ getY() const
+ {
+ return Y;
+ }
+
+ lp::NackReason
+ getExpectedResult() const
+ {
+ return R;
+ }
+};
+
+typedef boost::mpl::vector<
+ NackReasonCombination<lp::NackReason::CONGESTION, lp::NackReason::CONGESTION, lp::NackReason::CONGESTION>,
+ NackReasonCombination<lp::NackReason::CONGESTION, lp::NackReason::DUPLICATE, lp::NackReason::CONGESTION>,
+ NackReasonCombination<lp::NackReason::CONGESTION, lp::NackReason::NO_ROUTE, lp::NackReason::CONGESTION>,
+ NackReasonCombination<lp::NackReason::DUPLICATE, lp::NackReason::CONGESTION, lp::NackReason::CONGESTION>,
+ NackReasonCombination<lp::NackReason::DUPLICATE, lp::NackReason::DUPLICATE, lp::NackReason::DUPLICATE>,
+ NackReasonCombination<lp::NackReason::DUPLICATE, lp::NackReason::NO_ROUTE, lp::NackReason::DUPLICATE>,
+ NackReasonCombination<lp::NackReason::NO_ROUTE, lp::NackReason::CONGESTION, lp::NackReason::CONGESTION>,
+ NackReasonCombination<lp::NackReason::NO_ROUTE, lp::NackReason::DUPLICATE, lp::NackReason::DUPLICATE>,
+ NackReasonCombination<lp::NackReason::NO_ROUTE, lp::NackReason::NO_ROUTE, lp::NackReason::NO_ROUTE>
+ > NackReasonCombinations;
+
+BOOST_AUTO_TEST_CASE_TEMPLATE(CombineReasons, Combination, NackReasonCombinations)
+{
+ Combination combination;
+
+ shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first;
+ fibEntry->addNextHop(face3, 10);
+ fibEntry->addNextHop(face4, 20);
+ fibEntry->addNextHop(face5, 30);
+
+ shared_ptr<Interest> interest1 = makeInterest("/F6sEwB24I", 282);
+ shared_ptr<pit::Entry> pitEntry = pit.insert(*interest1).first;
+ pitEntry->insertOrUpdateInRecord(face1, *interest1);
+ pitEntry->insertOrUpdateOutRecord(face3, *interest1);
+ pitEntry->insertOrUpdateOutRecord(face4, *interest1);
+
+ lp::Nack nack3 = makeNack("/F6sEwB24I", 282, combination.getX());
+ pitEntry->getOutRecord(*face3)->setIncomingNack(nack3);
+ strategy.afterReceiveNack(*face3, nack3, fibEntry, pitEntry);
+
+ BOOST_CHECK_EQUAL(strategy.sendNackHistory.size(), 0);
+
+ lp::Nack nack4 = makeNack("/F6sEwB24I", 282, combination.getY());
+ pitEntry->getOutRecord(*face4)->setIncomingNack(nack4);
+ strategy.afterReceiveNack(*face4, nack4, fibEntry, pitEntry);
+
+ BOOST_REQUIRE_EQUAL(strategy.sendNackHistory.size(), 1);
+ BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].pitEntry, pitEntry);
+ BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].outFaceId, face1->getId());
+ BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].header.getReason(), combination.getExpectedResult());
+}
+
+BOOST_AUTO_TEST_SUITE_END() // IncomingNack
+
+BOOST_AUTO_TEST_SUITE_END() // TestBestRouteStrategy2
+BOOST_AUTO_TEST_SUITE_END() // Fw
} // namespace tests
} // namespace fw
diff --git a/tests/daemon/fw/client-control-strategy.t.cpp b/tests/daemon/fw/client-control-strategy.t.cpp
index ee3a362..189d42f 100644
--- a/tests/daemon/fw/client-control-strategy.t.cpp
+++ b/tests/daemon/fw/client-control-strategy.t.cpp
@@ -35,7 +35,8 @@
using namespace nfd::tests;
-BOOST_FIXTURE_TEST_SUITE(FwClientControlStrategy, BaseFixture)
+BOOST_AUTO_TEST_SUITE(Fw)
+BOOST_FIXTURE_TEST_SUITE(TestClientControlStrategy, BaseFixture)
BOOST_AUTO_TEST_CASE(Forward3)
{
@@ -65,20 +66,20 @@
shared_ptr<pit::Entry> pitEntry1 = pit.insert(*interest1).first;
pitEntry1->insertOrUpdateInRecord(face4, *interest1);
- strategy.m_sendInterestHistory.clear();
+ strategy.sendInterestHistory.clear();
strategy.afterReceiveInterest(*face4, *interest1, fibEntry, pitEntry1);
- BOOST_REQUIRE_EQUAL(strategy.m_sendInterestHistory.size(), 1);
- BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory[0].get<1>(), face1);
+ BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 1);
+ BOOST_CHECK_EQUAL(strategy.sendInterestHistory[0].outFaceId, face1->getId());
// Interest without NextHopFaceId
shared_ptr<Interest> interest2 = makeInterest("ndn:/y6JQADGVz");
shared_ptr<pit::Entry> pitEntry2 = pit.insert(*interest2).first;
pitEntry2->insertOrUpdateInRecord(face4, *interest2);
- strategy.m_sendInterestHistory.clear();
+ strategy.sendInterestHistory.clear();
strategy.afterReceiveInterest(*face4, *interest2, fibEntry, pitEntry2);
- BOOST_REQUIRE_EQUAL(strategy.m_sendInterestHistory.size(), 1);
- BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory[0].get<1>(), face2);
+ BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 1);
+ BOOST_CHECK_EQUAL(strategy.sendInterestHistory[0].outFaceId, face2->getId());
// Interest with invalid NextHopFaceId
shared_ptr<Interest> interest3 = makeInterest("ndn:/0z8r6yDDe");
@@ -87,14 +88,15 @@
pitEntry3->insertOrUpdateInRecord(face4, *interest3);
face3->close(); // face3 is closed and its FaceId becomes invalid
- strategy.m_sendInterestHistory.clear();
- strategy.m_rejectPendingInterestHistory.clear();
+ strategy.sendInterestHistory.clear();
+ strategy.rejectPendingInterestHistory.clear();
strategy.afterReceiveInterest(*face4, *interest3, fibEntry, pitEntry3);
- BOOST_REQUIRE_EQUAL(strategy.m_sendInterestHistory.size(), 0);
- BOOST_REQUIRE_EQUAL(strategy.m_rejectPendingInterestHistory.size(), 1);
+ BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 0);
+ BOOST_REQUIRE_EQUAL(strategy.rejectPendingInterestHistory.size(), 1);
}
-BOOST_AUTO_TEST_SUITE_END()
+BOOST_AUTO_TEST_SUITE_END() // TestClientControlStrategy
+BOOST_AUTO_TEST_SUITE_END() // Fw
} // namespace tests
} // namespace fw
diff --git a/tests/daemon/fw/dummy-strategy.hpp b/tests/daemon/fw/dummy-strategy.hpp
index d078051..33d2656 100644
--- a/tests/daemon/fw/dummy-strategy.hpp
+++ b/tests/daemon/fw/dummy-strategy.hpp
@@ -33,7 +33,7 @@
/** \brief strategy for unit testing
*
- * Triggers on DummyStrategy are recorded but does nothing
+ * Unless otherwise indicated, triggers are recorded but does nothing.
*/
class DummyStrategy : public fw::Strategy
{
@@ -47,9 +47,13 @@
{
}
+ /** \brief after receive Interest trigger
+ *
+ * If \p interestOutFace is not null, send Interest action is invoked with that face;
+ * otherwise, reject pending Interest action is invoked.
+ */
virtual void
- afterReceiveInterest(const Face& inFace,
- const Interest& interest,
+ afterReceiveInterest(const Face& inFace, const Interest& interest,
shared_ptr<fib::Entry> fibEntry,
shared_ptr<pit::Entry> pitEntry) DECL_OVERRIDE
{
@@ -59,7 +63,7 @@
interest, fibEntry, pitEntry));
}
- if (static_cast<bool>(interestOutFace)) {
+ if (interestOutFace) {
this->sendInterest(pitEntry, interestOutFace);
}
else {
@@ -80,16 +84,25 @@
++beforeExpirePendingInterest_count;
}
+ virtual void
+ afterReceiveNack(const Face& inFace, const lp::Nack& nack,
+ shared_ptr<fib::Entry> fibEntry,
+ shared_ptr<pit::Entry> pitEntry) DECL_OVERRIDE
+ {
+ ++afterReceiveNack_count;
+ }
+
public:
int afterReceiveInterest_count;
bool wantAfterReceiveInterestCalls;
std::vector<std::tuple<FaceId, Interest, shared_ptr<fib::Entry>,
shared_ptr<pit::Entry>>> afterReceiveInterestCalls;
+ shared_ptr<Face> interestOutFace;
+
int beforeSatisfyInterest_count;
int beforeExpirePendingInterest_count;
+ int afterReceiveNack_count;
- /// outFace to use in afterReceiveInterest, nullptr to reject
- shared_ptr<Face> interestOutFace;
};
} // namespace tests
diff --git a/tests/daemon/fw/forwarder.t.cpp b/tests/daemon/fw/forwarder.t.cpp
index d9d50d6..6a3509f 100644
--- a/tests/daemon/fw/forwarder.t.cpp
+++ b/tests/daemon/fw/forwarder.t.cpp
@@ -25,6 +25,8 @@
#include "fw/forwarder.hpp"
#include "tests/daemon/face/dummy-face.hpp"
+#include "tests/daemon/face/dummy-lp-face.hpp"
+#include "face/lp-face-wrapper.hpp"
#include "dummy-strategy.hpp"
#include "tests/test-common.hpp"
@@ -425,6 +427,225 @@
BOOST_CHECK_EQUAL(face4->m_sentDatas.size(), 1);
}
+BOOST_AUTO_TEST_CASE(IncomingNack)
+{
+ Forwarder forwarder;
+ auto face1 = make_shared<DummyFace>();
+ auto face2 = make_shared<DummyFace>();
+ auto face3 = make_shared<face::LpFaceWrapper>(make_unique<DummyLpFace>(
+ "dummy://", "dummy://",
+ ndn::nfd::FACE_SCOPE_NON_LOCAL,
+ ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
+ ndn::nfd::LINK_TYPE_MULTI_ACCESS));
+ forwarder.addFace(face1);
+ forwarder.addFace(face2);
+ forwarder.addFace(face3);
+
+ StrategyChoice& strategyChoice = forwarder.getStrategyChoice();
+ shared_ptr<DummyStrategy> strategyP = make_shared<DummyStrategy>(
+ ref(forwarder), "ndn:/strategyP");
+ shared_ptr<DummyStrategy> strategyQ = make_shared<DummyStrategy>(
+ ref(forwarder), "ndn:/strategyQ");
+ strategyChoice.install(strategyP);
+ strategyChoice.install(strategyQ);
+ strategyChoice.insert("ndn:/" , strategyP->getName());
+ strategyChoice.insert("ndn:/B", strategyQ->getName());
+
+ Pit& pit = forwarder.getPit();
+
+ // dispatch to the correct strategy
+ shared_ptr<Interest> interest1 = makeInterest("/A/AYJqayrzF", 562);
+ shared_ptr<pit::Entry> pit1 = pit.insert(*interest1).first;
+ pit1->insertOrUpdateOutRecord(face1, *interest1);
+ shared_ptr<Interest> interest2 = makeInterest("/B/EVyP73ru", 221);
+ shared_ptr<pit::Entry> pit2 = pit.insert(*interest2).first;
+ pit2->insertOrUpdateOutRecord(face1, *interest2);
+
+ lp::Nack nack1 = makeNack("/A/AYJqayrzF", 562, lp::NackReason::CONGESTION);
+ strategyP->afterReceiveNack_count = 0;
+ strategyQ->afterReceiveNack_count = 0;
+ forwarder.onIncomingNack(*face1, nack1);
+ BOOST_CHECK_EQUAL(strategyP->afterReceiveNack_count, 1);
+ BOOST_CHECK_EQUAL(strategyQ->afterReceiveNack_count, 0);
+
+ lp::Nack nack2 = makeNack("/B/EVyP73ru", 221, lp::NackReason::CONGESTION);
+ strategyP->afterReceiveNack_count = 0;
+ strategyQ->afterReceiveNack_count = 0;
+ forwarder.onIncomingNack(*face1, nack2);
+ BOOST_CHECK_EQUAL(strategyP->afterReceiveNack_count, 0);
+ BOOST_CHECK_EQUAL(strategyQ->afterReceiveNack_count, 1);
+
+ // record Nack on PIT out-record
+ pit::OutRecordCollection::const_iterator outRecord1 = pit1->getOutRecord(*face1);
+ BOOST_REQUIRE(outRecord1 != pit1->getOutRecords().end());
+ BOOST_REQUIRE(outRecord1->getIncomingNack() != nullptr);
+ BOOST_CHECK_EQUAL(outRecord1->getIncomingNack()->getReason(), lp::NackReason::CONGESTION);
+
+ // drop if no PIT entry
+ lp::Nack nack3 = makeNack("/yEcw5HhdM", 243, lp::NackReason::CONGESTION);
+ strategyP->afterReceiveNack_count = 0;
+ strategyQ->afterReceiveNack_count = 0;
+ forwarder.onIncomingNack(*face1, nack3);
+ BOOST_CHECK_EQUAL(strategyP->afterReceiveNack_count, 0);
+ BOOST_CHECK_EQUAL(strategyQ->afterReceiveNack_count, 0);
+
+ // drop if no out-record
+ shared_ptr<Interest> interest4 = makeInterest("/Etab4KpY", 157);
+ shared_ptr<pit::Entry> pit4 = pit.insert(*interest4).first;
+ pit4->insertOrUpdateOutRecord(face1, *interest4);
+
+ lp::Nack nack4a = makeNack("/Etab4KpY", 157, lp::NackReason::CONGESTION);
+ strategyP->afterReceiveNack_count = 0;
+ strategyQ->afterReceiveNack_count = 0;
+ forwarder.onIncomingNack(*face2, nack4a);
+ BOOST_CHECK_EQUAL(strategyP->afterReceiveNack_count, 0);
+ BOOST_CHECK_EQUAL(strategyQ->afterReceiveNack_count, 0);
+
+ // drop if Nonce does not match out-record
+ lp::Nack nack4b = makeNack("/Etab4KpY", 294, lp::NackReason::CONGESTION);
+ strategyP->afterReceiveNack_count = 0;
+ strategyQ->afterReceiveNack_count = 0;
+ forwarder.onIncomingNack(*face1, nack4b);
+ BOOST_CHECK_EQUAL(strategyP->afterReceiveNack_count, 0);
+ BOOST_CHECK_EQUAL(strategyQ->afterReceiveNack_count, 0);
+
+ // drop if inFace is multi-access
+ pit4->insertOrUpdateOutRecord(face3, *interest4);
+ strategyP->afterReceiveNack_count = 0;
+ strategyQ->afterReceiveNack_count = 0;
+ forwarder.onIncomingNack(*face3, nack4a);
+ BOOST_CHECK_EQUAL(strategyP->afterReceiveNack_count, 0);
+ BOOST_CHECK_EQUAL(strategyQ->afterReceiveNack_count, 0);
+}
+
+BOOST_AUTO_TEST_CASE(OutgoingNack)
+{
+ Forwarder forwarder;
+ auto face1w = make_shared<face::LpFaceWrapper>(make_unique<DummyLpFace>());
+ auto face1 = static_cast<DummyLpFace*>(face1w->getLpFace());
+ auto face2w = make_shared<face::LpFaceWrapper>(make_unique<DummyLpFace>());
+ auto face2 = static_cast<DummyLpFace*>(face2w->getLpFace());
+ auto face3w = make_shared<face::LpFaceWrapper>(make_unique<DummyLpFace>(
+ "dummy://", "dummy://",
+ ndn::nfd::FACE_SCOPE_NON_LOCAL,
+ ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
+ ndn::nfd::LINK_TYPE_MULTI_ACCESS));
+ auto face3 = static_cast<DummyLpFace*>(face3w->getLpFace());
+ forwarder.addFace(face1w);
+ forwarder.addFace(face2w);
+ forwarder.addFace(face3w);
+ // TODO#3172 eliminate wrapper
+
+ Pit& pit = forwarder.getPit();
+
+ lp::NackHeader nackHeader;
+ nackHeader.setReason(lp::NackReason::CONGESTION);
+
+ // don't send Nack if there's no in-record
+ shared_ptr<Interest> interest1 = makeInterest("/fM5IVEtC", 719);
+ shared_ptr<pit::Entry> pit1 = pit.insert(*interest1).first;
+ pit1->insertOrUpdateInRecord(face1w, *interest1);
+
+ face2->sentNacks.clear();
+ forwarder.onOutgoingNack(pit1, *face2w, nackHeader);
+ BOOST_CHECK_EQUAL(face2->sentNacks.size(), 0);
+
+ // send Nack with correct Nonce
+ shared_ptr<Interest> interest2a = makeInterest("/Vi8tRm9MG3", 152);
+ shared_ptr<pit::Entry> pit2 = pit.insert(*interest2a).first;
+ pit2->insertOrUpdateInRecord(face1w, *interest2a);
+ shared_ptr<Interest> interest2b = makeInterest("/Vi8tRm9MG3", 808);
+ pit2->insertOrUpdateInRecord(face2w, *interest2b);
+
+ face1->sentNacks.clear();
+ forwarder.onOutgoingNack(pit2, *face1w, nackHeader);
+ BOOST_REQUIRE_EQUAL(face1->sentNacks.size(), 1);
+ BOOST_CHECK_EQUAL(face1->sentNacks.back().getReason(), lp::NackReason::CONGESTION);
+ BOOST_CHECK_EQUAL(face1->sentNacks.back().getInterest().getNonce(), 152);
+
+ // erase in-record
+ pit::InRecordCollection::const_iterator inRecord2a = pit2->getInRecord(*face1w);
+ BOOST_CHECK(inRecord2a == pit2->getInRecords().end());
+
+ // send Nack with correct Nonce
+ face2->sentNacks.clear();
+ forwarder.onOutgoingNack(pit2, *face2w, nackHeader);
+ BOOST_REQUIRE_EQUAL(face2->sentNacks.size(), 1);
+ BOOST_CHECK_EQUAL(face2->sentNacks.back().getReason(), lp::NackReason::CONGESTION);
+ BOOST_CHECK_EQUAL(face2->sentNacks.back().getInterest().getNonce(), 808);
+
+ // erase in-record
+ pit::InRecordCollection::const_iterator inRecord2b = pit2->getInRecord(*face1w);
+ BOOST_CHECK(inRecord2b == pit2->getInRecords().end());
+
+ // don't send Nack to multi-access face
+ shared_ptr<Interest> interest2c = makeInterest("/Vi8tRm9MG3", 228);
+ pit2->insertOrUpdateInRecord(face3w, *interest2c);
+
+ face3->sentNacks.clear();
+ forwarder.onOutgoingNack(pit1, *face3w, nackHeader);
+ BOOST_CHECK_EQUAL(face3->sentNacks.size(), 0);
+}
+
+BOOST_AUTO_TEST_CASE(InterestLoopNack)
+{
+ Forwarder forwarder;
+ auto face1w = make_shared<face::LpFaceWrapper>(make_unique<DummyLpFace>());
+ auto face1 = static_cast<DummyLpFace*>(face1w->getLpFace());
+ auto face2w = make_shared<face::LpFaceWrapper>(make_unique<DummyLpFace>());
+ auto face2 = static_cast<DummyLpFace*>(face2w->getLpFace());
+ auto face3w = make_shared<face::LpFaceWrapper>(make_unique<DummyLpFace>(
+ "dummy://", "dummy://",
+ ndn::nfd::FACE_SCOPE_NON_LOCAL,
+ ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
+ ndn::nfd::LINK_TYPE_MULTI_ACCESS));
+ auto face3 = static_cast<DummyLpFace*>(face3w->getLpFace());
+ auto face4 = make_shared<DummyFace>();
+ forwarder.addFace(face1w);
+ forwarder.addFace(face2w);
+ forwarder.addFace(face3w);
+ forwarder.addFace(face4);
+ // TODO#3172 eliminate wrapper
+
+ Fib& fib = forwarder.getFib();
+ shared_ptr<fib::Entry> fibEntry = fib.insert(Name("/zT4XwK0Hnx")).first;
+ fibEntry->addNextHop(face4, 0);
+
+ // receive Interest on face1
+ face1->sentNacks.clear();
+ shared_ptr<Interest> interest1a = makeInterest("/zT4XwK0Hnx/28JBUvbEzc", 732);
+ face1->receiveInterest(*interest1a);
+ BOOST_CHECK(face1->sentNacks.empty());
+
+ // receive Interest with duplicate Nonce on face1
+ face1->sentNacks.clear();
+ shared_ptr<Interest> interest1b = makeInterest("/zT4XwK0Hnx/28JBUvbEzc", 732);
+ face1->receiveInterest(*interest1b);
+ BOOST_REQUIRE_EQUAL(face1->sentNacks.size(), 1);
+ BOOST_CHECK_EQUAL(face1->sentNacks.back().getInterest(), *interest1b);
+ BOOST_CHECK_EQUAL(face1->sentNacks.back().getReason(), lp::NackReason::DUPLICATE);
+
+ // receive Interest with duplicate Nonce on face2
+ face2->sentNacks.clear();
+ shared_ptr<Interest> interest2a = makeInterest("/zT4XwK0Hnx/28JBUvbEzc", 732);
+ face2->receiveInterest(*interest2a);
+ BOOST_REQUIRE_EQUAL(face2->sentNacks.size(), 1);
+ BOOST_CHECK_EQUAL(face2->sentNacks.back().getInterest(), *interest2a);
+ BOOST_CHECK_EQUAL(face2->sentNacks.back().getReason(), lp::NackReason::DUPLICATE);
+
+ // receive Interest with new Nonce on face2
+ face2->sentNacks.clear();
+ shared_ptr<Interest> interest2b = makeInterest("/zT4XwK0Hnx/28JBUvbEzc", 944);
+ face2->receiveInterest(*interest2b);
+ BOOST_CHECK(face2->sentNacks.empty());
+
+ // receive Interest with duplicate Nonce on face3, don't send Nack to multi-access face
+ face3->sentNacks.clear();
+ shared_ptr<Interest> interest3a = makeInterest("/zT4XwK0Hnx/28JBUvbEzc", 732);
+ face3->receiveInterest(*interest3a);
+ BOOST_CHECK(face3->sentNacks.empty());
+}
+
BOOST_FIXTURE_TEST_CASE(InterestLoopWithShortLifetime, UnitTestTimeFixture) // Bug 1953
{
Forwarder forwarder;
diff --git a/tests/daemon/fw/multicast-strategy.t.cpp b/tests/daemon/fw/multicast-strategy.t.cpp
index c67c408..3476cd3 100644
--- a/tests/daemon/fw/multicast-strategy.t.cpp
+++ b/tests/daemon/fw/multicast-strategy.t.cpp
@@ -35,7 +35,8 @@
using namespace nfd::tests;
-BOOST_FIXTURE_TEST_SUITE(FwMulticastStrategy, BaseFixture)
+BOOST_AUTO_TEST_SUITE(Fw)
+BOOST_FIXTURE_TEST_SUITE(TestMulticastStrategy, BaseFixture)
BOOST_AUTO_TEST_CASE(Forward2)
{
@@ -62,21 +63,17 @@
pitEntry->insertOrUpdateInRecord(face3, *interest);
strategy.afterReceiveInterest(*face3, *interest, fibEntry, pitEntry);
- BOOST_CHECK_EQUAL(strategy.m_rejectPendingInterestHistory.size(), 0);
- BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.size(), 2);
- bool hasFace1 = false;
- bool hasFace2 = false;
- for (std::vector<MulticastStrategyTester::SendInterestArgs>::iterator it =
- strategy.m_sendInterestHistory.begin();
- it != strategy.m_sendInterestHistory.end(); ++it) {
- if (it->get<1>() == face1) {
- hasFace1 = true;
- }
- if (it->get<1>() == face2) {
- hasFace2 = true;
- }
- }
- BOOST_CHECK(hasFace1 && hasFace2);
+ BOOST_CHECK_EQUAL(strategy.rejectPendingInterestHistory.size(), 0);
+ BOOST_CHECK_EQUAL(strategy.sendInterestHistory.size(), 2);
+ std::set<FaceId> sentInterestFaceIds;
+ std::transform(strategy.sendInterestHistory.begin(), strategy.sendInterestHistory.end(),
+ std::inserter(sentInterestFaceIds, sentInterestFaceIds.end()),
+ [] (const MulticastStrategyTester::SendInterestArgs& args) {
+ return args.outFaceId;
+ });
+ std::set<FaceId> expectedInterestFaceIds{face1->getId(), face2->getId()};
+ BOOST_CHECK_EQUAL_COLLECTIONS(sentInterestFaceIds.begin(), sentInterestFaceIds.end(),
+ expectedInterestFaceIds.begin(), expectedInterestFaceIds.end());
}
BOOST_AUTO_TEST_CASE(RejectScope)
@@ -100,8 +97,8 @@
pitEntry->insertOrUpdateInRecord(face1, *interest);
strategy.afterReceiveInterest(*face1, *interest, fibEntry, pitEntry);
- BOOST_CHECK_EQUAL(strategy.m_rejectPendingInterestHistory.size(), 1);
- BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.size(), 0);
+ BOOST_CHECK_EQUAL(strategy.rejectPendingInterestHistory.size(), 1);
+ BOOST_CHECK_EQUAL(strategy.sendInterestHistory.size(), 0);
}
BOOST_AUTO_TEST_CASE(RejectLoopback)
@@ -123,11 +120,12 @@
pitEntry->insertOrUpdateInRecord(face1, *interest);
strategy.afterReceiveInterest(*face1, *interest, fibEntry, pitEntry);
- BOOST_CHECK_EQUAL(strategy.m_rejectPendingInterestHistory.size(), 1);
- BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.size(), 0);
+ BOOST_CHECK_EQUAL(strategy.rejectPendingInterestHistory.size(), 1);
+ BOOST_CHECK_EQUAL(strategy.sendInterestHistory.size(), 0);
}
-BOOST_AUTO_TEST_SUITE_END()
+BOOST_AUTO_TEST_SUITE_END() // TestMulticastStrategy
+BOOST_AUTO_TEST_SUITE_END() // Fw
} // namespace tests
} // namespace fw
diff --git a/tests/daemon/fw/ncc-strategy.t.cpp b/tests/daemon/fw/ncc-strategy.t.cpp
index a10fc47..889b2e2 100644
--- a/tests/daemon/fw/ncc-strategy.t.cpp
+++ b/tests/daemon/fw/ncc-strategy.t.cpp
@@ -36,7 +36,8 @@
using namespace nfd::tests;
-BOOST_FIXTURE_TEST_SUITE(FwNccStrategy, UnitTestTimeFixture)
+BOOST_AUTO_TEST_SUITE(Fw)
+BOOST_FIXTURE_TEST_SUITE(TestNccStrategy, UnitTestTimeFixture)
// NccStrategy is fairly complex.
// The most important property is:
@@ -48,7 +49,7 @@
Forwarder forwarder;
typedef StrategyTester<fw::NccStrategy> NccStrategyTester;
shared_ptr<NccStrategyTester> strategy = make_shared<NccStrategyTester>(ref(forwarder));
- strategy->onAction.connect(bind(&LimitedIo::afterOp, &limitedIo));
+ strategy->afterAction.connect(bind(&LimitedIo::afterOp, &limitedIo));
shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
@@ -79,13 +80,13 @@
// forwards to face1 because routing says it's best
// (no io run here: afterReceiveInterest has already sent the Interest)
- BOOST_REQUIRE_EQUAL(strategy->m_sendInterestHistory.size(), 1);
- BOOST_CHECK_EQUAL(strategy->m_sendInterestHistory[0].get<1>(), face1);
+ BOOST_REQUIRE_EQUAL(strategy->sendInterestHistory.size(), 1);
+ BOOST_CHECK_EQUAL(strategy->sendInterestHistory[0].outFaceId, face1->getId());
// forwards to face2 because face1 doesn't respond
limitedIo.run(1, time::milliseconds(500), time::milliseconds(10));
- BOOST_REQUIRE_EQUAL(strategy->m_sendInterestHistory.size(), 2);
- BOOST_CHECK_EQUAL(strategy->m_sendInterestHistory[1].get<1>(), face2);
+ BOOST_REQUIRE_EQUAL(strategy->sendInterestHistory.size(), 2);
+ BOOST_CHECK_EQUAL(strategy->sendInterestHistory[1].outFaceId, face2->getId());
// face2 responds
shared_ptr<Data> data1p = makeData("ndn:/0Jm1ajrW/%00");
@@ -104,8 +105,8 @@
// forwards to face2 because it responds previously
this->advanceClocks(time::milliseconds(1));
- BOOST_REQUIRE_GE(strategy->m_sendInterestHistory.size(), 3);
- BOOST_CHECK_EQUAL(strategy->m_sendInterestHistory[2].get<1>(), face2);
+ BOOST_REQUIRE_GE(strategy->sendInterestHistory.size(), 3);
+ BOOST_CHECK_EQUAL(strategy->sendInterestHistory[2].outFaceId, face2->getId());
}
BOOST_AUTO_TEST_CASE(Bug1853)
@@ -140,8 +141,8 @@
strategy->afterReceiveInterest(*face3, *interest1, fibEntry, pitEntry1);
this->advanceClocks(time::milliseconds(1));
- BOOST_REQUIRE_EQUAL(strategy->m_sendInterestHistory.size(), 1);
- BOOST_CHECK_EQUAL(strategy->m_sendInterestHistory[0].get<1>(), face1);
+ BOOST_REQUIRE_EQUAL(strategy->sendInterestHistory.size(), 1);
+ BOOST_CHECK_EQUAL(strategy->sendInterestHistory[0].outFaceId, face1->getId());
// face1 responds
shared_ptr<Data> data1 = makeData("ndn:/nztwIvHX/%00");
@@ -168,7 +169,7 @@
Forwarder forwarder;
typedef StrategyTester<fw::NccStrategy> NccStrategyTester;
shared_ptr<NccStrategyTester> strategy = make_shared<NccStrategyTester>(ref(forwarder));
- strategy->onAction.connect(bind(&LimitedIo::afterOp, &limitedIo));
+ strategy->afterAction.connect(bind(&LimitedIo::afterOp, &limitedIo));
shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
@@ -195,11 +196,11 @@
pitEntry1->insertOrUpdateInRecord(face3, *interest1);
strategy->afterReceiveInterest(*face3, *interest1, fibEntry, pitEntry1);
- limitedIo.run(2 - strategy->m_sendInterestHistory.size(),
+ limitedIo.run(2 - strategy->sendInterestHistory.size(),
time::milliseconds(2000), time::milliseconds(10));
- BOOST_REQUIRE_EQUAL(strategy->m_sendInterestHistory.size(), 2);
- BOOST_CHECK_EQUAL(strategy->m_sendInterestHistory[0].get<1>(), face1);
- BOOST_CHECK_EQUAL(strategy->m_sendInterestHistory[1].get<1>(), face2);
+ BOOST_REQUIRE_EQUAL(strategy->sendInterestHistory.size(), 2);
+ BOOST_CHECK_EQUAL(strategy->sendInterestHistory[0].outFaceId, face1->getId());
+ BOOST_CHECK_EQUAL(strategy->sendInterestHistory[1].outFaceId, face2->getId());
// face1 responds
shared_ptr<Data> data1 = makeData("ndn:/seRMz5a6/%00");
@@ -217,11 +218,11 @@
pitEntry2->insertOrUpdateInRecord(face3, *interest2);
strategy->afterReceiveInterest(*face3, *interest2, fibEntry, pitEntry2);
- limitedIo.run(3 - strategy->m_sendInterestHistory.size(),
+ limitedIo.run(3 - strategy->sendInterestHistory.size(),
time::milliseconds(2000), time::milliseconds(10));
- BOOST_REQUIRE_GE(strategy->m_sendInterestHistory.size(), 3);
- BOOST_CHECK_EQUAL(strategy->m_sendInterestHistory[2].get<1>(), face1);
+ BOOST_REQUIRE_GE(strategy->sendInterestHistory.size(), 3);
+ BOOST_CHECK_EQUAL(strategy->sendInterestHistory[2].outFaceId, face1->getId());
}
BOOST_AUTO_TEST_CASE(Bug1971)
@@ -230,7 +231,7 @@
Forwarder forwarder;
typedef StrategyTester<fw::NccStrategy> NccStrategyTester;
shared_ptr<NccStrategyTester> strategy = make_shared<NccStrategyTester>(ref(forwarder));
- strategy->onAction.connect(bind(&LimitedIo::afterOp, &limitedIo));
+ strategy->afterAction.connect(bind(&LimitedIo::afterOp, &limitedIo));
shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
@@ -254,10 +255,10 @@
pitEntry1->insertOrUpdateInRecord(face1, *interest1);
strategy->afterReceiveInterest(*face1, *interest1, fibEntry, pitEntry1);
- limitedIo.run(1 - strategy->m_sendInterestHistory.size(),
+ limitedIo.run(1 - strategy->sendInterestHistory.size(),
time::milliseconds(2000), time::milliseconds(10));
- BOOST_REQUIRE_EQUAL(strategy->m_sendInterestHistory.size(), 1);
- BOOST_CHECK_EQUAL(strategy->m_sendInterestHistory[0].get<1>(), face2);
+ BOOST_REQUIRE_EQUAL(strategy->sendInterestHistory.size(), 1);
+ BOOST_CHECK_EQUAL(strategy->sendInterestHistory[0].outFaceId, face2->getId());
// face2 responds
shared_ptr<Data> data1 = makeData("ndn:/M4mBXCsd");
@@ -270,10 +271,10 @@
// similar Interest: strategy should still forward it
pitEntry1->insertOrUpdateInRecord(face1, *interest1);
strategy->afterReceiveInterest(*face1, *interest1, fibEntry, pitEntry1);
- limitedIo.run(2 - strategy->m_sendInterestHistory.size(),
+ limitedIo.run(2 - strategy->sendInterestHistory.size(),
time::milliseconds(2000), time::milliseconds(10));
- BOOST_REQUIRE_EQUAL(strategy->m_sendInterestHistory.size(), 2);
- BOOST_CHECK_EQUAL(strategy->m_sendInterestHistory[1].get<1>(), face2);
+ BOOST_REQUIRE_EQUAL(strategy->sendInterestHistory.size(), 2);
+ BOOST_CHECK_EQUAL(strategy->sendInterestHistory[1].outFaceId, face2->getId());
}
BOOST_AUTO_TEST_CASE(Bug1998)
@@ -306,11 +307,12 @@
strategy->afterReceiveInterest(*face1, *interest1, fibEntry, pitEntry1);
// Interest shall go to face2, not loop back to face1
- BOOST_REQUIRE_EQUAL(strategy->m_sendInterestHistory.size(), 1);
- BOOST_CHECK_EQUAL(strategy->m_sendInterestHistory[0].get<1>(), face2);
+ BOOST_REQUIRE_EQUAL(strategy->sendInterestHistory.size(), 1);
+ BOOST_CHECK_EQUAL(strategy->sendInterestHistory[0].outFaceId, face2->getId());
}
-BOOST_AUTO_TEST_SUITE_END()
+BOOST_AUTO_TEST_SUITE_END() // TestNccStrategy
+BOOST_AUTO_TEST_SUITE_END() // Fw
} // namespace tests
} // namespace fw
diff --git a/tests/daemon/fw/retx-suppression.t.cpp b/tests/daemon/fw/retx-suppression.t.cpp
index 2d1b146..266f168 100644
--- a/tests/daemon/fw/retx-suppression.t.cpp
+++ b/tests/daemon/fw/retx-suppression.t.cpp
@@ -26,7 +26,6 @@
#include "fw/retx-suppression.hpp"
#include "fw/retx-suppression-fixed.hpp"
#include "fw/retx-suppression-exponential.hpp"
-#include "strategy-tester.hpp"
#include "tests/test-common.hpp"
#include "tests/daemon/face/dummy-face.hpp"
diff --git a/tests/daemon/fw/strategy-tester.hpp b/tests/daemon/fw/strategy-tester.hpp
index 9cf4855..26c29c1 100644
--- a/tests/daemon/fw/strategy-tester.hpp
+++ b/tests/daemon/fw/strategy-tester.hpp
@@ -33,8 +33,7 @@
namespace fw {
namespace tests {
-/** \class StrategyTester
- * \brief extends strategy S for unit testing
+/** \brief extends strategy S for unit testing
*
* Actions invoked by S are recorded but not passed to forwarder
*/
@@ -49,7 +48,7 @@
}
/// fires after each Action
- signal::Signal<StrategyTester<S>> onAction;
+ signal::Signal<StrategyTester<S>> afterAction;
protected:
virtual void
@@ -60,12 +59,32 @@
virtual void
rejectPendingInterest(shared_ptr<pit::Entry> pitEntry) DECL_OVERRIDE;
-public:
- typedef boost::tuple<shared_ptr<pit::Entry>, shared_ptr<Face>> SendInterestArgs;
- std::vector<SendInterestArgs> m_sendInterestHistory;
+ virtual void
+ sendNack(shared_ptr<pit::Entry> pitEntry, const Face& outFace,
+ const lp::NackHeader& header) DECL_OVERRIDE;
- typedef boost::tuple<shared_ptr<pit::Entry>> RejectPendingInterestArgs;
- std::vector<RejectPendingInterestArgs> m_rejectPendingInterestHistory;
+public:
+ struct SendInterestArgs
+ {
+ shared_ptr<pit::Entry> pitEntry;
+ FaceId outFaceId;
+ bool wantNewNonce;
+ };
+ std::vector<SendInterestArgs> sendInterestHistory;
+
+ struct RejectPendingInterestArgs
+ {
+ shared_ptr<pit::Entry> pitEntry;
+ };
+ std::vector<RejectPendingInterestArgs> rejectPendingInterestHistory;
+
+ struct SendNackArgs
+ {
+ shared_ptr<pit::Entry> pitEntry;
+ FaceId outFaceId;
+ lp::NackHeader header;
+ };
+ std::vector<SendNackArgs> sendNackHistory;
};
@@ -75,17 +94,30 @@
shared_ptr<Face> outFace,
bool wantNewNonce)
{
- m_sendInterestHistory.push_back(SendInterestArgs(pitEntry, outFace));
+ SendInterestArgs args{pitEntry, outFace->getId()};
+ sendInterestHistory.push_back(args);
pitEntry->insertOrUpdateOutRecord(outFace, pitEntry->getInterest());
- onAction();
+ afterAction();
}
template<typename S>
inline void
StrategyTester<S>::rejectPendingInterest(shared_ptr<pit::Entry> pitEntry)
{
- m_rejectPendingInterestHistory.push_back(RejectPendingInterestArgs(pitEntry));
- onAction();
+ RejectPendingInterestArgs args{pitEntry};
+ rejectPendingInterestHistory.push_back(args);
+ afterAction();
+}
+
+template<typename S>
+inline void
+StrategyTester<S>::sendNack(shared_ptr<pit::Entry> pitEntry, const Face& outFace,
+ const lp::NackHeader& header)
+{
+ SendNackArgs args{pitEntry, outFace.getId(), header};
+ sendNackHistory.push_back(args);
+ pitEntry->deleteInRecord(outFace);
+ afterAction();
}
} // namespace tests
diff --git a/tests/daemon/fw/topology-tester.cpp b/tests/daemon/fw/topology-tester.cpp
new file mode 100644
index 0000000..10a0b31
--- /dev/null
+++ b/tests/daemon/fw/topology-tester.cpp
@@ -0,0 +1,260 @@
+/* -*- 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 "topology-tester.hpp"
+#include <ndn-cxx/encoding/encoding-buffer-fwd.hpp>
+#include "face/generic-link-service.hpp"
+
+namespace nfd {
+namespace fw {
+namespace tests {
+
+using face::LpFaceWrapper;
+
+TopologyForwarderTransport::TopologyForwarderTransport(
+ const FaceUri& localUri, const FaceUri& remoteUri,
+ ndn::nfd::FaceScope scope, ndn::nfd::LinkType linkType)
+{
+ this->setLocalUri(localUri);
+ this->setRemoteUri(remoteUri);
+ this->setScope(scope);
+ this->setPersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT);
+ this->setLinkType(linkType);
+}
+
+void
+TopologyForwarderTransport::receiveFromTopology(const Block& packet)
+{
+ Packet p;
+ p.packet = packet;
+ this->receive(std::move(p));
+}
+
+void
+TopologyForwarderTransport::doSend(Packet&& packet)
+{
+ this->emitSignal(afterSend, packet.packet);
+}
+
+void
+TopologyClientTransport::receiveFromTopology(const Block& packet)
+{
+ if (m_receiveCallback) {
+ m_receiveCallback(packet);
+ }
+}
+
+void
+TopologyClientTransport::send(const Block& wire)
+{
+ this->emitSignal(afterSend, wire);
+}
+
+void
+TopologyClientTransport::send(const Block& header, const Block& payload)
+{
+ ndn::EncodingBuffer encoder(header.size() + payload.size(), header.size() + payload.size());
+ encoder.appendByteArray(header.wire(), header.size());
+ encoder.appendByteArray(payload.wire(), payload.size());
+
+ this->send(encoder.block());
+}
+
+TopologyLinkBase::TopologyLinkBase()
+ : m_isUp(true)
+{
+}
+
+void
+TopologyLinkBase::attachTransport(TopologyNode i, TopologyTransportBase* transport)
+{
+ BOOST_ASSERT(transport != nullptr);
+ BOOST_ASSERT(m_transports.count(i) == 0);
+
+ m_transports[i] = transport;
+ transport->afterSend.connect([this, i] (const Block& packet) { this->transmit(i, packet); });
+}
+
+void
+TopologyLinkBase::transmit(TopologyNode i, const Block& packet)
+{
+ if (!m_isUp) {
+ return;
+ }
+
+ for (auto&& p : m_transports) {
+ if (p.first == i) {
+ continue;
+ }
+
+ TopologyTransportBase* recipient = p.second;
+ this->scheduleReceive(recipient, packet);
+ }
+}
+
+TopologyLink::TopologyLink(const time::nanoseconds& delay)
+ : m_delay(delay)
+{
+ BOOST_ASSERT(delay > time::nanoseconds::zero());
+ // zero delay does not work on OSX
+}
+
+void
+TopologyLink::addFace(TopologyNode i, shared_ptr<LpFaceWrapper> face)
+{
+ this->attachTransport(i, dynamic_cast<TopologyTransportBase*>(face->getLpFace()->getTransport()));
+ m_faces[i] = face;
+}
+
+void
+TopologyLink::scheduleReceive(TopologyTransportBase* recipient, const Block& packet)
+{
+ scheduler::schedule(m_delay, [packet, recipient] {
+ recipient->receiveFromTopology(packet);
+ });
+}
+
+TopologyAppLink::TopologyAppLink(shared_ptr<LpFaceWrapper> face)
+ : m_face(face)
+{
+ this->attachTransport(0, dynamic_cast<TopologyTransportBase*>(face->getLpFace()->getTransport()));
+
+ auto clientTransport = make_shared<TopologyClientTransport>();
+ m_client = make_shared<ndn::Face>(clientTransport, getGlobalIoService());
+ this->attachTransport(1, clientTransport.get());
+}
+
+void
+TopologyAppLink::scheduleReceive(TopologyTransportBase* recipient, const Block& packet)
+{
+ getGlobalIoService().post([packet, recipient] {
+ recipient->receiveFromTopology(packet);
+ });
+}
+
+TopologyNode
+TopologyTester::addForwarder(const std::string& label)
+{
+ size_t i = m_forwarders.size();
+ m_forwarders.push_back(std::move(make_unique<Forwarder>()));
+ m_forwarderLabels.push_back(label);
+ BOOST_ASSERT(m_forwarders.size() == m_forwarderLabels.size());
+ return i;
+}
+
+shared_ptr<TopologyLink>
+TopologyTester::addLink(const std::string& label, const time::nanoseconds& delay,
+ std::initializer_list<TopologyNode> forwarders,
+ bool forceMultiAccessFace)
+{
+ auto link = make_shared<TopologyLink>(delay);
+ FaceUri remoteUri("topology://link/" + label);
+ ndn::nfd::LinkType linkType = (forceMultiAccessFace || forwarders.size() > 2) ?
+ ndn::nfd::LINK_TYPE_MULTI_ACCESS :
+ ndn::nfd::LINK_TYPE_POINT_TO_POINT;
+
+ for (TopologyNode i : forwarders) {
+ Forwarder& forwarder = this->getForwarder(i);
+ FaceUri localUri("topology://" + m_forwarderLabels.at(i) + "/" + label);
+
+ auto service = make_unique<face::GenericLinkService>();
+ auto transport = make_unique<TopologyForwarderTransport>(localUri, remoteUri,
+ ndn::nfd::FACE_SCOPE_NON_LOCAL, linkType);
+ auto face = make_unique<LpFace>(std::move(service), std::move(transport));
+ auto faceW = make_shared<LpFaceWrapper>(std::move(face));
+
+ forwarder.addFace(faceW);
+ link->addFace(i, faceW);
+ }
+
+ m_links.push_back(link); // keep a shared_ptr so callers don't have to
+ return link;
+}
+
+shared_ptr<TopologyAppLink>
+TopologyTester::addAppFace(const std::string& label, TopologyNode i)
+{
+ Forwarder& forwarder = this->getForwarder(i);
+ FaceUri localUri("topology://" + m_forwarderLabels.at(i) + "/local/" + label);
+ FaceUri remoteUri("topology://" + m_forwarderLabels.at(i) + "/app/" + label);
+
+ auto service = make_unique<face::GenericLinkService>();
+ auto transport = make_unique<TopologyForwarderTransport>(localUri, remoteUri,
+ ndn::nfd::FACE_SCOPE_LOCAL, ndn::nfd::LINK_TYPE_POINT_TO_POINT);
+ auto face = make_unique<LpFace>(std::move(service), std::move(transport));
+ auto faceW = make_shared<LpFaceWrapper>(std::move(face));
+
+ forwarder.addFace(faceW);
+
+ auto al = make_shared<TopologyAppLink>(faceW);
+ m_appLinks.push_back(al); // keep a shared_ptr so callers don't have to
+ return al;
+}
+
+shared_ptr<TopologyAppLink>
+TopologyTester::addAppFace(const std::string& label, TopologyNode i, const Name& prefix, uint64_t cost)
+{
+ shared_ptr<TopologyAppLink> al = this->addAppFace(label, i);
+ this->registerPrefix(i, al->getForwarderFace(), prefix, cost);
+ return al;
+}
+
+void
+TopologyTester::registerPrefix(TopologyNode i, const Face& face, const Name& prefix, uint64_t cost)
+{
+ Forwarder& forwarder = this->getForwarder(i);
+ Fib& fib = forwarder.getFib();
+ shared_ptr<fib::Entry> fibEntry = fib.insert(prefix).first;
+ fibEntry->addNextHop(const_cast<Face&>(face).shared_from_this(), cost);
+}
+
+void
+TopologyTester::addEchoProducer(ndn::Face& face, const Name& prefix)
+{
+ face.setInterestFilter(prefix,
+ [&face] (const ndn::InterestFilter&, const Interest& interest) {
+ shared_ptr<Data> data = makeData(interest.getName());
+ face.put(*data);
+ });
+}
+
+void
+TopologyTester::addIntervalConsumer(ndn::Face& face, const Name& prefix,
+ const time::nanoseconds& interval, size_t n)
+{
+ Name name(prefix);
+ name.appendTimestamp();
+ shared_ptr<Interest> interest = makeInterest(name);
+ face.expressInterest(*interest, bind([]{}));
+
+ if (n > 1) {
+ scheduler::schedule(interval, bind(&TopologyTester::addIntervalConsumer, this,
+ ref(face), prefix, interval, n - 1));
+ }
+}
+
+} // namespace tests
+} // namespace fw
+} // namespace nfd
diff --git a/tests/daemon/fw/topology-tester.hpp b/tests/daemon/fw/topology-tester.hpp
index 406c6b1..dd6d77d 100644
--- a/tests/daemon/fw/topology-tester.hpp
+++ b/tests/daemon/fw/topology-tester.hpp
@@ -30,19 +30,86 @@
#ifndef NFD_TESTS_NFD_FW_TOPOLOGY_TESTER_HPP
#define NFD_TESTS_NFD_FW_TOPOLOGY_TESTER_HPP
-#include <unordered_map>
-#include <ndn-cxx/util/dummy-client-face.hpp>
+#include <ndn-cxx/face.hpp>
+#include <ndn-cxx/transport/transport.hpp>
+#include "face/lp-face-wrapper.hpp"
#include "fw/strategy.hpp"
#include "tests/test-common.hpp"
-#include "../face/dummy-face.hpp"
namespace nfd {
namespace fw {
namespace tests {
-using ndn::util::DummyClientFace;
using namespace nfd::tests;
+/** \brief abstracts a Transport used in TopologyTester
+ */
+class TopologyTransportBase
+{
+public:
+ /** \brief causes the transport to receive a link-layer packet
+ */
+ virtual void
+ receiveFromTopology(const Block& packet) = 0;
+
+ signal::Signal<TopologyTransportBase, Block> afterSend;
+
+protected:
+ DECLARE_SIGNAL_EMIT(afterSend)
+};
+
+/** \brief implements a forwarder-side Transport used in TopologyTester
+ */
+class TopologyForwarderTransport : public face::Transport, public TopologyTransportBase
+{
+public:
+ TopologyForwarderTransport(const FaceUri& localUri, const FaceUri& remoteUri,
+ ndn::nfd::FaceScope scope, ndn::nfd::LinkType linkType);
+
+ virtual void
+ receiveFromTopology(const Block& packet) DECL_OVERRIDE;
+
+protected:
+ virtual void
+ doClose() DECL_OVERRIDE
+ {
+ }
+
+private:
+ virtual void
+ doSend(Packet&& packet) DECL_OVERRIDE;
+};
+
+/** \brief implements a client-side Transport used in TopologyTester
+ */
+class TopologyClientTransport : public ndn::Transport, public TopologyTransportBase
+{
+public:
+ virtual void
+ receiveFromTopology(const Block& packet) DECL_OVERRIDE;
+
+ virtual void
+ close() DECL_OVERRIDE
+ {
+ }
+
+ virtual void
+ pause() DECL_OVERRIDE
+ {
+ }
+
+ virtual void
+ resume() DECL_OVERRIDE
+ {
+ }
+
+ virtual void
+ send(const Block& wire) DECL_OVERRIDE;
+
+ virtual void
+ send(const Block& header, const Block& payload) DECL_OVERRIDE;
+};
+
/** \brief identifies a node (forwarder) in the topology
*/
typedef size_t TopologyNode;
@@ -52,10 +119,7 @@
class TopologyLinkBase : noncopyable
{
public:
- TopologyLinkBase()
- : m_isUp(true)
- {
- }
+ TopologyLinkBase();
/** \brief fail the link, cause packets to be dropped silently
*/
@@ -74,7 +138,21 @@
}
protected:
+ /** \brief attach a Transport onto this link
+ */
+ void
+ attachTransport(TopologyNode i, TopologyTransportBase* transport);
+
+private:
+ void
+ transmit(TopologyNode i, const Block& packet);
+
+ virtual void
+ scheduleReceive(TopologyTransportBase* recipient, const Block& packet) = 0;
+
+protected:
bool m_isUp;
+ std::unordered_map<TopologyNode, TopologyTransportBase*> m_transports;
};
/** \brief represents a network link in the topology which connects two or more nodes
@@ -82,90 +160,27 @@
class TopologyLink : public TopologyLinkBase
{
public:
+ explicit
+ TopologyLink(const time::nanoseconds& delay);
+
+ void
+ addFace(TopologyNode i, shared_ptr<face::LpFaceWrapper> face);
+
/** \return a face of forwarder \p i which is attached to this link
*/
- shared_ptr<DummyFace>
+ Face&
getFace(TopologyNode i)
{
- return m_faces.at(i)->face;
+ return *m_faces.at(i);
}
private:
- explicit
- TopologyLink(const time::nanoseconds& delay)
- : m_delay(delay)
- {
- BOOST_ASSERT(delay >= time::nanoseconds::zero());
- }
-
- struct LinkFace
- {
- shared_ptr<DummyFace> face;
- };
-
- void
- addFace(TopologyNode i, shared_ptr<DummyFace> face)
- {
- BOOST_ASSERT(m_faces.count(i) == 0);
-
- LinkFace* lf = new LinkFace();
- lf->face = face;
- face->onSendInterest.connect(bind(&TopologyLink::transmitInterest, this, i, _1));
- face->onSendData.connect(bind(&TopologyLink::transmitData, this, i, _1));
-
- m_faces[i].reset(lf);
- }
-
- friend class TopologyTester;
-
-private:
- void
- transmitInterest(TopologyNode i, const Interest& interest)
- {
- if (!m_isUp) {
- return;
- }
-
- // Interest object cannot be shared between faces because
- // Forwarder can set different IncomingFaceId.
- Block wire = interest.wireEncode();
- for (auto&& p : m_faces) {
- if (p.first == i) {
- continue;
- }
- shared_ptr<DummyFace> face = p.second->face;
- scheduler::schedule(m_delay, [wire, face] {
- auto interest = make_shared<Interest>(wire);
- face->receiveInterest(*interest);
- });
- }
- }
-
- void
- transmitData(TopologyNode i, const Data& data)
- {
- if (!m_isUp) {
- return;
- }
-
- // Data object cannot be shared between faces because
- // Forwarder can set different IncomingFaceId.
- Block wire = data.wireEncode();
- for (auto&& p : m_faces) {
- if (p.first == i) {
- continue;
- }
- shared_ptr<DummyFace> face = p.second->face;
- scheduler::schedule(m_delay, [wire, face] {
- auto data = make_shared<Data>(wire);
- face->receiveData(*data);
- });
- }
- }
+ virtual void
+ scheduleReceive(TopologyTransportBase* recipient, const Block& packet) DECL_OVERRIDE;
private:
time::nanoseconds m_delay;
- std::unordered_map<TopologyNode, unique_ptr<LinkFace>> m_faces;
+ std::unordered_map<TopologyNode, shared_ptr<face::LpFaceWrapper>> m_faces;
};
/** \brief represents a link to a local application
@@ -173,66 +188,32 @@
class TopologyAppLink : public TopologyLinkBase
{
public:
+ explicit
+ TopologyAppLink(shared_ptr<face::LpFaceWrapper> face);
+
/** \return face on forwarder side
*/
- shared_ptr<DummyLocalFace>
+ Face&
getForwarderFace()
{
- return m_face;
+ return *m_face;
}
/** \return face on application side
*/
- shared_ptr<DummyClientFace>
+ ndn::Face&
getClientFace()
{
- return m_client;
+ return *m_client;
}
private:
- explicit
- TopologyAppLink(shared_ptr<DummyLocalFace> face)
- : m_face(face)
- , m_client(ndn::util::makeDummyClientFace(getGlobalIoService(), {false, false}))
- {
- m_client->onSendInterest.connect([this] (const Interest& interest) {
- if (!m_isUp) {
- return;
- }
- auto interest2 = interest.shared_from_this();
- getGlobalIoService().post([=] { m_face->receiveInterest(*interest2); });
- });
-
- m_client->onSendData.connect([this] (const Data& data) {
- if (!m_isUp) {
- return;
- }
- auto data2 = data.shared_from_this();
- getGlobalIoService().post([=] { m_face->receiveData(*data2); });
- });
-
- m_face->onSendInterest.connect([this] (const Interest& interest) {
- if (!m_isUp) {
- return;
- }
- auto interest2 = interest.shared_from_this();
- getGlobalIoService().post([=] { m_client->receive(*interest2); });
- });
-
- m_face->onSendData.connect([this] (const Data& data) {
- if (!m_isUp) {
- return;
- }
- auto data2 = data.shared_from_this();
- getGlobalIoService().post([=] { m_client->receive(*data2); });
- });
- }
-
- friend class TopologyTester;
+ virtual void
+ scheduleReceive(TopologyTransportBase* recipient, const Block& packet) DECL_OVERRIDE;
private:
- shared_ptr<DummyLocalFace> m_face;
- shared_ptr<DummyClientFace> m_client;
+ shared_ptr<face::LpFaceWrapper> m_face;
+ shared_ptr<ndn::Face> m_client;
};
/** \brief builds a topology for forwarding tests
@@ -244,12 +225,7 @@
* \return index of new forwarder
*/
TopologyNode
- addForwarder()
- {
- size_t i = m_forwarders.size();
- m_forwarders.push_back(make_unique<Forwarder>());
- return i;
- }
+ addForwarder(const std::string& label);
/** \return forwarder instance \p i
*/
@@ -281,85 +257,42 @@
* this packet will be received by all other faces on this link after \p delay .
*/
shared_ptr<TopologyLink>
- addLink(const time::nanoseconds& delay, std::initializer_list<TopologyNode> forwarders)
- {
- auto link = shared_ptr<TopologyLink>(new TopologyLink(delay));
- for (TopologyNode i : forwarders) {
- Forwarder& forwarder = this->getForwarder(i);
- shared_ptr<DummyFace> face = make_shared<DummyFace>();
- forwarder.addFace(face);
- link->addFace(i, face);
- }
- return link;
- }
+ addLink(const std::string& label, const time::nanoseconds& delay,
+ std::initializer_list<TopologyNode> forwarders,
+ bool forceMultiAccessFace = false);
/** \brief makes a link to local application
*/
shared_ptr<TopologyAppLink>
- addAppFace(TopologyNode i)
- {
- Forwarder& forwarder = this->getForwarder(i);
- auto face = make_shared<DummyLocalFace>();
- forwarder.addFace(face);
-
- return shared_ptr<TopologyAppLink>(new TopologyAppLink(face));
- }
+ addAppFace(const std::string& label, TopologyNode i);
/** \brief makes a link to local application, and register a prefix
*/
shared_ptr<TopologyAppLink>
- addAppFace(TopologyNode i, const Name& prefix, uint64_t cost = 0)
- {
- shared_ptr<TopologyAppLink> al = this->addAppFace(i);
- this->registerPrefix(i, al->getForwarderFace(), prefix, cost);
- return al;
- }
+ addAppFace(const std::string& label, TopologyNode i, const Name& prefix, uint64_t cost = 0);
- /** \brief registers a prefix on a face
- * \tparam F either DummyFace or DummyLocalFace
+ /** \brief registers a prefix on a forwarder face
*/
- template<typename F>
void
- registerPrefix(TopologyNode i, shared_ptr<F> face, const Name& prefix, uint64_t cost = 0)
- {
- Forwarder& forwarder = this->getForwarder(i);
- Fib& fib = forwarder.getFib();
- shared_ptr<fib::Entry> fibEntry = fib.insert(prefix).first;
- fibEntry->addNextHop(face, cost);
- }
+ registerPrefix(TopologyNode i, const Face& face, const Name& prefix, uint64_t cost = 0);
/** \brief creates a producer application that answers every Interest with Data of same Name
*/
void
- addEchoProducer(DummyClientFace& face, const Name& prefix = "/")
- {
- face.setInterestFilter(prefix,
- [&face] (const ndn::InterestFilter&, const Interest& interest) {
- shared_ptr<Data> data = makeData(interest.getName());
- face.put(*data);
- });
- }
+ addEchoProducer(ndn::Face& face, const Name& prefix = "/");
/** \brief creates a consumer application that sends \p n Interests under \p prefix
* at \p interval fixed rate.
*/
void
- addIntervalConsumer(DummyClientFace& face, const Name& prefix,
- const time::nanoseconds& interval, size_t n)
- {
- Name name(prefix);
- name.appendTimestamp();
- shared_ptr<Interest> interest = makeInterest(name);
- face.expressInterest(*interest, bind([]{}));
-
- if (n > 1) {
- scheduler::schedule(interval, bind(&TopologyTester::addIntervalConsumer, this,
- ref(face), prefix, interval, n - 1));
- }
- }
+ addIntervalConsumer(ndn::Face& face, const Name& prefix,
+ const time::nanoseconds& interval, size_t n);
private:
std::vector<unique_ptr<Forwarder>> m_forwarders;
+ std::vector<std::string> m_forwarderLabels;
+ std::vector<shared_ptr<TopologyLink>> m_links;
+ std::vector<shared_ptr<TopologyAppLink>> m_appLinks;
};
} // namespace tests
diff --git a/tests/daemon/table/pit.t.cpp b/tests/daemon/table/pit.t.cpp
index 7bd89fc..dd02bec 100644
--- a/tests/daemon/table/pit.t.cpp
+++ b/tests/daemon/table/pit.t.cpp
@@ -34,9 +34,12 @@
using namespace nfd::tests;
-BOOST_FIXTURE_TEST_SUITE(TablePit, BaseFixture)
+BOOST_AUTO_TEST_SUITE(Table)
+BOOST_FIXTURE_TEST_SUITE(TestPit, BaseFixture)
-BOOST_AUTO_TEST_CASE(EntryInOutRecords)
+BOOST_AUTO_TEST_SUITE(PitEntry)
+
+BOOST_AUTO_TEST_CASE(InOutRecords)
{
shared_ptr<Face> face1 = make_shared<DummyFace>();
shared_ptr<Face> face2 = make_shared<DummyFace>();
@@ -151,7 +154,7 @@
BOOST_CHECK(entry.getOutRecord(*face2) == entry.getOutRecords().end());
}
-BOOST_AUTO_TEST_CASE(EntryNonce)
+BOOST_AUTO_TEST_CASE(Nonce)
{
shared_ptr<Face> face1 = make_shared<DummyFace>();
shared_ptr<Face> face2 = make_shared<DummyFace>();
@@ -210,7 +213,7 @@
BOOST_CHECK_EQUAL(entry5.findNonce(19004, *face2), pit::DUPLICATE_NONCE_NONE);
}
-BOOST_AUTO_TEST_CASE(EntryLifetime)
+BOOST_AUTO_TEST_CASE(Lifetime)
{
shared_ptr<Interest> interest = makeInterest("ndn:/7oIEurbgy6");
// library uses -1 to indicate unset lifetime
@@ -226,7 +229,7 @@
BOOST_CHECK_GT(outIt->getExpiry(), time::steady_clock::now());
}
-BOOST_AUTO_TEST_CASE(EntryCanForwardTo)
+BOOST_AUTO_TEST_CASE(CanForwardTo)
{
shared_ptr<Interest> interest = makeInterest("ndn:/WDsuBLIMG");
pit::Entry entry(*interest);
@@ -247,6 +250,37 @@
BOOST_CHECK_EQUAL(entry.canForwardTo(*face2), true);
}
+BOOST_AUTO_TEST_CASE(OutRecordNack)
+{
+ shared_ptr<Face> face1 = make_shared<DummyFace>();
+ pit::OutRecord outR(face1);
+ BOOST_CHECK(outR.getIncomingNack() == nullptr);
+
+ shared_ptr<Interest> interest1 = makeInterest("ndn:/uWiapGjYL");
+ interest1->setNonce(165);
+ outR.update(*interest1);
+ BOOST_CHECK(outR.getIncomingNack() == nullptr);
+
+ shared_ptr<Interest> interest2 = makeInterest("ndn:/uWiapGjYL");
+ interest2->setNonce(996);
+ lp::Nack nack2(*interest2);
+ nack2.setReason(lp::NackReason::CONGESTION);
+ BOOST_CHECK_EQUAL(outR.setIncomingNack(nack2), false);
+ BOOST_CHECK(outR.getIncomingNack() == nullptr);
+
+ lp::Nack nack1(*interest1);
+ nack1.setReason(lp::NackReason::DUPLICATE);
+ BOOST_CHECK_EQUAL(outR.setIncomingNack(nack1), true);
+ BOOST_REQUIRE(outR.getIncomingNack() != nullptr);
+ BOOST_CHECK_EQUAL(outR.getIncomingNack()->getReason(), lp::NackReason::DUPLICATE);
+
+ outR.clearIncomingNack();
+ BOOST_CHECK(outR.getIncomingNack() == nullptr);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // PitEntry
+
+
BOOST_AUTO_TEST_CASE(Insert)
{
Name name1("ndn:/5vzBNnMst");
@@ -368,18 +402,21 @@
insertResult = pit.insert(*interest);
BOOST_CHECK_EQUAL(insertResult.second, true);
BOOST_CHECK_EQUAL(pit.size(), 1);
+ BOOST_CHECK(pit.find(*interest) != nullptr);
insertResult = pit.insert(*interest);
BOOST_CHECK_EQUAL(insertResult.second, false);
BOOST_CHECK_EQUAL(pit.size(), 1);
+ BOOST_CHECK(pit.find(*interest) != nullptr);
pit.erase(insertResult.first);
BOOST_CHECK_EQUAL(pit.size(), 0);
+ BOOST_CHECK(pit.find(*interest) == nullptr);
insertResult = pit.insert(*interest);
BOOST_CHECK_EQUAL(insertResult.second, true);
BOOST_CHECK_EQUAL(pit.size(), 1);
-
+ BOOST_CHECK(pit.find(*interest) != nullptr);
}
BOOST_AUTO_TEST_CASE(EraseNameTreeEntry)
@@ -496,6 +533,7 @@
}
BOOST_AUTO_TEST_SUITE_END()
+BOOST_AUTO_TEST_SUITE_END()
} // namespace tests
} // namespace pit