blob: 54cd2d44e0576a0060f5eea349a8a9c40e91b655 [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(UpdateFace)
38
39BOOST_AUTO_TEST_CASE(TurnOffChildInheritLowerCost)
40{
Vince Lehman218be0a2015-01-15 17:25:20 -060041 insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
42 insertRoute("/a", 2, 0, 10, 0);
43 insertRoute("/", 1, 128, 25, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
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 2 updates: 1 to update the cost of / face 1 to 50 and
49 // 1 to update the cost of /a face 1 to 50
Vince Lehman218be0a2015-01-15 17:25:20 -060050 insertRoute("/", 1, 128, 75, 0);
Vince Lehman4387e782014-06-19 16:57:45 -050051
Vince Lehman76c751c2014-11-18 17:36:38 -060052 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -050053 BOOST_REQUIRE_EQUAL(updates.size(), 2);
54
Vince Lehman76c751c2014-11-18 17:36:38 -060055 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
56 BOOST_CHECK_EQUAL(update->name, "/");
57 BOOST_CHECK_EQUAL(update->faceId, 1);
58 BOOST_CHECK_EQUAL(update->cost, 50);
59 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -050060
61 ++update;
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
68BOOST_AUTO_TEST_CASE(UpdateOnLowerCostOnly)
69{
Vince Lehman218be0a2015-01-15 17:25:20 -060070 insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
71 insertRoute("/a", 2, 0, 10, 0);
72 insertRoute("/", 1, 128, 100, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
Vince Lehman4387e782014-06-19 16:57:45 -050073
74 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -060075 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -050076
77 // Should generate 0 updates
Vince Lehman218be0a2015-01-15 17:25:20 -060078 insertRoute("/", 1, 128, 75, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
Vince Lehman4387e782014-06-19 16:57:45 -050079
Vince Lehman76c751c2014-11-18 17:36:38 -060080 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -050081 BOOST_REQUIRE_EQUAL(updates.size(), 0);
82
83 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -060084 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -050085
86 // Should generate 2 updates
Vince Lehman218be0a2015-01-15 17:25:20 -060087 insertRoute("/", 1, 128, 25, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
Vince Lehman4387e782014-06-19 16:57:45 -050088
89 updates = getSortedFibUpdates();
90 BOOST_REQUIRE_EQUAL(updates.size(), 2);
91
Vince Lehman76c751c2014-11-18 17:36:38 -060092 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
93 BOOST_CHECK_EQUAL(update->name, "/");
94 BOOST_CHECK_EQUAL(update->faceId, 1);
95 BOOST_CHECK_EQUAL(update->cost, 25);
96 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -050097
98 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -060099 BOOST_CHECK_EQUAL(update->name, "/a");
100 BOOST_CHECK_EQUAL(update->faceId, 1);
101 BOOST_CHECK_EQUAL(update->cost, 25);
102 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500103}
104
105BOOST_AUTO_TEST_CASE(NoChangeInCost)
106{
Vince Lehman218be0a2015-01-15 17:25:20 -0600107 insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
108 insertRoute("/a", 2, 0, 100, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
109 insertRoute("/a/b", 3, 0, 10, 0);
110 insertRoute("/a/c", 4, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
Vince Lehman4387e782014-06-19 16:57:45 -0500111
112 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600113 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500114
115 // Should generate 0 updates
Vince Lehman218be0a2015-01-15 17:25:20 -0600116 insertRoute("/a", 2, 0, 100, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
Vince Lehman4387e782014-06-19 16:57:45 -0500117
Vince Lehman76c751c2014-11-18 17:36:38 -0600118 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500119 BOOST_REQUIRE_EQUAL(updates.size(), 0);
120}
121
122BOOST_AUTO_TEST_CASE(ChangeCost)
123{
Vince Lehman218be0a2015-01-15 17:25:20 -0600124 insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
125 insertRoute("/a", 2, 0, 100, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
126 insertRoute("/a/b", 3, 0, 10, 0);
127 insertRoute("/a/c", 4, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
Vince Lehman4387e782014-06-19 16:57:45 -0500128
129 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600130 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500131
132 // Should generate 2 updates: 1 to add face2 with new cost to /a and
133 // 1 to add face2 with new cost to /a/b
Vince Lehman218be0a2015-01-15 17:25:20 -0600134 insertRoute("/a", 2, 0, 300, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
Vince Lehman4387e782014-06-19 16:57:45 -0500135
Vince Lehman76c751c2014-11-18 17:36:38 -0600136 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500137 BOOST_REQUIRE_EQUAL(updates.size(), 2);
138
Vince Lehman76c751c2014-11-18 17:36:38 -0600139 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
140 BOOST_CHECK_EQUAL(update->name, "/a");
141 BOOST_CHECK_EQUAL(update->faceId, 2);
142 BOOST_CHECK_EQUAL(update->cost, 300);
143 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500144
145 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -0600146 BOOST_CHECK_EQUAL(update->name, "/a/b");
147 BOOST_CHECK_EQUAL(update->faceId, 2);
148 BOOST_CHECK_EQUAL(update->cost, 300);
149 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500150}
151
152BOOST_AUTO_TEST_CASE(TurnOnChildInherit)
153{
Vince Lehman218be0a2015-01-15 17:25:20 -0600154 insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
155 insertRoute("/a", 2, 0, 10, 0);
156 insertRoute("/a/b", 3, 0, 10, 0);
157 insertRoute("/a/c", 4, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
Vince Lehman4387e782014-06-19 16:57:45 -0500158
159 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600160 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500161
162 // Turn on child inherit flag for the entry in /a
163 // Should generate 1 updates: 1 to add face to /a/b
Vince Lehman218be0a2015-01-15 17:25:20 -0600164 insertRoute("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
Vince Lehman4387e782014-06-19 16:57:45 -0500165
Vince Lehman76c751c2014-11-18 17:36:38 -0600166 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500167 BOOST_REQUIRE_EQUAL(updates.size(), 1);
168
Vince Lehman76c751c2014-11-18 17:36:38 -0600169 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
170 BOOST_CHECK_EQUAL(update->name, "/a/b");
171 BOOST_CHECK_EQUAL(update->faceId, 2);
172 BOOST_CHECK_EQUAL(update->cost, 10);
173 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500174}
175
176BOOST_AUTO_TEST_CASE(TurnOffChildInherit)
177{
Vince Lehman218be0a2015-01-15 17:25:20 -0600178 insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
179 insertRoute("/a", 1, 0, 100, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
180 insertRoute("/a/b", 2, 0, 10, 0);
181 insertRoute("/a/c", 1, 0, 25, 0);
Vince Lehman4387e782014-06-19 16:57:45 -0500182
183 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600184 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500185
186 // Turn off child inherit flag for the entry in /a
187 // Should generate 1 update: 1 to add face1 to /a/b
Vince Lehman218be0a2015-01-15 17:25:20 -0600188 insertRoute("/a", 1, 0, 100, 0);
Vince Lehman4387e782014-06-19 16:57:45 -0500189
Vince Lehman76c751c2014-11-18 17:36:38 -0600190 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500191 BOOST_REQUIRE_EQUAL(updates.size(), 1);
192
Vince Lehman76c751c2014-11-18 17:36:38 -0600193 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
194 BOOST_CHECK_EQUAL(update->name, "/a/b");
195 BOOST_CHECK_EQUAL(update->faceId, 1);
196 BOOST_CHECK_EQUAL(update->cost, 50);
197 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500198}
199
200BOOST_AUTO_TEST_CASE(TurnOnCapture)
201{
Vince Lehman218be0a2015-01-15 17:25:20 -0600202 insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
203 insertRoute("/a", 2, 0, 10, 0);
204 insertRoute("/a/b", 3, 0, 10, 0);
205 insertRoute("/a/c", 1, 0, 10, 0);
Vince Lehman4387e782014-06-19 16:57:45 -0500206
207 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600208 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500209
210 // Turn on capture flag for the entry in /a
211 // Should generate 2 updates: 1 to remove face1 from /a and
212 // 1 to remove face1 from /a/b
Vince Lehman218be0a2015-01-15 17:25:20 -0600213 insertRoute("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
Vince Lehman4387e782014-06-19 16:57:45 -0500214
Vince Lehman76c751c2014-11-18 17:36:38 -0600215 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500216 BOOST_REQUIRE_EQUAL(updates.size(), 2);
217
Vince Lehman76c751c2014-11-18 17:36:38 -0600218 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
219 BOOST_CHECK_EQUAL(update->name, "/a");
220 BOOST_CHECK_EQUAL(update->faceId, 1);
221 BOOST_CHECK_EQUAL(update->action, FibUpdate::REMOVE_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
229BOOST_AUTO_TEST_CASE(TurnOffCapture)
230{
Vince Lehman218be0a2015-01-15 17:25:20 -0600231 insertRoute("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
232 insertRoute("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
233 insertRoute("/a/b", 3, 0, 10, 0);
234 insertRoute("/a/c", 1, 0, 10, 0);
Vince Lehman4387e782014-06-19 16:57:45 -0500235
236 // Clear updates generated from previous insertions
Vince Lehman76c751c2014-11-18 17:36:38 -0600237 clearFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500238
239 // Turn off capture flag for the entry in /a
240 // Should generate 2 updates: 1 to add face1 to /a and
241 // 1 to add face1 to /a/b
Vince Lehman218be0a2015-01-15 17:25:20 -0600242 insertRoute("/a", 2, 0, 10, 0);
Vince Lehman4387e782014-06-19 16:57:45 -0500243
Vince Lehman76c751c2014-11-18 17:36:38 -0600244 FibUpdater::FibUpdateList updates = getSortedFibUpdates();
Vince Lehman4387e782014-06-19 16:57:45 -0500245 BOOST_REQUIRE_EQUAL(updates.size(), 2);
246
Vince Lehman76c751c2014-11-18 17:36:38 -0600247 FibUpdater::FibUpdateList::const_iterator update = updates.begin();
248 BOOST_CHECK_EQUAL(update->name, "/a");
249 BOOST_CHECK_EQUAL(update->faceId, 1);
250 BOOST_CHECK_EQUAL(update->cost, 50);
251 BOOST_CHECK_EQUAL(update->action, FibUpdate::ADD_NEXTHOP);
Vince Lehman4387e782014-06-19 16:57:45 -0500252
253 ++update;
Vince Lehman76c751c2014-11-18 17:36:38 -0600254 BOOST_CHECK_EQUAL(update->name, "/a/b");
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
260BOOST_AUTO_TEST_SUITE_END() // UpdateFace
261
262BOOST_AUTO_TEST_SUITE_END() // FibUpdates
263
264} // namespace tests
265} // namespace rib
266} // namespace nfd