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 | /* |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2020, 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 | */ |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 20 | |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 21 | #include "route/routing-table.hpp" |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 22 | #include "nlsr.hpp" |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 23 | #include "route/routing-table-entry.hpp" |
| 24 | #include "route/nexthop.hpp" |
Davide Pesavento | cb065f1 | 2019-12-27 01:03:34 -0500 | [diff] [blame] | 25 | |
| 26 | #include "tests/test-common.hpp" |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 27 | |
| 28 | namespace nlsr { |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 29 | namespace test { |
| 30 | |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 31 | class RoutingTableFixture |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 32 | { |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 33 | public: |
| 34 | RoutingTableFixture() |
| 35 | : conf(face, keyChain) |
| 36 | , nlsr(face, keyChain, conf) |
| 37 | , rt(nlsr.m_routingTable) |
| 38 | { |
| 39 | } |
| 40 | |
| 41 | public: |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 42 | ndn::util::DummyClientFace face; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 43 | ndn::KeyChain keyChain; |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 44 | ConfParameter conf; |
| 45 | Nlsr nlsr; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 46 | |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 47 | RoutingTable& rt; |
| 48 | }; |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 49 | |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 50 | BOOST_AUTO_TEST_SUITE(TestRoutingTable) |
| 51 | |
| 52 | BOOST_FIXTURE_TEST_CASE(RoutingTableAddNextHop, RoutingTableFixture) |
| 53 | { |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 54 | NextHop nh1; |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 55 | const std::string DEST_ROUTER = "destRouter"; |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 56 | rt.addNextHop(DEST_ROUTER, nh1); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 57 | |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 58 | BOOST_CHECK_EQUAL(rt.findRoutingTableEntry(DEST_ROUTER)->getDestination(), DEST_ROUTER); |
| 59 | } |
| 60 | |
| 61 | const uint8_t RoutingTableData1[] = |
| 62 | { |
| 63 | // Header |
| 64 | 0x90, 0x20, |
| 65 | // Routing table entry |
| 66 | 0x91, 0x1e, |
| 67 | // Destination |
| 68 | 0x07, 0x07, 0x08, 0x05, 0x64, 0x65, 0x73, 0x74, 0x31, 0x8f, 0x13, |
| 69 | // Nexthop |
| 70 | 0x8d, 0x07, 0x6e, 0x65, 0x78, 0x74, 0x68, 0x6f, 0x70, 0x86, 0x08, 0x3f, 0xfa, 0x66, |
| 71 | 0x66, 0x66, 0x66, 0x66, 0x66 |
| 72 | }; |
| 73 | |
| 74 | const uint8_t RoutingTableData2[] = |
| 75 | { |
| 76 | // Header |
| 77 | 0x90, 0x00 |
| 78 | }; |
| 79 | |
| 80 | BOOST_FIXTURE_TEST_CASE(RoutingTableEncode1, RoutingTableFixture) |
| 81 | { |
| 82 | NextHop nexthops; |
| 83 | nexthops.setConnectingFaceUri("nexthop"); |
| 84 | nexthops.setRouteCost(1.65); |
| 85 | rt.addNextHop("dest1", nexthops); |
| 86 | |
| 87 | auto wire = rt.wireEncode(); |
| 88 | BOOST_REQUIRE_EQUAL_COLLECTIONS(RoutingTableData1, |
| 89 | RoutingTableData1 + sizeof(RoutingTableData1), |
| 90 | wire.begin(), wire.end()); |
| 91 | } |
| 92 | |
| 93 | BOOST_FIXTURE_TEST_CASE(RoutingTableEncode2, RoutingTableFixture) |
| 94 | { |
| 95 | auto wire = rt.wireEncode(); |
| 96 | BOOST_REQUIRE_EQUAL_COLLECTIONS(RoutingTableData2, |
| 97 | RoutingTableData2 + sizeof(RoutingTableData2), |
| 98 | wire.begin(), wire.end()); |
| 99 | } |
| 100 | |
| 101 | BOOST_FIXTURE_TEST_CASE(RoutingTableDecode1, RoutingTableFixture) |
| 102 | { |
| 103 | RoutingTableStatus rtStatus(ndn::Block(RoutingTableData1, sizeof(RoutingTableData1))); |
| 104 | |
| 105 | auto it1 = rtStatus.m_rTable.begin(); |
| 106 | |
| 107 | ndn::Name des1 = it1->getDestination(); |
| 108 | BOOST_CHECK_EQUAL(des1, "dest1"); |
| 109 | |
| 110 | auto it2 = it1->getNexthopList().begin(); |
| 111 | BOOST_CHECK_EQUAL(it2->getConnectingFaceUri(), "nexthop"); |
| 112 | BOOST_CHECK_EQUAL(it2->getRouteCost(), 1.65); |
| 113 | |
| 114 | BOOST_CHECK_EQUAL(rtStatus.m_rTable.size(), 1); |
| 115 | } |
| 116 | |
| 117 | BOOST_FIXTURE_TEST_CASE(RoutingTableOutputStream, RoutingTableFixture) |
| 118 | { |
| 119 | NextHop nexthops; |
| 120 | nexthops.setConnectingFaceUri("nexthop"); |
| 121 | nexthops.setRouteCost(99); |
| 122 | rt.addNextHop("dest1", nexthops); |
| 123 | |
| 124 | std::ostringstream os; |
| 125 | os << rt; |
| 126 | |
| 127 | BOOST_CHECK_EQUAL(os.str(), |
| 128 | "Routing Table:\n" |
| 129 | " Destination: /dest1\n" |
| 130 | " NextHop(Uri: nexthop, Cost: 99)\n"); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | BOOST_AUTO_TEST_SUITE_END() |
| 134 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 135 | } // namespace test |
| 136 | } // namespace nlsr |