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 | /* |
Junxiao Shi | 6593a43 | 2023-08-21 10:50:28 +0000 | [diff] [blame^] | 3 | * Copyright (c) 2014-2023, 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 | |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 29 | BOOST_AUTO_TEST_CASE(Destination) |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 30 | { |
| 31 | RoutingTableEntry rte1("router1"); |
| 32 | |
| 33 | BOOST_CHECK_EQUAL(rte1.getDestination(), "router1"); |
| 34 | } |
| 35 | |
Junxiao Shi | 6593a43 | 2023-08-21 10:50:28 +0000 | [diff] [blame^] | 36 | static const ndn::FaceUri NEXTHOP1("udp4://192.168.3.1:6363"); |
| 37 | static const ndn::FaceUri NEXTHOP2("udp4://192.168.3.2:6363"); |
| 38 | |
| 39 | static const uint8_t RoutingTableEntryWithNexthopsData[] = { |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 40 | // Header |
Junxiao Shi | 6593a43 | 2023-08-21 10:50:28 +0000 | [diff] [blame^] | 41 | 0x91, 0x53, |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 42 | // Destination Name |
Junxiao Shi | 6593a43 | 2023-08-21 10:50:28 +0000 | [diff] [blame^] | 43 | 0x07, 0x07, 0x08, 0x05, 0x64, 0x65, 0x73, 0x74, 0x31, |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 44 | // Nexthop |
Junxiao Shi | 6593a43 | 2023-08-21 10:50:28 +0000 | [diff] [blame^] | 45 | 0x8f, 0x23, |
| 46 | // Nexthop.Uri |
| 47 | 0x8d, 0x17, 0x75, 0x64, 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x31, 0x36, 0x38, |
| 48 | 0x2e, 0x33, 0x2e, 0x31, 0x3a, 0x36, 0x33, 0x36, 0x33, |
| 49 | // Nexthop.CostDouble |
| 50 | 0x86, 0x08, 0x3f, 0xfa, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 51 | // Nexthop |
Junxiao Shi | 6593a43 | 2023-08-21 10:50:28 +0000 | [diff] [blame^] | 52 | 0x8f, 0x23, |
| 53 | // Nexthop.Uri |
| 54 | 0x8d, 0x17, 0x75, 0x64, 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x31, 0x36, 0x38, |
| 55 | 0x2e, 0x33, 0x2e, 0x32, 0x3a, 0x36, 0x33, 0x36, 0x33, |
| 56 | // Nexthop.CostDouble |
| 57 | 0x86, 0x08, 0x3f, 0xfa, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 58 | }; |
| 59 | |
Junxiao Shi | 6593a43 | 2023-08-21 10:50:28 +0000 | [diff] [blame^] | 60 | static const uint8_t RoutingTableEntryWithoutNexthopsData[] = { |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 61 | // Header |
| 62 | 0x91, 0x09, |
| 63 | // Destination Name |
| 64 | 0x07, 0x07, 0x08, 0x05, 0x64, 0x65, 0x73, 0x74, 0x31 |
| 65 | }; |
| 66 | |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 67 | BOOST_AUTO_TEST_CASE(EncodeWithNexthops) |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 68 | { |
| 69 | RoutingTableEntry rte(ndn::Name("dest1")); |
| 70 | |
| 71 | NextHop nexthops1; |
Junxiao Shi | 6593a43 | 2023-08-21 10:50:28 +0000 | [diff] [blame^] | 72 | nexthops1.setConnectingFaceUri(NEXTHOP1); |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 73 | nexthops1.setRouteCost(1.65); |
| 74 | rte.getNexthopList().addNextHop(nexthops1); |
| 75 | |
| 76 | NextHop nexthops2; |
Junxiao Shi | 6593a43 | 2023-08-21 10:50:28 +0000 | [diff] [blame^] | 77 | nexthops2.setConnectingFaceUri(NEXTHOP2); |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 78 | nexthops2.setRouteCost(1.65); |
| 79 | rte.getNexthopList().addNextHop(nexthops2); |
| 80 | |
Davide Pesavento | e28d875 | 2022-03-19 03:55:25 -0400 | [diff] [blame] | 81 | BOOST_TEST(rte.wireEncode() == RoutingTableEntryWithNexthopsData, |
| 82 | boost::test_tools::per_element()); |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 85 | BOOST_AUTO_TEST_CASE(DecodeWithNexthops) |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 86 | { |
Davide Pesavento | e28d875 | 2022-03-19 03:55:25 -0400 | [diff] [blame] | 87 | RoutingTableEntry rte(ndn::Block{RoutingTableEntryWithNexthopsData}); |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 88 | BOOST_CHECK_EQUAL(rte.getDestination(), "dest1"); |
| 89 | |
| 90 | BOOST_CHECK(rte.getNexthopList().size() != 0); |
| 91 | auto it = rte.getNexthopList().begin(); |
Junxiao Shi | 6593a43 | 2023-08-21 10:50:28 +0000 | [diff] [blame^] | 92 | BOOST_CHECK_EQUAL(it->getConnectingFaceUri(), NEXTHOP1); |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 93 | BOOST_CHECK_EQUAL(it->getRouteCost(), 1.65); |
| 94 | |
| 95 | it++; |
Junxiao Shi | 6593a43 | 2023-08-21 10:50:28 +0000 | [diff] [blame^] | 96 | BOOST_CHECK_EQUAL(it->getConnectingFaceUri(), NEXTHOP2); |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 97 | BOOST_CHECK_EQUAL(it->getRouteCost(), 1.65); |
| 98 | } |
| 99 | |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 100 | BOOST_AUTO_TEST_CASE(EncodeWithoutNexthops) |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 101 | { |
| 102 | RoutingTableEntry rte(ndn::Name("dest1")); |
Davide Pesavento | e28d875 | 2022-03-19 03:55:25 -0400 | [diff] [blame] | 103 | BOOST_TEST(rte.wireEncode() == RoutingTableEntryWithoutNexthopsData, |
| 104 | boost::test_tools::per_element()); |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 107 | BOOST_AUTO_TEST_CASE(DecodeWithoutNexthops) |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 108 | { |
Davide Pesavento | e28d875 | 2022-03-19 03:55:25 -0400 | [diff] [blame] | 109 | RoutingTableEntry rte(ndn::Block{RoutingTableEntryWithoutNexthopsData}); |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 110 | BOOST_CHECK_EQUAL(rte.getDestination(), "dest1"); |
Davide Pesavento | e28d875 | 2022-03-19 03:55:25 -0400 | [diff] [blame] | 111 | BOOST_CHECK_EQUAL(rte.getNexthopList().size(), 0); |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 114 | BOOST_AUTO_TEST_CASE(Clear) |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 115 | { |
| 116 | RoutingTableEntry rte(ndn::Name("dest1")); |
| 117 | |
| 118 | NextHop nexthops1; |
Junxiao Shi | 6593a43 | 2023-08-21 10:50:28 +0000 | [diff] [blame^] | 119 | nexthops1.setConnectingFaceUri(NEXTHOP1); |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 120 | nexthops1.setRouteCost(99); |
| 121 | rte.getNexthopList().addNextHop(nexthops1); |
| 122 | |
| 123 | BOOST_CHECK_EQUAL(rte.getNexthopList().size(), 1); |
| 124 | |
| 125 | auto it = rte.getNexthopList().begin(); |
Junxiao Shi | 6593a43 | 2023-08-21 10:50:28 +0000 | [diff] [blame^] | 126 | BOOST_CHECK_EQUAL(it->getConnectingFaceUri(), NEXTHOP1); |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 127 | BOOST_CHECK_EQUAL(it->getRouteCost(), 99); |
| 128 | |
| 129 | rte.getNexthopList().clear(); |
| 130 | BOOST_CHECK_EQUAL(rte.getNexthopList().size(), 0); |
| 131 | |
| 132 | NextHop nexthops2; |
Junxiao Shi | 6593a43 | 2023-08-21 10:50:28 +0000 | [diff] [blame^] | 133 | nexthops2.setConnectingFaceUri(NEXTHOP2); |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 134 | nexthops2.setRouteCost(99); |
| 135 | rte.getNexthopList().addNextHop(nexthops2); |
| 136 | |
| 137 | BOOST_CHECK_EQUAL(rte.getNexthopList().size(), 1); |
| 138 | it = rte.getNexthopList().begin(); |
Junxiao Shi | 6593a43 | 2023-08-21 10:50:28 +0000 | [diff] [blame^] | 139 | BOOST_CHECK_EQUAL(it->getConnectingFaceUri(), NEXTHOP2); |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 140 | BOOST_CHECK_EQUAL(it->getRouteCost(), 99); |
| 141 | } |
| 142 | |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 143 | BOOST_AUTO_TEST_CASE(OutputStream) |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 144 | { |
| 145 | RoutingTableEntry rte(ndn::Name("dest1")); |
Junxiao Shi | 6593a43 | 2023-08-21 10:50:28 +0000 | [diff] [blame^] | 146 | rte.getNexthopList().addNextHop({NEXTHOP1, 99}); |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 147 | |
| 148 | std::ostringstream os; |
| 149 | os << rte; |
| 150 | |
| 151 | BOOST_CHECK_EQUAL(os.str(), |
| 152 | " Destination: /dest1\n" |
Junxiao Shi | 6593a43 | 2023-08-21 10:50:28 +0000 | [diff] [blame^] | 153 | " NextHop(Uri: udp4://192.168.3.1:6363, Cost: 99)\n"); |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 154 | } |
| 155 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 156 | BOOST_AUTO_TEST_SUITE_END() |
| 157 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 158 | } // namespace test |
| 159 | } // namespace nlsr |