blob: 336aa11a1e6a6bb3435eb40356e7ae754a22392c [file] [log] [blame]
Junxiao Shib8590312016-12-29 21:22:25 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi0ba6d642017-07-17 00:53:22 +00002/*
Davide Pesaventoe422f9e2022-06-03 01:30:23 -04003 * Copyright (c) 2014-2022, Regents of the University of California,
Junxiao Shib8590312016-12-29 21:22:25 +00004 * 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 "face/face-system.hpp"
Junxiao Shi38b24c72017-01-05 02:59:31 +000027#include "face-system-fixture.hpp"
Junxiao Shib8590312016-12-29 21:22:25 +000028
Junxiao Shib8590312016-12-29 21:22:25 +000029#include "tests/test-common.hpp"
30
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040031namespace nfd::tests {
32
33using namespace nfd::face;
Junxiao Shib8590312016-12-29 21:22:25 +000034
Junxiao Shi38b24c72017-01-05 02:59:31 +000035BOOST_AUTO_TEST_SUITE(Face)
36BOOST_FIXTURE_TEST_SUITE(TestFaceSystem, FaceSystemFixture)
37
38BOOST_AUTO_TEST_SUITE(ProcessConfig)
39
Junxiao Shi38b24c72017-01-05 02:59:31 +000040BOOST_AUTO_TEST_CASE(Normal)
41{
Junxiao Shi0ba6d642017-07-17 00:53:22 +000042 faceSystem.m_factories["f1"] = make_unique<DummyProtocolFactory>(faceSystem.makePFCtorParams());
43 faceSystem.m_factories["f2"] = make_unique<DummyProtocolFactory>(faceSystem.makePFCtorParams());
Junxiao Shib47247d2017-01-24 15:09:16 +000044 auto f1 = static_cast<DummyProtocolFactory*>(faceSystem.getFactoryById("f1"));
45 auto f2 = static_cast<DummyProtocolFactory*>(faceSystem.getFactoryById("f2"));
Junxiao Shi38b24c72017-01-05 02:59:31 +000046
47 const std::string CONFIG = R"CONFIG(
48 face_system
49 {
Eric Newberry0c841642018-01-17 15:01:00 -070050 general
51 {
52 enable_congestion_marking yes
53 }
Junxiao Shi38b24c72017-01-05 02:59:31 +000054 f1
55 {
56 key v1
57 }
58 f2
59 {
60 key v2
61 }
62 }
63 )CONFIG";
64
Junxiao Shib47247d2017-01-24 15:09:16 +000065 parseConfig(CONFIG, true);
Junxiao Shi38b24c72017-01-05 02:59:31 +000066 BOOST_REQUIRE_EQUAL(f1->processConfigHistory.size(), 1);
Eric Newberry0c841642018-01-17 15:01:00 -070067 BOOST_CHECK(f1->processConfigHistory.back().isDryRun);
68 BOOST_CHECK(f1->processConfigHistory.back().wantCongestionMarking);
Junxiao Shi38b24c72017-01-05 02:59:31 +000069 BOOST_CHECK_EQUAL(f1->processConfigHistory.back().configSection->get<std::string>("key"), "v1");
70 BOOST_REQUIRE_EQUAL(f2->processConfigHistory.size(), 1);
Eric Newberry0c841642018-01-17 15:01:00 -070071 BOOST_CHECK(f2->processConfigHistory.back().isDryRun);
72 BOOST_CHECK(f2->processConfigHistory.back().wantCongestionMarking);
Junxiao Shi38b24c72017-01-05 02:59:31 +000073 BOOST_CHECK_EQUAL(f2->processConfigHistory.back().configSection->get<std::string>("key"), "v2");
74
Junxiao Shib47247d2017-01-24 15:09:16 +000075 parseConfig(CONFIG, false);
Junxiao Shi38b24c72017-01-05 02:59:31 +000076 BOOST_REQUIRE_EQUAL(f1->processConfigHistory.size(), 2);
Eric Newberry0c841642018-01-17 15:01:00 -070077 BOOST_CHECK(!f1->processConfigHistory.back().isDryRun);
78 BOOST_CHECK(f1->processConfigHistory.back().wantCongestionMarking);
Junxiao Shi38b24c72017-01-05 02:59:31 +000079 BOOST_CHECK_EQUAL(f1->processConfigHistory.back().configSection->get<std::string>("key"), "v1");
80 BOOST_REQUIRE_EQUAL(f2->processConfigHistory.size(), 2);
Eric Newberry0c841642018-01-17 15:01:00 -070081 BOOST_CHECK(!f2->processConfigHistory.back().isDryRun);
82 BOOST_CHECK(f2->processConfigHistory.back().wantCongestionMarking);
Junxiao Shi38b24c72017-01-05 02:59:31 +000083 BOOST_CHECK_EQUAL(f2->processConfigHistory.back().configSection->get<std::string>("key"), "v2");
84}
85
86BOOST_AUTO_TEST_CASE(OmittedSection)
87{
Junxiao Shi0ba6d642017-07-17 00:53:22 +000088 faceSystem.m_factories["f1"] = make_unique<DummyProtocolFactory>(faceSystem.makePFCtorParams());
89 faceSystem.m_factories["f2"] = make_unique<DummyProtocolFactory>(faceSystem.makePFCtorParams());
Junxiao Shib47247d2017-01-24 15:09:16 +000090 auto f1 = static_cast<DummyProtocolFactory*>(faceSystem.getFactoryById("f1"));
91 auto f2 = static_cast<DummyProtocolFactory*>(faceSystem.getFactoryById("f2"));
Junxiao Shi38b24c72017-01-05 02:59:31 +000092
93 const std::string CONFIG = R"CONFIG(
94 face_system
95 {
96 f1
97 {
98 }
99 }
100 )CONFIG";
101
Junxiao Shib47247d2017-01-24 15:09:16 +0000102 parseConfig(CONFIG, true);
Junxiao Shi38b24c72017-01-05 02:59:31 +0000103 BOOST_REQUIRE_EQUAL(f1->processConfigHistory.size(), 1);
104 BOOST_CHECK_EQUAL(f1->processConfigHistory.back().isDryRun, true);
105 BOOST_REQUIRE_EQUAL(f2->processConfigHistory.size(), 1);
106 BOOST_CHECK_EQUAL(f2->processConfigHistory.back().isDryRun, true);
107 BOOST_CHECK(!f2->processConfigHistory.back().configSection);
108
Junxiao Shib47247d2017-01-24 15:09:16 +0000109 parseConfig(CONFIG, false);
Junxiao Shi38b24c72017-01-05 02:59:31 +0000110 BOOST_REQUIRE_EQUAL(f1->processConfigHistory.size(), 2);
111 BOOST_CHECK_EQUAL(f1->processConfigHistory.back().isDryRun, false);
112 BOOST_REQUIRE_EQUAL(f2->processConfigHistory.size(), 2);
113 BOOST_CHECK_EQUAL(f2->processConfigHistory.back().isDryRun, false);
114 BOOST_CHECK(!f2->processConfigHistory.back().configSection);
115}
116
117BOOST_AUTO_TEST_CASE(UnknownSection)
118{
119 const std::string CONFIG = R"CONFIG(
120 face_system
121 {
122 f0
123 {
124 }
125 }
126 )CONFIG";
127
128 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
129 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
130}
131
132BOOST_AUTO_TEST_CASE(ChangeProvidedSchemes)
133{
Junxiao Shi0ba6d642017-07-17 00:53:22 +0000134 faceSystem.m_factories["f1"] = make_unique<DummyProtocolFactory>(faceSystem.makePFCtorParams());
Junxiao Shib47247d2017-01-24 15:09:16 +0000135 auto f1 = static_cast<DummyProtocolFactory*>(faceSystem.getFactoryById("f1"));
Junxiao Shi38b24c72017-01-05 02:59:31 +0000136
137 const std::string CONFIG = R"CONFIG(
138 face_system
139 {
140 f1
141 {
142 }
143 }
144 )CONFIG";
145
146 f1->newProvidedSchemes.insert("s1");
147 f1->newProvidedSchemes.insert("s2");
Junxiao Shib47247d2017-01-24 15:09:16 +0000148 parseConfig(CONFIG, false);
Junxiao Shi38b24c72017-01-05 02:59:31 +0000149 BOOST_CHECK(faceSystem.getFactoryByScheme("f1") == nullptr);
Junxiao Shib47247d2017-01-24 15:09:16 +0000150 BOOST_CHECK_EQUAL(faceSystem.getFactoryByScheme("s1"), f1);
151 BOOST_CHECK_EQUAL(faceSystem.getFactoryByScheme("s2"), f1);
Junxiao Shi38b24c72017-01-05 02:59:31 +0000152
153 f1->newProvidedSchemes.erase("s2");
154 f1->newProvidedSchemes.insert("s3");
Junxiao Shib47247d2017-01-24 15:09:16 +0000155 parseConfig(CONFIG, false);
Junxiao Shi38b24c72017-01-05 02:59:31 +0000156 BOOST_CHECK(faceSystem.getFactoryByScheme("f1") == nullptr);
Junxiao Shib47247d2017-01-24 15:09:16 +0000157 BOOST_CHECK_EQUAL(faceSystem.getFactoryByScheme("s1"), f1);
Junxiao Shi38b24c72017-01-05 02:59:31 +0000158 BOOST_CHECK(faceSystem.getFactoryByScheme("s2") == nullptr);
Junxiao Shib47247d2017-01-24 15:09:16 +0000159 BOOST_CHECK_EQUAL(faceSystem.getFactoryByScheme("s3"), f1);
Junxiao Shi38b24c72017-01-05 02:59:31 +0000160}
161
162BOOST_AUTO_TEST_SUITE_END() // ProcessConfig
163
Junxiao Shib8590312016-12-29 21:22:25 +0000164BOOST_AUTO_TEST_SUITE_END() // TestFaceSystem
Junxiao Shieef49a92018-11-10 12:19:36 +0000165BOOST_AUTO_TEST_SUITE_END() // Face
Junxiao Shib8590312016-12-29 21:22:25 +0000166
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400167} // namespace nfd::tests