blob: b68729a75b29ae18bd391fa17a87a4ccb7bb5e76 [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/*
3 * Copyright (c) 2014-2017, 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"
Junxiao Shi0de23a22015-12-03 20:07:02 +000027#include "table/cs.hpp"
Minsheng Zhangcb6e05f2015-04-20 15:51:47 -050028
29#include "tests/test-common.hpp"
30
31namespace nfd {
32namespace cs {
33namespace tests {
34
35using namespace nfd::tests;
Minsheng Zhangcb6e05f2015-04-20 15:51:47 -050036
Davide Pesavento97210d52016-10-14 15:45:48 +020037BOOST_AUTO_TEST_SUITE(Table)
38BOOST_AUTO_TEST_SUITE(TestCsPriorityFifo)
Minsheng Zhangcb6e05f2015-04-20 15:51:47 -050039
Junxiao Shi7ee00fb2016-12-04 21:23:00 +000040BOOST_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 Zhangcb6e05f2015-04-20 15:51:47 -050046BOOST_FIXTURE_TEST_CASE(EvictOne, UnitTestTimeFixture)
47{
48 Cs cs(3);
Davide Pesavento01f8dba2015-09-19 21:11:45 +020049 cs.setPolicy(make_unique<PriorityFifoPolicy>());
Minsheng Zhangcb6e05f2015-04-20 15:51:47 -050050
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
99BOOST_FIXTURE_TEST_CASE(Refresh, UnitTestTimeFixture)
100{
101 Cs cs(3);
Davide Pesavento01f8dba2015-09-19 21:11:45 +0200102 cs.setPolicy(make_unique<PriorityFifoPolicy>());
Minsheng Zhangcb6e05f2015-04-20 15:51:47 -0500103
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 Pesavento97210d52016-10-14 15:45:48 +0200149BOOST_AUTO_TEST_SUITE_END() // TestCsPriorityFifo
150BOOST_AUTO_TEST_SUITE_END() // Table
Minsheng Zhangcb6e05f2015-04-20 15:51:47 -0500151
152} // namespace tests
153} // namespace cs
154} // namespace nfd