blob: 50cc872cf41ea85681e17b7a84799af2c9ff4622 [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/**
Vince Lehmanc2e51f62015-01-20 15:03:11 -06003 * Copyright (c) 2014-2015, The University of Memphis,
4 * 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"
Vince Lehman904c2412014-09-23 19:36:11 -050023#include "dummy-face.hpp"
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -050024#include "logger.hpp"
Vince Lehman7c603292014-09-11 17:48:16 -050025
akmhoque157b0a42014-05-13 00:26:37 -050026#include <fstream>
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050027#include "conf-file-processor.hpp"
28#include "nlsr.hpp"
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -050029
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050030#include <boost/test/unit_test.hpp>
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -050031#include <boost/filesystem.hpp>
32#include <boost/algorithm/string.hpp>
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050033
34namespace nlsr {
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050035namespace test {
36
Vince Lehman904c2412014-09-23 19:36:11 -050037using ndn::DummyFace;
38using ndn::shared_ptr;
39
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
101const 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
109const 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
116const 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
123const std::string CONFIG_LINK_STATE = SECTION_GENERAL + SECTION_NEIGHBORS +
124 SECTION_HYPERBOLIC_OFF + SECTION_FIB + SECTION_ADVERTISING;
125
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -0500126const std::string CONFIG_LOG4CXX = SECTION_GENERAL_WITH_LOG4CXX;
127
Vince Lehman7b616582014-10-17 16:25:39 -0500128const std::string CONFIG_HYPERBOLIC = SECTION_GENERAL + SECTION_NEIGHBORS +
129 SECTION_HYPERBOLIC_ON + SECTION_FIB + SECTION_ADVERTISING;
130
131class ConfFileProcessorFixture : public BaseFixture
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500132{
Vince Lehman7b616582014-10-17 16:25:39 -0500133public:
134 ConfFileProcessorFixture()
135 : face(ndn::makeDummyFace())
136 , nlsr(g_ioService, g_scheduler, ndn::ref(*face))
137 , CONFIG_FILE("unit-test-nlsr.conf")
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -0500138 , m_logConfigFileName(boost::filesystem::unique_path().native())
139 , m_logFileName(boost::filesystem::unique_path().native())
Vince Lehman7b616582014-10-17 16:25:39 -0500140 {
141 }
Vince Lehman904c2412014-09-23 19:36:11 -0500142
Vince Lehman7b616582014-10-17 16:25:39 -0500143 ~ConfFileProcessorFixture()
144 {
145 remove("unit-test-nlsr.conf");
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -0500146 remove("/tmp/unit-test-log4cxx.xml");
147
148 boost::filesystem::remove(boost::filesystem::path(getLogConfigFileName()));
149 boost::filesystem::remove(boost::filesystem::path(getLogFileName()));
Vince Lehman7b616582014-10-17 16:25:39 -0500150 }
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500151
Vince Lehman7b616582014-10-17 16:25:39 -0500152 bool processConfigurationString(std::string confString)
153 {
154 std::ofstream config;
155 config.open("unit-test-nlsr.conf");
156 config << confString;
157 config.close();
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500158
Vince Lehman7b616582014-10-17 16:25:39 -0500159 ConfFileProcessor processor(nlsr, CONFIG_FILE);
160 return processor.processConfFile();
161 }
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500162
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -0500163 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
alvya2228c62014-12-09 10:25:11 -0600196 void
197 commentOut(const std::string& key, std::string& config)
198 {
199 boost::replace_all(config, key, ";" + key);
200 }
201
Vince Lehman7b616582014-10-17 16:25:39 -0500202public:
203 shared_ptr<ndn::DummyFace> face;
204 Nlsr nlsr;
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500205
Vince Lehman7b616582014-10-17 16:25:39 -0500206private:
207 const std::string CONFIG_FILE;
Muktadir R Chowdhurybfa27602014-10-31 10:57:41 -0500208 std::string m_logConfigFileName;
209 std::string m_logFileName;
Vince Lehman7b616582014-10-17 16:25:39 -0500210};
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500211
Vince Lehman7b616582014-10-17 16:25:39 -0500212BOOST_FIXTURE_TEST_SUITE(TestConfFileProcessor, ConfFileProcessorFixture)
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500213
Vince Lehman7b616582014-10-17 16:25:39 -0500214BOOST_AUTO_TEST_CASE(LinkState)
215{
216 processConfigurationString(CONFIG_LINK_STATE);
Vince Lehman7b616582014-10-17 16:25:39 -0500217 ConfParameter& conf = nlsr.getConfParameter();
218 conf.buildRouterPrefix();
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500219
Vince Lehman7b616582014-10-17 16:25:39 -0500220 // 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/");
225 BOOST_CHECK_EQUAL(conf.getChronosyncPrefix(), "/ndn/NLSR/sync");
226 BOOST_CHECK_EQUAL(conf.getLsaPrefix(), "/ndn/NLSR/LSA");
227 BOOST_CHECK_EQUAL(conf.getLsaRefreshTime(), 1800);
228 BOOST_CHECK_EQUAL(conf.getLsaInterestLifetime(), ndn::time::seconds(3));
Alexander Afanasyev1cf1e102014-08-17 19:47:57 -0700229 BOOST_CHECK_EQUAL(conf.getRouterDeadInterval(), 86400);
Vince Lehman7b616582014-10-17 16:25:39 -0500230 BOOST_CHECK_EQUAL(conf.getLogLevel(), "INFO");
231 BOOST_CHECK_EQUAL(conf.getLogDir(), "/tmp");
232 BOOST_CHECK_EQUAL(conf.getSeqFileDir(), "/tmp");
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700233
Vince Lehman7b616582014-10-17 16:25:39 -0500234 // 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 Chowdhurybfa27602014-10-31 10:57:41 -0500265BOOST_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
285BOOST_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
295BOOST_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
303BOOST_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
alvy2fe12872014-11-25 10:32:23 -0600340BOOST_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 Lehman7b616582014-10-17 16:25:39 -0500361BOOST_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
alvya2228c62014-12-09 10:25:11 -0600371BOOST_AUTO_TEST_CASE(DefaultValuesGeneral)
Vince Lehman7b616582014-10-17 16:25:39 -0500372{
alvya2228c62014-12-09 10:25:11 -0600373 std::string config = SECTION_GENERAL;
Vince Lehman7b616582014-10-17 16:25:39 -0500374
alvya2228c62014-12-09 10:25:11 -0600375 commentOut("lsa-refresh-time", config);
376 commentOut("lsa-interest-lifetime", config);
377 commentOut("router-dead-interval", config);
alvyd5a13cd2015-01-06 16:34:38 -0600378 commentOut("log-level", config);
alvya2228c62014-12-09 10:25:11 -0600379
380 BOOST_CHECK_EQUAL(processConfigurationString(config), true);
Vince Lehman7b616582014-10-17 16:25:39 -0500381
382 ConfParameter& conf = nlsr.getConfParameter();
383
alvy5a454952014-12-15 12:49:54 -0600384 BOOST_CHECK_EQUAL(conf.getLsaRefreshTime(), static_cast<uint32_t>(LSA_REFRESH_TIME_DEFAULT));
alvya2228c62014-12-09 10:25:11 -0600385 BOOST_CHECK_EQUAL(conf.getLsaInterestLifetime(),
386 static_cast<ndn::time::seconds>(LSA_INTEREST_LIFETIME_DEFAULT));
387 BOOST_CHECK_EQUAL(conf.getRouterDeadInterval(), (2*conf.getLsaRefreshTime()));
alvyd5a13cd2015-01-06 16:34:38 -0600388 BOOST_CHECK_EQUAL(conf.getLogLevel(), "INFO");
alvya2228c62014-12-09 10:25:11 -0600389}
390
391BOOST_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));
alvy5a454952014-12-15 12:49:54 -0600406 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));
alvya2228c62014-12-09 10:25:11 -0600408 BOOST_CHECK_EQUAL(conf.getFirstHelloInterval(),
409 static_cast<uint32_t>(FIRST_HELLO_INTERVAL_DEFAULT));
Vince Lehman7b616582014-10-17 16:25:39 -0500410 BOOST_CHECK_EQUAL(conf.getAdjLsaBuildInterval(),
411 static_cast<uint32_t>(ADJ_LSA_BUILD_INTERVAL_DEFAULT));
alvya2228c62014-12-09 10:25:11 -0600412}
Vince Lehman7b616582014-10-17 16:25:39 -0500413
alvya2228c62014-12-09 10:25:11 -0600414BOOST_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
431BOOST_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 Lehman7b616582014-10-17 16:25:39 -0500442}
443
444BOOST_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 Gawandeeb582eb2014-05-01 14:25:20 -0500455}
456
alvy5a454952014-12-15 12:49:54 -0600457BOOST_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 Lehmanc2acdcb2015-04-29 11:14:35 -0500474BOOST_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);
482 shared_ptr<ndn::IdentityCertificate> certificate = keyChain.getCertificate(certName);
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
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500521BOOST_AUTO_TEST_SUITE_END()
522
523} //namespace test
alvy2fe12872014-11-25 10:32:23 -0600524} //namespace nlsr