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