| /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| /* |
| * Copyright (c) 2014-2022, 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" |
| #include "tests/daemon/global-io-fixture.hpp" |
| |
| namespace nfd { |
| namespace rib { |
| namespace tests { |
| |
| using namespace nfd::tests; |
| |
| BOOST_FIXTURE_TEST_SUITE(TestRoute, GlobalIoTimeFixture) |
| |
| BOOST_AUTO_TEST_SUITE(CreateFromAnnouncement) |
| |
| 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; |
| 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() + 26782232_ms; |
| 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 = std::nullopt; |
| BOOST_CHECK_NE(a, b); |
| a.expires = std::nullopt; |
| |
| BOOST_CHECK_EQUAL(a, b); |
| } |
| |
| BOOST_AUTO_TEST_CASE(EqualityAnn) |
| { |
| 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_AUTO_TEST_CASE(Output) |
| { |
| 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() + 791214234_ms; |
| BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(r), |
| "Route(faceid: 4980, origin: static, cost: 2312, flags: 0x1, expires in: " |
| "791214234 milliseconds)"); |
| |
| r.expires = std::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 |
| |
| } // namespace tests |
| } // namespace rib |
| } // namespace nfd |