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