akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 2 | /* |
Junxiao Shi | 43f37a0 | 2023-08-09 00:09:00 +0000 | [diff] [blame^] | 3 | * Copyright (c) 2014-2023, 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/>. |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [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 | |
Davide Pesavento | cb065f1 | 2019-12-27 01:03:34 -0500 | [diff] [blame] | 27 | #include "tests/boost-test.hpp" |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 28 | |
Davide Pesavento | cb065f1 | 2019-12-27 01:03:34 -0500 | [diff] [blame] | 29 | #include <ndn-cxx/util/dummy-client-face.hpp> |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 30 | |
| 31 | namespace nlsr { |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 32 | namespace test { |
| 33 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 34 | BOOST_AUTO_TEST_SUITE(TestAdjacencyList) |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 35 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 36 | BOOST_AUTO_TEST_CASE(Basic) |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 37 | { |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 38 | const std::string ADJ_NAME_1 = "testname"; |
| 39 | const std::string ADJ_NAME_2 = "testname2"; |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 40 | |
| 41 | //adjacent needed to test adjacency list. |
| 42 | Adjacent adjacent1(ADJ_NAME_1); |
| 43 | Adjacent adjacent2(ADJ_NAME_2); |
| 44 | |
| 45 | adjacent1.setLinkCost(4); |
| 46 | adjacent2.setLinkCost(5); |
| 47 | |
| 48 | AdjacencyList adjacentList1; |
| 49 | AdjacencyList adjacentList2; |
| 50 | |
| 51 | adjacentList1.insert(adjacent1); |
| 52 | adjacentList2.insert(adjacent2); |
| 53 | |
Nick Gordon | ff9a627 | 2017-10-12 13:38:29 -0500 | [diff] [blame] | 54 | BOOST_CHECK_EQUAL(adjacentList1.size(), (uint32_t)1); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 55 | BOOST_CHECK_EQUAL(adjacentList1 == adjacentList2, false); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 56 | |
| 57 | BOOST_CHECK(adjacentList1.isNeighbor("testname")); |
| 58 | BOOST_CHECK_EQUAL(adjacentList1.isNeighbor("adjacent"), false); |
| 59 | |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 60 | std::string n1 = "testname"; |
Vince Lehman | cb76ade | 2014-08-28 21:24:41 -0500 | [diff] [blame] | 61 | BOOST_CHECK_EQUAL(adjacentList1.getStatusOfNeighbor(n1), Adjacent::STATUS_INACTIVE); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 62 | |
Vince Lehman | cb76ade | 2014-08-28 21:24:41 -0500 | [diff] [blame] | 63 | adjacentList1.setStatusOfNeighbor(n1, Adjacent::STATUS_ACTIVE); |
| 64 | BOOST_CHECK_EQUAL(adjacentList1.getStatusOfNeighbor(n1), Adjacent::STATUS_ACTIVE); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 65 | } |
| 66 | |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 67 | BOOST_AUTO_TEST_CASE(FindAdjacentByFaceUri) |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 68 | { |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 69 | ndn::FaceUri faceUri("udp4://10.0.0.1:6363"); |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 70 | Adjacent adj1("/ndn/test/1", faceUri, 10, Adjacent::STATUS_INACTIVE, 0, 0); |
| 71 | AdjacencyList adjList; |
| 72 | adjList.insert(adj1); |
| 73 | |
| 74 | std::list<Adjacent>::iterator adjIter = adjList.findAdjacent(faceUri); |
| 75 | BOOST_CHECK(adjIter != adjList.end()); |
| 76 | } |
| 77 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 78 | BOOST_AUTO_TEST_CASE(AdjLsaIsBuildableWithOneNodeActive) |
| 79 | { |
| 80 | Adjacent adjacencyA("/router/A"); |
| 81 | Adjacent adjacencyB("/router/B"); |
| 82 | |
| 83 | adjacencyA.setStatus(Adjacent::STATUS_ACTIVE); |
| 84 | adjacencyB.setStatus(Adjacent::STATUS_INACTIVE); |
| 85 | |
| 86 | AdjacencyList adjacencies; |
| 87 | adjacencies.insert(adjacencyA); |
| 88 | adjacencies.insert(adjacencyB); |
| 89 | |
Junxiao Shi | 43f37a0 | 2023-08-09 00:09:00 +0000 | [diff] [blame^] | 90 | ndn::DummyClientFace face; |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 91 | ndn::KeyChain keyChain; |
| 92 | ConfParameter conf(face, keyChain); |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 93 | BOOST_CHECK(adjacencies.isAdjLsaBuildable(conf.getInterestRetryNumber())); |
| 94 | } |
| 95 | |
| 96 | BOOST_AUTO_TEST_CASE(AdjLsaIsBuildableWithAllNodesTimedOut) |
| 97 | { |
| 98 | Adjacent adjacencyA("/router/A"); |
| 99 | Adjacent adjacencyB("/router/B"); |
| 100 | |
| 101 | adjacencyA.setStatus(Adjacent::STATUS_INACTIVE); |
| 102 | adjacencyB.setStatus(Adjacent::STATUS_INACTIVE); |
| 103 | |
| 104 | adjacencyA.setInterestTimedOutNo(HELLO_RETRIES_DEFAULT); |
| 105 | adjacencyB.setInterestTimedOutNo(HELLO_RETRIES_DEFAULT); |
| 106 | |
| 107 | AdjacencyList adjacencies; |
| 108 | adjacencies.insert(adjacencyA); |
| 109 | adjacencies.insert(adjacencyB); |
| 110 | |
Junxiao Shi | 43f37a0 | 2023-08-09 00:09:00 +0000 | [diff] [blame^] | 111 | ndn::DummyClientFace face; |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 112 | ndn::KeyChain keyChain; |
| 113 | ConfParameter conf(face, keyChain); |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 114 | conf.setInterestRetryNumber(HELLO_RETRIES_DEFAULT); |
| 115 | |
| 116 | BOOST_CHECK(adjacencies.isAdjLsaBuildable(conf.getInterestRetryNumber())); |
| 117 | } |
| 118 | |
| 119 | BOOST_AUTO_TEST_CASE(AdjLsaIsNotBuildable) |
| 120 | { |
| 121 | Adjacent adjacencyA("/router/A"); |
| 122 | Adjacent adjacencyB("/router/B"); |
| 123 | |
| 124 | adjacencyA.setStatus(Adjacent::STATUS_INACTIVE); |
| 125 | adjacencyB.setStatus(Adjacent::STATUS_INACTIVE); |
| 126 | |
| 127 | adjacencyA.setInterestTimedOutNo(HELLO_RETRIES_DEFAULT); |
| 128 | adjacencyB.setInterestTimedOutNo(0); |
| 129 | |
| 130 | AdjacencyList adjacencies; |
| 131 | adjacencies.insert(adjacencyA); |
| 132 | adjacencies.insert(adjacencyB); |
| 133 | |
Junxiao Shi | 43f37a0 | 2023-08-09 00:09:00 +0000 | [diff] [blame^] | 134 | ndn::DummyClientFace face; |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 135 | ndn::KeyChain keyChain; |
| 136 | ConfParameter conf(face, keyChain); |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 137 | conf.setInterestRetryNumber(HELLO_RETRIES_DEFAULT); |
| 138 | |
| 139 | BOOST_CHECK(!adjacencies.isAdjLsaBuildable(conf.getInterestRetryNumber())); |
| 140 | } |
| 141 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 142 | BOOST_AUTO_TEST_SUITE_END() |
| 143 | |
Nick Gordon | e9733ed | 2017-04-26 10:48:39 -0500 | [diff] [blame] | 144 | } // namespace test |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame] | 145 | } // namespace nlsr |