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" |
| 46 | " log-level INFO\n" |
| 47 | " log-dir /tmp\n" |
| 48 | " seq-dir /tmp\n" |
| 49 | "}\n\n"; |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 50 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame^] | 51 | const 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 | |
| 73 | const 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 | |
| 81 | const 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 | |
| 89 | const 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 | |
| 96 | const 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 | |
| 103 | const std::string CONFIG_LINK_STATE = SECTION_GENERAL + SECTION_NEIGHBORS + |
| 104 | SECTION_HYPERBOLIC_OFF + SECTION_FIB + SECTION_ADVERTISING; |
| 105 | |
| 106 | const std::string CONFIG_HYPERBOLIC = SECTION_GENERAL + SECTION_NEIGHBORS + |
| 107 | SECTION_HYPERBOLIC_ON + SECTION_FIB + SECTION_ADVERTISING; |
| 108 | |
| 109 | class ConfFileProcessorFixture : public BaseFixture |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 110 | { |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame^] | 111 | public: |
| 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 Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 118 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame^] | 119 | ~ConfFileProcessorFixture() |
| 120 | { |
| 121 | remove("unit-test-nlsr.conf"); |
| 122 | } |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 123 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame^] | 124 | bool processConfigurationString(std::string confString) |
| 125 | { |
| 126 | std::ofstream config; |
| 127 | config.open("unit-test-nlsr.conf"); |
| 128 | config << confString; |
| 129 | config.close(); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 130 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame^] | 131 | ConfFileProcessor processor(nlsr, CONFIG_FILE); |
| 132 | return processor.processConfFile(); |
| 133 | } |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 134 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame^] | 135 | public: |
| 136 | shared_ptr<ndn::DummyFace> face; |
| 137 | Nlsr nlsr; |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 138 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame^] | 139 | private: |
| 140 | const std::string CONFIG_FILE; |
| 141 | }; |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 142 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame^] | 143 | BOOST_FIXTURE_TEST_SUITE(TestConfFileProcessor, ConfFileProcessorFixture) |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 144 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame^] | 145 | BOOST_AUTO_TEST_CASE(LinkState) |
| 146 | { |
| 147 | processConfigurationString(CONFIG_LINK_STATE); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 148 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame^] | 149 | ConfParameter& conf = nlsr.getConfParameter(); |
| 150 | conf.buildRouterPrefix(); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 151 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame^] | 152 | // 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 Afanasyev | 411ee4b | 2014-08-16 23:17:03 -0700 | [diff] [blame] | 165 | |
Vince Lehman | 7b61658 | 2014-10-17 16:25:39 -0500 | [diff] [blame^] | 166 | // 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 | |
| 197 | BOOST_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 | |
| 207 | BOOST_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 | |
| 241 | BOOST_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 Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | BOOST_AUTO_TEST_SUITE_END() |
| 255 | |
| 256 | } //namespace test |
| 257 | } //namespace nlsr |