table: reorganize PIT implementation
Merge pit-{face,in,out}-record.{cpp,hpp} into pit-entry.{cpp,hpp}
and merge pit-iterator.{cpp,hpp} into pit.{cpp,hpp}.
Rename get{In,Out}Record() to find{In,Out}Record(), following the
typical C++ pattern of using the verb "find" for functions that
return iterators.
No functional changes.
Change-Id: I6740dd6cfe92ca477938ab8dc2f6271fd8b6cc26
diff --git a/daemon/fw/access-strategy.cpp b/daemon/fw/access-strategy.cpp
index 0070a3e..2c154bc 100644
--- a/daemon/fw/access-strategy.cpp
+++ b/daemon/fw/access-strategy.cpp
@@ -170,7 +170,7 @@
return;
}
- auto inRecord = pitEntry->getInRecord(*inFace);
+ auto inRecord = pitEntry->findInRecord(*inFace);
// in-record is erased only if Interest is satisfied, and RTO timer should have been cancelled
// note: if this strategy is extended to send Nacks, that would also erase the in-record,
// and the RTO timer should be cancelled in that case as well
@@ -218,7 +218,7 @@
return;
}
- auto outRecord = pitEntry->getOutRecord(ingress.face);
+ auto outRecord = pitEntry->findOutRecord(ingress.face);
if (outRecord == pitEntry->out_end()) {
NFD_LOG_DATA_FROM(data, ingress, "no-out-record");
return;
diff --git a/daemon/fw/algorithm.cpp b/daemon/fw/algorithm.cpp
index a16ccc3..cdc432b 100644
--- a/daemon/fw/algorithm.cpp
+++ b/daemon/fw/algorithm.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2022, Regents of the University of California,
+ * Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -116,7 +116,7 @@
if (!isNextHopEligible(inFace, interest, *it, pitEntry))
continue;
- auto outRecord = pitEntry->getOutRecord(it->getFace());
+ auto outRecord = pitEntry->findOutRecord(it->getFace());
BOOST_ASSERT(outRecord != pitEntry->out_end());
if (outRecord->getLastRenewed() < earliestRenewed) {
found = it;
@@ -142,7 +142,7 @@
if (wantUnused) {
// nexthop must not have unexpired out-record
- auto outRecord = pitEntry->getOutRecord(outFace);
+ auto outRecord = pitEntry->findOutRecord(outFace);
if (outRecord != pitEntry->out_end() && outRecord->getExpiry() > now) {
return false;
}
diff --git a/daemon/fw/asf-strategy.cpp b/daemon/fw/asf-strategy.cpp
index 18d1b70..edb6ec1 100644
--- a/daemon/fw/asf-strategy.cpp
+++ b/daemon/fw/asf-strategy.cpp
@@ -144,7 +144,7 @@
return;
}
- auto outRecord = pitEntry->getOutRecord(ingress.face);
+ auto outRecord = pitEntry->findOutRecord(ingress.face);
if (outRecord == pitEntry->out_end()) {
NFD_LOG_DATA_FROM(data, ingress, "no-out-record");
}
diff --git a/daemon/fw/forwarder.cpp b/daemon/fw/forwarder.cpp
index 4aa78e2..993f773 100644
--- a/daemon/fw/forwarder.cpp
+++ b/daemon/fw/forwarder.cpp
@@ -453,7 +453,7 @@
}
// has out-record?
- auto outRecord = pitEntry->getOutRecord(ingress.face);
+ auto outRecord = pitEntry->findOutRecord(ingress.face);
// if no out-record found, drop
if (outRecord == pitEntry->out_end()) {
NFD_LOG_DEBUG("onIncomingNack in=" << ingress << " nack=" << nack.getInterest().getName()
@@ -495,7 +495,7 @@
}
// has in-record?
- auto inRecord = pitEntry->getInRecord(egress);
+ auto inRecord = pitEntry->findInRecord(egress);
// if no in-record found, drop
if (inRecord == pitEntry->in_end()) {
@@ -585,15 +585,14 @@
// Dead Nonce List insert
if (upstream == nullptr) {
// insert all outgoing Nonces
- const auto& outRecords = pitEntry.getOutRecords();
- std::for_each(outRecords.begin(), outRecords.end(), [&] (const auto& outRecord) {
+ std::for_each(pitEntry.out_begin(), pitEntry.out_end(), [&] (const auto& outRecord) {
m_deadNonceList.add(pitEntry.getName(), outRecord.getLastNonce());
});
}
else {
// insert outgoing Nonce of a specific face
- auto outRecord = pitEntry.getOutRecord(*upstream);
- if (outRecord != pitEntry.getOutRecords().end()) {
+ auto outRecord = pitEntry.findOutRecord(*upstream);
+ if (outRecord != pitEntry.out_end()) {
m_deadNonceList.add(pitEntry.getName(), outRecord->getLastNonce());
}
}
diff --git a/daemon/fw/process-nack-traits.cpp b/daemon/fw/process-nack-traits.cpp
index 25b2526..6919268 100644
--- a/daemon/fw/process-nack-traits.cpp
+++ b/daemon/fw/process-nack-traits.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2023, Regents of the University of California,
+ * Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -55,7 +55,7 @@
if (nOutRecordsNotNacked == 1) {
BOOST_ASSERT(lastFaceNotNacked != nullptr);
- auto inR = pitEntry->getInRecord(*lastFaceNotNacked);
+ auto inR = pitEntry->findInRecord(*lastFaceNotNacked);
if (inR != pitEntry->in_end()) {
// one out-record not Nacked, which is also a downstream
NFD_LOG_NACK_FROM(nack, inFace.getId(), "bidirectional nack-to=" << lastFaceNotNacked->getId()
diff --git a/daemon/fw/retx-suppression-exponential.cpp b/daemon/fw/retx-suppression-exponential.cpp
index 39af1f5..8eb5071 100644
--- a/daemon/fw/retx-suppression-exponential.cpp
+++ b/daemon/fw/retx-suppression-exponential.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2022, Regents of the University of California,
+ * Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -99,7 +99,7 @@
RetxSuppressionExponential::decidePerUpstream(pit::Entry& pitEntry, Face& outFace)
{
// NEW if outRecord for the face does not exist
- auto outRecord = pitEntry.getOutRecord(outFace);
+ auto outRecord = pitEntry.findOutRecord(outFace);
if (outRecord == pitEntry.out_end()) {
return RetxSuppressionResult::NEW;
}
diff --git a/daemon/fw/self-learning-strategy.cpp b/daemon/fw/self-learning-strategy.cpp
index 7cb14c4..8b5b9e8 100644
--- a/daemon/fw/self-learning-strategy.cpp
+++ b/daemon/fw/self-learning-strategy.cpp
@@ -73,7 +73,7 @@
const fib::NextHopList& nexthops = fibEntry.getNextHops();
bool isNonDiscovery = interest.getTag<lp::NonDiscoveryTag>() != nullptr;
- auto inRecordInfo = pitEntry->getInRecord(ingress.face)->insertStrategyInfo<InRecordInfo>().first;
+ auto inRecordInfo = pitEntry->findInRecord(ingress.face)->insertStrategyInfo<InRecordInfo>().first;
if (isNonDiscovery) { // "non-discovery" Interest
inRecordInfo->isNonDiscoveryInterest = true;
if (nexthops.empty()) { // return NACK if no matching FIB entry exists
@@ -103,7 +103,7 @@
SelfLearningStrategy::afterReceiveData(const Data& data, const FaceEndpoint& ingress,
const shared_ptr<pit::Entry>& pitEntry)
{
- auto outRecord = pitEntry->getOutRecord(ingress.face);
+ auto outRecord = pitEntry->findOutRecord(ingress.face);
if (outRecord == pitEntry->out_end()) {
NFD_LOG_DATA_FROM(data, ingress, "no-out-record");
return;
diff --git a/daemon/fw/strategy.cpp b/daemon/fw/strategy.cpp
index 712e200..47fd7d9 100644
--- a/daemon/fw/strategy.cpp
+++ b/daemon/fw/strategy.cpp
@@ -248,7 +248,7 @@
{
BOOST_ASSERT(pitEntry->getInterest().matchesData(data));
- auto inRecord = pitEntry->getInRecord(egress);
+ auto inRecord = pitEntry->findInRecord(egress);
if (inRecord != pitEntry->in_end()) {
auto pitToken = inRecord->getInterest().getTag<lp::PitToken>();
diff --git a/daemon/table/pit-entry.cpp b/daemon/table/pit-entry.cpp
index 194106d..cfbbc82 100644
--- a/daemon/table/pit-entry.cpp
+++ b/daemon/table/pit-entry.cpp
@@ -29,6 +29,36 @@
namespace nfd::pit {
+void
+FaceRecord::update(const Interest& interest)
+{
+ m_lastNonce = interest.getNonce();
+ m_lastRenewed = time::steady_clock::now();
+
+ auto lifetime = interest.getInterestLifetime();
+ // impose an upper bound on the lifetime to prevent integer overflow when calculating m_expiry
+ lifetime = std::min<time::milliseconds>(lifetime, 10_days);
+ m_expiry = m_lastRenewed + lifetime;
+}
+
+void
+InRecord::update(const Interest& interest)
+{
+ FaceRecord::update(interest);
+ m_interest = interest.shared_from_this();
+}
+
+bool
+OutRecord::setIncomingNack(const lp::Nack& nack)
+{
+ if (nack.getInterest().getNonce() != this->getLastNonce()) {
+ return false;
+ }
+
+ m_incomingNack = make_unique<lp::NackHeader>(nack.getHeader());
+ return true;
+}
+
Entry::Entry(const Interest& interest)
: m_interest(interest.shared_from_this())
{
@@ -48,7 +78,7 @@
}
InRecordCollection::iterator
-Entry::getInRecord(const Face& face)
+Entry::findInRecord(const Face& face)
{
return std::find_if(m_inRecords.begin(), m_inRecords.end(),
[&face] (const InRecord& inRecord) { return &inRecord.getFace() == &face; });
@@ -70,21 +100,8 @@
return it;
}
-void
-Entry::deleteInRecord(InRecordCollection::const_iterator pos)
-{
- BOOST_ASSERT(pos != m_inRecords.end());
- m_inRecords.erase(pos);
-}
-
-void
-Entry::clearInRecords()
-{
- m_inRecords.clear();
-}
-
OutRecordCollection::iterator
-Entry::getOutRecord(const Face& face)
+Entry::findOutRecord(const Face& face)
{
return std::find_if(m_outRecords.begin(), m_outRecords.end(),
[&face] (const OutRecord& outRecord) { return &outRecord.getFace() == &face; });
diff --git a/daemon/table/pit-entry.hpp b/daemon/table/pit-entry.hpp
index d6f304b..a314ae6 100644
--- a/daemon/table/pit-entry.hpp
+++ b/daemon/table/pit-entry.hpp
@@ -26,18 +26,151 @@
#ifndef NFD_DAEMON_TABLE_PIT_ENTRY_HPP
#define NFD_DAEMON_TABLE_PIT_ENTRY_HPP
-#include "pit-in-record.hpp"
-#include "pit-out-record.hpp"
+#include "strategy-info-host.hpp"
#include <ndn-cxx/util/scheduler.hpp>
#include <list>
-namespace nfd::name_tree {
-class Entry;
-} // namespace nfd::name_tree
+namespace nfd {
-namespace nfd::pit {
+namespace face {
+class Face;
+} // namespace face
+using face::Face;
+
+namespace name_tree {
+class Entry;
+} // namespace name_tree
+
+namespace pit {
+
+/**
+ * \brief Contains information about an Interest on an incoming or outgoing face.
+ * \note This class is an implementation detail to extract common functionality
+ * of InRecord and OutRecord.
+ */
+class FaceRecord : public StrategyInfoHost
+{
+public:
+ explicit
+ FaceRecord(Face& face)
+ : m_face(face)
+ {
+ }
+
+ Face&
+ getFace() const noexcept
+ {
+ return m_face;
+ }
+
+ Interest::Nonce
+ getLastNonce() const noexcept
+ {
+ return m_lastNonce;
+ }
+
+ time::steady_clock::time_point
+ getLastRenewed() const noexcept
+ {
+ return m_lastRenewed;
+ }
+
+ /**
+ * \brief Returns the time point at which this record expires.
+ * \return getLastRenewed() + InterestLifetime
+ */
+ time::steady_clock::time_point
+ getExpiry() const noexcept
+ {
+ return m_expiry;
+ }
+
+ /**
+ * \brief Updates lastNonce, lastRenewed, expiry fields.
+ */
+ void
+ update(const Interest& interest);
+
+private:
+ Face& m_face;
+ Interest::Nonce m_lastNonce{0, 0, 0, 0};
+ time::steady_clock::time_point m_lastRenewed = time::steady_clock::time_point::min();
+ time::steady_clock::time_point m_expiry = time::steady_clock::time_point::min();
+};
+
+/**
+ * \brief Contains information about an Interest from an incoming face.
+ */
+class InRecord : public FaceRecord
+{
+public:
+ using FaceRecord::FaceRecord;
+
+ const Interest&
+ getInterest() const noexcept
+ {
+ BOOST_ASSERT(m_interest != nullptr);
+ return *m_interest;
+ }
+
+ void
+ update(const Interest& interest);
+
+private:
+ shared_ptr<const Interest> m_interest;
+};
+
+/**
+ * \brief Contains information about an Interest toward an outgoing face.
+ */
+class OutRecord : public FaceRecord
+{
+public:
+ using FaceRecord::FaceRecord;
+
+ /**
+ * \brief Returns the last Nack returned by getFace().
+ *
+ * A nullptr return value means the Interest is still pending or has timed out.
+ * A non-null return value means the last outgoing Interest has been Nacked.
+ */
+ const lp::NackHeader*
+ getIncomingNack() const noexcept
+ {
+ return m_incomingNack.get();
+ }
+
+ /**
+ * \brief Sets a Nack received from getFace().
+ * \return whether incoming Nack is accepted
+ *
+ * This is invoked in incoming Nack pipeline.
+ *
+ * An incoming Nack is accepted if its Nonce matches getLastNonce().
+ * If accepted, `nack.getHeader()` will be copied, and any pointers
+ * previously returned by getIncomingNack() are invalidated.
+ */
+ bool
+ setIncomingNack(const lp::Nack& nack);
+
+ /**
+ * \brief Clears last Nack.
+ *
+ * This is invoked in outgoing Interest pipeline.
+ *
+ * Any pointers previously returned by getIncomingNack() are invalidated.
+ */
+ void
+ clearIncomingNack() noexcept
+ {
+ m_incomingNack.reset();
+ }
+
+private:
+ unique_ptr<lp::NackHeader> m_incomingNack;
+};
/**
* \brief An unordered collection of in-records.
@@ -142,7 +275,7 @@
* \return an iterator to the in-record, or in_end() if it does not exist
*/
InRecordCollection::iterator
- getInRecord(const Face& face);
+ findInRecord(const Face& face);
/**
* \brief Insert or update an in-record.
@@ -156,13 +289,19 @@
* \param pos iterator to the in-record to remove; must be valid and dereferenceable.
*/
void
- deleteInRecord(InRecordCollection::const_iterator pos);
+ deleteInRecord(InRecordCollection::const_iterator pos)
+ {
+ m_inRecords.erase(pos);
+ }
/**
* \brief Removes all in-records.
*/
void
- clearInRecords();
+ clearInRecords() noexcept
+ {
+ m_inRecords.clear();
+ }
public: // out-record
/**
@@ -215,7 +354,7 @@
* \return an iterator to the out-record, or out_end() if it does not exist
*/
OutRecordCollection::iterator
- getOutRecord(const Face& face);
+ findOutRecord(const Face& face);
/**
* \brief Insert or update an out-record.
@@ -256,6 +395,7 @@
friend ::nfd::name_tree::Entry;
};
-} // namespace nfd::pit
+} // namespace pit
+} // namespace nfd
#endif // NFD_DAEMON_TABLE_PIT_ENTRY_HPP
diff --git a/daemon/table/pit-face-record.cpp b/daemon/table/pit-face-record.cpp
deleted file mode 100644
index 4b96c40..0000000
--- a/daemon/table/pit-face-record.cpp
+++ /dev/null
@@ -1,44 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2014-2022, 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.
- *
- * NFD is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * 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 "pit-face-record.hpp"
-
-namespace nfd::pit {
-
-// Impose a maximum lifetime to prevent integer overflow when calculating m_expiry.
-constexpr time::milliseconds MAX_LIFETIME = 10_days;
-
-void
-FaceRecord::update(const Interest& interest)
-{
- m_lastNonce = interest.getNonce();
- m_lastRenewed = time::steady_clock::now();
-
- auto lifetime = interest.getInterestLifetime();
- lifetime = std::min(lifetime, MAX_LIFETIME);
- m_expiry = m_lastRenewed + lifetime;
-}
-
-} // namespace nfd::pit
diff --git a/daemon/table/pit-face-record.hpp b/daemon/table/pit-face-record.hpp
deleted file mode 100644
index 830316e..0000000
--- a/daemon/table/pit-face-record.hpp
+++ /dev/null
@@ -1,89 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2014-2022, 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.
- *
- * NFD is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * 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_PIT_FACE_RECORD_HPP
-#define NFD_DAEMON_TABLE_PIT_FACE_RECORD_HPP
-
-#include "face/face.hpp"
-#include "strategy-info-host.hpp"
-
-namespace nfd::pit {
-
-/**
- * \brief Contains information about an Interest on an incoming or outgoing face.
- * \note This class is an implementation detail to extract common functionality
- * of InRecord and OutRecord.
- */
-class FaceRecord : public StrategyInfoHost
-{
-public:
- explicit
- FaceRecord(Face& face)
- : m_face(face)
- {
- }
-
- Face&
- getFace() const noexcept
- {
- return m_face;
- }
-
- Interest::Nonce
- getLastNonce() const noexcept
- {
- return m_lastNonce;
- }
-
- time::steady_clock::time_point
- getLastRenewed() const noexcept
- {
- return m_lastRenewed;
- }
-
- /** \brief Returns the time point at which this record expires.
- * \return getLastRenewed() + InterestLifetime
- */
- time::steady_clock::time_point
- getExpiry() const noexcept
- {
- return m_expiry;
- }
-
- /** \brief Updates lastNonce, lastRenewed, expiry fields.
- */
- void
- update(const Interest& interest);
-
-private:
- Face& m_face;
- Interest::Nonce m_lastNonce{0, 0, 0, 0};
- time::steady_clock::time_point m_lastRenewed = time::steady_clock::time_point::min();
- time::steady_clock::time_point m_expiry = time::steady_clock::time_point::min();
-};
-
-} // namespace nfd::pit
-
-#endif // NFD_DAEMON_TABLE_PIT_FACE_RECORD_HPP
diff --git a/daemon/table/pit-in-record.cpp b/daemon/table/pit-in-record.cpp
deleted file mode 100644
index 6982780..0000000
--- a/daemon/table/pit-in-record.cpp
+++ /dev/null
@@ -1,37 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2014-2022, 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.
- *
- * NFD is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * 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 "pit-in-record.hpp"
-
-namespace nfd::pit {
-
-void
-InRecord::update(const Interest& interest)
-{
- FaceRecord::update(interest);
- m_interest = interest.shared_from_this();
-}
-
-} // namespace nfd::pit
diff --git a/daemon/table/pit-in-record.hpp b/daemon/table/pit-in-record.hpp
deleted file mode 100644
index 95dc710..0000000
--- a/daemon/table/pit-in-record.hpp
+++ /dev/null
@@ -1,57 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2014-2022, 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.
- *
- * NFD is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * 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_PIT_IN_RECORD_HPP
-#define NFD_DAEMON_TABLE_PIT_IN_RECORD_HPP
-
-#include "pit-face-record.hpp"
-
-namespace nfd::pit {
-
-/**
- * \brief Contains information about an Interest from an incoming face.
- */
-class InRecord : public FaceRecord
-{
-public:
- using FaceRecord::FaceRecord;
-
- const Interest&
- getInterest() const noexcept
- {
- BOOST_ASSERT(m_interest != nullptr);
- return *m_interest;
- }
-
- void
- update(const Interest& interest);
-
-private:
- shared_ptr<const Interest> m_interest;
-};
-
-} // namespace nfd::pit
-
-#endif // NFD_DAEMON_TABLE_PIT_IN_RECORD_HPP
diff --git a/daemon/table/pit-iterator.cpp b/daemon/table/pit-iterator.cpp
deleted file mode 100644
index f3680f8..0000000
--- a/daemon/table/pit-iterator.cpp
+++ /dev/null
@@ -1,44 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2014-2023, 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.
- *
- * NFD is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * 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 "pit-iterator.hpp"
-
-namespace nfd::pit {
-
-Iterator&
-Iterator::operator++()
-{
- BOOST_ASSERT(m_ntIt != NameTree::const_iterator());
- BOOST_ASSERT(m_iPitEntry < m_ntIt->getPitEntries().size());
-
- if (++m_iPitEntry >= m_ntIt->getPitEntries().size()) {
- ++m_ntIt;
- m_iPitEntry = 0;
- BOOST_ASSERT(m_ntIt == NameTree::const_iterator() || m_ntIt->hasPitEntries());
- }
- return *this;
-}
-
-} // namespace nfd::pit
diff --git a/daemon/table/pit-iterator.hpp b/daemon/table/pit-iterator.hpp
deleted file mode 100644
index e1647ff..0000000
--- a/daemon/table/pit-iterator.hpp
+++ /dev/null
@@ -1,77 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2014-2023, 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.
- *
- * NFD is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * 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_PIT_ITERATOR_HPP
-#define NFD_DAEMON_TABLE_PIT_ITERATOR_HPP
-
-#include "name-tree.hpp"
-#include "pit-entry.hpp"
-
-namespace nfd::pit {
-
-/**
- * \brief PIT iterator.
- */
-class Iterator : public boost::forward_iterator_helper<Iterator, const Entry>
-{
-public:
- /**
- * \brief Constructor.
- * \param ntIt a name tree iterator that visits name tree entries with one or more PIT entries
- * \param iPitEntry make this iterator to dereference to the i-th PIT entry in name tree entry
- */
- explicit
- Iterator(const NameTree::const_iterator& ntIt = {}, size_t iPitEntry = 0)
- : m_ntIt(ntIt)
- , m_iPitEntry(iPitEntry)
- {
- }
-
- const Entry&
- operator*() const noexcept
- {
- BOOST_ASSERT(m_ntIt != NameTree::const_iterator());
- BOOST_ASSERT(m_iPitEntry < m_ntIt->getPitEntries().size());
- return *m_ntIt->getPitEntries()[m_iPitEntry];
- }
-
- Iterator&
- operator++();
-
- friend bool
- operator==(const Iterator& lhs, const Iterator& rhs) noexcept
- {
- return lhs.m_ntIt == rhs.m_ntIt &&
- lhs.m_iPitEntry == rhs.m_iPitEntry;
- }
-
-private:
- NameTree::const_iterator m_ntIt; ///< current name tree entry
- size_t m_iPitEntry; ///< current PIT entry within m_ntIt->getPitEntries()
-};
-
-} // namespace nfd::pit
-
-#endif // NFD_DAEMON_TABLE_PIT_ITERATOR_HPP
diff --git a/daemon/table/pit-out-record.cpp b/daemon/table/pit-out-record.cpp
deleted file mode 100644
index 1f3e899..0000000
--- a/daemon/table/pit-out-record.cpp
+++ /dev/null
@@ -1,41 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2014-2022, 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.
- *
- * NFD is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * 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 "pit-out-record.hpp"
-
-namespace nfd::pit {
-
-bool
-OutRecord::setIncomingNack(const lp::Nack& nack)
-{
- if (nack.getInterest().getNonce() != this->getLastNonce()) {
- return false;
- }
-
- m_incomingNack = make_unique<lp::NackHeader>(nack.getHeader());
- return true;
-}
-
-} // namespace nfd::pit
diff --git a/daemon/table/pit-out-record.hpp b/daemon/table/pit-out-record.hpp
deleted file mode 100644
index f165370..0000000
--- a/daemon/table/pit-out-record.hpp
+++ /dev/null
@@ -1,80 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2014-2022, 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.
- *
- * NFD is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * 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_PIT_OUT_RECORD_HPP
-#define NFD_DAEMON_TABLE_PIT_OUT_RECORD_HPP
-
-#include "pit-face-record.hpp"
-
-namespace nfd::pit {
-
-/**
- * \brief Contains information about an Interest toward an outgoing face.
- */
-class OutRecord : public FaceRecord
-{
-public:
- using FaceRecord::FaceRecord;
-
- /** \brief Returns the last NACK returned by getFace().
- *
- * A nullptr return value means the Interest is still pending or has timed out.
- * A non-null return value means the last outgoing Interest has been NACKed.
- */
- const lp::NackHeader*
- getIncomingNack() const noexcept
- {
- return m_incomingNack.get();
- }
-
- /** \brief Sets a NACK received from getFace().
- * \return whether incoming NACK is accepted
- *
- * This is invoked in incoming NACK pipeline.
- * An incoming NACK is accepted if its Nonce matches getLastNonce().
- * If accepted, `nack.getHeader()` will be copied,
- * and any pointer previously returned by getIncomingNack().
- */
- bool
- setIncomingNack(const lp::Nack& nack);
-
- /** \brief Clears last NACK.
- *
- * This is invoked in outgoing Interest pipeline.
- * This invalidates any pointer previously returned by getIncomingNack().
- */
- void
- clearIncomingNack() noexcept
- {
- m_incomingNack.reset();
- }
-
-private:
- unique_ptr<lp::NackHeader> m_incomingNack;
-};
-
-} // namespace nfd::pit
-
-#endif // NFD_DAEMON_TABLE_PIT_OUT_RECORD_HPP
diff --git a/daemon/table/pit.cpp b/daemon/table/pit.cpp
index b731df0..f2c7684 100644
--- a/daemon/table/pit.cpp
+++ b/daemon/table/pit.cpp
@@ -27,10 +27,18 @@
namespace nfd::pit {
-static inline bool
-nteHasPitEntries(const name_tree::Entry& nte)
+Iterator&
+Iterator::operator++()
{
- return nte.hasPitEntries();
+ BOOST_ASSERT(m_ntIt != NameTree::const_iterator());
+ BOOST_ASSERT(m_iPitEntry < m_ntIt->getPitEntries().size());
+
+ if (++m_iPitEntry >= m_ntIt->getPitEntries().size()) {
+ ++m_ntIt;
+ m_iPitEntry = 0;
+ BOOST_ASSERT(m_ntIt == NameTree::const_iterator() || m_ntIt->hasPitEntries());
+ }
+ return *this;
}
Pit::Pit(NameTree& nameTree)
@@ -44,7 +52,7 @@
// determine which NameTree entry should the PIT entry be attached onto
const Name& name = interest.getName();
bool hasDigest = name.size() > 0 && name[-1].isImplicitSha256Digest();
- size_t nteDepth = name.size() - static_cast<int>(hasDigest);
+ size_t nteDepth = name.size() - static_cast<size_t>(hasDigest);
nteDepth = std::min(nteDepth, NameTree::getMaxDepth());
// ensure NameTree entry exists
@@ -81,6 +89,12 @@
return {entry, true};
}
+static bool
+nteHasPitEntries(const name_tree::Entry& nte)
+{
+ return nte.hasPitEntries();
+}
+
DataMatchResult
Pit::findAllDataMatches(const Data& data) const
{
@@ -115,7 +129,7 @@
{
BOOST_ASSERT(entry != nullptr);
- auto in = entry->getInRecord(face);
+ auto in = entry->findInRecord(face);
if (in != entry->in_end()) {
entry->deleteInRecord(in);
}
diff --git a/daemon/table/pit.hpp b/daemon/table/pit.hpp
index b44dce8..dab57ea 100644
--- a/daemon/table/pit.hpp
+++ b/daemon/table/pit.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2022, Regents of the University of California,
+ * Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -26,23 +26,60 @@
#ifndef NFD_DAEMON_TABLE_PIT_HPP
#define NFD_DAEMON_TABLE_PIT_HPP
+#include "name-tree.hpp"
#include "pit-entry.hpp"
-#include "pit-iterator.hpp"
namespace nfd {
namespace pit {
-/** \class nfd::pit::DataMatchResult
- * \brief An unordered iterable of all PIT entries matching Data.
- *
- * This type has the following member functions:
- * - `iterator<shared_ptr<Entry>> begin()`
- * - `iterator<shared_ptr<Entry>> end()`
- * - `size_t size() const`
+/**
+ * \brief An unordered iterable of all PIT entries matching a Data packet.
*/
using DataMatchResult = std::vector<shared_ptr<Entry>>;
-/** \brief Represents the Interest Table
+/**
+ * \brief PIT iterator.
+ */
+class Iterator : public boost::forward_iterator_helper<Iterator, const Entry>
+{
+public:
+ /**
+ * \brief Constructor.
+ * \param ntIt a name tree iterator that visits name tree entries with one or more PIT entries
+ * \param iPitEntry make this iterator to dereference to the i-th PIT entry in name tree entry
+ */
+ explicit
+ Iterator(const NameTree::const_iterator& ntIt = {}, size_t iPitEntry = 0)
+ : m_ntIt(ntIt)
+ , m_iPitEntry(iPitEntry)
+ {
+ }
+
+ const Entry&
+ operator*() const noexcept
+ {
+ BOOST_ASSERT(m_ntIt != NameTree::const_iterator());
+ BOOST_ASSERT(m_iPitEntry < m_ntIt->getPitEntries().size());
+ return *m_ntIt->getPitEntries()[m_iPitEntry];
+ }
+
+ Iterator&
+ operator++();
+
+ friend bool
+ operator==(const Iterator& lhs, const Iterator& rhs) noexcept
+ {
+ return lhs.m_ntIt == rhs.m_ntIt &&
+ lhs.m_iPitEntry == rhs.m_iPitEntry;
+ }
+
+private:
+ NameTree::const_iterator m_ntIt; ///< current name tree entry
+ size_t m_iPitEntry; ///< current PIT entry within m_ntIt->getPitEntries()
+};
+
+/**
+ * \brief NFD's Interest Table.
*/
class Pit : noncopyable
{
@@ -50,7 +87,8 @@
explicit
Pit(NameTree& nameTree);
- /** \return number of entries
+ /**
+ * \brief Returns the number of entries.
*/
size_t
size() const