lsdb: emit signals when modified
RoutingTable and NamePrefixTable consume the signal
and behave accordingly.
refs: #4127
Change-Id: I6540f30f0222f804b01dc7d9640831c84e5264cc
diff --git a/tests/route/test-name-prefix-table.cpp b/tests/route/test-name-prefix-table.cpp
index 9585106..fbe6c5a 100644
--- a/tests/route/test-name-prefix-table.cpp
+++ b/tests/route/test-name-prefix-table.cpp
@@ -20,7 +20,9 @@
*/
#include "route/name-prefix-table.hpp"
-#include "nlsr.hpp"
+#include "route/fib.hpp"
+#include "route/routing-table.hpp"
+#include "lsdb.hpp"
#include "../test-common.hpp"
#include <ndn-cxx/util/dummy-client-face.hpp>
@@ -34,32 +36,38 @@
NamePrefixTableFixture()
: face(m_ioService, m_keyChain)
, conf(face, m_keyChain)
- , nlsr(face, m_keyChain, conf)
- , lsdb(nlsr.m_lsdb)
- , npt(nlsr.m_namePrefixTable)
+ , confProcessor(conf)
+ , lsdb(face, m_keyChain, conf)
+ , fib(face, m_scheduler, conf.getAdjacencyList(), conf, m_keyChain)
+ , rt(m_scheduler, lsdb, conf)
+ , npt(conf.getRouterPrefix(), fib, rt, rt.afterRoutingChange, lsdb.onLsdbModified)
{
}
+ bool
+ isNameInNpt(const ndn::Name& name)
+ {
+ auto it = std::find_if(npt.begin(), npt.end(),
+ [&] (const auto& entry) { return name == entry->getNamePrefix(); });
+ return it != npt.end();
+ }
+
public:
ndn::util::DummyClientFace face;
ConfParameter conf;
- Nlsr nlsr;
+ DummyConfFileProcessor confProcessor;
- Lsdb& lsdb;
- NamePrefixTable& npt;
+ Lsdb lsdb;
+ Fib fib;
+ RoutingTable rt;
+ NamePrefixTable npt;
};
BOOST_AUTO_TEST_SUITE(TestNamePrefixTable)
BOOST_FIXTURE_TEST_CASE(Bupt, NamePrefixTableFixture)
{
- conf.setNetwork("/ndn");
- conf.setSiteName("/router");
- conf.setRouterName("/a");
- conf.buildRouterAndSyncUserPrefix();
-
- RoutingTable& routingTable = nlsr.m_routingTable;
- routingTable.setRoutingCalcInterval(0);
+ rt.m_routingCalcInterval = 0_s;
Adjacent thisRouter(conf.getRouterPrefix(), ndn::FaceUri("udp4://10.0.0.1"), 0, Adjacent::STATUS_ACTIVE, 0, 0);
@@ -265,7 +273,6 @@
BOOST_FIXTURE_TEST_CASE(RoutingTableUpdate, NamePrefixTableFixture)
{
- RoutingTable& routingTable = nlsr.m_routingTable;
const ndn::Name destination = ndn::Name{"/ndn/destination1"};
NextHop hop1{"upd4://10.0.0.1", 0};
NextHop hop2{"udp4://10.0.0.2", 1};
@@ -273,10 +280,10 @@
const NamePrefixTableEntry entry1{"/ndn/router1"};
npt.addEntry(entry1.getNamePrefix(), destination);
- routingTable.addNextHop(destination, hop1);
- routingTable.addNextHop(destination, hop2);
+ rt.addNextHop(destination, hop1);
+ rt.addNextHop(destination, hop2);
- npt.updateWithNewRoute(routingTable.m_rTable);
+ npt.updateWithNewRoute(rt.m_rTable);
// At this point the NamePrefixTableEntry should have two NextHops.
auto nameIterator = std::find_if(npt.begin(), npt.end(),
@@ -291,8 +298,8 @@
BOOST_CHECK_EQUAL(nextHops.size(), 2);
// Add the other NextHop
- routingTable.addNextHop(destination, hop3);
- npt.updateWithNewRoute(routingTable.m_rTable);
+ rt.addNextHop(destination, hop3);
+ npt.updateWithNewRoute(rt.m_rTable);
// At this point the NamePrefixTableEntry should have three NextHops.
nameIterator = std::find_if(npt.begin(), npt.end(),
@@ -306,6 +313,65 @@
BOOST_CHECK_EQUAL(nextHops.size(), 3);
}
+BOOST_FIXTURE_TEST_CASE(UpdateFromLsdb, NamePrefixTableFixture)
+{
+ ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now();
+ NamePrefixList npl1;
+ ndn::Name n1("name1");
+ ndn::Name n2("name2");
+ ndn::Name router1("/router1/1");
+
+ npl1.insert(n1);
+ npl1.insert(n2);
+
+ NameLsa nlsa1(router1, 12, testTimePoint, npl1);
+ std::shared_ptr<Lsa> lsaPtr = std::make_shared<NameLsa>(nlsa1);
+
+ BOOST_CHECK(npt.begin() == npt.end());
+ npt.updateFromLsdb(lsaPtr, LsdbUpdate::INSTALLED, {}, {});
+ BOOST_CHECK_EQUAL(npt.m_table.size(), 3); // Router + 2 names
+
+ BOOST_CHECK(isNameInNpt(n1));
+ BOOST_CHECK(isNameInNpt(n2));
+
+ ndn::Name n3("name3");
+ auto nlsa = std::static_pointer_cast<NameLsa>(lsaPtr);
+ nlsa->removeName(n2);
+ nlsa->addName(n3);
+ npt.updateFromLsdb(lsaPtr, LsdbUpdate::UPDATED, {n3}, {n2});
+ BOOST_CHECK(isNameInNpt(n1));
+ BOOST_CHECK(!isNameInNpt(n2)); // Removed
+ BOOST_CHECK(isNameInNpt(n3));
+
+ BOOST_CHECK_EQUAL(npt.m_table.size(), 3); // Still router + 2 names
+
+ npt.updateFromLsdb(lsaPtr, LsdbUpdate::REMOVED, {}, {});
+ BOOST_CHECK_EQUAL(npt.m_table.size(), 0);
+
+ // Adj and Coordinate LSAs router
+ ndn::Name router2("/router2/2");
+ AdjLsa adjLsa(router2, 12, testTimePoint, 2, conf.getAdjacencyList());
+ lsaPtr = std::make_shared<AdjLsa>(adjLsa);
+ BOOST_CHECK(npt.begin() == npt.end());
+ npt.updateFromLsdb(lsaPtr, LsdbUpdate::INSTALLED, {}, {});
+ BOOST_CHECK_EQUAL(npt.m_table.size(), 1);
+ BOOST_CHECK(isNameInNpt(router2));
+
+ npt.updateFromLsdb(lsaPtr, LsdbUpdate::REMOVED, {}, {});
+ BOOST_CHECK_EQUAL(npt.m_table.size(), 0);
+
+ ndn::Name router3("/router3/3");
+ CoordinateLsa corLsa(router3, 12, testTimePoint, 2, {3});
+ lsaPtr = std::make_shared<CoordinateLsa>(corLsa);
+ BOOST_CHECK(npt.begin() == npt.end());
+ npt.updateFromLsdb(lsaPtr, LsdbUpdate::INSTALLED, {}, {});
+ BOOST_CHECK_EQUAL(npt.m_table.size(), 1);
+ BOOST_CHECK(isNameInNpt(router3));
+
+ npt.updateFromLsdb(lsaPtr, LsdbUpdate::REMOVED, {}, {});
+ BOOST_CHECK_EQUAL(npt.m_table.size(), 0);
+}
+
BOOST_AUTO_TEST_SUITE_END()
} // namespace test