blob: 79924df9aba9694181eb9a0665c718e8050a77ea [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(NewFace)
36
37BOOST_AUTO_TEST_CASE(Basic)
38{
39 // should generate 1 update
Vince Lehman218be0a2015-01-15 17:25:20 -060040 insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
Vince Lehman4387e782014-06-19 16:57:45 -050041
Vince Lehman76c751c2014-11-18 17:36:38 -060042 FibUpdater::FibUpdateList updates = getFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -050043 BOOST_REQUIRE_EQUAL(updates.size(), 1);
44
Vince Lehman76c751c2014-11-18 17:36:38 -060045 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
Vince Lehman4387e782014-06-19 16:57:45 -050046
Vince Lehman76c751c2014-11-18 17:36:38 -060047 BOOST_CHECK_EQUAL(update->name, "/");
48 BOOST_CHECK_EQUAL(update->faceId, 1);
49 BOOST_CHECK_EQUAL(update->cost, 50);
50 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -050051
52 // Clear any updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -060053 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -050054
55 // should generate 2 updates
Vince Lehman218be0a2015-01-15 17:25:20 -060056 insertRoute("/a", 2, 0, 50, 0);
Vince Lehman4387e782014-06-19 16:57:45 -050057
58 updates = getSortedFibUpdates();
59 BOOST_REQUIRE_EQUAL(updates.size(), 2);
60
61 update = updates.begin();
Vince Lehman76c751c2014-11-18 17:36:38 -060062 BOOST_CHECK_EQUAL(update->name, "/a");
63 BOOST_CHECK_EQUAL(update->faceId, 1);
64 BOOST_CHECK_EQUAL(update->cost, 50);
65 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -050066
67 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -060068 BOOST_CHECK_EQUAL(update->name, "/a");
69 BOOST_CHECK_EQUAL(update->faceId, 2);
70 BOOST_CHECK_EQUAL(update->cost, 50);
71 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -050072
73 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -060074 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -050075
76 // should generate 2 updates
Vince Lehman218be0a2015-01-15 17:25:20 -060077 insertRoute("/a/b", 3, 0, 10, 0);
Vince Lehman4387e782014-06-19 16:57:45 -050078
79 updates = getSortedFibUpdates();
80 BOOST_REQUIRE_EQUAL(updates.size(), 2);
81
82 update = updates.begin();
Vince Lehman76c751c2014-11-18 17:36:38 -060083 BOOST_CHECK_EQUAL(update->name, "/a/b");
84 BOOST_CHECK_EQUAL(update->faceId, 1);
85 BOOST_CHECK_EQUAL(update->cost, 50);
86 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -050087
88 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -060089 BOOST_CHECK_EQUAL(update->name, "/a/b");
90 BOOST_CHECK_EQUAL(update->faceId, 3);
91 BOOST_CHECK_EQUAL(update->cost, 10);
92 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -050093}
94
95BOOST_AUTO_TEST_CASE(UpdateOnLowerCostNoChildInherit)
96{
Vince Lehman218be0a2015-01-15 17:25:20 -060097 insertRoute("/", 1, 0, 50, 0);
Vince Lehman4387e782014-06-19 16:57:45 -050098
99 // Clear any updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600100 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500101
102 // Should generate 0 updates
Vince Lehman218be0a2015-01-15 17:25:20 -0600103 insertRoute("/", 1, 128, 75, 0);
Vince Lehman4387e782014-06-19 16:57:45 -0500104
Vince Lehman76c751c2014-11-18 17:36:38 -0600105 BOOST_CHECK_EQUAL(getFibUpdates().size(), 0);
Vince Lehman4387e782014-06-19 16:57:45 -0500106}
107
108BOOST_AUTO_TEST_CASE(UpdateOnLowerCostOnly)
109{
Vince Lehman218be0a2015-01-15 17:25:20 -0600110 insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
111 insertRoute("/a", 2, 0, 10, 0);
Vince Lehman4387e782014-06-19 16:57:45 -0500112
113 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600114 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500115
116 // Should generate 2 updates: to update cost for face 1 on / and /a
Vince Lehman218be0a2015-01-15 17:25:20 -0600117 insertRoute("/", 1, 0, 25, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
Vince Lehman4387e782014-06-19 16:57:45 -0500118
Vince Lehman76c751c2014-11-18 17:36:38 -0600119 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500120 BOOST_REQUIRE_EQUAL(updates.size(), 2);
121
Vince Lehman76c751c2014-11-18 17:36:38 -0600122 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
123 BOOST_CHECK_EQUAL(update->name, "/");
124 BOOST_CHECK_EQUAL(update->faceId, 1);
125 BOOST_CHECK_EQUAL(update->cost, 25);
126 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500127
128 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -0600129 BOOST_CHECK_EQUAL(update->name, "/a");
130 BOOST_CHECK_EQUAL(update->faceId, 1);
131 BOOST_CHECK_EQUAL(update->cost, 25);
132 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500133
134 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600135 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500136
137 // Should generate 0 updates
Vince Lehman218be0a2015-01-15 17:25:20 -0600138 insertRoute("/", 1, 128, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
Vince Lehman4387e782014-06-19 16:57:45 -0500139
Vince Lehman76c751c2014-11-18 17:36:38 -0600140 BOOST_CHECK_EQUAL(getFibUpdates().size(), 0);
Vince Lehman4387e782014-06-19 16:57:45 -0500141}
142
143BOOST_AUTO_TEST_CASE(NoCaptureChangeWithoutChildInherit)
144{
Vince Lehman218be0a2015-01-15 17:25:20 -0600145 insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
146 insertRoute("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
147 insertRoute("/a/b", 3, 0, 10, 0);
148 insertRoute("/a/c", 4, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
Vince Lehman4387e782014-06-19 16:57:45 -0500149
150 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600151 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500152
153 // Should generate 1 update: 1 to add face 5 to /a
Vince Lehman218be0a2015-01-15 17:25:20 -0600154 insertRoute("/a", 5, 128, 50, 0);
Vince Lehman4387e782014-06-19 16:57:45 -0500155
Vince Lehman76c751c2014-11-18 17:36:38 -0600156 const FibUpdater::FibUpdateList& updates = getFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500157 BOOST_REQUIRE_EQUAL(updates.size(), 1);
158
Vince Lehman76c751c2014-11-18 17:36:38 -0600159 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
Vince Lehman4387e782014-06-19 16:57:45 -0500160
Vince Lehman76c751c2014-11-18 17:36:38 -0600161 BOOST_CHECK_EQUAL(update->name, "/a");
162 BOOST_CHECK_EQUAL(update->faceId, 5);
163 BOOST_CHECK_EQUAL(update->cost, 50);
164 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500165}
166
167BOOST_AUTO_TEST_CASE(NoCaptureChangeWithChildInherit)
168{
Vince Lehman218be0a2015-01-15 17:25:20 -0600169 insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
170 insertRoute("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
171 insertRoute("/a/b", 3, 0, 10, 0);
172 insertRoute("/a/c", 4, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
Vince Lehman4387e782014-06-19 16:57:45 -0500173
174 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600175 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500176
Vince Lehman218be0a2015-01-15 17:25:20 -0600177 // Should generate 2 updates: one for the inserted route and
178 // one to add route to /a/b
179 insertRoute("/a", 4, 128, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
Vince Lehman4387e782014-06-19 16:57:45 -0500180
Vince Lehman76c751c2014-11-18 17:36:38 -0600181 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500182 BOOST_REQUIRE_EQUAL(updates.size(), 2);
183
Vince Lehman76c751c2014-11-18 17:36:38 -0600184 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
185 BOOST_CHECK_EQUAL(update->name, "/a");
186 BOOST_CHECK_EQUAL(update->faceId, 4);
187 BOOST_CHECK_EQUAL(update->cost, 5);
188 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500189
190 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -0600191 BOOST_CHECK_EQUAL(update->name, "/a/b");
192 BOOST_CHECK_EQUAL(update->faceId, 4);
193 BOOST_CHECK_EQUAL(update->cost, 5);
194 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500195}
196
197BOOST_AUTO_TEST_CASE(CaptureTurnedOnWithoutChildInherit)
198{
Vince Lehman218be0a2015-01-15 17:25:20 -0600199 insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
200 insertRoute("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
201 insertRoute("/a/b", 3, 0, 10, 0);
202 insertRoute("/a/c", 4, 0, 10, 0);
Vince Lehman4387e782014-06-19 16:57:45 -0500203
204 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600205 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500206
207 // Should generate 3 updates:
Vince Lehman218be0a2015-01-15 17:25:20 -0600208 // - one for the inserted route for /a and
Vince Lehman4387e782014-06-19 16:57:45 -0500209 // - two to remove face1 from /a/b and /a/c
Vince Lehman218be0a2015-01-15 17:25:20 -0600210 insertRoute("/a", 1, 128, 50, ndn::nfd::ROUTE_FLAG_CAPTURE);
Vince Lehman4387e782014-06-19 16:57:45 -0500211
Vince Lehman76c751c2014-11-18 17:36:38 -0600212 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500213 BOOST_REQUIRE_EQUAL(updates.size(), 3);
214
Vince Lehman76c751c2014-11-18 17:36:38 -0600215 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
216 BOOST_CHECK_EQUAL(update->name, "/a");
217 BOOST_CHECK_EQUAL(update->faceId, 1);
218 BOOST_CHECK_EQUAL(update->cost, 50);
219 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500220
221 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -0600222 BOOST_CHECK_EQUAL(update->name, "/a/b");
223 BOOST_CHECK_EQUAL(update->faceId, 1);
224 BOOST_CHECK_EQUAL(update->action, FibUpdate::REMOVE_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500225
226 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -0600227 BOOST_CHECK_EQUAL(update->name, "/a/c");
228 BOOST_CHECK_EQUAL(update->faceId, 1);
229 BOOST_CHECK_EQUAL(update->action, FibUpdate::REMOVE_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500230}
231
232BOOST_AUTO_TEST_CASE(CaptureTurnedOnWithChildInherit)
233{
Vince Lehman218be0a2015-01-15 17:25:20 -0600234 insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
235 insertRoute("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
236 insertRoute("/a/b", 3, 0, 10, 0);
237 insertRoute("/a/c", 4, 0, 10, 0);
Vince Lehman4387e782014-06-19 16:57:45 -0500238
239 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600240 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500241
242 // Should generate 2 updates:
Vince Lehman218be0a2015-01-15 17:25:20 -0600243 // - one for the inserted route for /a and
Vince Lehman4387e782014-06-19 16:57:45 -0500244 // - one to update /a/b with the new cost
Vince Lehman218be0a2015-01-15 17:25:20 -0600245 insertRoute("/a", 1, 128, 50, (ndn::nfd::ROUTE_FLAG_CAPTURE |
Vince Lehman4387e782014-06-19 16:57:45 -0500246 ndn::nfd::ROUTE_FLAG_CHILD_INHERIT));
247
Vince Lehman76c751c2014-11-18 17:36:38 -0600248 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500249 BOOST_REQUIRE_EQUAL(updates.size(), 3);
250
Vince Lehman76c751c2014-11-18 17:36:38 -0600251 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
252 BOOST_CHECK_EQUAL(update->name, "/a");
253 BOOST_CHECK_EQUAL(update->faceId, 1);
254 BOOST_CHECK_EQUAL(update->cost, 50);
255 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500256
257 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -0600258 BOOST_CHECK_EQUAL(update->name, "/a/b");
259 BOOST_CHECK_EQUAL(update->faceId, 1);
260 BOOST_CHECK_EQUAL(update->cost, 50);
261 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500262}
263
264BOOST_AUTO_TEST_SUITE_END() // NewFace
265
266BOOST_AUTO_TEST_SUITE_END() // FibUpdates
267
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400268} // namespace nfd::tests