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 | /* |
| 3 | * Copyright (c) 2014-2022, 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 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 32 | namespace nlsr { |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 33 | namespace test { |
| 34 | |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 35 | using std::shared_ptr; |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 36 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 37 | const std::string SECTION_GENERAL = |
| 38 | "general\n" |
| 39 | "{\n" |
| 40 | " network /ndn/\n" |
| 41 | " site /memphis.edu/\n" |
| 42 | " router /cs/pollux/\n" |
| 43 | " lsa-refresh-time 1800\n" |
| 44 | " lsa-interest-lifetime 3\n" |
Alexander Afanasyev | 1cf1e10 | 2014-08-17 19:47:57 -0700 | [diff] [blame] | 45 | " router-dead-interval 86400\n" |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 46 | " sync-protocol psync\n" |
Ashlesh Gawande | f7da9c5 | 2018-02-06 17:36:46 -0600 | [diff] [blame] | 47 | " sync-interest-lifetime 10000\n" |
dulalsaurab | 82a34c2 | 2019-02-04 17:31:21 +0000 | [diff] [blame] | 48 | " state-dir /tmp\n" |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 49 | "}\n\n"; |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 50 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 51 | const std::string SECTION_NEIGHBORS = |
| 52 | "neighbors\n" |
| 53 | "{\n" |
| 54 | " hello-retries 3\n" |
| 55 | " hello-timeout 1\n" |
| 56 | " hello-interval 60\n\n" |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 57 | " adj-lsa-build-interval 10\n" |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 58 | " neighbor\n" |
| 59 | " {\n" |
| 60 | " name /ndn/memphis.edu/cs/castor\n" |
Ashlesh Gawande | 7e3f6d7 | 2019-01-25 13:13:43 -0600 | [diff] [blame] | 61 | " face-uri udp://10.0.0.1\n" |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 62 | " link-cost 20\n" |
| 63 | " }\n\n" |
| 64 | " neighbor\n" |
| 65 | " {\n" |
| 66 | " name /ndn/memphis.edu/cs/mira\n" |
Ashlesh Gawande | 7e3f6d7 | 2019-01-25 13:13:43 -0600 | [diff] [blame] | 67 | " face-uri udp://10.0.0.2\n" |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 68 | " link-cost 30\n" |
| 69 | " }\n" |
| 70 | "}\n\n"; |
| 71 | |
| 72 | const std::string SECTION_HYPERBOLIC_ON = |
| 73 | "hyperbolic\n" |
| 74 | "{\n" |
| 75 | " state on\n" |
| 76 | " radius 123.456\n" |
| 77 | " angle 1.45\n" |
| 78 | "}\n\n"; |
| 79 | |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 80 | const std::string SECTION_HYPERBOLIC_ANGLES_ON = |
| 81 | "hyperbolic\n" |
| 82 | "{\n" |
| 83 | " state on\n" |
| 84 | " radius 123.456\n" |
| 85 | " angle 1.45,2.25\n" |
| 86 | "}\n\n"; |
| 87 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 88 | const std::string SECTION_HYPERBOLIC_OFF = |
| 89 | "hyperbolic\n" |
| 90 | "{\n" |
| 91 | " state off\n" |
| 92 | " radius 123.456\n" |
| 93 | " angle 1.45\n" |
| 94 | "}\n\n"; |
| 95 | |
| 96 | const std::string SECTION_FIB = |
| 97 | "fib\n" |
| 98 | "{\n" |
| 99 | " max-faces-per-prefix 3\n" |
| 100 | " routing-calc-interval 9\n" |
| 101 | "}\n\n"; |
| 102 | |
| 103 | const std::string SECTION_ADVERTISING = |
| 104 | "advertising\n" |
| 105 | "{\n" |
| 106 | " prefix /ndn/edu/memphis/cs/netlab\n" |
| 107 | " prefix /ndn/edu/memphis/sports/basketball\n" |
| 108 | "}\n"; |
| 109 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 110 | // NEED TO TEST SECURITY SECTION SUCH AS LOADING CERTIFICATE |
| 111 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 112 | const std::string CONFIG_LINK_STATE = SECTION_GENERAL + SECTION_NEIGHBORS + |
| 113 | SECTION_HYPERBOLIC_OFF + SECTION_FIB + SECTION_ADVERTISING; |
| 114 | |
| 115 | const std::string CONFIG_HYPERBOLIC = SECTION_GENERAL + SECTION_NEIGHBORS + |
| 116 | SECTION_HYPERBOLIC_ON + SECTION_FIB + SECTION_ADVERTISING; |
| 117 | |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 118 | const std::string CONFIG_HYPERBOLIC_ANGLES = SECTION_GENERAL + SECTION_NEIGHBORS + |
| 119 | SECTION_HYPERBOLIC_ANGLES_ON + SECTION_FIB + |
| 120 | SECTION_ADVERTISING; |
| 121 | |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 122 | class ConfFileProcessorFixture : public IoKeyChainFixture |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 123 | { |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 124 | public: |
| 125 | ConfFileProcessorFixture() |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 126 | : face(m_io, m_keyChain) |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 127 | , conf(face, m_keyChain, "unit-test-nlsr.conf") |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 128 | { |
| 129 | } |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 130 | |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 131 | ~ConfFileProcessorFixture() override |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 132 | { |
| 133 | remove("unit-test-nlsr.conf"); |
| 134 | } |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 135 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 136 | bool |
| 137 | processConfigurationString(std::string confString) |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 138 | { |
| 139 | std::ofstream config; |
| 140 | config.open("unit-test-nlsr.conf"); |
| 141 | config << confString; |
| 142 | config.close(); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 143 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 144 | ConfFileProcessor processor(conf); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 145 | return processor.processConfFile(); |
| 146 | } |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 147 | |
Muktadir R Chowdhury | bfa2760 | 2014-10-31 10:57:41 -0500 | [diff] [blame] | 148 | void |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 149 | commentOut(const std::string& key, std::string& config) |
| 150 | { |
| 151 | boost::replace_all(config, key, ";" + key); |
| 152 | } |
| 153 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 154 | public: |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 155 | ndn::util::DummyClientFace face; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 156 | ConfParameter conf; |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 157 | }; |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 158 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 159 | BOOST_FIXTURE_TEST_SUITE(TestConfFileProcessor, ConfFileProcessorFixture) |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 160 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 161 | BOOST_AUTO_TEST_CASE(LinkState) |
| 162 | { |
| 163 | processConfigurationString(CONFIG_LINK_STATE); |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 164 | conf.buildRouterAndSyncUserPrefix(); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 165 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 166 | // General |
| 167 | BOOST_CHECK_EQUAL(conf.getNetwork(), "/ndn/"); |
| 168 | BOOST_CHECK_EQUAL(conf.getSiteName(), "/memphis.edu/"); |
| 169 | BOOST_CHECK_EQUAL(conf.getRouterName(), "/cs/pollux/"); |
| 170 | BOOST_CHECK_EQUAL(conf.getRouterPrefix(), "/ndn/memphis.edu/cs/pollux/"); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 171 | 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] | 172 | BOOST_CHECK_EQUAL(conf.getLsaPrefix(), "/localhop/ndn/nlsr/LSA"); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 173 | BOOST_CHECK_EQUAL(conf.getLsaRefreshTime(), 1800); |
Davide Pesavento | 1954a0c | 2022-09-30 15:56:04 -0400 | [diff] [blame^] | 174 | BOOST_CHECK(conf.getSyncProtocol() == SyncProtocol::PSYNC); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 175 | BOOST_CHECK_EQUAL(conf.getLsaInterestLifetime(), ndn::time::seconds(3)); |
Alexander Afanasyev | 1cf1e10 | 2014-08-17 19:47:57 -0700 | [diff] [blame] | 176 | BOOST_CHECK_EQUAL(conf.getRouterDeadInterval(), 86400); |
Ashlesh Gawande | f7da9c5 | 2018-02-06 17:36:46 -0600 | [diff] [blame] | 177 | BOOST_CHECK_EQUAL(conf.getSyncInterestLifetime(), ndn::time::milliseconds(10000)); |
dulalsaurab | 82a34c2 | 2019-02-04 17:31:21 +0000 | [diff] [blame] | 178 | BOOST_CHECK_EQUAL(conf.getStateFileDir(), "/tmp"); |
Alexander Afanasyev | 411ee4b | 2014-08-16 23:17:03 -0700 | [diff] [blame] | 179 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 180 | // Neighbors |
| 181 | BOOST_CHECK_EQUAL(conf.getInterestRetryNumber(), 3); |
| 182 | BOOST_CHECK_EQUAL(conf.getInterestResendTime(), 1); |
| 183 | BOOST_CHECK_EQUAL(conf.getInfoInterestInterval(), 60); |
| 184 | |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 185 | BOOST_CHECK_EQUAL(conf.getAdjLsaBuildInterval(), 10); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 186 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 187 | BOOST_CHECK(conf.getAdjacencyList().isNeighbor("/ndn/memphis.edu/cs/mira")); |
| 188 | BOOST_CHECK(conf.getAdjacencyList().isNeighbor("/ndn/memphis.edu/cs/castor")); |
| 189 | BOOST_CHECK(!conf.getAdjacencyList().isNeighbor("/ndn/memphis.edu/cs/fail")); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 190 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 191 | Adjacent mira = conf.getAdjacencyList().getAdjacent("/ndn/memphis.edu/cs/mira"); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 192 | BOOST_CHECK_EQUAL(mira.getName(), "/ndn/memphis.edu/cs/mira"); |
| 193 | BOOST_CHECK_EQUAL(mira.getLinkCost(), 30); |
Ashlesh Gawande | 7e3f6d7 | 2019-01-25 13:13:43 -0600 | [diff] [blame] | 194 | BOOST_CHECK_EQUAL(mira.getFaceUri().toString(), "udp4://10.0.0.2:6363"); |
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 | Adjacent castor = conf.getAdjacencyList().getAdjacent("/ndn/memphis.edu/cs/castor"); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 197 | BOOST_CHECK_EQUAL(castor.getName(), "/ndn/memphis.edu/cs/castor"); |
| 198 | BOOST_CHECK_EQUAL(castor.getLinkCost(), 20); |
Ashlesh Gawande | 7e3f6d7 | 2019-01-25 13:13:43 -0600 | [diff] [blame] | 199 | BOOST_CHECK_EQUAL(castor.getFaceUri().toString(), "udp4://10.0.0.1:6363"); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 200 | |
| 201 | // Hyperbolic |
| 202 | BOOST_CHECK_EQUAL(conf.getHyperbolicState(), 0); |
| 203 | |
| 204 | // FIB |
| 205 | BOOST_CHECK_EQUAL(conf.getMaxFacesPerPrefix(), 3); |
| 206 | BOOST_CHECK_EQUAL(conf.getRoutingCalcInterval(), 9); |
| 207 | |
| 208 | // Advertising |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 209 | BOOST_CHECK_EQUAL(conf.getNamePrefixList().size(), 2); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 210 | } |
| 211 | |
alvy | 2fe1287 | 2014-11-25 10:32:23 -0600 | [diff] [blame] | 212 | BOOST_AUTO_TEST_CASE(MalformedUri) |
| 213 | { |
| 214 | const std::string MALFORMED_URI = |
| 215 | "neighbors\n" |
| 216 | "{\n" |
| 217 | " hello-retries 3\n" |
| 218 | " hello-timeout 1\n" |
| 219 | " hello-interval 60\n\n" |
Ashlesh Gawande | 6b388fc | 2019-09-30 10:14:41 -0500 | [diff] [blame] | 220 | " adj-lsa-build-interval 10\n" |
alvy | 2fe1287 | 2014-11-25 10:32:23 -0600 | [diff] [blame] | 221 | " neighbor\n" |
| 222 | " {\n" |
| 223 | " name /ndn/memphis.edu/cs/castor\n" |
| 224 | " face-uri udp4:malformed-uri\n" |
| 225 | " link-cost 20\n" |
| 226 | " }\n" |
| 227 | "}\n\n"; |
| 228 | |
| 229 | BOOST_CHECK_EQUAL(processConfigurationString(MALFORMED_URI), false); |
| 230 | } |
| 231 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 232 | BOOST_AUTO_TEST_CASE(Hyperbolic) |
| 233 | { |
| 234 | processConfigurationString(CONFIG_HYPERBOLIC); |
| 235 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 236 | BOOST_CHECK_EQUAL(conf.getHyperbolicState(), 1); |
| 237 | BOOST_CHECK_EQUAL(conf.getCorR(), 123.456); |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 238 | std::vector<double> angles; |
| 239 | angles.push_back(1.45); |
| 240 | BOOST_CHECK(conf.getCorTheta() == angles); |
| 241 | } |
| 242 | |
| 243 | BOOST_AUTO_TEST_CASE(Hyperbolic2) |
| 244 | { |
| 245 | processConfigurationString(CONFIG_HYPERBOLIC_ANGLES); |
| 246 | |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 247 | BOOST_CHECK_EQUAL(conf.getHyperbolicState(), 1); |
| 248 | BOOST_CHECK_EQUAL(conf.getCorR(), 123.456); |
| 249 | std::vector<double> angles; |
| 250 | angles.push_back(1.45); |
| 251 | angles.push_back(2.25); |
| 252 | BOOST_CHECK(conf.getCorTheta() == angles); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 253 | } |
| 254 | |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 255 | BOOST_AUTO_TEST_CASE(DefaultValuesGeneral) |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 256 | { |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 257 | std::string config = SECTION_GENERAL; |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 258 | |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 259 | commentOut("lsa-refresh-time", config); |
| 260 | commentOut("lsa-interest-lifetime", config); |
| 261 | commentOut("router-dead-interval", config); |
| 262 | |
Ashlesh Gawande | 328fc11 | 2019-12-12 17:06:44 -0600 | [diff] [blame] | 263 | BOOST_CHECK(processConfigurationString(config)); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 264 | |
alvy | 5a45495 | 2014-12-15 12:49:54 -0600 | [diff] [blame] | 265 | BOOST_CHECK_EQUAL(conf.getLsaRefreshTime(), static_cast<uint32_t>(LSA_REFRESH_TIME_DEFAULT)); |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 266 | BOOST_CHECK_EQUAL(conf.getLsaInterestLifetime(), |
| 267 | static_cast<ndn::time::seconds>(LSA_INTEREST_LIFETIME_DEFAULT)); |
Ashlesh Gawande | 328fc11 | 2019-12-12 17:06:44 -0600 | [diff] [blame] | 268 | BOOST_CHECK_EQUAL(conf.getRouterDeadInterval(), (2 * conf.getLsaRefreshTime())); |
| 269 | |
| 270 | BOOST_CHECK(conf.m_confFileName != conf.getConfFileNameDynamic()); |
| 271 | conf.m_confFileName = "/tmp/nlsr.conf"; |
| 272 | BOOST_CHECK(conf.m_confFileName == conf.getConfFileNameDynamic()); |
| 273 | BOOST_CHECK(!processConfigurationString(config)); |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | BOOST_AUTO_TEST_CASE(DefaultValuesNeighbors) |
| 277 | { |
| 278 | std::string config = SECTION_NEIGHBORS; |
| 279 | |
| 280 | commentOut("hello-retries", config); |
| 281 | commentOut("hello-timeout", config); |
| 282 | commentOut("hello-interval", config); |
| 283 | commentOut("first-hello-interval", config); |
| 284 | commentOut("adj-lsa-build-interval", config); |
| 285 | |
| 286 | BOOST_CHECK_EQUAL(processConfigurationString(config), true); |
| 287 | |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 288 | BOOST_CHECK_EQUAL(conf.getInterestRetryNumber(), static_cast<uint32_t>(HELLO_RETRIES_DEFAULT)); |
alvy | 5a45495 | 2014-12-15 12:49:54 -0600 | [diff] [blame] | 289 | BOOST_CHECK_EQUAL(conf.getInterestResendTime(), static_cast<uint32_t>(HELLO_TIMEOUT_DEFAULT)); |
| 290 | BOOST_CHECK_EQUAL(conf.getInfoInterestInterval(), static_cast<uint32_t>(HELLO_INTERVAL_DEFAULT)); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 291 | BOOST_CHECK_EQUAL(conf.getAdjLsaBuildInterval(), |
| 292 | static_cast<uint32_t>(ADJ_LSA_BUILD_INTERVAL_DEFAULT)); |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 293 | } |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 294 | |
Ashlesh Gawande | 9ecbdc9 | 2019-03-11 13:18:45 -0700 | [diff] [blame] | 295 | BOOST_AUTO_TEST_CASE(CanonizeNeighbors) |
| 296 | { |
| 297 | std::string config = std::string(R"INFO(neighbors |
| 298 | { |
| 299 | neighbor |
| 300 | { |
| 301 | name /ndn/edu/arizona/%C1.Router/hobo |
| 302 | face-uri udp4://hobo.cs.arizona.edu |
| 303 | link-cost 20 |
| 304 | } |
| 305 | neighbor |
| 306 | { |
| 307 | name /ndn/edu/umich/%C1.Router/ndn0 |
| 308 | face-uri udp4://michigan.testbed.named-data.net |
| 309 | link-cost 30 |
| 310 | } |
| 311 | })INFO"); |
| 312 | |
| 313 | BOOST_CHECK_EQUAL(processConfigurationString(config), true); |
| 314 | |
| 315 | BOOST_CHECK_EQUAL(conf.m_adjl.getAdjacent("/ndn/edu/arizona/%C1.Router/hobo").getFaceUri().toString(), |
| 316 | "udp4://128.196.203.36:6363"); |
| 317 | BOOST_CHECK_EQUAL(conf.m_adjl.getAdjacent("/ndn/edu/umich/%C1.Router/ndn0").getFaceUri().toString(), |
| 318 | "udp4://198.111.224.197:6363"); |
| 319 | } |
| 320 | |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 321 | BOOST_AUTO_TEST_CASE(DefaultValuesFib) |
| 322 | { |
| 323 | std::string config = SECTION_FIB; |
| 324 | |
| 325 | commentOut("max-faces-per-prefix", config); |
| 326 | commentOut("routing-calc-interval", config); |
| 327 | |
| 328 | BOOST_CHECK_EQUAL(processConfigurationString(config), true); |
| 329 | |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 330 | BOOST_CHECK_EQUAL(conf.getMaxFacesPerPrefix(), |
| 331 | static_cast<uint32_t>(MAX_FACES_PER_PREFIX_DEFAULT)); |
| 332 | BOOST_CHECK_EQUAL(conf.getRoutingCalcInterval(), |
| 333 | static_cast<uint32_t>(ROUTING_CALC_INTERVAL_DEFAULT)); |
| 334 | } |
| 335 | |
| 336 | BOOST_AUTO_TEST_CASE(DefaultValuesHyperbolic) |
| 337 | { |
| 338 | std::string config = SECTION_HYPERBOLIC_ON; |
| 339 | |
| 340 | commentOut("state", config); |
| 341 | |
| 342 | BOOST_CHECK_EQUAL(processConfigurationString(config), true); |
| 343 | |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 344 | BOOST_CHECK_EQUAL(conf.getHyperbolicState(), static_cast<int32_t>(HYPERBOLIC_STATE_DEFAULT)); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | BOOST_AUTO_TEST_CASE(OutOfRangeValue) |
| 348 | { |
| 349 | const std::string SECTION_FIB_OUT_OF_RANGE = |
| 350 | "fib\n" |
| 351 | "{\n" |
| 352 | " max-faces-per-prefix 3\n" |
| 353 | " routing-calc-interval 999\n" // Larger than max value |
| 354 | "}\n\n"; |
| 355 | |
| 356 | // Processing should fail due to out of range value |
| 357 | BOOST_CHECK_EQUAL(processConfigurationString(SECTION_FIB_OUT_OF_RANGE), false); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 358 | } |
| 359 | |
alvy | 5a45495 | 2014-12-15 12:49:54 -0600 | [diff] [blame] | 360 | BOOST_AUTO_TEST_CASE(NegativeValue) |
| 361 | { |
| 362 | const std::string SECTION_GENERAL_NEGATIVE_VALUE = |
| 363 | "general\n" |
| 364 | "{\n" |
| 365 | " network /ndn/\n" |
| 366 | " site /memphis.edu/\n" |
| 367 | " router /cs/pollux/\n" |
| 368 | " lsa-refresh-time -1800\n" |
| 369 | " lsa-interest-lifetime -3\n" |
| 370 | " router-dead-interval -86400\n" |
| 371 | "}\n\n"; |
| 372 | |
| 373 | // Processing should fail due to negative value |
| 374 | BOOST_CHECK_EQUAL(processConfigurationString(SECTION_GENERAL_NEGATIVE_VALUE), false); |
| 375 | } |
| 376 | |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 377 | BOOST_AUTO_TEST_CASE(LoadCertToPublish) |
| 378 | { |
Davide Pesavento | 8de8a8b | 2022-05-12 01:26:43 -0400 | [diff] [blame] | 379 | auto identity = m_keyChain.createIdentity("/TestNLSR/identity"); |
| 380 | saveIdentityCert(identity, "cert-to-publish.cert"); |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 381 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 382 | const std::string SECTION_SECURITY = R"CONF( |
| 383 | security |
| 384 | { |
| 385 | validator |
| 386 | { |
| 387 | trust-anchor |
| 388 | { |
| 389 | type any |
| 390 | } |
| 391 | } |
| 392 | prefix-update-validator |
| 393 | { |
| 394 | trust-anchor |
| 395 | { |
| 396 | type any |
| 397 | } |
| 398 | } |
| 399 | cert-to-publish "cert-to-publish.cert" |
| 400 | } |
| 401 | )CONF"; |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 402 | |
| 403 | BOOST_CHECK(processConfigurationString(SECTION_SECURITY)); |
| 404 | |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 405 | } |
| 406 | |
Vince Lehman | d33e5bc | 2015-06-22 15:27:50 -0500 | [diff] [blame] | 407 | BOOST_AUTO_TEST_CASE(PrefixUpdateValidatorOptional) // Bug #2814 |
| 408 | { |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 409 | const std::string SECTION_SECURITY = R"CONF( |
| 410 | security |
| 411 | { |
| 412 | validator |
| 413 | { |
| 414 | trust-anchor |
| 415 | { |
| 416 | type any |
| 417 | } |
| 418 | } |
| 419 | } |
| 420 | )CONF"; |
Vince Lehman | d33e5bc | 2015-06-22 15:27:50 -0500 | [diff] [blame] | 421 | |
| 422 | BOOST_CHECK(processConfigurationString(SECTION_SECURITY)); |
| 423 | } |
| 424 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 425 | BOOST_AUTO_TEST_SUITE_END() |
| 426 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 427 | } // namespace test |
| 428 | } // namespace nlsr |