blob: 2493668c78bdba8c0f79166339d8ceb58cc88f86 [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(EraseFace)
38
39BOOST_AUTO_TEST_CASE(WithInheritedFace_Root)
40{
Vince Lehman218be0a2015-01-15 17:25:20 -060041 insertRoute("/", 1, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
42 insertRoute("/a", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
43 insertRoute("/a/b", 2, 0, 75, 0);
Vince Lehman4387e782014-06-19 16:57:45 -050044
45 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -060046 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -050047
48 // Should generate 1 updates: 1 to remove face 1 from /
Vince Lehman218be0a2015-01-15 17:25:20 -060049 eraseRoute("/", 1, 0);
Vince Lehman4387e782014-06-19 16:57:45 -050050
Vince Lehman76c751c2014-11-18 17:36:38 -060051 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -050052 BOOST_REQUIRE_EQUAL(updates.size(), 1);
53
Vince Lehman76c751c2014-11-18 17:36:38 -060054 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
55 BOOST_CHECK_EQUAL(update->name, "/");
56 BOOST_CHECK_EQUAL(update->faceId, 1);
57 BOOST_CHECK_EQUAL(update->action, FibUpdate::REMOVE_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -050058}
59
60BOOST_AUTO_TEST_CASE(WithInheritedFace)
61{
Vince Lehman218be0a2015-01-15 17:25:20 -060062 insertRoute("/a", 5, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
63 insertRoute("/a", 5, 255, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
64 insertRoute("/a", 2, 0, 20, 0);
65 insertRoute("/a/b", 3, 0, 5, 0);
Vince Lehman4387e782014-06-19 16:57:45 -050066
67 // /a should have face 5 with cost 10; /a/b should have face 3 with cost 5 and
68 // face 5 with cost 10
Vince Lehman218be0a2015-01-15 17:25:20 -060069 eraseRoute("/a", 5, 255);
Vince Lehman4387e782014-06-19 16:57:45 -050070
71 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -060072 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -050073
Vince Lehman218be0a2015-01-15 17:25:20 -060074 // Should generate 2 updates: 1 to remove face 3 from /a/b and one to remove inherited route
75 eraseRoute("/a/b", 3, 0);
Vince Lehman4387e782014-06-19 16:57:45 -050076
Vince Lehman76c751c2014-11-18 17:36:38 -060077 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -050078 BOOST_REQUIRE_EQUAL(updates.size(), 2);
79
Vince Lehman76c751c2014-11-18 17:36:38 -060080 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
81 BOOST_CHECK_EQUAL(update->name, "/a/b");
82 BOOST_CHECK_EQUAL(update->faceId, 3);
83 BOOST_CHECK_EQUAL(update->action, FibUpdate::REMOVE_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -050084
85 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -060086 BOOST_CHECK_EQUAL(update->name, "/a/b");
87 BOOST_CHECK_EQUAL(update->faceId, 5);
88 BOOST_CHECK_EQUAL(update->action, FibUpdate::REMOVE_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -050089}
90
91BOOST_AUTO_TEST_CASE(MultipleFaces)
92{
Vince Lehman218be0a2015-01-15 17:25:20 -060093 insertRoute("/a", 5, 0, 10, 0);
94 insertRoute("/a", 5, 255, 5, 0);
Vince Lehman4387e782014-06-19 16:57:45 -050095
96 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -060097 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -050098
99 // Should generate 1 updates: 1 to update cost to 10 for /a
Vince Lehman218be0a2015-01-15 17:25:20 -0600100 eraseRoute("/a", 5, 255);
Vince Lehman4387e782014-06-19 16:57:45 -0500101
Vince Lehman76c751c2014-11-18 17:36:38 -0600102 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500103 BOOST_REQUIRE_EQUAL(updates.size(), 1);
104
Vince Lehman76c751c2014-11-18 17:36:38 -0600105 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
106 BOOST_CHECK_EQUAL(update->name, "/a");
107 BOOST_CHECK_EQUAL(update->faceId, 5);
108 BOOST_CHECK_EQUAL(update->cost, 10);
109 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500110}
111
112BOOST_AUTO_TEST_CASE(NoFlags_NoCaptureChange_NoCaptureOnRoute)
113{
Vince Lehman218be0a2015-01-15 17:25:20 -0600114 insertRoute("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
115 insertRoute("/a", 2, 0, 10, 0);
116 insertRoute("/a/b", 3, 0, 10, 0);
117 insertRoute("/a/c", 1, 0, 100, 0);
118 insertRoute("/a", 1, 128, 50, 0);
Vince Lehman4387e782014-06-19 16:57:45 -0500119
120 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600121 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500122
123 // Should generate 1 updates: 1 to update cost for /a
Vince Lehman218be0a2015-01-15 17:25:20 -0600124 eraseRoute("/a", 1, 128);
Vince Lehman4387e782014-06-19 16:57:45 -0500125
Vince Lehman76c751c2014-11-18 17:36:38 -0600126 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500127 BOOST_REQUIRE_EQUAL(updates.size(), 1);
128
Vince Lehman76c751c2014-11-18 17:36:38 -0600129 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
130 BOOST_CHECK_EQUAL(update->name, "/a");
131 BOOST_CHECK_EQUAL(update->faceId, 1);
132 BOOST_CHECK_EQUAL(update->cost, 5);
133 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500134}
135
136BOOST_AUTO_TEST_CASE(MakeRibEmpty)
137{
Vince Lehman218be0a2015-01-15 17:25:20 -0600138 insertRoute("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
Vince Lehman4387e782014-06-19 16:57:45 -0500139
140 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600141 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500142
Vince Lehman218be0a2015-01-15 17:25:20 -0600143 // Should generate 1 updates: 1 to remove route from /
144 eraseRoute("/", 1, 0);
Vince Lehman4387e782014-06-19 16:57:45 -0500145
Vince Lehman76c751c2014-11-18 17:36:38 -0600146 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500147 BOOST_REQUIRE_EQUAL(updates.size(), 1);
148
Vince Lehman76c751c2014-11-18 17:36:38 -0600149 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
150 BOOST_CHECK_EQUAL(update->name, "/");
151 BOOST_CHECK_EQUAL(update->faceId, 1);
152 BOOST_CHECK_EQUAL(update->action, FibUpdate::REMOVE_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500153}
154
155BOOST_AUTO_TEST_CASE(NoFlags_NoCaptureChange_CaptureOnRoute)
156{
Vince Lehman218be0a2015-01-15 17:25:20 -0600157 insertRoute("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
158 insertRoute("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
159 insertRoute("/a/b", 3, 0, 10, 0);
160 insertRoute("/a/c", 1, 0, 100, 0);
161 insertRoute("/a", 1, 128, 50, 0);
Vince Lehman4387e782014-06-19 16:57:45 -0500162
163 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600164 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500165
Vince Lehman218be0a2015-01-15 17:25:20 -0600166 // Should generate 1 updates: 1 to remove route from /a
167 eraseRoute("/a", 1, 128);
Vince Lehman4387e782014-06-19 16:57:45 -0500168
Vince Lehman76c751c2014-11-18 17:36:38 -0600169 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500170 BOOST_REQUIRE_EQUAL(updates.size(), 1);
171
Vince Lehman76c751c2014-11-18 17:36:38 -0600172 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
173 BOOST_CHECK_EQUAL(update->name, "/a");
174 BOOST_CHECK_EQUAL(update->faceId, 1);
175 BOOST_CHECK_EQUAL(update->action, FibUpdate::REMOVE_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500176}
177
178BOOST_AUTO_TEST_CASE(BothFlags_NoCaptureChange_CaptureOnRoute)
179{
Vince Lehman218be0a2015-01-15 17:25:20 -0600180 insertRoute("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
181 insertRoute("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
182 insertRoute("/a/b", 3, 0, 10, 0);
183 insertRoute("/a/c", 1, 0, 100, 0);
184 insertRoute("/a", 1, 128, 50, (ndn::nfd::ROUTE_FLAG_CHILD_INHERIT |
Vince Lehman4387e782014-06-19 16:57:45 -0500185 ndn::nfd::ROUTE_FLAG_CAPTURE));
186
187 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600188 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500189
190 // Should generate 2 updates: 1 to remove face1 from /a and
Vince Lehman218be0a2015-01-15 17:25:20 -0600191 // 1 to remove face1 from /a/b
192 eraseRoute("/a", 1, 128);
Vince Lehman4387e782014-06-19 16:57:45 -0500193
Vince Lehman76c751c2014-11-18 17:36:38 -0600194 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500195 BOOST_REQUIRE_EQUAL(updates.size(), 2);
196
Vince Lehman76c751c2014-11-18 17:36:38 -0600197 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
198 BOOST_CHECK_EQUAL(update->name, "/a");
199 BOOST_CHECK_EQUAL(update->faceId, 1);
200 BOOST_CHECK_EQUAL(update->action, FibUpdate::REMOVE_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500201
202 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -0600203 BOOST_CHECK_EQUAL(update->name, "/a/b");
204 BOOST_CHECK_EQUAL(update->faceId, 1);
205 BOOST_CHECK_EQUAL(update->action, FibUpdate::REMOVE_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500206}
207
208BOOST_AUTO_TEST_CASE(BothFlags_CaptureChange_NoCaptureOnRoute)
209{
Vince Lehman218be0a2015-01-15 17:25:20 -0600210 insertRoute("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
211 insertRoute("/a", 2, 0, 10, 0);
212 insertRoute("/a/b", 3, 0, 10, 0);
213 insertRoute("/a/c", 1, 0, 100, 0);
214 insertRoute("/a", 1, 128, 50, (ndn::nfd::ROUTE_FLAG_CHILD_INHERIT |
Vince Lehman4387e782014-06-19 16:57:45 -0500215 ndn::nfd::ROUTE_FLAG_CAPTURE));
216
217 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600218 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500219
220 // Should generate 2 updates: 1 to add face1 to /a and
221 // 1 to add face1 to /a/b
Vince Lehman218be0a2015-01-15 17:25:20 -0600222 eraseRoute("/a", 1, 128);
Vince Lehman4387e782014-06-19 16:57:45 -0500223
Vince Lehman76c751c2014-11-18 17:36:38 -0600224 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500225 BOOST_REQUIRE_EQUAL(updates.size(), 2);
226
Vince Lehman76c751c2014-11-18 17:36:38 -0600227 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
228 BOOST_CHECK_EQUAL(update->name, "/a");
229 BOOST_CHECK_EQUAL(update->faceId, 1);
230 BOOST_CHECK_EQUAL(update->cost, 5);
231 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500232
233 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -0600234 BOOST_CHECK_EQUAL(update->name, "/a/b");
235 BOOST_CHECK_EQUAL(update->faceId, 1);
236 BOOST_CHECK_EQUAL(update->cost, 5);
237 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500238}
239
240BOOST_AUTO_TEST_CASE(ChildInherit_NoCaptureChange_NoCaptureOnRoute)
241{
Vince Lehman218be0a2015-01-15 17:25:20 -0600242 insertRoute("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
243 insertRoute("/a", 2, 0, 10, 0);
244 insertRoute("/a/b", 3, 0, 10, 0);
245 insertRoute("/a/c", 1, 0, 100, 0);
246 insertRoute("/a", 1, 128, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
Vince Lehman4387e782014-06-19 16:57:45 -0500247
248 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600249 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500250
251 // Should generate 2 updates: 2 to add face1 to /a and /a/b
Vince Lehman218be0a2015-01-15 17:25:20 -0600252 eraseRoute("/a", 1, 128);
Vince Lehman4387e782014-06-19 16:57:45 -0500253
Vince Lehman76c751c2014-11-18 17:36:38 -0600254 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500255 BOOST_REQUIRE_EQUAL(updates.size(), 2);
256
Vince Lehman76c751c2014-11-18 17:36:38 -0600257 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
258 BOOST_CHECK_EQUAL(update->name, "/a");
259 BOOST_CHECK_EQUAL(update->faceId, 1);
260 BOOST_CHECK_EQUAL(update->cost, 5);
261 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500262
263 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -0600264 BOOST_CHECK_EQUAL(update->name, "/a/b");
265 BOOST_CHECK_EQUAL(update->faceId, 1);
266 BOOST_CHECK_EQUAL(update->cost, 5);
267 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500268}
269
270BOOST_AUTO_TEST_CASE(ChildInherit_NoCaptureChange_CaptureOnRoute)
271{
Vince Lehman218be0a2015-01-15 17:25:20 -0600272 insertRoute("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
273 insertRoute("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
274 insertRoute("/a/b", 3, 0, 10, 0);
275 insertRoute("/a/c", 1, 0, 100, 0);
276 insertRoute("/a", 1, 128, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
Vince Lehman4387e782014-06-19 16:57:45 -0500277
278 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600279 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500280
281 // Should generate 2 updates: 2 to remove face 1 from /a and /a/b
Vince Lehman218be0a2015-01-15 17:25:20 -0600282 eraseRoute("/a", 1, 128);
Vince Lehman4387e782014-06-19 16:57:45 -0500283
Vince Lehman76c751c2014-11-18 17:36:38 -0600284 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500285 BOOST_REQUIRE_EQUAL(updates.size(), 2);
286
Vince Lehman76c751c2014-11-18 17:36:38 -0600287 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
288 BOOST_CHECK_EQUAL(update->name, "/a");
289 BOOST_CHECK_EQUAL(update->faceId, 1);
290 BOOST_CHECK_EQUAL(update->action, FibUpdate::REMOVE_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500291
292 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -0600293 BOOST_CHECK_EQUAL(update->name, "/a/b");
294 BOOST_CHECK_EQUAL(update->faceId, 1);
295 BOOST_CHECK_EQUAL(update->action, FibUpdate::REMOVE_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500296}
297
298BOOST_AUTO_TEST_CASE(Capture_CaptureChange_NoCaptureOnRoute)
299{
Vince Lehman218be0a2015-01-15 17:25:20 -0600300 insertRoute("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
301 insertRoute("/a", 2, 0, 10, 0);
302 insertRoute("/a/b", 3, 0, 10, 0);
303 insertRoute("/a/c", 1, 0, 100, 0);
304 insertRoute("/a", 1, 128, 50, ndn::nfd::ROUTE_FLAG_CAPTURE);
Vince Lehman4387e782014-06-19 16:57:45 -0500305
306 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600307 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500308
309 // Should generate 2 updates: 1 to update cost on /a and
310 // 1 to add face1 to /a/b
Vince Lehman218be0a2015-01-15 17:25:20 -0600311 eraseRoute("/a", 1 ,128);
Vince Lehman4387e782014-06-19 16:57:45 -0500312
Vince Lehman76c751c2014-11-18 17:36:38 -0600313 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500314 BOOST_REQUIRE_EQUAL(updates.size(), 2);
315
Vince Lehman76c751c2014-11-18 17:36:38 -0600316 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
317 BOOST_CHECK_EQUAL(update->name, "/a");
318 BOOST_CHECK_EQUAL(update->faceId, 1);
319 BOOST_CHECK_EQUAL(update->cost, 5);
320 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500321
322 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -0600323 BOOST_CHECK_EQUAL(update->name, "/a/b");
324 BOOST_CHECK_EQUAL(update->faceId, 1);
325 BOOST_CHECK_EQUAL(update->cost, 5);
326 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500327}
328
329BOOST_AUTO_TEST_CASE(Capture_NoCaptureChange_CaptureOnRoute)
330{
Vince Lehman218be0a2015-01-15 17:25:20 -0600331 insertRoute("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
332 insertRoute("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
333 insertRoute("/a/b", 3, 0, 10, 0);
334 insertRoute("/a/c", 1, 0, 100, 0);
335 insertRoute("/a", 1, 128, 50, ndn::nfd::ROUTE_FLAG_CAPTURE);
Vince Lehman4387e782014-06-19 16:57:45 -0500336
337 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600338 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500339
Vince Lehman218be0a2015-01-15 17:25:20 -0600340 // Should generate 1 updates: 1 to remove route from /a
341 eraseRoute("/a", 1, 128);
Vince Lehman4387e782014-06-19 16:57:45 -0500342
Vince Lehman76c751c2014-11-18 17:36:38 -0600343 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500344 BOOST_REQUIRE_EQUAL(updates.size(), 1);
345
Vince Lehman76c751c2014-11-18 17:36:38 -0600346 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
347 BOOST_CHECK_EQUAL(update->name, "/a");
348 BOOST_CHECK_EQUAL(update->faceId, 1);
349 BOOST_CHECK_EQUAL(update->action, FibUpdate::REMOVE_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500350}
351
352BOOST_AUTO_TEST_CASE(EraseFaceById)
353{
Vince Lehman218be0a2015-01-15 17:25:20 -0600354 insertRoute("/", 1, 0, 5, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
Vince Lehman76c751c2014-11-18 17:36:38 -0600355 insertRoute("/a", 3, 0, 10, 0);
356 insertRoute("/a/b", 4, 0, 10, 0);
357 insertRoute("/a/c", 1, 0, 100, 0);
358 insertRoute("/a", 2, 128, 50, ndn::nfd::ROUTE_FLAG_CAPTURE);
Vince Lehman4387e782014-06-19 16:57:45 -0500359
360 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600361 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500362
Vince Lehman76c751c2014-11-18 17:36:38 -0600363 // Should generate 2 updates: 2 to add face ID 1 to /a and /a/b
364 destroyFace(2);
Vince Lehman4387e782014-06-19 16:57:45 -0500365
Vince Lehman76c751c2014-11-18 17:36:38 -0600366 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
367 BOOST_REQUIRE_EQUAL(updates.size(), 2);
Vince Lehman4387e782014-06-19 16:57:45 -0500368
Vince Lehman76c751c2014-11-18 17:36:38 -0600369 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
370 BOOST_CHECK_EQUAL(update->name, "/a");
371 BOOST_CHECK_EQUAL(update->faceId, 1);
372 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500373
374 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -0600375 BOOST_CHECK_EQUAL(update->name, "/a/b");
376 BOOST_CHECK_EQUAL(update->faceId, 1);
377 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500378}
379
380BOOST_AUTO_TEST_SUITE_END() // EraseFace
381
382BOOST_AUTO_TEST_SUITE_END() // FibUpdates
383
384} // namespace tests
385} // namespace rib
386} // namespace nfd