Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame^] | 2 | /* |
| 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. |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [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/>. |
| 24 | */ |
| 25 | |
| 26 | #include "rib/rib.hpp" |
| 27 | |
| 28 | #include "tests/test-common.hpp" |
| 29 | #include "fib-updates-common.hpp" |
| 30 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame^] | 31 | namespace nfd::tests { |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 32 | |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 33 | BOOST_FIXTURE_TEST_SUITE(TestFibUpdates, FibUpdatesFixture) |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 34 | |
| 35 | BOOST_AUTO_TEST_SUITE(EraseFace) |
| 36 | |
| 37 | BOOST_AUTO_TEST_CASE(WithInheritedFace_Root) |
| 38 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 39 | insertRoute("/", 1, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 40 | insertRoute("/a", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 41 | insertRoute("/a/b", 2, 0, 75, 0); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 42 | |
| 43 | // Clear updates generated from previous insertions |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 44 | clearFibUpdates(); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 45 | |
| 46 | // Should generate 1 updates: 1 to remove face 1 from / |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 47 | eraseRoute("/", 1, 0); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 48 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 49 | FibUpdater::FibUpdateList updates = getSortedFibUpdates(); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 50 | BOOST_REQUIRE_EQUAL(updates.size(), 1); |
| 51 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 52 | FibUpdater::FibUpdateList::const_iterator update = updates.begin(); |
| 53 | BOOST_CHECK_EQUAL(update->name, "/"); |
| 54 | BOOST_CHECK_EQUAL(update->faceId, 1); |
| 55 | BOOST_CHECK_EQUAL(update->action, FibUpdate::REMOVE_NEXTHOP); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | BOOST_AUTO_TEST_CASE(WithInheritedFace) |
| 59 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 60 | insertRoute("/a", 5, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 61 | insertRoute("/a", 5, 255, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 62 | insertRoute("/a", 2, 0, 20, 0); |
| 63 | insertRoute("/a/b", 3, 0, 5, 0); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 64 | |
| 65 | // /a should have face 5 with cost 10; /a/b should have face 3 with cost 5 and |
| 66 | // face 5 with cost 10 |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 67 | eraseRoute("/a", 5, 255); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 68 | |
| 69 | // Clear updates generated from previous insertions |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 70 | clearFibUpdates(); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 71 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 72 | // Should generate 2 updates: 1 to remove face 3 from /a/b and one to remove inherited route |
| 73 | eraseRoute("/a/b", 3, 0); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 74 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 75 | FibUpdater::FibUpdateList updates = getSortedFibUpdates(); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 76 | BOOST_REQUIRE_EQUAL(updates.size(), 2); |
| 77 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 78 | FibUpdater::FibUpdateList::const_iterator update = updates.begin(); |
| 79 | BOOST_CHECK_EQUAL(update->name, "/a/b"); |
| 80 | BOOST_CHECK_EQUAL(update->faceId, 3); |
| 81 | BOOST_CHECK_EQUAL(update->action, FibUpdate::REMOVE_NEXTHOP); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 82 | |
| 83 | ++update; |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 84 | BOOST_CHECK_EQUAL(update->name, "/a/b"); |
| 85 | BOOST_CHECK_EQUAL(update->faceId, 5); |
| 86 | BOOST_CHECK_EQUAL(update->action, FibUpdate::REMOVE_NEXTHOP); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | BOOST_AUTO_TEST_CASE(MultipleFaces) |
| 90 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 91 | insertRoute("/a", 5, 0, 10, 0); |
| 92 | insertRoute("/a", 5, 255, 5, 0); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 93 | |
| 94 | // Clear updates generated from previous insertions |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 95 | clearFibUpdates(); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 96 | |
| 97 | // Should generate 1 updates: 1 to update cost to 10 for /a |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 98 | eraseRoute("/a", 5, 255); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 99 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 100 | FibUpdater::FibUpdateList updates = getSortedFibUpdates(); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 101 | BOOST_REQUIRE_EQUAL(updates.size(), 1); |
| 102 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 103 | FibUpdater::FibUpdateList::const_iterator update = updates.begin(); |
| 104 | BOOST_CHECK_EQUAL(update->name, "/a"); |
| 105 | BOOST_CHECK_EQUAL(update->faceId, 5); |
| 106 | BOOST_CHECK_EQUAL(update->cost, 10); |
| 107 | BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | BOOST_AUTO_TEST_CASE(NoFlags_NoCaptureChange_NoCaptureOnRoute) |
| 111 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 112 | insertRoute("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 113 | insertRoute("/a", 2, 0, 10, 0); |
| 114 | insertRoute("/a/b", 3, 0, 10, 0); |
| 115 | insertRoute("/a/c", 1, 0, 100, 0); |
| 116 | insertRoute("/a", 1, 128, 50, 0); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 117 | |
| 118 | // Clear updates generated from previous insertions |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 119 | clearFibUpdates(); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 120 | |
| 121 | // Should generate 1 updates: 1 to update cost for /a |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 122 | eraseRoute("/a", 1, 128); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 123 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 124 | FibUpdater::FibUpdateList updates = getSortedFibUpdates(); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 125 | BOOST_REQUIRE_EQUAL(updates.size(), 1); |
| 126 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 127 | FibUpdater::FibUpdateList::const_iterator update = updates.begin(); |
| 128 | BOOST_CHECK_EQUAL(update->name, "/a"); |
| 129 | BOOST_CHECK_EQUAL(update->faceId, 1); |
| 130 | BOOST_CHECK_EQUAL(update->cost, 5); |
| 131 | BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | BOOST_AUTO_TEST_CASE(MakeRibEmpty) |
| 135 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 136 | insertRoute("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 137 | |
| 138 | // Clear updates generated from previous insertions |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 139 | clearFibUpdates(); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 140 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 141 | // Should generate 1 updates: 1 to remove route from / |
| 142 | eraseRoute("/", 1, 0); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 143 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 144 | FibUpdater::FibUpdateList updates = getSortedFibUpdates(); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 145 | BOOST_REQUIRE_EQUAL(updates.size(), 1); |
| 146 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 147 | FibUpdater::FibUpdateList::const_iterator update = updates.begin(); |
| 148 | BOOST_CHECK_EQUAL(update->name, "/"); |
| 149 | BOOST_CHECK_EQUAL(update->faceId, 1); |
| 150 | BOOST_CHECK_EQUAL(update->action, FibUpdate::REMOVE_NEXTHOP); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | BOOST_AUTO_TEST_CASE(NoFlags_NoCaptureChange_CaptureOnRoute) |
| 154 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 155 | insertRoute("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 156 | insertRoute("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE); |
| 157 | insertRoute("/a/b", 3, 0, 10, 0); |
| 158 | insertRoute("/a/c", 1, 0, 100, 0); |
| 159 | insertRoute("/a", 1, 128, 50, 0); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 160 | |
| 161 | // Clear updates generated from previous insertions |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 162 | clearFibUpdates(); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 163 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 164 | // Should generate 1 updates: 1 to remove route from /a |
| 165 | eraseRoute("/a", 1, 128); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 166 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 167 | FibUpdater::FibUpdateList updates = getSortedFibUpdates(); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 168 | BOOST_REQUIRE_EQUAL(updates.size(), 1); |
| 169 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 170 | FibUpdater::FibUpdateList::const_iterator update = updates.begin(); |
| 171 | BOOST_CHECK_EQUAL(update->name, "/a"); |
| 172 | BOOST_CHECK_EQUAL(update->faceId, 1); |
| 173 | BOOST_CHECK_EQUAL(update->action, FibUpdate::REMOVE_NEXTHOP); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | BOOST_AUTO_TEST_CASE(BothFlags_NoCaptureChange_CaptureOnRoute) |
| 177 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 178 | insertRoute("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 179 | insertRoute("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE); |
| 180 | insertRoute("/a/b", 3, 0, 10, 0); |
| 181 | insertRoute("/a/c", 1, 0, 100, 0); |
| 182 | insertRoute("/a", 1, 128, 50, (ndn::nfd::ROUTE_FLAG_CHILD_INHERIT | |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 183 | ndn::nfd::ROUTE_FLAG_CAPTURE)); |
| 184 | |
| 185 | // Clear updates generated from previous insertions |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 186 | clearFibUpdates(); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 187 | |
| 188 | // Should generate 2 updates: 1 to remove face1 from /a and |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 189 | // 1 to remove face1 from /a/b |
| 190 | eraseRoute("/a", 1, 128); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 191 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 192 | FibUpdater::FibUpdateList updates = getSortedFibUpdates(); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 193 | BOOST_REQUIRE_EQUAL(updates.size(), 2); |
| 194 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 195 | FibUpdater::FibUpdateList::const_iterator update = updates.begin(); |
| 196 | BOOST_CHECK_EQUAL(update->name, "/a"); |
| 197 | BOOST_CHECK_EQUAL(update->faceId, 1); |
| 198 | BOOST_CHECK_EQUAL(update->action, FibUpdate::REMOVE_NEXTHOP); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 199 | |
| 200 | ++update; |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 201 | BOOST_CHECK_EQUAL(update->name, "/a/b"); |
| 202 | BOOST_CHECK_EQUAL(update->faceId, 1); |
| 203 | BOOST_CHECK_EQUAL(update->action, FibUpdate::REMOVE_NEXTHOP); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | BOOST_AUTO_TEST_CASE(BothFlags_CaptureChange_NoCaptureOnRoute) |
| 207 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 208 | insertRoute("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 209 | insertRoute("/a", 2, 0, 10, 0); |
| 210 | insertRoute("/a/b", 3, 0, 10, 0); |
| 211 | insertRoute("/a/c", 1, 0, 100, 0); |
| 212 | insertRoute("/a", 1, 128, 50, (ndn::nfd::ROUTE_FLAG_CHILD_INHERIT | |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 213 | ndn::nfd::ROUTE_FLAG_CAPTURE)); |
| 214 | |
| 215 | // Clear updates generated from previous insertions |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 216 | clearFibUpdates(); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 217 | |
| 218 | // Should generate 2 updates: 1 to add face1 to /a and |
| 219 | // 1 to add face1 to /a/b |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 220 | eraseRoute("/a", 1, 128); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 221 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 222 | FibUpdater::FibUpdateList updates = getSortedFibUpdates(); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 223 | BOOST_REQUIRE_EQUAL(updates.size(), 2); |
| 224 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 225 | FibUpdater::FibUpdateList::const_iterator update = updates.begin(); |
| 226 | BOOST_CHECK_EQUAL(update->name, "/a"); |
| 227 | BOOST_CHECK_EQUAL(update->faceId, 1); |
| 228 | BOOST_CHECK_EQUAL(update->cost, 5); |
| 229 | BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 230 | |
| 231 | ++update; |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 232 | BOOST_CHECK_EQUAL(update->name, "/a/b"); |
| 233 | BOOST_CHECK_EQUAL(update->faceId, 1); |
| 234 | BOOST_CHECK_EQUAL(update->cost, 5); |
| 235 | BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | BOOST_AUTO_TEST_CASE(ChildInherit_NoCaptureChange_NoCaptureOnRoute) |
| 239 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 240 | insertRoute("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 241 | insertRoute("/a", 2, 0, 10, 0); |
| 242 | insertRoute("/a/b", 3, 0, 10, 0); |
| 243 | insertRoute("/a/c", 1, 0, 100, 0); |
| 244 | insertRoute("/a", 1, 128, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 245 | |
| 246 | // Clear updates generated from previous insertions |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 247 | clearFibUpdates(); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 248 | |
| 249 | // Should generate 2 updates: 2 to add face1 to /a and /a/b |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 250 | eraseRoute("/a", 1, 128); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 251 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 252 | FibUpdater::FibUpdateList updates = getSortedFibUpdates(); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 253 | BOOST_REQUIRE_EQUAL(updates.size(), 2); |
| 254 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 255 | FibUpdater::FibUpdateList::const_iterator update = updates.begin(); |
| 256 | BOOST_CHECK_EQUAL(update->name, "/a"); |
| 257 | BOOST_CHECK_EQUAL(update->faceId, 1); |
| 258 | BOOST_CHECK_EQUAL(update->cost, 5); |
| 259 | BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 260 | |
| 261 | ++update; |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 262 | BOOST_CHECK_EQUAL(update->name, "/a/b"); |
| 263 | BOOST_CHECK_EQUAL(update->faceId, 1); |
| 264 | BOOST_CHECK_EQUAL(update->cost, 5); |
| 265 | BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | BOOST_AUTO_TEST_CASE(ChildInherit_NoCaptureChange_CaptureOnRoute) |
| 269 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 270 | insertRoute("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 271 | insertRoute("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE); |
| 272 | insertRoute("/a/b", 3, 0, 10, 0); |
| 273 | insertRoute("/a/c", 1, 0, 100, 0); |
| 274 | insertRoute("/a", 1, 128, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 275 | |
| 276 | // Clear updates generated from previous insertions |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 277 | clearFibUpdates(); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 278 | |
| 279 | // Should generate 2 updates: 2 to remove face 1 from /a and /a/b |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 280 | eraseRoute("/a", 1, 128); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 281 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 282 | FibUpdater::FibUpdateList updates = getSortedFibUpdates(); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 283 | BOOST_REQUIRE_EQUAL(updates.size(), 2); |
| 284 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 285 | FibUpdater::FibUpdateList::const_iterator update = updates.begin(); |
| 286 | BOOST_CHECK_EQUAL(update->name, "/a"); |
| 287 | BOOST_CHECK_EQUAL(update->faceId, 1); |
| 288 | BOOST_CHECK_EQUAL(update->action, FibUpdate::REMOVE_NEXTHOP); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 289 | |
| 290 | ++update; |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 291 | BOOST_CHECK_EQUAL(update->name, "/a/b"); |
| 292 | BOOST_CHECK_EQUAL(update->faceId, 1); |
| 293 | BOOST_CHECK_EQUAL(update->action, FibUpdate::REMOVE_NEXTHOP); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | BOOST_AUTO_TEST_CASE(Capture_CaptureChange_NoCaptureOnRoute) |
| 297 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 298 | insertRoute("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 299 | insertRoute("/a", 2, 0, 10, 0); |
| 300 | insertRoute("/a/b", 3, 0, 10, 0); |
| 301 | insertRoute("/a/c", 1, 0, 100, 0); |
| 302 | insertRoute("/a", 1, 128, 50, ndn::nfd::ROUTE_FLAG_CAPTURE); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 303 | |
| 304 | // Clear updates generated from previous insertions |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 305 | clearFibUpdates(); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 306 | |
| 307 | // Should generate 2 updates: 1 to update cost on /a and |
| 308 | // 1 to add face1 to /a/b |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 309 | eraseRoute("/a", 1 ,128); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 310 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 311 | FibUpdater::FibUpdateList updates = getSortedFibUpdates(); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 312 | BOOST_REQUIRE_EQUAL(updates.size(), 2); |
| 313 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 314 | FibUpdater::FibUpdateList::const_iterator update = updates.begin(); |
| 315 | BOOST_CHECK_EQUAL(update->name, "/a"); |
| 316 | BOOST_CHECK_EQUAL(update->faceId, 1); |
| 317 | BOOST_CHECK_EQUAL(update->cost, 5); |
| 318 | BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 319 | |
| 320 | ++update; |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 321 | BOOST_CHECK_EQUAL(update->name, "/a/b"); |
| 322 | BOOST_CHECK_EQUAL(update->faceId, 1); |
| 323 | BOOST_CHECK_EQUAL(update->cost, 5); |
| 324 | BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | BOOST_AUTO_TEST_CASE(Capture_NoCaptureChange_CaptureOnRoute) |
| 328 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 329 | insertRoute("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 330 | insertRoute("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE); |
| 331 | insertRoute("/a/b", 3, 0, 10, 0); |
| 332 | insertRoute("/a/c", 1, 0, 100, 0); |
| 333 | insertRoute("/a", 1, 128, 50, ndn::nfd::ROUTE_FLAG_CAPTURE); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 334 | |
| 335 | // Clear updates generated from previous insertions |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 336 | clearFibUpdates(); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 337 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 338 | // Should generate 1 updates: 1 to remove route from /a |
| 339 | eraseRoute("/a", 1, 128); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 340 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 341 | FibUpdater::FibUpdateList updates = getSortedFibUpdates(); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 342 | BOOST_REQUIRE_EQUAL(updates.size(), 1); |
| 343 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 344 | FibUpdater::FibUpdateList::const_iterator update = updates.begin(); |
| 345 | BOOST_CHECK_EQUAL(update->name, "/a"); |
| 346 | BOOST_CHECK_EQUAL(update->faceId, 1); |
| 347 | BOOST_CHECK_EQUAL(update->action, FibUpdate::REMOVE_NEXTHOP); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | BOOST_AUTO_TEST_CASE(EraseFaceById) |
| 351 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 352 | insertRoute("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 353 | insertRoute("/a", 3, 0, 10, 0); |
| 354 | insertRoute("/a/b", 4, 0, 10, 0); |
| 355 | insertRoute("/a/c", 1, 0, 100, 0); |
| 356 | insertRoute("/a", 2, 128, 50, ndn::nfd::ROUTE_FLAG_CAPTURE); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 357 | |
| 358 | // Clear updates generated from previous insertions |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 359 | clearFibUpdates(); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 360 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 361 | // Should generate 2 updates: 2 to add face ID 1 to /a and /a/b |
| 362 | destroyFace(2); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 363 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 364 | FibUpdater::FibUpdateList updates = getSortedFibUpdates(); |
| 365 | BOOST_REQUIRE_EQUAL(updates.size(), 2); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 366 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 367 | FibUpdater::FibUpdateList::const_iterator update = updates.begin(); |
| 368 | BOOST_CHECK_EQUAL(update->name, "/a"); |
| 369 | BOOST_CHECK_EQUAL(update->faceId, 1); |
| 370 | BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 371 | |
| 372 | ++update; |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 373 | BOOST_CHECK_EQUAL(update->name, "/a/b"); |
| 374 | BOOST_CHECK_EQUAL(update->faceId, 1); |
| 375 | BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 376 | } |
| 377 | |
Vince Lehman | f91ab74 | 2015-04-23 15:26:55 -0500 | [diff] [blame] | 378 | BOOST_AUTO_TEST_CASE(RemoveNamespaceWithAncestorFace) // Bug #2757 |
| 379 | { |
| 380 | uint64_t faceId = 263; |
| 381 | |
| 382 | // Register route back to laptop |
| 383 | insertRoute("/", faceId, ndn::nfd::ROUTE_ORIGIN_STATIC, 0, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 384 | |
| 385 | // Register remote prefix |
| 386 | insertRoute("/Z/A", faceId, ndn::nfd::ROUTE_ORIGIN_CLIENT, 15, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 387 | |
| 388 | // Clear updates generated from previous insertions |
| 389 | clearFibUpdates(); |
| 390 | |
| 391 | // Unregister remote prefix |
| 392 | // Should create an update to remove the remote prefix but should not create |
| 393 | // an update to add the ancestor route to the remote prefix's namespace |
| 394 | eraseRoute("/Z/A", faceId, ndn::nfd::ROUTE_ORIGIN_CLIENT); |
| 395 | |
| 396 | FibUpdater::FibUpdateList updates = getSortedFibUpdates(); |
| 397 | BOOST_REQUIRE_EQUAL(updates.size(), 1); |
| 398 | |
| 399 | FibUpdater::FibUpdateList::const_iterator update = updates.begin(); |
| 400 | BOOST_CHECK_EQUAL(update->name, "/Z/A"); |
| 401 | BOOST_CHECK_EQUAL(update->faceId, faceId); |
| 402 | BOOST_CHECK_EQUAL(update->action, FibUpdate::REMOVE_NEXTHOP); |
| 403 | } |
| 404 | |
Vince Lehman | 9aac873 | 2016-01-11 15:49:23 -0600 | [diff] [blame] | 405 | BOOST_AUTO_TEST_CASE(RemoveNamespaceWithCapture) // Bug #3404 |
| 406 | { |
| 407 | insertRoute("/", 262, ndn::nfd::ROUTE_ORIGIN_STATIC, 0, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 408 | |
| 409 | uint64_t appFaceId = 264; |
| 410 | ndn::Name ndnConPrefix("/ndn/edu/site/ndnrtc/user/username/streams/main_camera/low"); |
| 411 | insertRoute(ndnConPrefix, appFaceId, ndn::nfd::ROUTE_ORIGIN_CLIENT, 0, |
| 412 | ndn::nfd::ROUTE_FLAG_CHILD_INHERIT | ndn::nfd::ROUTE_FLAG_CAPTURE); |
| 413 | |
| 414 | // Clear updates generated from previous insertions |
| 415 | clearFibUpdates(); |
| 416 | |
| 417 | destroyFace(appFaceId); |
| 418 | |
| 419 | // FibUpdater should not generate any inherited routes for the erased RibEntry |
| 420 | BOOST_CHECK_EQUAL(fibUpdater.m_inheritedRoutes.size(), 0); |
| 421 | } |
| 422 | |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 423 | BOOST_AUTO_TEST_SUITE_END() // EraseFace |
| 424 | |
| 425 | BOOST_AUTO_TEST_SUITE_END() // FibUpdates |
| 426 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame^] | 427 | } // namespace nfd::tests |