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 | /** |
Nick Gordon | feae557 | 2017-01-13 12:06:26 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, 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" |
Muktadir R Chowdhury | bfa2760 | 2014-10-31 10:57:41 -0500 | [diff] [blame] | 24 | #include "logger.hpp" |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 25 | #include "nlsr.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 Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 28 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 29 | #include <boost/test/unit_test.hpp> |
Muktadir R Chowdhury | bfa2760 | 2014-10-31 10:57:41 -0500 | [diff] [blame] | 30 | #include <boost/filesystem.hpp> |
| 31 | #include <boost/algorithm/string.hpp> |
Muktadir R Chowdhury | c69da0a | 2015-12-18 13:24:38 -0600 | [diff] [blame] | 32 | #include <ndn-cxx/util/dummy-client-face.hpp> |
| 33 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 34 | namespace nlsr { |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 35 | namespace test { |
| 36 | |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 37 | using std::shared_ptr; |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 38 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 39 | const std::string SECTION_GENERAL = |
| 40 | "general\n" |
| 41 | "{\n" |
| 42 | " network /ndn/\n" |
| 43 | " site /memphis.edu/\n" |
| 44 | " router /cs/pollux/\n" |
| 45 | " lsa-refresh-time 1800\n" |
| 46 | " lsa-interest-lifetime 3\n" |
Alexander Afanasyev | 1cf1e10 | 2014-08-17 19:47:57 -0700 | [diff] [blame] | 47 | " router-dead-interval 86400\n" |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 48 | " log-level INFO\n" |
| 49 | " log-dir /tmp\n" |
| 50 | " seq-dir /tmp\n" |
| 51 | "}\n\n"; |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 52 | |
Muktadir R Chowdhury | bfa2760 | 2014-10-31 10:57:41 -0500 | [diff] [blame] | 53 | const std::string LOG4CXX_PLACEHOLDER = "$LOG4CXX$"; |
| 54 | |
| 55 | const std::string SECTION_GENERAL_WITH_LOG4CXX = |
| 56 | "general\n" |
| 57 | "{\n" |
| 58 | " network /ndn/\n" |
| 59 | " site /memphis.edu/\n" |
| 60 | " router /cs/pollux/\n" |
| 61 | " lsa-refresh-time 1800\n" |
| 62 | " lsa-interest-lifetime 3\n" |
| 63 | " router-dead-interval 86400\n" |
| 64 | " log-level INFO\n" |
| 65 | " log-dir /tmp\n" |
| 66 | " seq-dir /tmp\n" |
| 67 | " log4cxx-conf " + LOG4CXX_PLACEHOLDER + "\n" |
| 68 | "}\n\n"; |
| 69 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 70 | const std::string SECTION_NEIGHBORS = |
| 71 | "neighbors\n" |
| 72 | "{\n" |
| 73 | " hello-retries 3\n" |
| 74 | " hello-timeout 1\n" |
| 75 | " hello-interval 60\n\n" |
| 76 | " adj-lsa-build-interval 3\n" |
| 77 | " first-hello-interval 6\n" |
| 78 | " neighbor\n" |
| 79 | " {\n" |
| 80 | " name /ndn/memphis.edu/cs/castor\n" |
| 81 | " face-uri udp4://localhost\n" |
| 82 | " link-cost 20\n" |
| 83 | " }\n\n" |
| 84 | " neighbor\n" |
| 85 | " {\n" |
| 86 | " name /ndn/memphis.edu/cs/mira\n" |
| 87 | " face-uri udp4://localhost\n" |
| 88 | " link-cost 30\n" |
| 89 | " }\n" |
| 90 | "}\n\n"; |
| 91 | |
| 92 | const std::string SECTION_HYPERBOLIC_ON = |
| 93 | "hyperbolic\n" |
| 94 | "{\n" |
| 95 | " state on\n" |
| 96 | " radius 123.456\n" |
| 97 | " angle 1.45\n" |
| 98 | "}\n\n"; |
| 99 | |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 100 | const std::string SECTION_HYPERBOLIC_ANGLES_ON = |
| 101 | "hyperbolic\n" |
| 102 | "{\n" |
| 103 | " state on\n" |
| 104 | " radius 123.456\n" |
| 105 | " angle 1.45,2.25\n" |
| 106 | "}\n\n"; |
| 107 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 108 | const std::string SECTION_HYPERBOLIC_OFF = |
| 109 | "hyperbolic\n" |
| 110 | "{\n" |
| 111 | " state off\n" |
| 112 | " radius 123.456\n" |
| 113 | " angle 1.45\n" |
| 114 | "}\n\n"; |
| 115 | |
| 116 | const std::string SECTION_FIB = |
| 117 | "fib\n" |
| 118 | "{\n" |
| 119 | " max-faces-per-prefix 3\n" |
| 120 | " routing-calc-interval 9\n" |
| 121 | "}\n\n"; |
| 122 | |
| 123 | const std::string SECTION_ADVERTISING = |
| 124 | "advertising\n" |
| 125 | "{\n" |
| 126 | " prefix /ndn/edu/memphis/cs/netlab\n" |
| 127 | " prefix /ndn/edu/memphis/sports/basketball\n" |
| 128 | "}\n"; |
| 129 | |
| 130 | const std::string CONFIG_LINK_STATE = SECTION_GENERAL + SECTION_NEIGHBORS + |
| 131 | SECTION_HYPERBOLIC_OFF + SECTION_FIB + SECTION_ADVERTISING; |
| 132 | |
Muktadir R Chowdhury | bfa2760 | 2014-10-31 10:57:41 -0500 | [diff] [blame] | 133 | const std::string CONFIG_LOG4CXX = SECTION_GENERAL_WITH_LOG4CXX; |
| 134 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 135 | const std::string CONFIG_HYPERBOLIC = SECTION_GENERAL + SECTION_NEIGHBORS + |
| 136 | SECTION_HYPERBOLIC_ON + SECTION_FIB + SECTION_ADVERTISING; |
| 137 | |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 138 | const std::string CONFIG_HYPERBOLIC_ANGLES = SECTION_GENERAL + SECTION_NEIGHBORS + |
| 139 | SECTION_HYPERBOLIC_ANGLES_ON + SECTION_FIB + |
| 140 | SECTION_ADVERTISING; |
| 141 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 142 | class ConfFileProcessorFixture : public BaseFixture |
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 | public: |
| 145 | ConfFileProcessorFixture() |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 146 | : face(m_ioService, m_keyChain) |
| 147 | , nlsr(m_ioService, m_scheduler, face, m_keyChain) |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 148 | , CONFIG_FILE("unit-test-nlsr.conf") |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 149 | , m_logConfigFileName(boost::filesystem::unique_path().string()) |
| 150 | , m_logFileName(boost::filesystem::unique_path().string()) |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 151 | { |
| 152 | } |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 153 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 154 | ~ConfFileProcessorFixture() |
| 155 | { |
| 156 | remove("unit-test-nlsr.conf"); |
Muktadir R Chowdhury | bfa2760 | 2014-10-31 10:57:41 -0500 | [diff] [blame] | 157 | remove("/tmp/unit-test-log4cxx.xml"); |
| 158 | |
| 159 | boost::filesystem::remove(boost::filesystem::path(getLogConfigFileName())); |
| 160 | boost::filesystem::remove(boost::filesystem::path(getLogFileName())); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 161 | } |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 162 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 163 | bool |
| 164 | processConfigurationString(std::string confString) |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 165 | { |
| 166 | std::ofstream config; |
| 167 | config.open("unit-test-nlsr.conf"); |
| 168 | config << confString; |
| 169 | config.close(); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 170 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 171 | ConfFileProcessor processor(nlsr, CONFIG_FILE); |
| 172 | return processor.processConfFile(); |
| 173 | } |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 174 | |
Muktadir R Chowdhury | bfa2760 | 2014-10-31 10:57:41 -0500 | [diff] [blame] | 175 | void |
| 176 | verifyOutputLog4cxx(const std::string expected[], size_t nExpected) |
| 177 | { |
| 178 | std::ifstream is(getLogFileName().c_str()); |
| 179 | std::string buffer((std::istreambuf_iterator<char>(is)), |
| 180 | (std::istreambuf_iterator<char>())); |
| 181 | |
| 182 | std::vector<std::string> components; |
| 183 | boost::split(components, buffer, boost::is_any_of(" ,\n")); |
| 184 | |
| 185 | // expected + number of timestamps (one per log statement) + trailing newline of last statement |
| 186 | BOOST_REQUIRE_EQUAL(components.size(), nExpected); |
| 187 | |
| 188 | for (size_t i = 0; i < nExpected; ++i) { |
| 189 | if (expected[i] == "") |
| 190 | continue; |
| 191 | |
| 192 | BOOST_CHECK_EQUAL(components[i], expected[i]); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | const std::string& |
| 197 | getLogConfigFileName() |
| 198 | { |
| 199 | return m_logConfigFileName; |
| 200 | } |
| 201 | |
| 202 | const std::string& |
| 203 | getLogFileName() |
| 204 | { |
| 205 | return m_logFileName; |
| 206 | } |
| 207 | |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 208 | void |
| 209 | commentOut(const std::string& key, std::string& config) |
| 210 | { |
| 211 | boost::replace_all(config, key, ";" + key); |
| 212 | } |
| 213 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 214 | public: |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 215 | ndn::util::DummyClientFace face; |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 216 | Nlsr nlsr; |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 217 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 218 | private: |
| 219 | const std::string CONFIG_FILE; |
Muktadir R Chowdhury | bfa2760 | 2014-10-31 10:57:41 -0500 | [diff] [blame] | 220 | std::string m_logConfigFileName; |
| 221 | std::string m_logFileName; |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 222 | }; |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 223 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 224 | BOOST_FIXTURE_TEST_SUITE(TestConfFileProcessor, ConfFileProcessorFixture) |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 225 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 226 | BOOST_AUTO_TEST_CASE(LinkState) |
| 227 | { |
| 228 | processConfigurationString(CONFIG_LINK_STATE); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 229 | ConfParameter& conf = nlsr.getConfParameter(); |
| 230 | conf.buildRouterPrefix(); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 231 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 232 | // General |
| 233 | BOOST_CHECK_EQUAL(conf.getNetwork(), "/ndn/"); |
| 234 | BOOST_CHECK_EQUAL(conf.getSiteName(), "/memphis.edu/"); |
| 235 | BOOST_CHECK_EQUAL(conf.getRouterName(), "/cs/pollux/"); |
| 236 | BOOST_CHECK_EQUAL(conf.getRouterPrefix(), "/ndn/memphis.edu/cs/pollux/"); |
Ashlesh Gawande | 8bfd124 | 2017-06-21 14:55:27 -0500 | [diff] [blame] | 237 | BOOST_CHECK_EQUAL(conf.getChronosyncPrefix(), "/localhop/ndn/NLSR/sync"); |
Ashlesh Gawande | 6077ea9 | 2017-01-19 11:48:29 -0600 | [diff] [blame] | 238 | BOOST_CHECK_EQUAL(conf.getLsaPrefix(), "/localhop/ndn/NLSR/LSA"); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 239 | BOOST_CHECK_EQUAL(conf.getLsaRefreshTime(), 1800); |
| 240 | BOOST_CHECK_EQUAL(conf.getLsaInterestLifetime(), ndn::time::seconds(3)); |
Alexander Afanasyev | 1cf1e10 | 2014-08-17 19:47:57 -0700 | [diff] [blame] | 241 | BOOST_CHECK_EQUAL(conf.getRouterDeadInterval(), 86400); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 242 | BOOST_CHECK_EQUAL(conf.getLogLevel(), "INFO"); |
| 243 | BOOST_CHECK_EQUAL(conf.getLogDir(), "/tmp"); |
| 244 | BOOST_CHECK_EQUAL(conf.getSeqFileDir(), "/tmp"); |
Alexander Afanasyev | 411ee4b | 2014-08-16 23:17:03 -0700 | [diff] [blame] | 245 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 246 | // Neighbors |
| 247 | BOOST_CHECK_EQUAL(conf.getInterestRetryNumber(), 3); |
| 248 | BOOST_CHECK_EQUAL(conf.getInterestResendTime(), 1); |
| 249 | BOOST_CHECK_EQUAL(conf.getInfoInterestInterval(), 60); |
| 250 | |
| 251 | BOOST_CHECK_EQUAL(conf.getAdjLsaBuildInterval(), 3); |
| 252 | BOOST_CHECK_EQUAL(conf.getFirstHelloInterval(), 6); |
| 253 | |
| 254 | BOOST_CHECK(nlsr.getAdjacencyList().isNeighbor("/ndn/memphis.edu/cs/mira")); |
| 255 | BOOST_CHECK(nlsr.getAdjacencyList().isNeighbor("/ndn/memphis.edu/cs/castor")); |
| 256 | BOOST_CHECK(!nlsr.getAdjacencyList().isNeighbor("/ndn/memphis.edu/cs/fail")); |
| 257 | |
| 258 | Adjacent mira = nlsr.getAdjacencyList().getAdjacent("/ndn/memphis.edu/cs/mira"); |
| 259 | BOOST_CHECK_EQUAL(mira.getName(), "/ndn/memphis.edu/cs/mira"); |
| 260 | BOOST_CHECK_EQUAL(mira.getLinkCost(), 30); |
| 261 | |
| 262 | Adjacent castor = nlsr.getAdjacencyList().getAdjacent("/ndn/memphis.edu/cs/castor"); |
| 263 | BOOST_CHECK_EQUAL(castor.getName(), "/ndn/memphis.edu/cs/castor"); |
| 264 | BOOST_CHECK_EQUAL(castor.getLinkCost(), 20); |
| 265 | |
| 266 | // Hyperbolic |
| 267 | BOOST_CHECK_EQUAL(conf.getHyperbolicState(), 0); |
| 268 | |
| 269 | // FIB |
| 270 | BOOST_CHECK_EQUAL(conf.getMaxFacesPerPrefix(), 3); |
| 271 | BOOST_CHECK_EQUAL(conf.getRoutingCalcInterval(), 9); |
| 272 | |
| 273 | // Advertising |
Nick Gordon | ff9a627 | 2017-10-12 13:38:29 -0500 | [diff] [blame] | 274 | BOOST_CHECK_EQUAL(nlsr.getNamePrefixList().size(), 2); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 275 | } |
| 276 | |
Muktadir R Chowdhury | bfa2760 | 2014-10-31 10:57:41 -0500 | [diff] [blame] | 277 | BOOST_AUTO_TEST_CASE(Log4cxxFileExists) |
| 278 | { |
| 279 | std::string configPath = boost::filesystem::unique_path().native(); |
| 280 | |
| 281 | std::ofstream log4cxxConfFile; |
| 282 | log4cxxConfFile.open(configPath); |
| 283 | log4cxxConfFile.close(); |
| 284 | |
| 285 | std::string config = CONFIG_LOG4CXX; |
| 286 | boost::replace_all(config, LOG4CXX_PLACEHOLDER, configPath); |
| 287 | |
| 288 | BOOST_CHECK_EQUAL(processConfigurationString(config), true); |
| 289 | |
| 290 | ConfParameter& conf = nlsr.getConfParameter(); |
| 291 | BOOST_CHECK_EQUAL(conf.getLog4CxxConfPath(), configPath); |
| 292 | BOOST_CHECK_EQUAL(conf.isLog4CxxConfAvailable(), true); |
| 293 | |
| 294 | boost::filesystem::remove(boost::filesystem::path(configPath)); |
| 295 | } |
| 296 | |
| 297 | BOOST_AUTO_TEST_CASE(Log4cxxFileDoesNotExist) |
| 298 | { |
| 299 | std::string configPath = boost::filesystem::unique_path().native(); |
| 300 | |
| 301 | std::string config = CONFIG_LOG4CXX; |
| 302 | boost::replace_all(config, LOG4CXX_PLACEHOLDER, configPath); |
| 303 | |
| 304 | BOOST_CHECK_EQUAL(processConfigurationString(config), false); |
| 305 | } |
| 306 | |
| 307 | BOOST_AUTO_TEST_CASE(Log4cxxNoValue) |
| 308 | { |
| 309 | std::string config = CONFIG_LOG4CXX; |
| 310 | boost::replace_all(config, LOG4CXX_PLACEHOLDER, ""); |
| 311 | |
| 312 | BOOST_CHECK_EQUAL(processConfigurationString(config), false); |
| 313 | } |
| 314 | |
| 315 | BOOST_AUTO_TEST_CASE(Log4cxxTestCase) |
| 316 | { |
| 317 | { |
| 318 | std::ofstream of(getLogConfigFileName().c_str()); |
| 319 | of << "log4j.rootLogger=TRACE, FILE\n" |
| 320 | << "log4j.appender.FILE=org.apache.log4j.FileAppender\n" |
| 321 | << "log4j.appender.FILE.layout=org.apache.log4j.PatternLayout\n" |
| 322 | << "log4j.appender.FILE.File=" << getLogFileName() << "\n" |
| 323 | << "log4j.appender.FILE.ImmediateFlush=true\n" |
| 324 | << "log4j.appender.FILE.layout.ConversionPattern=%d{HH:mm:ss} %p %c{1} - %m%n\n"; |
| 325 | } |
| 326 | |
| 327 | INIT_LOG4CXX(getLogConfigFileName()); |
| 328 | |
| 329 | INIT_LOGGER("DefaultConfig"); |
| 330 | |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 331 | NLSR_LOG_TRACE("trace-message-JHGFDSR^1"); |
| 332 | NLSR_LOG_DEBUG("debug-message-IGg2474fdksd-fo-" << 15 << 16 << 17); |
| 333 | NLSR_LOG_INFO("info-message-Jjxjshj13"); |
| 334 | NLSR_LOG_WARN("warning-message-XXXhdhd11" << 1 <<"x"); |
| 335 | NLSR_LOG_ERROR("error-message-!#$&^%$#@"); |
| 336 | NLSR_LOG_FATAL("fatal-message-JJSjaamcng"); |
Muktadir R Chowdhury | bfa2760 | 2014-10-31 10:57:41 -0500 | [diff] [blame] | 337 | |
| 338 | const std::string EXPECTED[] = |
| 339 | { |
| 340 | "", "TRACE", "DefaultConfig", "-", "trace-message-JHGFDSR^1", |
| 341 | "", "DEBUG", "DefaultConfig", "-", "debug-message-IGg2474fdksd-fo-151617", |
| 342 | "", "INFO", "DefaultConfig", "-", "info-message-Jjxjshj13", |
| 343 | "", "WARN", "DefaultConfig", "-", "warning-message-XXXhdhd111x", |
| 344 | "", "ERROR", "DefaultConfig", "-", "error-message-!#$&^%$#@", |
| 345 | "", "FATAL", "DefaultConfig", "-", "fatal-message-JJSjaamcng", |
| 346 | "", |
| 347 | }; |
| 348 | |
| 349 | verifyOutputLog4cxx(EXPECTED, sizeof(EXPECTED) / sizeof(std::string)); |
| 350 | } |
| 351 | |
alvy | 2fe1287 | 2014-11-25 10:32:23 -0600 | [diff] [blame] | 352 | BOOST_AUTO_TEST_CASE(MalformedUri) |
| 353 | { |
| 354 | const std::string MALFORMED_URI = |
| 355 | "neighbors\n" |
| 356 | "{\n" |
| 357 | " hello-retries 3\n" |
| 358 | " hello-timeout 1\n" |
| 359 | " hello-interval 60\n\n" |
| 360 | " adj-lsa-build-interval 3\n" |
| 361 | " first-hello-interval 6\n" |
| 362 | " neighbor\n" |
| 363 | " {\n" |
| 364 | " name /ndn/memphis.edu/cs/castor\n" |
| 365 | " face-uri udp4:malformed-uri\n" |
| 366 | " link-cost 20\n" |
| 367 | " }\n" |
| 368 | "}\n\n"; |
| 369 | |
| 370 | BOOST_CHECK_EQUAL(processConfigurationString(MALFORMED_URI), false); |
| 371 | } |
| 372 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 373 | BOOST_AUTO_TEST_CASE(Hyperbolic) |
| 374 | { |
| 375 | processConfigurationString(CONFIG_HYPERBOLIC); |
| 376 | |
| 377 | ConfParameter& conf = nlsr.getConfParameter(); |
| 378 | BOOST_CHECK_EQUAL(conf.getHyperbolicState(), 1); |
| 379 | BOOST_CHECK_EQUAL(conf.getCorR(), 123.456); |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 380 | std::vector<double> angles; |
| 381 | angles.push_back(1.45); |
| 382 | BOOST_CHECK(conf.getCorTheta() == angles); |
| 383 | } |
| 384 | |
| 385 | BOOST_AUTO_TEST_CASE(Hyperbolic2) |
| 386 | { |
| 387 | processConfigurationString(CONFIG_HYPERBOLIC_ANGLES); |
| 388 | |
| 389 | ConfParameter& conf = nlsr.getConfParameter(); |
| 390 | BOOST_CHECK_EQUAL(conf.getHyperbolicState(), 1); |
| 391 | BOOST_CHECK_EQUAL(conf.getCorR(), 123.456); |
| 392 | std::vector<double> angles; |
| 393 | angles.push_back(1.45); |
| 394 | angles.push_back(2.25); |
| 395 | BOOST_CHECK(conf.getCorTheta() == angles); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 396 | } |
| 397 | |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 398 | BOOST_AUTO_TEST_CASE(DefaultValuesGeneral) |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 399 | { |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 400 | std::string config = SECTION_GENERAL; |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 401 | |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 402 | commentOut("lsa-refresh-time", config); |
| 403 | commentOut("lsa-interest-lifetime", config); |
| 404 | commentOut("router-dead-interval", config); |
alvy | d5a13cd | 2015-01-06 16:34:38 -0600 | [diff] [blame] | 405 | commentOut("log-level", config); |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 406 | |
| 407 | BOOST_CHECK_EQUAL(processConfigurationString(config), true); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 408 | |
| 409 | ConfParameter& conf = nlsr.getConfParameter(); |
| 410 | |
alvy | 5a45495 | 2014-12-15 12:49:54 -0600 | [diff] [blame] | 411 | BOOST_CHECK_EQUAL(conf.getLsaRefreshTime(), static_cast<uint32_t>(LSA_REFRESH_TIME_DEFAULT)); |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 412 | BOOST_CHECK_EQUAL(conf.getLsaInterestLifetime(), |
| 413 | static_cast<ndn::time::seconds>(LSA_INTEREST_LIFETIME_DEFAULT)); |
| 414 | BOOST_CHECK_EQUAL(conf.getRouterDeadInterval(), (2*conf.getLsaRefreshTime())); |
alvy | d5a13cd | 2015-01-06 16:34:38 -0600 | [diff] [blame] | 415 | BOOST_CHECK_EQUAL(conf.getLogLevel(), "INFO"); |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | BOOST_AUTO_TEST_CASE(DefaultValuesNeighbors) |
| 419 | { |
| 420 | std::string config = SECTION_NEIGHBORS; |
| 421 | |
| 422 | commentOut("hello-retries", config); |
| 423 | commentOut("hello-timeout", config); |
| 424 | commentOut("hello-interval", config); |
| 425 | commentOut("first-hello-interval", config); |
| 426 | commentOut("adj-lsa-build-interval", config); |
| 427 | |
| 428 | BOOST_CHECK_EQUAL(processConfigurationString(config), true); |
| 429 | |
| 430 | ConfParameter& conf = nlsr.getConfParameter(); |
| 431 | |
| 432 | BOOST_CHECK_EQUAL(conf.getInterestRetryNumber(), static_cast<uint32_t>(HELLO_RETRIES_DEFAULT)); |
alvy | 5a45495 | 2014-12-15 12:49:54 -0600 | [diff] [blame] | 433 | BOOST_CHECK_EQUAL(conf.getInterestResendTime(), static_cast<uint32_t>(HELLO_TIMEOUT_DEFAULT)); |
| 434 | BOOST_CHECK_EQUAL(conf.getInfoInterestInterval(), static_cast<uint32_t>(HELLO_INTERVAL_DEFAULT)); |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 435 | BOOST_CHECK_EQUAL(conf.getFirstHelloInterval(), |
| 436 | static_cast<uint32_t>(FIRST_HELLO_INTERVAL_DEFAULT)); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 437 | BOOST_CHECK_EQUAL(conf.getAdjLsaBuildInterval(), |
| 438 | static_cast<uint32_t>(ADJ_LSA_BUILD_INTERVAL_DEFAULT)); |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 439 | } |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 440 | |
alvy | a2228c6 | 2014-12-09 10:25:11 -0600 | [diff] [blame] | 441 | BOOST_AUTO_TEST_CASE(DefaultValuesFib) |
| 442 | { |
| 443 | std::string config = SECTION_FIB; |
| 444 | |
| 445 | commentOut("max-faces-per-prefix", config); |
| 446 | commentOut("routing-calc-interval", config); |
| 447 | |
| 448 | BOOST_CHECK_EQUAL(processConfigurationString(config), true); |
| 449 | |
| 450 | ConfParameter& conf = nlsr.getConfParameter(); |
| 451 | |
| 452 | BOOST_CHECK_EQUAL(conf.getMaxFacesPerPrefix(), |
| 453 | static_cast<uint32_t>(MAX_FACES_PER_PREFIX_DEFAULT)); |
| 454 | BOOST_CHECK_EQUAL(conf.getRoutingCalcInterval(), |
| 455 | static_cast<uint32_t>(ROUTING_CALC_INTERVAL_DEFAULT)); |
| 456 | } |
| 457 | |
| 458 | BOOST_AUTO_TEST_CASE(DefaultValuesHyperbolic) |
| 459 | { |
| 460 | std::string config = SECTION_HYPERBOLIC_ON; |
| 461 | |
| 462 | commentOut("state", config); |
| 463 | |
| 464 | BOOST_CHECK_EQUAL(processConfigurationString(config), true); |
| 465 | |
| 466 | ConfParameter& conf = nlsr.getConfParameter(); |
| 467 | |
| 468 | BOOST_CHECK_EQUAL(conf.getHyperbolicState(), static_cast<int32_t>(HYPERBOLIC_STATE_DEFAULT)); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | BOOST_AUTO_TEST_CASE(OutOfRangeValue) |
| 472 | { |
| 473 | const std::string SECTION_FIB_OUT_OF_RANGE = |
| 474 | "fib\n" |
| 475 | "{\n" |
| 476 | " max-faces-per-prefix 3\n" |
| 477 | " routing-calc-interval 999\n" // Larger than max value |
| 478 | "}\n\n"; |
| 479 | |
| 480 | // Processing should fail due to out of range value |
| 481 | BOOST_CHECK_EQUAL(processConfigurationString(SECTION_FIB_OUT_OF_RANGE), false); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 482 | } |
| 483 | |
alvy | 5a45495 | 2014-12-15 12:49:54 -0600 | [diff] [blame] | 484 | BOOST_AUTO_TEST_CASE(NegativeValue) |
| 485 | { |
| 486 | const std::string SECTION_GENERAL_NEGATIVE_VALUE = |
| 487 | "general\n" |
| 488 | "{\n" |
| 489 | " network /ndn/\n" |
| 490 | " site /memphis.edu/\n" |
| 491 | " router /cs/pollux/\n" |
| 492 | " lsa-refresh-time -1800\n" |
| 493 | " lsa-interest-lifetime -3\n" |
| 494 | " router-dead-interval -86400\n" |
| 495 | "}\n\n"; |
| 496 | |
| 497 | // Processing should fail due to negative value |
| 498 | BOOST_CHECK_EQUAL(processConfigurationString(SECTION_GENERAL_NEGATIVE_VALUE), false); |
| 499 | } |
| 500 | |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 501 | BOOST_AUTO_TEST_CASE(LoadCertToPublish) |
| 502 | { |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 503 | auto identity = addIdentity("/TestNLSR/identity"); |
| 504 | saveCertificate(identity, "cert-to-publish.cert"); |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 505 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 506 | const std::string SECTION_SECURITY = R"CONF( |
| 507 | security |
| 508 | { |
| 509 | validator |
| 510 | { |
| 511 | trust-anchor |
| 512 | { |
| 513 | type any |
| 514 | } |
| 515 | } |
| 516 | prefix-update-validator |
| 517 | { |
| 518 | trust-anchor |
| 519 | { |
| 520 | type any |
| 521 | } |
| 522 | } |
| 523 | cert-to-publish "cert-to-publish.cert" |
| 524 | } |
| 525 | )CONF"; |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 526 | |
| 527 | BOOST_CHECK(processConfigurationString(SECTION_SECURITY)); |
| 528 | |
| 529 | // Certificate should now be in the CertificateStore |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 530 | security::CertificateStore& certStore = nlsr.getCertificateStore(); |
| 531 | BOOST_CHECK(certStore.find(identity.getDefaultKey().getName()) != nullptr); |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 532 | } |
| 533 | |
Vince Lehman | d33e5bc | 2015-06-22 15:27:50 -0500 | [diff] [blame] | 534 | BOOST_AUTO_TEST_CASE(PrefixUpdateValidatorOptional) // Bug #2814 |
| 535 | { |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 536 | const std::string SECTION_SECURITY = R"CONF( |
| 537 | security |
| 538 | { |
| 539 | validator |
| 540 | { |
| 541 | trust-anchor |
| 542 | { |
| 543 | type any |
| 544 | } |
| 545 | } |
| 546 | } |
| 547 | )CONF"; |
Vince Lehman | d33e5bc | 2015-06-22 15:27:50 -0500 | [diff] [blame] | 548 | |
| 549 | BOOST_CHECK(processConfigurationString(SECTION_SECURITY)); |
| 550 | } |
| 551 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 552 | BOOST_AUTO_TEST_SUITE_END() |
| 553 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 554 | } // namespace test |
| 555 | } // namespace nlsr |