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 | /* |
| 3 | * Copyright (c) 2014-2018, 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 | |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 28 | #include "rib-test-common.hpp" |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 29 | #include "tests/test-common.hpp" |
| 30 | |
| 31 | namespace nfd { |
| 32 | namespace rib { |
| 33 | namespace tests { |
| 34 | |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 35 | BOOST_FIXTURE_TEST_SUITE(TestRib, nfd::tests::BaseFixture) |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 36 | |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 37 | BOOST_AUTO_TEST_CASE(Parent) |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 38 | { |
| 39 | rib::Rib rib; |
| 40 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 41 | Name name1("/"); |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 42 | rib.insert(name1, createRoute(1, 20)); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 43 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 44 | Name name2("/hello"); |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 45 | rib.insert(name2, createRoute(2, 20)); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 46 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 47 | Name name3("/hello/world"); |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 48 | rib.insert(name3, createRoute(3, 20)); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 49 | |
| 50 | shared_ptr<rib::RibEntry> ribEntry = rib.findParent(name3); |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 51 | BOOST_REQUIRE(ribEntry != nullptr); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 52 | BOOST_CHECK_EQUAL(ribEntry->getRoutes().front().faceId, 2); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 53 | |
| 54 | ribEntry = rib.findParent(name2); |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 55 | BOOST_REQUIRE(ribEntry != nullptr); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 56 | BOOST_CHECK_EQUAL(ribEntry->getRoutes().front().faceId, 1); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 57 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 58 | Name name4("/hello/test/foo/bar"); |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 59 | rib.insert(name4, createRoute(3, 20)); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 60 | |
| 61 | ribEntry = rib.findParent(name4); |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 62 | BOOST_REQUIRE(ribEntry != nullptr); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 63 | BOOST_CHECK(ribEntry->getRoutes().front().faceId == 2); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 64 | } |
| 65 | |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 66 | BOOST_AUTO_TEST_CASE(Children) |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 67 | { |
| 68 | rib::Rib rib; |
| 69 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 70 | Name name1("/"); |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 71 | rib.insert(name1, createRoute(1, 20)); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 72 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 73 | Name name2("/hello/world"); |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 74 | rib.insert(name2, createRoute(2, 20)); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 75 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 76 | Name name3("/hello/test/foo/bar"); |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 77 | rib.insert(name3, createRoute(3, 20)); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 78 | |
| 79 | BOOST_CHECK_EQUAL((rib.find(name1)->second)->getChildren().size(), 2); |
| 80 | BOOST_CHECK_EQUAL((rib.find(name2)->second)->getChildren().size(), 0); |
| 81 | BOOST_CHECK_EQUAL((rib.find(name3)->second)->getChildren().size(), 0); |
| 82 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 83 | Name name4("/hello"); |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 84 | rib.insert(name4, createRoute(4, 20)); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 85 | |
| 86 | BOOST_CHECK_EQUAL((rib.find(name1)->second)->getChildren().size(), 1); |
| 87 | BOOST_CHECK_EQUAL((rib.find(name2)->second)->getChildren().size(), 0); |
| 88 | BOOST_CHECK_EQUAL((rib.find(name3)->second)->getChildren().size(), 0); |
| 89 | BOOST_CHECK_EQUAL((rib.find(name4)->second)->getChildren().size(), 2); |
| 90 | |
| 91 | BOOST_CHECK_EQUAL((rib.find(name1)->second)->getChildren().front()->getName(), "/hello"); |
| 92 | BOOST_CHECK_EQUAL((rib.find(name4)->second)->getParent()->getName(), "/"); |
| 93 | |
| 94 | BOOST_REQUIRE(static_cast<bool>((rib.find(name2)->second)->getParent())); |
| 95 | BOOST_CHECK_EQUAL((rib.find(name2)->second)->getParent()->getName(), name4); |
| 96 | BOOST_REQUIRE(static_cast<bool>((rib.find(name3)->second)->getParent())); |
| 97 | BOOST_CHECK_EQUAL((rib.find(name3)->second)->getParent()->getName(), name4); |
| 98 | } |
| 99 | |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 100 | BOOST_AUTO_TEST_CASE(EraseFace) |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 101 | { |
| 102 | rib::Rib rib; |
| 103 | |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 104 | Route route1 = createRoute(1, 20); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 105 | Name name1("/"); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 106 | rib.insert(name1, route1); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 107 | |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 108 | Route route2 = createRoute(2, 20); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 109 | Name name2("/hello/world"); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 110 | rib.insert(name2, route2); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 111 | |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 112 | Route route3 = createRoute(1, 20); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 113 | Name name3("/hello/world"); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 114 | rib.insert(name3, route3); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 115 | |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 116 | Route route4 = createRoute(1, 20); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 117 | Name name4("/not/inserted"); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 118 | |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 119 | rib.erase(name4, route4); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 120 | rib.erase(name1, route1); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 121 | |
| 122 | BOOST_CHECK(rib.find(name1) == rib.end()); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 123 | BOOST_CHECK_EQUAL((rib.find(name2)->second)->getRoutes().size(), 2); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 124 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 125 | rib.erase(name2, route2); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 126 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 127 | BOOST_CHECK_EQUAL((rib.find(name2)->second)->getRoutes().size(), 1); |
| 128 | BOOST_CHECK_EQUAL((rib.find(name2)->second)->getRoutes().front().faceId, 1); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 129 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 130 | rib.erase(name3, route3); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 131 | |
| 132 | BOOST_CHECK(rib.find(name2) == rib.end()); |
| 133 | |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 134 | rib.erase(name4, route4); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 135 | } |
| 136 | |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 137 | BOOST_AUTO_TEST_CASE(EraseRibEntry) |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 138 | { |
| 139 | rib::Rib rib; |
| 140 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 141 | Name name1("/"); |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 142 | rib.insert(name1, createRoute(1, 20)); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 143 | |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 144 | Route route2 = createRoute(2, 20); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 145 | Name name2("/hello"); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 146 | rib.insert(name2, route2); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 147 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 148 | Name name3("/hello/world"); |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 149 | rib.insert(name3, createRoute(1, 20)); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 150 | |
| 151 | shared_ptr<rib::RibEntry> ribEntry1 = rib.find(name1)->second; |
| 152 | shared_ptr<rib::RibEntry> ribEntry2 = rib.find(name2)->second; |
| 153 | shared_ptr<rib::RibEntry> ribEntry3 = rib.find(name3)->second; |
| 154 | |
| 155 | BOOST_CHECK(ribEntry1->getChildren().front() == ribEntry2); |
| 156 | BOOST_CHECK(ribEntry3->getParent() == ribEntry2); |
| 157 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 158 | rib.erase(name2, route2); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 159 | BOOST_CHECK(ribEntry1->getChildren().front() == ribEntry3); |
| 160 | BOOST_CHECK(ribEntry3->getParent() == ribEntry1); |
| 161 | } |
| 162 | |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 163 | BOOST_AUTO_TEST_CASE(Basic) |
| 164 | { |
| 165 | rib::Rib rib; |
| 166 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 167 | Route route1; |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 168 | Name name1("/hello/world"); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 169 | route1.faceId = 1; |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 170 | route1.cost = 10; |
| 171 | route1.flags = ndn::nfd::ROUTE_FLAG_CHILD_INHERIT | ndn::nfd::ROUTE_FLAG_CAPTURE; |
| 172 | route1.expires = time::steady_clock::now() + time::milliseconds(1500); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 173 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 174 | rib.insert(name1, route1); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 175 | BOOST_CHECK_EQUAL(rib.size(), 1); |
| 176 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 177 | rib.insert(name1, route1); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 178 | BOOST_CHECK_EQUAL(rib.size(), 1); |
| 179 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 180 | Route route2; |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 181 | Name name2("/hello/world"); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 182 | route2.faceId = 1; |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 183 | route2.cost = 100; |
| 184 | route2.flags = ndn::nfd::ROUTE_FLAG_CHILD_INHERIT; |
| 185 | route2.expires = time::steady_clock::now() + time::seconds(0); |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 186 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 187 | rib.insert(name2, route2); |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 188 | BOOST_CHECK_EQUAL(rib.size(), 1); |
| 189 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 190 | route2.faceId = 2; |
| 191 | rib.insert(name2, route2); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 192 | BOOST_CHECK_EQUAL(rib.size(), 2); |
| 193 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 194 | BOOST_CHECK(rib.find(name1)->second->hasFaceId(route1.faceId)); |
| 195 | BOOST_CHECK(rib.find(name1)->second->hasFaceId(route2.faceId)); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 196 | |
| 197 | Name name3("/foo/bar"); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 198 | rib.insert(name3, route2); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 199 | BOOST_CHECK_EQUAL(rib.size(), 3); |
| 200 | |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 201 | route2.origin = ndn::nfd::ROUTE_ORIGIN_AUTOCONF; |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 202 | rib.insert(name3, route2); |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 203 | BOOST_CHECK_EQUAL(rib.size(), 4); |
| 204 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 205 | rib.erase(name3, route2); |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 206 | BOOST_CHECK_EQUAL(rib.size(), 3); |
| 207 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 208 | Name name4("/hello/world"); |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 209 | rib.erase(name4, route2); |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 210 | BOOST_CHECK_EQUAL(rib.size(), 3); |
| 211 | |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 212 | route2.origin = ndn::nfd::ROUTE_ORIGIN_APP; |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 213 | rib.erase(name4, route2); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 214 | BOOST_CHECK_EQUAL(rib.size(), 2); |
| 215 | |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 216 | BOOST_CHECK(rib.find(name2, route2) == nullptr); |
| 217 | BOOST_CHECK(rib.find(name1, route1) != nullptr); |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 218 | |
Teng Liang | a4e6ec3 | 2018-10-21 09:25:00 -0700 | [diff] [blame] | 219 | Name name5("/hello/world/666"); |
| 220 | Name name6("/hello/world/cs/ua/edu"); |
| 221 | BOOST_CHECK(rib.findLongestPrefix(name1, route1) != nullptr); |
| 222 | BOOST_CHECK(rib.findLongestPrefix(name5, route1) != nullptr); |
| 223 | BOOST_CHECK(rib.findLongestPrefix(name6, route1) != nullptr); |
| 224 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 225 | rib.erase(name1, route1); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 226 | BOOST_CHECK_EQUAL(rib.size(), 1); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Nick Gordon | 89c4cca | 2016-11-02 15:42:32 +0000 | [diff] [blame] | 229 | BOOST_AUTO_TEST_CASE(RibSignals) |
| 230 | { |
| 231 | rib::Rib rib; |
| 232 | |
| 233 | Route route; |
| 234 | Name name("/hello/world"); |
| 235 | |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 236 | Route route1 = createRoute(1, 20, 10); |
| 237 | Route route2 = createRoute(2, 30, 20); |
Nick Gordon | 89c4cca | 2016-11-02 15:42:32 +0000 | [diff] [blame] | 238 | |
| 239 | RibRouteRef routeInfo; |
| 240 | |
| 241 | int nAfterInsertEntryInvocations = 0; |
| 242 | int nAfterAddRouteInvocations = 0; |
| 243 | int nBeforeRemoveRouteInvocations = 0; |
| 244 | int nAfterEraseEntryInvocations = 0; |
| 245 | rib.afterInsertEntry.connect([&] (const Name& inName) { |
| 246 | BOOST_CHECK_EQUAL(nAfterInsertEntryInvocations, 0); |
| 247 | BOOST_CHECK_EQUAL(nAfterAddRouteInvocations, 0); |
| 248 | BOOST_CHECK(rib.find(name) != rib.end()); |
| 249 | nAfterInsertEntryInvocations++; |
| 250 | }); |
| 251 | |
| 252 | rib.afterAddRoute.connect([&] (const RibRouteRef& rrr) { |
| 253 | BOOST_CHECK_EQUAL(nAfterInsertEntryInvocations, 1); |
| 254 | BOOST_CHECK(rib.find(name) != rib.end()); |
| 255 | BOOST_CHECK(rib.find(name, route) != nullptr); |
| 256 | nAfterAddRouteInvocations++; |
| 257 | }); |
| 258 | |
| 259 | rib.beforeRemoveRoute.connect([&] (const RibRouteRef& rrr) { |
| 260 | BOOST_CHECK_EQUAL(nAfterEraseEntryInvocations, 0); |
| 261 | BOOST_CHECK(rib.find(name) != rib.end()); |
| 262 | BOOST_CHECK(rib.find(name, route) != nullptr); |
| 263 | nBeforeRemoveRouteInvocations++; |
| 264 | }); |
| 265 | |
| 266 | rib.afterEraseEntry.connect([&] (const Name& inName) { |
| 267 | BOOST_CHECK_EQUAL(nBeforeRemoveRouteInvocations, 2); |
| 268 | BOOST_CHECK_EQUAL(nAfterEraseEntryInvocations, 0); |
| 269 | BOOST_CHECK(rib.find(name) == rib.end()); |
| 270 | nAfterEraseEntryInvocations++; |
| 271 | }); |
| 272 | |
| 273 | route = route1; |
| 274 | rib.insert(name, route); |
| 275 | BOOST_CHECK_EQUAL(nAfterInsertEntryInvocations, 1); |
| 276 | BOOST_CHECK_EQUAL(nAfterAddRouteInvocations, 1); |
| 277 | |
| 278 | route = route2; |
| 279 | rib.insert(name, route); |
| 280 | BOOST_CHECK_EQUAL(nAfterInsertEntryInvocations, 1); |
| 281 | BOOST_CHECK_EQUAL(nAfterAddRouteInvocations, 2); |
| 282 | |
| 283 | route = route1; |
| 284 | rib.erase(name, route); |
| 285 | BOOST_CHECK_EQUAL(nBeforeRemoveRouteInvocations, 1); |
| 286 | BOOST_CHECK_EQUAL(nAfterEraseEntryInvocations, 0); |
| 287 | |
| 288 | route = route2; |
| 289 | rib.erase(name, route); |
| 290 | BOOST_CHECK_EQUAL(nBeforeRemoveRouteInvocations, 2); |
| 291 | BOOST_CHECK_EQUAL(nAfterEraseEntryInvocations, 1); |
Nick Gordon | 89c4cca | 2016-11-02 15:42:32 +0000 | [diff] [blame] | 292 | } |
| 293 | |
Weiwei Liu | aaa58a6 | 2016-11-28 23:15:15 -0700 | [diff] [blame] | 294 | BOOST_AUTO_TEST_CASE(Output) |
| 295 | { |
| 296 | rib::Rib rib; |
| 297 | |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 298 | Route root = createRoute(1, 20); |
Weiwei Liu | aaa58a6 | 2016-11-28 23:15:15 -0700 | [diff] [blame] | 299 | Name name1("/"); |
Davide Pesavento | 87fc0f8 | 2018-04-11 23:43:51 -0400 | [diff] [blame] | 300 | root.expires = nullopt; |
Weiwei Liu | aaa58a6 | 2016-11-28 23:15:15 -0700 | [diff] [blame] | 301 | rib.insert(name1, root); |
| 302 | |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 303 | Route route1 = createRoute(2, 20); |
Weiwei Liu | aaa58a6 | 2016-11-28 23:15:15 -0700 | [diff] [blame] | 304 | Name name2("/hello"); |
Davide Pesavento | 87fc0f8 | 2018-04-11 23:43:51 -0400 | [diff] [blame] | 305 | route1.expires = nullopt; |
Weiwei Liu | aaa58a6 | 2016-11-28 23:15:15 -0700 | [diff] [blame] | 306 | rib.insert(name2, route1); |
| 307 | |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 308 | Route route2 = createRoute(3, 20); |
Weiwei Liu | aaa58a6 | 2016-11-28 23:15:15 -0700 | [diff] [blame] | 309 | Name name3("/hello/world"); |
Davide Pesavento | 87fc0f8 | 2018-04-11 23:43:51 -0400 | [diff] [blame] | 310 | route2.expires = nullopt; |
Weiwei Liu | aaa58a6 | 2016-11-28 23:15:15 -0700 | [diff] [blame] | 311 | rib.insert(name3, route2); |
| 312 | |
| 313 | const std::string ribStr = std::string(R"TEXT( |
| 314 | RibEntry { |
Junxiao Shi | 3f21e58 | 2017-05-29 15:26:32 +0000 | [diff] [blame] | 315 | Name: / |
| 316 | Route(faceid: 1, origin: 20, cost: 0, flags: 0x0, never expires) |
Weiwei Liu | aaa58a6 | 2016-11-28 23:15:15 -0700 | [diff] [blame] | 317 | } |
| 318 | RibEntry { |
Junxiao Shi | 3f21e58 | 2017-05-29 15:26:32 +0000 | [diff] [blame] | 319 | Name: /hello |
| 320 | Route(faceid: 2, origin: 20, cost: 0, flags: 0x0, never expires) |
Weiwei Liu | aaa58a6 | 2016-11-28 23:15:15 -0700 | [diff] [blame] | 321 | } |
| 322 | RibEntry { |
Junxiao Shi | 3f21e58 | 2017-05-29 15:26:32 +0000 | [diff] [blame] | 323 | Name: /hello/world |
| 324 | Route(faceid: 3, origin: 20, cost: 0, flags: 0x0, never expires) |
Weiwei Liu | aaa58a6 | 2016-11-28 23:15:15 -0700 | [diff] [blame] | 325 | } |
| 326 | )TEXT").substr(1); |
| 327 | |
| 328 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(rib), ribStr); |
| 329 | } |
| 330 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 331 | BOOST_AUTO_TEST_SUITE_END() // TestRib |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 332 | |
| 333 | } // namespace tests |
| 334 | } // namespace rib |
| 335 | } // namespace nfd |