blob: 0400b050758be5fd8363f83e84ac5e20ceb6b1aa [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -05002/**
Nick Gordonfeae5572017-01-13 12:06:26 -06003 * Copyright (c) 2014-2017, The University of Memphis,
Vince Lehmanc2e51f62015-01-20 15:03:11 -06004 * Regents of the University of California,
5 * Arizona Board of Regents.
akmhoque3d06e792014-05-27 16:23:20 -05006 *
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/>.
akmhoque3d06e792014-05-27 16:23:20 -050020 **/
Vince Lehman7c603292014-09-11 17:48:16 -050021
Nick Gordonff9a6272017-10-12 13:38:29 -050022#include "conf-file-processor.hpp"
Vince Lehman7c603292014-09-11 17:48:16 -050023#include "test-common.hpp"
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -050024#include "logger.hpp"
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050025#include "nlsr.hpp"
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -050026
Nick Gordonff9a6272017-10-12 13:38:29 -050027#include <fstream>
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050028
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050029#include <boost/test/unit_test.hpp>
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -050030#include <boost/filesystem.hpp>
31#include <boost/algorithm/string.hpp>
Muktadir R Chowdhuryc69da0a2015-12-18 13:24:38 -060032#include <ndn-cxx/util/dummy-client-face.hpp>
33
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050034namespace nlsr {
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050035namespace test {
36
dmcoomes9f936662017-03-02 10:33:09 -060037using std::shared_ptr;
Vince Lehman904c2412014-09-23 19:36:11 -050038
Vince Lehman7b616582014-10-17 16:25:39 -050039const 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 Afanasyev1cf1e102014-08-17 19:47:57 -070047 " router-dead-interval 86400\n"
Vince Lehman7b616582014-10-17 16:25:39 -050048 " log-level INFO\n"
49 " log-dir /tmp\n"
50 " seq-dir /tmp\n"
51 "}\n\n";
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050052
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -050053const std::string LOG4CXX_PLACEHOLDER = "$LOG4CXX$";
54
55const 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 Lehman7b616582014-10-17 16:25:39 -050070const 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
92const 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 Chowdhuryb00dc2a2016-11-05 10:48:58 -0600100const 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 Lehman7b616582014-10-17 16:25:39 -0500108const 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
116const 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
123const 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
130const std::string CONFIG_LINK_STATE = SECTION_GENERAL + SECTION_NEIGHBORS +
131 SECTION_HYPERBOLIC_OFF + SECTION_FIB + SECTION_ADVERTISING;
132
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -0500133const std::string CONFIG_LOG4CXX = SECTION_GENERAL_WITH_LOG4CXX;
134
Vince Lehman7b616582014-10-17 16:25:39 -0500135const std::string CONFIG_HYPERBOLIC = SECTION_GENERAL + SECTION_NEIGHBORS +
136 SECTION_HYPERBOLIC_ON + SECTION_FIB + SECTION_ADVERTISING;
137
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600138const std::string CONFIG_HYPERBOLIC_ANGLES = SECTION_GENERAL + SECTION_NEIGHBORS +
139 SECTION_HYPERBOLIC_ANGLES_ON + SECTION_FIB +
140 SECTION_ADVERTISING;
141
Vince Lehman7b616582014-10-17 16:25:39 -0500142class ConfFileProcessorFixture : public BaseFixture
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500143{
Vince Lehman7b616582014-10-17 16:25:39 -0500144public:
145 ConfFileProcessorFixture()
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500146 : face(m_ioService, m_keyChain)
147 , nlsr(m_ioService, m_scheduler, face, m_keyChain)
Vince Lehman7b616582014-10-17 16:25:39 -0500148 , CONFIG_FILE("unit-test-nlsr.conf")
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500149 , m_logConfigFileName(boost::filesystem::unique_path().string())
150 , m_logFileName(boost::filesystem::unique_path().string())
Vince Lehman7b616582014-10-17 16:25:39 -0500151 {
152 }
Vince Lehman904c2412014-09-23 19:36:11 -0500153
Vince Lehman7b616582014-10-17 16:25:39 -0500154 ~ConfFileProcessorFixture()
155 {
156 remove("unit-test-nlsr.conf");
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -0500157 remove("/tmp/unit-test-log4cxx.xml");
158
159 boost::filesystem::remove(boost::filesystem::path(getLogConfigFileName()));
160 boost::filesystem::remove(boost::filesystem::path(getLogFileName()));
Vince Lehman7b616582014-10-17 16:25:39 -0500161 }
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500162
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500163 bool
164 processConfigurationString(std::string confString)
Vince Lehman7b616582014-10-17 16:25:39 -0500165 {
166 std::ofstream config;
167 config.open("unit-test-nlsr.conf");
168 config << confString;
169 config.close();
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500170
Vince Lehman7b616582014-10-17 16:25:39 -0500171 ConfFileProcessor processor(nlsr, CONFIG_FILE);
172 return processor.processConfFile();
173 }
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500174
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -0500175 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
alvya2228c62014-12-09 10:25:11 -0600208 void
209 commentOut(const std::string& key, std::string& config)
210 {
211 boost::replace_all(config, key, ";" + key);
212 }
213
Vince Lehman7b616582014-10-17 16:25:39 -0500214public:
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500215 ndn::util::DummyClientFace face;
Vince Lehman7b616582014-10-17 16:25:39 -0500216 Nlsr nlsr;
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500217
Vince Lehman7b616582014-10-17 16:25:39 -0500218private:
219 const std::string CONFIG_FILE;
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -0500220 std::string m_logConfigFileName;
221 std::string m_logFileName;
Vince Lehman7b616582014-10-17 16:25:39 -0500222};
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500223
Vince Lehman7b616582014-10-17 16:25:39 -0500224BOOST_FIXTURE_TEST_SUITE(TestConfFileProcessor, ConfFileProcessorFixture)
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500225
Vince Lehman7b616582014-10-17 16:25:39 -0500226BOOST_AUTO_TEST_CASE(LinkState)
227{
228 processConfigurationString(CONFIG_LINK_STATE);
Vince Lehman7b616582014-10-17 16:25:39 -0500229 ConfParameter& conf = nlsr.getConfParameter();
230 conf.buildRouterPrefix();
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500231
Vince Lehman7b616582014-10-17 16:25:39 -0500232 // 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 Gawande8bfd1242017-06-21 14:55:27 -0500237 BOOST_CHECK_EQUAL(conf.getChronosyncPrefix(), "/localhop/ndn/NLSR/sync");
Ashlesh Gawande6077ea92017-01-19 11:48:29 -0600238 BOOST_CHECK_EQUAL(conf.getLsaPrefix(), "/localhop/ndn/NLSR/LSA");
Vince Lehman7b616582014-10-17 16:25:39 -0500239 BOOST_CHECK_EQUAL(conf.getLsaRefreshTime(), 1800);
240 BOOST_CHECK_EQUAL(conf.getLsaInterestLifetime(), ndn::time::seconds(3));
Alexander Afanasyev1cf1e102014-08-17 19:47:57 -0700241 BOOST_CHECK_EQUAL(conf.getRouterDeadInterval(), 86400);
Vince Lehman7b616582014-10-17 16:25:39 -0500242 BOOST_CHECK_EQUAL(conf.getLogLevel(), "INFO");
243 BOOST_CHECK_EQUAL(conf.getLogDir(), "/tmp");
244 BOOST_CHECK_EQUAL(conf.getSeqFileDir(), "/tmp");
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700245
Vince Lehman7b616582014-10-17 16:25:39 -0500246 // 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 Gordonff9a6272017-10-12 13:38:29 -0500274 BOOST_CHECK_EQUAL(nlsr.getNamePrefixList().size(), 2);
Vince Lehman7b616582014-10-17 16:25:39 -0500275}
276
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -0500277BOOST_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
297BOOST_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
307BOOST_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
315BOOST_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
dmcoomes5bcb39e2017-10-31 15:07:55 -0500331 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 Chowdhurybfa27602014-10-31 10:57:41 -0500337
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
alvy2fe12872014-11-25 10:32:23 -0600352BOOST_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 Lehman7b616582014-10-17 16:25:39 -0500373BOOST_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 Chowdhuryb00dc2a2016-11-05 10:48:58 -0600380 std::vector<double> angles;
381 angles.push_back(1.45);
382 BOOST_CHECK(conf.getCorTheta() == angles);
383}
384
385BOOST_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 Lehman7b616582014-10-17 16:25:39 -0500396}
397
alvya2228c62014-12-09 10:25:11 -0600398BOOST_AUTO_TEST_CASE(DefaultValuesGeneral)
Vince Lehman7b616582014-10-17 16:25:39 -0500399{
alvya2228c62014-12-09 10:25:11 -0600400 std::string config = SECTION_GENERAL;
Vince Lehman7b616582014-10-17 16:25:39 -0500401
alvya2228c62014-12-09 10:25:11 -0600402 commentOut("lsa-refresh-time", config);
403 commentOut("lsa-interest-lifetime", config);
404 commentOut("router-dead-interval", config);
alvyd5a13cd2015-01-06 16:34:38 -0600405 commentOut("log-level", config);
alvya2228c62014-12-09 10:25:11 -0600406
407 BOOST_CHECK_EQUAL(processConfigurationString(config), true);
Vince Lehman7b616582014-10-17 16:25:39 -0500408
409 ConfParameter& conf = nlsr.getConfParameter();
410
alvy5a454952014-12-15 12:49:54 -0600411 BOOST_CHECK_EQUAL(conf.getLsaRefreshTime(), static_cast<uint32_t>(LSA_REFRESH_TIME_DEFAULT));
alvya2228c62014-12-09 10:25:11 -0600412 BOOST_CHECK_EQUAL(conf.getLsaInterestLifetime(),
413 static_cast<ndn::time::seconds>(LSA_INTEREST_LIFETIME_DEFAULT));
414 BOOST_CHECK_EQUAL(conf.getRouterDeadInterval(), (2*conf.getLsaRefreshTime()));
alvyd5a13cd2015-01-06 16:34:38 -0600415 BOOST_CHECK_EQUAL(conf.getLogLevel(), "INFO");
alvya2228c62014-12-09 10:25:11 -0600416}
417
418BOOST_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));
alvy5a454952014-12-15 12:49:54 -0600433 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));
alvya2228c62014-12-09 10:25:11 -0600435 BOOST_CHECK_EQUAL(conf.getFirstHelloInterval(),
436 static_cast<uint32_t>(FIRST_HELLO_INTERVAL_DEFAULT));
Vince Lehman7b616582014-10-17 16:25:39 -0500437 BOOST_CHECK_EQUAL(conf.getAdjLsaBuildInterval(),
438 static_cast<uint32_t>(ADJ_LSA_BUILD_INTERVAL_DEFAULT));
alvya2228c62014-12-09 10:25:11 -0600439}
Vince Lehman7b616582014-10-17 16:25:39 -0500440
alvya2228c62014-12-09 10:25:11 -0600441BOOST_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
458BOOST_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 Lehman7b616582014-10-17 16:25:39 -0500469}
470
471BOOST_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 Gawandeeb582eb2014-05-01 14:25:20 -0500482}
483
alvy5a454952014-12-15 12:49:54 -0600484BOOST_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 Lehmanc2acdcb2015-04-29 11:14:35 -0500501BOOST_AUTO_TEST_CASE(LoadCertToPublish)
502{
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500503 auto identity = addIdentity("/TestNLSR/identity");
504 saveCertificate(identity, "cert-to-publish.cert");
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500505
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500506 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 Lehmanc2acdcb2015-04-29 11:14:35 -0500526
527 BOOST_CHECK(processConfigurationString(SECTION_SECURITY));
528
529 // Certificate should now be in the CertificateStore
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500530 security::CertificateStore& certStore = nlsr.getCertificateStore();
531 BOOST_CHECK(certStore.find(identity.getDefaultKey().getName()) != nullptr);
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500532}
533
Vince Lehmand33e5bc2015-06-22 15:27:50 -0500534BOOST_AUTO_TEST_CASE(PrefixUpdateValidatorOptional) // Bug #2814
535{
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500536 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 Lehmand33e5bc2015-06-22 15:27:50 -0500548
549 BOOST_CHECK(processConfigurationString(SECTION_SECURITY));
550}
551
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500552BOOST_AUTO_TEST_SUITE_END()
553
Nick Gordonfad8e252016-08-11 14:21:38 -0500554} // namespace test
555} // namespace nlsr