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