Make LSA buildable when one node is ACTIVE
refs: #2802
Change-Id: If3f99895522e22103130f32bb6634bf9a5691fe7
diff --git a/tests/test-nlsr.cpp b/tests/test-nlsr.cpp
index 5ad6efd..a469d5f 100644
--- a/tests/test-nlsr.cpp
+++ b/tests/test-nlsr.cpp
@@ -32,16 +32,40 @@
using ndn::shared_ptr;
-BOOST_FIXTURE_TEST_SUITE(TestNlsr, BaseFixture)
+class NlsrFixture : public UnitTestTimeFixture
+{
+public:
+ NlsrFixture()
+ : face(make_shared<ndn::util::DummyClientFace>())
+ , nlsr(g_ioService, g_scheduler, ndn::ref(*face))
+ , lsdb(nlsr.getLsdb())
+ , neighbors(nlsr.getAdjacencyList())
+ {
+ }
+
+ void
+ receiveHelloData(const ndn::Name& sender, const ndn::Name& receiver)
+ {
+ ndn::Name dataName(sender);
+ dataName.append("NLSR").append("INFO").append(receiver.wireEncode()).appendVersion();
+
+ shared_ptr<ndn::Data> data = make_shared<ndn::Data>(dataName);
+
+ nlsr.m_helloProtocol.onContentValidated(data);
+ }
+
+public:
+ shared_ptr<ndn::util::DummyClientFace> face;
+ Nlsr nlsr;
+ Lsdb& lsdb;
+ AdjacencyList& neighbors;
+};
+
+BOOST_FIXTURE_TEST_SUITE(TestNlsr, NlsrFixture)
BOOST_AUTO_TEST_CASE(HyperbolicOn_ZeroCostNeighbors)
{
- shared_ptr<ndn::util::DummyClientFace> face = make_shared<ndn::util::DummyClientFace>();
- Nlsr nlsr(g_ioService, g_scheduler, ndn::ref(*face));
-
// Simulate loading configuration file
- AdjacencyList& neighbors = nlsr.getAdjacencyList();
-
Adjacent neighborA("/ndn/neighborA", "uri://faceA", 25, Adjacent::STATUS_INACTIVE, 0, 0);
neighbors.insert(neighborA);
@@ -63,12 +87,7 @@
BOOST_AUTO_TEST_CASE(HyperbolicOff_LinkStateCost)
{
- shared_ptr<ndn::util::DummyClientFace> face = make_shared<ndn::util::DummyClientFace>();
- Nlsr nlsr(g_ioService, g_scheduler, ndn::ref(*face));
-
// Simulate loading configuration file
- AdjacencyList& neighbors = nlsr.getAdjacencyList();
-
Adjacent neighborA("/ndn/neighborA", "uri://faceA", 25, Adjacent::STATUS_INACTIVE, 0, 0);
neighbors.insert(neighborA);
@@ -88,9 +107,6 @@
BOOST_AUTO_TEST_CASE(SetEventIntervals)
{
- shared_ptr<ndn::util::DummyClientFace> face = make_shared<ndn::util::DummyClientFace>();
- Nlsr nlsr(g_ioService, g_scheduler, ndn::ref(*face));
-
// Simulate loading configuration file
ConfParameter& conf = nlsr.getConfParameter();
conf.setAdjLsaBuildInterval(3);
@@ -123,7 +139,6 @@
// Add active neighbors
AdjacencyList& neighbors = nlsr.getAdjacencyList();
-
uint64_t destroyFaceId = 128;
// Create a neighbor whose Face will be destroyed
@@ -323,11 +338,8 @@
BOOST_CHECK_EQUAL(parameters.getName(), nameToAdvertise);
}
-BOOST_FIXTURE_TEST_CASE(GetCertificate, UnitTestTimeFixture)
+BOOST_AUTO_TEST_CASE(GetCertificate)
{
- shared_ptr<ndn::util::DummyClientFace> face = make_shared<ndn::util::DummyClientFace>(g_ioService);
- Nlsr nlsr(g_ioService, g_scheduler, ndn::ref(*face));
-
// Create certificate
ndn::Name identity("/TestNLSR/identity");
identity.appendVersion();
@@ -355,11 +367,8 @@
BOOST_CHECK(nlsr.getCertificate(certKey) != nullptr);
}
-BOOST_FIXTURE_TEST_CASE(SetRouterCommandPrefix, UnitTestTimeFixture)
+BOOST_AUTO_TEST_CASE(SetRouterCommandPrefix)
{
- shared_ptr<ndn::util::DummyClientFace> face = make_shared<ndn::util::DummyClientFace>(g_ioService);
- Nlsr nlsr(g_ioService, g_scheduler, ndn::ref(*face));
-
// Simulate loading configuration file
ConfParameter& conf = nlsr.getConfParameter();
conf.setNetwork("/ndn");
@@ -372,6 +381,70 @@
ndn::Name("/ndn/site/%C1.router/this-router/lsdb"));
}
+BOOST_AUTO_TEST_CASE(BuildAdjLsaAfterHelloResponse)
+{
+ // Configure NLSR
+ ConfParameter& conf = nlsr.getConfParameter();
+ conf.setNetwork("/ndn");
+ conf.setSiteName("/site");
+
+ ndn::Name routerName("/%C1.Router/this-router");
+ conf.setRouterName(routerName);
+
+ conf.setAdjLsaBuildInterval(1);
+
+ // Add neighbors
+ // Router A
+ ndn::Name neighborAName("/ndn/site/%C1.router/routerA");
+ Adjacent neighborA(neighborAName, "uri://faceA", 0, Adjacent::STATUS_INACTIVE, 0, 0);
+ neighbors.insert(neighborA);
+
+ // Router B
+ ndn::Name neighborBName("/ndn/site/%C1.router/routerB");
+ Adjacent neighborB(neighborBName, "uri://faceA", 0, Adjacent::STATUS_INACTIVE, 0, 0);
+ neighbors.insert(neighborB);
+
+ nlsr.initialize();
+ this->advanceClocks(ndn::time::milliseconds(1));
+
+ // Receive HELLO response from Router A
+ receiveHelloData(neighborAName, conf.getRouterPrefix());
+ this->advanceClocks(ndn::time::seconds(1));
+
+ ndn::Name lsaKey = ndn::Name(conf.getRouterPrefix()).append(AdjLsa::TYPE_STRING);
+
+ // Adjacency LSA should be built even though other router is INACTIVE
+ AdjLsa* lsa = lsdb.findAdjLsa(lsaKey);
+ BOOST_REQUIRE(lsa != nullptr);
+ BOOST_CHECK_EQUAL(lsa->getAdl().getSize(), 1);
+
+ // Receive HELLO response from Router B
+ receiveHelloData(neighborBName, conf.getRouterPrefix());
+
+ // Both routers become INACTIVE and HELLO Interests have timed out
+ for (Adjacent& adjacency : neighbors.getAdjList()) {
+ adjacency.setStatus(Adjacent::STATUS_INACTIVE);
+ adjacency.setInterestTimedOutNo(HELLO_RETRIES_DEFAULT);
+ }
+
+ this->advanceClocks(ndn::time::seconds(1));
+
+ // Adjacency LSA should have been removed since this router's adjacencies are INACTIVE
+ // and have timed out
+ lsa = lsdb.findAdjLsa(lsaKey);
+ BOOST_CHECK(lsa == nullptr);
+
+ // Receive HELLO response from Router A and B
+ receiveHelloData(neighborAName, conf.getRouterPrefix());
+ receiveHelloData(neighborBName, conf.getRouterPrefix());
+ this->advanceClocks(ndn::time::seconds(1));
+
+ // Adjacency LSA should be built
+ lsa = lsdb.findAdjLsa(lsaKey);
+ BOOST_REQUIRE(lsa != nullptr);
+ BOOST_CHECK_EQUAL(lsa->getAdl().getSize(), 2);
+}
+
BOOST_AUTO_TEST_SUITE_END()
} //namespace test