table: allow setting CS capacity limit to zero
refs #3503
Change-Id: I6e1bfb64ea3a1f31070a7290c250fbcec46623fb
diff --git a/daemon/table/cs-policy.cpp b/daemon/table/cs-policy.cpp
index 9726269..3d22c1e 100644
--- a/daemon/table/cs-policy.cpp
+++ b/daemon/table/cs-policy.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, Regents of the University of California,
+ * Copyright (c) 2014-2016, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -41,9 +41,7 @@
void
Policy::setLimit(size_t nMaxEntries)
{
- BOOST_ASSERT(nMaxEntries > 0);
m_limit = nMaxEntries;
-
this->evictEntries();
}
diff --git a/daemon/table/cs.cpp b/daemon/table/cs.cpp
index 4550361..19df21a 100644
--- a/daemon/table/cs.cpp
+++ b/daemon/table/cs.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, Regents of the University of California,
+ * Copyright (c) 2014-2016, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -78,17 +78,22 @@
m_policy->setLimit(limit);
}
-bool
+void
Cs::insert(const Data& data, bool isUnsolicited)
{
NFD_LOG_DEBUG("insert " << data.getName());
+ if (m_policy->getLimit() == 0) {
+ // shortcut for disabled CS
+ return;
+ }
+
// recognize CachePolicy
shared_ptr<lp::CachePolicyTag> tag = data.getTag<lp::CachePolicyTag>();
if (tag != nullptr) {
lp::CachePolicyType policy = tag->get().getPolicy();
if (policy == lp::CachePolicyType::NO_CACHE) {
- return false;
+ return;
}
}
@@ -111,8 +116,6 @@
else {
m_policy->afterInsert(it);
}
-
- return true;
}
void
diff --git a/daemon/table/cs.hpp b/daemon/table/cs.hpp
index 5a24bde..3a9b1ca 100644
--- a/daemon/table/cs.hpp
+++ b/daemon/table/cs.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, Regents of the University of California,
+ * Copyright (c) 2014-2016, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -69,9 +69,8 @@
Cs(size_t nMaxPackets = 10, unique_ptr<Policy> policy = makeDefaultPolicy());
/** \brief inserts a Data packet
- * \return true
*/
- bool
+ void
insert(const Data& data, bool isUnsolicited = false);
typedef std::function<void(const Interest&, const Data& data)> HitCallback;
diff --git a/tests/daemon/fw/forwarder.t.cpp b/tests/daemon/fw/forwarder.t.cpp
index 8337491..906e2ca 100644
--- a/tests/daemon/fw/forwarder.t.cpp
+++ b/tests/daemon/fw/forwarder.t.cpp
@@ -108,7 +108,7 @@
BOOST_CHECK_EQUAL(pit.size(), 0);
Cs& cs = forwarder.getCs();
- BOOST_REQUIRE(cs.insert(*dataA));
+ cs.insert(*dataA);
face1->receiveInterest(*interestA);
limitedIo.run(LimitedIo::UNLIMITED_OPS, time::milliseconds(5));
diff --git a/tests/daemon/table/cs.t.cpp b/tests/daemon/table/cs.t.cpp
index 63caa44..a4c5d74 100644
--- a/tests/daemon/table/cs.t.cpp
+++ b/tests/daemon/table/cs.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, Regents of the University of California,
+ * Copyright (c) 2014-2016, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -36,7 +36,8 @@
using namespace nfd::tests;
-BOOST_FIXTURE_TEST_SUITE(TableCs, BaseFixture)
+BOOST_AUTO_TEST_SUITE(Table)
+BOOST_FIXTURE_TEST_SUITE(TestCs, BaseFixture)
class FindFixture : protected BaseFixture
{
@@ -313,7 +314,28 @@
CHECK_CS_FIND(1);
}
-BOOST_AUTO_TEST_SUITE_END()
+/// \todo test MustBeFresh
+
+BOOST_AUTO_TEST_SUITE_END() // Find
+
+// When the capacity limit is set to zero, Data cannot be inserted;
+// this test case covers this situation.
+// The behavior of non-zero capacity limit depends on the eviction policy,
+// and is tested in policy test suites.
+BOOST_FIXTURE_TEST_CASE(ZeroCapacity, FindFixture)
+{
+ m_cs.setLimit(0);
+
+ BOOST_CHECK_EQUAL(m_cs.getLimit(), 0);
+ BOOST_CHECK_EQUAL(m_cs.size(), 0);
+ BOOST_CHECK(m_cs.begin() == m_cs.end());
+
+ insert(1, "ndn:/A");
+ BOOST_CHECK_EQUAL(m_cs.size(), 0);
+
+ startInterest("ndn:/A");
+ CHECK_CS_FIND(0);
+}
BOOST_AUTO_TEST_CASE(CachePolicyNoCache)
{
@@ -321,12 +343,11 @@
shared_ptr<Data> dataA = makeData("ndn:/A");
dataA->wireEncode();
-
dataA->setTag(make_shared<lp::CachePolicyTag>(
lp::CachePolicy().setPolicy(lp::CachePolicyType::NO_CACHE)));
+ cs.insert(*dataA);
- BOOST_CHECK_EQUAL(cs.insert(*dataA), false);
-
+ BOOST_CHECK_EQUAL(cs.size(), 0);
cs.find(Interest("ndn:/A"),
bind([] { BOOST_CHECK(false); }),
bind([] { BOOST_CHECK(true); }));
@@ -368,7 +389,8 @@
BOOST_CHECK_EQUAL_COLLECTIONS(actual.begin(), actual.end(), expected.begin(), expected.end());
}
-BOOST_AUTO_TEST_SUITE_END()
+BOOST_AUTO_TEST_SUITE_END() // TestCs
+BOOST_AUTO_TEST_SUITE_END() // Table
} // namespace tests
} // namespace cs