fw: improve Strategy::lookupFib test coverage
refs #3664
Change-Id: I0ae2e2f99d91306930718d43982ca1744640e533
diff --git a/tests/daemon/fw/strategy.t.cpp b/tests/daemon/fw/strategy.t.cpp
index 10e13cb..455c80a 100644
--- a/tests/daemon/fw/strategy.t.cpp
+++ b/tests/daemon/fw/strategy.t.cpp
@@ -122,7 +122,20 @@
, fib(forwarder.getFib())
, pit(forwarder.getPit())
, nrt(forwarder.getNetworkRegionTable())
+ , inFace(make_shared<DummyFace>())
+ , outFace(make_shared<DummyFace>())
+ , link(makeLink("/net/ndnsim", {{10, "/telia/terabits"}, {20, "/ucla/cs"}}))
{
+ forwarder.addFace(inFace);
+ forwarder.addFace(outFace);
+ }
+
+ const fib::Entry&
+ lookupFib(Interest& interest)
+ {
+ shared_ptr<pit::Entry> pitEntry = pit.insert(interest).first;
+ pitEntry->insertOrUpdateInRecord(*inFace, interest);
+ return strategy.lookupFib(*pitEntry);
}
protected:
@@ -131,110 +144,102 @@
Fib& fib;
Pit& pit;
NetworkRegionTable& nrt;
+
+ shared_ptr<Face> inFace;
+ shared_ptr<Face> outFace;
+ shared_ptr<Link> link;
};
-BOOST_FIXTURE_TEST_CASE(LookupFib, LookupFibFixture)
+BOOST_FIXTURE_TEST_SUITE(LookupFib, LookupFibFixture)
+
+BOOST_AUTO_TEST_CASE(NoLink)
{
- /// \todo test lookupFib without Link
- /// \todo split each step to a separate test case
+ fib.insert("/net/ndnsim").first->addNextHop(*outFace, 10);
- shared_ptr<Face> face1 = make_shared<DummyFace>();
- shared_ptr<Face> face2 = make_shared<DummyFace>();
- forwarder.addFace(face1);
- forwarder.addFace(face2);
+ auto interest = makeInterest("/net/ndnsim/www/index.html");
+ const fib::Entry& fibEntry = this->lookupFib(*interest);
- shared_ptr<Link> link = makeLink("/net/ndnsim", {{10, "/telia/terabits"}, {20, "/ucla/cs"}});
-
- // consumer region
- nrt.clear();
- nrt.insert("/arizona/cs/avenir");
- fib.insert("/").first->addNextHop(*face2, 10);
-
- auto interest1 = makeInterest("/net/ndnsim/www/1.html");
- interest1->setLink(link->wireEncode());
- shared_ptr<pit::Entry> pit1 = pit.insert(*interest1).first;
- pit1->insertOrUpdateInRecord(*face1, *interest1);
-
- BOOST_CHECK_EQUAL(strategy.lookupFib(*pit1).getPrefix(), "/");
- BOOST_CHECK_EQUAL(interest1->hasSelectedDelegation(), false);
-
- fib.insert("/").first->removeNextHop(*face2);
-
- // first default-free router, both delegations are available
- nrt.clear();
- nrt.insert("/arizona/cs/hobo");
- fib.insert("/telia").first->addNextHop(*face2, 10);
- fib.insert("/ucla").first->addNextHop(*face2, 10);
-
- auto interest2 = makeInterest("/net/ndnsim/www/2.html");
- interest2->setLink(link->wireEncode());
- shared_ptr<pit::Entry> pit2 = pit.insert(*interest2).first;
- pit2->insertOrUpdateInRecord(*face1, *interest2);
-
- BOOST_CHECK_EQUAL(strategy.lookupFib(*pit2).getPrefix(), "/telia");
- BOOST_REQUIRE_EQUAL(interest2->hasSelectedDelegation(), true);
- BOOST_CHECK_EQUAL(interest2->getSelectedDelegation(), "/telia/terabits");
-
- fib.erase("/telia");
- fib.erase("/ucla");
-
- // first default-free router, only second delegation is available
- nrt.clear();
- nrt.insert("/arizona/cs/hobo");
- fib.insert("/ucla").first->addNextHop(*face2, 10);
-
- auto interest3 = makeInterest("/net/ndnsim/www/3.html");
- interest3->setLink(link->wireEncode());
- shared_ptr<pit::Entry> pit3 = pit.insert(*interest3).first;
- pit3->insertOrUpdateInRecord(*face1, *interest3);
-
- BOOST_CHECK_EQUAL(strategy.lookupFib(*pit3).getPrefix(), "/ucla");
- BOOST_REQUIRE_EQUAL(interest3->hasSelectedDelegation(), true);
- BOOST_CHECK_EQUAL(interest3->getSelectedDelegation(), "/ucla/cs");
-
- fib.erase("/ucla");
-
- // default-free router, chosen SelectedDelegation
- nrt.clear();
- nrt.insert("/ucsd/caida/click");
- fib.insert("/telia").first->addNextHop(*face2, 10);
- fib.insert("/ucla").first->addNextHop(*face2, 10);
-
- auto interest4 = makeInterest("/net/ndnsim/www/4.html");
- interest4->setLink(link->wireEncode());
- interest4->setSelectedDelegation("/ucla/cs");
- shared_ptr<pit::Entry> pit4 = pit.insert(*interest4).first;
- pit4->insertOrUpdateInRecord(*face1, *interest4);
-
- BOOST_CHECK_EQUAL(strategy.lookupFib(*pit4).getPrefix(), "/ucla");
- BOOST_REQUIRE_EQUAL(interest4->hasSelectedDelegation(), true);
- BOOST_CHECK_EQUAL(interest4->getSelectedDelegation(), "/ucla/cs");
-
- fib.erase("/telia");
- fib.erase("/ucla");
-
- // producer region
- nrt.clear();
- nrt.insert("/ucla/cs/spurs");
- fib.insert("/").first->addNextHop(*face2, 10);
- fib.insert("/ucla").first->addNextHop(*face2, 10);
- fib.insert("/net/ndnsim").first->addNextHop(*face2, 10);
-
- auto interest5 = makeInterest("/net/ndnsim/www/5.html");
- interest5->setLink(link->wireEncode());
- interest5->setSelectedDelegation("/ucla/cs");
- shared_ptr<pit::Entry> pit5 = pit.insert(*interest5).first;
- pit5->insertOrUpdateInRecord(*face1, *interest5);
-
- BOOST_CHECK_EQUAL(strategy.lookupFib(*pit1).getPrefix(), "/net/ndnsim");
- BOOST_REQUIRE_EQUAL(interest5->hasSelectedDelegation(), true);
- BOOST_CHECK_EQUAL(interest5->getSelectedDelegation(), "/ucla/cs");
-
- fib.insert("/").first->removeNextHop(*face2);
- fib.erase("/ucla");
- fib.erase("/ndnsim");
+ BOOST_CHECK_EQUAL(fibEntry.getPrefix(), "/net/ndnsim");
+ BOOST_CHECK_EQUAL(interest->hasSelectedDelegation(), false);
}
+BOOST_AUTO_TEST_CASE(ConsumerRegion)
+{
+ nrt.insert("/arizona/cs/avenir");
+ fib.insert("/").first->addNextHop(*outFace, 10);
+
+ auto interest = makeInterest("/net/ndnsim/www/index.html");
+ interest->setLink(link->wireEncode());
+ const fib::Entry& fibEntry = this->lookupFib(*interest);
+
+ BOOST_CHECK_EQUAL(fibEntry.getPrefix(), "/");
+ BOOST_CHECK_EQUAL(interest->hasSelectedDelegation(), false);
+}
+
+BOOST_AUTO_TEST_CASE(DefaultFreeFirstDegegation)
+{
+ nrt.insert("/arizona/cs/hobo");
+ fib.insert("/telia").first->addNextHop(*outFace, 20);
+ fib.insert("/ucla").first->addNextHop(*outFace, 10);
+
+ auto interest = makeInterest("/net/ndnsim/www/index.html");
+ interest->setLink(link->wireEncode());
+ const fib::Entry& fibEntry = this->lookupFib(*interest);
+
+ BOOST_CHECK_EQUAL(fibEntry.getPrefix(), "/telia");
+ BOOST_REQUIRE_EQUAL(interest->hasSelectedDelegation(), true);
+ BOOST_CHECK_EQUAL(interest->getSelectedDelegation(), "/telia/terabits");
+}
+
+BOOST_AUTO_TEST_CASE(DefaultFreeSecondDelegation)
+{
+ nrt.insert("/arizona/cs/hobo");
+ fib.insert("/ucla").first->addNextHop(*outFace, 10);
+
+ auto interest = makeInterest("/net/ndnsim/www/index.html");
+ interest->setLink(link->wireEncode());
+ const fib::Entry& fibEntry = this->lookupFib(*interest);
+
+ BOOST_CHECK_EQUAL(fibEntry.getPrefix(), "/ucla");
+ BOOST_REQUIRE_EQUAL(interest->hasSelectedDelegation(), true);
+ BOOST_CHECK_EQUAL(interest->getSelectedDelegation(), "/ucla/cs");
+}
+
+BOOST_AUTO_TEST_CASE(DefaultFreeHasSelectedDelegation)
+{
+ nrt.insert("/ucsd/caida/click");
+ fib.insert("/telia").first->addNextHop(*outFace, 10);
+ fib.insert("/ucla").first->addNextHop(*outFace, 10);
+
+ auto interest = makeInterest("/net/ndnsim/www/index.html");
+ interest->setLink(link->wireEncode());
+ interest->setSelectedDelegation("/ucla/cs");
+ const fib::Entry& fibEntry = this->lookupFib(*interest);
+
+ BOOST_CHECK_EQUAL(fibEntry.getPrefix(), "/ucla");
+ BOOST_REQUIRE_EQUAL(interest->hasSelectedDelegation(), true);
+ BOOST_CHECK_EQUAL(interest->getSelectedDelegation(), "/ucla/cs");
+}
+
+BOOST_AUTO_TEST_CASE(ProducerRegion)
+{
+ nrt.insert("/ucla/cs/spurs");
+ fib.insert("/").first->addNextHop(*outFace, 10);
+ fib.insert("/ucla").first->addNextHop(*outFace, 10);
+ fib.insert("/net/ndnsim").first->addNextHop(*outFace, 10);
+
+ auto interest = makeInterest("/net/ndnsim/www/index.html");
+ interest->setLink(link->wireEncode());
+ interest->setSelectedDelegation("/ucla/cs");
+ const fib::Entry& fibEntry = this->lookupFib(*interest);
+
+ BOOST_CHECK_EQUAL(fibEntry.getPrefix(), "/net/ndnsim");
+ BOOST_REQUIRE_EQUAL(interest->hasSelectedDelegation(), true);
+ BOOST_CHECK_EQUAL(interest->getSelectedDelegation(), "/ucla/cs");
+}
+
+BOOST_AUTO_TEST_SUITE_END() // LookupFib
+
BOOST_AUTO_TEST_SUITE_END() // TestStrategy
BOOST_AUTO_TEST_SUITE_END() // Fw