blob: c0d088a6c6e469d9b1a436362fef0b9b2e46323e [file] [log] [blame]
Yanbiao Lif48d0802018-06-01 03:00:02 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesavento21353752020-11-20 00:43:44 -05003 * Copyright (c) 2014-2020, Regents of the University of California,
Yanbiao Lif48d0802018-06-01 03:00:02 -07004 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26#include "rib/readvertise/host-to-gateway-readvertise-policy.hpp"
27
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040028#include "tests/test-common.hpp"
Davide Pesavento1d12d2f2019-03-22 12:44:14 -040029#include "tests/key-chain-fixture.hpp"
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040030#include "tests/daemon/global-io-fixture.hpp"
Yanbiao Lif48d0802018-06-01 03:00:02 -070031
Yanbiao Lif48d0802018-06-01 03:00:02 -070032namespace nfd {
33namespace rib {
34namespace tests {
35
36using namespace nfd::tests;
37
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040038class HostToGatewayReadvertisePolicyFixture : public GlobalIoFixture, public KeyChainFixture
Yanbiao Lif48d0802018-06-01 03:00:02 -070039{
40public:
Davide Pesavento0a71dd32019-03-17 20:36:18 -040041 static RibRouteRef
42 makeNewRoute(const Name& prefix)
43 {
Yanbiao Lif48d0802018-06-01 03:00:02 -070044 auto entry = make_shared<RibEntry>();
45 entry->setName(prefix);
46
47 Route route;
48 auto routeIt = entry->insertRoute(route).first;
49 return RibRouteRef{entry, routeIt};
50 }
51
52 shared_ptr<HostToGatewayReadvertisePolicy>
53 makePolicy(const ConfigSection& section = ConfigSection())
54 {
55 return make_shared<HostToGatewayReadvertisePolicy>(m_keyChain, section);
56 }
57};
58
59BOOST_AUTO_TEST_SUITE(Readvertise)
Davide Pesavento0a71dd32019-03-17 20:36:18 -040060BOOST_FIXTURE_TEST_SUITE(TestHostToGatewayReadvertisePolicy, HostToGatewayReadvertisePolicyFixture)
Yanbiao Lif48d0802018-06-01 03:00:02 -070061
62BOOST_AUTO_TEST_CASE(PrefixToAdvertise)
63{
Davide Pesavento21353752020-11-20 00:43:44 -050064 BOOST_REQUIRE(m_keyChain.createIdentity("/A"));
65 BOOST_REQUIRE(m_keyChain.createIdentity("/A/B"));
66 BOOST_REQUIRE(m_keyChain.createIdentity("/C/nrd"));
Yanbiao Lif48d0802018-06-01 03:00:02 -070067
68 auto test = [this] (Name routeName, optional<ReadvertiseAction> expectedAction) {
69 auto policy = makePolicy();
70 auto action = policy->handleNewRoute(makeNewRoute(routeName));
71
72 if (expectedAction) {
73 BOOST_REQUIRE(action);
74 BOOST_CHECK_EQUAL(action->prefix, expectedAction->prefix);
75 BOOST_REQUIRE_EQUAL(action->signer, expectedAction->signer);
76 }
77 else {
78 BOOST_REQUIRE(!action);
79 }
80 };
81
82 test("/D/app", nullopt);
83 test("/A/B/app", ReadvertiseAction{"/A", ndn::security::signingByIdentity("/A")});
84 test("/C/nrd", ReadvertiseAction{"/C", ndn::security::signingByIdentity("/C/nrd")});
85}
86
87BOOST_AUTO_TEST_CASE(DontReadvertise)
88{
89 auto policy = makePolicy();
90 BOOST_REQUIRE(!policy->handleNewRoute(makeNewRoute("/localhost/test")));
91 BOOST_REQUIRE(!policy->handleNewRoute(makeNewRoute("/localhop/nfd")));
92}
93
94BOOST_AUTO_TEST_CASE(LoadRefreshInterval)
95{
96 auto policy = makePolicy();
Davide Pesavento14e71f02019-03-28 17:35:25 -040097 BOOST_CHECK_EQUAL(policy->getRefreshInterval(), 25_s); // default setting is 25
Yanbiao Lif48d0802018-06-01 03:00:02 -070098
99 ConfigSection section;
100 section.put("refresh_interval_wrong", 10);
101 policy = makePolicy(section);
Davide Pesavento14e71f02019-03-28 17:35:25 -0400102 BOOST_CHECK_EQUAL(policy->getRefreshInterval(), 25_s); // wrong formate
Yanbiao Lif48d0802018-06-01 03:00:02 -0700103
104 section.put("refresh_interval", 10);
105 policy = makePolicy(section);
Davide Pesavento14e71f02019-03-28 17:35:25 -0400106 BOOST_CHECK_EQUAL(policy->getRefreshInterval(), 10_s);
Yanbiao Lif48d0802018-06-01 03:00:02 -0700107}
108
109BOOST_AUTO_TEST_SUITE_END() // TestHostToGatewayReadvertisePolicy
110BOOST_AUTO_TEST_SUITE_END() // Readvertise
111
112} // namespace tests
113} // namespace rib
114} // namespace nfd