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