rib: put PrefixAnnouncement in Route and RibEntry
refs #4650
Change-Id: I03a846cd6e013d52f080bd7b092cd392b0284f88
diff --git a/tests/rib/route.t.cpp b/tests/rib/route.t.cpp
index 4d66d0d..b1390b8 100644
--- a/tests/rib/route.t.cpp
+++ b/tests/rib/route.t.cpp
@@ -35,6 +35,59 @@
BOOST_FIXTURE_TEST_SUITE(TestRoute, BaseFixture)
+BOOST_FIXTURE_TEST_SUITE(CreateFromAnnouncement, UnitTestTimeFixture)
+
+BOOST_AUTO_TEST_CASE(NoValidity)
+{
+ auto pa = makePrefixAnn("/A", 212_s);
+ Route route(pa, 1815);
+ BOOST_CHECK_EQUAL(route.faceId, 1815);
+ BOOST_CHECK_EQUAL(route.origin, ndn::nfd::ROUTE_ORIGIN_PREFIXANN);
+ BOOST_CHECK_EQUAL(route.cost, 2048);
+ BOOST_CHECK_EQUAL(route.flags, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+ BOOST_CHECK_EQUAL(route.annExpires, time::steady_clock::now() + 212_s);
+ BOOST_REQUIRE(route.expires);
+ BOOST_CHECK_EQUAL(*route.expires, route.annExpires);
+}
+
+BOOST_AUTO_TEST_CASE(BeforeNotBefore)
+{
+ auto pa = makePrefixAnn("/A", 212_s, {10_s, 80_s});
+ Route route(pa, 1053);
+ BOOST_CHECK_LE(route.annExpires, time::steady_clock::now());
+ BOOST_REQUIRE(route.expires);
+ BOOST_CHECK_LE(*route.expires, time::steady_clock::now());
+}
+
+BOOST_AUTO_TEST_CASE(AfterNotAfter)
+{
+ auto pa = makePrefixAnn("/A", 212_s, {-80_s, -10_s});
+ Route route(pa, 2972);
+ BOOST_CHECK_LE(route.annExpires, time::steady_clock::now());
+ BOOST_REQUIRE(route.expires);
+ BOOST_CHECK_LE(*route.expires, time::steady_clock::now());
+}
+
+BOOST_AUTO_TEST_CASE(ExpirationLtValidity)
+{
+ auto pa = makePrefixAnn("/A", 212_s, {-100_s, 300_s});
+ Route route(pa, 7804);
+ BOOST_CHECK_EQUAL(route.annExpires, time::steady_clock::now() + 212_s);
+ BOOST_REQUIRE(route.expires);
+ BOOST_CHECK_EQUAL(*route.expires, route.annExpires);
+}
+
+BOOST_AUTO_TEST_CASE(ValidityLtExpiration)
+{
+ auto pa = makePrefixAnn("/A", 212_s, {-100_s, 200_s});
+ Route route(pa, 7804);
+ BOOST_CHECK_EQUAL(route.annExpires, time::steady_clock::now() + 200_s);
+ BOOST_REQUIRE(route.expires);
+ BOOST_CHECK_EQUAL(*route.expires, route.annExpires);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // CreateFromAnnouncement
+
BOOST_AUTO_TEST_CASE(Equality)
{
Route a;
@@ -45,7 +98,7 @@
a.origin = b.origin = ndn::nfd::ROUTE_ORIGIN_NLSR;
a.flags = b.flags = ndn::nfd::ROUTE_FLAG_CHILD_INHERIT;
a.cost = b.cost = 28826;
- a.expires = b.expires = time::steady_clock::now() + time::milliseconds(26782232);
+ a.expires = b.expires = time::steady_clock::now() + 26782232_ms;
BOOST_CHECK_EQUAL(a, b);
b.faceId = 18559;
@@ -71,6 +124,15 @@
BOOST_CHECK_EQUAL(a, b);
}
+BOOST_FIXTURE_TEST_CASE(EqualityAnn, UnitTestTimeFixture)
+{
+ auto ann1 = makePrefixAnn("/ann", 1_h);
+ auto ann2 = makePrefixAnn("/ann", 2_h);
+ BOOST_CHECK_EQUAL(Route(ann1, 7001), Route(ann1, 7001));
+ BOOST_CHECK_NE(Route(ann1, 7001), Route(ann1, 7002));
+ BOOST_CHECK_NE(Route(ann1, 7001), Route(ann2, 7001));
+}
+
BOOST_FIXTURE_TEST_CASE(Output, UnitTestTimeFixture)
{
Route r;
@@ -81,13 +143,19 @@
r.origin = ndn::nfd::ROUTE_ORIGIN_STATIC;
r.flags = ndn::nfd::ROUTE_FLAG_CHILD_INHERIT;
r.cost = 2312;
- r.expires = time::steady_clock::now() + time::milliseconds(791214234);
+ r.expires = time::steady_clock::now() + 791214234_ms;
BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(r),
- "Route(faceid: 4980, origin: static, cost: 2312, flags: 0x1, expires in: 791214234 milliseconds)");
+ "Route(faceid: 4980, origin: static, cost: 2312, flags: 0x1, expires in: "
+ "791214234 milliseconds)");
r.expires = nullopt;
BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(r),
"Route(faceid: 4980, origin: static, cost: 2312, flags: 0x1, never expires)");
+
+ r = Route(makePrefixAnn("/ann", 1_h), 3247);
+ BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(r),
+ "Route(faceid: 3247, origin: prefixann, cost: 2048, flags: 0x1, expires in: "
+ "3600000 milliseconds, announcement: (/ann expires=3600000 milliseconds))");
}
BOOST_AUTO_TEST_SUITE_END() // TestRoute