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" |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 27 | |
Junxiao Shi | 9222f36 | 2019-04-16 15:15:23 +0000 | [diff] [blame] | 28 | #include "tests/daemon/table/cs-fixture.hpp" |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 29 | |
| 30 | namespace nfd { |
| 31 | namespace cs { |
| 32 | namespace tests { |
| 33 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 34 | BOOST_AUTO_TEST_SUITE(Table) |
| 35 | BOOST_AUTO_TEST_SUITE(TestCsPriorityFifo) |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 36 | |
Junxiao Shi | 7ee00fb | 2016-12-04 21:23:00 +0000 | [diff] [blame] | 37 | BOOST_AUTO_TEST_CASE(Registration) |
| 38 | { |
| 39 | std::set<std::string> policyNames = Policy::getPolicyNames(); |
| 40 | BOOST_CHECK_EQUAL(policyNames.count("priority_fifo"), 1); |
| 41 | } |
| 42 | |
Junxiao Shi | 9222f36 | 2019-04-16 15:15:23 +0000 | [diff] [blame] | 43 | BOOST_FIXTURE_TEST_CASE(EvictOne, CsFixture) |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 44 | { |
Davide Pesavento | 01f8dba | 2015-09-19 21:11:45 +0200 | [diff] [blame] | 45 | cs.setPolicy(make_unique<PriorityFifoPolicy>()); |
Junxiao Shi | 9222f36 | 2019-04-16 15:15:23 +0000 | [diff] [blame] | 46 | cs.setLimit(3); |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 47 | |
Junxiao Shi | 9222f36 | 2019-04-16 15:15:23 +0000 | [diff] [blame] | 48 | insert(1, "/A", [] (Data& data) { data.setFreshnessPeriod(99999_ms); }); |
| 49 | insert(2, "/B", [] (Data& data) { data.setFreshnessPeriod(10_ms); }); |
| 50 | insert(3, "/C", [] (Data& data) { data.setFreshnessPeriod(99999_ms); }, true); |
| 51 | advanceClocks(11_ms); |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 52 | |
Junxiao Shi | 9222f36 | 2019-04-16 15:15:23 +0000 | [diff] [blame] | 53 | // evict /C (unsolicited) |
| 54 | insert(4, "/D", [] (Data& data) { data.setFreshnessPeriod(99999_ms); }); |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 55 | BOOST_CHECK_EQUAL(cs.size(), 3); |
Junxiao Shi | 9222f36 | 2019-04-16 15:15:23 +0000 | [diff] [blame] | 56 | startInterest("/C"); |
| 57 | CHECK_CS_FIND(0); |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 58 | |
Junxiao Shi | 9222f36 | 2019-04-16 15:15:23 +0000 | [diff] [blame] | 59 | // evict /B (stale) |
| 60 | insert(5, "/E", [] (Data& data) { data.setFreshnessPeriod(99999_ms); }); |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 61 | BOOST_CHECK_EQUAL(cs.size(), 3); |
Junxiao Shi | 9222f36 | 2019-04-16 15:15:23 +0000 | [diff] [blame] | 62 | startInterest("/B"); |
| 63 | CHECK_CS_FIND(0); |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 64 | |
Junxiao Shi | 9222f36 | 2019-04-16 15:15:23 +0000 | [diff] [blame] | 65 | // evict /F (fresh) |
| 66 | insert(6, "/F", [] (Data& data) { data.setFreshnessPeriod(99999_ms); }); |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 67 | BOOST_CHECK_EQUAL(cs.size(), 3); |
Junxiao Shi | 9222f36 | 2019-04-16 15:15:23 +0000 | [diff] [blame] | 68 | startInterest("/A"); |
| 69 | CHECK_CS_FIND(0); |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 70 | } |
| 71 | |
Junxiao Shi | 9222f36 | 2019-04-16 15:15:23 +0000 | [diff] [blame] | 72 | BOOST_FIXTURE_TEST_CASE(Refresh, CsFixture) |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 73 | { |
Davide Pesavento | 01f8dba | 2015-09-19 21:11:45 +0200 | [diff] [blame] | 74 | cs.setPolicy(make_unique<PriorityFifoPolicy>()); |
Junxiao Shi | 9222f36 | 2019-04-16 15:15:23 +0000 | [diff] [blame] | 75 | cs.setLimit(3); |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 76 | |
Junxiao Shi | 9222f36 | 2019-04-16 15:15:23 +0000 | [diff] [blame] | 77 | insert(1, "/A", [] (Data& data) { data.setFreshnessPeriod(99999_ms); }); |
| 78 | insert(2, "/B", [] (Data& data) { data.setFreshnessPeriod(10_ms); }); |
| 79 | insert(3, "/C", [] (Data& data) { data.setFreshnessPeriod(10_ms); }); |
| 80 | advanceClocks(11_ms); |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 81 | |
Junxiao Shi | 9222f36 | 2019-04-16 15:15:23 +0000 | [diff] [blame] | 82 | // refresh /B |
| 83 | insert(12, "/B", [] (Data& data) { data.setFreshnessPeriod(0_ms); }); |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 84 | BOOST_CHECK_EQUAL(cs.size(), 3); |
Junxiao Shi | 9222f36 | 2019-04-16 15:15:23 +0000 | [diff] [blame] | 85 | startInterest("/A"); |
| 86 | CHECK_CS_FIND(1); |
| 87 | startInterest("/B"); |
| 88 | CHECK_CS_FIND(12); |
| 89 | startInterest("/C"); |
| 90 | CHECK_CS_FIND(3); |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 91 | |
Junxiao Shi | 9222f36 | 2019-04-16 15:15:23 +0000 | [diff] [blame] | 92 | // evict /C from stale queue |
| 93 | insert(4, "/D", [] (Data& data) { data.setFreshnessPeriod(99999_ms); }); |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 94 | BOOST_CHECK_EQUAL(cs.size(), 3); |
Junxiao Shi | 9222f36 | 2019-04-16 15:15:23 +0000 | [diff] [blame] | 95 | startInterest("/C"); |
| 96 | CHECK_CS_FIND(0); |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 97 | } |
| 98 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 99 | BOOST_AUTO_TEST_SUITE_END() // TestCsPriorityFifo |
| 100 | BOOST_AUTO_TEST_SUITE_END() // Table |
Minsheng Zhang | cb6e05f | 2015-04-20 15:51:47 -0500 | [diff] [blame] | 101 | |
| 102 | } // namespace tests |
| 103 | } // namespace cs |
| 104 | } // namespace nfd |