Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 87fc0f8 | 2018-04-11 23:43:51 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2022, Regents of the University of California, |
Alexander Afanasyev | 7c10b3b | 2015-01-20 12:24:27 -0800 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 24 | */ |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 25 | |
| 26 | #include "rib/rib.hpp" |
| 27 | |
| 28 | #include "tests/test-common.hpp" |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 29 | #include "tests/daemon/global-io-fixture.hpp" |
Davide Pesavento | 1b077f6 | 2019-02-19 19:19:44 -0500 | [diff] [blame] | 30 | #include "tests/daemon/rib/create-route.hpp" |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 31 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame^] | 32 | namespace nfd::tests { |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 33 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame^] | 34 | using rib::Route; |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 35 | |
| 36 | BOOST_FIXTURE_TEST_SUITE(TestRib, GlobalIoFixture) |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 37 | |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 38 | BOOST_AUTO_TEST_CASE(Parent) |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 39 | { |
| 40 | rib::Rib rib; |
| 41 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 42 | Name name1("/"); |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 43 | rib.insert(name1, createRoute(1, 20)); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 44 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 45 | Name name2("/hello"); |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 46 | rib.insert(name2, createRoute(2, 20)); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 47 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 48 | Name name3("/hello/world"); |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 49 | rib.insert(name3, createRoute(3, 20)); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 50 | |
| 51 | shared_ptr<rib::RibEntry> ribEntry = rib.findParent(name3); |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 52 | BOOST_REQUIRE(ribEntry != nullptr); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 53 | BOOST_CHECK_EQUAL(ribEntry->getRoutes().front().faceId, 2); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 54 | |
| 55 | ribEntry = rib.findParent(name2); |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 56 | BOOST_REQUIRE(ribEntry != nullptr); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 57 | BOOST_CHECK_EQUAL(ribEntry->getRoutes().front().faceId, 1); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 58 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 59 | Name name4("/hello/test/foo/bar"); |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 60 | rib.insert(name4, createRoute(3, 20)); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 61 | |
| 62 | ribEntry = rib.findParent(name4); |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 63 | BOOST_REQUIRE(ribEntry != nullptr); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 64 | BOOST_CHECK(ribEntry->getRoutes().front().faceId == 2); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 65 | } |
| 66 | |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 67 | BOOST_AUTO_TEST_CASE(Children) |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 68 | { |
| 69 | rib::Rib rib; |
| 70 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 71 | Name name1("/"); |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 72 | rib.insert(name1, createRoute(1, 20)); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 73 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 74 | Name name2("/hello/world"); |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 75 | rib.insert(name2, createRoute(2, 20)); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 76 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 77 | Name name3("/hello/test/foo/bar"); |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 78 | rib.insert(name3, createRoute(3, 20)); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 79 | |
| 80 | BOOST_CHECK_EQUAL((rib.find(name1)->second)->getChildren().size(), 2); |
| 81 | BOOST_CHECK_EQUAL((rib.find(name2)->second)->getChildren().size(), 0); |
| 82 | BOOST_CHECK_EQUAL((rib.find(name3)->second)->getChildren().size(), 0); |
| 83 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 84 | Name name4("/hello"); |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 85 | rib.insert(name4, createRoute(4, 20)); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 86 | |
| 87 | BOOST_CHECK_EQUAL((rib.find(name1)->second)->getChildren().size(), 1); |
| 88 | BOOST_CHECK_EQUAL((rib.find(name2)->second)->getChildren().size(), 0); |
| 89 | BOOST_CHECK_EQUAL((rib.find(name3)->second)->getChildren().size(), 0); |
| 90 | BOOST_CHECK_EQUAL((rib.find(name4)->second)->getChildren().size(), 2); |
| 91 | |
| 92 | BOOST_CHECK_EQUAL((rib.find(name1)->second)->getChildren().front()->getName(), "/hello"); |
| 93 | BOOST_CHECK_EQUAL((rib.find(name4)->second)->getParent()->getName(), "/"); |
| 94 | |
| 95 | BOOST_REQUIRE(static_cast<bool>((rib.find(name2)->second)->getParent())); |
| 96 | BOOST_CHECK_EQUAL((rib.find(name2)->second)->getParent()->getName(), name4); |
| 97 | BOOST_REQUIRE(static_cast<bool>((rib.find(name3)->second)->getParent())); |
| 98 | BOOST_CHECK_EQUAL((rib.find(name3)->second)->getParent()->getName(), name4); |
| 99 | } |
| 100 | |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 101 | BOOST_AUTO_TEST_CASE(EraseFace) |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 102 | { |
| 103 | rib::Rib rib; |
| 104 | |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 105 | Route route1 = createRoute(1, 20); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 106 | Name name1("/"); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 107 | rib.insert(name1, route1); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 108 | |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 109 | Route route2 = createRoute(2, 20); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 110 | Name name2("/hello/world"); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 111 | rib.insert(name2, route2); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 112 | |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 113 | Route route3 = createRoute(1, 20); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 114 | Name name3("/hello/world"); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 115 | rib.insert(name3, route3); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 116 | |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 117 | Route route4 = createRoute(1, 20); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 118 | Name name4("/not/inserted"); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 119 | |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 120 | rib.erase(name4, route4); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 121 | rib.erase(name1, route1); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 122 | |
| 123 | BOOST_CHECK(rib.find(name1) == rib.end()); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 124 | BOOST_CHECK_EQUAL((rib.find(name2)->second)->getRoutes().size(), 2); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 125 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 126 | rib.erase(name2, route2); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 127 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 128 | BOOST_CHECK_EQUAL((rib.find(name2)->second)->getRoutes().size(), 1); |
| 129 | BOOST_CHECK_EQUAL((rib.find(name2)->second)->getRoutes().front().faceId, 1); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 130 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 131 | rib.erase(name3, route3); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 132 | |
| 133 | BOOST_CHECK(rib.find(name2) == rib.end()); |
| 134 | |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 135 | rib.erase(name4, route4); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 136 | } |
| 137 | |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 138 | BOOST_AUTO_TEST_CASE(EraseRibEntry) |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 139 | { |
| 140 | rib::Rib rib; |
| 141 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 142 | Name name1("/"); |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 143 | rib.insert(name1, createRoute(1, 20)); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 144 | |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 145 | Route route2 = createRoute(2, 20); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 146 | Name name2("/hello"); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 147 | rib.insert(name2, route2); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 148 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 149 | Name name3("/hello/world"); |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 150 | rib.insert(name3, createRoute(1, 20)); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 151 | |
| 152 | shared_ptr<rib::RibEntry> ribEntry1 = rib.find(name1)->second; |
| 153 | shared_ptr<rib::RibEntry> ribEntry2 = rib.find(name2)->second; |
| 154 | shared_ptr<rib::RibEntry> ribEntry3 = rib.find(name3)->second; |
| 155 | |
| 156 | BOOST_CHECK(ribEntry1->getChildren().front() == ribEntry2); |
| 157 | BOOST_CHECK(ribEntry3->getParent() == ribEntry2); |
| 158 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 159 | rib.erase(name2, route2); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 160 | BOOST_CHECK(ribEntry1->getChildren().front() == ribEntry3); |
| 161 | BOOST_CHECK(ribEntry3->getParent() == ribEntry1); |
| 162 | } |
| 163 | |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 164 | BOOST_AUTO_TEST_CASE(Basic) |
| 165 | { |
| 166 | rib::Rib rib; |
| 167 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 168 | Route route1; |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 169 | Name name1("/hello/world"); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 170 | route1.faceId = 1; |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 171 | route1.cost = 10; |
| 172 | route1.flags = ndn::nfd::ROUTE_FLAG_CHILD_INHERIT | ndn::nfd::ROUTE_FLAG_CAPTURE; |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 173 | route1.expires = time::steady_clock::now() + 1500_ms; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 174 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 175 | rib.insert(name1, route1); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 176 | BOOST_CHECK_EQUAL(rib.size(), 1); |
| 177 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 178 | rib.insert(name1, route1); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 179 | BOOST_CHECK_EQUAL(rib.size(), 1); |
| 180 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 181 | Route route2; |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 182 | Name name2("/hello/world"); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 183 | route2.faceId = 1; |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 184 | route2.cost = 100; |
| 185 | route2.flags = ndn::nfd::ROUTE_FLAG_CHILD_INHERIT; |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 186 | route2.expires = time::steady_clock::now() + 0_s; |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 187 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 188 | rib.insert(name2, route2); |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 189 | BOOST_CHECK_EQUAL(rib.size(), 1); |
| 190 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 191 | route2.faceId = 2; |
| 192 | rib.insert(name2, route2); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 193 | BOOST_CHECK_EQUAL(rib.size(), 2); |
| 194 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 195 | BOOST_CHECK(rib.find(name1)->second->hasFaceId(route1.faceId)); |
| 196 | BOOST_CHECK(rib.find(name1)->second->hasFaceId(route2.faceId)); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 197 | |
| 198 | Name name3("/foo/bar"); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 199 | rib.insert(name3, route2); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 200 | BOOST_CHECK_EQUAL(rib.size(), 3); |
| 201 | |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 202 | route2.origin = ndn::nfd::ROUTE_ORIGIN_AUTOCONF; |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 203 | rib.insert(name3, route2); |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 204 | BOOST_CHECK_EQUAL(rib.size(), 4); |
| 205 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 206 | rib.erase(name3, route2); |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 207 | BOOST_CHECK_EQUAL(rib.size(), 3); |
| 208 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 209 | Name name4("/hello/world"); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 210 | rib.erase(name4, route2); |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 211 | BOOST_CHECK_EQUAL(rib.size(), 3); |
| 212 | |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 213 | route2.origin = ndn::nfd::ROUTE_ORIGIN_APP; |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 214 | rib.erase(name4, route2); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 215 | BOOST_CHECK_EQUAL(rib.size(), 2); |
| 216 | |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 217 | BOOST_CHECK(rib.find(name2, route2) == nullptr); |
| 218 | BOOST_CHECK(rib.find(name1, route1) != nullptr); |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 219 | |
Teng Liang | a4e6ec3 | 2018-10-21 09:25:00 -0700 | [diff] [blame] | 220 | Name name5("/hello/world/666"); |
| 221 | Name name6("/hello/world/cs/ua/edu"); |
| 222 | BOOST_CHECK(rib.findLongestPrefix(name1, route1) != nullptr); |
| 223 | BOOST_CHECK(rib.findLongestPrefix(name5, route1) != nullptr); |
| 224 | BOOST_CHECK(rib.findLongestPrefix(name6, route1) != nullptr); |
| 225 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 226 | rib.erase(name1, route1); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 227 | BOOST_CHECK_EQUAL(rib.size(), 1); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 228 | } |
| 229 | |
Nick Gordon | 89c4cca | 2016-11-02 15:42:32 +0000 | [diff] [blame] | 230 | BOOST_AUTO_TEST_CASE(RibSignals) |
| 231 | { |
| 232 | rib::Rib rib; |
| 233 | |
| 234 | Route route; |
| 235 | Name name("/hello/world"); |
| 236 | |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 237 | Route route1 = createRoute(1, 20, 10); |
| 238 | Route route2 = createRoute(2, 30, 20); |
Nick Gordon | 89c4cca | 2016-11-02 15:42:32 +0000 | [diff] [blame] | 239 | |
Nick Gordon | 89c4cca | 2016-11-02 15:42:32 +0000 | [diff] [blame] | 240 | int nAfterInsertEntryInvocations = 0; |
| 241 | int nAfterAddRouteInvocations = 0; |
| 242 | int nBeforeRemoveRouteInvocations = 0; |
| 243 | int nAfterEraseEntryInvocations = 0; |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame^] | 244 | rib.afterInsertEntry.connect([&] (const auto&) { |
| 245 | BOOST_CHECK_EQUAL(nAfterInsertEntryInvocations, 0); |
| 246 | BOOST_CHECK_EQUAL(nAfterAddRouteInvocations, 0); |
| 247 | BOOST_CHECK(rib.find(name) != rib.end()); |
| 248 | nAfterInsertEntryInvocations++; |
| 249 | }); |
Nick Gordon | 89c4cca | 2016-11-02 15:42:32 +0000 | [diff] [blame] | 250 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame^] | 251 | rib.afterAddRoute.connect([&] (const auto&) { |
| 252 | BOOST_CHECK_EQUAL(nAfterInsertEntryInvocations, 1); |
| 253 | BOOST_CHECK(rib.find(name) != rib.end()); |
| 254 | BOOST_CHECK(rib.find(name, route) != nullptr); |
| 255 | nAfterAddRouteInvocations++; |
| 256 | }); |
Nick Gordon | 89c4cca | 2016-11-02 15:42:32 +0000 | [diff] [blame] | 257 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame^] | 258 | rib.beforeRemoveRoute.connect([&] (const auto&) { |
| 259 | BOOST_CHECK_EQUAL(nAfterEraseEntryInvocations, 0); |
| 260 | BOOST_CHECK(rib.find(name) != rib.end()); |
| 261 | BOOST_CHECK(rib.find(name, route) != nullptr); |
| 262 | nBeforeRemoveRouteInvocations++; |
| 263 | }); |
Nick Gordon | 89c4cca | 2016-11-02 15:42:32 +0000 | [diff] [blame] | 264 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame^] | 265 | rib.afterEraseEntry.connect([&] (const auto&) { |
| 266 | BOOST_CHECK_EQUAL(nBeforeRemoveRouteInvocations, 2); |
| 267 | BOOST_CHECK_EQUAL(nAfterEraseEntryInvocations, 0); |
| 268 | BOOST_CHECK(rib.find(name) == rib.end()); |
| 269 | nAfterEraseEntryInvocations++; |
| 270 | }); |
Nick Gordon | 89c4cca | 2016-11-02 15:42:32 +0000 | [diff] [blame] | 271 | |
| 272 | route = route1; |
| 273 | rib.insert(name, route); |
| 274 | BOOST_CHECK_EQUAL(nAfterInsertEntryInvocations, 1); |
| 275 | BOOST_CHECK_EQUAL(nAfterAddRouteInvocations, 1); |
| 276 | |
| 277 | route = route2; |
| 278 | rib.insert(name, route); |
| 279 | BOOST_CHECK_EQUAL(nAfterInsertEntryInvocations, 1); |
| 280 | BOOST_CHECK_EQUAL(nAfterAddRouteInvocations, 2); |
| 281 | |
| 282 | route = route1; |
| 283 | rib.erase(name, route); |
| 284 | BOOST_CHECK_EQUAL(nBeforeRemoveRouteInvocations, 1); |
| 285 | BOOST_CHECK_EQUAL(nAfterEraseEntryInvocations, 0); |
| 286 | |
| 287 | route = route2; |
| 288 | rib.erase(name, route); |
| 289 | BOOST_CHECK_EQUAL(nBeforeRemoveRouteInvocations, 2); |
| 290 | BOOST_CHECK_EQUAL(nAfterEraseEntryInvocations, 1); |
Nick Gordon | 89c4cca | 2016-11-02 15:42:32 +0000 | [diff] [blame] | 291 | } |
| 292 | |
Weiwei Liu | aaa58a6 | 2016-11-28 23:15:15 -0700 | [diff] [blame] | 293 | BOOST_AUTO_TEST_CASE(Output) |
| 294 | { |
| 295 | rib::Rib rib; |
| 296 | |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 297 | Route root = createRoute(1, 20); |
Weiwei Liu | aaa58a6 | 2016-11-28 23:15:15 -0700 | [diff] [blame] | 298 | Name name1("/"); |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 299 | root.expires = std::nullopt; |
Weiwei Liu | aaa58a6 | 2016-11-28 23:15:15 -0700 | [diff] [blame] | 300 | rib.insert(name1, root); |
| 301 | |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 302 | Route route1 = createRoute(2, 20); |
Weiwei Liu | aaa58a6 | 2016-11-28 23:15:15 -0700 | [diff] [blame] | 303 | Name name2("/hello"); |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 304 | route1.expires = std::nullopt; |
Weiwei Liu | aaa58a6 | 2016-11-28 23:15:15 -0700 | [diff] [blame] | 305 | rib.insert(name2, route1); |
| 306 | |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 307 | Route route2 = createRoute(3, 20); |
Weiwei Liu | aaa58a6 | 2016-11-28 23:15:15 -0700 | [diff] [blame] | 308 | Name name3("/hello/world"); |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 309 | route2.expires = std::nullopt; |
Weiwei Liu | aaa58a6 | 2016-11-28 23:15:15 -0700 | [diff] [blame] | 310 | rib.insert(name3, route2); |
| 311 | |
| 312 | const std::string ribStr = std::string(R"TEXT( |
| 313 | RibEntry { |
Junxiao Shi | 3f21e58 | 2017-05-29 15:26:32 +0000 | [diff] [blame] | 314 | Name: / |
| 315 | Route(faceid: 1, origin: 20, cost: 0, flags: 0x0, never expires) |
Weiwei Liu | aaa58a6 | 2016-11-28 23:15:15 -0700 | [diff] [blame] | 316 | } |
| 317 | RibEntry { |
Junxiao Shi | 3f21e58 | 2017-05-29 15:26:32 +0000 | [diff] [blame] | 318 | Name: /hello |
| 319 | Route(faceid: 2, origin: 20, cost: 0, flags: 0x0, never expires) |
Weiwei Liu | aaa58a6 | 2016-11-28 23:15:15 -0700 | [diff] [blame] | 320 | } |
| 321 | RibEntry { |
Junxiao Shi | 3f21e58 | 2017-05-29 15:26:32 +0000 | [diff] [blame] | 322 | Name: /hello/world |
| 323 | Route(faceid: 3, origin: 20, cost: 0, flags: 0x0, never expires) |
Weiwei Liu | aaa58a6 | 2016-11-28 23:15:15 -0700 | [diff] [blame] | 324 | } |
| 325 | )TEXT").substr(1); |
| 326 | |
| 327 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(rib), ribStr); |
| 328 | } |
| 329 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 330 | BOOST_AUTO_TEST_SUITE_END() // TestRib |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 331 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame^] | 332 | } // namespace nfd::tests |