Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | bb6146e | 2017-07-26 23:07:52 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2019, Regents of the University of California, |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 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. |
| 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/>. |
| 24 | */ |
| 25 | |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 26 | #include "table/cs-policy-priority-fifo.hpp" |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 27 | #include "table/cs.hpp" |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 28 | |
| 29 | #include "tests/test-common.hpp" |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 30 | #include "tests/daemon/global-io-fixture.hpp" |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 31 | |
| 32 | namespace nfd { |
| 33 | namespace cs { |
| 34 | namespace tests { |
| 35 | |
| 36 | using namespace nfd::tests; |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 37 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 38 | BOOST_AUTO_TEST_SUITE(Table) |
| 39 | BOOST_AUTO_TEST_SUITE(TestCsPriorityFifo) |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 40 | |
Junxiao Shi | 7ee00fb | 2016-12-04 21:23:00 +0000 | [diff] [blame] | 41 | BOOST_AUTO_TEST_CASE(Registration) |
| 42 | { |
| 43 | std::set<std::string> policyNames = Policy::getPolicyNames(); |
| 44 | BOOST_CHECK_EQUAL(policyNames.count("priority_fifo"), 1); |
| 45 | } |
| 46 | |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 47 | BOOST_FIXTURE_TEST_CASE(EvictOne, GlobalIoTimeFixture) |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 48 | { |
| 49 | Cs cs(3); |
Davide Pesavento | 01f8dba | 2015-09-19 21:11:45 +0200 | [diff] [blame] | 50 | cs.setPolicy(make_unique<PriorityFifoPolicy>()); |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 51 | |
| 52 | shared_ptr<Data> dataA = makeData("ndn:/A"); |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 53 | dataA->setFreshnessPeriod(99999_ms); |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 54 | dataA->wireEncode(); |
| 55 | cs.insert(*dataA); |
| 56 | |
| 57 | shared_ptr<Data> dataB = makeData("ndn:/B"); |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 58 | dataB->setFreshnessPeriod(10_ms); |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 59 | dataB->wireEncode(); |
| 60 | cs.insert(*dataB); |
| 61 | |
| 62 | shared_ptr<Data> dataC = makeData("ndn:/C"); |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 63 | dataC->setFreshnessPeriod(99999_ms); |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 64 | dataC->wireEncode(); |
| 65 | cs.insert(*dataC, true); |
| 66 | |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 67 | this->advanceClocks(11_ms); |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 68 | |
| 69 | // evict unsolicited |
| 70 | shared_ptr<Data> dataD = makeData("ndn:/D"); |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 71 | dataD->setFreshnessPeriod(99999_ms); |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 72 | dataD->wireEncode(); |
| 73 | cs.insert(*dataD); |
| 74 | BOOST_CHECK_EQUAL(cs.size(), 3); |
| 75 | cs.find(Interest("ndn:/C"), |
| 76 | bind([] { BOOST_CHECK(false); }), |
| 77 | bind([] { BOOST_CHECK(true); })); |
| 78 | |
| 79 | // evict stale |
| 80 | shared_ptr<Data> dataE = makeData("ndn:/E"); |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 81 | dataE->setFreshnessPeriod(99999_ms); |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 82 | dataE->wireEncode(); |
| 83 | cs.insert(*dataE); |
| 84 | BOOST_CHECK_EQUAL(cs.size(), 3); |
| 85 | cs.find(Interest("ndn:/B"), |
| 86 | bind([] { BOOST_CHECK(false); }), |
| 87 | bind([] { BOOST_CHECK(true); })); |
| 88 | |
| 89 | // evict fifo |
| 90 | shared_ptr<Data> dataF = makeData("ndn:/F"); |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 91 | dataF->setFreshnessPeriod(99999_ms); |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 92 | dataF->wireEncode(); |
| 93 | cs.insert(*dataF); |
| 94 | BOOST_CHECK_EQUAL(cs.size(), 3); |
| 95 | cs.find(Interest("ndn:/A"), |
| 96 | bind([] { BOOST_CHECK(false); }), |
| 97 | bind([] { BOOST_CHECK(true); })); |
| 98 | } |
| 99 | |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 100 | BOOST_FIXTURE_TEST_CASE(Refresh, GlobalIoTimeFixture) |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 101 | { |
| 102 | Cs cs(3); |
Davide Pesavento | 01f8dba | 2015-09-19 21:11:45 +0200 | [diff] [blame] | 103 | cs.setPolicy(make_unique<PriorityFifoPolicy>()); |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 104 | |
| 105 | shared_ptr<Data> dataA = makeData("ndn:/A"); |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 106 | dataA->setFreshnessPeriod(99999_ms); |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 107 | dataA->wireEncode(); |
| 108 | cs.insert(*dataA); |
| 109 | |
| 110 | shared_ptr<Data> dataB = makeData("ndn:/B"); |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 111 | dataB->setFreshnessPeriod(10_ms); |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 112 | dataB->wireEncode(); |
| 113 | cs.insert(*dataB); |
| 114 | |
| 115 | shared_ptr<Data> dataC = makeData("ndn:/C"); |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 116 | dataC->setFreshnessPeriod(10_ms); |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 117 | dataC->wireEncode(); |
| 118 | cs.insert(*dataC); |
| 119 | |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 120 | this->advanceClocks(11_ms); |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 121 | |
| 122 | // refresh dataB |
| 123 | shared_ptr<Data> dataB2 = make_shared<Data>(*dataB); |
| 124 | dataB2->wireEncode(); |
| 125 | cs.insert(*dataB2); |
| 126 | BOOST_CHECK_EQUAL(cs.size(), 3); |
| 127 | cs.find(Interest("ndn:/A"), |
| 128 | bind([] { BOOST_CHECK(true); }), |
| 129 | bind([] { BOOST_CHECK(false); })); |
| 130 | |
| 131 | cs.find(Interest("ndn:/B"), |
| 132 | bind([] { BOOST_CHECK(true); }), |
| 133 | bind([] { BOOST_CHECK(false); })); |
| 134 | |
| 135 | cs.find(Interest("ndn:/C"), |
| 136 | bind([] { BOOST_CHECK(true); }), |
| 137 | bind([] { BOOST_CHECK(false); })); |
| 138 | |
| 139 | // evict dataC stale |
| 140 | shared_ptr<Data> dataD = makeData("ndn:/D"); |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 141 | dataD->setFreshnessPeriod(99999_ms); |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 142 | dataD->wireEncode(); |
| 143 | cs.insert(*dataD); |
| 144 | BOOST_CHECK_EQUAL(cs.size(), 3); |
| 145 | cs.find(Interest("ndn:/C"), |
| 146 | bind([] { BOOST_CHECK(false); }), |
| 147 | bind([] { BOOST_CHECK(true); })); |
| 148 | } |
| 149 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 150 | BOOST_AUTO_TEST_SUITE_END() // TestCsPriorityFifo |
| 151 | BOOST_AUTO_TEST_SUITE_END() // Table |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 152 | |
| 153 | } // namespace tests |
| 154 | } // namespace cs |
| 155 | } // namespace nfd |