fw: reorder function params to make the strategy API more uniform
Also add a non-const overload of Face::getCounters to avoid const_cast
Refs: #5173
Change-Id: Iff0bfbdedb90e68a373090cf3f247d9a7501f58d
diff --git a/daemon/face/face-endpoint.hpp b/daemon/face/face-endpoint.hpp
index 4d33634..366c743 100644
--- a/daemon/face/face-endpoint.hpp
+++ b/daemon/face/face-endpoint.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2019, Regents of the University of California,
+ * Copyright (c) 2014-2021, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -36,8 +36,8 @@
class FaceEndpoint
{
public:
- FaceEndpoint(const Face& face, EndpointId endpoint)
- : face(const_cast<Face&>(face))
+ FaceEndpoint(Face& face, EndpointId endpoint)
+ : face(face)
, endpoint(endpoint)
{
}
diff --git a/daemon/face/face.hpp b/daemon/face/face.hpp
index 0076f85..c91e78a 100644
--- a/daemon/face/face.hpp
+++ b/daemon/face/face.hpp
@@ -171,7 +171,16 @@
getExpirationTime() const;
const FaceCounters&
- getCounters() const;
+ getCounters() const
+ {
+ return m_counters;
+ }
+
+ FaceCounters&
+ getCounters()
+ {
+ return m_counters;
+ }
/**
* \brief Get channel on which face was created (unicast) or the associated channel (multicast)
@@ -301,12 +310,6 @@
return m_transport->getExpirationTime();
}
-inline const FaceCounters&
-Face::getCounters() const
-{
- return m_counters;
-}
-
std::ostream&
operator<<(std::ostream& os, const FaceLogHelper<Face>& flh);
diff --git a/daemon/fw/access-strategy.cpp b/daemon/fw/access-strategy.cpp
index 8dfcba2..e1443df 100644
--- a/daemon/fw/access-strategy.cpp
+++ b/daemon/fw/access-strategy.cpp
@@ -57,15 +57,15 @@
}
void
-AccessStrategy::afterReceiveInterest(const FaceEndpoint& ingress, const Interest& interest,
+AccessStrategy::afterReceiveInterest(const Interest& interest, const FaceEndpoint& ingress,
const shared_ptr<pit::Entry>& pitEntry)
{
auto suppressResult = m_retxSuppression.decidePerPitEntry(*pitEntry);
switch (suppressResult) {
case RetxSuppressionResult::NEW:
- return afterReceiveNewInterest(ingress, interest, pitEntry);
+ return afterReceiveNewInterest(interest, ingress, pitEntry);
case RetxSuppressionResult::FORWARD:
- return afterReceiveRetxInterest(ingress, interest, pitEntry);
+ return afterReceiveRetxInterest(interest, ingress, pitEntry);
case RetxSuppressionResult::SUPPRESS:
NFD_LOG_DEBUG(interest << " interestFrom " << ingress << " retx-suppress");
return;
@@ -73,7 +73,7 @@
}
void
-AccessStrategy::afterReceiveNewInterest(const FaceEndpoint& ingress, const Interest& interest,
+AccessStrategy::afterReceiveNewInterest(const Interest& interest, const FaceEndpoint& ingress,
const shared_ptr<pit::Entry>& pitEntry)
{
const auto& fibEntry = this->lookupFib(*pitEntry);
@@ -86,7 +86,7 @@
NFD_LOG_DEBUG(interest << " interestFrom " << ingress << " new-interest mi=" << miName);
// send to last working nexthop
- bool isSentToLastNexthop = this->sendToLastNexthop(ingress, interest, pitEntry, *mi, fibEntry);
+ bool isSentToLastNexthop = this->sendToLastNexthop(interest, ingress, pitEntry, *mi, fibEntry);
if (isSentToLastNexthop) {
return;
}
@@ -98,7 +98,7 @@
// no measurements, or last working nexthop unavailable
// multicast to all nexthops except incoming face
- size_t nMulticastSent = this->multicast(ingress.face, interest, pitEntry, fibEntry);
+ size_t nMulticastSent = this->multicast(interest, ingress.face, pitEntry, fibEntry);
if (nMulticastSent == 0) {
this->rejectPendingInterest(pitEntry);
@@ -106,16 +106,16 @@
}
void
-AccessStrategy::afterReceiveRetxInterest(const FaceEndpoint& ingress, const Interest& interest,
+AccessStrategy::afterReceiveRetxInterest(const Interest& interest, const FaceEndpoint& ingress,
const shared_ptr<pit::Entry>& pitEntry)
{
const auto& fibEntry = this->lookupFib(*pitEntry);
NFD_LOG_DEBUG(interest << " interestFrom " << ingress << " retx-forward");
- this->multicast(ingress.face, interest, pitEntry, fibEntry);
+ this->multicast(interest, ingress.face, pitEntry, fibEntry);
}
bool
-AccessStrategy::sendToLastNexthop(const FaceEndpoint& ingress, const Interest& interest,
+AccessStrategy::sendToLastNexthop(const Interest& interest, const FaceEndpoint& ingress,
const shared_ptr<pit::Entry>& pitEntry, MtInfo& mi,
const fib::Entry& fibEntry)
{
@@ -144,7 +144,7 @@
NFD_LOG_DEBUG(pitEntry->getInterest() << " interestTo " << mi.lastNexthop
<< " last-nexthop rto=" << time::duration_cast<time::microseconds>(rto).count());
- if (!this->sendInterest(pitEntry, *outFace, interest)) {
+ if (!this->sendInterest(interest, *outFace, pitEntry)) {
return false;
}
@@ -184,11 +184,11 @@
NFD_LOG_DEBUG(pitEntry->getInterest() << " timeoutFrom " << firstOutFaceId
<< " multicast-except " << firstOutFaceId);
- this->multicast(*inFace, interest, pitEntry, fibEntry, firstOutFaceId);
+ this->multicast(interest, *inFace, pitEntry, fibEntry, firstOutFaceId);
}
size_t
-AccessStrategy::multicast(const Face& inFace, const Interest& interest,
+AccessStrategy::multicast(const Interest& interest, const Face& inFace,
const shared_ptr<pit::Entry>& pitEntry, const fib::Entry& fibEntry,
FaceId exceptFace)
{
@@ -200,7 +200,7 @@
continue;
}
NFD_LOG_DEBUG(pitEntry->getInterest() << " interestTo " << outFace.getId() << " multicast");
- if (this->sendInterest(pitEntry, outFace, interest)) {
+ if (this->sendInterest(interest, outFace, pitEntry)) {
++nSent;
}
}
@@ -208,8 +208,8 @@
}
void
-AccessStrategy::beforeSatisfyInterest(const shared_ptr<pit::Entry>& pitEntry,
- const FaceEndpoint& ingress, const Data& data)
+AccessStrategy::beforeSatisfyInterest(const Data& data, const FaceEndpoint& ingress,
+ const shared_ptr<pit::Entry>& pitEntry)
{
PitInfo* pi = pitEntry->getStrategyInfo<PitInfo>();
if (pi != nullptr) {
diff --git a/daemon/fw/access-strategy.hpp b/daemon/fw/access-strategy.hpp
index 0f83a64..edcf63b 100644
--- a/daemon/fw/access-strategy.hpp
+++ b/daemon/fw/access-strategy.hpp
@@ -56,12 +56,12 @@
public: // triggers
void
- afterReceiveInterest(const FaceEndpoint& ingress, const Interest& interest,
+ afterReceiveInterest(const Interest& interest, const FaceEndpoint& ingress,
const shared_ptr<pit::Entry>& pitEntry) override;
void
- beforeSatisfyInterest(const shared_ptr<pit::Entry>& pitEntry,
- const FaceEndpoint& ingress, const Data& data) override;
+ beforeSatisfyInterest(const Data& data, const FaceEndpoint& ingress,
+ const shared_ptr<pit::Entry>& pitEntry) override;
private: // StrategyInfo
using RttEstimator = ndn::util::RttEstimator;
@@ -133,18 +133,18 @@
private: // forwarding procedures
void
- afterReceiveNewInterest(const FaceEndpoint& ingress, const Interest& interest,
+ afterReceiveNewInterest(const Interest& interest, const FaceEndpoint& ingress,
const shared_ptr<pit::Entry>& pitEntry);
void
- afterReceiveRetxInterest(const FaceEndpoint& ingress, const Interest& interest,
+ afterReceiveRetxInterest(const Interest& interest, const FaceEndpoint& ingress,
const shared_ptr<pit::Entry>& pitEntry);
/** \brief send to last working nexthop
* \return whether an Interest is sent
*/
bool
- sendToLastNexthop(const FaceEndpoint& ingress, const Interest& interest,
+ sendToLastNexthop(const Interest& interest, const FaceEndpoint& ingress,
const shared_ptr<pit::Entry>& pitEntry, MtInfo& mi,
const fib::Entry& fibEntry);
@@ -157,7 +157,7 @@
* \return number of Interests that were sent
*/
size_t
- multicast(const Face& inFace, const Interest& interest,
+ multicast(const Interest& interest, const Face& inFace,
const shared_ptr<pit::Entry>& pitEntry, const fib::Entry& fibEntry,
FaceId exceptFace = face::INVALID_FACEID);
diff --git a/daemon/fw/asf-strategy.cpp b/daemon/fw/asf-strategy.cpp
index d8959af..f337a27 100644
--- a/daemon/fw/asf-strategy.cpp
+++ b/daemon/fw/asf-strategy.cpp
@@ -107,7 +107,7 @@
}
void
-AsfStrategy::afterReceiveInterest(const FaceEndpoint& ingress, const Interest& interest,
+AsfStrategy::afterReceiveInterest(const Interest& interest, const FaceEndpoint& ingress,
const shared_ptr<pit::Entry>& pitEntry)
{
const auto& fibEntry = this->lookupFib(*pitEntry);
@@ -165,7 +165,7 @@
NFD_LOG_DEBUG(interest << " retx-interest from=" << ingress << " retry-to=" << outFace.getId());
// sendInterest() is used here instead of forwardInterest() because the measurements info
// were already attached to this face in the previous forwarding
- auto* outRecord = sendInterest(pitEntry, outFace, interest);
+ auto* outRecord = sendInterest(interest, outFace, pitEntry);
if (outRecord && suppressResult == RetxSuppressionResult::FORWARD) {
m_retxSuppression.incrementIntervalForOutRecord(*outRecord);
}
@@ -173,8 +173,8 @@
}
void
-AsfStrategy::beforeSatisfyInterest(const shared_ptr<pit::Entry>& pitEntry,
- const FaceEndpoint& ingress, const Data& data)
+AsfStrategy::beforeSatisfyInterest(const Data& data, const FaceEndpoint& ingress,
+ const shared_ptr<pit::Entry>& pitEntry)
{
NamespaceInfo* namespaceInfo = m_measurements.getNamespaceInfo(pitEntry->getName());
if (namespaceInfo == nullptr) {
@@ -207,7 +207,7 @@
}
void
-AsfStrategy::afterReceiveNack(const FaceEndpoint& ingress, const lp::Nack& nack,
+AsfStrategy::afterReceiveNack(const lp::Nack& nack, const FaceEndpoint& ingress,
const shared_ptr<pit::Entry>& pitEntry)
{
NFD_LOG_DEBUG(nack.getInterest() << " nack from=" << ingress << " reason=" << nack.getReason());
@@ -221,7 +221,7 @@
const auto& interestName = interest.getName();
auto faceId = outFace.getId();
- auto* outRecord = sendInterest(pitEntry, outFace, interest);
+ auto* outRecord = sendInterest(interest, outFace, pitEntry);
FaceInfo& faceInfo = m_measurements.getOrCreateFaceInfo(fibEntry, interestName, faceId);
@@ -361,7 +361,7 @@
{
lp::NackHeader nackHeader;
nackHeader.setReason(lp::NackReason::NO_ROUTE);
- this->sendNack(pitEntry, face, nackHeader);
+ this->sendNack(nackHeader, face, pitEntry);
this->rejectPendingInterest(pitEntry);
}
diff --git a/daemon/fw/asf-strategy.hpp b/daemon/fw/asf-strategy.hpp
index 932cffa..2e0ba24 100644
--- a/daemon/fw/asf-strategy.hpp
+++ b/daemon/fw/asf-strategy.hpp
@@ -53,15 +53,15 @@
public: // triggers
void
- afterReceiveInterest(const FaceEndpoint& ingress, const Interest& interest,
+ afterReceiveInterest(const Interest& interest, const FaceEndpoint& ingress,
const shared_ptr<pit::Entry>& pitEntry) override;
void
- beforeSatisfyInterest(const shared_ptr<pit::Entry>& pitEntry,
- const FaceEndpoint& ingress, const Data& data) override;
+ beforeSatisfyInterest(const Data& data, const FaceEndpoint& ingress,
+ const shared_ptr<pit::Entry>& pitEntry) override;
void
- afterReceiveNack(const FaceEndpoint& ingress, const lp::Nack& nack,
+ afterReceiveNack(const lp::Nack& nack, const FaceEndpoint& ingress,
const shared_ptr<pit::Entry>& pitEntry) override;
private:
diff --git a/daemon/fw/best-route-strategy.cpp b/daemon/fw/best-route-strategy.cpp
index e684250..eecc3b5 100644
--- a/daemon/fw/best-route-strategy.cpp
+++ b/daemon/fw/best-route-strategy.cpp
@@ -62,7 +62,7 @@
}
void
-BestRouteStrategy::afterReceiveInterest(const FaceEndpoint& ingress, const Interest& interest,
+BestRouteStrategy::afterReceiveInterest(const Interest& interest, const FaceEndpoint& ingress,
const shared_ptr<pit::Entry>& pitEntry)
{
RetxSuppressionResult suppression = m_retxSuppression.decidePerPitEntry(*pitEntry);
@@ -86,15 +86,14 @@
lp::NackHeader nackHeader;
nackHeader.setReason(lp::NackReason::NO_ROUTE);
- this->sendNack(pitEntry, ingress.face, nackHeader);
-
+ this->sendNack(nackHeader, ingress.face, pitEntry);
this->rejectPendingInterest(pitEntry);
return;
}
Face& outFace = it->getFace();
NFD_LOG_DEBUG(interest << " from=" << ingress << " newPitEntry-to=" << outFace.getId());
- this->sendInterest(pitEntry, outFace, interest);
+ this->sendInterest(interest, outFace, pitEntry);
return;
}
@@ -106,7 +105,7 @@
if (it != nexthops.end()) {
Face& outFace = it->getFace();
- this->sendInterest(pitEntry, outFace, interest);
+ this->sendInterest(interest, outFace, pitEntry);
NFD_LOG_DEBUG(interest << " from=" << ingress << " retransmit-unused-to=" << outFace.getId());
return;
}
@@ -118,16 +117,16 @@
}
else {
Face& outFace = it->getFace();
- this->sendInterest(pitEntry, outFace, interest);
+ this->sendInterest(interest, outFace, pitEntry);
NFD_LOG_DEBUG(interest << " from=" << ingress << " retransmit-retry-to=" << outFace.getId());
}
}
void
-BestRouteStrategy::afterReceiveNack(const FaceEndpoint& ingress, const lp::Nack& nack,
+BestRouteStrategy::afterReceiveNack(const lp::Nack& nack, const FaceEndpoint& ingress,
const shared_ptr<pit::Entry>& pitEntry)
{
- this->processNack(ingress.face, nack, pitEntry);
+ this->processNack(nack, ingress.face, pitEntry);
}
} // namespace fw
diff --git a/daemon/fw/best-route-strategy.hpp b/daemon/fw/best-route-strategy.hpp
index 636abd2..3f11c7a 100644
--- a/daemon/fw/best-route-strategy.hpp
+++ b/daemon/fw/best-route-strategy.hpp
@@ -60,12 +60,13 @@
static const Name&
getStrategyName();
+public: // triggers
void
- afterReceiveInterest(const FaceEndpoint& ingress, const Interest& interest,
+ afterReceiveInterest(const Interest& interest, const FaceEndpoint& ingress,
const shared_ptr<pit::Entry>& pitEntry) override;
void
- afterReceiveNack(const FaceEndpoint& ingress, const lp::Nack& nack,
+ afterReceiveNack(const lp::Nack& nack, const FaceEndpoint& ingress,
const shared_ptr<pit::Entry>& pitEntry) override;
NFD_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
diff --git a/daemon/fw/forwarder.cpp b/daemon/fw/forwarder.cpp
index 171a541..fea18f6 100644
--- a/daemon/fw/forwarder.cpp
+++ b/daemon/fw/forwarder.cpp
@@ -57,19 +57,19 @@
m_faceTable.afterAdd.connect([this] (const Face& face) {
face.afterReceiveInterest.connect(
[this, &face] (const Interest& interest, const EndpointId& endpointId) {
- this->startProcessInterest(FaceEndpoint(face, endpointId), interest);
+ this->onIncomingInterest(interest, FaceEndpoint(const_cast<Face&>(face), endpointId));
});
face.afterReceiveData.connect(
[this, &face] (const Data& data, const EndpointId& endpointId) {
- this->startProcessData(FaceEndpoint(face, endpointId), data);
+ this->onIncomingData(data, FaceEndpoint(const_cast<Face&>(face), endpointId));
});
face.afterReceiveNack.connect(
[this, &face] (const lp::Nack& nack, const EndpointId& endpointId) {
- this->startProcessNack(FaceEndpoint(face, endpointId), nack);
+ this->onIncomingNack(nack, FaceEndpoint(const_cast<Face&>(face), endpointId));
});
face.onDroppedInterest.connect(
[this, &face] (const Interest& interest) {
- this->onDroppedInterest(face, interest);
+ this->onDroppedInterest(interest, const_cast<Face&>(face));
});
});
@@ -87,7 +87,7 @@
Forwarder::~Forwarder() = default;
void
-Forwarder::onIncomingInterest(const FaceEndpoint& ingress, const Interest& interest)
+Forwarder::onIncomingInterest(const Interest& interest, const FaceEndpoint& ingress)
{
// receive Interest
NFD_LOG_DEBUG("onIncomingInterest in=" << ingress << " interest=" << interest.getName());
@@ -96,13 +96,13 @@
// drop if HopLimit zero, decrement otherwise (if present)
if (interest.getHopLimit()) {
- if (*interest.getHopLimit() < 1) {
+ if (*interest.getHopLimit() == 0) {
NFD_LOG_DEBUG("onIncomingInterest in=" << ingress << " interest=" << interest.getName()
<< " hop-limit=0");
- ++const_cast<PacketCounter&>(ingress.face.getCounters().nInHopLimitZero);
+ ++ingress.face.getCounters().nInHopLimitZero;
+ // drop
return;
}
-
const_cast<Interest&>(interest).setHopLimit(*interest.getHopLimit() - 1);
}
@@ -112,7 +112,7 @@
if (isViolatingLocalhost) {
NFD_LOG_DEBUG("onIncomingInterest in=" << ingress
<< " interest=" << interest.getName() << " violates /localhost");
- // (drop)
+ // drop
return;
}
@@ -120,7 +120,7 @@
bool hasDuplicateNonceInDnl = m_deadNonceList.has(interest.getName(), interest.getNonce());
if (hasDuplicateNonceInDnl) {
// goto Interest loop pipeline
- this->onInterestLoop(ingress, interest);
+ this->onInterestLoop(interest, ingress);
return;
}
@@ -144,23 +144,23 @@
}
if (hasDuplicateNonceInPit) {
// goto Interest loop pipeline
- this->onInterestLoop(ingress, interest);
+ this->onInterestLoop(interest, ingress);
return;
}
// is pending?
if (!pitEntry->hasInRecords()) {
m_cs.find(interest,
- bind(&Forwarder::onContentStoreHit, this, ingress, pitEntry, _1, _2),
- bind(&Forwarder::onContentStoreMiss, this, ingress, pitEntry, _1));
+ [=] (const Interest& i, const Data& d) { onContentStoreHit(i, ingress, pitEntry, d); },
+ [=] (const Interest& i) { onContentStoreMiss(i, ingress, pitEntry); });
}
else {
- this->onContentStoreMiss(ingress, pitEntry, interest);
+ this->onContentStoreMiss(interest, ingress, pitEntry);
}
}
void
-Forwarder::onInterestLoop(const FaceEndpoint& ingress, const Interest& interest)
+Forwarder::onInterestLoop(const Interest& interest, const FaceEndpoint& ingress)
{
// if multi-access or ad hoc face, drop
if (ingress.face.getLinkType() != ndn::nfd::LINK_TYPE_POINT_TO_POINT) {
@@ -180,8 +180,8 @@
}
void
-Forwarder::onContentStoreMiss(const FaceEndpoint& ingress,
- const shared_ptr<pit::Entry>& pitEntry, const Interest& interest)
+Forwarder::onContentStoreMiss(const Interest& interest, const FaceEndpoint& ingress,
+ const shared_ptr<pit::Entry>& pitEntry)
{
NFD_LOG_DEBUG("onContentStoreMiss interest=" << interest.getName());
++m_counters.nCsMisses;
@@ -207,19 +207,19 @@
<< " nexthop-faceid=" << nextHopFace->getId());
// go to outgoing Interest pipeline
// scope control is unnecessary, because privileged app explicitly wants to forward
- this->onOutgoingInterest(pitEntry, *nextHopFace, interest);
+ this->onOutgoingInterest(interest, *nextHopFace, pitEntry);
}
return;
}
// dispatch to strategy: after receive Interest
m_strategyChoice.findEffectiveStrategy(*pitEntry)
- .afterReceiveInterest(FaceEndpoint(ingress.face, 0), interest, pitEntry);
+ .afterReceiveInterest(interest, FaceEndpoint(ingress.face, 0), pitEntry);
}
void
-Forwarder::onContentStoreHit(const FaceEndpoint& ingress, const shared_ptr<pit::Entry>& pitEntry,
- const Interest& interest, const Data& data)
+Forwarder::onContentStoreHit(const Interest& interest, const FaceEndpoint& ingress,
+ const shared_ptr<pit::Entry>& pitEntry, const Data& data)
{
NFD_LOG_DEBUG("onContentStoreHit interest=" << interest.getName());
++m_counters.nCsHits;
@@ -235,18 +235,18 @@
this->setExpiryTimer(pitEntry, 0_ms);
// dispatch to strategy: after Content Store hit
- m_strategyChoice.findEffectiveStrategy(*pitEntry).afterContentStoreHit(pitEntry, ingress, data);
+ m_strategyChoice.findEffectiveStrategy(*pitEntry).afterContentStoreHit(data, ingress, pitEntry);
}
pit::OutRecord*
-Forwarder::onOutgoingInterest(const shared_ptr<pit::Entry>& pitEntry,
- Face& egress, const Interest& interest)
+Forwarder::onOutgoingInterest(const Interest& interest, Face& egress,
+ const shared_ptr<pit::Entry>& pitEntry)
{
// drop if HopLimit == 0 but sending on non-local face
if (interest.getHopLimit() == 0 && egress.getScope() == ndn::nfd::FACE_SCOPE_NON_LOCAL) {
NFD_LOG_DEBUG("onOutgoingInterest out=" << egress.getId() << " interest=" << pitEntry->getName()
<< " non-local hop-limit=0");
- ++const_cast<PacketCounter&>(egress.getCounters().nOutHopLimitZero);
+ ++egress.getCounters().nOutHopLimitZero;
return nullptr;
}
@@ -285,7 +285,7 @@
}
void
-Forwarder::onIncomingData(const FaceEndpoint& ingress, const Data& data)
+Forwarder::onIncomingData(const Data& data, const FaceEndpoint& ingress)
{
// receive Data
NFD_LOG_DEBUG("onIncomingData in=" << ingress << " data=" << data.getName());
@@ -297,7 +297,7 @@
scope_prefix::LOCALHOST.isPrefixOf(data.getName());
if (isViolatingLocalhost) {
NFD_LOG_DEBUG("onIncomingData in=" << ingress << " data=" << data.getName() << " violates /localhost");
- // (drop)
+ // drop
return;
}
@@ -305,7 +305,7 @@
pit::DataMatchResult pitMatches = m_pit.findAllDataMatches(data);
if (pitMatches.size() == 0) {
// goto Data unsolicited pipeline
- this->onDataUnsolicited(ingress, data);
+ this->onDataUnsolicited(data, ingress);
return;
}
@@ -322,7 +322,7 @@
this->setExpiryTimer(pitEntry, 0_ms);
// trigger strategy: after receive Data
- m_strategyChoice.findEffectiveStrategy(*pitEntry).afterReceiveData(pitEntry, ingress, data);
+ m_strategyChoice.findEffectiveStrategy(*pitEntry).afterReceiveData(data, ingress, pitEntry);
// mark PIT satisfied
pitEntry->isSatisfied = true;
@@ -354,7 +354,7 @@
this->setExpiryTimer(pitEntry, 0_ms);
// invoke PIT satisfy callback
- m_strategyChoice.findEffectiveStrategy(*pitEntry).beforeSatisfyInterest(pitEntry, ingress, data);
+ m_strategyChoice.findEffectiveStrategy(*pitEntry).beforeSatisfyInterest(data, ingress, pitEntry);
// mark PIT satisfied
pitEntry->isSatisfied = true;
@@ -381,7 +381,7 @@
}
void
-Forwarder::onDataUnsolicited(const FaceEndpoint& ingress, const Data& data)
+Forwarder::onDataUnsolicited(const Data& data, const FaceEndpoint& ingress)
{
// accept to cache?
auto decision = m_unsolicitedDataPolicy->decide(ingress.face, data);
@@ -410,7 +410,7 @@
if (isViolatingLocalhost) {
NFD_LOG_DEBUG("onOutgoingData out=" << egress.getId() << " data=" << data.getName()
<< " violates /localhost");
- // (drop)
+ // drop
return false;
}
@@ -424,7 +424,7 @@
}
void
-Forwarder::onIncomingNack(const FaceEndpoint& ingress, const lp::Nack& nack)
+Forwarder::onIncomingNack(const lp::Nack& nack, const FaceEndpoint& ingress)
{
// receive Nack
nack.setTag(make_shared<lp::IncomingFaceIdTag>(ingress.face.getId()));
@@ -476,12 +476,12 @@
}
// trigger strategy: after receive NACK
- m_strategyChoice.findEffectiveStrategy(*pitEntry).afterReceiveNack(ingress, nack, pitEntry);
+ m_strategyChoice.findEffectiveStrategy(*pitEntry).afterReceiveNack(nack, ingress, pitEntry);
}
bool
-Forwarder::onOutgoingNack(const shared_ptr<pit::Entry>& pitEntry,
- Face& egress, const lp::NackHeader& nack)
+Forwarder::onOutgoingNack(const lp::NackHeader& nack, Face& egress,
+ const shared_ptr<pit::Entry>& pitEntry)
{
if (egress.getId() == face::INVALID_FACEID) {
NFD_LOG_WARN("onOutgoingNack out=(invalid)"
@@ -527,9 +527,9 @@
}
void
-Forwarder::onDroppedInterest(const Face& egress, const Interest& interest)
+Forwarder::onDroppedInterest(const Interest& interest, Face& egress)
{
- m_strategyChoice.findEffectiveStrategy(interest.getName()).onDroppedInterest(egress, interest);
+ m_strategyChoice.findEffectiveStrategy(interest.getName()).onDroppedInterest(interest, egress);
}
void
diff --git a/daemon/fw/forwarder.hpp b/daemon/fw/forwarder.hpp
index 51e4dd0..6a245de 100644
--- a/daemon/fw/forwarder.hpp
+++ b/daemon/fw/forwarder.hpp
@@ -44,9 +44,10 @@
class Strategy;
} // namespace fw
-/** \brief Main class of NFD's forwarding engine.
+/**
+ * \brief Main class of NFD's forwarding engine.
*
- * Forwarder owns all tables and implements the forwarding pipelines.
+ * The Forwarder class owns all tables and implements the forwarding pipelines.
*/
class Forwarder
{
@@ -76,37 +77,6 @@
m_unsolicitedDataPolicy = std::move(policy);
}
-public: // forwarding entrypoints and tables
- /** \brief start incoming Interest processing
- * \param ingress face on which Interest is received and endpoint of the sender
- * \param interest the incoming Interest, must be well-formed and created with make_shared
- */
- void
- startProcessInterest(const FaceEndpoint& ingress, const Interest& interest)
- {
- this->onIncomingInterest(ingress, interest);
- }
-
- /** \brief start incoming Data processing
- * \param ingress face on which Data is received and endpoint of the sender
- * \param data the incoming Data, must be well-formed and created with make_shared
- */
- void
- startProcessData(const FaceEndpoint& ingress, const Data& data)
- {
- this->onIncomingData(ingress, data);
- }
-
- /** \brief start incoming Nack processing
- * \param ingress face on which Nack is received and endpoint of the sender
- * \param nack the incoming Nack, must be well-formed
- */
- void
- startProcessNack(const FaceEndpoint& ingress, const lp::Nack& nack)
- {
- this->onIncomingNack(ingress, nack);
- }
-
NameTree&
getNameTree()
{
@@ -157,33 +127,35 @@
NFD_PUBLIC_WITH_TESTS_ELSE_PRIVATE: // pipelines
/** \brief incoming Interest pipeline
+ * \param interest the incoming Interest, must be well-formed and created with make_shared
+ * \param ingress face on which \p interest was received and endpoint of the sender
*/
NFD_VIRTUAL_WITH_TESTS void
- onIncomingInterest(const FaceEndpoint& ingress, const Interest& interest);
+ onIncomingInterest(const Interest& interest, const FaceEndpoint& ingress);
/** \brief Interest loop pipeline
*/
NFD_VIRTUAL_WITH_TESTS void
- onInterestLoop(const FaceEndpoint& ingress, const Interest& interest);
+ onInterestLoop(const Interest& interest, const FaceEndpoint& ingress);
/** \brief Content Store miss pipeline
*/
NFD_VIRTUAL_WITH_TESTS void
- onContentStoreMiss(const FaceEndpoint& ingress,
- const shared_ptr<pit::Entry>& pitEntry, const Interest& interest);
+ onContentStoreMiss(const Interest& interest, const FaceEndpoint& ingress,
+ const shared_ptr<pit::Entry>& pitEntry);
/** \brief Content Store hit pipeline
*/
NFD_VIRTUAL_WITH_TESTS void
- onContentStoreHit(const FaceEndpoint& ingress, const shared_ptr<pit::Entry>& pitEntry,
- const Interest& interest, const Data& data);
+ onContentStoreHit(const Interest& interest, const FaceEndpoint& ingress,
+ const shared_ptr<pit::Entry>& pitEntry, const Data& data);
/** \brief outgoing Interest pipeline
* \return A pointer to the out-record created or nullptr if the Interest was dropped
*/
NFD_VIRTUAL_WITH_TESTS pit::OutRecord*
- onOutgoingInterest(const shared_ptr<pit::Entry>& pitEntry,
- Face& egress, const Interest& interest);
+ onOutgoingInterest(const Interest& interest, Face& egress,
+ const shared_ptr<pit::Entry>& pitEntry);
/** \brief Interest finalize pipeline
*/
@@ -191,14 +163,16 @@
onInterestFinalize(const shared_ptr<pit::Entry>& pitEntry);
/** \brief incoming Data pipeline
+ * \param data the incoming Data, must be well-formed and created with make_shared
+ * \param ingress face on which \p data was received and endpoint of the sender
*/
NFD_VIRTUAL_WITH_TESTS void
- onIncomingData(const FaceEndpoint& ingress, const Data& data);
+ onIncomingData(const Data& data, const FaceEndpoint& ingress);
/** \brief Data unsolicited pipeline
*/
NFD_VIRTUAL_WITH_TESTS void
- onDataUnsolicited(const FaceEndpoint& ingress, const Data& data);
+ onDataUnsolicited(const Data& data, const FaceEndpoint& ingress);
/** \brief outgoing Data pipeline
* \return Whether the Data was transmitted (true) or dropped (false)
@@ -207,19 +181,21 @@
onOutgoingData(const Data& data, Face& egress);
/** \brief incoming Nack pipeline
+ * \param nack the incoming Nack, must be well-formed
+ * \param ingress face on which \p nack is received and endpoint of the sender
*/
NFD_VIRTUAL_WITH_TESTS void
- onIncomingNack(const FaceEndpoint& ingress, const lp::Nack& nack);
+ onIncomingNack(const lp::Nack& nack, const FaceEndpoint& ingress);
/** \brief outgoing Nack pipeline
* \return Whether the Nack was transmitted (true) or dropped (false)
*/
NFD_VIRTUAL_WITH_TESTS bool
- onOutgoingNack(const shared_ptr<pit::Entry>& pitEntry,
- Face& egress, const lp::NackHeader& nack);
+ onOutgoingNack(const lp::NackHeader& nack, Face& egress,
+ const shared_ptr<pit::Entry>& pitEntry);
NFD_VIRTUAL_WITH_TESTS void
- onDroppedInterest(const Face& egress, const Interest& interest);
+ onDroppedInterest(const Interest& interest, Face& egress);
NFD_VIRTUAL_WITH_TESTS void
onNewNextHop(const Name& prefix, const fib::NextHop& nextHop);
diff --git a/daemon/fw/multicast-strategy.cpp b/daemon/fw/multicast-strategy.cpp
index 866b8ae..090a560 100644
--- a/daemon/fw/multicast-strategy.cpp
+++ b/daemon/fw/multicast-strategy.cpp
@@ -62,7 +62,7 @@
}
void
-MulticastStrategy::afterReceiveInterest(const FaceEndpoint& ingress, const Interest& interest,
+MulticastStrategy::afterReceiveInterest(const Interest& interest, const FaceEndpoint& ingress,
const shared_ptr<pit::Entry>& pitEntry)
{
const fib::Entry& fibEntry = this->lookupFib(*pitEntry);
@@ -83,7 +83,7 @@
}
NFD_LOG_DEBUG(interest << " from=" << ingress << " pitEntry-to=" << outFace.getId());
- auto* sentOutRecord = this->sendInterest(pitEntry, outFace, interest);
+ auto* sentOutRecord = this->sendInterest(interest, outFace, pitEntry);
if (sentOutRecord && suppressResult == RetxSuppressionResult::FORWARD) {
m_retxSuppression.incrementIntervalForOutRecord(*sentOutRecord);
}
@@ -105,7 +105,7 @@
if (isNextHopEligible(inFace, interest, nextHop, pitEntry)) {
NFD_LOG_DEBUG(interest << " from=" << inFace.getId() << " pitEntry-to=" << nextHopFaceId);
- this->sendInterest(pitEntry, nextHop.getFace(), interest);
+ this->sendInterest(interest, nextHop.getFace(), pitEntry);
break; // just one eligible incoming face record is enough
}
diff --git a/daemon/fw/multicast-strategy.hpp b/daemon/fw/multicast-strategy.hpp
index 7ef0080..fe122a4 100644
--- a/daemon/fw/multicast-strategy.hpp
+++ b/daemon/fw/multicast-strategy.hpp
@@ -43,8 +43,9 @@
static const Name&
getStrategyName();
+public: // triggers
void
- afterReceiveInterest(const FaceEndpoint& ingress, const Interest& interest,
+ afterReceiveInterest(const Interest& interest, const FaceEndpoint& ingress,
const shared_ptr<pit::Entry>& pitEntry) override;
void
diff --git a/daemon/fw/process-nack-traits.cpp b/daemon/fw/process-nack-traits.cpp
index ed599d9..80e5c40 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-2019, Regents of the University of California,
+ * Copyright (c) 2014-2021, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -32,7 +32,7 @@
NFD_LOG_INIT(ProcessNackTraits);
void
-ProcessNackTraitsBase::processNack(const Face& inFace, const lp::Nack& nack,
+ProcessNackTraitsBase::processNack(const lp::Nack& nack, const Face& inFace,
const shared_ptr<pit::Entry>& pitEntry)
{
int nOutRecordsNotNacked = 0;
@@ -56,7 +56,7 @@
if (nOutRecordsNotNacked == 1) {
BOOST_ASSERT(lastFaceNotNacked != nullptr);
- pit::InRecordCollection::iterator inR = pitEntry->getInRecord(*lastFaceNotNacked);
+ auto inR = pitEntry->getInRecord(*lastFaceNotNacked);
if (inR != pitEntry->in_end()) {
// one out-record not Nacked, which is also a downstream
NFD_LOG_DEBUG(nack.getInterest() << " nack-from=" << inFace.getId() <<
diff --git a/daemon/fw/process-nack-traits.hpp b/daemon/fw/process-nack-traits.hpp
index 654c896..c07537b 100644
--- a/daemon/fw/process-nack-traits.hpp
+++ b/daemon/fw/process-nack-traits.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2020, Regents of the University of California,
+ * Copyright (c) 2014-2021, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -31,7 +31,7 @@
namespace nfd {
namespace fw {
-/** \brief provides a common procedure for processing Nacks
+/** \brief Provides a common procedure for processing Nacks
*
* This procedure works as follows:
* 1. If Nacks have been received from all upstream faces, return a Nack with least severe reason
@@ -44,7 +44,7 @@
*
* To use this helper, the strategy should inherit from ProcessNackTraits<MyStrategy>,
* and declare that specialization as a friend class.
- * Then, invoke processNack from afterReceiveNack trigger.
+ * Then, invoke processNack() from the Strategy::afterReceiveNack() trigger.
*/
class ProcessNackTraitsBase : noncopyable
{
@@ -53,7 +53,7 @@
~ProcessNackTraitsBase() = default;
void
- processNack(const Face& inFace, const lp::Nack& nack,
+ processNack(const lp::Nack& nack, const Face& inFace,
const shared_ptr<pit::Entry>& pitEntry);
private:
@@ -81,14 +81,14 @@
sendNackForProcessNackTraits(const shared_ptr<pit::Entry>& pitEntry, Face& outFace,
const lp::NackHeader& header) override
{
- m_strategy->sendNack(pitEntry, outFace, header);
+ m_strategy->sendNack(header, outFace, pitEntry);
}
void
sendNacksForProcessNackTraits(const shared_ptr<pit::Entry>& pitEntry,
const lp::NackHeader& header) override
{
- m_strategy->sendNacks(pitEntry, header);
+ m_strategy->sendNacks(header, pitEntry);
}
private:
diff --git a/daemon/fw/random-strategy.cpp b/daemon/fw/random-strategy.cpp
index 96b2ae7..2ab24c9 100644
--- a/daemon/fw/random-strategy.cpp
+++ b/daemon/fw/random-strategy.cpp
@@ -57,7 +57,7 @@
}
void
-RandomStrategy::afterReceiveInterest(const FaceEndpoint& ingress, const Interest& interest,
+RandomStrategy::afterReceiveInterest(const Interest& interest, const FaceEndpoint& ingress,
const shared_ptr<pit::Entry>& pitEntry)
{
const fib::Entry& fibEntry = this->lookupFib(*pitEntry);
@@ -71,20 +71,20 @@
lp::NackHeader nackHeader;
nackHeader.setReason(lp::NackReason::NO_ROUTE);
- this->sendNack(pitEntry, ingress.face, nackHeader);
+ this->sendNack(nackHeader, ingress.face, pitEntry);
this->rejectPendingInterest(pitEntry);
return;
}
std::shuffle(nhs.begin(), nhs.end(), ndn::random::getRandomNumberEngine());
- this->sendInterest(pitEntry, nhs.front().getFace(), interest);
+ this->sendInterest(interest, nhs.front().getFace(), pitEntry);
}
void
-RandomStrategy::afterReceiveNack(const FaceEndpoint& ingress, const lp::Nack& nack,
+RandomStrategy::afterReceiveNack(const lp::Nack& nack, const FaceEndpoint& ingress,
const shared_ptr<pit::Entry>& pitEntry)
{
- this->processNack(ingress.face, nack, pitEntry);
+ this->processNack(nack, ingress.face, pitEntry);
}
} // namespace fw
diff --git a/daemon/fw/random-strategy.hpp b/daemon/fw/random-strategy.hpp
index 1aa170a..27b2041 100644
--- a/daemon/fw/random-strategy.hpp
+++ b/daemon/fw/random-strategy.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2020, Regents of the University of California,
+ * Copyright (c) 2014-2021, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -46,12 +46,13 @@
static const Name&
getStrategyName();
+public: // triggers
void
- afterReceiveInterest(const FaceEndpoint& ingress, const Interest& interest,
+ afterReceiveInterest(const Interest& interest, const FaceEndpoint& ingress,
const shared_ptr<pit::Entry>& pitEntry) override;
void
- afterReceiveNack(const FaceEndpoint& ingress, const lp::Nack& nack,
+ afterReceiveNack(const lp::Nack& nack, const FaceEndpoint& ingress,
const shared_ptr<pit::Entry>& pitEntry) override;
private:
diff --git a/daemon/fw/self-learning-strategy.cpp b/daemon/fw/self-learning-strategy.cpp
index 3a4fcbb..80630dc 100644
--- a/daemon/fw/self-learning-strategy.cpp
+++ b/daemon/fw/self-learning-strategy.cpp
@@ -66,7 +66,7 @@
}
void
-SelfLearningStrategy::afterReceiveInterest(const FaceEndpoint& ingress, const Interest& interest,
+SelfLearningStrategy::afterReceiveInterest(const Interest& interest, const FaceEndpoint& ingress,
const shared_ptr<pit::Entry>& pitEntry)
{
const fib::Entry& fibEntry = this->lookupFib(*pitEntry);
@@ -80,7 +80,7 @@
NFD_LOG_DEBUG("NACK non-discovery Interest=" << interest << " from=" << ingress << " noNextHop");
lp::NackHeader nackHeader;
nackHeader.setReason(lp::NackReason::NO_ROUTE);
- this->sendNack(pitEntry, ingress.face, nackHeader);
+ this->sendNack(nackHeader, ingress.face, pitEntry);
this->rejectPendingInterest(pitEntry);
}
else { // multicast it if matching FIB entry exists
@@ -100,8 +100,8 @@
}
void
-SelfLearningStrategy::afterReceiveData(const shared_ptr<pit::Entry>& pitEntry,
- const FaceEndpoint& ingress, const Data& data)
+SelfLearningStrategy::afterReceiveData(const Data& data, const FaceEndpoint& ingress,
+ const shared_ptr<pit::Entry>& pitEntry)
{
auto outRecord = pitEntry->getOutRecord(ingress.face);
if (outRecord == pitEntry->out_end()) {
@@ -112,7 +112,7 @@
OutRecordInfo* outRecordInfo = outRecord->getStrategyInfo<OutRecordInfo>();
if (outRecordInfo && outRecordInfo->isNonDiscoveryInterest) { // outgoing Interest was non-discovery
if (!needPrefixAnn(pitEntry)) { // no need to attach a PA (common cases)
- sendDataToAll(pitEntry, ingress.face, data);
+ sendDataToAll(data, pitEntry, ingress.face);
}
else { // needs a PA (to respond discovery Interest)
asyncProcessData(pitEntry, ingress.face, data);
@@ -125,12 +125,12 @@
}
else { // Data contains no PrefixAnnouncement, upstreams do not support self-learning
}
- sendDataToAll(pitEntry, ingress.face, data);
+ sendDataToAll(data, pitEntry, ingress.face);
}
}
void
-SelfLearningStrategy::afterReceiveNack(const FaceEndpoint& ingress, const lp::Nack& nack,
+SelfLearningStrategy::afterReceiveNack(const lp::Nack& nack, const FaceEndpoint& ingress,
const shared_ptr<pit::Entry>& pitEntry)
{
NFD_LOG_DEBUG("Nack for " << nack.getInterest() << " from=" << ingress
@@ -138,7 +138,7 @@
if (nack.getReason() == lp::NackReason::NO_ROUTE) { // remove FIB entries
BOOST_ASSERT(this->lookupFib(*pitEntry).hasNextHops());
NFD_LOG_DEBUG("Send NACK to all downstreams");
- this->sendNacks(pitEntry, nack.getHeader());
+ this->sendNacks(nack.getHeader(), pitEntry);
renewRoute(nack.getInterest().getName(), ingress.face.getId(), 0_ms);
}
}
@@ -156,7 +156,7 @@
NFD_LOG_DEBUG("send discovery Interest=" << interest << " from=" << inFace.getId() <<
" to=" << outFace.getId());
- auto outRecord = this->sendInterest(pitEntry, outFace, interest);
+ auto outRecord = this->sendInterest(interest, outFace, pitEntry);
if (outRecord != nullptr) {
outRecord->insertStrategyInfo<OutRecordInfo>().first->isNonDiscoveryInterest = false;
}
@@ -176,7 +176,7 @@
Face& outFace = nexthop.getFace();
NFD_LOG_DEBUG("send non-discovery Interest=" << interest << " from=" << inFace.getId() <<
" to=" << outFace.getId());
- auto outRecord = this->sendInterest(pitEntry, outFace, interest);
+ auto outRecord = this->sendInterest(interest, outFace, pitEntry);
if (outRecord != nullptr) {
outRecord->insertStrategyInfo<OutRecordInfo>().first->isNonDiscoveryInterest = true;
}
@@ -201,7 +201,7 @@
if (pitEntry && inFace) {
NFD_LOG_DEBUG("found PrefixAnnouncement=" << pa.getAnnouncedName());
data.setTag(make_shared<lp::PrefixAnnouncementTag>(lp::PrefixAnnouncementHeader(pa)));
- this->sendDataToAll(pitEntry, *inFace, data);
+ this->sendDataToAll(data, pitEntry, *inFace);
this->setExpiryTimer(pitEntry, 0_ms);
}
else {
diff --git a/daemon/fw/self-learning-strategy.hpp b/daemon/fw/self-learning-strategy.hpp
index 7ffefc2..bb4f6f7 100644
--- a/daemon/fw/self-learning-strategy.hpp
+++ b/daemon/fw/self-learning-strategy.hpp
@@ -79,19 +79,18 @@
public: // triggers
void
- afterReceiveInterest(const FaceEndpoint& ingress, const Interest& interest,
+ afterReceiveInterest(const Interest& interest, const FaceEndpoint& ingress,
const shared_ptr<pit::Entry>& pitEntry) override;
void
- afterReceiveData(const shared_ptr<pit::Entry>& pitEntry,
- const FaceEndpoint& ingress, const Data& data) override;
+ afterReceiveData(const Data& data, const FaceEndpoint& ingress,
+ const shared_ptr<pit::Entry>& pitEntry) override;
void
- afterReceiveNack(const FaceEndpoint& ingress, const lp::Nack& nack,
+ afterReceiveNack(const lp::Nack& nack, const FaceEndpoint& ingress,
const shared_ptr<pit::Entry>& pitEntry) override;
private: // operations
-
/** \brief Send an Interest to all possible faces
*
* This function is invoked when the forwarder has no matching FIB entries for
diff --git a/daemon/fw/strategy.cpp b/daemon/fw/strategy.cpp
index 3dc9abd..9cfb3be 100644
--- a/daemon/fw/strategy.cpp
+++ b/daemon/fw/strategy.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2020, Regents of the University of California,
+ * Copyright (c) 2014-2021, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -136,7 +136,7 @@
BOOST_ASSERT(strategyName.at(-1).isVersion());
bool hasVersion = std::any_of(input.rbegin(), input.rend(),
- [] (const name::Component& comp) { return comp.isVersion(); });
+ [] (const auto& comp) { return comp.isVersion(); });
return hasVersion ? input : Name(input).append(strategyName.at(-1));
}
@@ -151,59 +151,47 @@
Strategy::~Strategy() = default;
void
-Strategy::beforeSatisfyInterest(const shared_ptr<pit::Entry>& pitEntry,
- const FaceEndpoint& ingress, const Data& data)
+Strategy::afterContentStoreHit(const Data& data, const FaceEndpoint& ingress,
+ const shared_ptr<pit::Entry>& pitEntry)
+{
+ NFD_LOG_DEBUG("afterContentStoreHit pitEntry=" << pitEntry->getName()
+ << " in=" << ingress << " data=" << data.getName());
+
+ this->sendData(data, ingress.face, pitEntry);
+}
+
+void
+Strategy::beforeSatisfyInterest(const Data& data, const FaceEndpoint& ingress,
+ const shared_ptr<pit::Entry>& pitEntry)
{
NFD_LOG_DEBUG("beforeSatisfyInterest pitEntry=" << pitEntry->getName()
<< " in=" << ingress << " data=" << data.getName());
}
void
-Strategy::afterContentStoreHit(const shared_ptr<pit::Entry>& pitEntry,
- const FaceEndpoint& ingress, const Data& data)
-{
- NFD_LOG_DEBUG("afterContentStoreHit pitEntry=" << pitEntry->getName()
- << " in=" << ingress << " data=" << data.getName());
-
- this->sendData(pitEntry, data, ingress.face);
-}
-
-void
-Strategy::afterReceiveData(const shared_ptr<pit::Entry>& pitEntry,
- const FaceEndpoint& ingress, const Data& data)
+Strategy::afterReceiveData(const Data& data, const FaceEndpoint& ingress,
+ const shared_ptr<pit::Entry>& pitEntry)
{
NFD_LOG_DEBUG("afterReceiveData pitEntry=" << pitEntry->getName()
<< " in=" << ingress << " data=" << data.getName());
- this->beforeSatisfyInterest(pitEntry, ingress, data);
-
- this->sendDataToAll(pitEntry, ingress.face, data);
+ this->beforeSatisfyInterest(data, ingress, pitEntry);
+ this->sendDataToAll(data, pitEntry, ingress.face);
}
void
-Strategy::afterReceiveNack(const FaceEndpoint& ingress, const lp::Nack&,
+Strategy::afterReceiveNack(const lp::Nack&, const FaceEndpoint& ingress,
const shared_ptr<pit::Entry>& pitEntry)
{
NFD_LOG_DEBUG("afterReceiveNack in=" << ingress << " pitEntry=" << pitEntry->getName());
}
void
-Strategy::onDroppedInterest(const Face& egress, const Interest& interest)
+Strategy::onDroppedInterest(const Interest& interest, Face& egress)
{
NFD_LOG_DEBUG("onDroppedInterest out=" << egress.getId() << " name=" << interest.getName());
}
-pit::OutRecord*
-Strategy::sendInterest(const shared_ptr<pit::Entry>& pitEntry, Face& egress, const Interest& interest)
-{
- if (interest.getTag<lp::PitToken>() != nullptr) {
- Interest interest2 = interest; // make a copy to preserve tag on original packet
- interest2.removeTag<lp::PitToken>();
- return m_forwarder.onOutgoingInterest(pitEntry, egress, interest2);
- }
- return m_forwarder.onOutgoingInterest(pitEntry, egress, interest);
-}
-
void
Strategy::afterNewNextHop(const fib::NextHop& nextHop, const shared_ptr<pit::Entry>& pitEntry)
{
@@ -211,8 +199,19 @@
<< " nexthop=" << nextHop.getFace().getId());
}
+pit::OutRecord*
+Strategy::sendInterest(const Interest& interest, Face& egress, const shared_ptr<pit::Entry>& pitEntry)
+{
+ if (interest.getTag<lp::PitToken>() != nullptr) {
+ Interest interest2 = interest; // make a copy to preserve tag on original packet
+ interest2.removeTag<lp::PitToken>();
+ return m_forwarder.onOutgoingInterest(interest2, egress, pitEntry);
+ }
+ return m_forwarder.onOutgoingInterest(interest, egress, pitEntry);
+}
+
bool
-Strategy::sendData(const shared_ptr<pit::Entry>& pitEntry, const Data& data, Face& egress)
+Strategy::sendData(const Data& data, Face& egress, const shared_ptr<pit::Entry>& pitEntry)
{
BOOST_ASSERT(pitEntry->getInterest().matchesData(data));
@@ -235,14 +234,13 @@
}
void
-Strategy::sendDataToAll(const shared_ptr<pit::Entry>& pitEntry,
- const Face& inFace, const Data& data)
+Strategy::sendDataToAll(const Data& data, const shared_ptr<pit::Entry>& pitEntry, const Face& inFace)
{
std::set<Face*> pendingDownstreams;
auto now = time::steady_clock::now();
// remember pending downstreams
- for (const pit::InRecord& inRecord : pitEntry->getInRecords()) {
+ for (const auto& inRecord : pitEntry->getInRecords()) {
if (inRecord.getExpiry() > now) {
if (inRecord.getFace().getId() == inFace.getId() &&
inRecord.getFace().getLinkType() != ndn::nfd::LINK_TYPE_AD_HOC) {
@@ -253,27 +251,28 @@
}
for (const auto& pendingDownstream : pendingDownstreams) {
- this->sendData(pitEntry, data, *pendingDownstream);
+ this->sendData(data, *pendingDownstream, pitEntry);
}
}
void
-Strategy::sendNacks(const shared_ptr<pit::Entry>& pitEntry, const lp::NackHeader& header,
+Strategy::sendNacks(const lp::NackHeader& header, const shared_ptr<pit::Entry>& pitEntry,
std::initializer_list<const Face*> exceptFaces)
{
// populate downstreams with all downstreams faces
std::unordered_set<Face*> downstreams;
- std::transform(pitEntry->in_begin(), pitEntry->in_end(), std::inserter(downstreams, downstreams.end()),
- [] (const pit::InRecord& inR) { return &inR.getFace(); });
+ std::transform(pitEntry->in_begin(), pitEntry->in_end(),
+ std::inserter(downstreams, downstreams.end()),
+ [] (const auto& inR) { return &inR.getFace(); });
- // delete excluded faces
+ // remove excluded faces
for (auto exceptFace : exceptFaces) {
downstreams.erase(const_cast<Face*>(exceptFace));
}
// send Nacks
for (auto downstream : downstreams) {
- this->sendNack(pitEntry, *downstream, header);
+ this->sendNack(header, *downstream, pitEntry);
}
// warning: don't loop on pitEntry->getInRecords(), because in-record is deleted when sending Nack
}
diff --git a/daemon/fw/strategy.hpp b/daemon/fw/strategy.hpp
index 3c6536e..93a154b 100644
--- a/daemon/fw/strategy.hpp
+++ b/daemon/fw/strategy.hpp
@@ -32,7 +32,8 @@
namespace nfd {
namespace fw {
-/** \brief Represents a forwarding strategy
+/**
+ * \brief Represents a forwarding strategy
*/
class Strategy : noncopyable
{
@@ -115,169 +116,193 @@
}
public: // triggers
- /** \brief Trigger after Interest is received
+ /**
+ * \brief Trigger after an Interest is received.
*
- * The Interest:
+ * The Interest:
* - has not exceeded HopLimit
* - does not violate Scope
* - is not looped
* - cannot be satisfied by ContentStore
* - is under a namespace managed by this strategy
*
- * The PIT entry is set to expire after InterestLifetime has elapsed at each downstream.
+ * The PIT entry is set to expire after InterestLifetime has elapsed at each downstream.
*
- * The strategy should decide whether and where to forward this Interest.
+ * The strategy should decide whether and where to forward this Interest.
* - If the strategy decides to forward this Interest,
- * invoke \c sendInterest for each upstream, either now or shortly after via a scheduler event,
- * but before PIT entry expires.
- * Optionally, the strategy can invoke \c setExpiryTimer to adjust how long it would wait for a response.
- * - If the strategy has already forwarded this Interest previously and decides to continue waiting,
- * do nothing.
- * Optionally, the strategy can invoke \c setExpiryTimer to adjust how long it would wait for a response.
+ * invoke sendInterest() for each upstream, either now or shortly after via a scheduler event,
+ * but before the PIT entry expires.
+ * Optionally, the strategy can invoke setExpiryTimer() to adjust how long it would wait for a response.
+ * - If the strategy has already forwarded this Interest previously and decides to continue
+ * waiting, do nothing.
+ * Optionally, the strategy can invoke setExpiryTimer() to adjust how long it would wait for a response.
* - If the strategy concludes that this Interest cannot be satisfied,
- * invoke \c rejectPendingInterest to erase the PIT entry.
+ * invoke rejectPendingInterest() to erase the PIT entry.
*
- * \warning The strategy must not retain shared_ptr<pit::Entry>, otherwise undefined behavior
- * may occur. However, the strategy is allowed to store weak_ptr<pit::Entry>.
+ * \warning The strategy must not retain a copy of the \p pitEntry shared_ptr after this function
+ * returns, otherwise undefined behavior may occur. However, the strategy is allowed to
+ * construct and keep a weak_ptr to \p pitEntry.
*/
virtual void
- afterReceiveInterest(const FaceEndpoint& ingress, const Interest& interest,
+ afterReceiveInterest(const Interest& interest, const FaceEndpoint& ingress,
const shared_ptr<pit::Entry>& pitEntry) = 0;
- /** \brief Trigger before PIT entry is satisfied
+ /**
+ * \brief Trigger after a matching Data is found in the Content Store.
*
- * This trigger is invoked when an incoming Data satisfies more than one PIT entry.
- * The strategy can collect measurements information, but cannot manipulate Data forwarding.
- * When an incoming Data satisfies only one PIT entry, \c afterReceiveData is invoked instead
- * and given full control over Data forwarding. If a strategy does not override \c afterReceiveData,
- * the default implementation invokes \c beforeSatisfyInterest.
+ * In the base class, this method sends \p data to \p ingress.
*
- * Normally, PIT entries would be erased after receiving the first matching Data.
- * If the strategy wishes to collect responses from additional upstream nodes,
- * it should invoke \c setExpiryTimer within this function to prolong the PIT entry lifetime.
- * If a Data arrives from another upstream during the extended PIT entry lifetime, this trigger will be invoked again.
- * At that time, this function must invoke \c setExpiryTimer again to continue collecting more responses.
- *
- * In this base class this method does nothing.
- *
- * \warning The strategy must not retain shared_ptr<pit::Entry>, otherwise undefined behavior
- * may occur. However, the strategy is allowed to store weak_ptr<pit::Entry>.
+ * \warning The strategy must not retain a copy of the \p pitEntry shared_ptr after this function
+ * returns, otherwise undefined behavior may occur. However, the strategy is allowed to
+ * construct and keep a weak_ptr to \p pitEntry.
*/
virtual void
- beforeSatisfyInterest(const shared_ptr<pit::Entry>& pitEntry,
- const FaceEndpoint& ingress, const Data& data);
+ afterContentStoreHit(const Data& data, const FaceEndpoint& ingress,
+ const shared_ptr<pit::Entry>& pitEntry);
- /** \brief Trigger after a Data is matched in CS
+ /**
+ * \brief Trigger before a PIT entry is satisfied.
*
- * In the base class this method sends \p data to \p ingress
+ * This trigger is invoked when an incoming Data satisfies more than one PIT entry.
+ * The strategy can collect measurements information, but cannot manipulate Data forwarding.
+ * When an incoming Data satisfies only one PIT entry, afterReceiveData() is invoked instead
+ * and given full control over Data forwarding. If a strategy does not override afterReceiveData(),
+ * the default implementation invokes beforeSatisfyInterest().
+ *
+ * Normally, PIT entries are erased after receiving the first matching Data.
+ * If the strategy wishes to collect responses from additional upstream nodes,
+ * it should invoke setExpiryTimer() within this function to prolong the PIT entry lifetime.
+ * If a Data arrives from another upstream during the extended PIT entry lifetime, this trigger
+ * will be invoked again. At that time, the strategy must invoke setExpiryTimer() again to
+ * continue collecting more responses.
+ *
+ * In the base class, this method does nothing.
+ *
+ * \warning The strategy must not retain a copy of the \p pitEntry shared_ptr after this function
+ * returns, otherwise undefined behavior may occur. However, the strategy is allowed to
+ * construct and keep a weak_ptr to \p pitEntry.
*/
virtual void
- afterContentStoreHit(const shared_ptr<pit::Entry>& pitEntry,
- const FaceEndpoint& ingress, const Data& data);
+ beforeSatisfyInterest(const Data& data, const FaceEndpoint& ingress,
+ const shared_ptr<pit::Entry>& pitEntry);
- /** \brief Trigger after Data is received
+ /**
+ * \brief Trigger after Data is received.
*
- * This trigger is invoked when an incoming Data satisfies exactly one PIT entry,
- * and gives the strategy full control over Data forwarding.
+ * This trigger is invoked when an incoming Data satisfies exactly one PIT entry,
+ * and gives the strategy full control over Data forwarding.
*
- * When this trigger is invoked:
+ * When this trigger is invoked:
* - The Data has been verified to satisfy the PIT entry.
* - The PIT entry expiry timer is set to now
*
- * Within this function:
- * - A strategy should return Data to downstream nodes via \c sendData or \c sendDataToAll.
+ * Inside this function:
+ * - A strategy should return Data to downstream nodes via sendData() or sendDataToAll().
* - A strategy can modify the Data as long as it still satisfies the PIT entry, such as
* adding or removing congestion marks.
- * - A strategy can delay Data forwarding by prolonging the PIT entry lifetime via \c setExpiryTimer,
- * and forward Data before the PIT entry is erased.
+ * - A strategy can delay Data forwarding by prolonging the PIT entry lifetime via setExpiryTimer(),
+ * and later forward the Data before the PIT entry is erased.
* - A strategy can collect measurements about the upstream.
* - A strategy can collect responses from additional upstream nodes by prolonging the PIT entry
- * lifetime via \c setExpiryTimer every time a Data is received. Note that only one Data should
+ * lifetime via setExpiryTimer() every time a Data is received. Note that only one Data should
* be returned to each downstream node.
*
- * In the base class this method invokes \c beforeSatisfyInterest trigger and then returns
- * the Data to downstream faces via \c sendDataToAll.
+ * In the base class, this method invokes beforeSatisfyInterest() and then returns the Data
+ * to all downstream faces via sendDataToAll().
+ *
+ * \warning The strategy must not retain a copy of the \p pitEntry shared_ptr after this function
+ * returns, otherwise undefined behavior may occur. However, the strategy is allowed to
+ * construct and keep a weak_ptr to \p pitEntry.
*/
virtual void
- afterReceiveData(const shared_ptr<pit::Entry>& pitEntry,
- const FaceEndpoint& ingress, const Data& data);
-
- /** \brief Trigger after Nack is received
- *
- * This trigger is invoked when an incoming Nack is received in response to
- * an forwarded Interest.
- * The Nack has been confirmed to be a response to the last Interest forwarded
- * to that upstream, i.e. the PIT out-record exists and has a matching Nonce.
- * The NackHeader has been recorded in the PIT out-record.
- *
- * If the PIT entry is not yet satisfied, its expiry timer remains unchanged.
- * Otherwise, the PIT entry normally would expire immediately after this function returns.
- *
- * If the strategy wishes to collect responses from additional upstream nodes,
- * it should invoke \c setExpiryTimer within this function to retain the PIT entry.
- * If a Nack arrives from another upstream during the extended PIT entry lifetime, this trigger will be invoked again.
- * At that time, this function must invoke \c setExpiryTimer again to continue collecting more responses.
- *
- * In the base class this method does nothing.
- *
- * \warning The strategy must not retain shared_ptr<pit::Entry>, otherwise undefined behavior
- * may occur. However, the strategy is allowed to store weak_ptr<pit::Entry>.
- */
- virtual void
- afterReceiveNack(const FaceEndpoint& ingress, const lp::Nack& nack,
+ afterReceiveData(const Data& data, const FaceEndpoint& ingress,
const shared_ptr<pit::Entry>& pitEntry);
- /** \brief Trigger after Interest dropped (e.g., for exceeding allowed retransmissions)
+ /**
+ * \brief Trigger after a Nack is received.
*
- * In the base class this method does nothing.
+ * This trigger is invoked when an incoming Nack is received in response to
+ * an forwarded Interest.
+ * The Nack has been confirmed to be a response to the last Interest forwarded
+ * to that upstream, i.e. the PIT out-record exists and has a matching Nonce.
+ * The NackHeader has been recorded in the PIT out-record.
+ *
+ * If the PIT entry is not yet satisfied, its expiry timer remains unchanged.
+ * Otherwise, the PIT entry will normally expire immediately after this function returns.
+ *
+ * If the strategy wishes to collect responses from additional upstream nodes,
+ * it should invoke setExpiryTimer() within this function to prolong the PIT entry lifetime.
+ * If a Nack arrives from another upstream during the extended PIT entry lifetime, this trigger
+ * will be invoked again. At that time, the strategy must invoke setExpiryTimer() again to
+ * continue collecting more responses.
+ *
+ * In the base class, this method does nothing.
+ *
+ * \warning The strategy must not retain a copy of the \p pitEntry shared_ptr after this function
+ * returns, otherwise undefined behavior may occur. However, the strategy is allowed to
+ * construct and keep a weak_ptr to \p pitEntry.
*/
virtual void
- onDroppedInterest(const Face& egress, const Interest& interest);
+ afterReceiveNack(const lp::Nack& nack, const FaceEndpoint& ingress,
+ const shared_ptr<pit::Entry>& pitEntry);
- /** \brief Trigger after new nexthop is added
+ /**
+ * \brief Trigger after an Interest is dropped (e.g., for exceeding allowed retransmissions).
*
- * The strategy should decide whether to send the buffered Interests to the new nexthop.
- * In the base class, this method does nothing.
+ * In the base class, this method does nothing.
+ */
+ virtual void
+ onDroppedInterest(const Interest& interest, Face& egress);
+
+ /**
+ * \brief Trigger after a new nexthop is added.
+ *
+ * The strategy should decide whether to send the buffered Interests to the new nexthop.
+ *
+ * In the base class, this method does nothing.
*/
virtual void
afterNewNextHop(const fib::NextHop& nextHop, const shared_ptr<pit::Entry>& pitEntry);
protected: // actions
- /** \brief Send an Interest packet.
- * \param pitEntry the PIT entry
- * \param egress face through which to send out the Interest
- * \param interest the Interest packet
- * \return A pointer to the out-record created or nullptr if the Interest was dropped
+ /**
+ * \brief Send an Interest packet.
+ * \param interest the Interest packet
+ * \param egress face through which to send out the Interest
+ * \param pitEntry the PIT entry
+ * \return A pointer to the out-record created or nullptr if the Interest was dropped
*/
NFD_VIRTUAL_WITH_TESTS pit::OutRecord*
- sendInterest(const shared_ptr<pit::Entry>& pitEntry, Face& egress,
- const Interest& interest);
+ sendInterest(const Interest& interest, Face& egress, const shared_ptr<pit::Entry>& pitEntry);
- /** \brief Send a Data packet.
- * \param pitEntry the PIT entry
- * \param data the Data packet
- * \param egress face through which to send out the Data
- * \return Whether the Data was sent (true) or dropped (false)
+ /**
+ * \brief Send a Data packet.
+ * \param data the Data packet
+ * \param egress face through which to send out the Data
+ * \param pitEntry the PIT entry
+ * \return Whether the Data was sent (true) or dropped (false)
*/
NFD_VIRTUAL_WITH_TESTS bool
- sendData(const shared_ptr<pit::Entry>& pitEntry, const Data& data, Face& egress);
+ sendData(const Data& data, Face& egress, const shared_ptr<pit::Entry>& pitEntry);
- /** \brief Send a Data packet to all matched and qualified faces.
+ /**
+ * \brief Send a Data packet to all matched and qualified faces.
*
- * A matched face is qualified if it is ad-hoc or it is NOT \p inFace.
+ * A matched face qualifies if it is ad-hoc OR it is NOT \p inFace.
*
- * \param pitEntry the PIT entry
- * \param inFace face on which the Data arrived
- * \param data the Data packet
+ * \param data the Data packet
+ * \param pitEntry the PIT entry
+ * \param inFace face on which the Data arrived
*/
NFD_VIRTUAL_WITH_TESTS void
- sendDataToAll(const shared_ptr<pit::Entry>& pitEntry, const Face& inFace, const Data& data);
+ sendDataToAll(const Data& data, const shared_ptr<pit::Entry>& pitEntry, const Face& inFace);
- /** \brief Schedule the PIT entry for immediate deletion.
+ /**
+ * \brief Schedule the PIT entry for immediate deletion.
*
- * This helper function sets the PIT entry expiry time to zero.
- * The strategy should invoke this function when it concludes that the Interest cannot
- * be forwarded and it does not want to wait for responses from existing upstream nodes.
+ * This helper function sets the PIT entry expiry time to zero.
+ * The strategy should invoke this function when it concludes that the Interest cannot
+ * be forwarded and it does not want to wait for responses from existing upstream nodes.
*/
NFD_VIRTUAL_WITH_TESTS void
rejectPendingInterest(const shared_ptr<pit::Entry>& pitEntry)
@@ -285,33 +310,35 @@
this->setExpiryTimer(pitEntry, 0_ms);
}
- /** \brief Send a Nack packet.
+ /**
+ * \brief Send a Nack packet.
*
- * The egress face must have a PIT in-record, otherwise this method has no effect.
+ * The egress face must have a PIT in-record, otherwise this method has no effect.
*
- * \param pitEntry the PIT entry
- * \param egress face through which to send out the Nack
- * \param header the Nack header
- * \return Whether the Nack was sent (true) or dropped (false)
+ * \param header the Nack header
+ * \param egress face through which to send out the Nack
+ * \param pitEntry the PIT entry
+ * \return Whether the Nack was sent (true) or dropped (false)
*/
NFD_VIRTUAL_WITH_TESTS bool
- sendNack(const shared_ptr<pit::Entry>& pitEntry, Face& egress,
- const lp::NackHeader& header)
+ sendNack(const lp::NackHeader& header, Face& egress, const shared_ptr<pit::Entry>& pitEntry)
{
- return m_forwarder.onOutgoingNack(pitEntry, egress, header);
+ return m_forwarder.onOutgoingNack(header, egress, pitEntry);
}
- /** \brief Send Nack to every face that has an in-record, except those in \p exceptFaces
- * \param pitEntry the PIT entry
- * \param header the Nack header
- * \param exceptFaces list of faces that should be excluded from sending Nacks
- * \note This is not an action, but a helper that invokes the sendNack() action.
+ /**
+ * \brief Send Nack to every face that has an in-record, except those in \p exceptFaces
+ * \param header the Nack header
+ * \param pitEntry the PIT entry
+ * \param exceptFaces list of faces that should be excluded from sending Nacks
+ * \note This is not an action, but a helper that invokes the sendNack() action.
*/
void
- sendNacks(const shared_ptr<pit::Entry>& pitEntry, const lp::NackHeader& header,
+ sendNacks(const lp::NackHeader& header, const shared_ptr<pit::Entry>& pitEntry,
std::initializer_list<const Face*> exceptFaces = {});
- /** \brief Schedule the PIT entry to be erased after \p duration.
+ /**
+ * \brief Schedule the PIT entry to be erased after \p duration.
*/
void
setExpiryTimer(const shared_ptr<pit::Entry>& pitEntry, time::milliseconds duration)
@@ -320,7 +347,8 @@
}
protected: // accessors
- /** \brief Performs a FIB lookup, considering Link object if present.
+ /**
+ * \brief Performs a FIB lookup, considering Link object if present.
*/
const fib::Entry&
lookupFib(const pit::Entry& pitEntry) const;
@@ -381,8 +409,8 @@
}
private: // registry
- typedef std::function<unique_ptr<Strategy>(Forwarder& forwarder, const Name& strategyName)> CreateFunc;
- typedef std::map<Name, CreateFunc> Registry; // indexed by strategy name
+ using CreateFunc = std::function<unique_ptr<Strategy>(Forwarder&, const Name& /*strategyName*/)>;
+ using Registry = std::map<Name, CreateFunc>; // indexed by strategy name
static Registry&
getRegistry();
@@ -396,13 +424,7 @@
private: // instance fields
Name m_name;
-
- /** \brief Reference to the forwarder
- *
- * Triggers can access forwarder indirectly via actions.
- */
Forwarder& m_forwarder;
-
MeasurementsAccessor m_measurements;
};