blob: 084cf40d741967794b6877870ef9d3041e2cef88 [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(NewNamespace)
36
37BOOST_AUTO_TEST_CASE(NoFlags)
38{
Vince Lehman218be0a2015-01-15 17:25:20 -060039 // No flags, empty RIB, should generate 1 update for the inserted route
40 insertRoute("/a/b", 1, 0, 10, 0);
Vince Lehman4387e782014-06-19 16:57:45 -050041
Vince Lehman76c751c2014-11-18 17:36:38 -060042 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
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();
46 BOOST_CHECK_EQUAL(update->name, "/a/b");
47 BOOST_CHECK_EQUAL(update->faceId, 1);
48 BOOST_CHECK_EQUAL(update->cost, 10);
49 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -050050
51 // Reset RIB
Vince Lehman218be0a2015-01-15 17:25:20 -060052 eraseRoute("/a/b", 1, 0);
Vince Lehman76c751c2014-11-18 17:36:38 -060053 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -050054
55 // Parent with child inherit flag
Vince Lehman218be0a2015-01-15 17:25:20 -060056 insertRoute("/a", 2, 0, 70, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
57 insertRoute("/a", 3, 0, 30, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
Vince Lehman4387e782014-06-19 16:57:45 -050058
59 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -060060 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -050061
Vince Lehman218be0a2015-01-15 17:25:20 -060062 // Should generate 3 updates, 1 for the inserted route and 2 from inheritance
63 insertRoute("/a/b", 1, 0, 10, 0);
Vince Lehman4387e782014-06-19 16:57:45 -050064
65 updates = getSortedFibUpdates();
66 BOOST_REQUIRE_EQUAL(updates.size(), 3);
67
68 update = updates.begin();
Vince Lehman76c751c2014-11-18 17:36:38 -060069 BOOST_CHECK_EQUAL(update->name, "/a/b");
70 BOOST_CHECK_EQUAL(update->faceId, 1);
71 BOOST_CHECK_EQUAL(update->cost, 10);
72 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -050073
74 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -060075 BOOST_CHECK_EQUAL(update->name, "/a/b");
76 BOOST_CHECK_EQUAL(update->faceId, 2);
77 BOOST_CHECK_EQUAL(update->cost, 70);
78 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -050079
80 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -060081 BOOST_CHECK_EQUAL(update->name, "/a/b");
82 BOOST_CHECK_EQUAL(update->faceId, 3);
83 BOOST_CHECK_EQUAL(update->cost, 30);
84 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -050085}
86
87BOOST_AUTO_TEST_CASE(BothFlags)
88{
Vince Lehman218be0a2015-01-15 17:25:20 -060089 // Empty RIB, should generate 1 update for the inserted route
90 insertRoute("/a", 1, 0, 10, (ndn::nfd::ROUTE_FLAG_CHILD_INHERIT | ndn::nfd::ROUTE_FLAG_CAPTURE));
Vince Lehman4387e782014-06-19 16:57:45 -050091
Vince Lehman76c751c2014-11-18 17:36:38 -060092 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -050093 BOOST_REQUIRE_EQUAL(updates.size(), 1);
94
Vince Lehman76c751c2014-11-18 17:36:38 -060095 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
96 BOOST_CHECK_EQUAL(update->name, "/a");
97 BOOST_CHECK_EQUAL(update->faceId, 1);
98 BOOST_CHECK_EQUAL(update->cost, 10);
99 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500100
101 // Reset RIB
Vince Lehman218be0a2015-01-15 17:25:20 -0600102 eraseRoute("/a", 1, 0);
Vince Lehman76c751c2014-11-18 17:36:38 -0600103 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500104
Vince Lehman218be0a2015-01-15 17:25:20 -0600105 insertRoute("/", 2, 0, 70, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
106 insertRoute("/a/b", 3, 0, 30, 0);
Vince Lehman4387e782014-06-19 16:57:45 -0500107
108 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600109 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500110
Vince Lehman218be0a2015-01-15 17:25:20 -0600111 // Should generate 3 updates, 1 for the inserted route, 1 to add the route to the child,
112 // and 1 to remove the previously inherited route
113 insertRoute("/a", 1, 0, 10, (ndn::nfd::ROUTE_FLAG_CHILD_INHERIT | ndn::nfd::ROUTE_FLAG_CAPTURE));
Vince Lehman4387e782014-06-19 16:57:45 -0500114
115 updates = getSortedFibUpdates();
116 BOOST_REQUIRE_EQUAL(updates.size(), 3);
117
118 update = updates.begin();
Vince Lehman76c751c2014-11-18 17:36:38 -0600119 BOOST_CHECK_EQUAL(update->name, "/a");
120 BOOST_CHECK_EQUAL(update->faceId, 1);
121 BOOST_CHECK_EQUAL(update->cost, 10);
122 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500123
124 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -0600125 BOOST_CHECK_EQUAL(update->name, "/a/b");
126 BOOST_CHECK_EQUAL(update->faceId, 1);
127 BOOST_CHECK_EQUAL(update->cost, 10);
128 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500129
130 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -0600131 BOOST_CHECK_EQUAL(update->name, "/a/b");
132 BOOST_CHECK_EQUAL(update->faceId, 2);
133 BOOST_CHECK_EQUAL(update->action, FibUpdate::REMOVE_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500134}
135
136BOOST_AUTO_TEST_CASE(ChildInherit)
137{
Vince Lehman218be0a2015-01-15 17:25:20 -0600138 insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
139 insertRoute("/a/b", 2, 0, 10, 0);
140 insertRoute("/a/c", 3, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
Vince Lehman4387e782014-06-19 16:57:45 -0500141
142 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600143 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500144
Vince Lehman218be0a2015-01-15 17:25:20 -0600145 // Should generate 2 updates: 1 for the inserted route and 1 to add the route to "/a/b"
146 insertRoute("/a", 1, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
Vince Lehman4387e782014-06-19 16:57:45 -0500147
Vince Lehman76c751c2014-11-18 17:36:38 -0600148 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500149 BOOST_REQUIRE_EQUAL(updates.size(), 2);
150
Vince Lehman76c751c2014-11-18 17:36:38 -0600151 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
152 BOOST_CHECK_EQUAL(update->name, "/a");
153 BOOST_CHECK_EQUAL(update->faceId, 1);
154 BOOST_CHECK_EQUAL(update->cost, 10);
155 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500156
157 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -0600158 BOOST_CHECK_EQUAL(update->name, "/a/b");
159 BOOST_CHECK_EQUAL(update->faceId, 1);
160 BOOST_CHECK_EQUAL(update->cost, 10);
161 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500162}
163
164BOOST_AUTO_TEST_CASE(Capture)
165{
Vince Lehman218be0a2015-01-15 17:25:20 -0600166 insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
167 insertRoute("/a/b", 2, 0, 10, 0);
168 insertRoute("/a/c", 3, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
Vince Lehman4387e782014-06-19 16:57:45 -0500169
170 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600171 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500172
Vince Lehman218be0a2015-01-15 17:25:20 -0600173 // Should generate 2 updates: 1 for the inserted route and
174 // 1 to remove the inherited route from "/a/b"
175 insertRoute("/a", 1, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
Vince Lehman4387e782014-06-19 16:57:45 -0500176
Vince Lehman76c751c2014-11-18 17:36:38 -0600177 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500178 BOOST_REQUIRE_EQUAL(updates.size(), 2);
179
Vince Lehman76c751c2014-11-18 17:36:38 -0600180 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
181 BOOST_CHECK_EQUAL(update->name, "/a");
182 BOOST_CHECK_EQUAL(update->faceId, 1);
183 BOOST_CHECK_EQUAL(update->cost, 10);
184 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500185
186 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -0600187 BOOST_CHECK_EQUAL(update->name, "/a/b");
188 BOOST_CHECK_EQUAL(update->faceId, 1);
189 BOOST_CHECK_EQUAL(update->action, FibUpdate::REMOVE_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500190}
191
192BOOST_AUTO_TEST_SUITE_END() // NewNamespace
Vince Lehman4387e782014-06-19 16:57:45 -0500193BOOST_AUTO_TEST_SUITE_END() // FibUpdates
Davide Pesaventocaa60cc2024-02-18 18:18:37 -0500194BOOST_AUTO_TEST_SUITE_END() // Rib
Vince Lehman4387e782014-06-19 16:57:45 -0500195
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400196} // namespace nfd::tests