blob: 3e8e98726585d32024809131d93a5906ef1e0f51 [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/*
Davide Pesaventocaa60cc2024-02-18 18:18:37 -05003 * Copyright (c) 2014-2024, 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
Davide Pesaventocaa60cc2024-02-18 18:18:37 -050033BOOST_AUTO_TEST_SUITE(Rib)
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080034BOOST_FIXTURE_TEST_SUITE(TestFibUpdates, FibUpdatesFixture)
Vince Lehman4387e782014-06-19 16:57:45 -050035BOOST_AUTO_TEST_SUITE(UpdateFace)
36
37BOOST_AUTO_TEST_CASE(TurnOffChildInheritLowerCost)
38{
Vince Lehman218be0a2015-01-15 17:25:20 -060039 insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
40 insertRoute("/a", 2, 0, 10, 0);
41 insertRoute("/", 1, 128, 25, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
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 2 updates: 1 to update the cost of / face 1 to 50 and
47 // 1 to update the cost of /a face 1 to 50
Vince Lehman218be0a2015-01-15 17:25:20 -060048 insertRoute("/", 1, 128, 75, 0);
Vince Lehman4387e782014-06-19 16:57:45 -050049
Vince Lehman76c751c2014-11-18 17:36:38 -060050 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -050051 BOOST_REQUIRE_EQUAL(updates.size(), 2);
52
Vince Lehman76c751c2014-11-18 17:36:38 -060053 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
54 BOOST_CHECK_EQUAL(update->name, "/");
55 BOOST_CHECK_EQUAL(update->faceId, 1);
56 BOOST_CHECK_EQUAL(update->cost, 50);
57 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -050058
59 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -060060 BOOST_CHECK_EQUAL(update->name, "/a");
61 BOOST_CHECK_EQUAL(update->faceId, 1);
62 BOOST_CHECK_EQUAL(update->cost, 50);
63 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -050064}
65
66BOOST_AUTO_TEST_CASE(UpdateOnLowerCostOnly)
67{
Vince Lehman218be0a2015-01-15 17:25:20 -060068 insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
69 insertRoute("/a", 2, 0, 10, 0);
70 insertRoute("/", 1, 128, 100, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
Vince Lehman4387e782014-06-19 16:57:45 -050071
72 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -060073 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -050074
75 // Should generate 0 updates
Vince Lehman218be0a2015-01-15 17:25:20 -060076 insertRoute("/", 1, 128, 75, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
Vince Lehman4387e782014-06-19 16:57:45 -050077
Vince Lehman76c751c2014-11-18 17:36:38 -060078 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -050079 BOOST_REQUIRE_EQUAL(updates.size(), 0);
80
81 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -060082 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -050083
84 // Should generate 2 updates
Vince Lehman218be0a2015-01-15 17:25:20 -060085 insertRoute("/", 1, 128, 25, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
Vince Lehman4387e782014-06-19 16:57:45 -050086
87 updates = getSortedFibUpdates();
88 BOOST_REQUIRE_EQUAL(updates.size(), 2);
89
Vince Lehman76c751c2014-11-18 17:36:38 -060090 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
91 BOOST_CHECK_EQUAL(update->name, "/");
92 BOOST_CHECK_EQUAL(update->faceId, 1);
93 BOOST_CHECK_EQUAL(update->cost, 25);
94 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -050095
96 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -060097 BOOST_CHECK_EQUAL(update->name, "/a");
98 BOOST_CHECK_EQUAL(update->faceId, 1);
99 BOOST_CHECK_EQUAL(update->cost, 25);
100 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500101}
102
103BOOST_AUTO_TEST_CASE(NoChangeInCost)
104{
Vince Lehman218be0a2015-01-15 17:25:20 -0600105 insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
106 insertRoute("/a", 2, 0, 100, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
107 insertRoute("/a/b", 3, 0, 10, 0);
108 insertRoute("/a/c", 4, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
Vince Lehman4387e782014-06-19 16:57:45 -0500109
110 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600111 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500112
113 // Should generate 0 updates
Vince Lehman218be0a2015-01-15 17:25:20 -0600114 insertRoute("/a", 2, 0, 100, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
Vince Lehman4387e782014-06-19 16:57:45 -0500115
Vince Lehman76c751c2014-11-18 17:36:38 -0600116 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500117 BOOST_REQUIRE_EQUAL(updates.size(), 0);
118}
119
120BOOST_AUTO_TEST_CASE(ChangeCost)
121{
Vince Lehman218be0a2015-01-15 17:25:20 -0600122 insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
123 insertRoute("/a", 2, 0, 100, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
124 insertRoute("/a/b", 3, 0, 10, 0);
125 insertRoute("/a/c", 4, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
Vince Lehman4387e782014-06-19 16:57:45 -0500126
127 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600128 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500129
130 // Should generate 2 updates: 1 to add face2 with new cost to /a and
131 // 1 to add face2 with new cost to /a/b
Vince Lehman218be0a2015-01-15 17:25:20 -0600132 insertRoute("/a", 2, 0, 300, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
Vince Lehman4387e782014-06-19 16:57:45 -0500133
Vince Lehman76c751c2014-11-18 17:36:38 -0600134 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500135 BOOST_REQUIRE_EQUAL(updates.size(), 2);
136
Vince Lehman76c751c2014-11-18 17:36:38 -0600137 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
138 BOOST_CHECK_EQUAL(update->name, "/a");
139 BOOST_CHECK_EQUAL(update->faceId, 2);
140 BOOST_CHECK_EQUAL(update->cost, 300);
141 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500142
143 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -0600144 BOOST_CHECK_EQUAL(update->name, "/a/b");
145 BOOST_CHECK_EQUAL(update->faceId, 2);
146 BOOST_CHECK_EQUAL(update->cost, 300);
147 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500148}
149
150BOOST_AUTO_TEST_CASE(TurnOnChildInherit)
151{
Vince Lehman218be0a2015-01-15 17:25:20 -0600152 insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
153 insertRoute("/a", 2, 0, 10, 0);
154 insertRoute("/a/b", 3, 0, 10, 0);
155 insertRoute("/a/c", 4, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
Vince Lehman4387e782014-06-19 16:57:45 -0500156
157 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600158 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500159
160 // Turn on child inherit flag for the entry in /a
161 // Should generate 1 updates: 1 to add face to /a/b
Vince Lehman218be0a2015-01-15 17:25:20 -0600162 insertRoute("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
Vince Lehman4387e782014-06-19 16:57:45 -0500163
Vince Lehman76c751c2014-11-18 17:36:38 -0600164 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500165 BOOST_REQUIRE_EQUAL(updates.size(), 1);
166
Vince Lehman76c751c2014-11-18 17:36:38 -0600167 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
168 BOOST_CHECK_EQUAL(update->name, "/a/b");
169 BOOST_CHECK_EQUAL(update->faceId, 2);
170 BOOST_CHECK_EQUAL(update->cost, 10);
171 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500172}
173
174BOOST_AUTO_TEST_CASE(TurnOffChildInherit)
175{
Vince Lehman218be0a2015-01-15 17:25:20 -0600176 insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
177 insertRoute("/a", 1, 0, 100, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
178 insertRoute("/a/b", 2, 0, 10, 0);
179 insertRoute("/a/c", 1, 0, 25, 0);
Vince Lehman4387e782014-06-19 16:57:45 -0500180
181 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600182 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500183
184 // Turn off child inherit flag for the entry in /a
185 // Should generate 1 update: 1 to add face1 to /a/b
Vince Lehman218be0a2015-01-15 17:25:20 -0600186 insertRoute("/a", 1, 0, 100, 0);
Vince Lehman4387e782014-06-19 16:57:45 -0500187
Vince Lehman76c751c2014-11-18 17:36:38 -0600188 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500189 BOOST_REQUIRE_EQUAL(updates.size(), 1);
190
Vince Lehman76c751c2014-11-18 17:36:38 -0600191 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
192 BOOST_CHECK_EQUAL(update->name, "/a/b");
193 BOOST_CHECK_EQUAL(update->faceId, 1);
194 BOOST_CHECK_EQUAL(update->cost, 50);
195 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500196}
197
198BOOST_AUTO_TEST_CASE(TurnOnCapture)
199{
Vince Lehman218be0a2015-01-15 17:25:20 -0600200 insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
201 insertRoute("/a", 2, 0, 10, 0);
202 insertRoute("/a/b", 3, 0, 10, 0);
203 insertRoute("/a/c", 1, 0, 10, 0);
Vince Lehman4387e782014-06-19 16:57:45 -0500204
205 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600206 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500207
208 // Turn on capture flag for the entry in /a
209 // Should generate 2 updates: 1 to remove face1 from /a and
210 // 1 to remove face1 from /a/b
Vince Lehman218be0a2015-01-15 17:25:20 -0600211 insertRoute("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
Vince Lehman4387e782014-06-19 16:57:45 -0500212
Vince Lehman76c751c2014-11-18 17:36:38 -0600213 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500214 BOOST_REQUIRE_EQUAL(updates.size(), 2);
215
Vince Lehman76c751c2014-11-18 17:36:38 -0600216 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
217 BOOST_CHECK_EQUAL(update->name, "/a");
218 BOOST_CHECK_EQUAL(update->faceId, 1);
219 BOOST_CHECK_EQUAL(update->action, FibUpdate::REMOVE_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
227BOOST_AUTO_TEST_CASE(TurnOffCapture)
228{
Vince Lehman218be0a2015-01-15 17:25:20 -0600229 insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
230 insertRoute("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
231 insertRoute("/a/b", 3, 0, 10, 0);
232 insertRoute("/a/c", 1, 0, 10, 0);
Vince Lehman4387e782014-06-19 16:57:45 -0500233
234 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600235 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500236
237 // Turn off capture flag for the entry in /a
238 // Should generate 2 updates: 1 to add face1 to /a and
239 // 1 to add face1 to /a/b
Vince Lehman218be0a2015-01-15 17:25:20 -0600240 insertRoute("/a", 2, 0, 10, 0);
Vince Lehman4387e782014-06-19 16:57:45 -0500241
Vince Lehman76c751c2014-11-18 17:36:38 -0600242 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500243 BOOST_REQUIRE_EQUAL(updates.size(), 2);
244
Vince Lehman76c751c2014-11-18 17:36:38 -0600245 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
246 BOOST_CHECK_EQUAL(update->name, "/a");
247 BOOST_CHECK_EQUAL(update->faceId, 1);
248 BOOST_CHECK_EQUAL(update->cost, 50);
249 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500250
251 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -0600252 BOOST_CHECK_EQUAL(update->name, "/a/b");
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
258BOOST_AUTO_TEST_SUITE_END() // UpdateFace
Vince Lehman4387e782014-06-19 16:57:45 -0500259BOOST_AUTO_TEST_SUITE_END() // FibUpdates
Davide Pesaventocaa60cc2024-02-18 18:18:37 -0500260BOOST_AUTO_TEST_SUITE_END() // Rib
Vince Lehman4387e782014-06-19 16:57:45 -0500261
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400262} // namespace nfd::tests