blob: 94120c005539bb4ef303c542ab0bfdd894e0cca0 [file] [log] [blame]
Yanbiao Lif48d0802018-06-01 03:00:02 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesavento0a71dd32019-03-17 20:36:18 -04003 * Copyright (c) 2014-2019, 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
32#include <ndn-cxx/security/signing-helpers.hpp>
33
34namespace nfd {
35namespace rib {
36namespace tests {
37
38using namespace nfd::tests;
39
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040040class HostToGatewayReadvertisePolicyFixture : public GlobalIoFixture, public KeyChainFixture
Yanbiao Lif48d0802018-06-01 03:00:02 -070041{
42public:
Davide Pesavento0a71dd32019-03-17 20:36:18 -040043 static RibRouteRef
44 makeNewRoute(const Name& prefix)
45 {
Yanbiao Lif48d0802018-06-01 03:00:02 -070046 auto entry = make_shared<RibEntry>();
47 entry->setName(prefix);
48
49 Route route;
50 auto routeIt = entry->insertRoute(route).first;
51 return RibRouteRef{entry, routeIt};
52 }
53
54 shared_ptr<HostToGatewayReadvertisePolicy>
55 makePolicy(const ConfigSection& section = ConfigSection())
56 {
57 return make_shared<HostToGatewayReadvertisePolicy>(m_keyChain, section);
58 }
59};
60
61BOOST_AUTO_TEST_SUITE(Readvertise)
Davide Pesavento0a71dd32019-03-17 20:36:18 -040062BOOST_FIXTURE_TEST_SUITE(TestHostToGatewayReadvertisePolicy, HostToGatewayReadvertisePolicyFixture)
Yanbiao Lif48d0802018-06-01 03:00:02 -070063
64BOOST_AUTO_TEST_CASE(PrefixToAdvertise)
65{
66 BOOST_REQUIRE(addIdentity("/A"));
67 BOOST_REQUIRE(addIdentity("/A/B"));
68 BOOST_REQUIRE(addIdentity("/C/nrd"));
69
70 auto test = [this] (Name routeName, optional<ReadvertiseAction> expectedAction) {
71 auto policy = makePolicy();
72 auto action = policy->handleNewRoute(makeNewRoute(routeName));
73
74 if (expectedAction) {
75 BOOST_REQUIRE(action);
76 BOOST_CHECK_EQUAL(action->prefix, expectedAction->prefix);
77 BOOST_REQUIRE_EQUAL(action->signer, expectedAction->signer);
78 }
79 else {
80 BOOST_REQUIRE(!action);
81 }
82 };
83
84 test("/D/app", nullopt);
85 test("/A/B/app", ReadvertiseAction{"/A", ndn::security::signingByIdentity("/A")});
86 test("/C/nrd", ReadvertiseAction{"/C", ndn::security::signingByIdentity("/C/nrd")});
87}
88
89BOOST_AUTO_TEST_CASE(DontReadvertise)
90{
91 auto policy = makePolicy();
92 BOOST_REQUIRE(!policy->handleNewRoute(makeNewRoute("/localhost/test")));
93 BOOST_REQUIRE(!policy->handleNewRoute(makeNewRoute("/localhop/nfd")));
94}
95
96BOOST_AUTO_TEST_CASE(LoadRefreshInterval)
97{
98 auto policy = makePolicy();
99 BOOST_CHECK_EQUAL(policy->getRefreshInterval(), time::seconds(25)); // default setting is 25
100
101 ConfigSection section;
102 section.put("refresh_interval_wrong", 10);
103 policy = makePolicy(section);
104 BOOST_CHECK_EQUAL(policy->getRefreshInterval(), time::seconds(25)); // wrong formate
105
106 section.put("refresh_interval", 10);
107 policy = makePolicy(section);
108 BOOST_CHECK_EQUAL(policy->getRefreshInterval(), time::seconds(10));
109}
110
111BOOST_AUTO_TEST_SUITE_END() // TestHostToGatewayReadvertisePolicy
112BOOST_AUTO_TEST_SUITE_END() // Readvertise
113
114} // namespace tests
115} // namespace rib
116} // namespace nfd