blob: f03b7b949418696a86ad3d743aa53d3fad6a09d1 [file] [log] [blame]
Yanbiao Li711c7932015-08-19 16:30:16 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Yanbiao Lidf846e52016-01-30 21:53:47 -08003 * Copyright (c) 2014-2016, Regents of the University of California,
Yanbiao Li711c7932015-08-19 16:30:16 -07004 * 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#include "mgmt/fib-manager.hpp"
26
Yanbiao Lidf846e52016-01-30 21:53:47 -080027#include "nfd-manager-common-fixture.hpp"
Yanbiao Li711c7932015-08-19 16:30:16 -070028#include "table/fib-nexthop.hpp"
29#include "../face/dummy-face.hpp"
30#include <ndn-cxx/management/nfd-fib-entry.hpp>
31
32namespace nfd {
33namespace tests {
34
Yanbiao Lidf846e52016-01-30 21:53:47 -080035class FibManagerFixture : public NfdManagerCommonFixture
Yanbiao Li711c7932015-08-19 16:30:16 -070036{
37public:
38 FibManagerFixture()
39 : m_fib(m_forwarder.getFib())
40 , m_faceTable(m_forwarder.getFaceTable())
Junxiao Shi9ddf1b52016-08-22 03:58:55 +000041 , m_manager(m_fib, m_faceTable, m_dispatcher, *m_authenticator)
Yanbiao Li711c7932015-08-19 16:30:16 -070042 {
Junxiao Shi9ddf1b52016-08-22 03:58:55 +000043 setTopPrefix();
Yanbiao Lidf846e52016-01-30 21:53:47 -080044 setPrivilege("fib");
Yanbiao Li711c7932015-08-19 16:30:16 -070045 }
46
47public: // for test
48 ControlParameters
49 makeParameters(const Name& name, const FaceId& id)
50 {
51 return ControlParameters().setName(name).setFaceId(id);
52 }
53
54 ControlParameters
55 makeParameters(const Name& name, const FaceId& id, const uint32_t& cost)
56 {
57 return ControlParameters().setName(name).setFaceId(id).setCost(cost);
58 }
59
60 FaceId
61 addFace()
62 {
63 auto face = make_shared<DummyFace>();
64 m_faceTable.add(face);
65 advanceClocks(time::milliseconds(1), 10);
66 m_responses.clear(); // clear all event notifications, if any
67 return face->getId();
68 }
69
70public: // for check
71 enum class CheckNextHopResult
72 {
73 OK,
74 NO_FIB_ENTRY,
75 WRONG_N_NEXTHOPS,
76 NO_NEXTHOP,
77 WRONG_COST
78 };
79
80 /**
81 * @brief check whether the nexthop record is added / removed properly
82 *
83 * @param expectedNNextHops use -1 to skip this check
Junxiao Shicde37ad2015-12-24 01:02:05 -070084 * @param faceId use face::FACEID_NULL to skip NextHopRecord checks
Yanbiao Li711c7932015-08-19 16:30:16 -070085 * @param expectedCost use -1 to skip this check
86 *
87 * @retval OK FIB entry is found by exact match and has the expected number of nexthops;
88 * NextHopRe record for faceId is found and has the expected cost
89 * @retval NO_FIB_ENTRY FIB entry is not found
90 * @retval WRONG_N_NEXTHOPS FIB entry is found but has wrong number of nexthops
91 * @retval NO_NEXTHOP NextHopRecord for faceId is not found
92 * @retval WRONG_COST NextHopRecord for faceId has wrong cost
93 */
94 CheckNextHopResult
95 checkNextHop(const Name& prefix, ssize_t expectedNNextHops = -1,
Junxiao Shicde37ad2015-12-24 01:02:05 -070096 FaceId faceId = face::FACEID_NULL, int32_t expectedCost = -1)
Yanbiao Li711c7932015-08-19 16:30:16 -070097 {
Junxiao Shia6de4292016-07-12 02:08:10 +000098 const fib::Entry* entry = m_fib.findExactMatch(prefix);
99 if (entry == nullptr) {
Yanbiao Li711c7932015-08-19 16:30:16 -0700100 return CheckNextHopResult::NO_FIB_ENTRY;
101 }
102
Junxiao Shia6de4292016-07-12 02:08:10 +0000103 const fib::NextHopList& nextHops = entry->getNextHops();
Yanbiao Li711c7932015-08-19 16:30:16 -0700104 if (expectedNNextHops != -1 && nextHops.size() != static_cast<size_t>(expectedNNextHops)) {
105 return CheckNextHopResult::WRONG_N_NEXTHOPS;
106 }
107
Junxiao Shicde37ad2015-12-24 01:02:05 -0700108 if (faceId != face::FACEID_NULL) {
Yanbiao Li711c7932015-08-19 16:30:16 -0700109 for (auto&& record : nextHops) {
Junxiao Shia6de4292016-07-12 02:08:10 +0000110 if (record.getFace().getId() == faceId) {
Yanbiao Li711c7932015-08-19 16:30:16 -0700111 return expectedCost != -1 && record.getCost() != static_cast<uint32_t>(expectedCost) ?
112 CheckNextHopResult::WRONG_COST : CheckNextHopResult::OK;
113 }
114 }
115
116 return CheckNextHopResult::NO_NEXTHOP;
117 }
118
119 return CheckNextHopResult::OK;
120 }
121
122protected:
123 Fib& m_fib;
124 FaceTable& m_faceTable;
125 FibManager m_manager;
126};
127
128std::ostream&
129operator<<(std::ostream &os, const FibManagerFixture::CheckNextHopResult& result)
130{
131 switch (result) {
132 case FibManagerFixture::CheckNextHopResult::OK:
133 os << "OK";
134 break;
135 case FibManagerFixture::CheckNextHopResult::NO_FIB_ENTRY:
136 os << "NO_FIB_ENTRY";
137 break;
138 case FibManagerFixture::CheckNextHopResult::WRONG_N_NEXTHOPS:
139 os << "WRONG_N_NEXTHOPS";
140 break;
141 case FibManagerFixture::CheckNextHopResult::NO_NEXTHOP:
142 os << "NO_NEXTHOP";
143 break;
144 case FibManagerFixture::CheckNextHopResult::WRONG_COST:
145 os << "WRONG_COST";
146 break;
147 default:
148 break;
149 };
150
151 return os;
152}
153
154BOOST_FIXTURE_TEST_SUITE(Mgmt, FibManagerFixture)
155BOOST_AUTO_TEST_SUITE(TestFibManager)
156
157BOOST_AUTO_TEST_SUITE(AddNextHop)
158
159BOOST_AUTO_TEST_CASE(UnknownFaceId)
160{
161 auto command = makeControlCommandRequest("/localhost/nfd/fib/add-nexthop",
Junxiao Shicde37ad2015-12-24 01:02:05 -0700162 makeParameters("hello", face::FACEID_NULL, 101));
Yanbiao Li711c7932015-08-19 16:30:16 -0700163 receiveInterest(command);
164 BOOST_REQUIRE_EQUAL(m_responses.size(), 1);
165
166 // check response
167 BOOST_CHECK_EQUAL(checkResponse(0, command->getName(), ControlResponse(410, "Face not found")),
168 CheckResponseResult::OK);
169
170 // double check that the next hop was not added
Junxiao Shicde37ad2015-12-24 01:02:05 -0700171 BOOST_CHECK_EQUAL(checkNextHop("/hello", -1, face::FACEID_NULL, 101), CheckNextHopResult::NO_FIB_ENTRY);
Yanbiao Li711c7932015-08-19 16:30:16 -0700172}
173
174BOOST_AUTO_TEST_CASE(ImplicitFaceId)
175{
176 auto face1 = addFace();
177 auto face2 = addFace();
Junxiao Shicde37ad2015-12-24 01:02:05 -0700178 BOOST_REQUIRE_NE(face1, face::INVALID_FACEID);
179 BOOST_REQUIRE_NE(face2, face::INVALID_FACEID);
Yanbiao Li711c7932015-08-19 16:30:16 -0700180
181 Name expectedName;
182 ControlResponse expectedResponse;
183 auto testAddNextHop = [&] (ControlParameters parameters, const FaceId& faceId) {
184 auto command = makeControlCommandRequest("/localhost/nfd/fib/add-nexthop", parameters,
Junxiao Shi0de23a22015-12-03 20:07:02 +0000185 [&faceId] (shared_ptr<Interest> interest) {
186 interest->setTag(make_shared<lp::IncomingFaceIdTag>(faceId));
187 });
Yanbiao Li711c7932015-08-19 16:30:16 -0700188 m_responses.clear();
189 expectedName = command->getName();
190 expectedResponse = makeResponse(200, "Success", parameters.setFaceId(faceId));
191 receiveInterest(command);
192 };
193
194 testAddNextHop(ControlParameters().setName("/hello").setCost(100).setFaceId(0), face1);
195 BOOST_REQUIRE_EQUAL(m_responses.size(), 1);
196 BOOST_CHECK_EQUAL(checkResponse(0, expectedName, expectedResponse), CheckResponseResult::OK);
197 BOOST_CHECK_EQUAL(checkNextHop("/hello", 1, face1, 100), CheckNextHopResult::OK);
198
199 testAddNextHop(ControlParameters().setName("/hello").setCost(100), face2);
200 BOOST_REQUIRE_EQUAL(m_responses.size(), 1);
201 BOOST_CHECK_EQUAL(checkResponse(0, expectedName, expectedResponse), CheckResponseResult::OK);
202 BOOST_CHECK_EQUAL(checkNextHop("/hello", 2, face2, 100), CheckNextHopResult::OK);
203}
204
205BOOST_AUTO_TEST_CASE(InitialAdd)
206{
207 FaceId addedFaceId = addFace();
Junxiao Shicde37ad2015-12-24 01:02:05 -0700208 BOOST_REQUIRE_NE(addedFaceId, face::INVALID_FACEID);
Yanbiao Li711c7932015-08-19 16:30:16 -0700209
210 auto parameters = makeParameters("hello", addedFaceId, 101);
211 auto command = makeControlCommandRequest("/localhost/nfd/fib/add-nexthop", parameters);
212
213 receiveInterest(command);
214 BOOST_REQUIRE_EQUAL(m_responses.size(), 1);
215 BOOST_CHECK_EQUAL(checkResponse(0, command->getName(), makeResponse(200, "Success", parameters)),
216 CheckResponseResult::OK);
217 BOOST_CHECK_EQUAL(checkNextHop("/hello", 1, addedFaceId, 101), CheckNextHopResult::OK);
218}
219
220BOOST_AUTO_TEST_CASE(ImplicitCost)
221{
222 FaceId addedFaceId = addFace();
Junxiao Shicde37ad2015-12-24 01:02:05 -0700223 BOOST_REQUIRE_NE(addedFaceId, face::INVALID_FACEID);
Yanbiao Li711c7932015-08-19 16:30:16 -0700224
225 auto originalParameters = ControlParameters().setName("/hello").setFaceId(addedFaceId);
226 auto parameters = makeParameters("/hello", addedFaceId, 0);
227 auto command = makeControlCommandRequest("/localhost/nfd/fib/add-nexthop", originalParameters);
228
229 receiveInterest(command);
230 BOOST_REQUIRE_EQUAL(m_responses.size(), 1);
231 BOOST_CHECK_EQUAL(checkResponse(0, command->getName(), makeResponse(200, "Success", parameters)),
232 CheckResponseResult::OK);
233 BOOST_CHECK_EQUAL(checkNextHop("/hello", 1, addedFaceId, 0), CheckNextHopResult::OK);
234}
235
236BOOST_AUTO_TEST_CASE(AddToExisting)
237{
238 FaceId face = addFace();
Junxiao Shicde37ad2015-12-24 01:02:05 -0700239 BOOST_REQUIRE_NE(face, face::INVALID_FACEID);
Yanbiao Li711c7932015-08-19 16:30:16 -0700240
241 Name expectedName;
242 ControlResponse expectedResponse;
243 auto testAddNextHop = [&] (const ControlParameters& parameters) {
244 m_responses.clear();
245 auto command = makeControlCommandRequest("/localhost/nfd/fib/add-nexthop", parameters);
246 expectedName = command->getName();
247 expectedResponse = makeResponse(200, "Success", parameters);
248 receiveInterest(command);
249 };
250
251 // add initial, succeeds
252 testAddNextHop(makeParameters("/hello", face, 101));
253 BOOST_REQUIRE_EQUAL(m_responses.size(), 1);
254 BOOST_CHECK_EQUAL(checkResponse(0, expectedName, expectedResponse), CheckResponseResult::OK);
255
256 // add to existing --> update cost, succeeds
257 testAddNextHop(makeParameters("/hello", face, 102));
258 BOOST_REQUIRE_EQUAL(m_responses.size(), 1);
259 BOOST_CHECK_EQUAL(checkResponse(0, expectedName, expectedResponse), CheckResponseResult::OK);
260
261 BOOST_CHECK_EQUAL(checkNextHop("/hello", 2, face, 102), CheckNextHopResult::WRONG_N_NEXTHOPS);
262 BOOST_CHECK_EQUAL(checkNextHop("/hello", 1, face, 101), CheckNextHopResult::WRONG_COST);
263 BOOST_CHECK_EQUAL(checkNextHop("/hello", 1, face, 102), CheckNextHopResult::OK);
264}
265
266BOOST_AUTO_TEST_SUITE_END() // AddNextHop
267
268BOOST_AUTO_TEST_SUITE(RemoveNextHop)
269
270BOOST_AUTO_TEST_CASE(Basic)
271{
272 Name expectedName;
273 ControlResponse expectedResponse;
274 auto testRemoveNextHop = [&] (const ControlParameters& parameters) {
275 m_responses.clear();
276 auto command = makeControlCommandRequest("/localhost/nfd/fib/remove-nexthop", parameters);
277 expectedName = command->getName();
278 expectedResponse = makeResponse(200, "Success", parameters);
279 receiveInterest(command);
280 };
281
282 FaceId face1 = addFace();
283 FaceId face2 = addFace();
284 FaceId face3 = addFace();
Junxiao Shicde37ad2015-12-24 01:02:05 -0700285 BOOST_REQUIRE_NE(face1, face::INVALID_FACEID);
286 BOOST_REQUIRE_NE(face2, face::INVALID_FACEID);
287 BOOST_REQUIRE_NE(face3, face::INVALID_FACEID);
Yanbiao Li711c7932015-08-19 16:30:16 -0700288
Junxiao Shia6de4292016-07-12 02:08:10 +0000289 fib::Entry* entry = m_fib.insert("/hello").first;
290 entry->addNextHop(*m_faceTable.get(face1), 101);
291 entry->addNextHop(*m_faceTable.get(face2), 202);
292 entry->addNextHop(*m_faceTable.get(face3), 303);
Yanbiao Li711c7932015-08-19 16:30:16 -0700293
294 testRemoveNextHop(makeParameters("/hello", face1));
295 BOOST_REQUIRE_EQUAL(m_responses.size(), 1);
296 BOOST_CHECK_EQUAL(checkResponse(0, expectedName, expectedResponse), CheckResponseResult::OK);
297 BOOST_CHECK_EQUAL(checkNextHop("/hello", 2, face1, 101), CheckNextHopResult::NO_NEXTHOP);
298
299 testRemoveNextHop(makeParameters("/hello", face2));
300 BOOST_REQUIRE_EQUAL(m_responses.size(), 1);
301 BOOST_CHECK_EQUAL(checkResponse(0, expectedName, expectedResponse), CheckResponseResult::OK);
302 BOOST_CHECK_EQUAL(checkNextHop("/hello", 1, face2, 202), CheckNextHopResult::NO_NEXTHOP);
303
304 testRemoveNextHop(makeParameters("/hello", face3));
305 BOOST_REQUIRE_EQUAL(m_responses.size(), 1);
306 BOOST_CHECK_EQUAL(checkResponse(0, expectedName, expectedResponse), CheckResponseResult::OK);
307 BOOST_CHECK_EQUAL(checkNextHop("/hello", 0, face3, 303), CheckNextHopResult::NO_FIB_ENTRY);
308}
309
310BOOST_AUTO_TEST_CASE(PrefixNotFound)
311{
312 FaceId addedFaceId = addFace();
Junxiao Shicde37ad2015-12-24 01:02:05 -0700313 BOOST_REQUIRE_NE(addedFaceId, face::INVALID_FACEID);
Yanbiao Li711c7932015-08-19 16:30:16 -0700314
315 auto parameters = makeParameters("hello", addedFaceId);
316 auto command = makeControlCommandRequest("/localhost/nfd/fib/remove-nexthop", parameters);
317 auto response = makeResponse(200, "Success", parameters);
318
319 receiveInterest(command);
320 BOOST_REQUIRE_EQUAL(m_responses.size(), 1);
321 BOOST_CHECK_EQUAL(checkResponse(0, command->getName(), response), CheckResponseResult::OK);
322}
323
324BOOST_AUTO_TEST_CASE(ImplicitFaceId)
325{
326 auto face1 = addFace();
327 auto face2 = addFace();
Junxiao Shicde37ad2015-12-24 01:02:05 -0700328 BOOST_REQUIRE_NE(face1, face::INVALID_FACEID);
329 BOOST_REQUIRE_NE(face2, face::INVALID_FACEID);
Yanbiao Li711c7932015-08-19 16:30:16 -0700330
331 Name expectedName;
332 ControlResponse expectedResponse;
333 auto testWithImplicitFaceId = [&] (ControlParameters parameters, FaceId face) {
334 m_responses.clear();
335 auto command = makeControlCommandRequest("/localhost/nfd/fib/remove-nexthop", parameters,
Junxiao Shi0de23a22015-12-03 20:07:02 +0000336 [face] (shared_ptr<Interest> interest) {
337 interest->setTag(make_shared<lp::IncomingFaceIdTag>(face));
338 });
Yanbiao Li711c7932015-08-19 16:30:16 -0700339 expectedName = command->getName();
340 expectedResponse = makeResponse(200, "Success", parameters.setFaceId(face));
341 receiveInterest(command);
342 };
343
Junxiao Shia6de4292016-07-12 02:08:10 +0000344 fib::Entry* entry = m_fib.insert("/hello").first;
345 entry->addNextHop(*m_faceTable.get(face1), 101);
346 entry->addNextHop(*m_faceTable.get(face2), 202);
Yanbiao Li711c7932015-08-19 16:30:16 -0700347
348 testWithImplicitFaceId(ControlParameters().setName("/hello").setFaceId(0), face1);
349 BOOST_REQUIRE_EQUAL(m_responses.size(), 1);
350 BOOST_CHECK_EQUAL(checkResponse(0, expectedName, expectedResponse), CheckResponseResult::OK);
351 BOOST_CHECK_EQUAL(checkNextHop("/hello", 1, face1, 101), CheckNextHopResult::NO_NEXTHOP);
352
353 testWithImplicitFaceId(ControlParameters().setName("/hello"), face2);
354 BOOST_REQUIRE_EQUAL(m_responses.size(), 1);
355 BOOST_CHECK_EQUAL(checkResponse(0, expectedName, expectedResponse), CheckResponseResult::OK);
356 BOOST_CHECK_EQUAL(checkNextHop("/hello", 0, face2, 202), CheckNextHopResult::NO_FIB_ENTRY);
357}
358
359BOOST_AUTO_TEST_CASE(RecordNotExist)
360{
361 auto face1 = addFace();
362 auto face2 = addFace();
Junxiao Shicde37ad2015-12-24 01:02:05 -0700363 BOOST_REQUIRE_NE(face1, face::INVALID_FACEID);
364 BOOST_REQUIRE_NE(face2, face::INVALID_FACEID);
Yanbiao Li711c7932015-08-19 16:30:16 -0700365
366 Name expectedName;
367 ControlResponse expectedResponse;
368 auto testRemoveNextHop = [&] (ControlParameters parameters) {
369 m_responses.clear();
370 auto command = makeControlCommandRequest("/localhost/nfd/fib/remove-nexthop", parameters);
371 expectedName = command->getName();
372 expectedResponse = makeResponse(200, "Success", parameters);
373 receiveInterest(command);
374 };
375
Junxiao Shia6de4292016-07-12 02:08:10 +0000376 m_fib.insert("/hello").first->addNextHop(*m_faceTable.get(face1), 101);
Yanbiao Li711c7932015-08-19 16:30:16 -0700377
378 testRemoveNextHop(makeParameters("/hello", face2 + 100));
379 BOOST_REQUIRE_EQUAL(m_responses.size(), 1); // face does not exist
380 BOOST_CHECK_EQUAL(checkResponse(0, expectedName, expectedResponse), CheckResponseResult::OK);
381 BOOST_CHECK_EQUAL(checkNextHop("/hello", -1, face2 + 100), CheckNextHopResult::NO_NEXTHOP);
382
383 testRemoveNextHop(makeParameters("/hello", face2));
384 BOOST_REQUIRE_EQUAL(m_responses.size(), 1); // record does not exist
385 BOOST_CHECK_EQUAL(checkResponse(0, expectedName, expectedResponse), CheckResponseResult::OK);
386 BOOST_CHECK_EQUAL(checkNextHop("/hello", -1, face2), CheckNextHopResult::NO_NEXTHOP);
387}
388
389BOOST_AUTO_TEST_SUITE_END() // RemoveNextHop
390
391// @todo Remove when ndn::nfd::FibEntry implements operator!= and operator<<
392class FibEntry : public ndn::nfd::FibEntry
393{
394public:
395 FibEntry() = default;
396
397 FibEntry(const ndn::nfd::FibEntry& entry)
398 : ndn::nfd::FibEntry(entry)
399 {
400 }
401};
402
403bool
404operator!=(const FibEntry& left, const FibEntry& right)
405{
406 if (left.getPrefix() != right.getPrefix()) {
407 return true;
408 }
409
410 auto leftNextHops = left.getNextHopRecords();
411 auto rightNextHops = right.getNextHopRecords();
412 if (leftNextHops.size() != rightNextHops.size()) {
413 return true;
414 }
415
416 for (auto&& nexthop : leftNextHops) {
417 auto hitEntry =
418 std::find_if(rightNextHops.begin(), rightNextHops.end(), [&] (const ndn::nfd::NextHopRecord& record) {
419 return nexthop.getCost() == record.getCost() && nexthop.getFaceId() == record.getFaceId();
420 });
421
422 if (hitEntry == rightNextHops.end()) {
423 return true;
424 }
425 }
426
427 return false;
428}
429
430std::ostream&
431operator<<(std::ostream &os, const FibEntry& entry)
432{
433 const auto& nexthops = entry.getNextHopRecords();
434 os << "[" << entry.getPrefix() << ", " << nexthops.size() << ": ";
435 for (auto record : nexthops) {
436 os << "{" << record.getFaceId() << ", " << record.getCost() << "} ";
437 }
438 os << "]";
439
440 return os;
441}
442
443BOOST_AUTO_TEST_CASE(FibDataset)
444{
445 const size_t nEntries = 108;
446 std::set<Name> actualPrefixes;
447 for (size_t i = 0 ; i < nEntries ; i ++) {
448 Name prefix = Name("test").appendSegment(i);
449 actualPrefixes.insert(prefix);
Junxiao Shia6de4292016-07-12 02:08:10 +0000450 fib::Entry* fibEntry = m_fib.insert(prefix).first;
451 fibEntry->addNextHop(*m_faceTable.get(addFace()), std::numeric_limits<uint8_t>::max() - 1);
452 fibEntry->addNextHop(*m_faceTable.get(addFace()), std::numeric_limits<uint8_t>::max() - 2);
Yanbiao Li711c7932015-08-19 16:30:16 -0700453 }
454
455 receiveInterest(makeInterest("/localhost/nfd/fib/list"));
456
457 Block content;
458 BOOST_CHECK_NO_THROW(content = concatenateResponses());
459 BOOST_CHECK_NO_THROW(content.parse());
460 BOOST_REQUIRE_EQUAL(content.elements().size(), nEntries);
461
462 std::vector<FibEntry> receivedRecords, expectedRecords;
463 for (size_t idx = 0; idx < nEntries; ++idx) {
464 BOOST_TEST_MESSAGE("processing element: " << idx);
465
466 FibEntry decodedEntry;
467 BOOST_REQUIRE_NO_THROW(decodedEntry.wireDecode(content.elements()[idx]));
468 receivedRecords.push_back(decodedEntry);
469
470 actualPrefixes.erase(decodedEntry.getPrefix());
471
472 auto matchedEntry = m_fib.findExactMatch(decodedEntry.getPrefix());
473 BOOST_REQUIRE(matchedEntry != nullptr);
474
475 FibEntry record;
476 record.setPrefix(matchedEntry->getPrefix());
477 const auto& nextHops = matchedEntry->getNextHops();
478 for (auto&& next : nextHops) {
479 ndn::nfd::NextHopRecord nextHopRecord;
Junxiao Shia6de4292016-07-12 02:08:10 +0000480 nextHopRecord.setFaceId(next.getFace().getId());
Yanbiao Li711c7932015-08-19 16:30:16 -0700481 nextHopRecord.setCost(next.getCost());
482 record.addNextHopRecord(nextHopRecord);
483 }
484 expectedRecords.push_back(record);
485 }
486
487 BOOST_CHECK_EQUAL(actualPrefixes.size(), 0);
488
489 BOOST_CHECK_EQUAL_COLLECTIONS(receivedRecords.begin(), receivedRecords.end(),
490 expectedRecords.begin(), expectedRecords.end());
491}
492
493BOOST_AUTO_TEST_SUITE_END() // TestFibManager
494BOOST_AUTO_TEST_SUITE_END() // Mgmt
495
496} // namespace tests
497} // namespace nfd