blob: a1c88d0deeba12ec28d423c1fe07fea2161d7c13 [file] [log] [blame]
Minsheng Zhangcb6e05f2015-04-20 15:51:47 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shibb6146e2017-07-26 23:07:52 +00002/*
Davide Pesaventoe422f9e2022-06-03 01:30:23 -04003 * Copyright (c) 2014-2022, Regents of the University of California,
Minsheng Zhangcb6e05f2015-04-20 15:51:47 -05004 * 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 Zhangcb6e05f2015-04-20 15:51:47 -050026#include "table/cs-policy-priority-fifo.hpp"
Minsheng Zhangcb6e05f2015-04-20 15:51:47 -050027
Junxiao Shi9222f362019-04-16 15:15:23 +000028#include "tests/daemon/table/cs-fixture.hpp"
Minsheng Zhangcb6e05f2015-04-20 15:51:47 -050029
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040030namespace nfd::tests {
Minsheng Zhangcb6e05f2015-04-20 15:51:47 -050031
Davide Pesavento97210d52016-10-14 15:45:48 +020032BOOST_AUTO_TEST_SUITE(Table)
33BOOST_AUTO_TEST_SUITE(TestCsPriorityFifo)
Minsheng Zhangcb6e05f2015-04-20 15:51:47 -050034
Junxiao Shi7ee00fb2016-12-04 21:23:00 +000035BOOST_AUTO_TEST_CASE(Registration)
36{
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040037 std::set<std::string> policyNames = cs::Policy::getPolicyNames();
Junxiao Shi7ee00fb2016-12-04 21:23:00 +000038 BOOST_CHECK_EQUAL(policyNames.count("priority_fifo"), 1);
39}
40
Junxiao Shi9222f362019-04-16 15:15:23 +000041BOOST_FIXTURE_TEST_CASE(EvictOne, CsFixture)
Minsheng Zhangcb6e05f2015-04-20 15:51:47 -050042{
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040043 cs.setPolicy(make_unique<cs::PriorityFifoPolicy>());
Junxiao Shi9222f362019-04-16 15:15:23 +000044 cs.setLimit(3);
Minsheng Zhangcb6e05f2015-04-20 15:51:47 -050045
Junxiao Shi9222f362019-04-16 15:15:23 +000046 insert(1, "/A", [] (Data& data) { data.setFreshnessPeriod(99999_ms); });
47 insert(2, "/B", [] (Data& data) { data.setFreshnessPeriod(10_ms); });
48 insert(3, "/C", [] (Data& data) { data.setFreshnessPeriod(99999_ms); }, true);
49 advanceClocks(11_ms);
Minsheng Zhangcb6e05f2015-04-20 15:51:47 -050050
Junxiao Shi9222f362019-04-16 15:15:23 +000051 // evict /C (unsolicited)
52 insert(4, "/D", [] (Data& data) { data.setFreshnessPeriod(99999_ms); });
Minsheng Zhangcb6e05f2015-04-20 15:51:47 -050053 BOOST_CHECK_EQUAL(cs.size(), 3);
Junxiao Shi9222f362019-04-16 15:15:23 +000054 startInterest("/C");
55 CHECK_CS_FIND(0);
Minsheng Zhangcb6e05f2015-04-20 15:51:47 -050056
Junxiao Shi9222f362019-04-16 15:15:23 +000057 // evict /B (stale)
58 insert(5, "/E", [] (Data& data) { data.setFreshnessPeriod(99999_ms); });
Minsheng Zhangcb6e05f2015-04-20 15:51:47 -050059 BOOST_CHECK_EQUAL(cs.size(), 3);
Junxiao Shi9222f362019-04-16 15:15:23 +000060 startInterest("/B");
61 CHECK_CS_FIND(0);
Minsheng Zhangcb6e05f2015-04-20 15:51:47 -050062
Junxiao Shi9222f362019-04-16 15:15:23 +000063 // evict /F (fresh)
64 insert(6, "/F", [] (Data& data) { data.setFreshnessPeriod(99999_ms); });
Minsheng Zhangcb6e05f2015-04-20 15:51:47 -050065 BOOST_CHECK_EQUAL(cs.size(), 3);
Junxiao Shi9222f362019-04-16 15:15:23 +000066 startInterest("/A");
67 CHECK_CS_FIND(0);
Minsheng Zhangcb6e05f2015-04-20 15:51:47 -050068}
69
Junxiao Shi9222f362019-04-16 15:15:23 +000070BOOST_FIXTURE_TEST_CASE(Refresh, CsFixture)
Minsheng Zhangcb6e05f2015-04-20 15:51:47 -050071{
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040072 cs.setPolicy(make_unique<cs::PriorityFifoPolicy>());
Junxiao Shi9222f362019-04-16 15:15:23 +000073 cs.setLimit(3);
Minsheng Zhangcb6e05f2015-04-20 15:51:47 -050074
Junxiao Shi9222f362019-04-16 15:15:23 +000075 insert(1, "/A", [] (Data& data) { data.setFreshnessPeriod(99999_ms); });
76 insert(2, "/B", [] (Data& data) { data.setFreshnessPeriod(10_ms); });
77 insert(3, "/C", [] (Data& data) { data.setFreshnessPeriod(10_ms); });
78 advanceClocks(11_ms);
Minsheng Zhangcb6e05f2015-04-20 15:51:47 -050079
Junxiao Shi9222f362019-04-16 15:15:23 +000080 // refresh /B
81 insert(12, "/B", [] (Data& data) { data.setFreshnessPeriod(0_ms); });
Minsheng Zhangcb6e05f2015-04-20 15:51:47 -050082 BOOST_CHECK_EQUAL(cs.size(), 3);
Junxiao Shi9222f362019-04-16 15:15:23 +000083 startInterest("/A");
84 CHECK_CS_FIND(1);
85 startInterest("/B");
86 CHECK_CS_FIND(12);
87 startInterest("/C");
88 CHECK_CS_FIND(3);
Minsheng Zhangcb6e05f2015-04-20 15:51:47 -050089
Junxiao Shi9222f362019-04-16 15:15:23 +000090 // evict /C from stale queue
91 insert(4, "/D", [] (Data& data) { data.setFreshnessPeriod(99999_ms); });
Minsheng Zhangcb6e05f2015-04-20 15:51:47 -050092 BOOST_CHECK_EQUAL(cs.size(), 3);
Junxiao Shi9222f362019-04-16 15:15:23 +000093 startInterest("/C");
94 CHECK_CS_FIND(0);
Minsheng Zhangcb6e05f2015-04-20 15:51:47 -050095}
96
Davide Pesavento97210d52016-10-14 15:45:48 +020097BOOST_AUTO_TEST_SUITE_END() // TestCsPriorityFifo
98BOOST_AUTO_TEST_SUITE_END() // Table
Minsheng Zhangcb6e05f2015-04-20 15:51:47 -050099
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400100} // namespace nfd::tests