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