blob: 35fcd3e983754aee2ce08aa3e97c73c0b5a6a5fc [file] [log] [blame]
Junxiao Shic1e12362014-01-24 20:03:26 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shiee5a4442014-07-27 17:13:43 -07003 * 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
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"
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070027#include "tests/daemon/face/dummy-face.hpp"
Junxiao Shic1e12362014-01-24 20:03:26 -070028
Junxiao Shid9ee45c2014-02-27 15:38:11 -070029#include "tests/test-common.hpp"
Junxiao Shic1e12362014-01-24 20:03:26 -070030
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080031namespace nfd {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070032namespace tests {
Junxiao Shic1e12362014-01-24 20:03:26 -070033
Junxiao Shid9ee45c2014-02-27 15:38:11 -070034BOOST_FIXTURE_TEST_SUITE(TableFib, BaseFixture)
Junxiao Shic1e12362014-01-24 20:03:26 -070035
36BOOST_AUTO_TEST_CASE(Entry)
37{
38 Name prefix("ndn:/pxWhfFza");
Junxiao Shi8c8d2182014-01-30 22:33:00 -070039 shared_ptr<Face> face1 = make_shared<DummyFace>();
40 shared_ptr<Face> face2 = make_shared<DummyFace>();
Junxiao Shiefceadc2014-03-09 18:52:57 -070041
Junxiao Shic1e12362014-01-24 20:03:26 -070042 fib::Entry entry(prefix);
Junxiao Shiefceadc2014-03-09 18:52:57 -070043 BOOST_CHECK_EQUAL(entry.getPrefix(), prefix);
44
Junxiao Shic1e12362014-01-24 20:03:26 -070045 const fib::NextHopList& nexthops1 = entry.getNextHops();
46 // []
47 BOOST_CHECK_EQUAL(nexthops1.size(), 0);
Junxiao Shiefceadc2014-03-09 18:52:57 -070048
Junxiao Shic1e12362014-01-24 20:03:26 -070049 entry.addNextHop(face1, 20);
50 const fib::NextHopList& nexthops2 = entry.getNextHops();
51 // [(face1,20)]
52 BOOST_CHECK_EQUAL(nexthops2.size(), 1);
53 BOOST_CHECK_EQUAL(nexthops2.begin()->getFace(), face1);
54 BOOST_CHECK_EQUAL(nexthops2.begin()->getCost(), 20);
Junxiao Shiefceadc2014-03-09 18:52:57 -070055
Junxiao Shic1e12362014-01-24 20:03:26 -070056 entry.addNextHop(face1, 30);
57 const fib::NextHopList& nexthops3 = entry.getNextHops();
58 // [(face1,30)]
59 BOOST_CHECK_EQUAL(nexthops3.size(), 1);
60 BOOST_CHECK_EQUAL(nexthops3.begin()->getFace(), face1);
61 BOOST_CHECK_EQUAL(nexthops3.begin()->getCost(), 30);
62
63 entry.addNextHop(face2, 40);
64 const fib::NextHopList& nexthops4 = entry.getNextHops();
65 // [(face1,30), (face2,40)]
66 BOOST_CHECK_EQUAL(nexthops4.size(), 2);
67 int i = -1;
68 for (fib::NextHopList::const_iterator it = nexthops4.begin();
69 it != nexthops4.end(); ++it) {
70 ++i;
71 switch (i) {
72 case 0 :
73 BOOST_CHECK_EQUAL(it->getFace(), face1);
74 BOOST_CHECK_EQUAL(it->getCost(), 30);
75 break;
76 case 1 :
77 BOOST_CHECK_EQUAL(it->getFace(), face2);
78 BOOST_CHECK_EQUAL(it->getCost(), 40);
79 break;
80 }
81 }
82
83 entry.addNextHop(face2, 10);
84 const fib::NextHopList& nexthops5 = entry.getNextHops();
85 // [(face2,10), (face1,30)]
86 BOOST_CHECK_EQUAL(nexthops5.size(), 2);
87 i = -1;
88 for (fib::NextHopList::const_iterator it = nexthops5.begin();
89 it != nexthops5.end(); ++it) {
90 ++i;
91 switch (i) {
92 case 0 :
93 BOOST_CHECK_EQUAL(it->getFace(), face2);
94 BOOST_CHECK_EQUAL(it->getCost(), 10);
95 break;
96 case 1 :
97 BOOST_CHECK_EQUAL(it->getFace(), face1);
98 BOOST_CHECK_EQUAL(it->getCost(), 30);
99 break;
100 }
101 }
Junxiao Shiefceadc2014-03-09 18:52:57 -0700102
Junxiao Shic1e12362014-01-24 20:03:26 -0700103 entry.removeNextHop(face1);
104 const fib::NextHopList& nexthops6 = entry.getNextHops();
105 // [(face2,10)]
106 BOOST_CHECK_EQUAL(nexthops6.size(), 1);
107 BOOST_CHECK_EQUAL(nexthops6.begin()->getFace(), face2);
108 BOOST_CHECK_EQUAL(nexthops6.begin()->getCost(), 10);
Junxiao Shiefceadc2014-03-09 18:52:57 -0700109
Junxiao Shic1e12362014-01-24 20:03:26 -0700110 entry.removeNextHop(face1);
111 const fib::NextHopList& nexthops7 = entry.getNextHops();
112 // [(face2,10)]
113 BOOST_CHECK_EQUAL(nexthops7.size(), 1);
114 BOOST_CHECK_EQUAL(nexthops7.begin()->getFace(), face2);
115 BOOST_CHECK_EQUAL(nexthops7.begin()->getCost(), 10);
Junxiao Shiefceadc2014-03-09 18:52:57 -0700116
Junxiao Shic1e12362014-01-24 20:03:26 -0700117 entry.removeNextHop(face2);
118 const fib::NextHopList& nexthops8 = entry.getNextHops();
119 // []
120 BOOST_CHECK_EQUAL(nexthops8.size(), 0);
Junxiao Shiefceadc2014-03-09 18:52:57 -0700121
Junxiao Shic1e12362014-01-24 20:03:26 -0700122 entry.removeNextHop(face2);
123 const fib::NextHopList& nexthops9 = entry.getNextHops();
124 // []
125 BOOST_CHECK_EQUAL(nexthops9.size(), 0);
126}
127
128BOOST_AUTO_TEST_CASE(Insert_LongestPrefixMatch)
129{
130 Name nameEmpty;
131 Name nameA ("ndn:/A");
132 Name nameAB ("ndn:/A/B");
133 Name nameABC ("ndn:/A/B/C");
134 Name nameABCD("ndn:/A/B/C/D");
135 Name nameE ("ndn:/E");
Junxiao Shiefceadc2014-03-09 18:52:57 -0700136
Junxiao Shic1e12362014-01-24 20:03:26 -0700137 std::pair<shared_ptr<fib::Entry>, bool> insertRes;
138 shared_ptr<fib::Entry> entry;
139
Haowei Yuanf52dac72014-03-24 23:35:03 -0500140 NameTree nameTree;
HangZhangad4afd12014-03-01 11:03:08 +0800141 Fib fib(nameTree);
Junxiao Shi40631842014-03-01 13:52:37 -0700142 // []
Junxiao Shiefceadc2014-03-09 18:52:57 -0700143 BOOST_CHECK_EQUAL(fib.size(), 0);
Junxiao Shi40631842014-03-01 13:52:37 -0700144
145 entry = fib.findLongestPrefixMatch(nameA);
146 BOOST_REQUIRE(static_cast<bool>(entry)); // the empty entry
Junxiao Shiefceadc2014-03-09 18:52:57 -0700147
Junxiao Shi40631842014-03-01 13:52:37 -0700148 insertRes = fib.insert(nameEmpty);
149 BOOST_CHECK_EQUAL(insertRes.second, true);
150 BOOST_CHECK_EQUAL(insertRes.first->getPrefix(), nameEmpty);
Junxiao Shic1e12362014-01-24 20:03:26 -0700151 // ['/']
Junxiao Shiefceadc2014-03-09 18:52:57 -0700152 BOOST_CHECK_EQUAL(fib.size(), 1);
153
Junxiao Shic1e12362014-01-24 20:03:26 -0700154 entry = fib.findLongestPrefixMatch(nameA);
Junxiao Shi40631842014-03-01 13:52:37 -0700155 BOOST_REQUIRE(static_cast<bool>(entry));
156 BOOST_CHECK_EQUAL(entry->getPrefix(), nameEmpty);
Junxiao Shiefceadc2014-03-09 18:52:57 -0700157
Junxiao Shic1e12362014-01-24 20:03:26 -0700158 insertRes = fib.insert(nameA);
159 BOOST_CHECK_EQUAL(insertRes.second, true);
Junxiao Shi40631842014-03-01 13:52:37 -0700160 BOOST_CHECK_EQUAL(insertRes.first->getPrefix(), nameA);
Junxiao Shic1e12362014-01-24 20:03:26 -0700161 // ['/', '/A']
Junxiao Shiefceadc2014-03-09 18:52:57 -0700162 BOOST_CHECK_EQUAL(fib.size(), 2);
163
Junxiao Shic1e12362014-01-24 20:03:26 -0700164 insertRes = fib.insert(nameA);
165 BOOST_CHECK_EQUAL(insertRes.second, false);
Junxiao Shi40631842014-03-01 13:52:37 -0700166 BOOST_CHECK_EQUAL(insertRes.first->getPrefix(), nameA);
Junxiao Shic1e12362014-01-24 20:03:26 -0700167 // ['/', '/A']
Junxiao Shiefceadc2014-03-09 18:52:57 -0700168 BOOST_CHECK_EQUAL(fib.size(), 2);
Junxiao Shic1e12362014-01-24 20:03:26 -0700169
170 entry = fib.findLongestPrefixMatch(nameA);
Junxiao Shi40631842014-03-01 13:52:37 -0700171 BOOST_REQUIRE(static_cast<bool>(entry));
172 BOOST_CHECK_EQUAL(entry->getPrefix(), nameA);
Junxiao Shiefceadc2014-03-09 18:52:57 -0700173
Junxiao Shic1e12362014-01-24 20:03:26 -0700174 entry = fib.findLongestPrefixMatch(nameABCD);
Junxiao Shi40631842014-03-01 13:52:37 -0700175 BOOST_REQUIRE(static_cast<bool>(entry));
176 BOOST_CHECK_EQUAL(entry->getPrefix(), nameA);
Junxiao Shiefceadc2014-03-09 18:52:57 -0700177
Junxiao Shic1e12362014-01-24 20:03:26 -0700178 insertRes = fib.insert(nameABC);
179 BOOST_CHECK_EQUAL(insertRes.second, true);
Junxiao Shi40631842014-03-01 13:52:37 -0700180 BOOST_CHECK_EQUAL(insertRes.first->getPrefix(), nameABC);
Junxiao Shic1e12362014-01-24 20:03:26 -0700181 // ['/', '/A', '/A/B/C']
Junxiao Shiefceadc2014-03-09 18:52:57 -0700182 BOOST_CHECK_EQUAL(fib.size(), 3);
Junxiao Shic1e12362014-01-24 20:03:26 -0700183
184 entry = fib.findLongestPrefixMatch(nameA);
Junxiao Shi40631842014-03-01 13:52:37 -0700185 BOOST_REQUIRE(static_cast<bool>(entry));
186 BOOST_CHECK_EQUAL(entry->getPrefix(), nameA);
Junxiao Shiefceadc2014-03-09 18:52:57 -0700187
Junxiao Shic1e12362014-01-24 20:03:26 -0700188 entry = fib.findLongestPrefixMatch(nameAB);
Junxiao Shi40631842014-03-01 13:52:37 -0700189 BOOST_REQUIRE(static_cast<bool>(entry));
190 BOOST_CHECK_EQUAL(entry->getPrefix(), nameA);
Junxiao Shiefceadc2014-03-09 18:52:57 -0700191
Junxiao Shic1e12362014-01-24 20:03:26 -0700192 entry = fib.findLongestPrefixMatch(nameABCD);
Junxiao Shi40631842014-03-01 13:52:37 -0700193 BOOST_REQUIRE(static_cast<bool>(entry));
194 BOOST_CHECK_EQUAL(entry->getPrefix(), nameABC);
Junxiao Shiefceadc2014-03-09 18:52:57 -0700195
Junxiao Shic1e12362014-01-24 20:03:26 -0700196 entry = fib.findLongestPrefixMatch(nameE);
Junxiao Shi40631842014-03-01 13:52:37 -0700197 BOOST_REQUIRE(static_cast<bool>(entry));
198 BOOST_CHECK_EQUAL(entry->getPrefix(), nameEmpty);
Junxiao Shic1e12362014-01-24 20:03:26 -0700199}
200
201BOOST_AUTO_TEST_CASE(RemoveNextHopFromAllEntries)
202{
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700203 shared_ptr<Face> face1 = make_shared<DummyFace>();
204 shared_ptr<Face> face2 = make_shared<DummyFace>();
Junxiao Shiefceadc2014-03-09 18:52:57 -0700205 Name nameEmpty("ndn:/");
Junxiao Shic1e12362014-01-24 20:03:26 -0700206 Name nameA("ndn:/A");
207 Name nameB("ndn:/B");
Junxiao Shiefceadc2014-03-09 18:52:57 -0700208
Junxiao Shic1e12362014-01-24 20:03:26 -0700209 std::pair<shared_ptr<fib::Entry>, bool> insertRes;
210 shared_ptr<fib::Entry> entry;
Junxiao Shiefceadc2014-03-09 18:52:57 -0700211
Haowei Yuanf52dac72014-03-24 23:35:03 -0500212 NameTree nameTree;
HangZhangad4afd12014-03-01 11:03:08 +0800213 Fib fib(nameTree);
Junxiao Shiefceadc2014-03-09 18:52:57 -0700214 // {}
215
Junxiao Shic1e12362014-01-24 20:03:26 -0700216 insertRes = fib.insert(nameA);
217 insertRes.first->addNextHop(face1, 0);
218 insertRes.first->addNextHop(face2, 0);
Junxiao Shiefceadc2014-03-09 18:52:57 -0700219 // {'/A':[1,2]}
Junxiao Shic1e12362014-01-24 20:03:26 -0700220
221 insertRes = fib.insert(nameB);
222 insertRes.first->addNextHop(face1, 0);
Junxiao Shiefceadc2014-03-09 18:52:57 -0700223 // {'/A':[1,2], '/B':[1]}
224 BOOST_CHECK_EQUAL(fib.size(), 2);
225
Alexander Afanasyevb3033242014-08-04 11:09:05 -0700226 insertRes = fib.insert("/C");
227 insertRes.first->addNextHop(face2, 1);
228 // {'/A':[1,2], '/B':[1], '/C':[2]}
229 BOOST_CHECK_EQUAL(fib.size(), 3);
230
231 insertRes = fib.insert("/B/1");
232 insertRes.first->addNextHop(face1, 0);
233 // {'/A':[1,2], '/B':[1], '/B/1':[1], '/C':[2]}
234 BOOST_CHECK_EQUAL(fib.size(), 4);
235
236 insertRes = fib.insert("/B/1/2");
237 insertRes.first->addNextHop(face1, 0);
238 // {'/A':[1,2], '/B':[1], '/B/1':[1], '/B/1/2':[1], '/C':[2]}
239 BOOST_CHECK_EQUAL(fib.size(), 5);
240
241 insertRes = fib.insert("/B/1/2/3");
242 insertRes.first->addNextHop(face1, 0);
243 // {'/A':[1,2], '/B':[1], '/B/1':[1], '/B/1/2':[1], '/B/1/3':[1], '/C':[2]}
244 BOOST_CHECK_EQUAL(fib.size(), 6);
245
246 insertRes = fib.insert("/B/1/2/3/4");
247 insertRes.first->addNextHop(face1, 0);
248 // {'/A':[1,2], '/B':[1], '/B/1':[1], '/B/1/2':[1], '/B/1/2/3':[1], '/B/1/2/3/4':[1], '/C':[2]}
249 BOOST_CHECK_EQUAL(fib.size(), 7);
250
251 /////////////
252
Junxiao Shic1e12362014-01-24 20:03:26 -0700253 fib.removeNextHopFromAllEntries(face1);
Alexander Afanasyevb3033242014-08-04 11:09:05 -0700254 // {'/A':[2], '/C':[2]}
255 BOOST_CHECK_EQUAL(fib.size(), 2);
Junxiao Shiefceadc2014-03-09 18:52:57 -0700256
Junxiao Shic1e12362014-01-24 20:03:26 -0700257 entry = fib.findLongestPrefixMatch(nameA);
Junxiao Shi40631842014-03-01 13:52:37 -0700258 BOOST_CHECK_EQUAL(entry->getPrefix(), nameA);
Junxiao Shic1e12362014-01-24 20:03:26 -0700259 const fib::NextHopList& nexthopsA = entry->getNextHops();
260 BOOST_CHECK_EQUAL(nexthopsA.size(), 1);
261 BOOST_CHECK_EQUAL(nexthopsA.begin()->getFace(), face2);
Junxiao Shiefceadc2014-03-09 18:52:57 -0700262
Junxiao Shic1e12362014-01-24 20:03:26 -0700263 entry = fib.findLongestPrefixMatch(nameB);
Junxiao Shiefceadc2014-03-09 18:52:57 -0700264 BOOST_CHECK_EQUAL(entry->getPrefix(), nameEmpty);
Junxiao Shic1e12362014-01-24 20:03:26 -0700265}
266
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700267void
268validateFindExactMatch(const Fib& fib, const Name& target)
269{
270 shared_ptr<fib::Entry> entry = fib.findExactMatch(target);
271 if (static_cast<bool>(entry))
272 {
273 BOOST_CHECK_EQUAL(entry->getPrefix(), target);
274 }
275 else
276 {
277 BOOST_FAIL("No entry found for " << target);
278 }
279}
280
281void
282validateNoExactMatch(const Fib& fib, const Name& target)
283{
284 shared_ptr<fib::Entry> entry = fib.findExactMatch(target);
285 if (static_cast<bool>(entry))
286 {
287 BOOST_FAIL("Found unexpected entry for " << target);
288 }
289}
290
291BOOST_AUTO_TEST_CASE(FindExactMatch)
292{
Haowei Yuanf52dac72014-03-24 23:35:03 -0500293 NameTree nameTree;
HangZhangad4afd12014-03-01 11:03:08 +0800294 Fib fib(nameTree);
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700295 fib.insert("/A");
296 fib.insert("/A/B");
297 fib.insert("/A/B/C");
298
299 validateFindExactMatch(fib, "/A");
300 validateFindExactMatch(fib, "/A/B");
301 validateFindExactMatch(fib, "/A/B/C");
Junxiao Shi40631842014-03-01 13:52:37 -0700302 validateNoExactMatch(fib, "/");
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700303
304 validateNoExactMatch(fib, "/does/not/exist");
305
Haowei Yuanf52dac72014-03-24 23:35:03 -0500306 NameTree gapNameTree;
HangZhangad4afd12014-03-01 11:03:08 +0800307 Fib gapFib(nameTree);
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700308 fib.insert("/X");
309 fib.insert("/X/Y/Z");
310
311 validateNoExactMatch(gapFib, "/X/Y");
312
Haowei Yuanf52dac72014-03-24 23:35:03 -0500313 NameTree emptyNameTree;
HangZhangad4afd12014-03-01 11:03:08 +0800314 Fib emptyFib(emptyNameTree);
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700315 validateNoExactMatch(emptyFib, "/nothing/here");
316}
317
318void
Junxiao Shiee5a4442014-07-27 17:13:43 -0700319validateErase(Fib& fib, const Name& target)
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700320{
HangZhangad4afd12014-03-01 11:03:08 +0800321 fib.erase(target);
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700322
323 shared_ptr<fib::Entry> entry = fib.findExactMatch(target);
324 if (static_cast<bool>(entry))
325 {
326 BOOST_FAIL("Found \"removed\" entry for " << target);
327 }
328}
329
Junxiao Shiee5a4442014-07-27 17:13:43 -0700330BOOST_AUTO_TEST_CASE(Erase)
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700331{
Haowei Yuanf52dac72014-03-24 23:35:03 -0500332 NameTree emptyNameTree;
HangZhangad4afd12014-03-01 11:03:08 +0800333 Fib emptyFib(emptyNameTree);
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700334
HangZhangad4afd12014-03-01 11:03:08 +0800335 emptyFib.erase("/does/not/exist"); // crash test
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700336
Junxiao Shiee5a4442014-07-27 17:13:43 -0700337 validateErase(emptyFib, "/");
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700338
HangZhangad4afd12014-03-01 11:03:08 +0800339 emptyFib.erase("/still/does/not/exist"); // crash test
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700340
Haowei Yuanf52dac72014-03-24 23:35:03 -0500341 NameTree nameTree;
HangZhangad4afd12014-03-01 11:03:08 +0800342 Fib fib(nameTree);
Junxiao Shi40631842014-03-01 13:52:37 -0700343 fib.insert("/");
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700344 fib.insert("/A");
345 fib.insert("/A/B");
346 fib.insert("/A/B/C");
347
348 // check if we remove the right thing and leave
349 // everything else alone
350
Junxiao Shiee5a4442014-07-27 17:13:43 -0700351 validateErase(fib, "/A/B");
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700352 validateFindExactMatch(fib, "/A");
353 validateFindExactMatch(fib, "/A/B/C");
354 validateFindExactMatch(fib, "/");
355
Junxiao Shiee5a4442014-07-27 17:13:43 -0700356 validateErase(fib, "/A/B/C");
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700357 validateFindExactMatch(fib, "/A");
358 validateFindExactMatch(fib, "/");
359
Junxiao Shiee5a4442014-07-27 17:13:43 -0700360 validateErase(fib, "/A");
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700361 validateFindExactMatch(fib, "/");
362
Junxiao Shiee5a4442014-07-27 17:13:43 -0700363 validateErase(fib, "/");
Junxiao Shi40631842014-03-01 13:52:37 -0700364 validateNoExactMatch(fib, "/");
365
Haowei Yuanf52dac72014-03-24 23:35:03 -0500366 NameTree gapNameTree;
HangZhangad4afd12014-03-01 11:03:08 +0800367 Fib gapFib(gapNameTree);
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700368 gapFib.insert("/X");
369 gapFib.insert("/X/Y/Z");
370
HangZhangad4afd12014-03-01 11:03:08 +0800371 gapFib.erase("/X/Y"); //should do nothing
Steve DiBenedettod5f87932014-02-05 15:11:39 -0700372 validateFindExactMatch(gapFib, "/X");
373 validateFindExactMatch(gapFib, "/X/Y/Z");
374}
375
Junxiao Shiee5a4442014-07-27 17:13:43 -0700376BOOST_AUTO_TEST_CASE(EraseNameTreeEntry)
377{
378 NameTree nameTree;
379 Fib fib(nameTree);
380 size_t nNameTreeEntriesBefore = nameTree.size();
381
382 fib.insert("ndn:/A/B/C");
383 fib.erase("ndn:/A/B/C");
384 BOOST_CHECK_EQUAL(nameTree.size(), nNameTreeEntriesBefore);
385}
386
HangZhang5d469422014-03-12 09:26:26 +0800387BOOST_AUTO_TEST_CASE(Iterator)
388{
Haowei Yuanf52dac72014-03-24 23:35:03 -0500389 NameTree nameTree;
HangZhang5d469422014-03-12 09:26:26 +0800390 Fib fib(nameTree);
391 Name nameA("/A");
392 Name nameAB("/A/B");
393 Name nameABC("/A/B/C");
394 Name nameRoot("/");
395
396 fib.insert(nameA);
397 fib.insert(nameAB);
398 fib.insert(nameABC);
399 fib.insert(nameRoot);
400
401 std::set<Name> expected;
402 expected.insert(nameA);
403 expected.insert(nameAB);
404 expected.insert(nameABC);
405 expected.insert(nameRoot);
406
407 for (Fib::const_iterator it = fib.begin(); it != fib.end(); it++)
408 {
409 bool isInSet = expected.find(it->getPrefix()) != expected.end();
410 BOOST_CHECK(isInSet);
411 expected.erase(it->getPrefix());
412 }
413
414 BOOST_CHECK_EQUAL(expected.size(), 0);
415}
416
Junxiao Shic1e12362014-01-24 20:03:26 -0700417BOOST_AUTO_TEST_SUITE_END()
418
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700419} // namespace tests
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800420} // namespace nfd