akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 2 | /* |
Junxiao Shi | f467467 | 2024-01-06 02:27:36 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2024, The University of Memphis, |
Vince Lehman | c2e51f6 | 2015-01-20 15:03:11 -0600 | [diff] [blame] | 4 | * Regents of the University of California, |
| 5 | * Arizona Board of Regents. |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 6 | * |
| 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/>. |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 20 | **/ |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 21 | |
Nick Gordon | ff9a627 | 2017-10-12 13:38:29 -0500 | [diff] [blame] | 22 | #include "conf-file-processor.hpp" |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 23 | |
| 24 | #include "tests/boost-test.hpp" |
| 25 | #include "tests/io-key-chain-fixture.hpp" |
Muktadir R Chowdhury | bfa2760 | 2014-10-31 10:57:41 -0500 | [diff] [blame] | 26 | |
Nick Gordon | ff9a627 | 2017-10-12 13:38:29 -0500 | [diff] [blame] | 27 | #include <fstream> |
Muktadir R Chowdhury | bfa2760 | 2014-10-31 10:57:41 -0500 | [diff] [blame] | 28 | #include <boost/algorithm/string.hpp> |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 29 | |
Muktadir R Chowdhury | c69da0a | 2015-12-18 13:24:38 -0600 | [diff] [blame] | 30 | #include <ndn-cxx/util/dummy-client-face.hpp> |
| 31 | |
Davide Pesavento | 288141a | 2024-02-13 17:30:35 -0500 | [diff] [blame] | 32 | namespace nlsr::tests { |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 33 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 34 | const std::string SECTION_GENERAL = |
| 35 | "general\n" |
| 36 | "{\n" |
Davide Pesavento | 907675b | 2023-08-02 16:20:55 -0400 | [diff] [blame] | 37 | " network /ndn\n" |
| 38 | " site /memphis.edu\n" |
| 39 | " router /cs/pollux\n" |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 40 | " lsa-refresh-time 1800\n" |
| 41 | " lsa-interest-lifetime 3\n" |
Alexander Afanasyev | 1cf1e10 | 2014-08-17 19:47:57 -0700 | [diff] [blame] | 42 | " router-dead-interval 86400\n" |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 43 | " sync-protocol psync\n" |
Ashlesh Gawande | f7da9c5 | 2018-02-06 17:36:46 -0600 | [diff] [blame] | 44 | " sync-interest-lifetime 10000\n" |
dulalsaurab | 82a34c2 | 2019-02-04 17:31:21 +0000 | [diff] [blame] | 45 | " state-dir /tmp\n" |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 46 | "}\n\n"; |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 47 | |
Varun Patil | a2599da | 2023-07-12 16:37:15 -0700 | [diff] [blame] | 48 | const std::string SECTION_GENERAL_SVS = |
| 49 | "general\n" |
| 50 | "{\n" |
Davide Pesavento | 907675b | 2023-08-02 16:20:55 -0400 | [diff] [blame] | 51 | " network /ndn\n" |
| 52 | " site /memphis.edu\n" |
| 53 | " router /cs/pollux\n" |
Varun Patil | a2599da | 2023-07-12 16:37:15 -0700 | [diff] [blame] | 54 | " sync-protocol svs\n" |
Davide Pesavento | 907675b | 2023-08-02 16:20:55 -0400 | [diff] [blame] | 55 | " state-dir /tmp\n" |
Varun Patil | a2599da | 2023-07-12 16:37:15 -0700 | [diff] [blame] | 56 | "}\n\n"; |
| 57 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 58 | const 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 Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 64 | " adj-lsa-build-interval 10\n" |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 65 | " neighbor\n" |
| 66 | " {\n" |
| 67 | " name /ndn/memphis.edu/cs/castor\n" |
Ashlesh Gawande | 7e3f6d7 | 2019-01-25 13:13:43 -0600 | [diff] [blame] | 68 | " face-uri udp://10.0.0.1\n" |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 69 | " link-cost 20\n" |
| 70 | " }\n\n" |
| 71 | " neighbor\n" |
| 72 | " {\n" |
| 73 | " name /ndn/memphis.edu/cs/mira\n" |
Ashlesh Gawande | 7e3f6d7 | 2019-01-25 13:13:43 -0600 | [diff] [blame] | 74 | " face-uri udp://10.0.0.2\n" |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 75 | " link-cost 30\n" |
| 76 | " }\n" |
| 77 | "}\n\n"; |
| 78 | |
| 79 | const 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 Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 87 | const 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 Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 95 | const 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 | |
| 103 | const 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 | |
| 110 | const 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 Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 117 | // NEED TO TEST SECURITY SECTION SUCH AS LOADING CERTIFICATE |
| 118 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 119 | const std::string CONFIG_LINK_STATE = SECTION_GENERAL + SECTION_NEIGHBORS + |
| 120 | SECTION_HYPERBOLIC_OFF + SECTION_FIB + SECTION_ADVERTISING; |
| 121 | |
| 122 | const std::string CONFIG_HYPERBOLIC = SECTION_GENERAL + SECTION_NEIGHBORS + |
| 123 | SECTION_HYPERBOLIC_ON + SECTION_FIB + SECTION_ADVERTISING; |
| 124 | |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 125 | const std::string CONFIG_HYPERBOLIC_ANGLES = SECTION_GENERAL + SECTION_NEIGHBORS + |
| 126 | SECTION_HYPERBOLIC_ANGLES_ON + SECTION_FIB + |
| 127 | SECTION_ADVERTISING; |
| 128 | |
Varun Patil | a2599da | 2023-07-12 16:37:15 -0700 | [diff] [blame] | 129 | const std::string CONFIG_SVS = SECTION_GENERAL_SVS; |
| 130 | |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 131 | class ConfFileProcessorFixture : public IoKeyChainFixture |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 132 | { |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 133 | public: |
| 134 | ConfFileProcessorFixture() |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 135 | : face(m_io, m_keyChain) |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 136 | , conf(face, m_keyChain, "unit-test-nlsr.conf") |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 137 | { |
| 138 | } |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 139 | |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 140 | ~ConfFileProcessorFixture() override |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 141 | { |
| 142 | remove("unit-test-nlsr.conf"); |
| 143 | } |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 144 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 145 | bool |
Davide Pesavento | 907675b | 2023-08-02 16:20:55 -0400 | [diff] [blame] | 146 | processConfigurationString(std::string_view confString) |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 147 | { |
| 148 | std::ofstream config; |
| 149 | config.open("unit-test-nlsr.conf"); |
| 150 | config << confString; |
| 151 | config.close(); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 152 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 153 | ConfFileProcessor processor(conf); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 154 | return processor.processConfFile(); |
| 155 | } |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 156 | |
Muktadir R Chowdhury | bfa2760 | 2014-10-31 10:57:41 -0500 | [diff] [blame] | 157 | void |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 158 | commentOut(const std::string& key, std::string& config) |
| 159 | { |
| 160 | boost::replace_all(config, key, ";" + key); |
| 161 | } |
| 162 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 163 | public: |
Junxiao Shi | 43f37a0 | 2023-08-09 00:09:00 +0000 | [diff] [blame] | 164 | ndn::DummyClientFace face; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 165 | ConfParameter conf; |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 166 | }; |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 167 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 168 | BOOST_FIXTURE_TEST_SUITE(TestConfFileProcessor, ConfFileProcessorFixture) |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 169 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 170 | BOOST_AUTO_TEST_CASE(LinkState) |
| 171 | { |
Davide Pesavento | 907675b | 2023-08-02 16:20:55 -0400 | [diff] [blame] | 172 | BOOST_REQUIRE(processConfigurationString(CONFIG_LINK_STATE)); |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 173 | conf.buildRouterAndSyncUserPrefix(); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 174 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 175 | // General |
Davide Pesavento | 907675b | 2023-08-02 16:20:55 -0400 | [diff] [blame] | 176 | 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 Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 180 | BOOST_CHECK_EQUAL(conf.getSyncPrefix(), ndn::Name("/localhop/ndn/nlsr/sync").appendVersion(ConfParameter::SYNC_VERSION)); |
Ashlesh Gawande | cba0ae2 | 2018-03-27 17:57:56 -0500 | [diff] [blame] | 181 | BOOST_CHECK_EQUAL(conf.getLsaPrefix(), "/localhop/ndn/nlsr/LSA"); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 182 | BOOST_CHECK_EQUAL(conf.getLsaRefreshTime(), 1800); |
Davide Pesavento | 1954a0c | 2022-09-30 15:56:04 -0400 | [diff] [blame] | 183 | BOOST_CHECK(conf.getSyncProtocol() == SyncProtocol::PSYNC); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 184 | BOOST_CHECK_EQUAL(conf.getLsaInterestLifetime(), ndn::time::seconds(3)); |
Alexander Afanasyev | 1cf1e10 | 2014-08-17 19:47:57 -0700 | [diff] [blame] | 185 | BOOST_CHECK_EQUAL(conf.getRouterDeadInterval(), 86400); |
Ashlesh Gawande | f7da9c5 | 2018-02-06 17:36:46 -0600 | [diff] [blame] | 186 | BOOST_CHECK_EQUAL(conf.getSyncInterestLifetime(), ndn::time::milliseconds(10000)); |
dulalsaurab | 82a34c2 | 2019-02-04 17:31:21 +0000 | [diff] [blame] | 187 | BOOST_CHECK_EQUAL(conf.getStateFileDir(), "/tmp"); |
Alexander Afanasyev | 411ee4b | 2014-08-16 23:17:03 -0700 | [diff] [blame] | 188 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 189 | // Neighbors |
| 190 | BOOST_CHECK_EQUAL(conf.getInterestRetryNumber(), 3); |
| 191 | BOOST_CHECK_EQUAL(conf.getInterestResendTime(), 1); |
| 192 | BOOST_CHECK_EQUAL(conf.getInfoInterestInterval(), 60); |
| 193 | |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 194 | BOOST_CHECK_EQUAL(conf.getAdjLsaBuildInterval(), 10); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 195 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 196 | 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 Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 199 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 200 | Adjacent mira = conf.getAdjacencyList().getAdjacent("/ndn/memphis.edu/cs/mira"); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 201 | BOOST_CHECK_EQUAL(mira.getName(), "/ndn/memphis.edu/cs/mira"); |
| 202 | BOOST_CHECK_EQUAL(mira.getLinkCost(), 30); |
Ashlesh Gawande | 7e3f6d7 | 2019-01-25 13:13:43 -0600 | [diff] [blame] | 203 | BOOST_CHECK_EQUAL(mira.getFaceUri().toString(), "udp4://10.0.0.2:6363"); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 204 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 205 | Adjacent castor = conf.getAdjacencyList().getAdjacent("/ndn/memphis.edu/cs/castor"); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 206 | BOOST_CHECK_EQUAL(castor.getName(), "/ndn/memphis.edu/cs/castor"); |
| 207 | BOOST_CHECK_EQUAL(castor.getLinkCost(), 20); |
Ashlesh Gawande | 7e3f6d7 | 2019-01-25 13:13:43 -0600 | [diff] [blame] | 208 | BOOST_CHECK_EQUAL(castor.getFaceUri().toString(), "udp4://10.0.0.1:6363"); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 209 | |
| 210 | // Hyperbolic |
Junxiao Shi | f467467 | 2024-01-06 02:27:36 +0000 | [diff] [blame] | 211 | BOOST_CHECK_EQUAL(conf.getHyperbolicState(), HYPERBOLIC_STATE_OFF); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 212 | |
| 213 | // FIB |
| 214 | BOOST_CHECK_EQUAL(conf.getMaxFacesPerPrefix(), 3); |
| 215 | BOOST_CHECK_EQUAL(conf.getRoutingCalcInterval(), 9); |
| 216 | |
| 217 | // Advertising |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 218 | BOOST_CHECK_EQUAL(conf.getNamePrefixList().size(), 2); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 219 | } |
| 220 | |
Davide Pesavento | 907675b | 2023-08-02 16:20:55 -0400 | [diff] [blame] | 221 | BOOST_AUTO_TEST_CASE(SvsPrefix) |
Varun Patil | a2599da | 2023-07-12 16:37:15 -0700 | [diff] [blame] | 222 | { |
Davide Pesavento | 907675b | 2023-08-02 16:20:55 -0400 | [diff] [blame] | 223 | #ifdef HAVE_SVS |
| 224 | BOOST_REQUIRE(processConfigurationString(CONFIG_SVS)); |
Varun Patil | a2599da | 2023-07-12 16:37:15 -0700 | [diff] [blame] | 225 | conf.buildRouterAndSyncUserPrefix(); |
| 226 | |
| 227 | // SVS does not use localhop |
Davide Pesavento | 907675b | 2023-08-02 16:20:55 -0400 | [diff] [blame] | 228 | BOOST_CHECK_EQUAL(conf.getNetwork(), "/ndn"); |
Varun Patil | a2599da | 2023-07-12 16:37:15 -0700 | [diff] [blame] | 229 | BOOST_CHECK_EQUAL(conf.getSyncPrefix(), ndn::Name("/ndn/nlsr/sync").appendVersion(ConfParameter::SYNC_VERSION)); |
Davide Pesavento | 907675b | 2023-08-02 16:20:55 -0400 | [diff] [blame] | 230 | #else |
| 231 | BOOST_CHECK_EQUAL(processConfigurationString(CONFIG_SVS), false); |
| 232 | #endif |
Varun Patil | a2599da | 2023-07-12 16:37:15 -0700 | [diff] [blame] | 233 | } |
| 234 | |
alvy | 2fe1287 | 2014-11-25 10:32:23 -0600 | [diff] [blame] | 235 | BOOST_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 Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 243 | " adj-lsa-build-interval 10\n" |
alvy | 2fe1287 | 2014-11-25 10:32:23 -0600 | [diff] [blame] | 244 | " 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 Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 255 | BOOST_AUTO_TEST_CASE(Hyperbolic) |
| 256 | { |
Davide Pesavento | 907675b | 2023-08-02 16:20:55 -0400 | [diff] [blame] | 257 | BOOST_REQUIRE(processConfigurationString(CONFIG_HYPERBOLIC)); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 258 | |
Junxiao Shi | f467467 | 2024-01-06 02:27:36 +0000 | [diff] [blame] | 259 | BOOST_CHECK_EQUAL(conf.getHyperbolicState(), HYPERBOLIC_STATE_ON); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 260 | BOOST_CHECK_EQUAL(conf.getCorR(), 123.456); |
Davide Pesavento | 907675b | 2023-08-02 16:20:55 -0400 | [diff] [blame] | 261 | std::vector<double> angles{1.45}; |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 262 | BOOST_CHECK(conf.getCorTheta() == angles); |
| 263 | } |
| 264 | |
| 265 | BOOST_AUTO_TEST_CASE(Hyperbolic2) |
| 266 | { |
Davide Pesavento | 907675b | 2023-08-02 16:20:55 -0400 | [diff] [blame] | 267 | BOOST_REQUIRE(processConfigurationString(CONFIG_HYPERBOLIC_ANGLES)); |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 268 | |
Junxiao Shi | f467467 | 2024-01-06 02:27:36 +0000 | [diff] [blame] | 269 | BOOST_CHECK_EQUAL(conf.getHyperbolicState(), HYPERBOLIC_STATE_ON); |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 270 | BOOST_CHECK_EQUAL(conf.getCorR(), 123.456); |
Davide Pesavento | 907675b | 2023-08-02 16:20:55 -0400 | [diff] [blame] | 271 | std::vector<double> angles{1.45, 2.25}; |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 272 | BOOST_CHECK(conf.getCorTheta() == angles); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 273 | } |
| 274 | |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 275 | BOOST_AUTO_TEST_CASE(DefaultValuesGeneral) |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 276 | { |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 277 | std::string config = SECTION_GENERAL; |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 278 | |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 279 | commentOut("lsa-refresh-time", config); |
| 280 | commentOut("lsa-interest-lifetime", config); |
| 281 | commentOut("router-dead-interval", config); |
| 282 | |
Davide Pesavento | 907675b | 2023-08-02 16:20:55 -0400 | [diff] [blame] | 283 | BOOST_REQUIRE(processConfigurationString(config)); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 284 | |
alvy | 5a45495 | 2014-12-15 12:49:54 -0600 | [diff] [blame] | 285 | BOOST_CHECK_EQUAL(conf.getLsaRefreshTime(), static_cast<uint32_t>(LSA_REFRESH_TIME_DEFAULT)); |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 286 | BOOST_CHECK_EQUAL(conf.getLsaInterestLifetime(), |
| 287 | static_cast<ndn::time::seconds>(LSA_INTEREST_LIFETIME_DEFAULT)); |
Ashlesh Gawande | 328fc11 | 2019-12-12 17:06:44 -0600 | [diff] [blame] | 288 | BOOST_CHECK_EQUAL(conf.getRouterDeadInterval(), (2 * conf.getLsaRefreshTime())); |
| 289 | |
Davide Pesavento | 907675b | 2023-08-02 16:20:55 -0400 | [diff] [blame] | 290 | BOOST_CHECK_NE(conf.m_confFileName, conf.getConfFileNameDynamic()); |
Ashlesh Gawande | 328fc11 | 2019-12-12 17:06:44 -0600 | [diff] [blame] | 291 | conf.m_confFileName = "/tmp/nlsr.conf"; |
Davide Pesavento | 907675b | 2023-08-02 16:20:55 -0400 | [diff] [blame] | 292 | BOOST_CHECK_EQUAL(conf.m_confFileName, conf.getConfFileNameDynamic()); |
| 293 | BOOST_CHECK_EQUAL(processConfigurationString(config), false); |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | BOOST_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 Pesavento | 907675b | 2023-08-02 16:20:55 -0400 | [diff] [blame] | 306 | BOOST_REQUIRE(processConfigurationString(config)); |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 307 | |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 308 | BOOST_CHECK_EQUAL(conf.getInterestRetryNumber(), static_cast<uint32_t>(HELLO_RETRIES_DEFAULT)); |
alvy | 5a45495 | 2014-12-15 12:49:54 -0600 | [diff] [blame] | 309 | 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 Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 311 | BOOST_CHECK_EQUAL(conf.getAdjLsaBuildInterval(), |
| 312 | static_cast<uint32_t>(ADJ_LSA_BUILD_INTERVAL_DEFAULT)); |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 313 | } |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 314 | |
Ashlesh Gawande | 9ecbdc9 | 2019-03-11 13:18:45 -0700 | [diff] [blame] | 315 | BOOST_AUTO_TEST_CASE(CanonizeNeighbors) |
| 316 | { |
Davide Pesavento | 907675b | 2023-08-02 16:20:55 -0400 | [diff] [blame] | 317 | std::string config{R"INFO(neighbors |
Ashlesh Gawande | 9ecbdc9 | 2019-03-11 13:18:45 -0700 | [diff] [blame] | 318 | { |
| 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 Pesavento | 907675b | 2023-08-02 16:20:55 -0400 | [diff] [blame] | 331 | })INFO"}; |
Ashlesh Gawande | 9ecbdc9 | 2019-03-11 13:18:45 -0700 | [diff] [blame] | 332 | |
Davide Pesavento | 907675b | 2023-08-02 16:20:55 -0400 | [diff] [blame] | 333 | BOOST_REQUIRE(processConfigurationString(config)); |
Ashlesh Gawande | 9ecbdc9 | 2019-03-11 13:18:45 -0700 | [diff] [blame] | 334 | |
| 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 | |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 341 | BOOST_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 Pesavento | 907675b | 2023-08-02 16:20:55 -0400 | [diff] [blame] | 348 | BOOST_REQUIRE(processConfigurationString(config)); |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 349 | |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 350 | 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 | |
| 356 | BOOST_AUTO_TEST_CASE(DefaultValuesHyperbolic) |
| 357 | { |
| 358 | std::string config = SECTION_HYPERBOLIC_ON; |
| 359 | |
| 360 | commentOut("state", config); |
| 361 | |
Davide Pesavento | 907675b | 2023-08-02 16:20:55 -0400 | [diff] [blame] | 362 | BOOST_REQUIRE(processConfigurationString(config)); |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 363 | |
Junxiao Shi | f467467 | 2024-01-06 02:27:36 +0000 | [diff] [blame] | 364 | BOOST_CHECK_EQUAL(conf.getHyperbolicState(), HYPERBOLIC_STATE_DEFAULT); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | BOOST_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 Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 378 | } |
| 379 | |
alvy | 5a45495 | 2014-12-15 12:49:54 -0600 | [diff] [blame] | 380 | BOOST_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 Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 397 | BOOST_AUTO_TEST_CASE(LoadCertToPublish) |
| 398 | { |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 399 | auto identity = m_keyChain.createIdentity("/TestNLSR/identity"); |
| 400 | saveIdentityCert(identity, "cert-to-publish.cert"); |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 401 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 402 | 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 Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 422 | |
Davide Pesavento | 907675b | 2023-08-02 16:20:55 -0400 | [diff] [blame] | 423 | BOOST_REQUIRE(processConfigurationString(SECTION_SECURITY)); |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 424 | } |
| 425 | |
Vince Lehman | d33e5bc | 2015-06-22 15:27:50 -0500 | [diff] [blame] | 426 | BOOST_AUTO_TEST_CASE(PrefixUpdateValidatorOptional) // Bug #2814 |
| 427 | { |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 428 | 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 Lehman | d33e5bc | 2015-06-22 15:27:50 -0500 | [diff] [blame] | 440 | |
Davide Pesavento | 907675b | 2023-08-02 16:20:55 -0400 | [diff] [blame] | 441 | BOOST_REQUIRE(processConfigurationString(SECTION_SECURITY)); |
Vince Lehman | d33e5bc | 2015-06-22 15:27:50 -0500 | [diff] [blame] | 442 | } |
| 443 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 444 | BOOST_AUTO_TEST_SUITE_END() |
| 445 | |
Davide Pesavento | 288141a | 2024-02-13 17:30:35 -0500 | [diff] [blame] | 446 | } // namespace nlsr::tests |