blob: 479bba1e4954c81241607c58b0bb059cef00618e [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>
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050028#include <boost/test/unit_test.hpp>
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -050029#include <boost/filesystem.hpp>
30#include <boost/algorithm/string.hpp>
Muktadir R Chowdhuryc69da0a2015-12-18 13:24:38 -060031#include <ndn-cxx/util/dummy-client-face.hpp>
32
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050033namespace nlsr {
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050034namespace test {
35
dmcoomes9f936662017-03-02 10:33:09 -060036using std::shared_ptr;
Vince Lehman904c2412014-09-23 19:36:11 -050037
Vince Lehman7b616582014-10-17 16:25:39 -050038const std::string SECTION_GENERAL =
39 "general\n"
40 "{\n"
41 " network /ndn/\n"
42 " site /memphis.edu/\n"
43 " router /cs/pollux/\n"
44 " lsa-refresh-time 1800\n"
45 " lsa-interest-lifetime 3\n"
Alexander Afanasyev1cf1e102014-08-17 19:47:57 -070046 " router-dead-interval 86400\n"
Vince Lehman7b616582014-10-17 16:25:39 -050047 " log-level INFO\n"
48 " log-dir /tmp\n"
49 " seq-dir /tmp\n"
50 "}\n\n";
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050051
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -050052const std::string LOG4CXX_PLACEHOLDER = "$LOG4CXX$";
53
54const std::string SECTION_GENERAL_WITH_LOG4CXX =
55 "general\n"
56 "{\n"
57 " network /ndn/\n"
58 " site /memphis.edu/\n"
59 " router /cs/pollux/\n"
60 " lsa-refresh-time 1800\n"
61 " lsa-interest-lifetime 3\n"
62 " router-dead-interval 86400\n"
63 " log-level INFO\n"
64 " log-dir /tmp\n"
65 " seq-dir /tmp\n"
66 " log4cxx-conf " + LOG4CXX_PLACEHOLDER + "\n"
67 "}\n\n";
68
Vince Lehman7b616582014-10-17 16:25:39 -050069const std::string SECTION_NEIGHBORS =
70 "neighbors\n"
71 "{\n"
72 " hello-retries 3\n"
73 " hello-timeout 1\n"
74 " hello-interval 60\n\n"
75 " adj-lsa-build-interval 3\n"
76 " first-hello-interval 6\n"
77 " neighbor\n"
78 " {\n"
79 " name /ndn/memphis.edu/cs/castor\n"
80 " face-uri udp4://localhost\n"
81 " link-cost 20\n"
82 " }\n\n"
83 " neighbor\n"
84 " {\n"
85 " name /ndn/memphis.edu/cs/mira\n"
86 " face-uri udp4://localhost\n"
87 " link-cost 30\n"
88 " }\n"
89 "}\n\n";
90
91const std::string SECTION_HYPERBOLIC_ON =
92 "hyperbolic\n"
93 "{\n"
94 " state on\n"
95 " radius 123.456\n"
96 " angle 1.45\n"
97 "}\n\n";
98
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -060099const std::string SECTION_HYPERBOLIC_ANGLES_ON =
100 "hyperbolic\n"
101 "{\n"
102 " state on\n"
103 " radius 123.456\n"
104 " angle 1.45,2.25\n"
105 "}\n\n";
106
Vince Lehman7b616582014-10-17 16:25:39 -0500107const std::string SECTION_HYPERBOLIC_OFF =
108 "hyperbolic\n"
109 "{\n"
110 " state off\n"
111 " radius 123.456\n"
112 " angle 1.45\n"
113 "}\n\n";
114
115const std::string SECTION_FIB =
116 "fib\n"
117 "{\n"
118 " max-faces-per-prefix 3\n"
119 " routing-calc-interval 9\n"
120 "}\n\n";
121
122const std::string SECTION_ADVERTISING =
123 "advertising\n"
124 "{\n"
125 " prefix /ndn/edu/memphis/cs/netlab\n"
126 " prefix /ndn/edu/memphis/sports/basketball\n"
127 "}\n";
128
129const std::string CONFIG_LINK_STATE = SECTION_GENERAL + SECTION_NEIGHBORS +
130 SECTION_HYPERBOLIC_OFF + SECTION_FIB + SECTION_ADVERTISING;
131
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -0500132const std::string CONFIG_LOG4CXX = SECTION_GENERAL_WITH_LOG4CXX;
133
Vince Lehman7b616582014-10-17 16:25:39 -0500134const std::string CONFIG_HYPERBOLIC = SECTION_GENERAL + SECTION_NEIGHBORS +
135 SECTION_HYPERBOLIC_ON + SECTION_FIB + SECTION_ADVERTISING;
136
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600137const std::string CONFIG_HYPERBOLIC_ANGLES = SECTION_GENERAL + SECTION_NEIGHBORS +
138 SECTION_HYPERBOLIC_ANGLES_ON + SECTION_FIB +
139 SECTION_ADVERTISING;
140
Vince Lehman7b616582014-10-17 16:25:39 -0500141class ConfFileProcessorFixture : public BaseFixture
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500142{
Vince Lehman7b616582014-10-17 16:25:39 -0500143public:
144 ConfFileProcessorFixture()
dmcoomes9f936662017-03-02 10:33:09 -0600145 : face(std::make_shared<ndn::util::DummyClientFace>())
146 , nlsr(g_ioService, g_scheduler, std::ref(*face), g_keyChain)
Vince Lehman7b616582014-10-17 16:25:39 -0500147 , CONFIG_FILE("unit-test-nlsr.conf")
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -0500148 , m_logConfigFileName(boost::filesystem::unique_path().native())
149 , m_logFileName(boost::filesystem::unique_path().native())
Vince Lehman7b616582014-10-17 16:25:39 -0500150 {
151 }
Vince Lehman904c2412014-09-23 19:36:11 -0500152
Vince Lehman7b616582014-10-17 16:25:39 -0500153 ~ConfFileProcessorFixture()
154 {
155 remove("unit-test-nlsr.conf");
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -0500156 remove("/tmp/unit-test-log4cxx.xml");
157
158 boost::filesystem::remove(boost::filesystem::path(getLogConfigFileName()));
159 boost::filesystem::remove(boost::filesystem::path(getLogFileName()));
Vince Lehman7b616582014-10-17 16:25:39 -0500160 }
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500161
Vince Lehman7b616582014-10-17 16:25:39 -0500162 bool processConfigurationString(std::string confString)
163 {
164 std::ofstream config;
165 config.open("unit-test-nlsr.conf");
166 config << confString;
167 config.close();
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500168
Vince Lehman7b616582014-10-17 16:25:39 -0500169 ConfFileProcessor processor(nlsr, CONFIG_FILE);
170 return processor.processConfFile();
171 }
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500172
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -0500173 void
174 verifyOutputLog4cxx(const std::string expected[], size_t nExpected)
175 {
176 std::ifstream is(getLogFileName().c_str());
177 std::string buffer((std::istreambuf_iterator<char>(is)),
178 (std::istreambuf_iterator<char>()));
179
180 std::vector<std::string> components;
181 boost::split(components, buffer, boost::is_any_of(" ,\n"));
182
183 // expected + number of timestamps (one per log statement) + trailing newline of last statement
184 BOOST_REQUIRE_EQUAL(components.size(), nExpected);
185
186 for (size_t i = 0; i < nExpected; ++i) {
187 if (expected[i] == "")
188 continue;
189
190 BOOST_CHECK_EQUAL(components[i], expected[i]);
191 }
192 }
193
194 const std::string&
195 getLogConfigFileName()
196 {
197 return m_logConfigFileName;
198 }
199
200 const std::string&
201 getLogFileName()
202 {
203 return m_logFileName;
204 }
205
alvya2228c62014-12-09 10:25:11 -0600206 void
207 commentOut(const std::string& key, std::string& config)
208 {
209 boost::replace_all(config, key, ";" + key);
210 }
211
Vince Lehman7b616582014-10-17 16:25:39 -0500212public:
dmcoomes9f936662017-03-02 10:33:09 -0600213 std::shared_ptr<ndn::util::DummyClientFace> face;
Vince Lehman7b616582014-10-17 16:25:39 -0500214 Nlsr nlsr;
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500215
Vince Lehman7b616582014-10-17 16:25:39 -0500216private:
217 const std::string CONFIG_FILE;
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -0500218 std::string m_logConfigFileName;
219 std::string m_logFileName;
Vince Lehman7b616582014-10-17 16:25:39 -0500220};
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500221
Vince Lehman7b616582014-10-17 16:25:39 -0500222BOOST_FIXTURE_TEST_SUITE(TestConfFileProcessor, ConfFileProcessorFixture)
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500223
Vince Lehman7b616582014-10-17 16:25:39 -0500224BOOST_AUTO_TEST_CASE(LinkState)
225{
226 processConfigurationString(CONFIG_LINK_STATE);
Vince Lehman7b616582014-10-17 16:25:39 -0500227 ConfParameter& conf = nlsr.getConfParameter();
228 conf.buildRouterPrefix();
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500229
Vince Lehman7b616582014-10-17 16:25:39 -0500230 // General
231 BOOST_CHECK_EQUAL(conf.getNetwork(), "/ndn/");
232 BOOST_CHECK_EQUAL(conf.getSiteName(), "/memphis.edu/");
233 BOOST_CHECK_EQUAL(conf.getRouterName(), "/cs/pollux/");
234 BOOST_CHECK_EQUAL(conf.getRouterPrefix(), "/ndn/memphis.edu/cs/pollux/");
Ashlesh Gawande8bfd1242017-06-21 14:55:27 -0500235 BOOST_CHECK_EQUAL(conf.getChronosyncPrefix(), "/localhop/ndn/NLSR/sync");
Ashlesh Gawande6077ea92017-01-19 11:48:29 -0600236 BOOST_CHECK_EQUAL(conf.getLsaPrefix(), "/localhop/ndn/NLSR/LSA");
Vince Lehman7b616582014-10-17 16:25:39 -0500237 BOOST_CHECK_EQUAL(conf.getLsaRefreshTime(), 1800);
238 BOOST_CHECK_EQUAL(conf.getLsaInterestLifetime(), ndn::time::seconds(3));
Alexander Afanasyev1cf1e102014-08-17 19:47:57 -0700239 BOOST_CHECK_EQUAL(conf.getRouterDeadInterval(), 86400);
Vince Lehman7b616582014-10-17 16:25:39 -0500240 BOOST_CHECK_EQUAL(conf.getLogLevel(), "INFO");
241 BOOST_CHECK_EQUAL(conf.getLogDir(), "/tmp");
242 BOOST_CHECK_EQUAL(conf.getSeqFileDir(), "/tmp");
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700243
Vince Lehman7b616582014-10-17 16:25:39 -0500244 // Neighbors
245 BOOST_CHECK_EQUAL(conf.getInterestRetryNumber(), 3);
246 BOOST_CHECK_EQUAL(conf.getInterestResendTime(), 1);
247 BOOST_CHECK_EQUAL(conf.getInfoInterestInterval(), 60);
248
249 BOOST_CHECK_EQUAL(conf.getAdjLsaBuildInterval(), 3);
250 BOOST_CHECK_EQUAL(conf.getFirstHelloInterval(), 6);
251
252 BOOST_CHECK(nlsr.getAdjacencyList().isNeighbor("/ndn/memphis.edu/cs/mira"));
253 BOOST_CHECK(nlsr.getAdjacencyList().isNeighbor("/ndn/memphis.edu/cs/castor"));
254 BOOST_CHECK(!nlsr.getAdjacencyList().isNeighbor("/ndn/memphis.edu/cs/fail"));
255
256 Adjacent mira = nlsr.getAdjacencyList().getAdjacent("/ndn/memphis.edu/cs/mira");
257 BOOST_CHECK_EQUAL(mira.getName(), "/ndn/memphis.edu/cs/mira");
258 BOOST_CHECK_EQUAL(mira.getLinkCost(), 30);
259
260 Adjacent castor = nlsr.getAdjacencyList().getAdjacent("/ndn/memphis.edu/cs/castor");
261 BOOST_CHECK_EQUAL(castor.getName(), "/ndn/memphis.edu/cs/castor");
262 BOOST_CHECK_EQUAL(castor.getLinkCost(), 20);
263
264 // Hyperbolic
265 BOOST_CHECK_EQUAL(conf.getHyperbolicState(), 0);
266
267 // FIB
268 BOOST_CHECK_EQUAL(conf.getMaxFacesPerPrefix(), 3);
269 BOOST_CHECK_EQUAL(conf.getRoutingCalcInterval(), 9);
270
271 // Advertising
Nick Gordonff9a6272017-10-12 13:38:29 -0500272 BOOST_CHECK_EQUAL(nlsr.getNamePrefixList().size(), 2);
Vince Lehman7b616582014-10-17 16:25:39 -0500273}
274
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -0500275BOOST_AUTO_TEST_CASE(Log4cxxFileExists)
276{
277 std::string configPath = boost::filesystem::unique_path().native();
278
279 std::ofstream log4cxxConfFile;
280 log4cxxConfFile.open(configPath);
281 log4cxxConfFile.close();
282
283 std::string config = CONFIG_LOG4CXX;
284 boost::replace_all(config, LOG4CXX_PLACEHOLDER, configPath);
285
286 BOOST_CHECK_EQUAL(processConfigurationString(config), true);
287
288 ConfParameter& conf = nlsr.getConfParameter();
289 BOOST_CHECK_EQUAL(conf.getLog4CxxConfPath(), configPath);
290 BOOST_CHECK_EQUAL(conf.isLog4CxxConfAvailable(), true);
291
292 boost::filesystem::remove(boost::filesystem::path(configPath));
293}
294
295BOOST_AUTO_TEST_CASE(Log4cxxFileDoesNotExist)
296{
297 std::string configPath = boost::filesystem::unique_path().native();
298
299 std::string config = CONFIG_LOG4CXX;
300 boost::replace_all(config, LOG4CXX_PLACEHOLDER, configPath);
301
302 BOOST_CHECK_EQUAL(processConfigurationString(config), false);
303}
304
305BOOST_AUTO_TEST_CASE(Log4cxxNoValue)
306{
307 std::string config = CONFIG_LOG4CXX;
308 boost::replace_all(config, LOG4CXX_PLACEHOLDER, "");
309
310 BOOST_CHECK_EQUAL(processConfigurationString(config), false);
311}
312
313BOOST_AUTO_TEST_CASE(Log4cxxTestCase)
314{
315 {
316 std::ofstream of(getLogConfigFileName().c_str());
317 of << "log4j.rootLogger=TRACE, FILE\n"
318 << "log4j.appender.FILE=org.apache.log4j.FileAppender\n"
319 << "log4j.appender.FILE.layout=org.apache.log4j.PatternLayout\n"
320 << "log4j.appender.FILE.File=" << getLogFileName() << "\n"
321 << "log4j.appender.FILE.ImmediateFlush=true\n"
322 << "log4j.appender.FILE.layout.ConversionPattern=%d{HH:mm:ss} %p %c{1} - %m%n\n";
323 }
324
325 INIT_LOG4CXX(getLogConfigFileName());
326
327 INIT_LOGGER("DefaultConfig");
328
dmcoomes5bcb39e2017-10-31 15:07:55 -0500329 NLSR_LOG_TRACE("trace-message-JHGFDSR^1");
330 NLSR_LOG_DEBUG("debug-message-IGg2474fdksd-fo-" << 15 << 16 << 17);
331 NLSR_LOG_INFO("info-message-Jjxjshj13");
332 NLSR_LOG_WARN("warning-message-XXXhdhd11" << 1 <<"x");
333 NLSR_LOG_ERROR("error-message-!#$&^%$#@");
334 NLSR_LOG_FATAL("fatal-message-JJSjaamcng");
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -0500335
336 const std::string EXPECTED[] =
337 {
338 "", "TRACE", "DefaultConfig", "-", "trace-message-JHGFDSR^1",
339 "", "DEBUG", "DefaultConfig", "-", "debug-message-IGg2474fdksd-fo-151617",
340 "", "INFO", "DefaultConfig", "-", "info-message-Jjxjshj13",
341 "", "WARN", "DefaultConfig", "-", "warning-message-XXXhdhd111x",
342 "", "ERROR", "DefaultConfig", "-", "error-message-!#$&^%$#@",
343 "", "FATAL", "DefaultConfig", "-", "fatal-message-JJSjaamcng",
344 "",
345 };
346
347 verifyOutputLog4cxx(EXPECTED, sizeof(EXPECTED) / sizeof(std::string));
348}
349
alvy2fe12872014-11-25 10:32:23 -0600350BOOST_AUTO_TEST_CASE(MalformedUri)
351{
352 const std::string MALFORMED_URI =
353 "neighbors\n"
354 "{\n"
355 " hello-retries 3\n"
356 " hello-timeout 1\n"
357 " hello-interval 60\n\n"
358 " adj-lsa-build-interval 3\n"
359 " first-hello-interval 6\n"
360 " neighbor\n"
361 " {\n"
362 " name /ndn/memphis.edu/cs/castor\n"
363 " face-uri udp4:malformed-uri\n"
364 " link-cost 20\n"
365 " }\n"
366 "}\n\n";
367
368 BOOST_CHECK_EQUAL(processConfigurationString(MALFORMED_URI), false);
369}
370
Vince Lehman7b616582014-10-17 16:25:39 -0500371BOOST_AUTO_TEST_CASE(Hyperbolic)
372{
373 processConfigurationString(CONFIG_HYPERBOLIC);
374
375 ConfParameter& conf = nlsr.getConfParameter();
376 BOOST_CHECK_EQUAL(conf.getHyperbolicState(), 1);
377 BOOST_CHECK_EQUAL(conf.getCorR(), 123.456);
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600378 std::vector<double> angles;
379 angles.push_back(1.45);
380 BOOST_CHECK(conf.getCorTheta() == angles);
381}
382
383BOOST_AUTO_TEST_CASE(Hyperbolic2)
384{
385 processConfigurationString(CONFIG_HYPERBOLIC_ANGLES);
386
387 ConfParameter& conf = nlsr.getConfParameter();
388 BOOST_CHECK_EQUAL(conf.getHyperbolicState(), 1);
389 BOOST_CHECK_EQUAL(conf.getCorR(), 123.456);
390 std::vector<double> angles;
391 angles.push_back(1.45);
392 angles.push_back(2.25);
393 BOOST_CHECK(conf.getCorTheta() == angles);
Vince Lehman7b616582014-10-17 16:25:39 -0500394}
395
alvya2228c62014-12-09 10:25:11 -0600396BOOST_AUTO_TEST_CASE(DefaultValuesGeneral)
Vince Lehman7b616582014-10-17 16:25:39 -0500397{
alvya2228c62014-12-09 10:25:11 -0600398 std::string config = SECTION_GENERAL;
Vince Lehman7b616582014-10-17 16:25:39 -0500399
alvya2228c62014-12-09 10:25:11 -0600400 commentOut("lsa-refresh-time", config);
401 commentOut("lsa-interest-lifetime", config);
402 commentOut("router-dead-interval", config);
alvyd5a13cd2015-01-06 16:34:38 -0600403 commentOut("log-level", config);
alvya2228c62014-12-09 10:25:11 -0600404
405 BOOST_CHECK_EQUAL(processConfigurationString(config), true);
Vince Lehman7b616582014-10-17 16:25:39 -0500406
407 ConfParameter& conf = nlsr.getConfParameter();
408
alvy5a454952014-12-15 12:49:54 -0600409 BOOST_CHECK_EQUAL(conf.getLsaRefreshTime(), static_cast<uint32_t>(LSA_REFRESH_TIME_DEFAULT));
alvya2228c62014-12-09 10:25:11 -0600410 BOOST_CHECK_EQUAL(conf.getLsaInterestLifetime(),
411 static_cast<ndn::time::seconds>(LSA_INTEREST_LIFETIME_DEFAULT));
412 BOOST_CHECK_EQUAL(conf.getRouterDeadInterval(), (2*conf.getLsaRefreshTime()));
alvyd5a13cd2015-01-06 16:34:38 -0600413 BOOST_CHECK_EQUAL(conf.getLogLevel(), "INFO");
alvya2228c62014-12-09 10:25:11 -0600414}
415
416BOOST_AUTO_TEST_CASE(DefaultValuesNeighbors)
417{
418 std::string config = SECTION_NEIGHBORS;
419
420 commentOut("hello-retries", config);
421 commentOut("hello-timeout", config);
422 commentOut("hello-interval", config);
423 commentOut("first-hello-interval", config);
424 commentOut("adj-lsa-build-interval", config);
425
426 BOOST_CHECK_EQUAL(processConfigurationString(config), true);
427
428 ConfParameter& conf = nlsr.getConfParameter();
429
430 BOOST_CHECK_EQUAL(conf.getInterestRetryNumber(), static_cast<uint32_t>(HELLO_RETRIES_DEFAULT));
alvy5a454952014-12-15 12:49:54 -0600431 BOOST_CHECK_EQUAL(conf.getInterestResendTime(), static_cast<uint32_t>(HELLO_TIMEOUT_DEFAULT));
432 BOOST_CHECK_EQUAL(conf.getInfoInterestInterval(), static_cast<uint32_t>(HELLO_INTERVAL_DEFAULT));
alvya2228c62014-12-09 10:25:11 -0600433 BOOST_CHECK_EQUAL(conf.getFirstHelloInterval(),
434 static_cast<uint32_t>(FIRST_HELLO_INTERVAL_DEFAULT));
Vince Lehman7b616582014-10-17 16:25:39 -0500435 BOOST_CHECK_EQUAL(conf.getAdjLsaBuildInterval(),
436 static_cast<uint32_t>(ADJ_LSA_BUILD_INTERVAL_DEFAULT));
alvya2228c62014-12-09 10:25:11 -0600437}
Vince Lehman7b616582014-10-17 16:25:39 -0500438
alvya2228c62014-12-09 10:25:11 -0600439BOOST_AUTO_TEST_CASE(DefaultValuesFib)
440{
441 std::string config = SECTION_FIB;
442
443 commentOut("max-faces-per-prefix", config);
444 commentOut("routing-calc-interval", config);
445
446 BOOST_CHECK_EQUAL(processConfigurationString(config), true);
447
448 ConfParameter& conf = nlsr.getConfParameter();
449
450 BOOST_CHECK_EQUAL(conf.getMaxFacesPerPrefix(),
451 static_cast<uint32_t>(MAX_FACES_PER_PREFIX_DEFAULT));
452 BOOST_CHECK_EQUAL(conf.getRoutingCalcInterval(),
453 static_cast<uint32_t>(ROUTING_CALC_INTERVAL_DEFAULT));
454}
455
456BOOST_AUTO_TEST_CASE(DefaultValuesHyperbolic)
457{
458 std::string config = SECTION_HYPERBOLIC_ON;
459
460 commentOut("state", config);
461
462 BOOST_CHECK_EQUAL(processConfigurationString(config), true);
463
464 ConfParameter& conf = nlsr.getConfParameter();
465
466 BOOST_CHECK_EQUAL(conf.getHyperbolicState(), static_cast<int32_t>(HYPERBOLIC_STATE_DEFAULT));
Vince Lehman7b616582014-10-17 16:25:39 -0500467}
468
469BOOST_AUTO_TEST_CASE(OutOfRangeValue)
470{
471 const std::string SECTION_FIB_OUT_OF_RANGE =
472 "fib\n"
473 "{\n"
474 " max-faces-per-prefix 3\n"
475 " routing-calc-interval 999\n" // Larger than max value
476 "}\n\n";
477
478 // Processing should fail due to out of range value
479 BOOST_CHECK_EQUAL(processConfigurationString(SECTION_FIB_OUT_OF_RANGE), false);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500480}
481
alvy5a454952014-12-15 12:49:54 -0600482BOOST_AUTO_TEST_CASE(NegativeValue)
483{
484 const std::string SECTION_GENERAL_NEGATIVE_VALUE =
485 "general\n"
486 "{\n"
487 " network /ndn/\n"
488 " site /memphis.edu/\n"
489 " router /cs/pollux/\n"
490 " lsa-refresh-time -1800\n"
491 " lsa-interest-lifetime -3\n"
492 " router-dead-interval -86400\n"
493 "}\n\n";
494
495 // Processing should fail due to negative value
496 BOOST_CHECK_EQUAL(processConfigurationString(SECTION_GENERAL_NEGATIVE_VALUE), false);
497}
498
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500499BOOST_AUTO_TEST_CASE(LoadCertToPublish)
500{
501 ndn::Name identity("/TestNLSR/identity");
502 identity.appendVersion();
503
504 ndn::KeyChain keyChain;
505 keyChain.createIdentity(identity);
506 ndn::Name certName = keyChain.getDefaultCertificateNameForIdentity(identity);
dmcoomes9f936662017-03-02 10:33:09 -0600507 std::shared_ptr<ndn::IdentityCertificate> certificate = keyChain.getCertificate(certName);
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500508
509 const boost::filesystem::path CERT_PATH =
510 (boost::filesystem::current_path() / std::string("cert-to-publish.cert"));
511 ndn::io::save(*certificate, CERT_PATH.string());
512
513 const std::string SECTION_SECURITY =
514 "security\n"
515 "{\n"
516 " validator\n"
517 " {\n"
518 " trust-anchor\n"
519 " {\n"
520 " type any\n"
521 " }\n"
522 " }\n"
523 " prefix-update-validator\n"
524 " {\n"
525 " trust-anchor\n"
526 " {\n"
527 " type any\n"
528 " }\n"
529 " }\n"
530 " cert-to-publish \"cert-to-publish.cert\"\n"
531 "}\n\n";
532
533 BOOST_CHECK(processConfigurationString(SECTION_SECURITY));
534
535 // Certificate should now be in the CertificateStore
536 const security::CertificateStore& certStore = nlsr.getCertificateStore();
537 const ndn::Name certKey = certificate->getName().getPrefix(-1);
538
539 BOOST_CHECK(certStore.find(certKey) != nullptr);
540
541 // Cleanup
542 keyChain.deleteIdentity(identity);
543 boost::filesystem::remove(CERT_PATH);
544}
545
Vince Lehmand33e5bc2015-06-22 15:27:50 -0500546BOOST_AUTO_TEST_CASE(PrefixUpdateValidatorOptional) // Bug #2814
547{
548 const std::string SECTION_SECURITY =
549 "security\n"
550 "{\n"
551 " validator\n"
552 " {\n"
553 " trust-anchor\n"
554 " {\n"
555 " type any\n"
556 " }\n"
557 " }\n"
558 "}\n\n";
559
560 BOOST_CHECK(processConfigurationString(SECTION_SECURITY));
561}
562
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500563BOOST_AUTO_TEST_SUITE_END()
564
Nick Gordonfad8e252016-08-11 14:21:38 -0500565} // namespace test
566} // namespace nlsr