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 | /** |
Muktadir R Chowdhury | 800833b | 2016-07-29 13:43:59 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, The University of Memphis, |
Vince Lehman | cec3885 | 2015-03-31 13:21:38 -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 | cec3885 | 2015-03-31 13:21:38 -0500 | [diff] [blame] | 21 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 22 | #include "route/nexthop-list.hpp" |
| 23 | #include "route/nexthop.hpp" |
| 24 | #include <boost/test/unit_test.hpp> |
| 25 | |
| 26 | namespace nlsr { |
| 27 | |
| 28 | namespace test { |
| 29 | |
| 30 | BOOST_AUTO_TEST_SUITE(TestNhl) |
| 31 | |
| 32 | BOOST_AUTO_TEST_CASE(NhlAddNextHop) |
| 33 | { |
| 34 | NextHop np1; |
| 35 | |
| 36 | NexthopList nhl1; |
| 37 | |
| 38 | nhl1.addNextHop(np1); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 39 | BOOST_CHECK_EQUAL(nhl1.getSize(), (uint32_t)1); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 40 | |
| 41 | nhl1.removeNextHop(np1); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 42 | BOOST_CHECK_EQUAL(nhl1.getSize(), (uint32_t)0); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 43 | } |
| 44 | |
Vince Lehman | 20fe4a9 | 2014-09-09 15:57:59 -0500 | [diff] [blame] | 45 | BOOST_AUTO_TEST_CASE(LinkStateRemoveNextHop) |
Vince Lehman | 145064a | 2014-08-23 11:44:16 -0500 | [diff] [blame] | 46 | { |
| 47 | NextHop hop1; |
| 48 | hop1.setRouteCost(12.34); |
| 49 | |
| 50 | NexthopList hopList; |
| 51 | hopList.addNextHop(hop1); |
| 52 | |
| 53 | NextHop hop2; |
Vince Lehman | 20fe4a9 | 2014-09-09 15:57:59 -0500 | [diff] [blame] | 54 | hop2.setRouteCost(13.01); |
| 55 | |
| 56 | BOOST_REQUIRE_EQUAL(hopList.getSize(), 1); |
| 57 | |
| 58 | hopList.removeNextHop(hop2); |
| 59 | BOOST_CHECK_EQUAL(hopList.getSize(), 1); |
| 60 | |
| 61 | hopList.removeNextHop(hop1); |
| 62 | BOOST_CHECK_EQUAL(hopList.getSize(), 0); |
| 63 | } |
| 64 | |
| 65 | BOOST_AUTO_TEST_CASE(HyperbolicRemoveNextHop) |
| 66 | { |
| 67 | NextHop hop1; |
| 68 | hop1.setHyperbolic(true); |
| 69 | hop1.setRouteCost(12.34); |
| 70 | |
| 71 | NexthopList hopList; |
| 72 | hopList.addNextHop(hop1); |
| 73 | |
| 74 | NextHop hop2; |
| 75 | hop2.setHyperbolic(true); |
Vince Lehman | 145064a | 2014-08-23 11:44:16 -0500 | [diff] [blame] | 76 | hop2.setRouteCost(12.35); |
| 77 | |
| 78 | BOOST_REQUIRE_EQUAL(hopList.getSize(), 1); |
| 79 | |
| 80 | hopList.removeNextHop(hop2); |
| 81 | BOOST_CHECK_EQUAL(hopList.getSize(), 1); |
| 82 | |
| 83 | hopList.removeNextHop(hop1); |
| 84 | BOOST_CHECK_EQUAL(hopList.getSize(), 0); |
| 85 | } |
| 86 | |
Vince Lehman | cec3885 | 2015-03-31 13:21:38 -0500 | [diff] [blame] | 87 | BOOST_AUTO_TEST_CASE(TieBreaker) |
| 88 | { |
| 89 | NextHop hopA; |
| 90 | hopA.setRouteCost(25); |
| 91 | hopA.setConnectingFaceUri("AAA"); |
| 92 | |
| 93 | NextHop hopZ; |
| 94 | hopZ.setRouteCost(25); |
| 95 | hopZ.setConnectingFaceUri("ZZZ"); |
| 96 | |
| 97 | NexthopList list; |
| 98 | list.addNextHop(hopA); |
| 99 | list.addNextHop(hopZ); |
| 100 | |
| 101 | list.sort(); |
| 102 | |
| 103 | NexthopList::iterator it = list.begin(); |
| 104 | BOOST_CHECK_EQUAL(it->getConnectingFaceUri(), hopA.getConnectingFaceUri()); |
| 105 | |
| 106 | list.reset(); |
| 107 | |
| 108 | list.addNextHop(hopZ); |
| 109 | list.addNextHop(hopA); |
| 110 | |
| 111 | list.sort(); |
| 112 | |
| 113 | it = list.begin(); |
| 114 | BOOST_CHECK_EQUAL(it->getConnectingFaceUri(), hopA.getConnectingFaceUri()); |
| 115 | } |
| 116 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 117 | BOOST_AUTO_TEST_SUITE_END() |
| 118 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame^] | 119 | } // namespace test |
| 120 | } // namespace nlsr |