laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame^] | 3 | * Copyright (c) 2014-2020, The University of Memphis, |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 4 | * Regents of the University of California, |
| 5 | * Arizona Board of Regents. |
| 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/>. |
| 20 | **/ |
| 21 | |
| 22 | #include "tlv/routing-table-status.hpp" |
| 23 | |
Davide Pesavento | cb065f1 | 2019-12-27 01:03:34 -0500 | [diff] [blame] | 24 | #include "tests/boost-test.hpp" |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 25 | |
| 26 | namespace nlsr { |
| 27 | namespace tlv { |
| 28 | namespace test { |
| 29 | |
| 30 | BOOST_AUTO_TEST_SUITE(TlvTestRoutingTable) |
| 31 | |
| 32 | const uint8_t RoutingTableData1[] = |
| 33 | { |
| 34 | // Header |
Tianxing Ma | 9ea3639 | 2018-10-05 14:32:55 -0500 | [diff] [blame] | 35 | 0x90, 0x22, |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 36 | // Routing table entry |
Tianxing Ma | 9ea3639 | 2018-10-05 14:32:55 -0500 | [diff] [blame] | 37 | 0x91, 0x20, |
| 38 | // Destination |
| 39 | 0x8e, 0x09, 0x07, 0x07, 0x08, 0x05, 0x64, 0x65, 0x73, 0x74, 0x31, |
| 40 | // Nexthop |
| 41 | 0x8f, 0x13, 0x8d, 0x07, 0x6e, 0x65, 0x78, 0x74, 0x68, 0x6f, 0x70, 0x86, 0x08, 0x3f, |
| 42 | 0xfa, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66 |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | const uint8_t RoutingTableData2[] = |
| 46 | { |
| 47 | // Header |
| 48 | 0x90, 0x00 |
| 49 | }; |
| 50 | |
| 51 | BOOST_AUTO_TEST_CASE(RoutingTableEncode1) |
| 52 | { |
| 53 | RoutingTableStatus rtStatus; |
| 54 | |
| 55 | Destination des; |
| 56 | des.setName("dest1"); |
| 57 | |
| 58 | // RoutingtableEntry |
| 59 | RoutingTable rt; |
| 60 | rt.setDestination(des); |
| 61 | |
| 62 | NextHop nexthops; |
| 63 | nexthops.setUri("nexthop"); |
| 64 | nexthops.setCost(1.65); |
| 65 | rt.addNexthops(nexthops); |
| 66 | |
| 67 | rtStatus.addRoutingTable(rt); |
| 68 | |
| 69 | const ndn::Block& wire = rtStatus.wireEncode(); |
| 70 | |
| 71 | BOOST_REQUIRE_EQUAL_COLLECTIONS(RoutingTableData1, |
| 72 | RoutingTableData1 + sizeof(RoutingTableData1), |
| 73 | wire.begin(), wire.end()); |
| 74 | } |
| 75 | |
| 76 | BOOST_AUTO_TEST_CASE(RoutingTableEncode2) |
| 77 | { |
| 78 | RoutingTableStatus rtStatus; |
| 79 | |
| 80 | const ndn::Block& wire = rtStatus.wireEncode(); |
| 81 | |
| 82 | BOOST_REQUIRE_EQUAL_COLLECTIONS(RoutingTableData2, |
| 83 | RoutingTableData2 + sizeof(RoutingTableData2), |
| 84 | wire.begin(), wire.end()); |
| 85 | } |
| 86 | |
| 87 | BOOST_AUTO_TEST_CASE(RoutingTableDecode1) |
| 88 | { |
| 89 | RoutingTableStatus rtStatus; |
| 90 | |
| 91 | rtStatus.wireDecode(ndn::Block(RoutingTableData1, sizeof(RoutingTableData1))); |
| 92 | |
| 93 | std::list<RoutingTable> rte = rtStatus.getRoutingtable(); |
| 94 | std::list<RoutingTable>::const_iterator it1 = rte.begin(); |
| 95 | |
| 96 | Destination des1 = it1->getDestination(); |
| 97 | BOOST_CHECK_EQUAL(des1.getName(), "dest1"); |
| 98 | |
| 99 | std::list<NextHop> nexthops = it1->getNextHops(); |
| 100 | std::list<NextHop>::const_iterator it2 = nexthops.begin(); |
| 101 | BOOST_CHECK_EQUAL(it2->getUri(), "nexthop"); |
| 102 | BOOST_CHECK_EQUAL(it2->getCost(), 1.65); |
| 103 | |
| 104 | BOOST_CHECK_EQUAL(rtStatus.hasRoutingTable(), true); |
| 105 | } |
| 106 | |
| 107 | BOOST_AUTO_TEST_CASE(RoutingTableDecode2) |
| 108 | { |
| 109 | RoutingTableStatus rtStatus; |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 110 | rtStatus.wireDecode(ndn::Block(RoutingTableData2, sizeof(RoutingTableData2))); |
| 111 | |
| 112 | BOOST_CHECK_EQUAL(rtStatus.hasRoutingTable(), false); |
| 113 | } |
| 114 | |
| 115 | BOOST_AUTO_TEST_CASE(RoutingTableClear) |
| 116 | { |
| 117 | RoutingTableStatus rtStatus; |
| 118 | Destination des; |
| 119 | des.setName("dest1"); |
| 120 | |
| 121 | // RoutingtableEntry |
| 122 | RoutingTable rt; |
| 123 | rt.setDestination(des); |
| 124 | |
| 125 | NextHop nexthops; |
| 126 | nexthops.setUri("nexthop"); |
| 127 | nexthops.setCost(1.65); |
| 128 | rt.addNexthops(nexthops); |
| 129 | |
| 130 | rtStatus.addRoutingTable(rt); |
| 131 | |
| 132 | BOOST_CHECK_EQUAL(rtStatus.hasRoutingTable(), true); |
| 133 | rtStatus.clearRoutingTable(); |
| 134 | BOOST_CHECK_EQUAL(rtStatus.hasRoutingTable(), false); |
| 135 | } |
| 136 | |
| 137 | BOOST_AUTO_TEST_CASE(RoutingTableOutputStream) |
| 138 | { |
| 139 | RoutingTableStatus rtStatus; |
| 140 | Destination des; |
| 141 | des.setName("dest1"); |
| 142 | |
| 143 | // RoutingtableEntry |
| 144 | RoutingTable rt; |
| 145 | rt.setDestination(des); |
| 146 | |
| 147 | NextHop nexthops; |
| 148 | nexthops.setUri("nexthop"); |
| 149 | nexthops.setCost(99); |
| 150 | rt.addNexthops(nexthops); |
| 151 | |
| 152 | rtStatus.addRoutingTable(rt); |
| 153 | |
| 154 | std::ostringstream os; |
| 155 | os << rtStatus; |
| 156 | |
| 157 | BOOST_CHECK_EQUAL(os.str(), "Routing Table Status: \n" |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 158 | "Destination: /dest1\n" |
laqinfan | a073e2e | 2018-01-15 21:17:24 +0000 | [diff] [blame] | 159 | "NexthopList(\n" |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 160 | "NextHop(Uri: nexthop, Cost: 99)\n" |
laqinfan | a073e2e | 2018-01-15 21:17:24 +0000 | [diff] [blame] | 161 | ")"); |
laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | BOOST_AUTO_TEST_SUITE_END() |
| 165 | |
| 166 | } // namespace test |
| 167 | } // namespace tlv |
| 168 | } // namespace nlsr |