akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 2 | /** |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 3 | * 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 Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 23 | |
| 24 | #include "test-common.hpp" |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 25 | #include "dummy-face.hpp" |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 26 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 27 | #include <fstream> |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 28 | #include "conf-file-processor.hpp" |
| 29 | #include "nlsr.hpp" |
| 30 | #include <boost/test/unit_test.hpp> |
| 31 | |
| 32 | namespace nlsr { |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 33 | namespace test { |
| 34 | |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 35 | using ndn::DummyFace; |
| 36 | using ndn::shared_ptr; |
| 37 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 38 | const 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 Afanasyev | 1cf1e10 | 2014-08-17 19:47:57 -0700 | [diff] [blame^] | 46 | " router-dead-interval 86400\n" |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 47 | " log-level INFO\n" |
| 48 | " log-dir /tmp\n" |
| 49 | " seq-dir /tmp\n" |
| 50 | "}\n\n"; |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 51 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 52 | const 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 | |
| 74 | const 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 | |
| 82 | const 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 | |
| 90 | const 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 | |
| 97 | const 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 | |
| 104 | const std::string CONFIG_LINK_STATE = SECTION_GENERAL + SECTION_NEIGHBORS + |
| 105 | SECTION_HYPERBOLIC_OFF + SECTION_FIB + SECTION_ADVERTISING; |
| 106 | |
| 107 | const std::string CONFIG_HYPERBOLIC = SECTION_GENERAL + SECTION_NEIGHBORS + |
| 108 | SECTION_HYPERBOLIC_ON + SECTION_FIB + SECTION_ADVERTISING; |
| 109 | |
| 110 | class ConfFileProcessorFixture : public BaseFixture |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 111 | { |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 112 | public: |
| 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 Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 119 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 120 | ~ConfFileProcessorFixture() |
| 121 | { |
| 122 | remove("unit-test-nlsr.conf"); |
| 123 | } |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 124 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 125 | bool processConfigurationString(std::string confString) |
| 126 | { |
| 127 | std::ofstream config; |
| 128 | config.open("unit-test-nlsr.conf"); |
| 129 | config << confString; |
| 130 | config.close(); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 131 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 132 | ConfFileProcessor processor(nlsr, CONFIG_FILE); |
| 133 | return processor.processConfFile(); |
| 134 | } |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 135 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 136 | public: |
| 137 | shared_ptr<ndn::DummyFace> face; |
| 138 | Nlsr nlsr; |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 139 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 140 | private: |
| 141 | const std::string CONFIG_FILE; |
| 142 | }; |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 143 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 144 | BOOST_FIXTURE_TEST_SUITE(TestConfFileProcessor, ConfFileProcessorFixture) |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 145 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 146 | BOOST_AUTO_TEST_CASE(LinkState) |
| 147 | { |
| 148 | processConfigurationString(CONFIG_LINK_STATE); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 149 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 150 | ConfParameter& conf = nlsr.getConfParameter(); |
| 151 | conf.buildRouterPrefix(); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 152 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 153 | // 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 Afanasyev | 1cf1e10 | 2014-08-17 19:47:57 -0700 | [diff] [blame^] | 162 | BOOST_CHECK_EQUAL(conf.getRouterDeadInterval(), 86400); |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 163 | BOOST_CHECK_EQUAL(conf.getLogLevel(), "INFO"); |
| 164 | BOOST_CHECK_EQUAL(conf.getLogDir(), "/tmp"); |
| 165 | BOOST_CHECK_EQUAL(conf.getSeqFileDir(), "/tmp"); |
Alexander Afanasyev | 411ee4b | 2014-08-16 23:17:03 -0700 | [diff] [blame] | 166 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame] | 167 | // 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 | |
| 198 | BOOST_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 | |
| 208 | BOOST_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 | |
| 242 | BOOST_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 Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | BOOST_AUTO_TEST_SUITE_END() |
| 256 | |
| 257 | } //namespace test |
| 258 | } //namespace nlsr |