blob: df347f1f4d607b0edf13cffb10d0d74be7b96a3b [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
22#include "test-common.hpp"
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -050023#include "logger.hpp"
Vince Lehman7c603292014-09-11 17:48:16 -050024
akmhoque157b0a42014-05-13 00:26:37 -050025#include <fstream>
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050026#include "conf-file-processor.hpp"
27#include "nlsr.hpp"
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -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>
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050032
Muktadir R Chowdhuryc69da0a2015-12-18 13:24:38 -060033#include <ndn-cxx/util/dummy-client-face.hpp>
34
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050035namespace nlsr {
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050036namespace test {
37
dmcoomes9f936662017-03-02 10:33:09 -060038using std::shared_ptr;
Vince Lehman904c2412014-09-23 19:36:11 -050039
Vince Lehman7b616582014-10-17 16:25:39 -050040const 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 Afanasyev1cf1e102014-08-17 19:47:57 -070048 " router-dead-interval 86400\n"
Vince Lehman7b616582014-10-17 16:25:39 -050049 " log-level INFO\n"
50 " log-dir /tmp\n"
51 " seq-dir /tmp\n"
52 "}\n\n";
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050053
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -050054const std::string LOG4CXX_PLACEHOLDER = "$LOG4CXX$";
55
56const 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 Lehman7b616582014-10-17 16:25:39 -050071const 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
93const 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
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600101const std::string SECTION_HYPERBOLIC_ANGLES_ON =
102 "hyperbolic\n"
103 "{\n"
104 " state on\n"
105 " radius 123.456\n"
106 " angle 1.45,2.25\n"
107 "}\n\n";
108
Vince Lehman7b616582014-10-17 16:25:39 -0500109const std::string SECTION_HYPERBOLIC_OFF =
110 "hyperbolic\n"
111 "{\n"
112 " state off\n"
113 " radius 123.456\n"
114 " angle 1.45\n"
115 "}\n\n";
116
117const std::string SECTION_FIB =
118 "fib\n"
119 "{\n"
120 " max-faces-per-prefix 3\n"
121 " routing-calc-interval 9\n"
122 "}\n\n";
123
124const std::string SECTION_ADVERTISING =
125 "advertising\n"
126 "{\n"
127 " prefix /ndn/edu/memphis/cs/netlab\n"
128 " prefix /ndn/edu/memphis/sports/basketball\n"
129 "}\n";
130
131const std::string CONFIG_LINK_STATE = SECTION_GENERAL + SECTION_NEIGHBORS +
132 SECTION_HYPERBOLIC_OFF + SECTION_FIB + SECTION_ADVERTISING;
133
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -0500134const std::string CONFIG_LOG4CXX = SECTION_GENERAL_WITH_LOG4CXX;
135
Vince Lehman7b616582014-10-17 16:25:39 -0500136const std::string CONFIG_HYPERBOLIC = SECTION_GENERAL + SECTION_NEIGHBORS +
137 SECTION_HYPERBOLIC_ON + SECTION_FIB + SECTION_ADVERTISING;
138
Muktadir R Chowdhuryb00dc2a2016-11-05 10:48:58 -0600139const std::string CONFIG_HYPERBOLIC_ANGLES = SECTION_GENERAL + SECTION_NEIGHBORS +
140 SECTION_HYPERBOLIC_ANGLES_ON + SECTION_FIB +
141 SECTION_ADVERTISING;
142
Vince Lehman7b616582014-10-17 16:25:39 -0500143class ConfFileProcessorFixture : public BaseFixture
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500144{
Vince Lehman7b616582014-10-17 16:25:39 -0500145public:
146 ConfFileProcessorFixture()
dmcoomes9f936662017-03-02 10:33:09 -0600147 : face(std::make_shared<ndn::util::DummyClientFace>())
148 , nlsr(g_ioService, g_scheduler, std::ref(*face), g_keyChain)
Vince Lehman7b616582014-10-17 16:25:39 -0500149 , CONFIG_FILE("unit-test-nlsr.conf")
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -0500150 , m_logConfigFileName(boost::filesystem::unique_path().native())
151 , m_logFileName(boost::filesystem::unique_path().native())
Vince Lehman7b616582014-10-17 16:25:39 -0500152 {
153 }
Vince Lehman904c2412014-09-23 19:36:11 -0500154
Vince Lehman7b616582014-10-17 16:25:39 -0500155 ~ConfFileProcessorFixture()
156 {
157 remove("unit-test-nlsr.conf");
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -0500158 remove("/tmp/unit-test-log4cxx.xml");
159
160 boost::filesystem::remove(boost::filesystem::path(getLogConfigFileName()));
161 boost::filesystem::remove(boost::filesystem::path(getLogFileName()));
Vince Lehman7b616582014-10-17 16:25:39 -0500162 }
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500163
Vince Lehman7b616582014-10-17 16:25:39 -0500164 bool processConfigurationString(std::string confString)
165 {
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:
dmcoomes9f936662017-03-02 10:33:09 -0600215 std::shared_ptr<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
274 BOOST_CHECK_EQUAL(nlsr.getNamePrefixList().getSize(), 2);
275}
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
331 _LOG_TRACE("trace-message-JHGFDSR^1");
332 _LOG_DEBUG("debug-message-IGg2474fdksd-fo-" << 15 << 16 << 17);
333 _LOG_INFO("info-message-Jjxjshj13");
334 _LOG_WARN("warning-message-XXXhdhd11" << 1 <<"x");
335 _LOG_ERROR("error-message-!#$&^%$#@");
336 _LOG_FATAL("fatal-message-JJSjaamcng");
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
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{
503 ndn::Name identity("/TestNLSR/identity");
504 identity.appendVersion();
505
506 ndn::KeyChain keyChain;
507 keyChain.createIdentity(identity);
508 ndn::Name certName = keyChain.getDefaultCertificateNameForIdentity(identity);
dmcoomes9f936662017-03-02 10:33:09 -0600509 std::shared_ptr<ndn::IdentityCertificate> certificate = keyChain.getCertificate(certName);
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500510
511 const boost::filesystem::path CERT_PATH =
512 (boost::filesystem::current_path() / std::string("cert-to-publish.cert"));
513 ndn::io::save(*certificate, CERT_PATH.string());
514
515 const std::string SECTION_SECURITY =
516 "security\n"
517 "{\n"
518 " validator\n"
519 " {\n"
520 " trust-anchor\n"
521 " {\n"
522 " type any\n"
523 " }\n"
524 " }\n"
525 " prefix-update-validator\n"
526 " {\n"
527 " trust-anchor\n"
528 " {\n"
529 " type any\n"
530 " }\n"
531 " }\n"
532 " cert-to-publish \"cert-to-publish.cert\"\n"
533 "}\n\n";
534
535 BOOST_CHECK(processConfigurationString(SECTION_SECURITY));
536
537 // Certificate should now be in the CertificateStore
538 const security::CertificateStore& certStore = nlsr.getCertificateStore();
539 const ndn::Name certKey = certificate->getName().getPrefix(-1);
540
541 BOOST_CHECK(certStore.find(certKey) != nullptr);
542
543 // Cleanup
544 keyChain.deleteIdentity(identity);
545 boost::filesystem::remove(CERT_PATH);
546}
547
Vince Lehmand33e5bc2015-06-22 15:27:50 -0500548BOOST_AUTO_TEST_CASE(PrefixUpdateValidatorOptional) // Bug #2814
549{
550 const std::string SECTION_SECURITY =
551 "security\n"
552 "{\n"
553 " validator\n"
554 " {\n"
555 " trust-anchor\n"
556 " {\n"
557 " type any\n"
558 " }\n"
559 " }\n"
560 "}\n\n";
561
562 BOOST_CHECK(processConfigurationString(SECTION_SECURITY));
563}
564
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500565BOOST_AUTO_TEST_SUITE_END()
566
Nick Gordonfad8e252016-08-11 14:21:38 -0500567} // namespace test
568} // namespace nlsr