blob: 1b357cb35f489bbd91a32c97570128cf44d3deb2 [file] [log] [blame]
Yanbiao Lif48d0802018-06-01 03:00:02 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2014-2018, Regents of the University of California,
4 * 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
28#include "tests/identity-management-fixture.hpp"
29
30#include <ndn-cxx/security/signing-helpers.hpp>
31
32namespace nfd {
33namespace rib {
34namespace tests {
35
36using namespace nfd::tests;
37
38class HostToGatewayReadvertisePolicyFixture : public IdentityManagementFixture
39{
40public:
41 RibRouteRef
42 makeNewRoute(const Name& prefix) {
43 auto entry = make_shared<RibEntry>();
44 entry->setName(prefix);
45
46 Route route;
47 auto routeIt = entry->insertRoute(route).first;
48 return RibRouteRef{entry, routeIt};
49 }
50
51 shared_ptr<HostToGatewayReadvertisePolicy>
52 makePolicy(const ConfigSection& section = ConfigSection())
53 {
54 return make_shared<HostToGatewayReadvertisePolicy>(m_keyChain, section);
55 }
56};
57
58BOOST_AUTO_TEST_SUITE(Readvertise)
59BOOST_FIXTURE_TEST_SUITE(TestHostToGatewayReadvertisePolicy,
60 HostToGatewayReadvertisePolicyFixture)
61
62BOOST_AUTO_TEST_CASE(PrefixToAdvertise)
63{
64 BOOST_REQUIRE(addIdentity("/A"));
65 BOOST_REQUIRE(addIdentity("/A/B"));
66 BOOST_REQUIRE(addIdentity("/C/nrd"));
67
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();
97 BOOST_CHECK_EQUAL(policy->getRefreshInterval(), time::seconds(25)); // default setting is 25
98
99 ConfigSection section;
100 section.put("refresh_interval_wrong", 10);
101 policy = makePolicy(section);
102 BOOST_CHECK_EQUAL(policy->getRefreshInterval(), time::seconds(25)); // wrong formate
103
104 section.put("refresh_interval", 10);
105 policy = makePolicy(section);
106 BOOST_CHECK_EQUAL(policy->getRefreshInterval(), time::seconds(10));
107}
108
109BOOST_AUTO_TEST_SUITE_END() // TestHostToGatewayReadvertisePolicy
110BOOST_AUTO_TEST_SUITE_END() // Readvertise
111
112} // namespace tests
113} // namespace rib
114} // namespace nfd