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 | /** |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014 University of Memphis, |
| 4 | * Regents of the University of California |
| 5 | * |
| 6 | * This file is part of NLSR (Named-data Link State Routing). |
| 7 | * See AUTHORS.md for complete list of NLSR authors and contributors. |
| 8 | * |
| 9 | * NLSR is free software: you can redistribute it and/or modify it under the terms |
| 10 | * of the GNU General Public License as published by the Free Software Foundation, |
| 11 | * either version 3 of the License, or (at your option) any later version. |
| 12 | * |
| 13 | * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 14 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 15 | * PURPOSE. See the GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along with |
| 18 | * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 19 | * |
| 20 | * \author Ashlesh Gawande <agawande@memphis.edu> |
| 21 | * |
| 22 | **/ |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 23 | |
| 24 | #include "test-common.hpp" |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 25 | #include "dummy-face.hpp" |
Muktadir R Chowdhury | bfa2760 | 2014-10-31 10:57:41 -0500 | [diff] [blame] | 26 | #include "logger.hpp" |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 27 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 28 | #include <fstream> |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 29 | #include "conf-file-processor.hpp" |
| 30 | #include "nlsr.hpp" |
Muktadir R Chowdhury | bfa2760 | 2014-10-31 10:57:41 -0500 | [diff] [blame] | 31 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 32 | #include <boost/test/unit_test.hpp> |
Muktadir R Chowdhury | bfa2760 | 2014-10-31 10:57:41 -0500 | [diff] [blame] | 33 | #include <boost/filesystem.hpp> |
| 34 | #include <boost/algorithm/string.hpp> |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 35 | |
| 36 | namespace nlsr { |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 37 | namespace test { |
| 38 | |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 39 | using ndn::DummyFace; |
| 40 | using ndn::shared_ptr; |
| 41 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 42 | const std::string SECTION_GENERAL = |
| 43 | "general\n" |
| 44 | "{\n" |
| 45 | " network /ndn/\n" |
| 46 | " site /memphis.edu/\n" |
| 47 | " router /cs/pollux/\n" |
| 48 | " lsa-refresh-time 1800\n" |
| 49 | " lsa-interest-lifetime 3\n" |
Alexander Afanasyev | 1cf1e10 | 2014-08-17 19:47:57 -0700 | [diff] [blame] | 50 | " router-dead-interval 86400\n" |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 51 | " log-level INFO\n" |
| 52 | " log-dir /tmp\n" |
| 53 | " seq-dir /tmp\n" |
| 54 | "}\n\n"; |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 55 | |
Muktadir R Chowdhury | bfa2760 | 2014-10-31 10:57:41 -0500 | [diff] [blame] | 56 | const std::string LOG4CXX_PLACEHOLDER = "$LOG4CXX$"; |
| 57 | |
| 58 | const std::string SECTION_GENERAL_WITH_LOG4CXX = |
| 59 | "general\n" |
| 60 | "{\n" |
| 61 | " network /ndn/\n" |
| 62 | " site /memphis.edu/\n" |
| 63 | " router /cs/pollux/\n" |
| 64 | " lsa-refresh-time 1800\n" |
| 65 | " lsa-interest-lifetime 3\n" |
| 66 | " router-dead-interval 86400\n" |
| 67 | " log-level INFO\n" |
| 68 | " log-dir /tmp\n" |
| 69 | " seq-dir /tmp\n" |
| 70 | " log4cxx-conf " + LOG4CXX_PLACEHOLDER + "\n" |
| 71 | "}\n\n"; |
| 72 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 73 | const std::string SECTION_NEIGHBORS = |
| 74 | "neighbors\n" |
| 75 | "{\n" |
| 76 | " hello-retries 3\n" |
| 77 | " hello-timeout 1\n" |
| 78 | " hello-interval 60\n\n" |
| 79 | " adj-lsa-build-interval 3\n" |
| 80 | " first-hello-interval 6\n" |
| 81 | " neighbor\n" |
| 82 | " {\n" |
| 83 | " name /ndn/memphis.edu/cs/castor\n" |
| 84 | " face-uri udp4://localhost\n" |
| 85 | " link-cost 20\n" |
| 86 | " }\n\n" |
| 87 | " neighbor\n" |
| 88 | " {\n" |
| 89 | " name /ndn/memphis.edu/cs/mira\n" |
| 90 | " face-uri udp4://localhost\n" |
| 91 | " link-cost 30\n" |
| 92 | " }\n" |
| 93 | "}\n\n"; |
| 94 | |
| 95 | const std::string SECTION_HYPERBOLIC_ON = |
| 96 | "hyperbolic\n" |
| 97 | "{\n" |
| 98 | " state on\n" |
| 99 | " radius 123.456\n" |
| 100 | " angle 1.45\n" |
| 101 | "}\n\n"; |
| 102 | |
| 103 | const std::string SECTION_HYPERBOLIC_OFF = |
| 104 | "hyperbolic\n" |
| 105 | "{\n" |
| 106 | " state off\n" |
| 107 | " radius 123.456\n" |
| 108 | " angle 1.45\n" |
| 109 | "}\n\n"; |
| 110 | |
| 111 | const std::string SECTION_FIB = |
| 112 | "fib\n" |
| 113 | "{\n" |
| 114 | " max-faces-per-prefix 3\n" |
| 115 | " routing-calc-interval 9\n" |
| 116 | "}\n\n"; |
| 117 | |
| 118 | const std::string SECTION_ADVERTISING = |
| 119 | "advertising\n" |
| 120 | "{\n" |
| 121 | " prefix /ndn/edu/memphis/cs/netlab\n" |
| 122 | " prefix /ndn/edu/memphis/sports/basketball\n" |
| 123 | "}\n"; |
| 124 | |
| 125 | const std::string CONFIG_LINK_STATE = SECTION_GENERAL + SECTION_NEIGHBORS + |
| 126 | SECTION_HYPERBOLIC_OFF + SECTION_FIB + SECTION_ADVERTISING; |
| 127 | |
Muktadir R Chowdhury | bfa2760 | 2014-10-31 10:57:41 -0500 | [diff] [blame] | 128 | const std::string CONFIG_LOG4CXX = SECTION_GENERAL_WITH_LOG4CXX; |
| 129 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 130 | const std::string CONFIG_HYPERBOLIC = SECTION_GENERAL + SECTION_NEIGHBORS + |
| 131 | SECTION_HYPERBOLIC_ON + SECTION_FIB + SECTION_ADVERTISING; |
| 132 | |
| 133 | class ConfFileProcessorFixture : public BaseFixture |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 134 | { |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 135 | public: |
| 136 | ConfFileProcessorFixture() |
| 137 | : face(ndn::makeDummyFace()) |
| 138 | , nlsr(g_ioService, g_scheduler, ndn::ref(*face)) |
| 139 | , CONFIG_FILE("unit-test-nlsr.conf") |
Muktadir R Chowdhury | bfa2760 | 2014-10-31 10:57:41 -0500 | [diff] [blame] | 140 | , m_logConfigFileName(boost::filesystem::unique_path().native()) |
| 141 | , m_logFileName(boost::filesystem::unique_path().native()) |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 142 | { |
| 143 | } |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 144 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 145 | ~ConfFileProcessorFixture() |
| 146 | { |
| 147 | remove("unit-test-nlsr.conf"); |
Muktadir R Chowdhury | bfa2760 | 2014-10-31 10:57:41 -0500 | [diff] [blame] | 148 | remove("/tmp/unit-test-log4cxx.xml"); |
| 149 | |
| 150 | boost::filesystem::remove(boost::filesystem::path(getLogConfigFileName())); |
| 151 | boost::filesystem::remove(boost::filesystem::path(getLogFileName())); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 152 | } |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 153 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 154 | bool processConfigurationString(std::string confString) |
| 155 | { |
| 156 | std::ofstream config; |
| 157 | config.open("unit-test-nlsr.conf"); |
| 158 | config << confString; |
| 159 | config.close(); |
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 | ConfFileProcessor processor(nlsr, CONFIG_FILE); |
| 162 | return processor.processConfFile(); |
| 163 | } |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 164 | |
Muktadir R Chowdhury | bfa2760 | 2014-10-31 10:57:41 -0500 | [diff] [blame] | 165 | void |
| 166 | verifyOutputLog4cxx(const std::string expected[], size_t nExpected) |
| 167 | { |
| 168 | std::ifstream is(getLogFileName().c_str()); |
| 169 | std::string buffer((std::istreambuf_iterator<char>(is)), |
| 170 | (std::istreambuf_iterator<char>())); |
| 171 | |
| 172 | std::vector<std::string> components; |
| 173 | boost::split(components, buffer, boost::is_any_of(" ,\n")); |
| 174 | |
| 175 | // expected + number of timestamps (one per log statement) + trailing newline of last statement |
| 176 | BOOST_REQUIRE_EQUAL(components.size(), nExpected); |
| 177 | |
| 178 | for (size_t i = 0; i < nExpected; ++i) { |
| 179 | if (expected[i] == "") |
| 180 | continue; |
| 181 | |
| 182 | BOOST_CHECK_EQUAL(components[i], expected[i]); |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | const std::string& |
| 187 | getLogConfigFileName() |
| 188 | { |
| 189 | return m_logConfigFileName; |
| 190 | } |
| 191 | |
| 192 | const std::string& |
| 193 | getLogFileName() |
| 194 | { |
| 195 | return m_logFileName; |
| 196 | } |
| 197 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 198 | public: |
| 199 | shared_ptr<ndn::DummyFace> face; |
| 200 | Nlsr nlsr; |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 201 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 202 | private: |
| 203 | const std::string CONFIG_FILE; |
Muktadir R Chowdhury | bfa2760 | 2014-10-31 10:57:41 -0500 | [diff] [blame] | 204 | std::string m_logConfigFileName; |
| 205 | std::string m_logFileName; |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 206 | }; |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 207 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 208 | BOOST_FIXTURE_TEST_SUITE(TestConfFileProcessor, ConfFileProcessorFixture) |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 209 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 210 | BOOST_AUTO_TEST_CASE(LinkState) |
| 211 | { |
| 212 | processConfigurationString(CONFIG_LINK_STATE); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 213 | ConfParameter& conf = nlsr.getConfParameter(); |
| 214 | conf.buildRouterPrefix(); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 215 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 216 | // General |
| 217 | BOOST_CHECK_EQUAL(conf.getNetwork(), "/ndn/"); |
| 218 | BOOST_CHECK_EQUAL(conf.getSiteName(), "/memphis.edu/"); |
| 219 | BOOST_CHECK_EQUAL(conf.getRouterName(), "/cs/pollux/"); |
| 220 | BOOST_CHECK_EQUAL(conf.getRouterPrefix(), "/ndn/memphis.edu/cs/pollux/"); |
| 221 | BOOST_CHECK_EQUAL(conf.getChronosyncPrefix(), "/ndn/NLSR/sync"); |
| 222 | BOOST_CHECK_EQUAL(conf.getLsaPrefix(), "/ndn/NLSR/LSA"); |
| 223 | BOOST_CHECK_EQUAL(conf.getLsaRefreshTime(), 1800); |
| 224 | BOOST_CHECK_EQUAL(conf.getLsaInterestLifetime(), ndn::time::seconds(3)); |
Alexander Afanasyev | 1cf1e10 | 2014-08-17 19:47:57 -0700 | [diff] [blame] | 225 | BOOST_CHECK_EQUAL(conf.getRouterDeadInterval(), 86400); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 226 | BOOST_CHECK_EQUAL(conf.getLogLevel(), "INFO"); |
| 227 | BOOST_CHECK_EQUAL(conf.getLogDir(), "/tmp"); |
| 228 | BOOST_CHECK_EQUAL(conf.getSeqFileDir(), "/tmp"); |
Alexander Afanasyev | 411ee4b | 2014-08-16 23:17:03 -0700 | [diff] [blame] | 229 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 230 | // Neighbors |
| 231 | BOOST_CHECK_EQUAL(conf.getInterestRetryNumber(), 3); |
| 232 | BOOST_CHECK_EQUAL(conf.getInterestResendTime(), 1); |
| 233 | BOOST_CHECK_EQUAL(conf.getInfoInterestInterval(), 60); |
| 234 | |
| 235 | BOOST_CHECK_EQUAL(conf.getAdjLsaBuildInterval(), 3); |
| 236 | BOOST_CHECK_EQUAL(conf.getFirstHelloInterval(), 6); |
| 237 | |
| 238 | BOOST_CHECK(nlsr.getAdjacencyList().isNeighbor("/ndn/memphis.edu/cs/mira")); |
| 239 | BOOST_CHECK(nlsr.getAdjacencyList().isNeighbor("/ndn/memphis.edu/cs/castor")); |
| 240 | BOOST_CHECK(!nlsr.getAdjacencyList().isNeighbor("/ndn/memphis.edu/cs/fail")); |
| 241 | |
| 242 | Adjacent mira = nlsr.getAdjacencyList().getAdjacent("/ndn/memphis.edu/cs/mira"); |
| 243 | BOOST_CHECK_EQUAL(mira.getName(), "/ndn/memphis.edu/cs/mira"); |
| 244 | BOOST_CHECK_EQUAL(mira.getLinkCost(), 30); |
| 245 | |
| 246 | Adjacent castor = nlsr.getAdjacencyList().getAdjacent("/ndn/memphis.edu/cs/castor"); |
| 247 | BOOST_CHECK_EQUAL(castor.getName(), "/ndn/memphis.edu/cs/castor"); |
| 248 | BOOST_CHECK_EQUAL(castor.getLinkCost(), 20); |
| 249 | |
| 250 | // Hyperbolic |
| 251 | BOOST_CHECK_EQUAL(conf.getHyperbolicState(), 0); |
| 252 | |
| 253 | // FIB |
| 254 | BOOST_CHECK_EQUAL(conf.getMaxFacesPerPrefix(), 3); |
| 255 | BOOST_CHECK_EQUAL(conf.getRoutingCalcInterval(), 9); |
| 256 | |
| 257 | // Advertising |
| 258 | BOOST_CHECK_EQUAL(nlsr.getNamePrefixList().getSize(), 2); |
| 259 | } |
| 260 | |
Muktadir R Chowdhury | bfa2760 | 2014-10-31 10:57:41 -0500 | [diff] [blame] | 261 | BOOST_AUTO_TEST_CASE(Log4cxxFileExists) |
| 262 | { |
| 263 | std::string configPath = boost::filesystem::unique_path().native(); |
| 264 | |
| 265 | std::ofstream log4cxxConfFile; |
| 266 | log4cxxConfFile.open(configPath); |
| 267 | log4cxxConfFile.close(); |
| 268 | |
| 269 | std::string config = CONFIG_LOG4CXX; |
| 270 | boost::replace_all(config, LOG4CXX_PLACEHOLDER, configPath); |
| 271 | |
| 272 | BOOST_CHECK_EQUAL(processConfigurationString(config), true); |
| 273 | |
| 274 | ConfParameter& conf = nlsr.getConfParameter(); |
| 275 | BOOST_CHECK_EQUAL(conf.getLog4CxxConfPath(), configPath); |
| 276 | BOOST_CHECK_EQUAL(conf.isLog4CxxConfAvailable(), true); |
| 277 | |
| 278 | boost::filesystem::remove(boost::filesystem::path(configPath)); |
| 279 | } |
| 280 | |
| 281 | BOOST_AUTO_TEST_CASE(Log4cxxFileDoesNotExist) |
| 282 | { |
| 283 | std::string configPath = boost::filesystem::unique_path().native(); |
| 284 | |
| 285 | std::string config = CONFIG_LOG4CXX; |
| 286 | boost::replace_all(config, LOG4CXX_PLACEHOLDER, configPath); |
| 287 | |
| 288 | BOOST_CHECK_EQUAL(processConfigurationString(config), false); |
| 289 | } |
| 290 | |
| 291 | BOOST_AUTO_TEST_CASE(Log4cxxNoValue) |
| 292 | { |
| 293 | std::string config = CONFIG_LOG4CXX; |
| 294 | boost::replace_all(config, LOG4CXX_PLACEHOLDER, ""); |
| 295 | |
| 296 | BOOST_CHECK_EQUAL(processConfigurationString(config), false); |
| 297 | } |
| 298 | |
| 299 | BOOST_AUTO_TEST_CASE(Log4cxxTestCase) |
| 300 | { |
| 301 | { |
| 302 | std::ofstream of(getLogConfigFileName().c_str()); |
| 303 | of << "log4j.rootLogger=TRACE, FILE\n" |
| 304 | << "log4j.appender.FILE=org.apache.log4j.FileAppender\n" |
| 305 | << "log4j.appender.FILE.layout=org.apache.log4j.PatternLayout\n" |
| 306 | << "log4j.appender.FILE.File=" << getLogFileName() << "\n" |
| 307 | << "log4j.appender.FILE.ImmediateFlush=true\n" |
| 308 | << "log4j.appender.FILE.layout.ConversionPattern=%d{HH:mm:ss} %p %c{1} - %m%n\n"; |
| 309 | } |
| 310 | |
| 311 | INIT_LOG4CXX(getLogConfigFileName()); |
| 312 | |
| 313 | INIT_LOGGER("DefaultConfig"); |
| 314 | |
| 315 | _LOG_TRACE("trace-message-JHGFDSR^1"); |
| 316 | _LOG_DEBUG("debug-message-IGg2474fdksd-fo-" << 15 << 16 << 17); |
| 317 | _LOG_INFO("info-message-Jjxjshj13"); |
| 318 | _LOG_WARN("warning-message-XXXhdhd11" << 1 <<"x"); |
| 319 | _LOG_ERROR("error-message-!#$&^%$#@"); |
| 320 | _LOG_FATAL("fatal-message-JJSjaamcng"); |
| 321 | |
| 322 | const std::string EXPECTED[] = |
| 323 | { |
| 324 | "", "TRACE", "DefaultConfig", "-", "trace-message-JHGFDSR^1", |
| 325 | "", "DEBUG", "DefaultConfig", "-", "debug-message-IGg2474fdksd-fo-151617", |
| 326 | "", "INFO", "DefaultConfig", "-", "info-message-Jjxjshj13", |
| 327 | "", "WARN", "DefaultConfig", "-", "warning-message-XXXhdhd111x", |
| 328 | "", "ERROR", "DefaultConfig", "-", "error-message-!#$&^%$#@", |
| 329 | "", "FATAL", "DefaultConfig", "-", "fatal-message-JJSjaamcng", |
| 330 | "", |
| 331 | }; |
| 332 | |
| 333 | verifyOutputLog4cxx(EXPECTED, sizeof(EXPECTED) / sizeof(std::string)); |
| 334 | } |
| 335 | |
alvy | 2fe1287 | 2014-11-25 10:32:23 -0600 | [diff] [blame^] | 336 | BOOST_AUTO_TEST_CASE(MalformedUri) |
| 337 | { |
| 338 | const std::string MALFORMED_URI = |
| 339 | "neighbors\n" |
| 340 | "{\n" |
| 341 | " hello-retries 3\n" |
| 342 | " hello-timeout 1\n" |
| 343 | " hello-interval 60\n\n" |
| 344 | " adj-lsa-build-interval 3\n" |
| 345 | " first-hello-interval 6\n" |
| 346 | " neighbor\n" |
| 347 | " {\n" |
| 348 | " name /ndn/memphis.edu/cs/castor\n" |
| 349 | " face-uri udp4:malformed-uri\n" |
| 350 | " link-cost 20\n" |
| 351 | " }\n" |
| 352 | "}\n\n"; |
| 353 | |
| 354 | BOOST_CHECK_EQUAL(processConfigurationString(MALFORMED_URI), false); |
| 355 | } |
| 356 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 357 | BOOST_AUTO_TEST_CASE(Hyperbolic) |
| 358 | { |
| 359 | processConfigurationString(CONFIG_HYPERBOLIC); |
| 360 | |
| 361 | ConfParameter& conf = nlsr.getConfParameter(); |
| 362 | BOOST_CHECK_EQUAL(conf.getHyperbolicState(), 1); |
| 363 | BOOST_CHECK_EQUAL(conf.getCorR(), 123.456); |
| 364 | BOOST_CHECK_EQUAL(conf.getCorTheta(), 1.45); |
| 365 | } |
| 366 | |
| 367 | BOOST_AUTO_TEST_CASE(DefaultValues) |
| 368 | { |
| 369 | // Missing adj-lsa-build-interval |
| 370 | const std::string SECTION_NEIGHBORS_DEFAULT_VALUES = |
| 371 | "neighbors\n" |
| 372 | "{\n" |
| 373 | " hello-retries 3\n" |
| 374 | " hello-timeout 1\n" |
| 375 | " hello-interval 60\n\n" |
| 376 | " first-hello-interval 6\n" |
| 377 | " neighbor\n" |
| 378 | " {\n" |
| 379 | " name /ndn/memphis.edu/cs/castor\n" |
| 380 | " face-uri udp4://localhost\n" |
| 381 | " link-cost 20\n" |
| 382 | " }\n\n" |
| 383 | " neighbor\n" |
| 384 | " {\n" |
| 385 | " name /ndn/memphis.edu/cs/mira\n" |
| 386 | " face-uri udp4://localhost\n" |
| 387 | " link-cost 30\n" |
| 388 | " }\n" |
| 389 | "}\n\n"; |
| 390 | |
| 391 | processConfigurationString(SECTION_NEIGHBORS_DEFAULT_VALUES); |
| 392 | |
| 393 | ConfParameter& conf = nlsr.getConfParameter(); |
| 394 | |
| 395 | BOOST_CHECK_EQUAL(conf.getAdjLsaBuildInterval(), |
| 396 | static_cast<uint32_t>(ADJ_LSA_BUILD_INTERVAL_DEFAULT)); |
| 397 | |
| 398 | BOOST_CHECK_EQUAL(conf.getFirstHelloInterval(), 6); |
| 399 | } |
| 400 | |
| 401 | BOOST_AUTO_TEST_CASE(OutOfRangeValue) |
| 402 | { |
| 403 | const std::string SECTION_FIB_OUT_OF_RANGE = |
| 404 | "fib\n" |
| 405 | "{\n" |
| 406 | " max-faces-per-prefix 3\n" |
| 407 | " routing-calc-interval 999\n" // Larger than max value |
| 408 | "}\n\n"; |
| 409 | |
| 410 | // Processing should fail due to out of range value |
| 411 | BOOST_CHECK_EQUAL(processConfigurationString(SECTION_FIB_OUT_OF_RANGE), false); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | BOOST_AUTO_TEST_SUITE_END() |
| 415 | |
| 416 | } //namespace test |
alvy | 2fe1287 | 2014-11-25 10:32:23 -0600 | [diff] [blame^] | 417 | } //namespace nlsr |