Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 6593a43 | 2023-08-21 10:50:28 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | 288141a | 2024-02-13 17:30:35 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2024, The University of Memphis, |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 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 Nicholas Gordon <nmgordon@memphis.edu> |
Davide Pesavento | 288141a | 2024-02-13 17:30:35 -0500 | [diff] [blame] | 21 | */ |
Davide Pesavento | cb065f1 | 2019-12-27 01:03:34 -0500 | [diff] [blame] | 22 | |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 23 | #include "route/routing-table-pool-entry.hpp" |
| 24 | #include "route/nexthop.hpp" |
| 25 | #include "route/nexthop-list.hpp" |
| 26 | |
Davide Pesavento | cb065f1 | 2019-12-27 01:03:34 -0500 | [diff] [blame] | 27 | #include "tests/boost-test.hpp" |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 28 | |
Davide Pesavento | 288141a | 2024-02-13 17:30:35 -0500 | [diff] [blame] | 29 | namespace nlsr::tests { |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 30 | |
| 31 | BOOST_AUTO_TEST_SUITE(TestRoutingTablePoolEntry) |
| 32 | |
| 33 | BOOST_AUTO_TEST_CASE(EqualsOperator) |
| 34 | { |
| 35 | NextHop hop1; |
| 36 | hop1.setRouteCost(25); |
Junxiao Shi | 6593a43 | 2023-08-21 10:50:28 +0000 | [diff] [blame] | 37 | hop1.setConnectingFaceUri(ndn::FaceUri("udp4://192.168.3.1:6363")); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 38 | |
| 39 | NextHop hop2; |
| 40 | hop2.setRouteCost(10); |
Junxiao Shi | 6593a43 | 2023-08-21 10:50:28 +0000 | [diff] [blame] | 41 | hop2.setConnectingFaceUri(ndn::FaceUri("udp4://192.168.3.2:6363")); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 42 | |
| 43 | NexthopList nhl1; |
| 44 | NexthopList nhl2; |
| 45 | |
| 46 | nhl1.addNextHop(hop1); |
| 47 | nhl1.addNextHop(hop2); |
| 48 | |
| 49 | RoutingTablePoolEntry rtpe1("/memphis/ndn/rtr1", 0); |
| 50 | RoutingTablePoolEntry rtpe2("/memphis/ndn/rtr1", 0); |
| 51 | |
| 52 | rtpe1.setNexthopList(nhl1); |
| 53 | rtpe2.setNexthopList(nhl1); |
| 54 | |
| 55 | BOOST_CHECK_EQUAL(rtpe1, rtpe2); |
| 56 | } |
| 57 | |
| 58 | BOOST_AUTO_TEST_CASE(IncrementEntryUseCount) |
| 59 | { |
| 60 | RoutingTablePoolEntry rtpe1("router1"); |
| 61 | |
| 62 | rtpe1.incrementUseCount(); |
| 63 | |
| 64 | BOOST_CHECK_EQUAL(rtpe1.getUseCount(), 2); |
| 65 | } |
| 66 | |
| 67 | BOOST_AUTO_TEST_CASE(DecrementEntryUseCountNotZero) |
| 68 | { |
| 69 | RoutingTablePoolEntry rtpe1("router1"); |
| 70 | |
| 71 | rtpe1.decrementUseCount(); |
| 72 | |
| 73 | BOOST_CHECK_EQUAL(rtpe1.getUseCount(), 0); |
| 74 | } |
| 75 | |
| 76 | BOOST_AUTO_TEST_CASE(DecrementEntryUseCountAtZero) |
| 77 | { |
| 78 | RoutingTablePoolEntry rtpe1("router1"); |
| 79 | |
| 80 | rtpe1.decrementUseCount(); |
| 81 | rtpe1.decrementUseCount(); |
| 82 | |
| 83 | BOOST_CHECK_EQUAL(rtpe1.getUseCount(), 0); |
| 84 | } |
| 85 | |
| 86 | BOOST_AUTO_TEST_CASE(UpdateNextHopList) |
| 87 | { |
| 88 | RoutingTablePoolEntry rtpe1("router1"); |
| 89 | NextHop nh1; |
| 90 | NexthopList nhl1; |
| 91 | |
| 92 | nhl1.addNextHop(nh1); |
| 93 | |
| 94 | rtpe1.setNexthopList(nhl1); |
| 95 | |
| 96 | BOOST_CHECK_EQUAL(rtpe1.getNexthopList(), nhl1); |
| 97 | } |
| 98 | |
| 99 | BOOST_AUTO_TEST_SUITE_END() |
| 100 | |
Davide Pesavento | 288141a | 2024-02-13 17:30:35 -0500 | [diff] [blame] | 101 | } // namespace nlsr::tests |