Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 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 | * |
| 10 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 11 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 12 | * |
| 13 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 14 | * of the GNU General Public License as published by the Free Software Foundation, |
| 15 | * either version 3 of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 18 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 19 | * PURPOSE. See the GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License along with |
| 22 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 23 | **/ |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 24 | |
| 25 | #include "table/pit.hpp" |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 26 | #include "tests/daemon/face/dummy-face.hpp" |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 27 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 28 | #include "tests/test-common.hpp" |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 29 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 30 | namespace nfd { |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 31 | namespace tests { |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 32 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 33 | BOOST_FIXTURE_TEST_SUITE(TablePit, BaseFixture) |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 34 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 35 | BOOST_AUTO_TEST_CASE(EntryInOutRecords) |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 36 | { |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 37 | shared_ptr<Face> face1 = make_shared<DummyFace>(); |
| 38 | shared_ptr<Face> face2 = make_shared<DummyFace>(); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 39 | Name name("ndn:/KuYfjtRq"); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 40 | shared_ptr<Interest> interest = makeInterest(name); |
| 41 | shared_ptr<Interest> interest1 = makeInterest(name); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 42 | interest1->setInterestLifetime(time::milliseconds(2528)); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 43 | interest1->setNonce(25559); |
| 44 | shared_ptr<Interest> interest2 = makeInterest(name); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 45 | interest2->setInterestLifetime(time::milliseconds(6464)); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 46 | interest2->setNonce(19004); |
| 47 | shared_ptr<Interest> interest3 = makeInterest(name); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 48 | interest3->setInterestLifetime(time::milliseconds(3585)); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 49 | interest3->setNonce(24216); |
| 50 | shared_ptr<Interest> interest4 = makeInterest(name); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 51 | interest4->setInterestLifetime(time::milliseconds(8795)); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 52 | interest4->setNonce(17365); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 53 | |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 54 | pit::Entry entry(*interest); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 55 | |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 56 | BOOST_CHECK_EQUAL(entry.getInterest().getName(), name); |
| 57 | BOOST_CHECK_EQUAL(entry.getName(), name); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 58 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 59 | const pit::InRecordCollection& inRecords1 = entry.getInRecords(); |
| 60 | BOOST_CHECK_EQUAL(inRecords1.size(), 0); |
| 61 | const pit::OutRecordCollection& outRecords1 = entry.getOutRecords(); |
| 62 | BOOST_CHECK_EQUAL(outRecords1.size(), 0); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 63 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 64 | // insert InRecord |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 65 | time::steady_clock::TimePoint before1 = time::steady_clock::now(); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 66 | pit::InRecordCollection::iterator in1 = |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 67 | entry.insertOrUpdateInRecord(face1, *interest1); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 68 | time::steady_clock::TimePoint after1 = time::steady_clock::now(); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 69 | const pit::InRecordCollection& inRecords2 = entry.getInRecords(); |
| 70 | BOOST_CHECK_EQUAL(inRecords2.size(), 1); |
| 71 | BOOST_CHECK(in1 == inRecords2.begin()); |
| 72 | BOOST_CHECK_EQUAL(in1->getFace(), face1); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 73 | BOOST_CHECK_EQUAL(in1->getLastNonce(), interest1->getNonce()); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 74 | BOOST_CHECK_GE(in1->getLastRenewed(), before1); |
| 75 | BOOST_CHECK_LE(in1->getLastRenewed(), after1); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 76 | BOOST_CHECK_LE(in1->getExpiry() - in1->getLastRenewed() |
| 77 | - interest1->getInterestLifetime(), |
| 78 | (after1 - before1)); |
Junxiao Shi | 66f91f8 | 2014-05-10 17:28:58 -0700 | [diff] [blame^] | 79 | BOOST_CHECK(in1 == entry.getInRecord(face1)); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 80 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 81 | // insert OutRecord |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 82 | time::steady_clock::TimePoint before2 = time::steady_clock::now(); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 83 | pit::OutRecordCollection::iterator out1 = |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 84 | entry.insertOrUpdateOutRecord(face1, *interest1); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 85 | time::steady_clock::TimePoint after2 = time::steady_clock::now(); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 86 | const pit::OutRecordCollection& outRecords2 = entry.getOutRecords(); |
| 87 | BOOST_CHECK_EQUAL(outRecords2.size(), 1); |
| 88 | BOOST_CHECK(out1 == outRecords2.begin()); |
| 89 | BOOST_CHECK_EQUAL(out1->getFace(), face1); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 90 | BOOST_CHECK_EQUAL(out1->getLastNonce(), interest1->getNonce()); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 91 | BOOST_CHECK_GE(out1->getLastRenewed(), before2); |
| 92 | BOOST_CHECK_LE(out1->getLastRenewed(), after2); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 93 | BOOST_CHECK_LE(out1->getExpiry() - out1->getLastRenewed() |
| 94 | - interest1->getInterestLifetime(), |
| 95 | (after2 - before2)); |
Junxiao Shi | 66f91f8 | 2014-05-10 17:28:58 -0700 | [diff] [blame^] | 96 | BOOST_CHECK(out1 == entry.getOutRecord(face1)); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 97 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 98 | // update InRecord |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 99 | time::steady_clock::TimePoint before3 = time::steady_clock::now(); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 100 | pit::InRecordCollection::iterator in2 = |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 101 | entry.insertOrUpdateInRecord(face1, *interest2); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 102 | time::steady_clock::TimePoint after3 = time::steady_clock::now(); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 103 | const pit::InRecordCollection& inRecords3 = entry.getInRecords(); |
| 104 | BOOST_CHECK_EQUAL(inRecords3.size(), 1); |
| 105 | BOOST_CHECK(in2 == inRecords3.begin()); |
| 106 | BOOST_CHECK_EQUAL(in2->getFace(), face1); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 107 | BOOST_CHECK_EQUAL(in2->getLastNonce(), interest2->getNonce()); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 108 | BOOST_CHECK_LE(in2->getExpiry() - in2->getLastRenewed() |
| 109 | - interest2->getInterestLifetime(), |
| 110 | (after3 - before3)); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 111 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 112 | // insert another InRecord |
| 113 | pit::InRecordCollection::iterator in3 = |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 114 | entry.insertOrUpdateInRecord(face2, *interest3); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 115 | const pit::InRecordCollection& inRecords4 = entry.getInRecords(); |
| 116 | BOOST_CHECK_EQUAL(inRecords4.size(), 2); |
| 117 | BOOST_CHECK_EQUAL(in3->getFace(), face2); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 118 | |
Junxiao Shi | 66f91f8 | 2014-05-10 17:28:58 -0700 | [diff] [blame^] | 119 | // get InRecord |
| 120 | pit::InRecordCollection::const_iterator in4 = entry.getInRecord(face1); |
| 121 | BOOST_REQUIRE(in4 != entry.getInRecords().end()); |
| 122 | BOOST_CHECK_EQUAL(in4->getFace(), face1); |
| 123 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 124 | // delete all InRecords |
| 125 | entry.deleteInRecords(); |
| 126 | const pit::InRecordCollection& inRecords5 = entry.getInRecords(); |
| 127 | BOOST_CHECK_EQUAL(inRecords5.size(), 0); |
Junxiao Shi | 66f91f8 | 2014-05-10 17:28:58 -0700 | [diff] [blame^] | 128 | BOOST_CHECK(entry.getInRecord(face1) == entry.getInRecords().end()); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 129 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 130 | // insert another OutRecord |
| 131 | pit::OutRecordCollection::iterator out2 = |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 132 | entry.insertOrUpdateOutRecord(face2, *interest4); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 133 | const pit::OutRecordCollection& outRecords3 = entry.getOutRecords(); |
| 134 | BOOST_CHECK_EQUAL(outRecords3.size(), 2); |
| 135 | BOOST_CHECK_EQUAL(out2->getFace(), face2); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 136 | |
Junxiao Shi | 66f91f8 | 2014-05-10 17:28:58 -0700 | [diff] [blame^] | 137 | // get OutRecord |
| 138 | pit::OutRecordCollection::const_iterator out3 = entry.getOutRecord(face1); |
| 139 | BOOST_REQUIRE(out3 != entry.getOutRecords().end()); |
| 140 | BOOST_CHECK_EQUAL(out3->getFace(), face1); |
| 141 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 142 | // delete OutRecord |
| 143 | entry.deleteOutRecord(face2); |
| 144 | const pit::OutRecordCollection& outRecords4 = entry.getOutRecords(); |
| 145 | BOOST_REQUIRE_EQUAL(outRecords4.size(), 1); |
| 146 | BOOST_CHECK_EQUAL(outRecords4.begin()->getFace(), face1); |
Junxiao Shi | 66f91f8 | 2014-05-10 17:28:58 -0700 | [diff] [blame^] | 147 | BOOST_CHECK(entry.getOutRecord(face2) == entry.getOutRecords().end()); |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | BOOST_AUTO_TEST_CASE(EntryNonce) |
| 151 | { |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 152 | shared_ptr<Interest> interest = makeInterest("ndn:/qtCQ7I1c"); |
| 153 | |
| 154 | pit::Entry entry(*interest); |
| 155 | |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 156 | BOOST_CHECK_EQUAL(entry.addNonce(25559), true); |
| 157 | BOOST_CHECK_EQUAL(entry.addNonce(25559), false); |
| 158 | BOOST_CHECK_EQUAL(entry.addNonce(19004), true); |
| 159 | BOOST_CHECK_EQUAL(entry.addNonce(19004), false); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 162 | BOOST_AUTO_TEST_CASE(EntryLifetime) |
| 163 | { |
| 164 | shared_ptr<Interest> interest = makeInterest("ndn:/7oIEurbgy6"); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 165 | BOOST_ASSERT(interest->getInterestLifetime() < time::milliseconds::zero()); // library uses -1 to indicate unset lifetime |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 166 | |
| 167 | shared_ptr<Face> face = make_shared<DummyFace>(); |
| 168 | pit::Entry entry(*interest); |
| 169 | |
| 170 | pit::InRecordCollection::iterator inIt = entry.insertOrUpdateInRecord(face, *interest); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 171 | BOOST_CHECK_GT(inIt->getExpiry(), time::steady_clock::now()); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 172 | |
| 173 | pit::OutRecordCollection::iterator outIt = entry.insertOrUpdateOutRecord(face, *interest); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 174 | BOOST_CHECK_GT(outIt->getExpiry(), time::steady_clock::now()); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | BOOST_AUTO_TEST_CASE(EntryCanForwardTo) |
| 178 | { |
| 179 | shared_ptr<Interest> interest = makeInterest("ndn:/WDsuBLIMG"); |
| 180 | pit::Entry entry(*interest); |
| 181 | |
| 182 | shared_ptr<Face> face1 = make_shared<DummyFace>(); |
| 183 | shared_ptr<Face> face2 = make_shared<DummyFace>(); |
| 184 | |
| 185 | entry.insertOrUpdateInRecord(face1, *interest); |
| 186 | BOOST_CHECK_EQUAL(entry.canForwardTo(*face1), false); |
| 187 | BOOST_CHECK_EQUAL(entry.canForwardTo(*face2), true); |
| 188 | |
| 189 | entry.insertOrUpdateInRecord(face2, *interest); |
| 190 | BOOST_CHECK_EQUAL(entry.canForwardTo(*face1), true); |
| 191 | BOOST_CHECK_EQUAL(entry.canForwardTo(*face2), true); |
| 192 | |
| 193 | entry.insertOrUpdateOutRecord(face1, *interest); |
| 194 | BOOST_CHECK_EQUAL(entry.canForwardTo(*face1), false); |
| 195 | BOOST_CHECK_EQUAL(entry.canForwardTo(*face2), true); |
| 196 | } |
| 197 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 198 | BOOST_AUTO_TEST_CASE(Insert) |
| 199 | { |
| 200 | Name name1("ndn:/5vzBNnMst"); |
| 201 | Name name2("ndn:/igSGfEIM62"); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 202 | Exclude exclude1; |
| 203 | exclude1.excludeOne(Name::Component("u26p47oep")); |
| 204 | Exclude exclude2; |
Junxiao Shi | 30d3599 | 2014-04-03 14:51:58 -0700 | [diff] [blame] | 205 | exclude2.excludeBefore(Name::Component("u26p47oep")); |
| 206 | ndn::KeyLocator keyLocator1("ndn:/sGAE3peMHA"); |
| 207 | ndn::KeyLocator keyLocator2("ndn:/nIJH6pr4"); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 208 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 209 | NameTree nameTree(16); |
| 210 | Pit pit(nameTree); |
Junxiao Shi | 30d3599 | 2014-04-03 14:51:58 -0700 | [diff] [blame] | 211 | BOOST_CHECK_EQUAL(pit.size(), 0); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 212 | std::pair<shared_ptr<pit::Entry>, bool> insertResult; |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 213 | |
Junxiao Shi | 30d3599 | 2014-04-03 14:51:58 -0700 | [diff] [blame] | 214 | // base |
| 215 | shared_ptr<Interest> interestA = make_shared<Interest>(name1); |
| 216 | insertResult = pit.insert(*interestA); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 217 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 218 | BOOST_CHECK_EQUAL(pit.size(), 1); |
| 219 | |
Junxiao Shi | 30d3599 | 2014-04-03 14:51:58 -0700 | [diff] [blame] | 220 | // A+MinSuffixComponents |
| 221 | shared_ptr<Interest> interestB = make_shared<Interest>(*interestA); |
| 222 | interestB->setMinSuffixComponents(2); |
| 223 | insertResult = pit.insert(*interestB); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 224 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 225 | BOOST_CHECK_EQUAL(pit.size(), 2); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 226 | |
Junxiao Shi | 30d3599 | 2014-04-03 14:51:58 -0700 | [diff] [blame] | 227 | // A+MaxSuffixComponents |
| 228 | shared_ptr<Interest> interestC = make_shared<Interest>(*interestA); |
| 229 | interestC->setMaxSuffixComponents(4); |
| 230 | insertResult = pit.insert(*interestC); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 231 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 232 | BOOST_CHECK_EQUAL(pit.size(), 3); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 233 | |
Junxiao Shi | 30d3599 | 2014-04-03 14:51:58 -0700 | [diff] [blame] | 234 | // A+KeyLocator1 |
| 235 | shared_ptr<Interest> interestD = make_shared<Interest>(*interestA); |
| 236 | interestD->setPublisherPublicKeyLocator(keyLocator1); |
| 237 | insertResult = pit.insert(*interestD); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 238 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 239 | BOOST_CHECK_EQUAL(pit.size(), 4); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 240 | |
Junxiao Shi | 30d3599 | 2014-04-03 14:51:58 -0700 | [diff] [blame] | 241 | // A+KeyLocator2 |
| 242 | shared_ptr<Interest> interestE = make_shared<Interest>(*interestA); |
| 243 | interestE->setPublisherPublicKeyLocator(keyLocator2); |
| 244 | insertResult = pit.insert(*interestE); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 245 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 246 | BOOST_CHECK_EQUAL(pit.size(), 5); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 247 | |
Junxiao Shi | 30d3599 | 2014-04-03 14:51:58 -0700 | [diff] [blame] | 248 | // A+Exclude1 |
| 249 | shared_ptr<Interest> interestF = make_shared<Interest>(*interestA); |
| 250 | interestF->setExclude(exclude1); |
| 251 | insertResult = pit.insert(*interestF); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 252 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 253 | BOOST_CHECK_EQUAL(pit.size(), 6); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 254 | |
Junxiao Shi | 30d3599 | 2014-04-03 14:51:58 -0700 | [diff] [blame] | 255 | // A+Exclude2 |
| 256 | shared_ptr<Interest> interestG = make_shared<Interest>(*interestA); |
| 257 | interestG->setExclude(exclude2); |
| 258 | insertResult = pit.insert(*interestG); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 259 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 260 | BOOST_CHECK_EQUAL(pit.size(), 7); |
| 261 | |
Junxiao Shi | 30d3599 | 2014-04-03 14:51:58 -0700 | [diff] [blame] | 262 | // A+ChildSelector0 |
| 263 | shared_ptr<Interest> interestH = make_shared<Interest>(*interestA); |
| 264 | interestH->setChildSelector(0); |
| 265 | insertResult = pit.insert(*interestH); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 266 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 267 | BOOST_CHECK_EQUAL(pit.size(), 8); |
Junxiao Shi | 30d3599 | 2014-04-03 14:51:58 -0700 | [diff] [blame] | 268 | |
| 269 | // A+ChildSelector1 |
| 270 | shared_ptr<Interest> interestI = make_shared<Interest>(*interestA); |
| 271 | interestI->setChildSelector(1); |
| 272 | insertResult = pit.insert(*interestI); |
| 273 | BOOST_CHECK_EQUAL(insertResult.second, true); |
| 274 | BOOST_CHECK_EQUAL(pit.size(), 9); |
| 275 | |
| 276 | // A+MustBeFresh |
| 277 | shared_ptr<Interest> interestJ = make_shared<Interest>(*interestA); |
| 278 | interestJ->setMustBeFresh(true); |
| 279 | insertResult = pit.insert(*interestJ); |
| 280 | BOOST_CHECK_EQUAL(insertResult.second, true); |
| 281 | BOOST_CHECK_EQUAL(pit.size(), 10); |
| 282 | |
| 283 | // A+InterestLifetime |
| 284 | shared_ptr<Interest> interestK = make_shared<Interest>(*interestA); |
| 285 | interestK->setInterestLifetime(time::milliseconds(1000)); |
| 286 | insertResult = pit.insert(*interestK); |
| 287 | BOOST_CHECK_EQUAL(insertResult.second, false);// only guiders differ |
| 288 | BOOST_CHECK_EQUAL(pit.size(), 10); |
| 289 | |
| 290 | // A+Nonce |
| 291 | shared_ptr<Interest> interestL = make_shared<Interest>(*interestA); |
| 292 | interestL->setNonce(2192); |
| 293 | insertResult = pit.insert(*interestL); |
| 294 | BOOST_CHECK_EQUAL(insertResult.second, false);// only guiders differ |
| 295 | BOOST_CHECK_EQUAL(pit.size(), 10); |
| 296 | |
| 297 | // different Name+Exclude1 |
| 298 | shared_ptr<Interest> interestM = make_shared<Interest>(name2); |
| 299 | interestM->setExclude(exclude1); |
| 300 | insertResult = pit.insert(*interestM); |
| 301 | BOOST_CHECK_EQUAL(insertResult.second, true); |
| 302 | BOOST_CHECK_EQUAL(pit.size(), 11); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 303 | } |
| 304 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 305 | BOOST_AUTO_TEST_CASE(Erase) |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 306 | { |
| 307 | Interest interest(Name("ndn:/z88Admz6A2")); |
| 308 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 309 | NameTree nameTree(16); |
| 310 | Pit pit(nameTree); |
| 311 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 312 | std::pair<shared_ptr<pit::Entry>, bool> insertResult; |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 313 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 314 | BOOST_CHECK_EQUAL(pit.size(), 0); |
| 315 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 316 | insertResult = pit.insert(interest); |
| 317 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 318 | BOOST_CHECK_EQUAL(pit.size(), 1); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 319 | |
| 320 | insertResult = pit.insert(interest); |
| 321 | BOOST_CHECK_EQUAL(insertResult.second, false); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 322 | BOOST_CHECK_EQUAL(pit.size(), 1); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 323 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 324 | pit.erase(insertResult.first); |
| 325 | BOOST_CHECK_EQUAL(pit.size(), 0); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 326 | |
| 327 | insertResult = pit.insert(interest); |
| 328 | BOOST_CHECK_EQUAL(insertResult.second, true); |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 329 | BOOST_CHECK_EQUAL(pit.size(), 1); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 330 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 331 | } |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 332 | |
| 333 | BOOST_AUTO_TEST_CASE(FindAllDataMatches) |
| 334 | { |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 335 | Name nameA ("ndn:/A"); |
| 336 | Name nameAB ("ndn:/A/B"); |
| 337 | Name nameABC ("ndn:/A/B/C"); |
| 338 | Name nameABCD("ndn:/A/B/C/D"); |
| 339 | Name nameD ("ndn:/D"); |
| 340 | |
| 341 | Interest interestA (nameA ); |
| 342 | Interest interestABC(nameABC); |
| 343 | Interest interestD (nameD ); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 344 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 345 | NameTree nameTree(16); |
| 346 | Pit pit(nameTree); |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 347 | int count = 0; |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 348 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 349 | BOOST_CHECK_EQUAL(pit.size(), 0); |
| 350 | |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 351 | pit.insert(interestA ); |
| 352 | pit.insert(interestABC); |
| 353 | pit.insert(interestD ); |
| 354 | |
| 355 | nameTree.lookup(nameABCD); // make sure /A/B/C/D is in nameTree |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 356 | |
Haowei Yuan | 78c84d1 | 2014-02-27 15:35:13 -0600 | [diff] [blame] | 357 | BOOST_CHECK_EQUAL(pit.size(), 3); |
| 358 | |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 359 | Data data(nameABCD); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 360 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 361 | shared_ptr<pit::DataMatchResult> matches = pit.findAllDataMatches(data); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 362 | |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 363 | bool hasA = false; |
| 364 | bool hasAB = false; |
| 365 | bool hasABC = false; |
| 366 | bool hasD = false; |
| 367 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 368 | for (pit::DataMatchResult::iterator it = matches->begin(); |
| 369 | it != matches->end(); ++it) { |
| 370 | ++count; |
| 371 | shared_ptr<pit::Entry> entry = *it; |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 372 | |
| 373 | if (entry->getName().equals(nameA )) |
| 374 | hasA = true; |
| 375 | |
| 376 | if (entry->getName().equals(nameAB)) |
| 377 | hasAB = true; |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 378 | |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 379 | if (entry->getName().equals(nameABC)) |
| 380 | hasABC = true; |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 381 | |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 382 | if (entry->getName().equals(nameD)) |
| 383 | hasD = true; |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 384 | } |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 385 | BOOST_CHECK_EQUAL(hasA , true); |
| 386 | BOOST_CHECK_EQUAL(hasAB , false); |
| 387 | BOOST_CHECK_EQUAL(hasABC, true); |
| 388 | BOOST_CHECK_EQUAL(hasD , false); |
| 389 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 390 | BOOST_CHECK_EQUAL(count, 2); |
Haowei Yuan | e1079fc | 2014-03-08 14:41:25 -0600 | [diff] [blame] | 391 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | BOOST_AUTO_TEST_SUITE_END() |
| 395 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 396 | } // namespace tests |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 397 | } // namespace nfd |