table+fw: move forwarding semantics out of PIT entry
refs #3546
Change-Id: I1e6f87fd81176c116b6d758156da1cf96ea03608
diff --git a/daemon/table/pit-entry.cpp b/daemon/table/pit-entry.cpp
index 22df4a4..21e4c53 100644
--- a/daemon/table/pit-entry.cpp
+++ b/daemon/table/pit-entry.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,
@@ -29,9 +29,6 @@
namespace nfd {
namespace pit {
-const Name Entry::LOCALHOST_NAME("ndn:/localhost");
-const Name Entry::LOCALHOP_NAME("ndn:/localhop");
-
Entry::Entry(const Interest& interest)
: m_interest(interest.shared_from_this())
{
@@ -43,90 +40,6 @@
return m_interest->getName();
}
-bool
-Entry::hasLocalInRecord() const
-{
- return std::any_of(m_inRecords.begin(), m_inRecords.end(),
- [] (const InRecord& inRecord) { return inRecord.getFace()->getScope() == ndn::nfd::FACE_SCOPE_LOCAL; });
-}
-
-bool
-Entry::canForwardTo(const Face& face) const
-{
- time::steady_clock::TimePoint now = time::steady_clock::now();
-
- bool hasUnexpiredOutRecord = std::any_of(m_outRecords.begin(), m_outRecords.end(),
- [&face, &now] (const OutRecord& outRecord) {
- return outRecord.getFace().get() == &face && outRecord.getExpiry() >= now;
- });
- if (hasUnexpiredOutRecord) {
- return false;
- }
-
- bool hasUnexpiredOtherInRecord = std::any_of(m_inRecords.begin(), m_inRecords.end(),
- [&face, &now] (const InRecord& inRecord) {
- return inRecord.getFace().get() != &face && inRecord.getExpiry() >= now;
- });
- if (!hasUnexpiredOtherInRecord) {
- return false;
- }
-
- return !this->violatesScope(face);
-}
-
-bool
-Entry::violatesScope(const Face& face) const
-{
- // /localhost scope
- bool isViolatingLocalhost = face.getScope() == ndn::nfd::FACE_SCOPE_NON_LOCAL &&
- LOCALHOST_NAME.isPrefixOf(this->getName());
- if (isViolatingLocalhost) {
- return true;
- }
-
- // /localhop scope
- bool isViolatingLocalhop = face.getScope() == ndn::nfd::FACE_SCOPE_NON_LOCAL &&
- LOCALHOP_NAME.isPrefixOf(this->getName()) &&
- !this->hasLocalInRecord();
- if (isViolatingLocalhop) {
- return true;
- }
-
- return false;
-}
-
-int
-Entry::findNonce(uint32_t nonce, const Face& face) const
-{
- // TODO should we ignore expired in/out records?
-
- int dnw = DUPLICATE_NONCE_NONE;
-
- for (const InRecord& inRecord : m_inRecords) {
- if (inRecord.getLastNonce() == nonce) {
- if (inRecord.getFace().get() == &face) {
- dnw |= DUPLICATE_NONCE_IN_SAME;
- }
- else {
- dnw |= DUPLICATE_NONCE_IN_OTHER;
- }
- }
- }
-
- for (const OutRecord& outRecord : m_outRecords) {
- if (outRecord.getLastNonce() == nonce) {
- if (outRecord.getFace().get() == &face) {
- dnw |= DUPLICATE_NONCE_OUT_SAME;
- }
- else {
- dnw |= DUPLICATE_NONCE_OUT_OTHER;
- }
- }
- }
-
- return dnw;
-}
-
InRecordCollection::iterator
Entry::insertOrUpdateInRecord(shared_ptr<Face> face, const Interest& interest)
{
@@ -195,14 +108,5 @@
}
}
-bool
-Entry::hasUnexpiredOutRecords() const
-{
- time::steady_clock::TimePoint now = time::steady_clock::now();
-
- return std::any_of(m_outRecords.begin(), m_outRecords.end(),
- [&now] (const OutRecord& outRecord) { return outRecord.getExpiry() >= now; });
-}
-
} // namespace pit
} // namespace nfd
diff --git a/daemon/table/pit-entry.hpp b/daemon/table/pit-entry.hpp
index 3f15598..012b5aa 100644
--- a/daemon/table/pit-entry.hpp
+++ b/daemon/table/pit-entry.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,
@@ -36,7 +36,7 @@
namespace name_tree {
class Entry;
-}
+} // namespace name_tree
namespace pit {
@@ -48,20 +48,6 @@
*/
typedef std::list<OutRecord> OutRecordCollection;
-/** \brief indicates where duplicate Nonces are found
- */
-enum DuplicateNonceWhere {
- DUPLICATE_NONCE_NONE = 0,
- /// in-record of same face
- DUPLICATE_NONCE_IN_SAME = (1 << 0),
- /// in-record of other face
- DUPLICATE_NONCE_IN_OTHER = (1 << 1),
- /// out-record of same face
- DUPLICATE_NONCE_OUT_SAME = (1 << 2),
- /// out-record of other face
- DUPLICATE_NONCE_OUT_OTHER = (1 << 3)
-};
-
/** \brief represents a PIT entry
*/
class Entry : public StrategyInfoHost, noncopyable
@@ -78,45 +64,10 @@
const Name&
getName() const;
- /** \brief decides whether Interest can be forwarded to face
- *
- * \return true if OutRecord of this face does not exist or has expired,
- * and there is an InRecord not of this face,
- * and scope is not violated
- */
- bool
- canForwardTo(const Face& face) const;
-
- /** \brief decides whether forwarding Interest to face would violate scope
- *
- * \return true if scope control would be violated
- * \note canForwardTo has more comprehensive checks (including scope control)
- * and should be used by most strategies. Outgoing Interest pipeline
- * should only check scope because some strategy (eg. vehicular) needs
- * to retransmit sooner than OutRecord expiry, or forward Interest
- * back to incoming face
- */
- bool
- violatesScope(const Face& face) const;
-
- /** \brief finds where a duplicate Nonce appears
- * \return OR'ed DuplicateNonceWhere
- */
- int
- findNonce(uint32_t nonce, const Face& face) const;
-
public: // InRecord
const InRecordCollection&
getInRecords() const;
- /** \brief determines whether any InRecord is a local Face
- *
- * \return true if any InRecord is a local Face,
- * false if all InRecords are non-local Faces
- */
- bool
- hasLocalInRecord() const;
-
/** \brief inserts a InRecord for face, and updates it with interest
*
* If InRecord for face exists, the existing one is updated.
@@ -162,11 +113,6 @@
void
deleteOutRecord(const Face& face);
- /** \return true if there is one or more unexpired OutRecords
- */
- bool
- hasUnexpiredOutRecords() const;
-
public:
scheduler::EventId m_unsatisfyTimer;
scheduler::EventId m_stragglerTimer;