blob: 49cd56fe92d5339ef2f4acafb5191a91fdf5a67f [file] [log] [blame]
Vince Lehman4387e782014-06-19 16:57:45 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev7c10b3b2015-01-20 12:24:27 -08003 * Copyright (c) 2014-2015, Regents of the University of California,
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 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
31namespace nfd {
32namespace rib {
33namespace tests {
34
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080035BOOST_FIXTURE_TEST_SUITE(TestFibUpdates, FibUpdatesFixture)
Vince Lehman4387e782014-06-19 16:57:45 -050036
37BOOST_AUTO_TEST_SUITE(NewFace)
38
39BOOST_AUTO_TEST_CASE(Basic)
40{
41 // should generate 1 update
Vince Lehman218be0a2015-01-15 17:25:20 -060042 insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
Vince Lehman4387e782014-06-19 16:57:45 -050043
Vince Lehman76c751c2014-11-18 17:36:38 -060044 FibUpdater::FibUpdateList updates = getFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -050045 BOOST_REQUIRE_EQUAL(updates.size(), 1);
46
Vince Lehman76c751c2014-11-18 17:36:38 -060047 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
Vince Lehman4387e782014-06-19 16:57:45 -050048
Vince Lehman76c751c2014-11-18 17:36:38 -060049 BOOST_CHECK_EQUAL(update->name, "/");
50 BOOST_CHECK_EQUAL(update->faceId, 1);
51 BOOST_CHECK_EQUAL(update->cost, 50);
52 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -050053
54 // Clear any updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -060055 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -050056
57 // should generate 2 updates
Vince Lehman218be0a2015-01-15 17:25:20 -060058 insertRoute("/a", 2, 0, 50, 0);
Vince Lehman4387e782014-06-19 16:57:45 -050059
60 updates = getSortedFibUpdates();
61 BOOST_REQUIRE_EQUAL(updates.size(), 2);
62
63 update = updates.begin();
Vince Lehman76c751c2014-11-18 17:36:38 -060064 BOOST_CHECK_EQUAL(update->name, "/a");
65 BOOST_CHECK_EQUAL(update->faceId, 1);
66 BOOST_CHECK_EQUAL(update->cost, 50);
67 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -050068
69 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -060070 BOOST_CHECK_EQUAL(update->name, "/a");
71 BOOST_CHECK_EQUAL(update->faceId, 2);
72 BOOST_CHECK_EQUAL(update->cost, 50);
73 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -050074
75 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -060076 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -050077
78 // should generate 2 updates
Vince Lehman218be0a2015-01-15 17:25:20 -060079 insertRoute("/a/b", 3, 0, 10, 0);
Vince Lehman4387e782014-06-19 16:57:45 -050080
81 updates = getSortedFibUpdates();
82 BOOST_REQUIRE_EQUAL(updates.size(), 2);
83
84 update = updates.begin();
Vince Lehman76c751c2014-11-18 17:36:38 -060085 BOOST_CHECK_EQUAL(update->name, "/a/b");
86 BOOST_CHECK_EQUAL(update->faceId, 1);
87 BOOST_CHECK_EQUAL(update->cost, 50);
88 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -050089
90 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -060091 BOOST_CHECK_EQUAL(update->name, "/a/b");
92 BOOST_CHECK_EQUAL(update->faceId, 3);
93 BOOST_CHECK_EQUAL(update->cost, 10);
94 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -050095}
96
97BOOST_AUTO_TEST_CASE(UpdateOnLowerCostNoChildInherit)
98{
Vince Lehman218be0a2015-01-15 17:25:20 -060099 insertRoute("/", 1, 0, 50, 0);
Vince Lehman4387e782014-06-19 16:57:45 -0500100
101 // Clear any updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600102 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500103
104 // Should generate 0 updates
Vince Lehman218be0a2015-01-15 17:25:20 -0600105 insertRoute("/", 1, 128, 75, 0);
Vince Lehman4387e782014-06-19 16:57:45 -0500106
Vince Lehman76c751c2014-11-18 17:36:38 -0600107 BOOST_CHECK_EQUAL(getFibUpdates().size(), 0);
Vince Lehman4387e782014-06-19 16:57:45 -0500108}
109
110BOOST_AUTO_TEST_CASE(UpdateOnLowerCostOnly)
111{
Vince Lehman218be0a2015-01-15 17:25:20 -0600112 insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
113 insertRoute("/a", 2, 0, 10, 0);
Vince Lehman4387e782014-06-19 16:57:45 -0500114
115 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600116 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500117
118 // Should generate 2 updates: to update cost for face 1 on / and /a
Vince Lehman218be0a2015-01-15 17:25:20 -0600119 insertRoute("/", 1, 0, 25, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
Vince Lehman4387e782014-06-19 16:57:45 -0500120
Vince Lehman76c751c2014-11-18 17:36:38 -0600121 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500122 BOOST_REQUIRE_EQUAL(updates.size(), 2);
123
Vince Lehman76c751c2014-11-18 17:36:38 -0600124 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
125 BOOST_CHECK_EQUAL(update->name, "/");
126 BOOST_CHECK_EQUAL(update->faceId, 1);
127 BOOST_CHECK_EQUAL(update->cost, 25);
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");
132 BOOST_CHECK_EQUAL(update->faceId, 1);
133 BOOST_CHECK_EQUAL(update->cost, 25);
134 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500135
136 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600137 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500138
139 // Should generate 0 updates
Vince Lehman218be0a2015-01-15 17:25:20 -0600140 insertRoute("/", 1, 128, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
Vince Lehman4387e782014-06-19 16:57:45 -0500141
Vince Lehman76c751c2014-11-18 17:36:38 -0600142 BOOST_CHECK_EQUAL(getFibUpdates().size(), 0);
Vince Lehman4387e782014-06-19 16:57:45 -0500143}
144
145BOOST_AUTO_TEST_CASE(NoCaptureChangeWithoutChildInherit)
146{
Vince Lehman218be0a2015-01-15 17:25:20 -0600147 insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
148 insertRoute("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
149 insertRoute("/a/b", 3, 0, 10, 0);
150 insertRoute("/a/c", 4, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
Vince Lehman4387e782014-06-19 16:57:45 -0500151
152 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600153 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500154
155 // Should generate 1 update: 1 to add face 5 to /a
Vince Lehman218be0a2015-01-15 17:25:20 -0600156 insertRoute("/a", 5, 128, 50, 0);
Vince Lehman4387e782014-06-19 16:57:45 -0500157
Vince Lehman76c751c2014-11-18 17:36:38 -0600158 const FibUpdater::FibUpdateList& updates = getFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500159 BOOST_REQUIRE_EQUAL(updates.size(), 1);
160
Vince Lehman76c751c2014-11-18 17:36:38 -0600161 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
Vince Lehman4387e782014-06-19 16:57:45 -0500162
Vince Lehman76c751c2014-11-18 17:36:38 -0600163 BOOST_CHECK_EQUAL(update->name, "/a");
164 BOOST_CHECK_EQUAL(update->faceId, 5);
165 BOOST_CHECK_EQUAL(update->cost, 50);
166 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500167}
168
169BOOST_AUTO_TEST_CASE(NoCaptureChangeWithChildInherit)
170{
Vince Lehman218be0a2015-01-15 17:25:20 -0600171 insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
172 insertRoute("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
173 insertRoute("/a/b", 3, 0, 10, 0);
174 insertRoute("/a/c", 4, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
Vince Lehman4387e782014-06-19 16:57:45 -0500175
176 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600177 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500178
Vince Lehman218be0a2015-01-15 17:25:20 -0600179 // Should generate 2 updates: one for the inserted route and
180 // one to add route to /a/b
181 insertRoute("/a", 4, 128, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
Vince Lehman4387e782014-06-19 16:57:45 -0500182
Vince Lehman76c751c2014-11-18 17:36:38 -0600183 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500184 BOOST_REQUIRE_EQUAL(updates.size(), 2);
185
Vince Lehman76c751c2014-11-18 17:36:38 -0600186 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
187 BOOST_CHECK_EQUAL(update->name, "/a");
188 BOOST_CHECK_EQUAL(update->faceId, 4);
189 BOOST_CHECK_EQUAL(update->cost, 5);
190 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500191
192 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -0600193 BOOST_CHECK_EQUAL(update->name, "/a/b");
194 BOOST_CHECK_EQUAL(update->faceId, 4);
195 BOOST_CHECK_EQUAL(update->cost, 5);
196 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500197}
198
199BOOST_AUTO_TEST_CASE(CaptureTurnedOnWithoutChildInherit)
200{
Vince Lehman218be0a2015-01-15 17:25:20 -0600201 insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
202 insertRoute("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
203 insertRoute("/a/b", 3, 0, 10, 0);
204 insertRoute("/a/c", 4, 0, 10, 0);
Vince Lehman4387e782014-06-19 16:57:45 -0500205
206 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600207 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500208
209 // Should generate 3 updates:
Vince Lehman218be0a2015-01-15 17:25:20 -0600210 // - one for the inserted route for /a and
Vince Lehman4387e782014-06-19 16:57:45 -0500211 // - two to remove face1 from /a/b and /a/c
Vince Lehman218be0a2015-01-15 17:25:20 -0600212 insertRoute("/a", 1, 128, 50, ndn::nfd::ROUTE_FLAG_CAPTURE);
Vince Lehman4387e782014-06-19 16:57:45 -0500213
Vince Lehman76c751c2014-11-18 17:36:38 -0600214 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500215 BOOST_REQUIRE_EQUAL(updates.size(), 3);
216
Vince Lehman76c751c2014-11-18 17:36:38 -0600217 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
218 BOOST_CHECK_EQUAL(update->name, "/a");
219 BOOST_CHECK_EQUAL(update->faceId, 1);
220 BOOST_CHECK_EQUAL(update->cost, 50);
221 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500222
223 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -0600224 BOOST_CHECK_EQUAL(update->name, "/a/b");
225 BOOST_CHECK_EQUAL(update->faceId, 1);
226 BOOST_CHECK_EQUAL(update->action, FibUpdate::REMOVE_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500227
228 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -0600229 BOOST_CHECK_EQUAL(update->name, "/a/c");
230 BOOST_CHECK_EQUAL(update->faceId, 1);
231 BOOST_CHECK_EQUAL(update->action, FibUpdate::REMOVE_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500232}
233
234BOOST_AUTO_TEST_CASE(CaptureTurnedOnWithChildInherit)
235{
Vince Lehman218be0a2015-01-15 17:25:20 -0600236 insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
237 insertRoute("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
238 insertRoute("/a/b", 3, 0, 10, 0);
239 insertRoute("/a/c", 4, 0, 10, 0);
Vince Lehman4387e782014-06-19 16:57:45 -0500240
241 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600242 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500243
244 // Should generate 2 updates:
Vince Lehman218be0a2015-01-15 17:25:20 -0600245 // - one for the inserted route for /a and
Vince Lehman4387e782014-06-19 16:57:45 -0500246 // - one to update /a/b with the new cost
Vince Lehman218be0a2015-01-15 17:25:20 -0600247 insertRoute("/a", 1, 128, 50, (ndn::nfd::ROUTE_FLAG_CAPTURE |
Vince Lehman4387e782014-06-19 16:57:45 -0500248 ndn::nfd::ROUTE_FLAG_CHILD_INHERIT));
249
Vince Lehman76c751c2014-11-18 17:36:38 -0600250 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500251 BOOST_REQUIRE_EQUAL(updates.size(), 3);
252
Vince Lehman76c751c2014-11-18 17:36:38 -0600253 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
254 BOOST_CHECK_EQUAL(update->name, "/a");
255 BOOST_CHECK_EQUAL(update->faceId, 1);
256 BOOST_CHECK_EQUAL(update->cost, 50);
257 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500258
259 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -0600260 BOOST_CHECK_EQUAL(update->name, "/a/b");
261 BOOST_CHECK_EQUAL(update->faceId, 1);
262 BOOST_CHECK_EQUAL(update->cost, 50);
263 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500264}
265
266BOOST_AUTO_TEST_SUITE_END() // NewFace
267
268BOOST_AUTO_TEST_SUITE_END() // FibUpdates
269
270} // namespace tests
271} // namespace rib
272} // namespace nfd