blob: af49188fbb0d10d1df6a00bdc40ffa234eddb72b [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
46 rib.clearFibUpdates();
47
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
52 Rib::FibUpdateList updates = getSortedFibUpdates();
53 BOOST_REQUIRE_EQUAL(updates.size(), 2);
54
55 Rib::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);
60
61 ++update;
62 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);
66}
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
75 rib.clearFibUpdates();
76
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
80 Rib::FibUpdateList updates = getSortedFibUpdates();
81 BOOST_REQUIRE_EQUAL(updates.size(), 0);
82
83 // Clear updates generated from previous insertions
84 rib.clearFibUpdates();
85
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
92 Rib::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);
97
98 ++update;
99 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);
103}
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
113 rib.clearFibUpdates();
114
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
118 Rib::FibUpdateList updates = getSortedFibUpdates();
119 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
130 rib.clearFibUpdates();
131
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
136 Rib::FibUpdateList updates = getSortedFibUpdates();
137 BOOST_REQUIRE_EQUAL(updates.size(), 2);
138
139 Rib::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);
144
145 ++update;
146 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);
150}
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
160 rib.clearFibUpdates();
161
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
166 Rib::FibUpdateList updates = getSortedFibUpdates();
167 BOOST_REQUIRE_EQUAL(updates.size(), 1);
168
169 Rib::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);
174}
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
184 rib.clearFibUpdates();
185
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
190 Rib::FibUpdateList updates = getSortedFibUpdates();
191 BOOST_REQUIRE_EQUAL(updates.size(), 1);
192
193 Rib::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);
198}
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
208 rib.clearFibUpdates();
209
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
215 Rib::FibUpdateList updates = getSortedFibUpdates();
216 BOOST_REQUIRE_EQUAL(updates.size(), 2);
217
218 Rib::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);
222
223 ++update;
224 BOOST_CHECK_EQUAL((*update)->name, "/a/b");
225 BOOST_CHECK_EQUAL((*update)->faceId, 1);
226 BOOST_CHECK_EQUAL((*update)->action, FibUpdate::REMOVE_NEXTHOP);
227}
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
237 rib.clearFibUpdates();
238
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
244 Rib::FibUpdateList updates = getSortedFibUpdates();
245 BOOST_REQUIRE_EQUAL(updates.size(), 2);
246
247 Rib::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);
252
253 ++update;
254 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);
258}
259
260BOOST_AUTO_TEST_SUITE_END() // UpdateFace
261
262BOOST_AUTO_TEST_SUITE_END() // FibUpdates
263
264} // namespace tests
265} // namespace rib
266} // namespace nfd