blob: a911d5eb1021b754a84b827c9a63f7738337b4aa [file] [log] [blame]
Vince Lehman4387e782014-06-19 16:57:45 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventoe422f9e2022-06-03 01:30:23 -04002/*
3 * Copyright (c) 2014-2022, Regents of the University of California,
Alexander Afanasyev7c10b3b2015-01-20 12:24:27 -08004 * 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 Lehman4387e782014-06-19 16:57:45 -050010 *
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 Pesaventoe422f9e2022-06-03 01:30:23 -040031namespace nfd::tests {
Vince Lehman4387e782014-06-19 16:57:45 -050032
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080033BOOST_FIXTURE_TEST_SUITE(TestFibUpdates, FibUpdatesFixture)
Vince Lehman4387e782014-06-19 16:57:45 -050034
35BOOST_AUTO_TEST_SUITE(EraseFace)
36
37BOOST_AUTO_TEST_CASE(WithInheritedFace_Root)
38{
Vince Lehman218be0a2015-01-15 17:25:20 -060039 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 Lehman4387e782014-06-19 16:57:45 -050042
43 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -060044 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -050045
46 // Should generate 1 updates: 1 to remove face 1 from /
Vince Lehman218be0a2015-01-15 17:25:20 -060047 eraseRoute("/", 1, 0);
Vince Lehman4387e782014-06-19 16:57:45 -050048
Vince Lehman76c751c2014-11-18 17:36:38 -060049 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -050050 BOOST_REQUIRE_EQUAL(updates.size(), 1);
51
Vince Lehman76c751c2014-11-18 17:36:38 -060052 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 Lehman4387e782014-06-19 16:57:45 -050056}
57
58BOOST_AUTO_TEST_CASE(WithInheritedFace)
59{
Vince Lehman218be0a2015-01-15 17:25:20 -060060 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 Lehman4387e782014-06-19 16:57:45 -050064
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 Lehman218be0a2015-01-15 17:25:20 -060067 eraseRoute("/a", 5, 255);
Vince Lehman4387e782014-06-19 16:57:45 -050068
69 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -060070 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -050071
Vince Lehman218be0a2015-01-15 17:25:20 -060072 // 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 Lehman4387e782014-06-19 16:57:45 -050074
Vince Lehman76c751c2014-11-18 17:36:38 -060075 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -050076 BOOST_REQUIRE_EQUAL(updates.size(), 2);
77
Vince Lehman76c751c2014-11-18 17:36:38 -060078 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 Lehman4387e782014-06-19 16:57:45 -050082
83 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -060084 BOOST_CHECK_EQUAL(update->name, "/a/b");
85 BOOST_CHECK_EQUAL(update->faceId, 5);
86 BOOST_CHECK_EQUAL(update->action, FibUpdate::REMOVE_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -050087}
88
89BOOST_AUTO_TEST_CASE(MultipleFaces)
90{
Vince Lehman218be0a2015-01-15 17:25:20 -060091 insertRoute("/a", 5, 0, 10, 0);
92 insertRoute("/a", 5, 255, 5, 0);
Vince Lehman4387e782014-06-19 16:57:45 -050093
94 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -060095 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -050096
97 // Should generate 1 updates: 1 to update cost to 10 for /a
Vince Lehman218be0a2015-01-15 17:25:20 -060098 eraseRoute("/a", 5, 255);
Vince Lehman4387e782014-06-19 16:57:45 -050099
Vince Lehman76c751c2014-11-18 17:36:38 -0600100 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500101 BOOST_REQUIRE_EQUAL(updates.size(), 1);
102
Vince Lehman76c751c2014-11-18 17:36:38 -0600103 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 Lehman4387e782014-06-19 16:57:45 -0500108}
109
110BOOST_AUTO_TEST_CASE(NoFlags_NoCaptureChange_NoCaptureOnRoute)
111{
Vince Lehman218be0a2015-01-15 17:25:20 -0600112 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 Lehman4387e782014-06-19 16:57:45 -0500117
118 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600119 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500120
121 // Should generate 1 updates: 1 to update cost for /a
Vince Lehman218be0a2015-01-15 17:25:20 -0600122 eraseRoute("/a", 1, 128);
Vince Lehman4387e782014-06-19 16:57:45 -0500123
Vince Lehman76c751c2014-11-18 17:36:38 -0600124 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500125 BOOST_REQUIRE_EQUAL(updates.size(), 1);
126
Vince Lehman76c751c2014-11-18 17:36:38 -0600127 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 Lehman4387e782014-06-19 16:57:45 -0500132}
133
134BOOST_AUTO_TEST_CASE(MakeRibEmpty)
135{
Vince Lehman218be0a2015-01-15 17:25:20 -0600136 insertRoute("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
Vince Lehman4387e782014-06-19 16:57:45 -0500137
138 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600139 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500140
Vince Lehman218be0a2015-01-15 17:25:20 -0600141 // Should generate 1 updates: 1 to remove route from /
142 eraseRoute("/", 1, 0);
Vince Lehman4387e782014-06-19 16:57:45 -0500143
Vince Lehman76c751c2014-11-18 17:36:38 -0600144 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500145 BOOST_REQUIRE_EQUAL(updates.size(), 1);
146
Vince Lehman76c751c2014-11-18 17:36:38 -0600147 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 Lehman4387e782014-06-19 16:57:45 -0500151}
152
153BOOST_AUTO_TEST_CASE(NoFlags_NoCaptureChange_CaptureOnRoute)
154{
Vince Lehman218be0a2015-01-15 17:25:20 -0600155 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 Lehman4387e782014-06-19 16:57:45 -0500160
161 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600162 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500163
Vince Lehman218be0a2015-01-15 17:25:20 -0600164 // Should generate 1 updates: 1 to remove route from /a
165 eraseRoute("/a", 1, 128);
Vince Lehman4387e782014-06-19 16:57:45 -0500166
Vince Lehman76c751c2014-11-18 17:36:38 -0600167 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500168 BOOST_REQUIRE_EQUAL(updates.size(), 1);
169
Vince Lehman76c751c2014-11-18 17:36:38 -0600170 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 Lehman4387e782014-06-19 16:57:45 -0500174}
175
176BOOST_AUTO_TEST_CASE(BothFlags_NoCaptureChange_CaptureOnRoute)
177{
Vince Lehman218be0a2015-01-15 17:25:20 -0600178 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 Lehman4387e782014-06-19 16:57:45 -0500183 ndn::nfd::ROUTE_FLAG_CAPTURE));
184
185 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600186 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500187
188 // Should generate 2 updates: 1 to remove face1 from /a and
Vince Lehman218be0a2015-01-15 17:25:20 -0600189 // 1 to remove face1 from /a/b
190 eraseRoute("/a", 1, 128);
Vince Lehman4387e782014-06-19 16:57:45 -0500191
Vince Lehman76c751c2014-11-18 17:36:38 -0600192 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500193 BOOST_REQUIRE_EQUAL(updates.size(), 2);
194
Vince Lehman76c751c2014-11-18 17:36:38 -0600195 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 Lehman4387e782014-06-19 16:57:45 -0500199
200 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -0600201 BOOST_CHECK_EQUAL(update->name, "/a/b");
202 BOOST_CHECK_EQUAL(update->faceId, 1);
203 BOOST_CHECK_EQUAL(update->action, FibUpdate::REMOVE_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500204}
205
206BOOST_AUTO_TEST_CASE(BothFlags_CaptureChange_NoCaptureOnRoute)
207{
Vince Lehman218be0a2015-01-15 17:25:20 -0600208 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 Lehman4387e782014-06-19 16:57:45 -0500213 ndn::nfd::ROUTE_FLAG_CAPTURE));
214
215 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600216 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500217
218 // Should generate 2 updates: 1 to add face1 to /a and
219 // 1 to add face1 to /a/b
Vince Lehman218be0a2015-01-15 17:25:20 -0600220 eraseRoute("/a", 1, 128);
Vince Lehman4387e782014-06-19 16:57:45 -0500221
Vince Lehman76c751c2014-11-18 17:36:38 -0600222 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500223 BOOST_REQUIRE_EQUAL(updates.size(), 2);
224
Vince Lehman76c751c2014-11-18 17:36:38 -0600225 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 Lehman4387e782014-06-19 16:57:45 -0500230
231 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -0600232 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 Lehman4387e782014-06-19 16:57:45 -0500236}
237
238BOOST_AUTO_TEST_CASE(ChildInherit_NoCaptureChange_NoCaptureOnRoute)
239{
Vince Lehman218be0a2015-01-15 17:25:20 -0600240 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 Lehman4387e782014-06-19 16:57:45 -0500245
246 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600247 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500248
249 // Should generate 2 updates: 2 to add face1 to /a and /a/b
Vince Lehman218be0a2015-01-15 17:25:20 -0600250 eraseRoute("/a", 1, 128);
Vince Lehman4387e782014-06-19 16:57:45 -0500251
Vince Lehman76c751c2014-11-18 17:36:38 -0600252 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500253 BOOST_REQUIRE_EQUAL(updates.size(), 2);
254
Vince Lehman76c751c2014-11-18 17:36:38 -0600255 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 Lehman4387e782014-06-19 16:57:45 -0500260
261 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -0600262 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 Lehman4387e782014-06-19 16:57:45 -0500266}
267
268BOOST_AUTO_TEST_CASE(ChildInherit_NoCaptureChange_CaptureOnRoute)
269{
Vince Lehman218be0a2015-01-15 17:25:20 -0600270 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 Lehman4387e782014-06-19 16:57:45 -0500275
276 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600277 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500278
279 // Should generate 2 updates: 2 to remove face 1 from /a and /a/b
Vince Lehman218be0a2015-01-15 17:25:20 -0600280 eraseRoute("/a", 1, 128);
Vince Lehman4387e782014-06-19 16:57:45 -0500281
Vince Lehman76c751c2014-11-18 17:36:38 -0600282 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500283 BOOST_REQUIRE_EQUAL(updates.size(), 2);
284
Vince Lehman76c751c2014-11-18 17:36:38 -0600285 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 Lehman4387e782014-06-19 16:57:45 -0500289
290 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -0600291 BOOST_CHECK_EQUAL(update->name, "/a/b");
292 BOOST_CHECK_EQUAL(update->faceId, 1);
293 BOOST_CHECK_EQUAL(update->action, FibUpdate::REMOVE_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500294}
295
296BOOST_AUTO_TEST_CASE(Capture_CaptureChange_NoCaptureOnRoute)
297{
Vince Lehman218be0a2015-01-15 17:25:20 -0600298 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 Lehman4387e782014-06-19 16:57:45 -0500303
304 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600305 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500306
307 // Should generate 2 updates: 1 to update cost on /a and
308 // 1 to add face1 to /a/b
Vince Lehman218be0a2015-01-15 17:25:20 -0600309 eraseRoute("/a", 1 ,128);
Vince Lehman4387e782014-06-19 16:57:45 -0500310
Vince Lehman76c751c2014-11-18 17:36:38 -0600311 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500312 BOOST_REQUIRE_EQUAL(updates.size(), 2);
313
Vince Lehman76c751c2014-11-18 17:36:38 -0600314 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 Lehman4387e782014-06-19 16:57:45 -0500319
320 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -0600321 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 Lehman4387e782014-06-19 16:57:45 -0500325}
326
327BOOST_AUTO_TEST_CASE(Capture_NoCaptureChange_CaptureOnRoute)
328{
Vince Lehman218be0a2015-01-15 17:25:20 -0600329 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 Lehman4387e782014-06-19 16:57:45 -0500334
335 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600336 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500337
Vince Lehman218be0a2015-01-15 17:25:20 -0600338 // Should generate 1 updates: 1 to remove route from /a
339 eraseRoute("/a", 1, 128);
Vince Lehman4387e782014-06-19 16:57:45 -0500340
Vince Lehman76c751c2014-11-18 17:36:38 -0600341 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500342 BOOST_REQUIRE_EQUAL(updates.size(), 1);
343
Vince Lehman76c751c2014-11-18 17:36:38 -0600344 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 Lehman4387e782014-06-19 16:57:45 -0500348}
349
350BOOST_AUTO_TEST_CASE(EraseFaceById)
351{
Vince Lehman218be0a2015-01-15 17:25:20 -0600352 insertRoute("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
Vince Lehman76c751c2014-11-18 17:36:38 -0600353 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 Lehman4387e782014-06-19 16:57:45 -0500357
358 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600359 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500360
Vince Lehman76c751c2014-11-18 17:36:38 -0600361 // Should generate 2 updates: 2 to add face ID 1 to /a and /a/b
362 destroyFace(2);
Vince Lehman4387e782014-06-19 16:57:45 -0500363
Vince Lehman76c751c2014-11-18 17:36:38 -0600364 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
365 BOOST_REQUIRE_EQUAL(updates.size(), 2);
Vince Lehman4387e782014-06-19 16:57:45 -0500366
Vince Lehman76c751c2014-11-18 17:36:38 -0600367 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 Lehman4387e782014-06-19 16:57:45 -0500371
372 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -0600373 BOOST_CHECK_EQUAL(update->name, "/a/b");
374 BOOST_CHECK_EQUAL(update->faceId, 1);
375 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500376}
377
Vince Lehmanf91ab742015-04-23 15:26:55 -0500378BOOST_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 Lehman9aac8732016-01-11 15:49:23 -0600405BOOST_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 Lehman4387e782014-06-19 16:57:45 -0500423BOOST_AUTO_TEST_SUITE_END() // EraseFace
424
425BOOST_AUTO_TEST_SUITE_END() // FibUpdates
426
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400427} // namespace nfd::tests