akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 2 | /** |
dmcoomes | cf8d0ed | 2017-02-21 11:39:01 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2018, 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" |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 23 | #include "test-common.hpp" |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 24 | #include "nlsr.hpp" |
Muktadir R Chowdhury | bfa2760 | 2014-10-31 10:57:41 -0500 | [diff] [blame] | 25 | |
Nick Gordon | ff9a627 | 2017-10-12 13:38:29 -0500 | [diff] [blame] | 26 | #include <fstream> |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 27 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 28 | #include <boost/test/unit_test.hpp> |
Muktadir R Chowdhury | bfa2760 | 2014-10-31 10:57:41 -0500 | [diff] [blame] | 29 | #include <boost/filesystem.hpp> |
| 30 | #include <boost/algorithm/string.hpp> |
Muktadir R Chowdhury | c69da0a | 2015-12-18 13:24:38 -0600 | [diff] [blame] | 31 | #include <ndn-cxx/util/dummy-client-face.hpp> |
| 32 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 33 | namespace nlsr { |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 34 | namespace test { |
| 35 | |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 36 | using std::shared_ptr; |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 37 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 38 | const std::string SECTION_GENERAL = |
| 39 | "general\n" |
| 40 | "{\n" |
| 41 | " network /ndn/\n" |
| 42 | " site /memphis.edu/\n" |
| 43 | " router /cs/pollux/\n" |
| 44 | " lsa-refresh-time 1800\n" |
| 45 | " lsa-interest-lifetime 3\n" |
Alexander Afanasyev | 1cf1e10 | 2014-08-17 19:47:57 -0700 | [diff] [blame] | 46 | " router-dead-interval 86400\n" |
Ashlesh Gawande | f7da9c5 | 2018-02-06 17:36:46 -0600 | [diff] [blame] | 47 | " sync-interest-lifetime 10000\n" |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 48 | " seq-dir /tmp\n" |
| 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" |
| 57 | " adj-lsa-build-interval 3\n" |
| 58 | " first-hello-interval 6\n" |
| 59 | " neighbor\n" |
| 60 | " {\n" |
| 61 | " name /ndn/memphis.edu/cs/castor\n" |
| 62 | " face-uri udp4://localhost\n" |
| 63 | " link-cost 20\n" |
| 64 | " }\n\n" |
| 65 | " neighbor\n" |
| 66 | " {\n" |
| 67 | " name /ndn/memphis.edu/cs/mira\n" |
| 68 | " face-uri udp4://localhost\n" |
| 69 | " link-cost 30\n" |
| 70 | " }\n" |
| 71 | "}\n\n"; |
| 72 | |
| 73 | const std::string SECTION_HYPERBOLIC_ON = |
| 74 | "hyperbolic\n" |
| 75 | "{\n" |
| 76 | " state on\n" |
| 77 | " radius 123.456\n" |
| 78 | " angle 1.45\n" |
| 79 | "}\n\n"; |
| 80 | |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 81 | const std::string SECTION_HYPERBOLIC_ANGLES_ON = |
| 82 | "hyperbolic\n" |
| 83 | "{\n" |
| 84 | " state on\n" |
| 85 | " radius 123.456\n" |
| 86 | " angle 1.45,2.25\n" |
| 87 | "}\n\n"; |
| 88 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 89 | const std::string SECTION_HYPERBOLIC_OFF = |
| 90 | "hyperbolic\n" |
| 91 | "{\n" |
| 92 | " state off\n" |
| 93 | " radius 123.456\n" |
| 94 | " angle 1.45\n" |
| 95 | "}\n\n"; |
| 96 | |
| 97 | const std::string SECTION_FIB = |
| 98 | "fib\n" |
| 99 | "{\n" |
| 100 | " max-faces-per-prefix 3\n" |
| 101 | " routing-calc-interval 9\n" |
| 102 | "}\n\n"; |
| 103 | |
| 104 | const std::string SECTION_ADVERTISING = |
| 105 | "advertising\n" |
| 106 | "{\n" |
| 107 | " prefix /ndn/edu/memphis/cs/netlab\n" |
| 108 | " prefix /ndn/edu/memphis/sports/basketball\n" |
| 109 | "}\n"; |
| 110 | |
| 111 | const std::string CONFIG_LINK_STATE = SECTION_GENERAL + SECTION_NEIGHBORS + |
| 112 | SECTION_HYPERBOLIC_OFF + SECTION_FIB + SECTION_ADVERTISING; |
| 113 | |
| 114 | const std::string CONFIG_HYPERBOLIC = SECTION_GENERAL + SECTION_NEIGHBORS + |
| 115 | SECTION_HYPERBOLIC_ON + SECTION_FIB + SECTION_ADVERTISING; |
| 116 | |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 117 | const std::string CONFIG_HYPERBOLIC_ANGLES = SECTION_GENERAL + SECTION_NEIGHBORS + |
| 118 | SECTION_HYPERBOLIC_ANGLES_ON + SECTION_FIB + |
| 119 | SECTION_ADVERTISING; |
| 120 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 121 | class ConfFileProcessorFixture : public BaseFixture |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 122 | { |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 123 | public: |
| 124 | ConfFileProcessorFixture() |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 125 | : face(m_ioService, m_keyChain) |
| 126 | , nlsr(m_ioService, m_scheduler, face, m_keyChain) |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 127 | , CONFIG_FILE("unit-test-nlsr.conf") |
| 128 | { |
| 129 | } |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 130 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 131 | ~ConfFileProcessorFixture() |
| 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 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 144 | ConfFileProcessor processor(nlsr, CONFIG_FILE); |
| 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; |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 156 | Nlsr nlsr; |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 157 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 158 | private: |
| 159 | const std::string CONFIG_FILE; |
| 160 | }; |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 161 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 162 | BOOST_FIXTURE_TEST_SUITE(TestConfFileProcessor, ConfFileProcessorFixture) |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 163 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 164 | BOOST_AUTO_TEST_CASE(LinkState) |
| 165 | { |
| 166 | processConfigurationString(CONFIG_LINK_STATE); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 167 | ConfParameter& conf = nlsr.getConfParameter(); |
| 168 | conf.buildRouterPrefix(); |
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 | // General |
| 171 | BOOST_CHECK_EQUAL(conf.getNetwork(), "/ndn/"); |
| 172 | BOOST_CHECK_EQUAL(conf.getSiteName(), "/memphis.edu/"); |
| 173 | BOOST_CHECK_EQUAL(conf.getRouterName(), "/cs/pollux/"); |
| 174 | BOOST_CHECK_EQUAL(conf.getRouterPrefix(), "/ndn/memphis.edu/cs/pollux/"); |
Ashlesh Gawande | cba0ae2 | 2018-03-27 17:57:56 -0500 | [diff] [blame^] | 175 | BOOST_CHECK_EQUAL(conf.getChronosyncPrefix(), ndn::Name("/localhop/ndn/nlsr/sync").appendVersion(ConfParameter::SYNC_VERSION)); |
| 176 | BOOST_CHECK_EQUAL(conf.getLsaPrefix(), "/localhop/ndn/nlsr/LSA"); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 177 | BOOST_CHECK_EQUAL(conf.getLsaRefreshTime(), 1800); |
| 178 | BOOST_CHECK_EQUAL(conf.getLsaInterestLifetime(), ndn::time::seconds(3)); |
Alexander Afanasyev | 1cf1e10 | 2014-08-17 19:47:57 -0700 | [diff] [blame] | 179 | BOOST_CHECK_EQUAL(conf.getRouterDeadInterval(), 86400); |
Ashlesh Gawande | f7da9c5 | 2018-02-06 17:36:46 -0600 | [diff] [blame] | 180 | BOOST_CHECK_EQUAL(conf.getSyncInterestLifetime(), ndn::time::milliseconds(10000)); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 181 | BOOST_CHECK_EQUAL(conf.getSeqFileDir(), "/tmp"); |
Alexander Afanasyev | 411ee4b | 2014-08-16 23:17:03 -0700 | [diff] [blame] | 182 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 183 | // Neighbors |
| 184 | BOOST_CHECK_EQUAL(conf.getInterestRetryNumber(), 3); |
| 185 | BOOST_CHECK_EQUAL(conf.getInterestResendTime(), 1); |
| 186 | BOOST_CHECK_EQUAL(conf.getInfoInterestInterval(), 60); |
| 187 | |
| 188 | BOOST_CHECK_EQUAL(conf.getAdjLsaBuildInterval(), 3); |
| 189 | BOOST_CHECK_EQUAL(conf.getFirstHelloInterval(), 6); |
| 190 | |
| 191 | BOOST_CHECK(nlsr.getAdjacencyList().isNeighbor("/ndn/memphis.edu/cs/mira")); |
| 192 | BOOST_CHECK(nlsr.getAdjacencyList().isNeighbor("/ndn/memphis.edu/cs/castor")); |
| 193 | BOOST_CHECK(!nlsr.getAdjacencyList().isNeighbor("/ndn/memphis.edu/cs/fail")); |
| 194 | |
| 195 | Adjacent mira = nlsr.getAdjacencyList().getAdjacent("/ndn/memphis.edu/cs/mira"); |
| 196 | BOOST_CHECK_EQUAL(mira.getName(), "/ndn/memphis.edu/cs/mira"); |
| 197 | BOOST_CHECK_EQUAL(mira.getLinkCost(), 30); |
| 198 | |
| 199 | Adjacent castor = nlsr.getAdjacencyList().getAdjacent("/ndn/memphis.edu/cs/castor"); |
| 200 | BOOST_CHECK_EQUAL(castor.getName(), "/ndn/memphis.edu/cs/castor"); |
| 201 | BOOST_CHECK_EQUAL(castor.getLinkCost(), 20); |
| 202 | |
| 203 | // Hyperbolic |
| 204 | BOOST_CHECK_EQUAL(conf.getHyperbolicState(), 0); |
| 205 | |
| 206 | // FIB |
| 207 | BOOST_CHECK_EQUAL(conf.getMaxFacesPerPrefix(), 3); |
| 208 | BOOST_CHECK_EQUAL(conf.getRoutingCalcInterval(), 9); |
| 209 | |
| 210 | // Advertising |
Nick Gordon | ff9a627 | 2017-10-12 13:38:29 -0500 | [diff] [blame] | 211 | BOOST_CHECK_EQUAL(nlsr.getNamePrefixList().size(), 2); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 212 | } |
| 213 | |
alvy | 2fe1287 | 2014-11-25 10:32:23 -0600 | [diff] [blame] | 214 | BOOST_AUTO_TEST_CASE(MalformedUri) |
| 215 | { |
| 216 | const std::string MALFORMED_URI = |
| 217 | "neighbors\n" |
| 218 | "{\n" |
| 219 | " hello-retries 3\n" |
| 220 | " hello-timeout 1\n" |
| 221 | " hello-interval 60\n\n" |
| 222 | " adj-lsa-build-interval 3\n" |
| 223 | " first-hello-interval 6\n" |
| 224 | " neighbor\n" |
| 225 | " {\n" |
| 226 | " name /ndn/memphis.edu/cs/castor\n" |
| 227 | " face-uri udp4:malformed-uri\n" |
| 228 | " link-cost 20\n" |
| 229 | " }\n" |
| 230 | "}\n\n"; |
| 231 | |
| 232 | BOOST_CHECK_EQUAL(processConfigurationString(MALFORMED_URI), false); |
| 233 | } |
| 234 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 235 | BOOST_AUTO_TEST_CASE(Hyperbolic) |
| 236 | { |
| 237 | processConfigurationString(CONFIG_HYPERBOLIC); |
| 238 | |
| 239 | ConfParameter& conf = nlsr.getConfParameter(); |
| 240 | BOOST_CHECK_EQUAL(conf.getHyperbolicState(), 1); |
| 241 | BOOST_CHECK_EQUAL(conf.getCorR(), 123.456); |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 242 | std::vector<double> angles; |
| 243 | angles.push_back(1.45); |
| 244 | BOOST_CHECK(conf.getCorTheta() == angles); |
| 245 | } |
| 246 | |
| 247 | BOOST_AUTO_TEST_CASE(Hyperbolic2) |
| 248 | { |
| 249 | processConfigurationString(CONFIG_HYPERBOLIC_ANGLES); |
| 250 | |
| 251 | ConfParameter& conf = nlsr.getConfParameter(); |
| 252 | BOOST_CHECK_EQUAL(conf.getHyperbolicState(), 1); |
| 253 | BOOST_CHECK_EQUAL(conf.getCorR(), 123.456); |
| 254 | std::vector<double> angles; |
| 255 | angles.push_back(1.45); |
| 256 | angles.push_back(2.25); |
| 257 | BOOST_CHECK(conf.getCorTheta() == angles); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 258 | } |
| 259 | |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 260 | BOOST_AUTO_TEST_CASE(DefaultValuesGeneral) |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 261 | { |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 262 | std::string config = SECTION_GENERAL; |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 263 | |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 264 | commentOut("lsa-refresh-time", config); |
| 265 | commentOut("lsa-interest-lifetime", config); |
| 266 | commentOut("router-dead-interval", config); |
| 267 | |
| 268 | BOOST_CHECK_EQUAL(processConfigurationString(config), true); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 269 | |
| 270 | ConfParameter& conf = nlsr.getConfParameter(); |
| 271 | |
alvy | 5a45495 | 2014-12-15 12:49:54 -0600 | [diff] [blame] | 272 | BOOST_CHECK_EQUAL(conf.getLsaRefreshTime(), static_cast<uint32_t>(LSA_REFRESH_TIME_DEFAULT)); |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 273 | BOOST_CHECK_EQUAL(conf.getLsaInterestLifetime(), |
| 274 | static_cast<ndn::time::seconds>(LSA_INTEREST_LIFETIME_DEFAULT)); |
| 275 | BOOST_CHECK_EQUAL(conf.getRouterDeadInterval(), (2*conf.getLsaRefreshTime())); |
| 276 | } |
| 277 | |
| 278 | BOOST_AUTO_TEST_CASE(DefaultValuesNeighbors) |
| 279 | { |
| 280 | std::string config = SECTION_NEIGHBORS; |
| 281 | |
| 282 | commentOut("hello-retries", config); |
| 283 | commentOut("hello-timeout", config); |
| 284 | commentOut("hello-interval", config); |
| 285 | commentOut("first-hello-interval", config); |
| 286 | commentOut("adj-lsa-build-interval", config); |
| 287 | |
| 288 | BOOST_CHECK_EQUAL(processConfigurationString(config), true); |
| 289 | |
| 290 | ConfParameter& conf = nlsr.getConfParameter(); |
| 291 | |
| 292 | BOOST_CHECK_EQUAL(conf.getInterestRetryNumber(), static_cast<uint32_t>(HELLO_RETRIES_DEFAULT)); |
alvy | 5a45495 | 2014-12-15 12:49:54 -0600 | [diff] [blame] | 293 | BOOST_CHECK_EQUAL(conf.getInterestResendTime(), static_cast<uint32_t>(HELLO_TIMEOUT_DEFAULT)); |
| 294 | BOOST_CHECK_EQUAL(conf.getInfoInterestInterval(), static_cast<uint32_t>(HELLO_INTERVAL_DEFAULT)); |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 295 | BOOST_CHECK_EQUAL(conf.getFirstHelloInterval(), |
| 296 | static_cast<uint32_t>(FIRST_HELLO_INTERVAL_DEFAULT)); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 297 | BOOST_CHECK_EQUAL(conf.getAdjLsaBuildInterval(), |
| 298 | static_cast<uint32_t>(ADJ_LSA_BUILD_INTERVAL_DEFAULT)); |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 299 | } |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 300 | |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 301 | BOOST_AUTO_TEST_CASE(DefaultValuesFib) |
| 302 | { |
| 303 | std::string config = SECTION_FIB; |
| 304 | |
| 305 | commentOut("max-faces-per-prefix", config); |
| 306 | commentOut("routing-calc-interval", config); |
| 307 | |
| 308 | BOOST_CHECK_EQUAL(processConfigurationString(config), true); |
| 309 | |
| 310 | ConfParameter& conf = nlsr.getConfParameter(); |
| 311 | |
| 312 | BOOST_CHECK_EQUAL(conf.getMaxFacesPerPrefix(), |
| 313 | static_cast<uint32_t>(MAX_FACES_PER_PREFIX_DEFAULT)); |
| 314 | BOOST_CHECK_EQUAL(conf.getRoutingCalcInterval(), |
| 315 | static_cast<uint32_t>(ROUTING_CALC_INTERVAL_DEFAULT)); |
| 316 | } |
| 317 | |
| 318 | BOOST_AUTO_TEST_CASE(DefaultValuesHyperbolic) |
| 319 | { |
| 320 | std::string config = SECTION_HYPERBOLIC_ON; |
| 321 | |
| 322 | commentOut("state", config); |
| 323 | |
| 324 | BOOST_CHECK_EQUAL(processConfigurationString(config), true); |
| 325 | |
| 326 | ConfParameter& conf = nlsr.getConfParameter(); |
| 327 | |
| 328 | BOOST_CHECK_EQUAL(conf.getHyperbolicState(), static_cast<int32_t>(HYPERBOLIC_STATE_DEFAULT)); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | BOOST_AUTO_TEST_CASE(OutOfRangeValue) |
| 332 | { |
| 333 | const std::string SECTION_FIB_OUT_OF_RANGE = |
| 334 | "fib\n" |
| 335 | "{\n" |
| 336 | " max-faces-per-prefix 3\n" |
| 337 | " routing-calc-interval 999\n" // Larger than max value |
| 338 | "}\n\n"; |
| 339 | |
| 340 | // Processing should fail due to out of range value |
| 341 | BOOST_CHECK_EQUAL(processConfigurationString(SECTION_FIB_OUT_OF_RANGE), false); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 342 | } |
| 343 | |
alvy | 5a45495 | 2014-12-15 12:49:54 -0600 | [diff] [blame] | 344 | BOOST_AUTO_TEST_CASE(NegativeValue) |
| 345 | { |
| 346 | const std::string SECTION_GENERAL_NEGATIVE_VALUE = |
| 347 | "general\n" |
| 348 | "{\n" |
| 349 | " network /ndn/\n" |
| 350 | " site /memphis.edu/\n" |
| 351 | " router /cs/pollux/\n" |
| 352 | " lsa-refresh-time -1800\n" |
| 353 | " lsa-interest-lifetime -3\n" |
| 354 | " router-dead-interval -86400\n" |
| 355 | "}\n\n"; |
| 356 | |
| 357 | // Processing should fail due to negative value |
| 358 | BOOST_CHECK_EQUAL(processConfigurationString(SECTION_GENERAL_NEGATIVE_VALUE), false); |
| 359 | } |
| 360 | |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 361 | BOOST_AUTO_TEST_CASE(LoadCertToPublish) |
| 362 | { |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 363 | auto identity = addIdentity("/TestNLSR/identity"); |
| 364 | saveCertificate(identity, "cert-to-publish.cert"); |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 365 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 366 | const std::string SECTION_SECURITY = R"CONF( |
| 367 | security |
| 368 | { |
| 369 | validator |
| 370 | { |
| 371 | trust-anchor |
| 372 | { |
| 373 | type any |
| 374 | } |
| 375 | } |
| 376 | prefix-update-validator |
| 377 | { |
| 378 | trust-anchor |
| 379 | { |
| 380 | type any |
| 381 | } |
| 382 | } |
| 383 | cert-to-publish "cert-to-publish.cert" |
| 384 | } |
| 385 | )CONF"; |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 386 | |
| 387 | BOOST_CHECK(processConfigurationString(SECTION_SECURITY)); |
| 388 | |
| 389 | // Certificate should now be in the CertificateStore |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 390 | security::CertificateStore& certStore = nlsr.getCertificateStore(); |
| 391 | BOOST_CHECK(certStore.find(identity.getDefaultKey().getName()) != nullptr); |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 392 | } |
| 393 | |
Vince Lehman | d33e5bc | 2015-06-22 15:27:50 -0500 | [diff] [blame] | 394 | BOOST_AUTO_TEST_CASE(PrefixUpdateValidatorOptional) // Bug #2814 |
| 395 | { |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 396 | const std::string SECTION_SECURITY = R"CONF( |
| 397 | security |
| 398 | { |
| 399 | validator |
| 400 | { |
| 401 | trust-anchor |
| 402 | { |
| 403 | type any |
| 404 | } |
| 405 | } |
| 406 | } |
| 407 | )CONF"; |
Vince Lehman | d33e5bc | 2015-06-22 15:27:50 -0500 | [diff] [blame] | 408 | |
| 409 | BOOST_CHECK(processConfigurationString(SECTION_SECURITY)); |
| 410 | } |
| 411 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 412 | BOOST_AUTO_TEST_SUITE_END() |
| 413 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 414 | } // namespace test |
| 415 | } // namespace nlsr |