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 | /* |
| 3 | * Copyright (c) 2014-2023, 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> |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -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 | |
| 29 | namespace nlsr { |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 30 | namespace test { |
| 31 | |
| 32 | BOOST_AUTO_TEST_SUITE(TestRoutingTablePoolEntry) |
| 33 | |
| 34 | BOOST_AUTO_TEST_CASE(EqualsOperator) |
| 35 | { |
| 36 | NextHop hop1; |
| 37 | hop1.setRouteCost(25); |
Junxiao Shi | 6593a43 | 2023-08-21 10:50:28 +0000 | [diff] [blame^] | 38 | hop1.setConnectingFaceUri(ndn::FaceUri("udp4://192.168.3.1:6363")); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 39 | |
| 40 | NextHop hop2; |
| 41 | hop2.setRouteCost(10); |
Junxiao Shi | 6593a43 | 2023-08-21 10:50:28 +0000 | [diff] [blame^] | 42 | hop2.setConnectingFaceUri(ndn::FaceUri("udp4://192.168.3.2:6363")); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 43 | |
| 44 | NexthopList nhl1; |
| 45 | NexthopList nhl2; |
| 46 | |
| 47 | nhl1.addNextHop(hop1); |
| 48 | nhl1.addNextHop(hop2); |
| 49 | |
| 50 | RoutingTablePoolEntry rtpe1("/memphis/ndn/rtr1", 0); |
| 51 | RoutingTablePoolEntry rtpe2("/memphis/ndn/rtr1", 0); |
| 52 | |
| 53 | rtpe1.setNexthopList(nhl1); |
| 54 | rtpe2.setNexthopList(nhl1); |
| 55 | |
| 56 | BOOST_CHECK_EQUAL(rtpe1, rtpe2); |
| 57 | } |
| 58 | |
| 59 | BOOST_AUTO_TEST_CASE(IncrementEntryUseCount) |
| 60 | { |
| 61 | RoutingTablePoolEntry rtpe1("router1"); |
| 62 | |
| 63 | rtpe1.incrementUseCount(); |
| 64 | |
| 65 | BOOST_CHECK_EQUAL(rtpe1.getUseCount(), 2); |
| 66 | } |
| 67 | |
| 68 | BOOST_AUTO_TEST_CASE(DecrementEntryUseCountNotZero) |
| 69 | { |
| 70 | RoutingTablePoolEntry rtpe1("router1"); |
| 71 | |
| 72 | rtpe1.decrementUseCount(); |
| 73 | |
| 74 | BOOST_CHECK_EQUAL(rtpe1.getUseCount(), 0); |
| 75 | } |
| 76 | |
| 77 | BOOST_AUTO_TEST_CASE(DecrementEntryUseCountAtZero) |
| 78 | { |
| 79 | RoutingTablePoolEntry rtpe1("router1"); |
| 80 | |
| 81 | rtpe1.decrementUseCount(); |
| 82 | rtpe1.decrementUseCount(); |
| 83 | |
| 84 | BOOST_CHECK_EQUAL(rtpe1.getUseCount(), 0); |
| 85 | } |
| 86 | |
| 87 | BOOST_AUTO_TEST_CASE(UpdateNextHopList) |
| 88 | { |
| 89 | RoutingTablePoolEntry rtpe1("router1"); |
| 90 | NextHop nh1; |
| 91 | NexthopList nhl1; |
| 92 | |
| 93 | nhl1.addNextHop(nh1); |
| 94 | |
| 95 | rtpe1.setNexthopList(nhl1); |
| 96 | |
| 97 | BOOST_CHECK_EQUAL(rtpe1.getNexthopList(), nhl1); |
| 98 | } |
| 99 | |
| 100 | BOOST_AUTO_TEST_SUITE_END() |
| 101 | |
| 102 | } // namespace test |
| 103 | } // namespace nlsr |