blob: 13f5e214870fc13972997419e6e4ec416ba13652 [file] [log] [blame]
Vince Lehman4387e782014-06-19 16:57:45 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014, 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
10 *
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
35BOOST_FIXTURE_TEST_SUITE(FibUpdates, FibUpdatesFixture)
36
37BOOST_AUTO_TEST_SUITE(UpdateFace)
38
39BOOST_AUTO_TEST_CASE(TurnOffChildInheritLowerCost)
40{
41 insertFaceEntry("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
42 insertFaceEntry("/a", 2, 0, 10, 0);
43 insertFaceEntry("/", 1, 128, 25, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
44
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
50 insertFaceEntry("/", 1, 128, 75, 0);
51
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{
70 insertFaceEntry("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
71 insertFaceEntry("/a", 2, 0, 10, 0);
72 insertFaceEntry("/", 1, 128, 100, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
73
74 // Clear updates generated from previous insertions
75 rib.clearFibUpdates();
76
77 // Should generate 0 updates
78 insertFaceEntry("/", 1, 128, 75, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
79
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
87 insertFaceEntry("/", 1, 128, 25, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
88
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{
107 insertFaceEntry("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
108 insertFaceEntry("/a", 2, 0, 100, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
109 insertFaceEntry("/a/b", 3, 0, 10, 0);
110 insertFaceEntry("/a/c", 4, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
111
112 // Clear updates generated from previous insertions
113 rib.clearFibUpdates();
114
115 // Should generate 0 updates
116 insertFaceEntry("/a", 2, 0, 100, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
117
118 Rib::FibUpdateList updates = getSortedFibUpdates();
119 BOOST_REQUIRE_EQUAL(updates.size(), 0);
120}
121
122BOOST_AUTO_TEST_CASE(ChangeCost)
123{
124 insertFaceEntry("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
125 insertFaceEntry("/a", 2, 0, 100, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
126 insertFaceEntry("/a/b", 3, 0, 10, 0);
127 insertFaceEntry("/a/c", 4, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
128
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
134 insertFaceEntry("/a", 2, 0, 300, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
135
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{
154 insertFaceEntry("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
155 insertFaceEntry("/a", 2, 0, 10, 0);
156 insertFaceEntry("/a/b", 3, 0, 10, 0);
157 insertFaceEntry("/a/c", 4, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
158
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
164 insertFaceEntry("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
165
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{
178 insertFaceEntry("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
179 insertFaceEntry("/a", 1, 0, 100, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
180 insertFaceEntry("/a/b", 2, 0, 10, 0);
181 insertFaceEntry("/a/c", 1, 0, 25, 0);
182
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
188 insertFaceEntry("/a", 1, 0, 100, 0);
189
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{
202 insertFaceEntry("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
203 insertFaceEntry("/a", 2, 0, 10, 0);
204 insertFaceEntry("/a/b", 3, 0, 10, 0);
205 insertFaceEntry("/a/c", 1, 0, 10, 0);
206
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
213 insertFaceEntry("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
214
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{
231 insertFaceEntry("/", 1, 0, 50, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
232 insertFaceEntry("/a", 2, 0, 10, ndn::nfd::ROUTE_FLAG_CAPTURE);
233 insertFaceEntry("/a/b", 3, 0, 10, 0);
234 insertFaceEntry("/a/c", 1, 0, 10, 0);
235
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
242 insertFaceEntry("/a", 2, 0, 10, 0);
243
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