table: erase NameTree entry when FIB/Measurements/StrategyChoice entry is erased

This commit also optimizes Measurements table to make use of NameTree shortcuts.

refs #1803

Change-Id: Ib0e465750ed5e8ff9ed129a926a7bc852db4e9e1
This commit is contained in:
Junxiao Shi committed 2014-07-27 17:13:43 -07:00
1 parent 5dd26c3ef8
commit ee5a444344
15 files changed
+264 -188

No files matched your search

+2 -2
View File
@@ -166,7 +166,7 @@ NccStrategy::timeoutOnBestFace(weak_ptr<pit::Entry> pitEntryWeak)
// going out of this strategy's namespace
return;
}
this->getMeasurements().extendLifetime(*measurementsEntry, MEASUREMENTS_LIFETIME);
this->getMeasurements().extendLifetime(measurementsEntry, MEASUREMENTS_LIFETIME);
shared_ptr<MeasurementsEntryInfo> measurementsEntryInfo =
this->getMeasurementsEntryInfo(measurementsEntry);
@@ -187,7 +187,7 @@ NccStrategy::beforeSatisfyPendingInterest(shared_ptr<pit::Entry> pitEntry,
// going out of this strategy's namespace
return;
}
this->getMeasurements().extendLifetime(*measurementsEntry, MEASUREMENTS_LIFETIME);
this->getMeasurements().extendLifetime(measurementsEntry, MEASUREMENTS_LIFETIME);
shared_ptr<MeasurementsEntryInfo> measurementsEntryInfo =
this->getMeasurementsEntryInfo(measurementsEntry);
+21 -16
View File
@@ -1,11 +1,12 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014 Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
* Washington University in St. Louis,
* Beijing Institute of Technology
* Copyright (c) 2014, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
* Washington University in St. Louis,
* Beijing Institute of Technology,
* The University of Memphis
*
* This file is part of NFD (Named Data Networking Forwarding Daemon).
* See AUTHORS.md for complete list of NFD authors and contributors.
@@ -20,7 +21,7 @@
*
* You should have received a copy of the GNU General Public License along with
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
**/
*/
#include "fib.hpp"
#include "pit-entry.hpp"
@@ -113,25 +114,29 @@ Fib::findExactMatch(const Name& prefix) const
return shared_ptr<fib::Entry>();
}
void
Fib::erase(shared_ptr<name_tree::Entry> nameTreeEntry)
{
nameTreeEntry->setFibEntry(shared_ptr<fib::Entry>());
m_nameTree.eraseEntryIfEmpty(nameTreeEntry);
--m_nItems;
}
void
Fib::erase(const Name& prefix)
{
shared_ptr<name_tree::Entry> nameTreeEntry = m_nameTree.findExactMatch(prefix);
if (static_cast<bool>(nameTreeEntry))
{
nameTreeEntry->setFibEntry(shared_ptr<fib::Entry>());
--m_nItems;
if (static_cast<bool>(nameTreeEntry)) {
this->erase(nameTreeEntry);
}
}
void
Fib::erase(const fib::Entry& entry)
{
shared_ptr<name_tree::Entry> nameTreeEntry = m_nameTree.findExactMatch(entry);
if (static_cast<bool>(nameTreeEntry))
{
nameTreeEntry->setFibEntry(shared_ptr<fib::Entry>());
--m_nItems;
shared_ptr<name_tree::Entry> nameTreeEntry = m_nameTree.get(entry);
if (static_cast<bool>(nameTreeEntry)) {
this->erase(nameTreeEntry);
}
}
+11 -7
View File
@@ -1,11 +1,12 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014 Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
* Washington University in St. Louis,
* Beijing Institute of Technology
* Copyright (c) 2014, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
* Washington University in St. Louis,
* Beijing Institute of Technology,
* The University of Memphis
*
* This file is part of NFD (Named Data Networking Forwarding Daemon).
* See AUTHORS.md for complete list of NFD authors and contributors.
@@ -20,7 +21,7 @@
*
* You should have received a copy of the GNU General Public License along with
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
**/
*/
#ifndef NFD_DAEMON_TABLE_FIB_HPP
#define NFD_DAEMON_TABLE_FIB_HPP
@@ -128,6 +129,9 @@ private:
shared_ptr<fib::Entry>
findLongestPrefixMatch(shared_ptr<name_tree::Entry> nameTreeEntry) const;
void
erase(shared_ptr<name_tree::Entry> nameTreeEntry);
private:
NameTree& m_nameTree;
size_t m_nItems;
+8 -7
View File
@@ -1,11 +1,12 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014 Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
* Washington University in St. Louis,
* Beijing Institute of Technology
* Copyright (c) 2014, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
* Washington University in St. Louis,
* Beijing Institute of Technology,
* The University of Memphis
*
* This file is part of NFD (Named Data Networking Forwarding Daemon).
* See AUTHORS.md for complete list of NFD authors and contributors.
@@ -20,7 +21,7 @@
*
* You should have received a copy of the GNU General Public License along with
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
**/
*/
#include "measurements-accessor.hpp"
+11 -9
View File
@@ -1,11 +1,12 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014 Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
* Washington University in St. Louis,
* Beijing Institute of Technology
* Copyright (c) 2014, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
* Washington University in St. Louis,
* Beijing Institute of Technology,
* The University of Memphis
*
* This file is part of NFD (Named Data Networking Forwarding Daemon).
* See AUTHORS.md for complete list of NFD authors and contributors.
@@ -20,7 +21,7 @@
*
* You should have received a copy of the GNU General Public License along with
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
**/
*/
#ifndef NFD_DAEMON_TABLE_MEASUREMENTS_ACCESSOR_HPP
#define NFD_DAEMON_TABLE_MEASUREMENTS_ACCESSOR_HPP
@@ -68,7 +69,7 @@ public:
* The entry will be kept until at least now()+lifetime.
*/
void
extendLifetime(measurements::Entry& entry, const time::nanoseconds& lifetime);
extendLifetime(shared_ptr<measurements::Entry> entry, const time::nanoseconds& lifetime);
private:
/** \brief perform access control to Measurements entry
@@ -109,7 +110,8 @@ MeasurementsAccessor::getParent(shared_ptr<measurements::Entry> child)
}
inline void
MeasurementsAccessor::extendLifetime(measurements::Entry& entry, const time::nanoseconds& lifetime)
MeasurementsAccessor::extendLifetime(shared_ptr<measurements::Entry> entry,
const time::nanoseconds& lifetime)
{
m_measurements.extendLifetime(entry, lifetime);
}
+30 -17
View File
@@ -100,7 +100,15 @@ Measurements::getParent(shared_ptr<measurements::Entry> child)
return shared_ptr<measurements::Entry>();
}
return this->get(child->getName().getPrefix(-1));
shared_ptr<name_tree::Entry> nameTreeChild = m_nameTree.get(*child);
shared_ptr<name_tree::Entry> nameTreeEntry = nameTreeChild->getParent();
if (static_cast<bool>(nameTreeEntry)) {
return this->get(nameTreeEntry);
}
else {
BOOST_ASSERT(nameTreeChild->getPrefix().size() == 0); // root entry has no parent
return shared_ptr<measurements::Entry>();
}
}
shared_ptr<measurements::Entry>
@@ -124,33 +132,38 @@ Measurements::findExactMatch(const Name& name) const
}
void
Measurements::extendLifetime(measurements::Entry& entry, const time::nanoseconds& lifetime)
Measurements::extendLifetime(shared_ptr<measurements::Entry> entry,
const time::nanoseconds& lifetime)
{
shared_ptr<measurements::Entry> ret = this->findExactMatch(entry.getName());
if (static_cast<bool>(ret))
{
time::steady_clock::TimePoint expiry = time::steady_clock::now() + lifetime;
if (ret->m_expiry >= expiry) // has longer lifetime, not extending
return;
scheduler::cancel(entry.m_cleanup);
entry.m_expiry = expiry;
entry.m_cleanup = scheduler::schedule(lifetime,
bind(&Measurements::cleanup, this, ret));
shared_ptr<name_tree::Entry> nameTreeEntry = m_nameTree.get(*entry);
if (!static_cast<bool>(nameTreeEntry) ||
nameTreeEntry->getMeasurementsEntry().get() != entry.get()) {
// entry is already gone; it is a dangling reference
return;
}
time::steady_clock::TimePoint expiry = time::steady_clock::now() + lifetime;
if (entry->m_expiry >= expiry) {
// has longer lifetime, not extending
return;
}
scheduler::cancel(entry->m_cleanup);
entry->m_expiry = expiry;
entry->m_cleanup = scheduler::schedule(lifetime, bind(&Measurements::cleanup, this, entry));
}
void
Measurements::cleanup(shared_ptr<measurements::Entry> entry)
{
BOOST_ASSERT(entry);
BOOST_ASSERT(static_cast<bool>(entry));
shared_ptr<name_tree::Entry> nameTreeEntry = m_nameTree.findExactMatch(entry->getName());
if (static_cast<bool>(nameTreeEntry))
{
shared_ptr<name_tree::Entry> nameTreeEntry = m_nameTree.get(*entry);
if (static_cast<bool>(nameTreeEntry)) {
nameTreeEntry->setMeasurementsEntry(shared_ptr<measurements::Entry>());
m_nameTree.eraseEntryIfEmpty(nameTreeEntry);
m_nItems--;
}
}
} // namespace nfd
+1 -1
View File
@@ -86,7 +86,7 @@ public:
* The entry will be kept until at least now()+lifetime.
*/
void
extendLifetime(measurements::Entry& entry, const time::nanoseconds& lifetime);
extendLifetime(shared_ptr<measurements::Entry> entry, const time::nanoseconds& lifetime);
size_t
size() const;
+77 -10
View File
@@ -1,11 +1,12 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014 Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
* Washington University in St. Louis,
* Beijing Institute of Technology
* Copyright (c) 2014, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
* Washington University in St. Louis,
* Beijing Institute of Technology,
* The University of Memphis
*
* This file is part of NFD (Named Data Networking Forwarding Daemon).
* See AUTHORS.md for complete list of NFD authors and contributors.
@@ -20,9 +21,7 @@
*
* You should have received a copy of the GNU General Public License along with
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
**/
// Name Tree Entry (i.e., Name Prefix Entry)
*/
#include "name-tree-entry.hpp"
@@ -41,7 +40,7 @@ Node::~Node()
// resolve hash collisions
// So before erasing a single node, make sure its m_next == 0
// See eraseEntryIfEmpty in name-tree.cpp
if (m_next)
if (m_next != 0)
delete m_next;
}
@@ -55,6 +54,42 @@ Entry::~Entry()
{
}
bool
Entry::isEmpty() const
{
return m_children.empty() &&
!static_cast<bool>(m_fibEntry) &&
m_pitEntries.empty() &&
!static_cast<bool>(m_measurementsEntry) &&
!static_cast<bool>(m_strategyChoiceEntry);
}
void
Entry::setFibEntry(shared_ptr<fib::Entry> fibEntry)
{
if (static_cast<bool>(fibEntry)) {
BOOST_ASSERT(!static_cast<bool>(fibEntry->m_nameTreeEntry));
}
if (static_cast<bool>(m_fibEntry)) {
m_fibEntry->m_nameTreeEntry.reset();
}
m_fibEntry = fibEntry;
if (static_cast<bool>(m_fibEntry)) {
m_fibEntry->m_nameTreeEntry = this->shared_from_this();
}
}
void
Entry::insertPitEntry(shared_ptr<pit::Entry> pitEntry)
{
BOOST_ASSERT(static_cast<bool>(pitEntry));
BOOST_ASSERT(!static_cast<bool>(pitEntry->m_nameTreeEntry));
m_pitEntries.push_back(pitEntry);
pitEntry->m_nameTreeEntry = this->shared_from_this();
}
void
Entry::erasePitEntry(shared_ptr<pit::Entry> pitEntry)
{
@@ -70,5 +105,37 @@ Entry::erasePitEntry(shared_ptr<pit::Entry> pitEntry)
pitEntry->m_nameTreeEntry.reset();
}
void
Entry::setMeasurementsEntry(shared_ptr<measurements::Entry> measurementsEntry)
{
if (static_cast<bool>(measurementsEntry)) {
BOOST_ASSERT(!static_cast<bool>(measurementsEntry->m_nameTreeEntry));
}
if (static_cast<bool>(m_measurementsEntry)) {
m_measurementsEntry->m_nameTreeEntry.reset();
}
m_measurementsEntry = measurementsEntry;
if (static_cast<bool>(m_measurementsEntry)) {
m_measurementsEntry->m_nameTreeEntry = this->shared_from_this();
}
}
void
Entry::setStrategyChoiceEntry(shared_ptr<strategy_choice::Entry> strategyChoiceEntry)
{
if (static_cast<bool>(strategyChoiceEntry)) {
BOOST_ASSERT(!static_cast<bool>(strategyChoiceEntry->m_nameTreeEntry));
}
if (static_cast<bool>(m_strategyChoiceEntry)) {
m_strategyChoiceEntry->m_nameTreeEntry.reset();
}
m_strategyChoiceEntry = strategyChoiceEntry;
if (static_cast<bool>(m_strategyChoiceEntry)) {
m_strategyChoiceEntry->m_nameTreeEntry = this->shared_from_this();
}
}
} // namespace name_tree
} // namespace nfd
+9 -76
View File
@@ -1,11 +1,12 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014 Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
* Washington University in St. Louis,
* Beijing Institute of Technology
* Copyright (c) 2014, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
* Washington University in St. Louis,
* Beijing Institute of Technology,
* The University of Memphis
*
* This file is part of NFD (Named Data Networking Forwarding Daemon).
* See AUTHORS.md for complete list of NFD authors and contributors.
@@ -20,9 +21,7 @@
*
* You should have received a copy of the GNU General Public License along with
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
**/
// Name Tree Entry (i.e., Name Prefix Entry)
*/
#ifndef NFD_DAEMON_TABLE_NAME_TREE_ENTRY_HPP
#define NFD_DAEMON_TABLE_NAME_TREE_ENTRY_HPP
@@ -95,6 +94,7 @@ public:
bool
isEmpty() const;
public: // attached table entries
void
setFibEntry(shared_ptr<fib::Entry> fibEntry);
@@ -187,37 +187,12 @@ Entry::hasChildren() const
return !m_children.empty();
}
inline bool
Entry::isEmpty() const
{
return m_children.empty() &&
!static_cast<bool>(m_fibEntry) &&
m_pitEntries.empty() &&
!static_cast<bool>(m_measurementsEntry);
}
inline shared_ptr<fib::Entry>
Entry::getFibEntry() const
{
return m_fibEntry;
}
inline void
Entry::setFibEntry(shared_ptr<fib::Entry> fibEntry)
{
if (static_cast<bool>(fibEntry)) {
BOOST_ASSERT(!static_cast<bool>(fibEntry->m_nameTreeEntry));
}
if (static_cast<bool>(m_fibEntry)) {
m_fibEntry->m_nameTreeEntry.reset();
}
m_fibEntry = fibEntry;
if (static_cast<bool>(m_fibEntry)) {
m_fibEntry->m_nameTreeEntry = this->shared_from_this();
}
}
inline bool
Entry::hasPitEntries() const
{
@@ -230,60 +205,18 @@ Entry::getPitEntries() const
return m_pitEntries;
}
inline void
Entry::insertPitEntry(shared_ptr<pit::Entry> pitEntry)
{
BOOST_ASSERT(static_cast<bool>(pitEntry));
BOOST_ASSERT(!static_cast<bool>(pitEntry->m_nameTreeEntry));
m_pitEntries.push_back(pitEntry);
pitEntry->m_nameTreeEntry = this->shared_from_this();
}
inline shared_ptr<measurements::Entry>
Entry::getMeasurementsEntry() const
{
return m_measurementsEntry;
}
inline void
Entry::setMeasurementsEntry(shared_ptr<measurements::Entry> measurementsEntry)
{
if (static_cast<bool>(measurementsEntry)) {
BOOST_ASSERT(!static_cast<bool>(measurementsEntry->m_nameTreeEntry));
}
if (static_cast<bool>(m_measurementsEntry)) {
m_measurementsEntry->m_nameTreeEntry.reset();
}
m_measurementsEntry = measurementsEntry;
if (static_cast<bool>(m_measurementsEntry)) {
m_measurementsEntry->m_nameTreeEntry = this->shared_from_this();
}
}
inline shared_ptr<strategy_choice::Entry>
Entry::getStrategyChoiceEntry() const
{
return m_strategyChoiceEntry;
}
inline void
Entry::setStrategyChoiceEntry(shared_ptr<strategy_choice::Entry> strategyChoiceEntry)
{
if (static_cast<bool>(strategyChoiceEntry)) {
BOOST_ASSERT(!static_cast<bool>(strategyChoiceEntry->m_nameTreeEntry));
}
if (static_cast<bool>(m_strategyChoiceEntry)) {
m_strategyChoiceEntry->m_nameTreeEntry.reset();
}
m_strategyChoiceEntry = strategyChoiceEntry;
if (static_cast<bool>(m_strategyChoiceEntry)) {
m_strategyChoiceEntry->m_nameTreeEntry = this->shared_from_this();
}
}
} // namespace name_tree
} // namespace nfd
+13 -25
View File
@@ -1,11 +1,12 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014 Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
* Washington University in St. Louis,
* Beijing Institute of Technology
* Copyright (c) 2014, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
* Washington University in St. Louis,
* Beijing Institute of Technology,
* The University of Memphis
*
* This file is part of NFD (Named Data Networking Forwarding Daemon).
* See AUTHORS.md for complete list of NFD authors and contributors.
@@ -20,9 +21,7 @@
*
* You should have received a copy of the GNU General Public License along with
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
**/
// Name Tree (Name Prefix Hash Table)
*/
#ifndef NFD_DAEMON_TABLE_NAME_TREE_HPP
#define NFD_DAEMON_TABLE_NAME_TREE_HPP
@@ -121,17 +120,12 @@ public:
shared_ptr<name_tree::Entry>
findExactMatch(const Name& prefix) const;
shared_ptr<name_tree::Entry>
findExactMatch(const fib::Entry& fibEntry) const;
/**
* \brief Erase a Name Tree Entry if this entry is empty.
* \details If a Name Tree Entry contains no Children, no FIB, no PIT, and
* no Measurements entries, then it can be erased. In addition, its parent entry
* will also be examined by following the parent pointer until all empty entries
* are erased.
* \param entry The pointer to the entry to be erased. The entry pointer should
* returned by the findExactMatch(), lookup(), or findLongestPrefixMatch() functions.
* \brief Delete a Name Tree Entry if this entry is empty.
* \param entry The entry to be deleted if empty.
* \note This function must be called after a table entry is detached from Name Tree
* entry. The function deletes a Name Tree entry if nothing is attached to it and
* it has no children, then repeats the same process on its ancestors.
*/
bool
eraseEntryIfEmpty(shared_ptr<name_tree::Entry> entry);
@@ -296,12 +290,6 @@ NameTree::getNBuckets() const
return m_nBuckets;
}
inline shared_ptr<name_tree::Entry>
NameTree::findExactMatch(const fib::Entry& fibEntry) const
{
return fibEntry.m_nameTreeEntry;
}
inline shared_ptr<name_tree::Entry>
NameTree::get(const fib::Entry& fibEntry) const
{
+2 -1
View File
@@ -21,7 +21,7 @@
*
* You should have received a copy of the GNU General Public License along with
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
**/
*/
#include "strategy-choice.hpp"
#include "core/logger.hpp"
@@ -120,6 +120,7 @@ StrategyChoice::erase(const Name& prefix)
this->changeStrategy(entry, oldStrategy.shared_from_this(), parentStrategy.shared_from_this());
nameTreeEntry->setStrategyChoiceEntry(shared_ptr<Entry>());
m_nameTree.eraseEntryIfEmpty(nameTreeEntry);
--m_nItems;
}
+26 -14
View File
@@ -1,11 +1,12 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014 Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
* Washington University in St. Louis,
* Beijing Institute of Technology
* Copyright (c) 2014, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
* Washington University in St. Louis,
* Beijing Institute of Technology,
* The University of Memphis
*
* This file is part of NFD (Named Data Networking Forwarding Daemon).
* See AUTHORS.md for complete list of NFD authors and contributors.
@@ -20,7 +21,7 @@
*
* You should have received a copy of the GNU General Public License along with
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
**/
*/
#include "table/fib.hpp"
#include "tests/daemon/face/dummy-face.hpp"
@@ -288,7 +289,7 @@ BOOST_AUTO_TEST_CASE(FindExactMatch)
}
void
validateRemove(Fib& fib, const Name& target)
validateErase(Fib& fib, const Name& target)
{
fib.erase(target);
@@ -299,14 +300,14 @@ validateRemove(Fib& fib, const Name& target)
}
}
BOOST_AUTO_TEST_CASE(Remove)
BOOST_AUTO_TEST_CASE(Erase)
{
NameTree emptyNameTree;
Fib emptyFib(emptyNameTree);
emptyFib.erase("/does/not/exist"); // crash test
validateRemove(emptyFib, "/");
validateErase(emptyFib, "/");
emptyFib.erase("/still/does/not/exist"); // crash test
@@ -320,19 +321,19 @@ BOOST_AUTO_TEST_CASE(Remove)
// check if we remove the right thing and leave
// everything else alone
validateRemove(fib, "/A/B");
validateErase(fib, "/A/B");
validateFindExactMatch(fib, "/A");
validateFindExactMatch(fib, "/A/B/C");
validateFindExactMatch(fib, "/");
validateRemove(fib, "/A/B/C");
validateErase(fib, "/A/B/C");
validateFindExactMatch(fib, "/A");
validateFindExactMatch(fib, "/");
validateRemove(fib, "/A");
validateErase(fib, "/A");
validateFindExactMatch(fib, "/");
validateRemove(fib, "/");
validateErase(fib, "/");
validateNoExactMatch(fib, "/");
NameTree gapNameTree;
@@ -345,6 +346,17 @@ BOOST_AUTO_TEST_CASE(Remove)
validateFindExactMatch(gapFib, "/X/Y/Z");
}
BOOST_AUTO_TEST_CASE(EraseNameTreeEntry)
{
NameTree nameTree;
Fib fib(nameTree);
size_t nNameTreeEntriesBefore = nameTree.size();
fib.insert("ndn:/A/B/C");
fib.erase("ndn:/A/B/C");
BOOST_CHECK_EQUAL(nameTree.size(), nNameTreeEntriesBefore);
}
BOOST_AUTO_TEST_CASE(Iterator)
{
NameTree nameTree;
+18 -2
View File
@@ -84,8 +84,8 @@ BOOST_AUTO_TEST_CASE(Lifetime)
CHECK2 < EXTEND_C &&
EXTEND_C < CHECK3);
measurements.extendLifetime(*entryA, EXTEND_A);
measurements.extendLifetime(*entryC, EXTEND_C);
measurements.extendLifetime(entryA, EXTEND_A);
measurements.extendLifetime(entryC, EXTEND_C);
// remaining lifetime:
// A = initial lifetime, because it's extended by less duration
// B = initial lifetime
@@ -115,6 +115,22 @@ BOOST_AUTO_TEST_CASE(Lifetime)
BOOST_CHECK_EQUAL(measurements.size(), 0);
}
BOOST_AUTO_TEST_CASE(EraseNameTreeEntry)
{
LimitedIo limitedIo;
NameTree nameTree;
Measurements measurements(nameTree);
size_t nNameTreeEntriesBefore = nameTree.size();
shared_ptr<measurements::Entry> entry = measurements.get("/A");
BOOST_CHECK_EQUAL(
limitedIo.run(LimitedIo::UNLIMITED_OPS,
Measurements::getInitialLifetime() + time::milliseconds(10)),
LimitedIo::EXCEED_TIME);
BOOST_CHECK_EQUAL(measurements.size(), 0);
BOOST_CHECK_EQUAL(nameTree.size(), nNameTreeEntriesBefore);
}
BOOST_AUTO_TEST_SUITE_END()
} // namespace tests
+12
View File
@@ -352,6 +352,18 @@ BOOST_AUTO_TEST_CASE(Erase)
}
BOOST_AUTO_TEST_CASE(EraseNameTreeEntry)
{
NameTree nameTree;
Pit pit(nameTree);
size_t nNameTreeEntriesBefore = nameTree.size();
shared_ptr<Interest> interest = makeInterest("/37xWVvQ2K");
shared_ptr<pit::Entry> entry = pit.insert(*interest).first;
pit.erase(entry);
BOOST_CHECK_EQUAL(nameTree.size(), nNameTreeEntriesBefore);
}
BOOST_AUTO_TEST_CASE(FindAllDataMatches)
{
Name nameA ("ndn:/A");
+23 -1
View File
@@ -21,7 +21,7 @@
*
* You should have received a copy of the GNU General Public License along with
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
**/
*/
#include "table/strategy-choice.hpp"
#include "tests/daemon/fw/dummy-strategy.hpp"
@@ -188,6 +188,28 @@ BOOST_AUTO_TEST_CASE(ClearStrategyInfo)
BOOST_CHECK(!static_cast<bool>(measurements.get("ndn:/A/C")->getStrategyInfo<PStrategyInfo>()));
}
BOOST_AUTO_TEST_CASE(EraseNameTreeEntry)
{
Forwarder forwarder;
NameTree& nameTree = forwarder.getNameTree();
StrategyChoice& table = forwarder.getStrategyChoice();
Name nameP("ndn:/strategy/P");
Name nameQ("ndn:/strategy/Q");
shared_ptr<Strategy> strategyP = make_shared<DummyStrategy>(ref(forwarder), nameP);
shared_ptr<Strategy> strategyQ = make_shared<DummyStrategy>(ref(forwarder), nameQ);
table.install(strategyP);
table.install(strategyQ);
table.insert("ndn:/", nameP);
size_t nNameTreeEntriesBefore = nameTree.size();
table.insert("ndn:/A/B", nameQ);
table.erase("ndn:/A/B");
BOOST_CHECK_EQUAL(nameTree.size(), nNameTreeEntriesBefore);
}
BOOST_AUTO_TEST_SUITE_END()
} // namespace tests