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