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