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 | /** |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame^] | 3 | * Copyright (c) 2014-2015, The University of Memphis, |
| 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 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 22 | #include "adjacency-list.hpp" |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame^] | 23 | |
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 | |
| 32 | using namespace std; |
| 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 | { |
| 38 | const string ADJ_NAME_1 = "testname"; |
| 39 | const string ADJ_NAME_2 = "testname2"; |
| 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 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 54 | BOOST_CHECK_EQUAL(adjacentList1.getSize(), (uint32_t)1); |
| 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 | |
| 60 | 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 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame^] | 67 | BOOST_AUTO_TEST_CASE(AdjLsaIsBuildableWithOneNodeActive) |
| 68 | { |
| 69 | Adjacent adjacencyA("/router/A"); |
| 70 | Adjacent adjacencyB("/router/B"); |
| 71 | |
| 72 | adjacencyA.setStatus(Adjacent::STATUS_ACTIVE); |
| 73 | adjacencyB.setStatus(Adjacent::STATUS_INACTIVE); |
| 74 | |
| 75 | AdjacencyList adjacencies; |
| 76 | adjacencies.insert(adjacencyA); |
| 77 | adjacencies.insert(adjacencyB); |
| 78 | |
| 79 | ConfParameter conf; |
| 80 | BOOST_CHECK(adjacencies.isAdjLsaBuildable(conf.getInterestRetryNumber())); |
| 81 | } |
| 82 | |
| 83 | BOOST_AUTO_TEST_CASE(AdjLsaIsBuildableWithAllNodesTimedOut) |
| 84 | { |
| 85 | Adjacent adjacencyA("/router/A"); |
| 86 | Adjacent adjacencyB("/router/B"); |
| 87 | |
| 88 | adjacencyA.setStatus(Adjacent::STATUS_INACTIVE); |
| 89 | adjacencyB.setStatus(Adjacent::STATUS_INACTIVE); |
| 90 | |
| 91 | adjacencyA.setInterestTimedOutNo(HELLO_RETRIES_DEFAULT); |
| 92 | adjacencyB.setInterestTimedOutNo(HELLO_RETRIES_DEFAULT); |
| 93 | |
| 94 | AdjacencyList adjacencies; |
| 95 | adjacencies.insert(adjacencyA); |
| 96 | adjacencies.insert(adjacencyB); |
| 97 | |
| 98 | ConfParameter conf; |
| 99 | conf.setInterestRetryNumber(HELLO_RETRIES_DEFAULT); |
| 100 | |
| 101 | BOOST_CHECK(adjacencies.isAdjLsaBuildable(conf.getInterestRetryNumber())); |
| 102 | } |
| 103 | |
| 104 | BOOST_AUTO_TEST_CASE(AdjLsaIsNotBuildable) |
| 105 | { |
| 106 | Adjacent adjacencyA("/router/A"); |
| 107 | Adjacent adjacencyB("/router/B"); |
| 108 | |
| 109 | adjacencyA.setStatus(Adjacent::STATUS_INACTIVE); |
| 110 | adjacencyB.setStatus(Adjacent::STATUS_INACTIVE); |
| 111 | |
| 112 | adjacencyA.setInterestTimedOutNo(HELLO_RETRIES_DEFAULT); |
| 113 | adjacencyB.setInterestTimedOutNo(0); |
| 114 | |
| 115 | AdjacencyList adjacencies; |
| 116 | adjacencies.insert(adjacencyA); |
| 117 | adjacencies.insert(adjacencyB); |
| 118 | |
| 119 | ConfParameter conf; |
| 120 | conf.setInterestRetryNumber(HELLO_RETRIES_DEFAULT); |
| 121 | |
| 122 | BOOST_CHECK(!adjacencies.isAdjLsaBuildable(conf.getInterestRetryNumber())); |
| 123 | } |
| 124 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 125 | BOOST_AUTO_TEST_SUITE_END() |
| 126 | |
Vince Lehman | f7eec4f | 2015-05-08 19:02:31 -0500 | [diff] [blame^] | 127 | } // namespace tests |
| 128 | } // namespace nlsr |