rib: simplify Route class
Route::expires is changed to an optional, with nullopt representing
"never expires". This avoids an integer overflow.
RouteFlags accessors are now provided by ndn::nfd::RouteFlagsTraits.
Stream insertion operator is improved.
refs #3502
Change-Id: Ia912eab771fb00020385bf84d486955feae6aafa
diff --git a/tests/rib/fib-updates-common.hpp b/tests/rib/fib-updates-common.hpp
index 59505bc..925ca81 100644
--- a/tests/rib/fib-updates-common.hpp
+++ b/tests/rib/fib-updates-common.hpp
@@ -72,7 +72,7 @@
void
insertRoute(const Name& name, uint64_t faceId,
std::underlying_type<ndn::nfd::RouteOrigin>::type origin,
- uint64_t cost, uint64_t flags)
+ uint64_t cost, std::underlying_type<ndn::nfd::RouteFlags>::type flags)
{
Route route = createRoute(faceId, origin, cost, flags);
diff --git a/tests/rib/rib-manager.t.cpp b/tests/rib/rib-manager.t.cpp
index 117b264..42e8c93 100644
--- a/tests/rib/rib-manager.t.cpp
+++ b/tests/rib/rib-manager.t.cpp
@@ -434,7 +434,7 @@
Route route;
route.faceId = ++faceId;
route.cost = route.faceId * 10;
- route.expires = time::steady_clock::TimePoint::max();
+ route.expires = ndn::nullopt;
return route;
};
diff --git a/tests/rib/rib-test-common.hpp b/tests/rib/rib-test-common.hpp
index 3a09d4b..8cddafe 100644
--- a/tests/rib/rib-test-common.hpp
+++ b/tests/rib/rib-test-common.hpp
@@ -36,7 +36,7 @@
createRoute(uint64_t faceId,
std::underlying_type<ndn::nfd::RouteOrigin>::type origin,
uint64_t cost = 0,
- uint64_t flags = 0)
+ std::underlying_type<ndn::nfd::RouteFlags>::type flags = ndn::nfd::ROUTE_FLAGS_NONE)
{
Route temp;
temp.faceId = faceId;
diff --git a/tests/rib/rib.t.cpp b/tests/rib/rib.t.cpp
index d856f94..e572a72 100644
--- a/tests/rib/rib.t.cpp
+++ b/tests/rib/rib.t.cpp
@@ -291,31 +291,31 @@
Route root = createRoute(1, 20);
Name name1("/");
- root.expires = time::steady_clock::TimePoint::max();
+ root.expires = ndn::nullopt;
rib.insert(name1, root);
Route route1 = createRoute(2, 20);
Name name2("/hello");
- route1.expires = time::steady_clock::TimePoint::max();
+ route1.expires = ndn::nullopt;
rib.insert(name2, route1);
Route route2 = createRoute(3, 20);
Name name3("/hello/world");
- route2.expires = time::steady_clock::TimePoint::max();
+ route2.expires = ndn::nullopt;
rib.insert(name3, route2);
const std::string ribStr = std::string(R"TEXT(
RibEntry {
- Name: /
- Route(faceid: 1, origin: 20, cost: 0, flags: 0, never expires)
+ Name: /
+ Route(faceid: 1, origin: 20, cost: 0, flags: 0x0, never expires)
}
RibEntry {
- Name: /hello
- Route(faceid: 2, origin: 20, cost: 0, flags: 0, never expires)
+ Name: /hello
+ Route(faceid: 2, origin: 20, cost: 0, flags: 0x0, never expires)
}
RibEntry {
- Name: /hello/world
- Route(faceid: 3, origin: 20, cost: 0, flags: 0, never expires)
+ Name: /hello/world
+ Route(faceid: 3, origin: 20, cost: 0, flags: 0x0, never expires)
}
)TEXT").substr(1);
diff --git a/tests/rib/route.t.cpp b/tests/rib/route.t.cpp
new file mode 100644
index 0000000..d7b70eb
--- /dev/null
+++ b/tests/rib/route.t.cpp
@@ -0,0 +1,96 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2017, 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 "rib/route.hpp"
+#include "tests/test-common.hpp"
+
+namespace nfd {
+namespace rib {
+namespace tests {
+
+using namespace nfd::tests;
+
+BOOST_FIXTURE_TEST_SUITE(TestRoute, BaseFixture)
+
+BOOST_AUTO_TEST_CASE(Equality)
+{
+ Route a;
+ Route b;
+ BOOST_CHECK_EQUAL(a, b);
+
+ a.faceId = b.faceId = 15404;
+ 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);
+ BOOST_CHECK_EQUAL(a, b);
+
+ b.faceId = 18559;
+ BOOST_CHECK_NE(a, b);
+ a.faceId = 18559;
+
+ b.origin = ndn::nfd::ROUTE_ORIGIN_CLIENT;
+ BOOST_CHECK_NE(a, b);
+ a.origin = ndn::nfd::ROUTE_ORIGIN_CLIENT;
+
+ b.flags = ndn::nfd::ROUTE_FLAG_CAPTURE;
+ BOOST_CHECK_NE(a, b);
+ a.flags = ndn::nfd::ROUTE_FLAG_CAPTURE;
+
+ b.cost = 103;
+ BOOST_CHECK_NE(a, b);
+ a.cost = 103;
+
+ b.expires = ndn::nullopt;
+ BOOST_CHECK_NE(a, b);
+ a.expires = ndn::nullopt;
+
+ BOOST_CHECK_EQUAL(a, b);
+}
+
+BOOST_FIXTURE_TEST_CASE(Output, UnitTestTimeFixture)
+{
+ Route r;
+ BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(r),
+ "Route(faceid: 0, origin: app, cost: 0, flags: 0x0, never expires)");
+
+ r.faceId = 4980;
+ 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);
+ BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(r),
+ "Route(faceid: 4980, origin: static, cost: 2312, flags: 0x1, expires in: 791214234 milliseconds)");
+
+ r.expires = ndn::nullopt;
+ BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(r),
+ "Route(faceid: 4980, origin: static, cost: 2312, flags: 0x1, never expires)");
+}
+
+BOOST_AUTO_TEST_SUITE_END() // TestRoute
+
+} // namespace tests
+} // namespace rib
+} // namespace nfd