blob: 33cbdfe0c38c61d9cdb7a349087a5ddb5a901455 [file] [log] [blame]
Junxiao Shic1e12362014-01-24 20:03:26 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
ashiqopu3ad49db2018-10-20 22:38:47 +00002/*
3 * Copyright (c) 2014-2019, Regents of the University of California,
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -08004 * 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.
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
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/>.
Junxiao Shiee5a4442014-07-27 17:13:43 -070024 */
Junxiao Shic1e12362014-01-24 20:03:26 -070025
26#include "table/fib.hpp"
Junxiao Shi4370fde2016-02-24 12:20:46 -070027#include "table/pit.hpp"
28#include "table/measurements.hpp"
Junxiao Shic1e12362014-01-24 20:03:26 -070029
Junxiao Shid9ee45c2014-02-27 15:38:11 -070030#include "tests/test-common.hpp"
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040031#include "tests/daemon/global-io-fixture.hpp"
32#include "tests/daemon/face/dummy-face.hpp"
Junxiao Shic1e12362014-01-24 20:03:26 -070033
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080034namespace nfd {
Junxiao Shia6de4292016-07-12 02:08:10 +000035namespace fib {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070036namespace tests {
Junxiao Shic1e12362014-01-24 20:03:26 -070037
Junxiao Shia6de4292016-07-12 02:08:10 +000038using namespace nfd::tests;
39
Junxiao Shi4370fde2016-02-24 12:20:46 -070040BOOST_AUTO_TEST_SUITE(Table)
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040041BOOST_FIXTURE_TEST_SUITE(TestFib, GlobalIoFixture)
Junxiao Shic1e12362014-01-24 20:03:26 -070042
Junxiao Shia6de4292016-07-12 02:08:10 +000043BOOST_AUTO_TEST_CASE(FibEntry)
Junxiao Shic1e12362014-01-24 20:03:26 -070044{
45 Name prefix("ndn:/pxWhfFza");
Junxiao Shi8c8d2182014-01-30 22:33:00 -070046 shared_ptr<Face> face1 = make_shared<DummyFace>();
47 shared_ptr<Face> face2 = make_shared<DummyFace>();
Junxiao Shiefceadc2014-03-09 18:52:57 -070048
Junxiao Shia6de4292016-07-12 02:08:10 +000049 Entry entry(prefix);
Junxiao Shiefceadc2014-03-09 18:52:57 -070050 BOOST_CHECK_EQUAL(entry.getPrefix(), prefix);
51
Junxiao Shic1e12362014-01-24 20:03:26 -070052 // []
Junxiao Shia6de4292016-07-12 02:08:10 +000053 BOOST_CHECK_EQUAL(entry.getNextHops().size(), 0);
Junxiao Shiefceadc2014-03-09 18:52:57 -070054
Md Ashiqur Rahman6be93872019-08-07 01:25:31 +000055 entry.addOrUpdateNextHop(*face1, 20);
56 // [(face1,20)]
Junxiao Shia6de4292016-07-12 02:08:10 +000057 BOOST_CHECK_EQUAL(entry.getNextHops().size(), 1);
58 BOOST_CHECK_EQUAL(&entry.getNextHops().begin()->getFace(), face1.get());
59 BOOST_CHECK_EQUAL(entry.getNextHops().begin()->getCost(), 20);
Junxiao Shiefceadc2014-03-09 18:52:57 -070060
Md Ashiqur Rahman6be93872019-08-07 01:25:31 +000061 entry.addOrUpdateNextHop(*face1, 30);
62 // [(face1,30)]
63 BOOST_CHECK_EQUAL(entry.getNextHops().size(), 1);
ashiqopu3ad49db2018-10-20 22:38:47 +000064 BOOST_CHECK_EQUAL(&entry.getNextHops().begin()->getFace(), face1.get());
Md Ashiqur Rahman6be93872019-08-07 01:25:31 +000065 BOOST_CHECK_EQUAL(entry.getNextHops().begin()->getCost(), 30);
ashiqopu3ad49db2018-10-20 22:38:47 +000066
Md Ashiqur Rahman6be93872019-08-07 01:25:31 +000067 entry.addOrUpdateNextHop(*face2, 40);
68 // [(face1,30), (face2,40)]
69 BOOST_CHECK_EQUAL(entry.getNextHops().size(), 2);
Junxiao Shia6de4292016-07-12 02:08:10 +000070 {
71 NextHopList::const_iterator it = entry.getNextHops().begin();
72 BOOST_REQUIRE(it != entry.getNextHops().end());
73 BOOST_CHECK_EQUAL(&it->getFace(), face1.get());
74 BOOST_CHECK_EQUAL(it->getCost(), 30);
75
76 ++it;
77 BOOST_REQUIRE(it != entry.getNextHops().end());
78 BOOST_CHECK_EQUAL(&it->getFace(), face2.get());
79 BOOST_CHECK_EQUAL(it->getCost(), 40);
80
81 ++it;
82 BOOST_CHECK(it == entry.getNextHops().end());
Junxiao Shic1e12362014-01-24 20:03:26 -070083 }
84
Md Ashiqur Rahman6be93872019-08-07 01:25:31 +000085 entry.addOrUpdateNextHop(*face2, 10);
86 // [(face2,10), (face1,30)]
87 BOOST_CHECK_EQUAL(entry.getNextHops().size(), 2);
Junxiao Shia6de4292016-07-12 02:08:10 +000088 {
89 NextHopList::const_iterator it = entry.getNextHops().begin();
90 BOOST_REQUIRE(it != entry.getNextHops().end());
91 BOOST_CHECK_EQUAL(&it->getFace(), face2.get());
92 BOOST_CHECK_EQUAL(it->getCost(), 10);
93
94 ++it;
95 BOOST_REQUIRE(it != entry.getNextHops().end());
96 BOOST_CHECK_EQUAL(&it->getFace(), face1.get());
97 BOOST_CHECK_EQUAL(it->getCost(), 30);
98
99 ++it;
100 BOOST_CHECK(it == entry.getNextHops().end());
Junxiao Shic1e12362014-01-24 20:03:26 -0700101 }
Junxiao Shiefceadc2014-03-09 18:52:57 -0700102
Md Ashiqur Rahman6be93872019-08-07 01:25:31 +0000103 entry.removeNextHop(*face1);
104 // [(face2,10)]
ashiqopu3ad49db2018-10-20 22:38:47 +0000105 BOOST_CHECK_EQUAL(entry.getNextHops().size(), 1);
Md Ashiqur Rahman6be93872019-08-07 01:25:31 +0000106 BOOST_CHECK_EQUAL(entry.getNextHops().begin()->getFace().getId(), face2->getId());
107 BOOST_CHECK_EQUAL(entry.getNextHops().begin()->getCost(), 10);
ashiqopu3ad49db2018-10-20 22:38:47 +0000108
Md Ashiqur Rahman6be93872019-08-07 01:25:31 +0000109 entry.removeNextHop(*face1);
110 // [(face2,10)]
111 BOOST_CHECK_EQUAL(entry.getNextHops().size(), 1);
112 BOOST_CHECK_EQUAL(entry.getNextHops().begin()->getFace().getId(), face2->getId());
113 BOOST_CHECK_EQUAL(entry.getNextHops().begin()->getCost(), 10);
114
115 entry.removeNextHop(*face2);
Junxiao Shic1e12362014-01-24 20:03:26 -0700116 // []
Junxiao Shia6de4292016-07-12 02:08:10 +0000117 BOOST_CHECK_EQUAL(entry.getNextHops().size(), 0);
Junxiao Shiefceadc2014-03-09 18:52:57 -0700118
Md Ashiqur Rahman6be93872019-08-07 01:25:31 +0000119 entry.removeNextHop(*face2);
Junxiao Shic1e12362014-01-24 20:03:26 -0700120 // []
Junxiao Shia6de4292016-07-12 02:08:10 +0000121 BOOST_CHECK_EQUAL(entry.getNextHops().size(), 0);
Junxiao Shic1e12362014-01-24 20:03:26 -0700122}
123
124BOOST_AUTO_TEST_CASE(Insert_LongestPrefixMatch)
125{
Haowei Yuanf52dac72014-03-24 23:35:03 -0500126 NameTree nameTree;
HangZhangad4afd12014-03-01 11:03:08 +0800127 Fib fib(nameTree);
Junxiao Shia6de4292016-07-12 02:08:10 +0000128
Junxiao Shi40631842014-03-01 13:52:37 -0700129 // []
Junxiao Shiefceadc2014-03-09 18:52:57 -0700130 BOOST_CHECK_EQUAL(fib.size(), 0);
Junxiao Shia6de4292016-07-12 02:08:10 +0000131 BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch("/A").getPrefix(), "/"); // the empty entry
Junxiao Shi40631842014-03-01 13:52:37 -0700132
Junxiao Shia6de4292016-07-12 02:08:10 +0000133 std::pair<Entry*, bool> insertRes = fib.insert("/");
Junxiao Shi40631842014-03-01 13:52:37 -0700134 BOOST_CHECK_EQUAL(insertRes.second, true);
Junxiao Shia6de4292016-07-12 02:08:10 +0000135 BOOST_REQUIRE(insertRes.first != nullptr);
136 BOOST_CHECK_EQUAL(insertRes.first->getPrefix(), "/");
Junxiao Shic1e12362014-01-24 20:03:26 -0700137 // ['/']
Junxiao Shiefceadc2014-03-09 18:52:57 -0700138 BOOST_CHECK_EQUAL(fib.size(), 1);
139
Junxiao Shia6de4292016-07-12 02:08:10 +0000140 BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch("/A").getPrefix(), "/");
Junxiao Shiefceadc2014-03-09 18:52:57 -0700141
Junxiao Shia6de4292016-07-12 02:08:10 +0000142 insertRes = fib.insert("/A");
Junxiao Shic1e12362014-01-24 20:03:26 -0700143 BOOST_CHECK_EQUAL(insertRes.second, true);
Junxiao Shia6de4292016-07-12 02:08:10 +0000144 BOOST_REQUIRE(insertRes.first != nullptr);
145 BOOST_CHECK_EQUAL(insertRes.first->getPrefix(), "/A");
Junxiao Shic1e12362014-01-24 20:03:26 -0700146 // ['/', '/A']
Junxiao Shiefceadc2014-03-09 18:52:57 -0700147 BOOST_CHECK_EQUAL(fib.size(), 2);
148
Junxiao Shia6de4292016-07-12 02:08:10 +0000149 insertRes = fib.insert("/A");
Junxiao Shic1e12362014-01-24 20:03:26 -0700150 BOOST_CHECK_EQUAL(insertRes.second, false);
Junxiao Shia6de4292016-07-12 02:08:10 +0000151 BOOST_REQUIRE(insertRes.first != nullptr);
152 BOOST_CHECK_EQUAL(insertRes.first->getPrefix(), "/A");
Junxiao Shic1e12362014-01-24 20:03:26 -0700153 // ['/', '/A']
Junxiao Shiefceadc2014-03-09 18:52:57 -0700154 BOOST_CHECK_EQUAL(fib.size(), 2);
Junxiao Shic1e12362014-01-24 20:03:26 -0700155
Junxiao Shia6de4292016-07-12 02:08:10 +0000156 BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch("/A").getPrefix(), "/A");
Junxiao Shiefceadc2014-03-09 18:52:57 -0700157
Junxiao Shia6de4292016-07-12 02:08:10 +0000158 BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch("/A/B/C/D").getPrefix(), "/A");
Junxiao Shiefceadc2014-03-09 18:52:57 -0700159
Junxiao Shia6de4292016-07-12 02:08:10 +0000160 insertRes = fib.insert("/A/B/C");
Junxiao Shic1e12362014-01-24 20:03:26 -0700161 BOOST_CHECK_EQUAL(insertRes.second, true);
Junxiao Shia6de4292016-07-12 02:08:10 +0000162 BOOST_REQUIRE(insertRes.first != nullptr);
163 BOOST_CHECK_EQUAL(insertRes.first->getPrefix(), "/A/B/C");
Junxiao Shic1e12362014-01-24 20:03:26 -0700164 // ['/', '/A', '/A/B/C']
Junxiao Shiefceadc2014-03-09 18:52:57 -0700165 BOOST_CHECK_EQUAL(fib.size(), 3);
Junxiao Shic1e12362014-01-24 20:03:26 -0700166
Junxiao Shia6de4292016-07-12 02:08:10 +0000167 BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch("/A").getPrefix(), "/A");
168 BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch("/A/B").getPrefix(), "/A");
169 BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch("/A/B/C/D").getPrefix(), "/A/B/C");
170 BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch("/E").getPrefix(), "/");
Junxiao Shic1e12362014-01-24 20:03:26 -0700171}
172
Junxiao Shi4370fde2016-02-24 12:20:46 -0700173BOOST_AUTO_TEST_CASE(LongestPrefixMatchWithPitEntry)
174{
175 NameTree nameTree;
176 Fib fib(nameTree);
177
178 shared_ptr<Data> dataABC = makeData("/A/B/C");
179 Name fullNameABC = dataABC->getFullName();
180 shared_ptr<Data> dataADE = makeData("/A/D/E");
181 Name fullNameADE = dataADE->getFullName();
182 fib.insert("/A");
183 fib.insert(fullNameABC);
184
185 Pit pit(nameTree);
186 shared_ptr<Interest> interestAB = makeInterest("/A/B");
187 shared_ptr<pit::Entry> pitAB = pit.insert(*interestAB).first;
188 shared_ptr<Interest> interestABC = makeInterest(fullNameABC);
189 shared_ptr<pit::Entry> pitABC = pit.insert(*interestABC).first;
190 shared_ptr<Interest> interestADE = makeInterest(fullNameADE);
191 shared_ptr<pit::Entry> pitADE = pit.insert(*interestADE).first;
192
Junxiao Shia6de4292016-07-12 02:08:10 +0000193 size_t nNameTreeEntriesBefore = nameTree.size();
Junxiao Shi4370fde2016-02-24 12:20:46 -0700194
Junxiao Shia6de4292016-07-12 02:08:10 +0000195 BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch(*pitAB).getPrefix(), "/A");
196 BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch(*pitABC).getPrefix(), fullNameABC);
197 BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch(*pitADE).getPrefix(), "/A");
Junxiao Shi4370fde2016-02-24 12:20:46 -0700198
Junxiao Shia6de4292016-07-12 02:08:10 +0000199 BOOST_CHECK_EQUAL(nameTree.size(), nNameTreeEntriesBefore);
Junxiao Shi4370fde2016-02-24 12:20:46 -0700200}
201
202BOOST_AUTO_TEST_CASE(LongestPrefixMatchWithMeasurementsEntry)
203{
204 NameTree nameTree;
205 Fib fib(nameTree);
206
207 fib.insert("/A");
208 fib.insert("/A/B/C");
209
210 Measurements measurements(nameTree);
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000211 measurements::Entry& mAB = measurements.get("/A/B");
212 measurements::Entry& mABCD = measurements.get("/A/B/C/D");
Junxiao Shi4370fde2016-02-24 12:20:46 -0700213
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000214 BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch(mAB).getPrefix(), "/A");
215 BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch(mABCD).getPrefix(), "/A/B/C");
Junxiao Shi4370fde2016-02-24 12:20:46 -0700216}
217
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700218void
Junxiao Shia6de4292016-07-12 02:08:10 +0000219validateFindExactMatch(Fib& fib, const Name& target)
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700220{
Junxiao Shia6de4292016-07-12 02:08:10 +0000221 const Entry* entry = fib.findExactMatch(target);
222 BOOST_REQUIRE_MESSAGE(entry != nullptr, "No entry found for " << target);
223 BOOST_CHECK_EQUAL(entry->getPrefix(), target);
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700224}
225
226void
Junxiao Shia6de4292016-07-12 02:08:10 +0000227validateNoExactMatch(Fib& fib, const Name& target)
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700228{
Junxiao Shia6de4292016-07-12 02:08:10 +0000229 const Entry* entry = fib.findExactMatch(target);
230 BOOST_CHECK_MESSAGE(entry == nullptr,
231 "Found unexpected entry for " << target);
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700232}
233
Junxiao Shia6de4292016-07-12 02:08:10 +0000234BOOST_AUTO_TEST_CASE(ExactMatch)
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700235{
Haowei Yuanf52dac72014-03-24 23:35:03 -0500236 NameTree nameTree;
HangZhangad4afd12014-03-01 11:03:08 +0800237 Fib fib(nameTree);
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700238 fib.insert("/A");
239 fib.insert("/A/B");
240 fib.insert("/A/B/C");
241
242 validateFindExactMatch(fib, "/A");
243 validateFindExactMatch(fib, "/A/B");
244 validateFindExactMatch(fib, "/A/B/C");
Junxiao Shia6de4292016-07-12 02:08:10 +0000245
Junxiao Shi40631842014-03-01 13:52:37 -0700246 validateNoExactMatch(fib, "/");
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700247 validateNoExactMatch(fib, "/does/not/exist");
Junxiao Shia6de4292016-07-12 02:08:10 +0000248}
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700249
Junxiao Shia6de4292016-07-12 02:08:10 +0000250BOOST_AUTO_TEST_CASE(ExactMatchGap)
251{
252 NameTree nameTree;
253 Fib fib(nameTree);
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700254 fib.insert("/X");
255 fib.insert("/X/Y/Z");
256
Junxiao Shia6de4292016-07-12 02:08:10 +0000257 validateNoExactMatch(fib, "/X/Y");
258}
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700259
Junxiao Shia6de4292016-07-12 02:08:10 +0000260BOOST_AUTO_TEST_CASE(ExactMatchEmpty)
261{
262 NameTree nameTree;
263 Fib fib(nameTree);
264 validateNoExactMatch(fib, "/");
265 validateNoExactMatch(fib, "/nothing/here");
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700266}
267
268void
Junxiao Shiee5a4442014-07-27 17:13:43 -0700269validateErase(Fib& fib, const Name& target)
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700270{
HangZhangad4afd12014-03-01 11:03:08 +0800271 fib.erase(target);
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700272
Junxiao Shia6de4292016-07-12 02:08:10 +0000273 const Entry* entry = fib.findExactMatch(target);
274 BOOST_CHECK_MESSAGE(entry == nullptr, "Found \"removed\" entry for " << target);
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700275}
276
Junxiao Shiee5a4442014-07-27 17:13:43 -0700277BOOST_AUTO_TEST_CASE(Erase)
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700278{
Haowei Yuanf52dac72014-03-24 23:35:03 -0500279 NameTree nameTree;
HangZhangad4afd12014-03-01 11:03:08 +0800280 Fib fib(nameTree);
Junxiao Shi40631842014-03-01 13:52:37 -0700281 fib.insert("/");
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700282 fib.insert("/A");
283 fib.insert("/A/B");
284 fib.insert("/A/B/C");
285
286 // check if we remove the right thing and leave
287 // everything else alone
288
Junxiao Shiee5a4442014-07-27 17:13:43 -0700289 validateErase(fib, "/A/B");
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700290 validateFindExactMatch(fib, "/A");
291 validateFindExactMatch(fib, "/A/B/C");
292 validateFindExactMatch(fib, "/");
293
Junxiao Shiee5a4442014-07-27 17:13:43 -0700294 validateErase(fib, "/A/B/C");
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700295 validateFindExactMatch(fib, "/A");
296 validateFindExactMatch(fib, "/");
297
Junxiao Shiee5a4442014-07-27 17:13:43 -0700298 validateErase(fib, "/A");
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700299 validateFindExactMatch(fib, "/");
300
Junxiao Shiee5a4442014-07-27 17:13:43 -0700301 validateErase(fib, "/");
Junxiao Shi40631842014-03-01 13:52:37 -0700302 validateNoExactMatch(fib, "/");
Junxiao Shia6de4292016-07-12 02:08:10 +0000303}
Junxiao Shi40631842014-03-01 13:52:37 -0700304
Junxiao Shia6de4292016-07-12 02:08:10 +0000305BOOST_AUTO_TEST_CASE(EraseGap)
306{
307 NameTree nameTree;
308 Fib fib(nameTree);
309 fib.insert("/X");
310 fib.insert("/X/Y/Z");
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700311
Junxiao Shia6de4292016-07-12 02:08:10 +0000312 fib.erase("/X/Y"); //should do nothing
313 validateFindExactMatch(fib, "/X");
314 validateFindExactMatch(fib, "/X/Y/Z");
315}
316
317BOOST_AUTO_TEST_CASE(EraseEmpty)
318{
319 NameTree nameTree;
320 Fib fib(nameTree);
321
322 BOOST_CHECK_NO_THROW(fib.erase("/does/not/exist"));
323 validateErase(fib, "/");
324 BOOST_CHECK_NO_THROW(fib.erase("/still/does/not/exist"));
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700325}
326
Junxiao Shiee5a4442014-07-27 17:13:43 -0700327BOOST_AUTO_TEST_CASE(EraseNameTreeEntry)
328{
329 NameTree nameTree;
330 Fib fib(nameTree);
331 size_t nNameTreeEntriesBefore = nameTree.size();
332
Junxiao Shia6de4292016-07-12 02:08:10 +0000333 fib.insert("/A/B/C");
334 fib.erase("/A/B/C");
Junxiao Shiee5a4442014-07-27 17:13:43 -0700335 BOOST_CHECK_EQUAL(nameTree.size(), nNameTreeEntriesBefore);
336}
337
HangZhang5d469422014-03-12 09:26:26 +0800338BOOST_AUTO_TEST_CASE(Iterator)
339{
Haowei Yuanf52dac72014-03-24 23:35:03 -0500340 NameTree nameTree;
HangZhang5d469422014-03-12 09:26:26 +0800341 Fib fib(nameTree);
342 Name nameA("/A");
343 Name nameAB("/A/B");
344 Name nameABC("/A/B/C");
345 Name nameRoot("/");
346
347 fib.insert(nameA);
348 fib.insert(nameAB);
349 fib.insert(nameABC);
350 fib.insert(nameRoot);
351
Junxiao Shia6de4292016-07-12 02:08:10 +0000352 std::set<Name> expected{nameA, nameAB, nameABC, nameRoot};
HangZhang5d469422014-03-12 09:26:26 +0800353
Junxiao Shi4370fde2016-02-24 12:20:46 -0700354 for (Fib::const_iterator it = fib.begin(); it != fib.end(); it++) {
HangZhang5d469422014-03-12 09:26:26 +0800355 bool isInSet = expected.find(it->getPrefix()) != expected.end();
356 BOOST_CHECK(isInSet);
357 expected.erase(it->getPrefix());
358 }
359
360 BOOST_CHECK_EQUAL(expected.size(), 0);
361}
362
Junxiao Shi4370fde2016-02-24 12:20:46 -0700363BOOST_AUTO_TEST_SUITE_END() // TestFib
364BOOST_AUTO_TEST_SUITE_END() // Table
Junxiao Shic1e12362014-01-24 20:03:26 -0700365
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700366} // namespace tests
Junxiao Shia6de4292016-07-12 02:08:10 +0000367} // namespace fib
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800368} // namespace nfd