table: Measurements::findLongestPrefixMatch(pit::Entry)
refs #2314
Change-Id: Iebe80240760b22b573da1e6d23b43273ff3efbeb
diff --git a/daemon/table/measurements.cpp b/daemon/table/measurements.cpp
index f9b9bd3..03042ba 100644
--- a/daemon/table/measurements.cpp
+++ b/daemon/table/measurements.cpp
@@ -1,12 +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,
- * The University of Memphis
+ * Copyright (c) 2014-2015, Regents of the University of California,
+ * Arizona Board of Regents,
+ * Colorado State University,
+ * University Pierre & Marie Curie, Sorbonne Universit
+ * 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.
@@ -90,22 +90,38 @@
return this->get(*nte);
}
+template<typename K>
shared_ptr<Entry>
-Measurements::findLongestPrefixMatch(const Name& name,
- const measurements::EntryPredicate& pred) const
+Measurements::findLongestPrefixMatchImpl(const K& key,
+ const measurements::EntryPredicate& pred) const
{
- shared_ptr<name_tree::Entry> nte = m_nameTree.findLongestPrefixMatch(name,
+ shared_ptr<name_tree::Entry> match = m_nameTree.findLongestPrefixMatch(key,
[pred] (const name_tree::Entry& nte) -> bool {
shared_ptr<Entry> entry = nte.getMeasurementsEntry();
return entry != nullptr && pred(*entry);
});
- if (nte != nullptr) {
- return nte->getMeasurementsEntry();
+ if (match != nullptr) {
+ return match->getMeasurementsEntry();
}
return nullptr;
}
shared_ptr<Entry>
+Measurements::findLongestPrefixMatch(const Name& name,
+ const measurements::EntryPredicate& pred) const
+{
+ return this->findLongestPrefixMatchImpl(name, pred);
+}
+
+shared_ptr<Entry>
+Measurements::findLongestPrefixMatch(const pit::Entry& pitEntry,
+ const measurements::EntryPredicate& pred) const
+{
+ shared_ptr<name_tree::Entry> nte = m_nameTree.get(pitEntry);
+ return this->findLongestPrefixMatchImpl(nte, pred);
+}
+
+shared_ptr<Entry>
Measurements::findExactMatch(const Name& name) const
{
shared_ptr<name_tree::Entry> nte = m_nameTree.lookup(name);
diff --git a/daemon/table/measurements.hpp b/daemon/table/measurements.hpp
index 4d19f34..068c488 100644
--- a/daemon/table/measurements.hpp
+++ b/daemon/table/measurements.hpp
@@ -1,12 +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,
- * The University of Memphis
+ * Copyright (c) 2014-2015, Regents of the University of California,
+ * Arizona Board of Regents,
+ * Colorado State University,
+ * University Pierre & Marie Curie, Sorbonne Universit
+ * 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.
@@ -78,17 +78,17 @@
explicit
Measurements(NameTree& nametree);
- /** \brief find or insert a Measurements entry for name
+ /** \brief find or insert a Measurements entry for \p name
*/
shared_ptr<measurements::Entry>
get(const Name& name);
- /** \brief find or insert a Measurements entry for fibEntry->getPrefix()
+ /** \brief find or insert a Measurements entry for \p fibEntry.getPrefix()
*/
shared_ptr<measurements::Entry>
get(const fib::Entry& fibEntry);
- /** \brief find or insert a Measurements entry for pitEntry->getName()
+ /** \brief find or insert a Measurements entry for \p pitEntry.getName()
*/
shared_ptr<measurements::Entry>
get(const pit::Entry& pitEntry);
@@ -99,13 +99,20 @@
shared_ptr<measurements::Entry>
getParent(const measurements::Entry& child);
- /** \brief perform a longest prefix match
+ /** \brief perform a longest prefix match for \p name
*/
shared_ptr<measurements::Entry>
findLongestPrefixMatch(const Name& name,
const measurements::EntryPredicate& pred =
measurements::AnyEntry()) const;
+ /** \brief perform a longest prefix match for \p pitEntry.getName()
+ */
+ shared_ptr<measurements::Entry>
+ findLongestPrefixMatch(const pit::Entry& pitEntry,
+ const measurements::EntryPredicate& pred =
+ measurements::AnyEntry()) const;
+
/** \brief perform an exact match
*/
shared_ptr<measurements::Entry>
@@ -131,6 +138,12 @@
shared_ptr<measurements::Entry>
get(name_tree::Entry& nte);
+ /** \tparam K Name or shared_ptr<name_tree::Entry>
+ */
+ template<typename K>
+ shared_ptr<measurements::Entry>
+ findLongestPrefixMatchImpl(const K& key, const measurements::EntryPredicate& pred) const;
+
private:
NameTree& m_nameTree;
size_t m_nItems;
diff --git a/tests/daemon/table/measurements.cpp b/tests/daemon/table/measurements.cpp
index 4cf7f81..7083a42 100644
--- a/tests/daemon/table/measurements.cpp
+++ b/tests/daemon/table/measurements.cpp
@@ -1,12 +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,
- * The University of Memphis
+ * Copyright (c) 2014-2015, Regents of the University of California,
+ * Arizona Board of Regents,
+ * Colorado State University,
+ * University Pierre & Marie Curie, Sorbonne Universit
+ * 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.
@@ -24,9 +24,9 @@
*/
#include "table/measurements.hpp"
+#include "table/pit.hpp"
#include "tests/test-common.hpp"
-#include "tests/limited-io.hpp"
namespace nfd {
namespace tests {
@@ -100,6 +100,33 @@
BOOST_CHECK(found3 == nullptr);
}
+BOOST_AUTO_TEST_CASE(FindLongestPrefixMatchWithPitEntry)
+{
+ NameTree nameTree;
+ Measurements measurements(nameTree);
+ Pit pit(nameTree);
+
+ measurements.get("/A");
+ measurements.get("/A/B/C")->getOrCreateStrategyInfo<DummyStrategyInfo1>();
+ measurements.get("/A/B/C/D");
+
+ shared_ptr<Interest> interest = makeInterest("/A/B/C/D/E");
+ shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
+
+ shared_ptr<measurements::Entry> found1 = measurements.findLongestPrefixMatch(*pitEntry);
+ BOOST_REQUIRE(found1 != nullptr);
+ BOOST_CHECK_EQUAL(found1->getName(), "/A/B/C/D");
+
+ shared_ptr<measurements::Entry> found2 = measurements.findLongestPrefixMatch(*pitEntry,
+ measurements::EntryWithStrategyInfo<DummyStrategyInfo1>());
+ BOOST_REQUIRE(found2 != nullptr);
+ BOOST_CHECK_EQUAL(found2->getName(), "/A/B/C");
+
+ shared_ptr<measurements::Entry> found3 = measurements.findLongestPrefixMatch(*pitEntry,
+ measurements::EntryWithStrategyInfo<DummyStrategyInfo2>());
+ BOOST_CHECK(found3 == nullptr);
+}
+
BOOST_FIXTURE_TEST_CASE(Lifetime, UnitTestTimeFixture)
{
NameTree nameTree;