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 "adjacency-list.hpp" |
Nick Gordon | ff9a627 | 2017-10-12 13:38:29 -0500 | [diff] [blame] | 23 | #include "common.hpp" |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 24 | #include "adjacent.hpp" |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 25 | #include "conf-parameter.hpp" |
| 26 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 27 | #include <boost/test/unit_test.hpp> |
| 28 | |
| 29 | namespace nlsr { |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 30 | namespace test { |
| 31 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 32 | BOOST_AUTO_TEST_SUITE(TestAdjacencyList) |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 33 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 34 | BOOST_AUTO_TEST_CASE(Basic) |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 35 | { |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 36 | const std::string ADJ_NAME_1 = "testname"; |
| 37 | const std::string ADJ_NAME_2 = "testname2"; |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 38 | |
| 39 | //adjacent needed to test adjacency list. |
| 40 | Adjacent adjacent1(ADJ_NAME_1); |
| 41 | Adjacent adjacent2(ADJ_NAME_2); |
| 42 | |
| 43 | adjacent1.setLinkCost(4); |
| 44 | adjacent2.setLinkCost(5); |
| 45 | |
| 46 | AdjacencyList adjacentList1; |
| 47 | AdjacencyList adjacentList2; |
| 48 | |
| 49 | adjacentList1.insert(adjacent1); |
| 50 | adjacentList2.insert(adjacent2); |
| 51 | |
Nick Gordon | ff9a627 | 2017-10-12 13:38:29 -0500 | [diff] [blame] | 52 | BOOST_CHECK_EQUAL(adjacentList1.size(), (uint32_t)1); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 53 | BOOST_CHECK_EQUAL(adjacentList1 == adjacentList2, false); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 54 | |
| 55 | BOOST_CHECK(adjacentList1.isNeighbor("testname")); |
| 56 | BOOST_CHECK_EQUAL(adjacentList1.isNeighbor("adjacent"), false); |
| 57 | |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 58 | std::string n1 = "testname"; |
Vince Lehman | cb76ade | 2014-08-28 21:24:41 -0500 | [diff] [blame] | 59 | BOOST_CHECK_EQUAL(adjacentList1.getStatusOfNeighbor(n1), Adjacent::STATUS_INACTIVE); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 60 | |
Vince Lehman | cb76ade | 2014-08-28 21:24:41 -0500 | [diff] [blame] | 61 | adjacentList1.setStatusOfNeighbor(n1, Adjacent::STATUS_ACTIVE); |
| 62 | BOOST_CHECK_EQUAL(adjacentList1.getStatusOfNeighbor(n1), Adjacent::STATUS_ACTIVE); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 63 | } |
| 64 | |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 65 | BOOST_AUTO_TEST_CASE(findAdjacentByFaceUri) |
| 66 | { |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame^] | 67 | ndn::FaceUri faceUri("udp4://10.0.0.1:6363"); |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 68 | Adjacent adj1("/ndn/test/1", faceUri, 10, Adjacent::STATUS_INACTIVE, 0, 0); |
| 69 | AdjacencyList adjList; |
| 70 | adjList.insert(adj1); |
| 71 | |
| 72 | std::list<Adjacent>::iterator adjIter = adjList.findAdjacent(faceUri); |
| 73 | BOOST_CHECK(adjIter != adjList.end()); |
| 74 | } |
| 75 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 76 | BOOST_AUTO_TEST_CASE(AdjLsaIsBuildableWithOneNodeActive) |
| 77 | { |
| 78 | Adjacent adjacencyA("/router/A"); |
| 79 | Adjacent adjacencyB("/router/B"); |
| 80 | |
| 81 | adjacencyA.setStatus(Adjacent::STATUS_ACTIVE); |
| 82 | adjacencyB.setStatus(Adjacent::STATUS_INACTIVE); |
| 83 | |
| 84 | AdjacencyList adjacencies; |
| 85 | adjacencies.insert(adjacencyA); |
| 86 | adjacencies.insert(adjacencyB); |
| 87 | |
| 88 | ConfParameter conf; |
| 89 | BOOST_CHECK(adjacencies.isAdjLsaBuildable(conf.getInterestRetryNumber())); |
| 90 | } |
| 91 | |
| 92 | BOOST_AUTO_TEST_CASE(AdjLsaIsBuildableWithAllNodesTimedOut) |
| 93 | { |
| 94 | Adjacent adjacencyA("/router/A"); |
| 95 | Adjacent adjacencyB("/router/B"); |
| 96 | |
| 97 | adjacencyA.setStatus(Adjacent::STATUS_INACTIVE); |
| 98 | adjacencyB.setStatus(Adjacent::STATUS_INACTIVE); |
| 99 | |
| 100 | adjacencyA.setInterestTimedOutNo(HELLO_RETRIES_DEFAULT); |
| 101 | adjacencyB.setInterestTimedOutNo(HELLO_RETRIES_DEFAULT); |
| 102 | |
| 103 | AdjacencyList adjacencies; |
| 104 | adjacencies.insert(adjacencyA); |
| 105 | adjacencies.insert(adjacencyB); |
| 106 | |
| 107 | ConfParameter conf; |
| 108 | conf.setInterestRetryNumber(HELLO_RETRIES_DEFAULT); |
| 109 | |
| 110 | BOOST_CHECK(adjacencies.isAdjLsaBuildable(conf.getInterestRetryNumber())); |
| 111 | } |
| 112 | |
| 113 | BOOST_AUTO_TEST_CASE(AdjLsaIsNotBuildable) |
| 114 | { |
| 115 | Adjacent adjacencyA("/router/A"); |
| 116 | Adjacent adjacencyB("/router/B"); |
| 117 | |
| 118 | adjacencyA.setStatus(Adjacent::STATUS_INACTIVE); |
| 119 | adjacencyB.setStatus(Adjacent::STATUS_INACTIVE); |
| 120 | |
| 121 | adjacencyA.setInterestTimedOutNo(HELLO_RETRIES_DEFAULT); |
| 122 | adjacencyB.setInterestTimedOutNo(0); |
| 123 | |
| 124 | AdjacencyList adjacencies; |
| 125 | adjacencies.insert(adjacencyA); |
| 126 | adjacencies.insert(adjacencyB); |
| 127 | |
| 128 | ConfParameter conf; |
| 129 | conf.setInterestRetryNumber(HELLO_RETRIES_DEFAULT); |
| 130 | |
| 131 | BOOST_CHECK(!adjacencies.isAdjLsaBuildable(conf.getInterestRetryNumber())); |
| 132 | } |
| 133 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 134 | BOOST_AUTO_TEST_SUITE_END() |
| 135 | |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 136 | } // namespace test |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 137 | } // namespace nlsr |