blob: 249dab4f539c66ae0cdef7ea0fef5c5e3544d552 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento8de8a8b2022-05-12 01:26:43 -04002/*
Varun Patila2599da2023-07-12 16:37:15 -07003 * Copyright (c) 2014-2023, The University of Memphis,
Vince Lehmanc2e51f62015-01-20 15:03:11 -06004 * Regents of the University of California,
5 * Arizona Board of Regents.
akmhoque3d06e792014-05-27 16:23:20 -05006 *
7 * This file is part of NLSR (Named-data Link State Routing).
8 * See AUTHORS.md for complete list of NLSR authors and contributors.
9 *
10 * NLSR is free software: you can redistribute it and/or modify it under the terms
11 * of the GNU General Public License as published by the Free Software Foundation,
12 * either version 3 of the License, or (at your option) any later version.
13 *
14 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 * PURPOSE. See the GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
akmhoque3d06e792014-05-27 16:23:20 -050020 **/
Vince Lehman7c603292014-09-11 17:48:16 -050021
Nick Gordonff9a6272017-10-12 13:38:29 -050022#include "conf-file-processor.hpp"
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040023
24#include "tests/boost-test.hpp"
25#include "tests/io-key-chain-fixture.hpp"
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -050026
Nick Gordonff9a6272017-10-12 13:38:29 -050027#include <fstream>
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -050028#include <boost/algorithm/string.hpp>
Davide Pesavento8de8a8b2022-05-12 01:26:43 -040029
Muktadir R Chowdhuryc69da0a2015-12-18 13:24:38 -060030#include <ndn-cxx/util/dummy-client-face.hpp>
31
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050032namespace nlsr {
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050033namespace test {
34
dmcoomes9f936662017-03-02 10:33:09 -060035using std::shared_ptr;
Vince Lehman904c2412014-09-23 19:36:11 -050036
Vince Lehman7b616582014-10-17 16:25:39 -050037const std::string SECTION_GENERAL =
38 "general\n"
39 "{\n"
Davide Pesavento907675b2023-08-02 16:20:55 -040040 " network /ndn\n"
41 " site /memphis.edu\n"
42 " router /cs/pollux\n"
Vince Lehman7b616582014-10-17 16:25:39 -050043 " lsa-refresh-time 1800\n"
44 " lsa-interest-lifetime 3\n"
Alexander Afanasyev1cf1e102014-08-17 19:47:57 -070045 " router-dead-interval 86400\n"
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050046 " sync-protocol psync\n"
Ashlesh Gawandef7da9c52018-02-06 17:36:46 -060047 " sync-interest-lifetime 10000\n"
dulalsaurab82a34c22019-02-04 17:31:21 +000048 " state-dir /tmp\n"
Vince Lehman7b616582014-10-17 16:25:39 -050049 "}\n\n";
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050050
Varun Patila2599da2023-07-12 16:37:15 -070051const std::string SECTION_GENERAL_SVS =
52 "general\n"
53 "{\n"
Davide Pesavento907675b2023-08-02 16:20:55 -040054 " network /ndn\n"
55 " site /memphis.edu\n"
56 " router /cs/pollux\n"
Varun Patila2599da2023-07-12 16:37:15 -070057 " sync-protocol svs\n"
Davide Pesavento907675b2023-08-02 16:20:55 -040058 " state-dir /tmp\n"
Varun Patila2599da2023-07-12 16:37:15 -070059 "}\n\n";
60
Vince Lehman7b616582014-10-17 16:25:39 -050061const std::string SECTION_NEIGHBORS =
62 "neighbors\n"
63 "{\n"
64 " hello-retries 3\n"
65 " hello-timeout 1\n"
66 " hello-interval 60\n\n"
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050067 " adj-lsa-build-interval 10\n"
Vince Lehman7b616582014-10-17 16:25:39 -050068 " neighbor\n"
69 " {\n"
70 " name /ndn/memphis.edu/cs/castor\n"
Ashlesh Gawande7e3f6d72019-01-25 13:13:43 -060071 " face-uri udp://10.0.0.1\n"
Vince Lehman7b616582014-10-17 16:25:39 -050072 " link-cost 20\n"
73 " }\n\n"
74 " neighbor\n"
75 " {\n"
76 " name /ndn/memphis.edu/cs/mira\n"
Ashlesh Gawande7e3f6d72019-01-25 13:13:43 -060077 " face-uri udp://10.0.0.2\n"
Vince Lehman7b616582014-10-17 16:25:39 -050078 " link-cost 30\n"
79 " }\n"
80 "}\n\n";
81
82const std::string SECTION_HYPERBOLIC_ON =
83 "hyperbolic\n"
84 "{\n"
85 " state on\n"
86 " radius 123.456\n"
87 " angle 1.45\n"
88 "}\n\n";
89
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -060090const std::string SECTION_HYPERBOLIC_ANGLES_ON =
91 "hyperbolic\n"
92 "{\n"
93 " state on\n"
94 " radius 123.456\n"
95 " angle 1.45,2.25\n"
96 "}\n\n";
97
Vince Lehman7b616582014-10-17 16:25:39 -050098const std::string SECTION_HYPERBOLIC_OFF =
99 "hyperbolic\n"
100 "{\n"
101 " state off\n"
102 " radius 123.456\n"
103 " angle 1.45\n"
104 "}\n\n";
105
106const std::string SECTION_FIB =
107 "fib\n"
108 "{\n"
109 " max-faces-per-prefix 3\n"
110 " routing-calc-interval 9\n"
111 "}\n\n";
112
113const std::string SECTION_ADVERTISING =
114 "advertising\n"
115 "{\n"
116 " prefix /ndn/edu/memphis/cs/netlab\n"
117 " prefix /ndn/edu/memphis/sports/basketball\n"
118 "}\n";
119
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600120// NEED TO TEST SECURITY SECTION SUCH AS LOADING CERTIFICATE
121
Vince Lehman7b616582014-10-17 16:25:39 -0500122const std::string CONFIG_LINK_STATE = SECTION_GENERAL + SECTION_NEIGHBORS +
123 SECTION_HYPERBOLIC_OFF + SECTION_FIB + SECTION_ADVERTISING;
124
125const std::string CONFIG_HYPERBOLIC = SECTION_GENERAL + SECTION_NEIGHBORS +
126 SECTION_HYPERBOLIC_ON + SECTION_FIB + SECTION_ADVERTISING;
127
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600128const std::string CONFIG_HYPERBOLIC_ANGLES = SECTION_GENERAL + SECTION_NEIGHBORS +
129 SECTION_HYPERBOLIC_ANGLES_ON + SECTION_FIB +
130 SECTION_ADVERTISING;
131
Varun Patila2599da2023-07-12 16:37:15 -0700132const std::string CONFIG_SVS = SECTION_GENERAL_SVS;
133
Davide Pesavento8de8a8b2022-05-12 01:26:43 -0400134class ConfFileProcessorFixture : public IoKeyChainFixture
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500135{
Vince Lehman7b616582014-10-17 16:25:39 -0500136public:
137 ConfFileProcessorFixture()
Davide Pesavento8de8a8b2022-05-12 01:26:43 -0400138 : face(m_io, m_keyChain)
Saurab Dulal427e0122019-11-28 11:58:02 -0600139 , conf(face, m_keyChain, "unit-test-nlsr.conf")
Vince Lehman7b616582014-10-17 16:25:39 -0500140 {
141 }
Vince Lehman904c2412014-09-23 19:36:11 -0500142
Davide Pesavento8de8a8b2022-05-12 01:26:43 -0400143 ~ConfFileProcessorFixture() override
Vince Lehman7b616582014-10-17 16:25:39 -0500144 {
145 remove("unit-test-nlsr.conf");
146 }
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500147
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500148 bool
Davide Pesavento907675b2023-08-02 16:20:55 -0400149 processConfigurationString(std::string_view confString)
Vince Lehman7b616582014-10-17 16:25:39 -0500150 {
151 std::ofstream config;
152 config.open("unit-test-nlsr.conf");
153 config << confString;
154 config.close();
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500155
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600156 ConfFileProcessor processor(conf);
Vince Lehman7b616582014-10-17 16:25:39 -0500157 return processor.processConfFile();
158 }
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500159
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -0500160 void
alvya2228c62014-12-09 10:25:11 -0600161 commentOut(const std::string& key, std::string& config)
162 {
163 boost::replace_all(config, key, ";" + key);
164 }
165
Vince Lehman7b616582014-10-17 16:25:39 -0500166public:
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500167 ndn::util::DummyClientFace face;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600168 ConfParameter conf;
Vince Lehman7b616582014-10-17 16:25:39 -0500169};
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500170
Vince Lehman7b616582014-10-17 16:25:39 -0500171BOOST_FIXTURE_TEST_SUITE(TestConfFileProcessor, ConfFileProcessorFixture)
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500172
Vince Lehman7b616582014-10-17 16:25:39 -0500173BOOST_AUTO_TEST_CASE(LinkState)
174{
Davide Pesavento907675b2023-08-02 16:20:55 -0400175 BOOST_REQUIRE(processConfigurationString(CONFIG_LINK_STATE));
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500176 conf.buildRouterAndSyncUserPrefix();
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500177
Vince Lehman7b616582014-10-17 16:25:39 -0500178 // General
Davide Pesavento907675b2023-08-02 16:20:55 -0400179 BOOST_CHECK_EQUAL(conf.getNetwork(), "/ndn");
180 BOOST_CHECK_EQUAL(conf.getSiteName(), "/memphis.edu");
181 BOOST_CHECK_EQUAL(conf.getRouterName(), "/cs/pollux");
182 BOOST_CHECK_EQUAL(conf.getRouterPrefix(), "/ndn/memphis.edu/cs/pollux");
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600183 BOOST_CHECK_EQUAL(conf.getSyncPrefix(), ndn::Name("/localhop/ndn/nlsr/sync").appendVersion(ConfParameter::SYNC_VERSION));
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -0500184 BOOST_CHECK_EQUAL(conf.getLsaPrefix(), "/localhop/ndn/nlsr/LSA");
Vince Lehman7b616582014-10-17 16:25:39 -0500185 BOOST_CHECK_EQUAL(conf.getLsaRefreshTime(), 1800);
Davide Pesavento1954a0c2022-09-30 15:56:04 -0400186 BOOST_CHECK(conf.getSyncProtocol() == SyncProtocol::PSYNC);
Vince Lehman7b616582014-10-17 16:25:39 -0500187 BOOST_CHECK_EQUAL(conf.getLsaInterestLifetime(), ndn::time::seconds(3));
Alexander Afanasyev1cf1e102014-08-17 19:47:57 -0700188 BOOST_CHECK_EQUAL(conf.getRouterDeadInterval(), 86400);
Ashlesh Gawandef7da9c52018-02-06 17:36:46 -0600189 BOOST_CHECK_EQUAL(conf.getSyncInterestLifetime(), ndn::time::milliseconds(10000));
dulalsaurab82a34c22019-02-04 17:31:21 +0000190 BOOST_CHECK_EQUAL(conf.getStateFileDir(), "/tmp");
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700191
Vince Lehman7b616582014-10-17 16:25:39 -0500192 // Neighbors
193 BOOST_CHECK_EQUAL(conf.getInterestRetryNumber(), 3);
194 BOOST_CHECK_EQUAL(conf.getInterestResendTime(), 1);
195 BOOST_CHECK_EQUAL(conf.getInfoInterestInterval(), 60);
196
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500197 BOOST_CHECK_EQUAL(conf.getAdjLsaBuildInterval(), 10);
Vince Lehman7b616582014-10-17 16:25:39 -0500198
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600199 BOOST_CHECK(conf.getAdjacencyList().isNeighbor("/ndn/memphis.edu/cs/mira"));
200 BOOST_CHECK(conf.getAdjacencyList().isNeighbor("/ndn/memphis.edu/cs/castor"));
201 BOOST_CHECK(!conf.getAdjacencyList().isNeighbor("/ndn/memphis.edu/cs/fail"));
Vince Lehman7b616582014-10-17 16:25:39 -0500202
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600203 Adjacent mira = conf.getAdjacencyList().getAdjacent("/ndn/memphis.edu/cs/mira");
Vince Lehman7b616582014-10-17 16:25:39 -0500204 BOOST_CHECK_EQUAL(mira.getName(), "/ndn/memphis.edu/cs/mira");
205 BOOST_CHECK_EQUAL(mira.getLinkCost(), 30);
Ashlesh Gawande7e3f6d72019-01-25 13:13:43 -0600206 BOOST_CHECK_EQUAL(mira.getFaceUri().toString(), "udp4://10.0.0.2:6363");
Vince Lehman7b616582014-10-17 16:25:39 -0500207
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600208 Adjacent castor = conf.getAdjacencyList().getAdjacent("/ndn/memphis.edu/cs/castor");
Vince Lehman7b616582014-10-17 16:25:39 -0500209 BOOST_CHECK_EQUAL(castor.getName(), "/ndn/memphis.edu/cs/castor");
210 BOOST_CHECK_EQUAL(castor.getLinkCost(), 20);
Ashlesh Gawande7e3f6d72019-01-25 13:13:43 -0600211 BOOST_CHECK_EQUAL(castor.getFaceUri().toString(), "udp4://10.0.0.1:6363");
Vince Lehman7b616582014-10-17 16:25:39 -0500212
213 // Hyperbolic
214 BOOST_CHECK_EQUAL(conf.getHyperbolicState(), 0);
215
216 // FIB
217 BOOST_CHECK_EQUAL(conf.getMaxFacesPerPrefix(), 3);
218 BOOST_CHECK_EQUAL(conf.getRoutingCalcInterval(), 9);
219
220 // Advertising
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600221 BOOST_CHECK_EQUAL(conf.getNamePrefixList().size(), 2);
Vince Lehman7b616582014-10-17 16:25:39 -0500222}
223
Davide Pesavento907675b2023-08-02 16:20:55 -0400224BOOST_AUTO_TEST_CASE(SvsPrefix)
Varun Patila2599da2023-07-12 16:37:15 -0700225{
Davide Pesavento907675b2023-08-02 16:20:55 -0400226#ifdef HAVE_SVS
227 BOOST_REQUIRE(processConfigurationString(CONFIG_SVS));
Varun Patila2599da2023-07-12 16:37:15 -0700228 conf.buildRouterAndSyncUserPrefix();
229
230 // SVS does not use localhop
Davide Pesavento907675b2023-08-02 16:20:55 -0400231 BOOST_CHECK_EQUAL(conf.getNetwork(), "/ndn");
Varun Patila2599da2023-07-12 16:37:15 -0700232 BOOST_CHECK_EQUAL(conf.getSyncPrefix(), ndn::Name("/ndn/nlsr/sync").appendVersion(ConfParameter::SYNC_VERSION));
Davide Pesavento907675b2023-08-02 16:20:55 -0400233#else
234 BOOST_CHECK_EQUAL(processConfigurationString(CONFIG_SVS), false);
235#endif
Varun Patila2599da2023-07-12 16:37:15 -0700236}
237
alvy2fe12872014-11-25 10:32:23 -0600238BOOST_AUTO_TEST_CASE(MalformedUri)
239{
240 const std::string MALFORMED_URI =
241 "neighbors\n"
242 "{\n"
243 " hello-retries 3\n"
244 " hello-timeout 1\n"
245 " hello-interval 60\n\n"
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500246 " adj-lsa-build-interval 10\n"
alvy2fe12872014-11-25 10:32:23 -0600247 " neighbor\n"
248 " {\n"
249 " name /ndn/memphis.edu/cs/castor\n"
250 " face-uri udp4:malformed-uri\n"
251 " link-cost 20\n"
252 " }\n"
253 "}\n\n";
254
255 BOOST_CHECK_EQUAL(processConfigurationString(MALFORMED_URI), false);
256}
257
Vince Lehman7b616582014-10-17 16:25:39 -0500258BOOST_AUTO_TEST_CASE(Hyperbolic)
259{
Davide Pesavento907675b2023-08-02 16:20:55 -0400260 BOOST_REQUIRE(processConfigurationString(CONFIG_HYPERBOLIC));
Vince Lehman7b616582014-10-17 16:25:39 -0500261
Vince Lehman7b616582014-10-17 16:25:39 -0500262 BOOST_CHECK_EQUAL(conf.getHyperbolicState(), 1);
263 BOOST_CHECK_EQUAL(conf.getCorR(), 123.456);
Davide Pesavento907675b2023-08-02 16:20:55 -0400264 std::vector<double> angles{1.45};
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600265 BOOST_CHECK(conf.getCorTheta() == angles);
266}
267
268BOOST_AUTO_TEST_CASE(Hyperbolic2)
269{
Davide Pesavento907675b2023-08-02 16:20:55 -0400270 BOOST_REQUIRE(processConfigurationString(CONFIG_HYPERBOLIC_ANGLES));
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600271
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600272 BOOST_CHECK_EQUAL(conf.getHyperbolicState(), 1);
273 BOOST_CHECK_EQUAL(conf.getCorR(), 123.456);
Davide Pesavento907675b2023-08-02 16:20:55 -0400274 std::vector<double> angles{1.45, 2.25};
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600275 BOOST_CHECK(conf.getCorTheta() == angles);
Vince Lehman7b616582014-10-17 16:25:39 -0500276}
277
alvya2228c62014-12-09 10:25:11 -0600278BOOST_AUTO_TEST_CASE(DefaultValuesGeneral)
Vince Lehman7b616582014-10-17 16:25:39 -0500279{
alvya2228c62014-12-09 10:25:11 -0600280 std::string config = SECTION_GENERAL;
Vince Lehman7b616582014-10-17 16:25:39 -0500281
alvya2228c62014-12-09 10:25:11 -0600282 commentOut("lsa-refresh-time", config);
283 commentOut("lsa-interest-lifetime", config);
284 commentOut("router-dead-interval", config);
285
Davide Pesavento907675b2023-08-02 16:20:55 -0400286 BOOST_REQUIRE(processConfigurationString(config));
Vince Lehman7b616582014-10-17 16:25:39 -0500287
alvy5a454952014-12-15 12:49:54 -0600288 BOOST_CHECK_EQUAL(conf.getLsaRefreshTime(), static_cast<uint32_t>(LSA_REFRESH_TIME_DEFAULT));
alvya2228c62014-12-09 10:25:11 -0600289 BOOST_CHECK_EQUAL(conf.getLsaInterestLifetime(),
290 static_cast<ndn::time::seconds>(LSA_INTEREST_LIFETIME_DEFAULT));
Ashlesh Gawande328fc112019-12-12 17:06:44 -0600291 BOOST_CHECK_EQUAL(conf.getRouterDeadInterval(), (2 * conf.getLsaRefreshTime()));
292
Davide Pesavento907675b2023-08-02 16:20:55 -0400293 BOOST_CHECK_NE(conf.m_confFileName, conf.getConfFileNameDynamic());
Ashlesh Gawande328fc112019-12-12 17:06:44 -0600294 conf.m_confFileName = "/tmp/nlsr.conf";
Davide Pesavento907675b2023-08-02 16:20:55 -0400295 BOOST_CHECK_EQUAL(conf.m_confFileName, conf.getConfFileNameDynamic());
296 BOOST_CHECK_EQUAL(processConfigurationString(config), false);
alvya2228c62014-12-09 10:25:11 -0600297}
298
299BOOST_AUTO_TEST_CASE(DefaultValuesNeighbors)
300{
301 std::string config = SECTION_NEIGHBORS;
302
303 commentOut("hello-retries", config);
304 commentOut("hello-timeout", config);
305 commentOut("hello-interval", config);
306 commentOut("first-hello-interval", config);
307 commentOut("adj-lsa-build-interval", config);
308
Davide Pesavento907675b2023-08-02 16:20:55 -0400309 BOOST_REQUIRE(processConfigurationString(config));
alvya2228c62014-12-09 10:25:11 -0600310
alvya2228c62014-12-09 10:25:11 -0600311 BOOST_CHECK_EQUAL(conf.getInterestRetryNumber(), static_cast<uint32_t>(HELLO_RETRIES_DEFAULT));
alvy5a454952014-12-15 12:49:54 -0600312 BOOST_CHECK_EQUAL(conf.getInterestResendTime(), static_cast<uint32_t>(HELLO_TIMEOUT_DEFAULT));
313 BOOST_CHECK_EQUAL(conf.getInfoInterestInterval(), static_cast<uint32_t>(HELLO_INTERVAL_DEFAULT));
Vince Lehman7b616582014-10-17 16:25:39 -0500314 BOOST_CHECK_EQUAL(conf.getAdjLsaBuildInterval(),
315 static_cast<uint32_t>(ADJ_LSA_BUILD_INTERVAL_DEFAULT));
alvya2228c62014-12-09 10:25:11 -0600316}
Vince Lehman7b616582014-10-17 16:25:39 -0500317
Ashlesh Gawande9ecbdc92019-03-11 13:18:45 -0700318BOOST_AUTO_TEST_CASE(CanonizeNeighbors)
319{
Davide Pesavento907675b2023-08-02 16:20:55 -0400320 std::string config{R"INFO(neighbors
Ashlesh Gawande9ecbdc92019-03-11 13:18:45 -0700321 {
322 neighbor
323 {
324 name /ndn/edu/arizona/%C1.Router/hobo
325 face-uri udp4://hobo.cs.arizona.edu
326 link-cost 20
327 }
328 neighbor
329 {
330 name /ndn/edu/umich/%C1.Router/ndn0
331 face-uri udp4://michigan.testbed.named-data.net
332 link-cost 30
333 }
Davide Pesavento907675b2023-08-02 16:20:55 -0400334 })INFO"};
Ashlesh Gawande9ecbdc92019-03-11 13:18:45 -0700335
Davide Pesavento907675b2023-08-02 16:20:55 -0400336 BOOST_REQUIRE(processConfigurationString(config));
Ashlesh Gawande9ecbdc92019-03-11 13:18:45 -0700337
338 BOOST_CHECK_EQUAL(conf.m_adjl.getAdjacent("/ndn/edu/arizona/%C1.Router/hobo").getFaceUri().toString(),
339 "udp4://128.196.203.36:6363");
340 BOOST_CHECK_EQUAL(conf.m_adjl.getAdjacent("/ndn/edu/umich/%C1.Router/ndn0").getFaceUri().toString(),
341 "udp4://198.111.224.197:6363");
342}
343
alvya2228c62014-12-09 10:25:11 -0600344BOOST_AUTO_TEST_CASE(DefaultValuesFib)
345{
346 std::string config = SECTION_FIB;
347
348 commentOut("max-faces-per-prefix", config);
349 commentOut("routing-calc-interval", config);
350
Davide Pesavento907675b2023-08-02 16:20:55 -0400351 BOOST_REQUIRE(processConfigurationString(config));
alvya2228c62014-12-09 10:25:11 -0600352
alvya2228c62014-12-09 10:25:11 -0600353 BOOST_CHECK_EQUAL(conf.getMaxFacesPerPrefix(),
354 static_cast<uint32_t>(MAX_FACES_PER_PREFIX_DEFAULT));
355 BOOST_CHECK_EQUAL(conf.getRoutingCalcInterval(),
356 static_cast<uint32_t>(ROUTING_CALC_INTERVAL_DEFAULT));
357}
358
359BOOST_AUTO_TEST_CASE(DefaultValuesHyperbolic)
360{
361 std::string config = SECTION_HYPERBOLIC_ON;
362
363 commentOut("state", config);
364
Davide Pesavento907675b2023-08-02 16:20:55 -0400365 BOOST_REQUIRE(processConfigurationString(config));
alvya2228c62014-12-09 10:25:11 -0600366
alvya2228c62014-12-09 10:25:11 -0600367 BOOST_CHECK_EQUAL(conf.getHyperbolicState(), static_cast<int32_t>(HYPERBOLIC_STATE_DEFAULT));
Vince Lehman7b616582014-10-17 16:25:39 -0500368}
369
370BOOST_AUTO_TEST_CASE(OutOfRangeValue)
371{
372 const std::string SECTION_FIB_OUT_OF_RANGE =
373 "fib\n"
374 "{\n"
375 " max-faces-per-prefix 3\n"
376 " routing-calc-interval 999\n" // Larger than max value
377 "}\n\n";
378
379 // Processing should fail due to out of range value
380 BOOST_CHECK_EQUAL(processConfigurationString(SECTION_FIB_OUT_OF_RANGE), false);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500381}
382
alvy5a454952014-12-15 12:49:54 -0600383BOOST_AUTO_TEST_CASE(NegativeValue)
384{
385 const std::string SECTION_GENERAL_NEGATIVE_VALUE =
386 "general\n"
387 "{\n"
388 " network /ndn/\n"
389 " site /memphis.edu/\n"
390 " router /cs/pollux/\n"
391 " lsa-refresh-time -1800\n"
392 " lsa-interest-lifetime -3\n"
393 " router-dead-interval -86400\n"
394 "}\n\n";
395
396 // Processing should fail due to negative value
397 BOOST_CHECK_EQUAL(processConfigurationString(SECTION_GENERAL_NEGATIVE_VALUE), false);
398}
399
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500400BOOST_AUTO_TEST_CASE(LoadCertToPublish)
401{
Davide Pesavento8de8a8b2022-05-12 01:26:43 -0400402 auto identity = m_keyChain.createIdentity("/TestNLSR/identity");
403 saveIdentityCert(identity, "cert-to-publish.cert");
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500404
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500405 const std::string SECTION_SECURITY = R"CONF(
406 security
407 {
408 validator
409 {
410 trust-anchor
411 {
412 type any
413 }
414 }
415 prefix-update-validator
416 {
417 trust-anchor
418 {
419 type any
420 }
421 }
422 cert-to-publish "cert-to-publish.cert"
423 }
424 )CONF";
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500425
Davide Pesavento907675b2023-08-02 16:20:55 -0400426 BOOST_REQUIRE(processConfigurationString(SECTION_SECURITY));
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500427}
428
Vince Lehmand33e5bc2015-06-22 15:27:50 -0500429BOOST_AUTO_TEST_CASE(PrefixUpdateValidatorOptional) // Bug #2814
430{
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500431 const std::string SECTION_SECURITY = R"CONF(
432 security
433 {
434 validator
435 {
436 trust-anchor
437 {
438 type any
439 }
440 }
441 }
442 )CONF";
Vince Lehmand33e5bc2015-06-22 15:27:50 -0500443
Davide Pesavento907675b2023-08-02 16:20:55 -0400444 BOOST_REQUIRE(processConfigurationString(SECTION_SECURITY));
Vince Lehmand33e5bc2015-06-22 15:27:50 -0500445}
446
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500447BOOST_AUTO_TEST_SUITE_END()
448
Nick Gordonfad8e252016-08-11 14:21:38 -0500449} // namespace test
450} // namespace nlsr