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 | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 38 | BOOST_FIXTURE_TEST_SUITE(TestConfFileProcessor, BaseFixture) |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 39 | |
| 40 | BOOST_AUTO_TEST_CASE(ConfFileProcessorSample) |
| 41 | { |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 42 | shared_ptr<DummyFace> face = ndn::makeDummyFace(); |
| 43 | |
| 44 | Nlsr nlsr1(g_ioService, g_scheduler, ndn::ref(*face)); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 45 | |
| 46 | const std::string CONFIG = |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 47 | "general\n" |
| 48 | "{\n" |
Alexander Afanasyev | 411ee4b | 2014-08-16 23:17:03 -0700 | [diff] [blame] | 49 | " network /ndn/\n" |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 50 | " site /memphis.edu/\n" |
| 51 | " router /cs/pollux/\n" |
| 52 | " lsa-refresh-time 1800\n" |
Alexander Afanasyev | 411ee4b | 2014-08-16 23:17:03 -0700 | [diff] [blame] | 53 | " lsa-interest-lifetime 3\n" |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 54 | " log-level INFO\n" |
Alexander Afanasyev | 411ee4b | 2014-08-16 23:17:03 -0700 | [diff] [blame] | 55 | " log-dir /tmp\n" |
| 56 | " seq-dir /tmp\n" |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 57 | "}\n\n" |
| 58 | "neighbors\n" |
| 59 | "{\n" |
| 60 | " hello-retries 3\n" |
Alexander Afanasyev | 411ee4b | 2014-08-16 23:17:03 -0700 | [diff] [blame] | 61 | " hello-timeout 1\n" |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 62 | " hello-interval 60\n\n" |
| 63 | " neighbor\n" |
| 64 | " {\n" |
| 65 | " name /ndn/memphis.edu/cs/castor\n" |
Alexander Afanasyev | 411ee4b | 2014-08-16 23:17:03 -0700 | [diff] [blame] | 66 | " face-uri udp4://localhost\n" |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 67 | " link-cost 20\n" |
| 68 | " }\n\n" |
| 69 | " neighbor\n" |
| 70 | " {\n" |
| 71 | " name /ndn/memphis.edu/cs/mira\n" |
Alexander Afanasyev | 411ee4b | 2014-08-16 23:17:03 -0700 | [diff] [blame] | 72 | " face-uri udp4://localhost\n" |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 73 | " link-cost 30\n" |
| 74 | " }\n" |
| 75 | "}\n\n" |
| 76 | "hyperbolic\n" |
| 77 | "{\n" |
| 78 | "state off\n" |
| 79 | "radius 123.456\n" |
| 80 | "angle 1.45\n" |
| 81 | "}\n\n" |
| 82 | "fib\n" |
| 83 | "{\n" |
| 84 | " max-faces-per-prefix 3\n" |
| 85 | "}\n\n" |
| 86 | "advertising\n" |
| 87 | "{\n" |
| 88 | "prefix /ndn/edu/memphis/cs/netlab\n" |
| 89 | "prefix /ndn/edu/memphis/sports/basketball\n" |
| 90 | "}\n"; |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 91 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 92 | std::ofstream config; |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 93 | config.open("unit-test-nlsr.conf"); |
| 94 | config << CONFIG; |
| 95 | config.close(); |
| 96 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 97 | const std::string CONFIG_FILE = "unit-test-nlsr.conf"; |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 98 | |
| 99 | ConfFileProcessor cfp1(nlsr1, CONFIG_FILE); |
| 100 | |
| 101 | cfp1.processConfFile(); |
| 102 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 103 | BOOST_CHECK(nlsr1.getAdjacencyList().isNeighbor("/ndn/memphis.edu/cs/mira")); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 104 | BOOST_CHECK_EQUAL( |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 105 | nlsr1.getAdjacencyList().getAdjacent("/ndn/memphis.edu/cs/mira").getName(), |
| 106 | "/ndn/memphis.edu/cs/mira"); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 107 | BOOST_CHECK_EQUAL( |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 108 | nlsr1.getAdjacencyList().getAdjacent("/ndn/memphis.edu/cs/mira").getLinkCost(), |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 109 | 30); |
| 110 | |
| 111 | BOOST_CHECK_EQUAL(nlsr1.getNamePrefixList().getSize(), 2); |
| 112 | |
Alexander Afanasyev | 411ee4b | 2014-08-16 23:17:03 -0700 | [diff] [blame] | 113 | BOOST_CHECK_EQUAL(nlsr1.getConfParameter().getLsaInterestLifetime(), |
| 114 | ndn::time::seconds(3)); |
| 115 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 116 | remove("unit-test-nlsr.conf"); |
| 117 | } |
| 118 | |
| 119 | BOOST_AUTO_TEST_SUITE_END() |
| 120 | |
| 121 | } //namespace test |
| 122 | } //namespace nlsr |