blob: 850e8ae115cf33a646064874f06eca92546bc0f5 [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
44 Rib::FibUpdateList updates = rib.getFibUpdates();
45 BOOST_REQUIRE_EQUAL(updates.size(), 1);
46
47 Rib::FibUpdateList::const_iterator update = updates.begin();
48
49 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);
53
54 // Clear any updates generated from previous insertions
55 rib.clearFibUpdates();
56
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();
64 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);
68
69 ++update;
70 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);
74
75 // Clear updates generated from previous insertions
76 rib.clearFibUpdates();
77
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();
85 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);
89
90 ++update;
91 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);
95}
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
102 rib.clearFibUpdates();
103
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
107 BOOST_CHECK_EQUAL(rib.getFibUpdates().size(), 0);
108}
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
116 rib.clearFibUpdates();
117
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
121 Rib::FibUpdateList updates = getSortedFibUpdates();
122 BOOST_REQUIRE_EQUAL(updates.size(), 2);
123
124 Rib::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);
129
130 ++update;
131 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);
135
136 // Clear updates generated from previous insertions
137 rib.clearFibUpdates();
138
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
142 BOOST_CHECK_EQUAL(rib.getFibUpdates().size(), 0);
143}
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
153 rib.clearFibUpdates();
154
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
158 const Rib::FibUpdateList& updates = rib.getFibUpdates();
159 BOOST_REQUIRE_EQUAL(updates.size(), 1);
160
161 Rib::FibUpdateList::const_iterator update = updates.begin();
162
163 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);
167}
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
177 rib.clearFibUpdates();
178
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
183 Rib::FibUpdateList updates = getSortedFibUpdates();
184 BOOST_REQUIRE_EQUAL(updates.size(), 2);
185
186 Rib::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);
191
192 ++update;
193 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);
197}
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
207 rib.clearFibUpdates();
208
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
214 Rib::FibUpdateList updates = getSortedFibUpdates();
215 BOOST_REQUIRE_EQUAL(updates.size(), 3);
216
217 Rib::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);
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 ++update;
229 BOOST_CHECK_EQUAL((*update)->name, "/a/c");
230 BOOST_CHECK_EQUAL((*update)->faceId, 1);
231 BOOST_CHECK_EQUAL((*update)->action, FibUpdate::REMOVE_NEXTHOP);
232}
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
242 rib.clearFibUpdates();
243
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
250 Rib::FibUpdateList updates = getSortedFibUpdates();
251 BOOST_REQUIRE_EQUAL(updates.size(), 3);
252
253 Rib::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);
258
259 ++update;
260 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);
264}
265
266BOOST_AUTO_TEST_SUITE_END() // NewFace
267
268BOOST_AUTO_TEST_SUITE_END() // FibUpdates
269
270} // namespace tests
271} // namespace rib
272} // namespace nfd