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 | /** |
Nick Gordon | feae557 | 2017-01-13 12:06:26 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, The University of Memphis, |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 4 | * Regents of the University of California, |
| 5 | * Arizona Board of Regents. |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 6 | * |
| 7 | * This file is part of NLSR (Named-data Link State Routing). |
| 8 | * See AUTHORS.md for complete list of NLSR authors and contributors. |
| 9 | * |
| 10 | * NLSR is free software: you can redistribute it and/or modify it under the terms |
| 11 | * of the GNU General Public License as published by the Free Software Foundation, |
| 12 | * either version 3 of the License, or (at your option) any later version. |
| 13 | * |
| 14 | * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 15 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE. See the GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along with |
| 19 | * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 20 | **/ |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 21 | |
Nick Gordon | e98480b | 2017-05-24 11:23:03 -0500 | [diff] [blame] | 22 | #include "common.hpp" |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 23 | |
Nick Gordon | e98480b | 2017-05-24 11:23:03 -0500 | [diff] [blame] | 24 | #include "adjacency-list.hpp" |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 25 | #include "adjacent.hpp" |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 26 | #include "conf-parameter.hpp" |
| 27 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 28 | #include <boost/test/unit_test.hpp> |
| 29 | |
| 30 | namespace nlsr { |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 31 | namespace test { |
| 32 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 33 | BOOST_AUTO_TEST_SUITE(TestAdjacencyList) |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 34 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 35 | BOOST_AUTO_TEST_CASE(Basic) |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 36 | { |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 37 | const std::string ADJ_NAME_1 = "testname"; |
| 38 | const std::string ADJ_NAME_2 = "testname2"; |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 39 | |
| 40 | //adjacent needed to test adjacency list. |
| 41 | Adjacent adjacent1(ADJ_NAME_1); |
| 42 | Adjacent adjacent2(ADJ_NAME_2); |
| 43 | |
| 44 | adjacent1.setLinkCost(4); |
| 45 | adjacent2.setLinkCost(5); |
| 46 | |
| 47 | AdjacencyList adjacentList1; |
| 48 | AdjacencyList adjacentList2; |
| 49 | |
| 50 | adjacentList1.insert(adjacent1); |
| 51 | adjacentList2.insert(adjacent2); |
| 52 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 53 | BOOST_CHECK_EQUAL(adjacentList1.getSize(), (uint32_t)1); |
| 54 | BOOST_CHECK_EQUAL(adjacentList1 == adjacentList2, false); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 55 | |
| 56 | BOOST_CHECK(adjacentList1.isNeighbor("testname")); |
| 57 | BOOST_CHECK_EQUAL(adjacentList1.isNeighbor("adjacent"), false); |
| 58 | |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 59 | std::string n1 = "testname"; |
Vince Lehman | cb76ade | 2014-08-28 21:24:41 -0500 | [diff] [blame] | 60 | BOOST_CHECK_EQUAL(adjacentList1.getStatusOfNeighbor(n1), Adjacent::STATUS_INACTIVE); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 61 | |
Vince Lehman | cb76ade | 2014-08-28 21:24:41 -0500 | [diff] [blame] | 62 | adjacentList1.setStatusOfNeighbor(n1, Adjacent::STATUS_ACTIVE); |
| 63 | BOOST_CHECK_EQUAL(adjacentList1.getStatusOfNeighbor(n1), Adjacent::STATUS_ACTIVE); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 64 | } |
| 65 | |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 66 | BOOST_AUTO_TEST_CASE(findAdjacentByFaceUri) |
| 67 | { |
| 68 | ndn::util::FaceUri faceUri("udp4://10.0.0.1:6363"); |
| 69 | Adjacent adj1("/ndn/test/1", faceUri, 10, Adjacent::STATUS_INACTIVE, 0, 0); |
| 70 | AdjacencyList adjList; |
| 71 | adjList.insert(adj1); |
| 72 | |
| 73 | std::list<Adjacent>::iterator adjIter = adjList.findAdjacent(faceUri); |
| 74 | BOOST_CHECK(adjIter != adjList.end()); |
| 75 | } |
| 76 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 77 | BOOST_AUTO_TEST_CASE(AdjLsaIsBuildableWithOneNodeActive) |
| 78 | { |
| 79 | Adjacent adjacencyA("/router/A"); |
| 80 | Adjacent adjacencyB("/router/B"); |
| 81 | |
| 82 | adjacencyA.setStatus(Adjacent::STATUS_ACTIVE); |
| 83 | adjacencyB.setStatus(Adjacent::STATUS_INACTIVE); |
| 84 | |
| 85 | AdjacencyList adjacencies; |
| 86 | adjacencies.insert(adjacencyA); |
| 87 | adjacencies.insert(adjacencyB); |
| 88 | |
| 89 | ConfParameter conf; |
| 90 | BOOST_CHECK(adjacencies.isAdjLsaBuildable(conf.getInterestRetryNumber())); |
| 91 | } |
| 92 | |
| 93 | BOOST_AUTO_TEST_CASE(AdjLsaIsBuildableWithAllNodesTimedOut) |
| 94 | { |
| 95 | Adjacent adjacencyA("/router/A"); |
| 96 | Adjacent adjacencyB("/router/B"); |
| 97 | |
| 98 | adjacencyA.setStatus(Adjacent::STATUS_INACTIVE); |
| 99 | adjacencyB.setStatus(Adjacent::STATUS_INACTIVE); |
| 100 | |
| 101 | adjacencyA.setInterestTimedOutNo(HELLO_RETRIES_DEFAULT); |
| 102 | adjacencyB.setInterestTimedOutNo(HELLO_RETRIES_DEFAULT); |
| 103 | |
| 104 | AdjacencyList adjacencies; |
| 105 | adjacencies.insert(adjacencyA); |
| 106 | adjacencies.insert(adjacencyB); |
| 107 | |
| 108 | ConfParameter conf; |
| 109 | conf.setInterestRetryNumber(HELLO_RETRIES_DEFAULT); |
| 110 | |
| 111 | BOOST_CHECK(adjacencies.isAdjLsaBuildable(conf.getInterestRetryNumber())); |
| 112 | } |
| 113 | |
| 114 | BOOST_AUTO_TEST_CASE(AdjLsaIsNotBuildable) |
| 115 | { |
| 116 | Adjacent adjacencyA("/router/A"); |
| 117 | Adjacent adjacencyB("/router/B"); |
| 118 | |
| 119 | adjacencyA.setStatus(Adjacent::STATUS_INACTIVE); |
| 120 | adjacencyB.setStatus(Adjacent::STATUS_INACTIVE); |
| 121 | |
| 122 | adjacencyA.setInterestTimedOutNo(HELLO_RETRIES_DEFAULT); |
| 123 | adjacencyB.setInterestTimedOutNo(0); |
| 124 | |
| 125 | AdjacencyList adjacencies; |
| 126 | adjacencies.insert(adjacencyA); |
| 127 | adjacencies.insert(adjacencyB); |
| 128 | |
| 129 | ConfParameter conf; |
| 130 | conf.setInterestRetryNumber(HELLO_RETRIES_DEFAULT); |
| 131 | |
| 132 | BOOST_CHECK(!adjacencies.isAdjLsaBuildable(conf.getInterestRetryNumber())); |
| 133 | } |
| 134 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 135 | BOOST_AUTO_TEST_SUITE_END() |
| 136 | |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 137 | } // namespace test |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 138 | } // namespace nlsr |