akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 2 | /* |
Davide Pesavento | e28d875 | 2022-03-19 03:55:25 -0400 | [diff] [blame^] | 3 | * Copyright (c) 2014-2022, The University of Memphis, |
Nick Gordon | f8b5bcd | 2016-08-11 15:06:50 -0500 | [diff] [blame] | 4 | * Regents of the University of California |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 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/>. |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 19 | */ |
Davide Pesavento | cb065f1 | 2019-12-27 01:03:34 -0500 | [diff] [blame] | 20 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 21 | #include "route/routing-table-entry.hpp" |
Davide Pesavento | cb065f1 | 2019-12-27 01:03:34 -0500 | [diff] [blame] | 22 | #include "tests/boost-test.hpp" |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 23 | |
| 24 | namespace nlsr { |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 25 | namespace test { |
| 26 | |
| 27 | BOOST_AUTO_TEST_SUITE(TestRoutingTableEntry) |
| 28 | |
| 29 | BOOST_AUTO_TEST_CASE(RoutingTableEntryDestination) |
| 30 | { |
| 31 | RoutingTableEntry rte1("router1"); |
| 32 | |
| 33 | BOOST_CHECK_EQUAL(rte1.getDestination(), "router1"); |
| 34 | } |
| 35 | |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 36 | const uint8_t RoutingTableEntryWithNexthopsData[] = |
| 37 | { |
| 38 | // Header |
| 39 | 0x91, 0x35, |
| 40 | // Destination Name |
| 41 | 0x07, 0x07, 0x08, 0x05, 0x64, 0x65, 0x73, 0x74, 0x31, 0x8f, 0x14, |
| 42 | // Nexthop |
| 43 | 0x8d, 0x08, 0x6e, 0x65, 0x78, 0x74, 0x68, 0x6f, 0x70, 0x31, 0x86, 0x08, 0x3f, 0xfa, |
| 44 | 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x8f, 0x14, 0x8d, 0x08, |
| 45 | // Nexthop |
| 46 | 0x6e, 0x65, 0x78, 0x74, 0x68, 0x6f, 0x70, 0x32, 0x86, 0x08, 0x3f, 0xfa, 0x66, 0x66, |
| 47 | 0x66, 0x66, 0x66, 0x66 |
| 48 | }; |
| 49 | |
| 50 | const uint8_t RoutingTableEntryWithoutNexthopsData[] = |
| 51 | { |
| 52 | // Header |
| 53 | 0x91, 0x09, |
| 54 | // Destination Name |
| 55 | 0x07, 0x07, 0x08, 0x05, 0x64, 0x65, 0x73, 0x74, 0x31 |
| 56 | }; |
| 57 | |
| 58 | BOOST_AUTO_TEST_CASE(RoutingTableEntryEncodeWithNexthops) |
| 59 | { |
| 60 | RoutingTableEntry rte(ndn::Name("dest1")); |
| 61 | |
| 62 | NextHop nexthops1; |
| 63 | nexthops1.setConnectingFaceUri("nexthop1"); |
| 64 | nexthops1.setRouteCost(1.65); |
| 65 | rte.getNexthopList().addNextHop(nexthops1); |
| 66 | |
| 67 | NextHop nexthops2; |
| 68 | nexthops2.setConnectingFaceUri("nexthop2"); |
| 69 | nexthops2.setRouteCost(1.65); |
| 70 | rte.getNexthopList().addNextHop(nexthops2); |
| 71 | |
Davide Pesavento | e28d875 | 2022-03-19 03:55:25 -0400 | [diff] [blame^] | 72 | BOOST_TEST(rte.wireEncode() == RoutingTableEntryWithNexthopsData, |
| 73 | boost::test_tools::per_element()); |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | BOOST_AUTO_TEST_CASE(RoutingTableEntryDecodeWithNexthops) |
| 77 | { |
Davide Pesavento | e28d875 | 2022-03-19 03:55:25 -0400 | [diff] [blame^] | 78 | RoutingTableEntry rte(ndn::Block{RoutingTableEntryWithNexthopsData}); |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 79 | BOOST_CHECK_EQUAL(rte.getDestination(), "dest1"); |
| 80 | |
| 81 | BOOST_CHECK(rte.getNexthopList().size() != 0); |
| 82 | auto it = rte.getNexthopList().begin(); |
| 83 | BOOST_CHECK_EQUAL(it->getConnectingFaceUri(), "nexthop1"); |
| 84 | BOOST_CHECK_EQUAL(it->getRouteCost(), 1.65); |
| 85 | |
| 86 | it++; |
| 87 | BOOST_CHECK_EQUAL(it->getConnectingFaceUri(), "nexthop2"); |
| 88 | BOOST_CHECK_EQUAL(it->getRouteCost(), 1.65); |
| 89 | } |
| 90 | |
| 91 | BOOST_AUTO_TEST_CASE(RoutingTableEntryEncodeWithoutNexthops) |
| 92 | { |
| 93 | RoutingTableEntry rte(ndn::Name("dest1")); |
Davide Pesavento | e28d875 | 2022-03-19 03:55:25 -0400 | [diff] [blame^] | 94 | BOOST_TEST(rte.wireEncode() == RoutingTableEntryWithoutNexthopsData, |
| 95 | boost::test_tools::per_element()); |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | BOOST_AUTO_TEST_CASE(RoutingTableEntryDecodeWithoutNexthops) |
| 99 | { |
Davide Pesavento | e28d875 | 2022-03-19 03:55:25 -0400 | [diff] [blame^] | 100 | RoutingTableEntry rte(ndn::Block{RoutingTableEntryWithoutNexthopsData}); |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 101 | BOOST_CHECK_EQUAL(rte.getDestination(), "dest1"); |
Davide Pesavento | e28d875 | 2022-03-19 03:55:25 -0400 | [diff] [blame^] | 102 | BOOST_CHECK_EQUAL(rte.getNexthopList().size(), 0); |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 105 | BOOST_AUTO_TEST_CASE(RoutingTableEntryClear) |
| 106 | { |
| 107 | RoutingTableEntry rte(ndn::Name("dest1")); |
| 108 | |
| 109 | NextHop nexthops1; |
| 110 | nexthops1.setConnectingFaceUri("nexthop1"); |
| 111 | nexthops1.setRouteCost(99); |
| 112 | rte.getNexthopList().addNextHop(nexthops1); |
| 113 | |
| 114 | BOOST_CHECK_EQUAL(rte.getNexthopList().size(), 1); |
| 115 | |
| 116 | auto it = rte.getNexthopList().begin(); |
| 117 | BOOST_CHECK_EQUAL(it->getConnectingFaceUri(), "nexthop1"); |
| 118 | BOOST_CHECK_EQUAL(it->getRouteCost(), 99); |
| 119 | |
| 120 | rte.getNexthopList().clear(); |
| 121 | BOOST_CHECK_EQUAL(rte.getNexthopList().size(), 0); |
| 122 | |
| 123 | NextHop nexthops2; |
| 124 | nexthops2.setConnectingFaceUri("nexthop2"); |
| 125 | nexthops2.setRouteCost(99); |
| 126 | rte.getNexthopList().addNextHop(nexthops2); |
| 127 | |
| 128 | BOOST_CHECK_EQUAL(rte.getNexthopList().size(), 1); |
| 129 | it = rte.getNexthopList().begin(); |
| 130 | BOOST_CHECK_EQUAL(it->getConnectingFaceUri(), "nexthop2"); |
| 131 | BOOST_CHECK_EQUAL(it->getRouteCost(), 99); |
| 132 | } |
| 133 | |
| 134 | BOOST_AUTO_TEST_CASE(RoutingTableEntryOutputStream) |
| 135 | { |
| 136 | RoutingTableEntry rte(ndn::Name("dest1")); |
| 137 | |
| 138 | NextHop nexthops1; |
| 139 | nexthops1.setConnectingFaceUri("nexthop1"); |
| 140 | nexthops1.setRouteCost(99); |
| 141 | rte.getNexthopList().addNextHop(nexthops1); |
| 142 | |
| 143 | std::ostringstream os; |
| 144 | os << rte; |
| 145 | |
| 146 | BOOST_CHECK_EQUAL(os.str(), |
| 147 | " Destination: /dest1\n" |
| 148 | " NextHop(Uri: nexthop1, Cost: 99)\n"); |
| 149 | } |
| 150 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 151 | BOOST_AUTO_TEST_SUITE_END() |
| 152 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 153 | } // namespace test |
| 154 | } // namespace nlsr |