blob: 44987de08b9046db2b51167386d11d55f0307a35 [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/**
akmhoque3d06e792014-05-27 16:23:20 -05003 * 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 Lehman7c603292014-09-11 17:48:16 -050023
24#include "test-common.hpp"
25
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"
29#include <boost/test/unit_test.hpp>
30
31namespace nlsr {
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050032namespace test {
33
Vince Lehman7c603292014-09-11 17:48:16 -050034BOOST_FIXTURE_TEST_SUITE(TestConfFileProcessor, BaseFixture)
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050035
36BOOST_AUTO_TEST_CASE(ConfFileProcessorSample)
37{
Vince Lehman7c603292014-09-11 17:48:16 -050038 Nlsr nlsr1(g_ioService, g_scheduler);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050039
40 const std::string CONFIG =
akmhoque157b0a42014-05-13 00:26:37 -050041 "general\n"
42 "{\n"
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -070043 " network /ndn/\n"
akmhoque157b0a42014-05-13 00:26:37 -050044 " site /memphis.edu/\n"
45 " router /cs/pollux/\n"
46 " lsa-refresh-time 1800\n"
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -070047 " lsa-interest-lifetime 3\n"
akmhoque157b0a42014-05-13 00:26:37 -050048 " log-level INFO\n"
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -070049 " log-dir /tmp\n"
50 " seq-dir /tmp\n"
akmhoque157b0a42014-05-13 00:26:37 -050051 "}\n\n"
52 "neighbors\n"
53 "{\n"
54 " hello-retries 3\n"
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -070055 " hello-timeout 1\n"
akmhoque157b0a42014-05-13 00:26:37 -050056 " hello-interval 60\n\n"
57 " neighbor\n"
58 " {\n"
59 " name /ndn/memphis.edu/cs/castor\n"
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -070060 " face-uri udp4://localhost\n"
akmhoque157b0a42014-05-13 00:26:37 -050061 " link-cost 20\n"
62 " }\n\n"
63 " neighbor\n"
64 " {\n"
65 " name /ndn/memphis.edu/cs/mira\n"
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -070066 " face-uri udp4://localhost\n"
akmhoque157b0a42014-05-13 00:26:37 -050067 " link-cost 30\n"
68 " }\n"
69 "}\n\n"
70 "hyperbolic\n"
71 "{\n"
72 "state off\n"
73 "radius 123.456\n"
74 "angle 1.45\n"
75 "}\n\n"
76 "fib\n"
77 "{\n"
78 " max-faces-per-prefix 3\n"
79 "}\n\n"
80 "advertising\n"
81 "{\n"
82 "prefix /ndn/edu/memphis/cs/netlab\n"
83 "prefix /ndn/edu/memphis/sports/basketball\n"
84 "}\n";
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050085
akmhoquefdbddb12014-05-02 18:35:19 -050086 std::ofstream config;
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050087 config.open("unit-test-nlsr.conf");
88 config << CONFIG;
89 config.close();
90
akmhoquefdbddb12014-05-02 18:35:19 -050091 const std::string CONFIG_FILE = "unit-test-nlsr.conf";
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050092
93 ConfFileProcessor cfp1(nlsr1, CONFIG_FILE);
94
95 cfp1.processConfFile();
96
akmhoque157b0a42014-05-13 00:26:37 -050097 BOOST_CHECK(nlsr1.getAdjacencyList().isNeighbor("/ndn/memphis.edu/cs/mira"));
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050098 BOOST_CHECK_EQUAL(
akmhoque157b0a42014-05-13 00:26:37 -050099 nlsr1.getAdjacencyList().getAdjacent("/ndn/memphis.edu/cs/mira").getName(),
100 "/ndn/memphis.edu/cs/mira");
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500101 BOOST_CHECK_EQUAL(
akmhoque157b0a42014-05-13 00:26:37 -0500102 nlsr1.getAdjacencyList().getAdjacent("/ndn/memphis.edu/cs/mira").getLinkCost(),
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500103 30);
104
105 BOOST_CHECK_EQUAL(nlsr1.getNamePrefixList().getSize(), 2);
106
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700107 BOOST_CHECK_EQUAL(nlsr1.getConfParameter().getLsaInterestLifetime(),
108 ndn::time::seconds(3));
109
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500110 remove("unit-test-nlsr.conf");
111}
112
113BOOST_AUTO_TEST_SUITE_END()
114
115} //namespace test
116} //namespace nlsr