blob: c9acbd27a34790ec79bcbf6a171634b14c472a42 [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/*
Junxiao Shif4674672024-01-06 02:27:36 +00003 * Copyright (c) 2014-2024, 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
Davide Pesavento288141a2024-02-13 17:30:35 -050032namespace nlsr::tests {
Vince Lehman904c2412014-09-23 19:36:11 -050033
Vince Lehman7b616582014-10-17 16:25:39 -050034const std::string SECTION_GENERAL =
35 "general\n"
36 "{\n"
Davide Pesavento907675b2023-08-02 16:20:55 -040037 " network /ndn\n"
38 " site /memphis.edu\n"
39 " router /cs/pollux\n"
Vince Lehman7b616582014-10-17 16:25:39 -050040 " lsa-refresh-time 1800\n"
41 " lsa-interest-lifetime 3\n"
Alexander Afanasyev1cf1e102014-08-17 19:47:57 -070042 " router-dead-interval 86400\n"
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050043 " sync-protocol psync\n"
Ashlesh Gawandef7da9c52018-02-06 17:36:46 -060044 " sync-interest-lifetime 10000\n"
dulalsaurab82a34c22019-02-04 17:31:21 +000045 " state-dir /tmp\n"
Vince Lehman7b616582014-10-17 16:25:39 -050046 "}\n\n";
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050047
Varun Patila2599da2023-07-12 16:37:15 -070048const std::string SECTION_GENERAL_SVS =
49 "general\n"
50 "{\n"
Davide Pesavento907675b2023-08-02 16:20:55 -040051 " network /ndn\n"
52 " site /memphis.edu\n"
53 " router /cs/pollux\n"
Varun Patila2599da2023-07-12 16:37:15 -070054 " sync-protocol svs\n"
Davide Pesavento907675b2023-08-02 16:20:55 -040055 " state-dir /tmp\n"
Varun Patila2599da2023-07-12 16:37:15 -070056 "}\n\n";
57
Vince Lehman7b616582014-10-17 16:25:39 -050058const std::string SECTION_NEIGHBORS =
59 "neighbors\n"
60 "{\n"
61 " hello-retries 3\n"
62 " hello-timeout 1\n"
63 " hello-interval 60\n\n"
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -050064 " adj-lsa-build-interval 10\n"
Vince Lehman7b616582014-10-17 16:25:39 -050065 " neighbor\n"
66 " {\n"
67 " name /ndn/memphis.edu/cs/castor\n"
Ashlesh Gawande7e3f6d72019-01-25 13:13:43 -060068 " face-uri udp://10.0.0.1\n"
Vince Lehman7b616582014-10-17 16:25:39 -050069 " link-cost 20\n"
70 " }\n\n"
71 " neighbor\n"
72 " {\n"
73 " name /ndn/memphis.edu/cs/mira\n"
Ashlesh Gawande7e3f6d72019-01-25 13:13:43 -060074 " face-uri udp://10.0.0.2\n"
Vince Lehman7b616582014-10-17 16:25:39 -050075 " link-cost 30\n"
76 " }\n"
77 "}\n\n";
78
79const std::string SECTION_HYPERBOLIC_ON =
80 "hyperbolic\n"
81 "{\n"
82 " state on\n"
83 " radius 123.456\n"
84 " angle 1.45\n"
85 "}\n\n";
86
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -060087const std::string SECTION_HYPERBOLIC_ANGLES_ON =
88 "hyperbolic\n"
89 "{\n"
90 " state on\n"
91 " radius 123.456\n"
92 " angle 1.45,2.25\n"
93 "}\n\n";
94
Vince Lehman7b616582014-10-17 16:25:39 -050095const std::string SECTION_HYPERBOLIC_OFF =
96 "hyperbolic\n"
97 "{\n"
98 " state off\n"
99 " radius 123.456\n"
100 " angle 1.45\n"
101 "}\n\n";
102
103const std::string SECTION_FIB =
104 "fib\n"
105 "{\n"
106 " max-faces-per-prefix 3\n"
107 " routing-calc-interval 9\n"
108 "}\n\n";
109
110const std::string SECTION_ADVERTISING =
111 "advertising\n"
112 "{\n"
113 " prefix /ndn/edu/memphis/cs/netlab\n"
114 " prefix /ndn/edu/memphis/sports/basketball\n"
115 "}\n";
116
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600117// NEED TO TEST SECURITY SECTION SUCH AS LOADING CERTIFICATE
118
Vince Lehman7b616582014-10-17 16:25:39 -0500119const std::string CONFIG_LINK_STATE = SECTION_GENERAL + SECTION_NEIGHBORS +
120 SECTION_HYPERBOLIC_OFF + SECTION_FIB + SECTION_ADVERTISING;
121
122const std::string CONFIG_HYPERBOLIC = SECTION_GENERAL + SECTION_NEIGHBORS +
123 SECTION_HYPERBOLIC_ON + SECTION_FIB + SECTION_ADVERTISING;
124
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600125const std::string CONFIG_HYPERBOLIC_ANGLES = SECTION_GENERAL + SECTION_NEIGHBORS +
126 SECTION_HYPERBOLIC_ANGLES_ON + SECTION_FIB +
127 SECTION_ADVERTISING;
128
Varun Patila2599da2023-07-12 16:37:15 -0700129const std::string CONFIG_SVS = SECTION_GENERAL_SVS;
130
Davide Pesavento8de8a8b2022-05-12 01:26:43 -0400131class ConfFileProcessorFixture : public IoKeyChainFixture
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500132{
Vince Lehman7b616582014-10-17 16:25:39 -0500133public:
134 ConfFileProcessorFixture()
Davide Pesavento8de8a8b2022-05-12 01:26:43 -0400135 : face(m_io, m_keyChain)
Saurab Dulal427e0122019-11-28 11:58:02 -0600136 , conf(face, m_keyChain, "unit-test-nlsr.conf")
Vince Lehman7b616582014-10-17 16:25:39 -0500137 {
138 }
Vince Lehman904c2412014-09-23 19:36:11 -0500139
Davide Pesavento8de8a8b2022-05-12 01:26:43 -0400140 ~ConfFileProcessorFixture() override
Vince Lehman7b616582014-10-17 16:25:39 -0500141 {
142 remove("unit-test-nlsr.conf");
143 }
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500144
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500145 bool
Davide Pesavento907675b2023-08-02 16:20:55 -0400146 processConfigurationString(std::string_view confString)
Vince Lehman7b616582014-10-17 16:25:39 -0500147 {
148 std::ofstream config;
149 config.open("unit-test-nlsr.conf");
150 config << confString;
151 config.close();
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500152
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600153 ConfFileProcessor processor(conf);
Vince Lehman7b616582014-10-17 16:25:39 -0500154 return processor.processConfFile();
155 }
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500156
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -0500157 void
alvya2228c62014-12-09 10:25:11 -0600158 commentOut(const std::string& key, std::string& config)
159 {
160 boost::replace_all(config, key, ";" + key);
161 }
162
Vince Lehman7b616582014-10-17 16:25:39 -0500163public:
Junxiao Shi43f37a02023-08-09 00:09:00 +0000164 ndn::DummyClientFace face;
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600165 ConfParameter conf;
Vince Lehman7b616582014-10-17 16:25:39 -0500166};
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500167
Vince Lehman7b616582014-10-17 16:25:39 -0500168BOOST_FIXTURE_TEST_SUITE(TestConfFileProcessor, ConfFileProcessorFixture)
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500169
Vince Lehman7b616582014-10-17 16:25:39 -0500170BOOST_AUTO_TEST_CASE(LinkState)
171{
Davide Pesavento907675b2023-08-02 16:20:55 -0400172 BOOST_REQUIRE(processConfigurationString(CONFIG_LINK_STATE));
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500173 conf.buildRouterAndSyncUserPrefix();
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500174
Vince Lehman7b616582014-10-17 16:25:39 -0500175 // General
Davide Pesavento907675b2023-08-02 16:20:55 -0400176 BOOST_CHECK_EQUAL(conf.getNetwork(), "/ndn");
177 BOOST_CHECK_EQUAL(conf.getSiteName(), "/memphis.edu");
178 BOOST_CHECK_EQUAL(conf.getRouterName(), "/cs/pollux");
179 BOOST_CHECK_EQUAL(conf.getRouterPrefix(), "/ndn/memphis.edu/cs/pollux");
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600180 BOOST_CHECK_EQUAL(conf.getSyncPrefix(), ndn::Name("/localhop/ndn/nlsr/sync").appendVersion(ConfParameter::SYNC_VERSION));
Ashlesh Gawandecba0ae22018-03-27 17:57:56 -0500181 BOOST_CHECK_EQUAL(conf.getLsaPrefix(), "/localhop/ndn/nlsr/LSA");
Vince Lehman7b616582014-10-17 16:25:39 -0500182 BOOST_CHECK_EQUAL(conf.getLsaRefreshTime(), 1800);
Davide Pesavento1954a0c2022-09-30 15:56:04 -0400183 BOOST_CHECK(conf.getSyncProtocol() == SyncProtocol::PSYNC);
Vince Lehman7b616582014-10-17 16:25:39 -0500184 BOOST_CHECK_EQUAL(conf.getLsaInterestLifetime(), ndn::time::seconds(3));
Alexander Afanasyev1cf1e102014-08-17 19:47:57 -0700185 BOOST_CHECK_EQUAL(conf.getRouterDeadInterval(), 86400);
Ashlesh Gawandef7da9c52018-02-06 17:36:46 -0600186 BOOST_CHECK_EQUAL(conf.getSyncInterestLifetime(), ndn::time::milliseconds(10000));
dulalsaurab82a34c22019-02-04 17:31:21 +0000187 BOOST_CHECK_EQUAL(conf.getStateFileDir(), "/tmp");
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700188
Vince Lehman7b616582014-10-17 16:25:39 -0500189 // Neighbors
190 BOOST_CHECK_EQUAL(conf.getInterestRetryNumber(), 3);
191 BOOST_CHECK_EQUAL(conf.getInterestResendTime(), 1);
192 BOOST_CHECK_EQUAL(conf.getInfoInterestInterval(), 60);
193
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500194 BOOST_CHECK_EQUAL(conf.getAdjLsaBuildInterval(), 10);
Vince Lehman7b616582014-10-17 16:25:39 -0500195
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600196 BOOST_CHECK(conf.getAdjacencyList().isNeighbor("/ndn/memphis.edu/cs/mira"));
197 BOOST_CHECK(conf.getAdjacencyList().isNeighbor("/ndn/memphis.edu/cs/castor"));
198 BOOST_CHECK(!conf.getAdjacencyList().isNeighbor("/ndn/memphis.edu/cs/fail"));
Vince Lehman7b616582014-10-17 16:25:39 -0500199
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600200 Adjacent mira = conf.getAdjacencyList().getAdjacent("/ndn/memphis.edu/cs/mira");
Vince Lehman7b616582014-10-17 16:25:39 -0500201 BOOST_CHECK_EQUAL(mira.getName(), "/ndn/memphis.edu/cs/mira");
202 BOOST_CHECK_EQUAL(mira.getLinkCost(), 30);
Ashlesh Gawande7e3f6d72019-01-25 13:13:43 -0600203 BOOST_CHECK_EQUAL(mira.getFaceUri().toString(), "udp4://10.0.0.2:6363");
Vince Lehman7b616582014-10-17 16:25:39 -0500204
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600205 Adjacent castor = conf.getAdjacencyList().getAdjacent("/ndn/memphis.edu/cs/castor");
Vince Lehman7b616582014-10-17 16:25:39 -0500206 BOOST_CHECK_EQUAL(castor.getName(), "/ndn/memphis.edu/cs/castor");
207 BOOST_CHECK_EQUAL(castor.getLinkCost(), 20);
Ashlesh Gawande7e3f6d72019-01-25 13:13:43 -0600208 BOOST_CHECK_EQUAL(castor.getFaceUri().toString(), "udp4://10.0.0.1:6363");
Vince Lehman7b616582014-10-17 16:25:39 -0500209
210 // Hyperbolic
Junxiao Shif4674672024-01-06 02:27:36 +0000211 BOOST_CHECK_EQUAL(conf.getHyperbolicState(), HYPERBOLIC_STATE_OFF);
Vince Lehman7b616582014-10-17 16:25:39 -0500212
213 // FIB
214 BOOST_CHECK_EQUAL(conf.getMaxFacesPerPrefix(), 3);
215 BOOST_CHECK_EQUAL(conf.getRoutingCalcInterval(), 9);
216
217 // Advertising
Ashlesh Gawande85998a12017-12-07 22:22:13 -0600218 BOOST_CHECK_EQUAL(conf.getNamePrefixList().size(), 2);
Vince Lehman7b616582014-10-17 16:25:39 -0500219}
220
Davide Pesavento907675b2023-08-02 16:20:55 -0400221BOOST_AUTO_TEST_CASE(SvsPrefix)
Varun Patila2599da2023-07-12 16:37:15 -0700222{
Davide Pesavento907675b2023-08-02 16:20:55 -0400223#ifdef HAVE_SVS
224 BOOST_REQUIRE(processConfigurationString(CONFIG_SVS));
Varun Patila2599da2023-07-12 16:37:15 -0700225 conf.buildRouterAndSyncUserPrefix();
226
227 // SVS does not use localhop
Davide Pesavento907675b2023-08-02 16:20:55 -0400228 BOOST_CHECK_EQUAL(conf.getNetwork(), "/ndn");
Varun Patila2599da2023-07-12 16:37:15 -0700229 BOOST_CHECK_EQUAL(conf.getSyncPrefix(), ndn::Name("/ndn/nlsr/sync").appendVersion(ConfParameter::SYNC_VERSION));
Davide Pesavento907675b2023-08-02 16:20:55 -0400230#else
231 BOOST_CHECK_EQUAL(processConfigurationString(CONFIG_SVS), false);
232#endif
Varun Patila2599da2023-07-12 16:37:15 -0700233}
234
alvy2fe12872014-11-25 10:32:23 -0600235BOOST_AUTO_TEST_CASE(MalformedUri)
236{
237 const std::string MALFORMED_URI =
238 "neighbors\n"
239 "{\n"
240 " hello-retries 3\n"
241 " hello-timeout 1\n"
242 " hello-interval 60\n\n"
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500243 " adj-lsa-build-interval 10\n"
alvy2fe12872014-11-25 10:32:23 -0600244 " neighbor\n"
245 " {\n"
246 " name /ndn/memphis.edu/cs/castor\n"
247 " face-uri udp4:malformed-uri\n"
248 " link-cost 20\n"
249 " }\n"
250 "}\n\n";
251
252 BOOST_CHECK_EQUAL(processConfigurationString(MALFORMED_URI), false);
253}
254
Vince Lehman7b616582014-10-17 16:25:39 -0500255BOOST_AUTO_TEST_CASE(Hyperbolic)
256{
Davide Pesavento907675b2023-08-02 16:20:55 -0400257 BOOST_REQUIRE(processConfigurationString(CONFIG_HYPERBOLIC));
Vince Lehman7b616582014-10-17 16:25:39 -0500258
Junxiao Shif4674672024-01-06 02:27:36 +0000259 BOOST_CHECK_EQUAL(conf.getHyperbolicState(), HYPERBOLIC_STATE_ON);
Vince Lehman7b616582014-10-17 16:25:39 -0500260 BOOST_CHECK_EQUAL(conf.getCorR(), 123.456);
Davide Pesavento907675b2023-08-02 16:20:55 -0400261 std::vector<double> angles{1.45};
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600262 BOOST_CHECK(conf.getCorTheta() == angles);
263}
264
265BOOST_AUTO_TEST_CASE(Hyperbolic2)
266{
Davide Pesavento907675b2023-08-02 16:20:55 -0400267 BOOST_REQUIRE(processConfigurationString(CONFIG_HYPERBOLIC_ANGLES));
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600268
Junxiao Shif4674672024-01-06 02:27:36 +0000269 BOOST_CHECK_EQUAL(conf.getHyperbolicState(), HYPERBOLIC_STATE_ON);
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600270 BOOST_CHECK_EQUAL(conf.getCorR(), 123.456);
Davide Pesavento907675b2023-08-02 16:20:55 -0400271 std::vector<double> angles{1.45, 2.25};
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600272 BOOST_CHECK(conf.getCorTheta() == angles);
Vince Lehman7b616582014-10-17 16:25:39 -0500273}
274
alvya2228c62014-12-09 10:25:11 -0600275BOOST_AUTO_TEST_CASE(DefaultValuesGeneral)
Vince Lehman7b616582014-10-17 16:25:39 -0500276{
alvya2228c62014-12-09 10:25:11 -0600277 std::string config = SECTION_GENERAL;
Vince Lehman7b616582014-10-17 16:25:39 -0500278
alvya2228c62014-12-09 10:25:11 -0600279 commentOut("lsa-refresh-time", config);
280 commentOut("lsa-interest-lifetime", config);
281 commentOut("router-dead-interval", config);
282
Davide Pesavento907675b2023-08-02 16:20:55 -0400283 BOOST_REQUIRE(processConfigurationString(config));
Vince Lehman7b616582014-10-17 16:25:39 -0500284
alvy5a454952014-12-15 12:49:54 -0600285 BOOST_CHECK_EQUAL(conf.getLsaRefreshTime(), static_cast<uint32_t>(LSA_REFRESH_TIME_DEFAULT));
alvya2228c62014-12-09 10:25:11 -0600286 BOOST_CHECK_EQUAL(conf.getLsaInterestLifetime(),
287 static_cast<ndn::time::seconds>(LSA_INTEREST_LIFETIME_DEFAULT));
Ashlesh Gawande328fc112019-12-12 17:06:44 -0600288 BOOST_CHECK_EQUAL(conf.getRouterDeadInterval(), (2 * conf.getLsaRefreshTime()));
289
Davide Pesavento907675b2023-08-02 16:20:55 -0400290 BOOST_CHECK_NE(conf.m_confFileName, conf.getConfFileNameDynamic());
Ashlesh Gawande328fc112019-12-12 17:06:44 -0600291 conf.m_confFileName = "/tmp/nlsr.conf";
Davide Pesavento907675b2023-08-02 16:20:55 -0400292 BOOST_CHECK_EQUAL(conf.m_confFileName, conf.getConfFileNameDynamic());
293 BOOST_CHECK_EQUAL(processConfigurationString(config), false);
alvya2228c62014-12-09 10:25:11 -0600294}
295
296BOOST_AUTO_TEST_CASE(DefaultValuesNeighbors)
297{
298 std::string config = SECTION_NEIGHBORS;
299
300 commentOut("hello-retries", config);
301 commentOut("hello-timeout", config);
302 commentOut("hello-interval", config);
303 commentOut("first-hello-interval", config);
304 commentOut("adj-lsa-build-interval", config);
305
Davide Pesavento907675b2023-08-02 16:20:55 -0400306 BOOST_REQUIRE(processConfigurationString(config));
alvya2228c62014-12-09 10:25:11 -0600307
alvya2228c62014-12-09 10:25:11 -0600308 BOOST_CHECK_EQUAL(conf.getInterestRetryNumber(), static_cast<uint32_t>(HELLO_RETRIES_DEFAULT));
alvy5a454952014-12-15 12:49:54 -0600309 BOOST_CHECK_EQUAL(conf.getInterestResendTime(), static_cast<uint32_t>(HELLO_TIMEOUT_DEFAULT));
310 BOOST_CHECK_EQUAL(conf.getInfoInterestInterval(), static_cast<uint32_t>(HELLO_INTERVAL_DEFAULT));
Vince Lehman7b616582014-10-17 16:25:39 -0500311 BOOST_CHECK_EQUAL(conf.getAdjLsaBuildInterval(),
312 static_cast<uint32_t>(ADJ_LSA_BUILD_INTERVAL_DEFAULT));
alvya2228c62014-12-09 10:25:11 -0600313}
Vince Lehman7b616582014-10-17 16:25:39 -0500314
Ashlesh Gawande9ecbdc92019-03-11 13:18:45 -0700315BOOST_AUTO_TEST_CASE(CanonizeNeighbors)
316{
Davide Pesavento907675b2023-08-02 16:20:55 -0400317 std::string config{R"INFO(neighbors
Ashlesh Gawande9ecbdc92019-03-11 13:18:45 -0700318 {
319 neighbor
320 {
321 name /ndn/edu/arizona/%C1.Router/hobo
322 face-uri udp4://hobo.cs.arizona.edu
323 link-cost 20
324 }
325 neighbor
326 {
327 name /ndn/edu/umich/%C1.Router/ndn0
328 face-uri udp4://michigan.testbed.named-data.net
329 link-cost 30
330 }
Davide Pesavento907675b2023-08-02 16:20:55 -0400331 })INFO"};
Ashlesh Gawande9ecbdc92019-03-11 13:18:45 -0700332
Davide Pesavento907675b2023-08-02 16:20:55 -0400333 BOOST_REQUIRE(processConfigurationString(config));
Ashlesh Gawande9ecbdc92019-03-11 13:18:45 -0700334
335 BOOST_CHECK_EQUAL(conf.m_adjl.getAdjacent("/ndn/edu/arizona/%C1.Router/hobo").getFaceUri().toString(),
336 "udp4://128.196.203.36:6363");
337 BOOST_CHECK_EQUAL(conf.m_adjl.getAdjacent("/ndn/edu/umich/%C1.Router/ndn0").getFaceUri().toString(),
338 "udp4://198.111.224.197:6363");
339}
340
alvya2228c62014-12-09 10:25:11 -0600341BOOST_AUTO_TEST_CASE(DefaultValuesFib)
342{
343 std::string config = SECTION_FIB;
344
345 commentOut("max-faces-per-prefix", config);
346 commentOut("routing-calc-interval", config);
347
Davide Pesavento907675b2023-08-02 16:20:55 -0400348 BOOST_REQUIRE(processConfigurationString(config));
alvya2228c62014-12-09 10:25:11 -0600349
alvya2228c62014-12-09 10:25:11 -0600350 BOOST_CHECK_EQUAL(conf.getMaxFacesPerPrefix(),
351 static_cast<uint32_t>(MAX_FACES_PER_PREFIX_DEFAULT));
352 BOOST_CHECK_EQUAL(conf.getRoutingCalcInterval(),
353 static_cast<uint32_t>(ROUTING_CALC_INTERVAL_DEFAULT));
354}
355
356BOOST_AUTO_TEST_CASE(DefaultValuesHyperbolic)
357{
358 std::string config = SECTION_HYPERBOLIC_ON;
359
360 commentOut("state", config);
361
Davide Pesavento907675b2023-08-02 16:20:55 -0400362 BOOST_REQUIRE(processConfigurationString(config));
alvya2228c62014-12-09 10:25:11 -0600363
Junxiao Shif4674672024-01-06 02:27:36 +0000364 BOOST_CHECK_EQUAL(conf.getHyperbolicState(), HYPERBOLIC_STATE_DEFAULT);
Vince Lehman7b616582014-10-17 16:25:39 -0500365}
366
367BOOST_AUTO_TEST_CASE(OutOfRangeValue)
368{
369 const std::string SECTION_FIB_OUT_OF_RANGE =
370 "fib\n"
371 "{\n"
372 " max-faces-per-prefix 3\n"
373 " routing-calc-interval 999\n" // Larger than max value
374 "}\n\n";
375
376 // Processing should fail due to out of range value
377 BOOST_CHECK_EQUAL(processConfigurationString(SECTION_FIB_OUT_OF_RANGE), false);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500378}
379
alvy5a454952014-12-15 12:49:54 -0600380BOOST_AUTO_TEST_CASE(NegativeValue)
381{
382 const std::string SECTION_GENERAL_NEGATIVE_VALUE =
383 "general\n"
384 "{\n"
385 " network /ndn/\n"
386 " site /memphis.edu/\n"
387 " router /cs/pollux/\n"
388 " lsa-refresh-time -1800\n"
389 " lsa-interest-lifetime -3\n"
390 " router-dead-interval -86400\n"
391 "}\n\n";
392
393 // Processing should fail due to negative value
394 BOOST_CHECK_EQUAL(processConfigurationString(SECTION_GENERAL_NEGATIVE_VALUE), false);
395}
396
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500397BOOST_AUTO_TEST_CASE(LoadCertToPublish)
398{
Davide Pesavento8de8a8b2022-05-12 01:26:43 -0400399 auto identity = m_keyChain.createIdentity("/TestNLSR/identity");
400 saveIdentityCert(identity, "cert-to-publish.cert");
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500401
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500402 const std::string SECTION_SECURITY = R"CONF(
403 security
404 {
405 validator
406 {
407 trust-anchor
408 {
409 type any
410 }
411 }
412 prefix-update-validator
413 {
414 trust-anchor
415 {
416 type any
417 }
418 }
419 cert-to-publish "cert-to-publish.cert"
420 }
421 )CONF";
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500422
Davide Pesavento907675b2023-08-02 16:20:55 -0400423 BOOST_REQUIRE(processConfigurationString(SECTION_SECURITY));
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500424}
425
Vince Lehmand33e5bc2015-06-22 15:27:50 -0500426BOOST_AUTO_TEST_CASE(PrefixUpdateValidatorOptional) // Bug #2814
427{
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500428 const std::string SECTION_SECURITY = R"CONF(
429 security
430 {
431 validator
432 {
433 trust-anchor
434 {
435 type any
436 }
437 }
438 }
439 )CONF";
Vince Lehmand33e5bc2015-06-22 15:27:50 -0500440
Davide Pesavento907675b2023-08-02 16:20:55 -0400441 BOOST_REQUIRE(processConfigurationString(SECTION_SECURITY));
Vince Lehmand33e5bc2015-06-22 15:27:50 -0500442}
443
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500444BOOST_AUTO_TEST_SUITE_END()
445
Davide Pesavento288141a2024-02-13 17:30:35 -0500446} // namespace nlsr::tests