blob: ce19f94e913e14e8c6d5d514d7b3c2224ec5fd5f [file] [log] [blame]
Minsheng Zhang03152692015-07-28 11:53:21 -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 Zhang03152692015-07-28 11:53:21 -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 Zhang03152692015-07-28 11:53:21 -050026#include "table/cs-policy-lru.hpp"
Minsheng Zhang03152692015-07-28 11:53:21 -050027
Junxiao Shi9222f362019-04-16 15:15:23 +000028#include "tests/daemon/table/cs-fixture.hpp"
Minsheng Zhang03152692015-07-28 11:53:21 -050029
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040030namespace nfd::tests {
Minsheng Zhang03152692015-07-28 11:53:21 -050031
Davide Pesavento97210d52016-10-14 15:45:48 +020032BOOST_AUTO_TEST_SUITE(Table)
33BOOST_AUTO_TEST_SUITE(TestCsLru)
Minsheng Zhang03152692015-07-28 11:53:21 -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("lru"), 1);
39}
40
Junxiao Shi9222f362019-04-16 15:15:23 +000041BOOST_FIXTURE_TEST_CASE(EvictOne, CsFixture)
Minsheng Zhang03152692015-07-28 11:53:21 -050042{
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040043 cs.setPolicy(make_unique<cs::LruPolicy>());
Junxiao Shi9222f362019-04-16 15:15:23 +000044 cs.setLimit(3);
Minsheng Zhang03152692015-07-28 11:53:21 -050045
Junxiao Shi9222f362019-04-16 15:15:23 +000046 insert(1, "/A");
47 insert(2, "/B");
48 insert(3, "/C");
Minsheng Zhang03152692015-07-28 11:53:21 -050049 BOOST_CHECK_EQUAL(cs.size(), 3);
50
51 // evict A
Junxiao Shi9222f362019-04-16 15:15:23 +000052 insert(4, "/D");
Minsheng Zhang03152692015-07-28 11:53:21 -050053 BOOST_CHECK_EQUAL(cs.size(), 3);
Junxiao Shi9222f362019-04-16 15:15:23 +000054 startInterest("/A");
55 CHECK_CS_FIND(0);
Minsheng Zhang03152692015-07-28 11:53:21 -050056
57 // use C then B
Junxiao Shi9222f362019-04-16 15:15:23 +000058 startInterest("/C");
59 CHECK_CS_FIND(3);
60 startInterest("/B");
61 CHECK_CS_FIND(2);
Minsheng Zhang03152692015-07-28 11:53:21 -050062
63 // evict D then C
Junxiao Shi9222f362019-04-16 15:15:23 +000064 insert(5, "/E");
Minsheng Zhang03152692015-07-28 11:53:21 -050065 BOOST_CHECK_EQUAL(cs.size(), 3);
Junxiao Shi9222f362019-04-16 15:15:23 +000066 startInterest("/D");
67 CHECK_CS_FIND(0);
68 insert(6, "/F");
Minsheng Zhang03152692015-07-28 11:53:21 -050069 BOOST_CHECK_EQUAL(cs.size(), 3);
Junxiao Shi9222f362019-04-16 15:15:23 +000070 startInterest("/C");
71 CHECK_CS_FIND(0);
Minsheng Zhang03152692015-07-28 11:53:21 -050072
73 // refresh B
Junxiao Shi9222f362019-04-16 15:15:23 +000074 insert(12, "/B");
Minsheng Zhang03152692015-07-28 11:53:21 -050075 // evict E
Junxiao Shi9222f362019-04-16 15:15:23 +000076 insert(7, "/G");
Minsheng Zhang03152692015-07-28 11:53:21 -050077 BOOST_CHECK_EQUAL(cs.size(), 3);
Junxiao Shi9222f362019-04-16 15:15:23 +000078 startInterest("/E");
79 CHECK_CS_FIND(0);
Minsheng Zhang03152692015-07-28 11:53:21 -050080}
81
Davide Pesavento97210d52016-10-14 15:45:48 +020082BOOST_AUTO_TEST_SUITE_END() // TestCsLru
83BOOST_AUTO_TEST_SUITE_END() // Table
Minsheng Zhang03152692015-07-28 11:53:21 -050084
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040085} // namespace nfd::tests