blob: 5b70a65b45086a7bec47c8a31e0a0b52980035a1 [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"
Vince Lehman904c2412014-09-23 19:36:11 -050025#include "dummy-face.hpp"
Vince Lehman7c603292014-09-11 17:48:16 -050026
akmhoque157b0a42014-05-13 00:26:37 -050027#include <fstream>
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050028#include "conf-file-processor.hpp"
29#include "nlsr.hpp"
30#include <boost/test/unit_test.hpp>
31
32namespace nlsr {
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -050033namespace test {
34
Vince Lehman904c2412014-09-23 19:36:11 -050035using ndn::DummyFace;
36using ndn::shared_ptr;
37
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
Vince Lehman7b616582014-10-17 16:25:39 -050052const std::string SECTION_NEIGHBORS =
53 "neighbors\n"
54 "{\n"
55 " hello-retries 3\n"
56 " hello-timeout 1\n"
57 " hello-interval 60\n\n"
58 " adj-lsa-build-interval 3\n"
59 " first-hello-interval 6\n"
60 " neighbor\n"
61 " {\n"
62 " name /ndn/memphis.edu/cs/castor\n"
63 " face-uri udp4://localhost\n"
64 " link-cost 20\n"
65 " }\n\n"
66 " neighbor\n"
67 " {\n"
68 " name /ndn/memphis.edu/cs/mira\n"
69 " face-uri udp4://localhost\n"
70 " link-cost 30\n"
71 " }\n"
72 "}\n\n";
73
74const std::string SECTION_HYPERBOLIC_ON =
75 "hyperbolic\n"
76 "{\n"
77 " state on\n"
78 " radius 123.456\n"
79 " angle 1.45\n"
80 "}\n\n";
81
82const std::string SECTION_HYPERBOLIC_OFF =
83 "hyperbolic\n"
84 "{\n"
85 " state off\n"
86 " radius 123.456\n"
87 " angle 1.45\n"
88 "}\n\n";
89
90const std::string SECTION_FIB =
91 "fib\n"
92 "{\n"
93 " max-faces-per-prefix 3\n"
94 " routing-calc-interval 9\n"
95 "}\n\n";
96
97const std::string SECTION_ADVERTISING =
98 "advertising\n"
99 "{\n"
100 " prefix /ndn/edu/memphis/cs/netlab\n"
101 " prefix /ndn/edu/memphis/sports/basketball\n"
102 "}\n";
103
104const std::string CONFIG_LINK_STATE = SECTION_GENERAL + SECTION_NEIGHBORS +
105 SECTION_HYPERBOLIC_OFF + SECTION_FIB + SECTION_ADVERTISING;
106
107const std::string CONFIG_HYPERBOLIC = SECTION_GENERAL + SECTION_NEIGHBORS +
108 SECTION_HYPERBOLIC_ON + SECTION_FIB + SECTION_ADVERTISING;
109
110class ConfFileProcessorFixture : public BaseFixture
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500111{
Vince Lehman7b616582014-10-17 16:25:39 -0500112public:
113 ConfFileProcessorFixture()
114 : face(ndn::makeDummyFace())
115 , nlsr(g_ioService, g_scheduler, ndn::ref(*face))
116 , CONFIG_FILE("unit-test-nlsr.conf")
117 {
118 }
Vince Lehman904c2412014-09-23 19:36:11 -0500119
Vince Lehman7b616582014-10-17 16:25:39 -0500120 ~ConfFileProcessorFixture()
121 {
122 remove("unit-test-nlsr.conf");
123 }
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500124
Vince Lehman7b616582014-10-17 16:25:39 -0500125 bool processConfigurationString(std::string confString)
126 {
127 std::ofstream config;
128 config.open("unit-test-nlsr.conf");
129 config << confString;
130 config.close();
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500131
Vince Lehman7b616582014-10-17 16:25:39 -0500132 ConfFileProcessor processor(nlsr, CONFIG_FILE);
133 return processor.processConfFile();
134 }
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500135
Vince Lehman7b616582014-10-17 16:25:39 -0500136public:
137 shared_ptr<ndn::DummyFace> face;
138 Nlsr nlsr;
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500139
Vince Lehman7b616582014-10-17 16:25:39 -0500140private:
141 const std::string CONFIG_FILE;
142};
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500143
Vince Lehman7b616582014-10-17 16:25:39 -0500144BOOST_FIXTURE_TEST_SUITE(TestConfFileProcessor, ConfFileProcessorFixture)
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500145
Vince Lehman7b616582014-10-17 16:25:39 -0500146BOOST_AUTO_TEST_CASE(LinkState)
147{
148 processConfigurationString(CONFIG_LINK_STATE);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500149
Vince Lehman7b616582014-10-17 16:25:39 -0500150 ConfParameter& conf = nlsr.getConfParameter();
151 conf.buildRouterPrefix();
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500152
Vince Lehman7b616582014-10-17 16:25:39 -0500153 // General
154 BOOST_CHECK_EQUAL(conf.getNetwork(), "/ndn/");
155 BOOST_CHECK_EQUAL(conf.getSiteName(), "/memphis.edu/");
156 BOOST_CHECK_EQUAL(conf.getRouterName(), "/cs/pollux/");
157 BOOST_CHECK_EQUAL(conf.getRouterPrefix(), "/ndn/memphis.edu/cs/pollux/");
158 BOOST_CHECK_EQUAL(conf.getChronosyncPrefix(), "/ndn/NLSR/sync");
159 BOOST_CHECK_EQUAL(conf.getLsaPrefix(), "/ndn/NLSR/LSA");
160 BOOST_CHECK_EQUAL(conf.getLsaRefreshTime(), 1800);
161 BOOST_CHECK_EQUAL(conf.getLsaInterestLifetime(), ndn::time::seconds(3));
Alexander Afanasyev1cf1e102014-08-17 19:47:57 -0700162 BOOST_CHECK_EQUAL(conf.getRouterDeadInterval(), 86400);
Vince Lehman7b616582014-10-17 16:25:39 -0500163 BOOST_CHECK_EQUAL(conf.getLogLevel(), "INFO");
164 BOOST_CHECK_EQUAL(conf.getLogDir(), "/tmp");
165 BOOST_CHECK_EQUAL(conf.getSeqFileDir(), "/tmp");
Alexander Afanasyev411ee4b2014-08-16 23:17:03 -0700166
Vince Lehman7b616582014-10-17 16:25:39 -0500167 // Neighbors
168 BOOST_CHECK_EQUAL(conf.getInterestRetryNumber(), 3);
169 BOOST_CHECK_EQUAL(conf.getInterestResendTime(), 1);
170 BOOST_CHECK_EQUAL(conf.getInfoInterestInterval(), 60);
171
172 BOOST_CHECK_EQUAL(conf.getAdjLsaBuildInterval(), 3);
173 BOOST_CHECK_EQUAL(conf.getFirstHelloInterval(), 6);
174
175 BOOST_CHECK(nlsr.getAdjacencyList().isNeighbor("/ndn/memphis.edu/cs/mira"));
176 BOOST_CHECK(nlsr.getAdjacencyList().isNeighbor("/ndn/memphis.edu/cs/castor"));
177 BOOST_CHECK(!nlsr.getAdjacencyList().isNeighbor("/ndn/memphis.edu/cs/fail"));
178
179 Adjacent mira = nlsr.getAdjacencyList().getAdjacent("/ndn/memphis.edu/cs/mira");
180 BOOST_CHECK_EQUAL(mira.getName(), "/ndn/memphis.edu/cs/mira");
181 BOOST_CHECK_EQUAL(mira.getLinkCost(), 30);
182
183 Adjacent castor = nlsr.getAdjacencyList().getAdjacent("/ndn/memphis.edu/cs/castor");
184 BOOST_CHECK_EQUAL(castor.getName(), "/ndn/memphis.edu/cs/castor");
185 BOOST_CHECK_EQUAL(castor.getLinkCost(), 20);
186
187 // Hyperbolic
188 BOOST_CHECK_EQUAL(conf.getHyperbolicState(), 0);
189
190 // FIB
191 BOOST_CHECK_EQUAL(conf.getMaxFacesPerPrefix(), 3);
192 BOOST_CHECK_EQUAL(conf.getRoutingCalcInterval(), 9);
193
194 // Advertising
195 BOOST_CHECK_EQUAL(nlsr.getNamePrefixList().getSize(), 2);
196}
197
198BOOST_AUTO_TEST_CASE(Hyperbolic)
199{
200 processConfigurationString(CONFIG_HYPERBOLIC);
201
202 ConfParameter& conf = nlsr.getConfParameter();
203 BOOST_CHECK_EQUAL(conf.getHyperbolicState(), 1);
204 BOOST_CHECK_EQUAL(conf.getCorR(), 123.456);
205 BOOST_CHECK_EQUAL(conf.getCorTheta(), 1.45);
206}
207
208BOOST_AUTO_TEST_CASE(DefaultValues)
209{
210 // Missing adj-lsa-build-interval
211 const std::string SECTION_NEIGHBORS_DEFAULT_VALUES =
212 "neighbors\n"
213 "{\n"
214 " hello-retries 3\n"
215 " hello-timeout 1\n"
216 " hello-interval 60\n\n"
217 " first-hello-interval 6\n"
218 " neighbor\n"
219 " {\n"
220 " name /ndn/memphis.edu/cs/castor\n"
221 " face-uri udp4://localhost\n"
222 " link-cost 20\n"
223 " }\n\n"
224 " neighbor\n"
225 " {\n"
226 " name /ndn/memphis.edu/cs/mira\n"
227 " face-uri udp4://localhost\n"
228 " link-cost 30\n"
229 " }\n"
230 "}\n\n";
231
232 processConfigurationString(SECTION_NEIGHBORS_DEFAULT_VALUES);
233
234 ConfParameter& conf = nlsr.getConfParameter();
235
236 BOOST_CHECK_EQUAL(conf.getAdjLsaBuildInterval(),
237 static_cast<uint32_t>(ADJ_LSA_BUILD_INTERVAL_DEFAULT));
238
239 BOOST_CHECK_EQUAL(conf.getFirstHelloInterval(), 6);
240}
241
242BOOST_AUTO_TEST_CASE(OutOfRangeValue)
243{
244 const std::string SECTION_FIB_OUT_OF_RANGE =
245 "fib\n"
246 "{\n"
247 " max-faces-per-prefix 3\n"
248 " routing-calc-interval 999\n" // Larger than max value
249 "}\n\n";
250
251 // Processing should fail due to out of range value
252 BOOST_CHECK_EQUAL(processConfigurationString(SECTION_FIB_OUT_OF_RANGE), false);
Ashlesh Gawandeeb582eb2014-05-01 14:25:20 -0500253}
254
255BOOST_AUTO_TEST_SUITE_END()
256
257} //namespace test
258} //namespace nlsr