table: don't use shared_ptr in FIB
refs #3164
Change-Id: I5b5eb47d60f6bf5b6389c32ac840f793767e4334
diff --git a/daemon/fw/access-strategy.cpp b/daemon/fw/access-strategy.cpp
index db8a192..204aaaa 100644
--- a/daemon/fw/access-strategy.cpp
+++ b/daemon/fw/access-strategy.cpp
@@ -126,7 +126,7 @@
}
shared_ptr<Face> face = this->getFace(mi.lastNexthop);
- if (face == nullptr || !fibEntry.hasNextHop(face)) {
+ if (face == nullptr || !fibEntry.hasNextHop(*face)) {
NFD_LOG_DEBUG(pitEntry->getInterest() << " last-nexthop-gone");
return false;
}
@@ -140,7 +140,7 @@
NFD_LOG_DEBUG(pitEntry->getInterest() << " interestTo " << mi.lastNexthop <<
" last-nexthop rto=" << time::duration_cast<time::microseconds>(rto).count());
- this->sendInterest(pitEntry, face);
+ this->sendInterest(pitEntry, *face);
// schedule RTO timeout
shared_ptr<PitInfo> pi = pitEntry->getOrCreateStrategyInfo<PitInfo>();
@@ -171,11 +171,11 @@
std::unordered_set<FaceId> exceptFaces)
{
for (const fib::NextHop& nexthop : fibEntry.getNextHops()) {
- shared_ptr<Face> face = nexthop.getFace();
- if (exceptFaces.count(face->getId()) > 0) {
+ Face& face = nexthop.getFace();
+ if (exceptFaces.count(face.getId()) > 0) {
continue;
}
- NFD_LOG_DEBUG(pitEntry->getInterest() << " interestTo " << face->getId() <<
+ NFD_LOG_DEBUG(pitEntry->getInterest() << " interestTo " << face.getId() <<
" multicast");
this->sendInterest(pitEntry, face);
}
diff --git a/daemon/fw/asf-probing-module.cpp b/daemon/fw/asf-probing-module.cpp
index f561b52..097a372 100644
--- a/daemon/fw/asf-probing-module.cpp
+++ b/daemon/fw/asf-probing-module.cpp
@@ -64,7 +64,7 @@
});
}
-shared_ptr<Face>
+Face*
ProbingModule::getFaceToProbe(const Face& inFace,
const Interest& interest,
const fib::Entry& fibEntry,
@@ -84,23 +84,23 @@
// Put eligible faces into rankedFaces. If a face does not have an RTT measurement,
// immediately pick the face for probing
for (const fib::NextHop& hop : fibEntry.getNextHops()) {
- const shared_ptr<Face>& hopFace = hop.getFace();
+ Face& hopFace = hop.getFace();
// Don't send probe Interest back to the incoming face or use the same face
// as the forwarded Interest
- if (hopFace->getId() == inFace.getId() || hopFace->getId() == faceUsed.getId()) {
+ if (hopFace.getId() == inFace.getId() || hopFace.getId() == faceUsed.getId()) {
continue;
}
- FaceInfo* info = m_measurements.getFaceInfo(fibEntry, interest, *hopFace);
+ FaceInfo* info = m_measurements.getFaceInfo(fibEntry, interest, hopFace);
// If no RTT has been recorded, probe this face
if (info == nullptr || !info->hasSrttMeasurement()) {
- return hopFace;
+ return &hopFace;
}
// Add FaceInfo to container sorted by RTT
- rankedFaces.insert(std::make_pair(info, hopFace));
+ rankedFaces.insert(std::make_pair(info, &hopFace));
}
if (rankedFaces.empty()) {
@@ -140,7 +140,7 @@
scheduleProbe(fibEntry, m_probingInterval);
}
-shared_ptr<Face>
+Face*
ProbingModule::getFaceBasedOnProbability(const FaceInfoFacePairSet& rankedFaces)
{
double randomNumber = getRandomNumber(0, 1);
diff --git a/daemon/fw/asf-probing-module.hpp b/daemon/fw/asf-probing-module.hpp
index 585b76a..3a4df6e 100644
--- a/daemon/fw/asf-probing-module.hpp
+++ b/daemon/fw/asf-probing-module.hpp
@@ -43,7 +43,7 @@
void
scheduleProbe(const fib::Entry& fibEntry, const time::milliseconds& interval);
- shared_ptr<Face>
+ Face*
getFaceToProbe(const Face& inFace,
const Interest& interest,
const fib::Entry& fibEntry,
@@ -57,11 +57,11 @@
private:
// Used to associate FaceInfo with the face in a NextHop
- typedef std::pair<FaceInfo*, shared_ptr<Face>> FaceInfoFacePair;
+ typedef std::pair<FaceInfo*, Face*> FaceInfoFacePair;
typedef std::function<bool(FaceInfoFacePair, FaceInfoFacePair)> FaceInfoPredicate;
typedef std::set<FaceInfoFacePair, FaceInfoPredicate> FaceInfoFacePairSet;
- shared_ptr<Face>
+ Face*
getFaceBasedOnProbability(const FaceInfoFacePairSet& rankedFaces);
double
diff --git a/daemon/fw/asf-strategy.cpp b/daemon/fw/asf-strategy.cpp
index cf616e8..3f8abf7 100644
--- a/daemon/fw/asf-strategy.cpp
+++ b/daemon/fw/asf-strategy.cpp
@@ -79,7 +79,7 @@
return;
}
- const shared_ptr<Face> faceToUse = getBestFaceForForwarding(fibEntry, interest, inFace);
+ Face* faceToUse = getBestFaceForForwarding(fibEntry, interest, inFace);
if (faceToUse == nullptr) {
sendNoRouteNack(inFace, interest, pitEntry);
@@ -87,18 +87,18 @@
return;
}
- forwardInterest(interest, fibEntry, pitEntry, faceToUse);
+ forwardInterest(interest, fibEntry, pitEntry, *faceToUse);
// If necessary, send probe
if (m_probing.isProbingNeeded(fibEntry, interest)) {
- shared_ptr<Face> faceToProbe = m_probing.getFaceToProbe(inFace, interest, fibEntry, *faceToUse);
+ Face* faceToProbe = m_probing.getFaceToProbe(inFace, interest, fibEntry, *faceToUse);
if (faceToProbe != nullptr) {
NFD_LOG_TRACE("Sending probe for " << fibEntry.getPrefix()
<< " to FaceId: " << faceToProbe->getId());
bool wantNewNonce = true;
- forwardInterest(interest, fibEntry, pitEntry, faceToProbe, wantNewNonce);
+ forwardInterest(interest, fibEntry, pitEntry, *faceToProbe, wantNewNonce);
m_probing.afterForwardingProbe(fibEntry, interest);
}
}
@@ -143,27 +143,27 @@
AsfStrategy::forwardInterest(const Interest& interest,
const fib::Entry& fibEntry,
shared_ptr<pit::Entry> pitEntry,
- shared_ptr<Face> outFace,
+ Face& outFace,
bool wantNewNonce)
{
this->sendInterest(pitEntry, outFace, wantNewNonce);
- FaceInfo& faceInfo = m_measurements.getOrCreateFaceInfo(fibEntry, interest, *outFace);
+ FaceInfo& faceInfo = m_measurements.getOrCreateFaceInfo(fibEntry, interest, outFace);
// Refresh measurements since Face is being used for forwarding
NamespaceInfo& namespaceInfo = m_measurements.getOrCreateNamespaceInfo(fibEntry, interest);
- namespaceInfo.extendFaceInfoLifetime(faceInfo, *outFace);
+ namespaceInfo.extendFaceInfoLifetime(faceInfo, outFace);
if (!faceInfo.isTimeoutScheduled()) {
// Estimate and schedule timeout
RttEstimator::Duration timeout = faceInfo.computeRto();
NFD_LOG_TRACE("Scheduling timeout for " << fibEntry.getPrefix()
- << " FaceId: " << outFace->getId()
+ << " FaceId: " << outFace.getId()
<< " in " << time::duration_cast<time::milliseconds>(timeout) << " ms");
scheduler::EventId id = scheduler::schedule(timeout,
- bind(&AsfStrategy::onTimeout, this, interest.getName(), outFace->getId()));
+ bind(&AsfStrategy::onTimeout, this, interest.getName(), outFace.getId()));
faceInfo.setTimeoutEvent(id, interest.getName());
}
@@ -171,7 +171,7 @@
struct FaceStats
{
- shared_ptr<Face> face;
+ Face* face;
RttStats::Rtt rtt;
RttStats::Rtt srtt;
uint64_t cost;
@@ -196,7 +196,7 @@
}
}
-const shared_ptr<Face>
+Face*
AsfStrategy::getBestFaceForForwarding(const fib::Entry& fibEntry, const ndn::Interest& interest, const Face& inFace)
{
NFD_LOG_TRACE("Looking for best face for " << fibEntry.getPrefix());
@@ -222,17 +222,16 @@
});
for (const fib::NextHop& hop : fibEntry.getNextHops()) {
+ Face& hopFace = hop.getFace();
- const shared_ptr<Face>& hopFace = hop.getFace();
-
- if (hopFace->getId() == inFace.getId()) {
+ if (hopFace.getId() == inFace.getId()) {
continue;
}
- FaceInfo* info = m_measurements.getFaceInfo(fibEntry, interest, *hopFace);
+ FaceInfo* info = m_measurements.getFaceInfo(fibEntry, interest, hopFace);
if (info == nullptr) {
- FaceStats stats = {hopFace,
+ FaceStats stats = {&hopFace,
RttStats::RTT_NO_MEASUREMENT,
RttStats::RTT_NO_MEASUREMENT,
hop.getCost()};
@@ -240,7 +239,7 @@
rankedFaces.insert(stats);
}
else {
- FaceStats stats = {hopFace, info->getRtt(), info->getSrtt(), hop.getCost()};
+ FaceStats stats = {&hopFace, info->getRtt(), info->getSrtt(), hop.getCost()};
rankedFaces.insert(stats);
}
}
diff --git a/daemon/fw/asf-strategy.hpp b/daemon/fw/asf-strategy.hpp
index cb50e01..ad00a3d 100644
--- a/daemon/fw/asf-strategy.hpp
+++ b/daemon/fw/asf-strategy.hpp
@@ -69,10 +69,10 @@
forwardInterest(const Interest& interest,
const fib::Entry& fibEntry,
shared_ptr<pit::Entry> pitEntry,
- shared_ptr<Face> outFace,
+ Face& outFace,
bool wantNewNonce = false);
- const shared_ptr<Face>
+ Face*
getBestFaceForForwarding(const fib::Entry& fibEntry, const ndn::Interest& interest, const Face& inFace);
void
diff --git a/daemon/fw/best-route-strategy.cpp b/daemon/fw/best-route-strategy.cpp
index bae5262..b97afca 100644
--- a/daemon/fw/best-route-strategy.cpp
+++ b/daemon/fw/best-route-strategy.cpp
@@ -54,14 +54,14 @@
const fib::Entry& fibEntry = this->lookupFib(*pitEntry);
const fib::NextHopList& nexthops = fibEntry.getNextHops();
fib::NextHopList::const_iterator it = std::find_if(nexthops.begin(), nexthops.end(),
- [&pitEntry] (const fib::NextHop& nexthop) { return canForwardToLegacy(*pitEntry, *nexthop.getFace()); });
+ [&pitEntry] (const fib::NextHop& nexthop) { return canForwardToLegacy(*pitEntry, nexthop.getFace()); });
if (it == nexthops.end()) {
this->rejectPendingInterest(pitEntry);
return;
}
- shared_ptr<Face> outFace = it->getFace();
+ Face& outFace = it->getFace();
this->sendInterest(pitEntry, outFace);
}
diff --git a/daemon/fw/best-route-strategy2.cpp b/daemon/fw/best-route-strategy2.cpp
index ef68175..df6ca4d 100644
--- a/daemon/fw/best-route-strategy2.cpp
+++ b/daemon/fw/best-route-strategy2.cpp
@@ -59,19 +59,19 @@
bool wantUnused = false,
time::steady_clock::TimePoint now = time::steady_clock::TimePoint::min())
{
- shared_ptr<Face> upstream = nexthop.getFace();
+ Face& upstream = nexthop.getFace();
// upstream is current downstream
- if (upstream->getId() == currentDownstream)
+ if (upstream.getId() == currentDownstream)
return false;
// forwarding would violate scope
- if (violatesScope(*pitEntry, *upstream))
+ if (violatesScope(*pitEntry, upstream))
return false;
if (wantUnused) {
// NextHop must not have unexpired out-record
- pit::OutRecordCollection::iterator outRecord = pitEntry->getOutRecord(*upstream);
+ pit::OutRecordCollection::iterator outRecord = pitEntry->getOutRecord(upstream);
if (outRecord != pitEntry->out_end() && outRecord->getExpiry() > now) {
return false;
}
@@ -93,7 +93,7 @@
for (fib::NextHopList::const_iterator it = nexthops.begin(); it != nexthops.end(); ++it) {
if (!predicate_NextHop_eligible(pitEntry, *it, currentDownstream))
continue;
- pit::OutRecordCollection::iterator outRecord = pitEntry->getOutRecord(*it->getFace());
+ pit::OutRecordCollection::iterator outRecord = pitEntry->getOutRecord(it->getFace());
BOOST_ASSERT(outRecord != pitEntry->out_end());
if (outRecord->getLastRenewed() < earliestRenewed) {
found = it;
@@ -136,10 +136,10 @@
return;
}
- shared_ptr<Face> outFace = it->getFace();
+ Face& outFace = it->getFace();
this->sendInterest(pitEntry, outFace);
NFD_LOG_DEBUG(interest << " from=" << inFace.getId()
- << " newPitEntry-to=" << outFace->getId());
+ << " newPitEntry-to=" << outFace.getId());
return;
}
@@ -148,10 +148,10 @@
bind(&predicate_NextHop_eligible, pitEntry, _1, inFace.getId(),
true, time::steady_clock::now()));
if (it != nexthops.end()) {
- shared_ptr<Face> outFace = it->getFace();
+ Face& outFace = it->getFace();
this->sendInterest(pitEntry, outFace);
NFD_LOG_DEBUG(interest << " from=" << inFace.getId()
- << " retransmit-unused-to=" << outFace->getId());
+ << " retransmit-unused-to=" << outFace.getId());
return;
}
@@ -161,10 +161,10 @@
NFD_LOG_DEBUG(interest << " from=" << inFace.getId() << " retransmitNoNextHop");
}
else {
- shared_ptr<Face> outFace = it->getFace();
+ Face& outFace = it->getFace();
this->sendInterest(pitEntry, outFace);
NFD_LOG_DEBUG(interest << " from=" << inFace.getId()
- << " retransmit-retry-to=" << outFace->getId());
+ << " retransmit-retry-to=" << outFace.getId());
}
}
diff --git a/daemon/fw/best-route-strategy2.hpp b/daemon/fw/best-route-strategy2.hpp
index 8c6a778..d78baf6 100644
--- a/daemon/fw/best-route-strategy2.hpp
+++ b/daemon/fw/best-route-strategy2.hpp
@@ -56,10 +56,12 @@
virtual void
afterReceiveInterest(const Face& inFace, const Interest& interest,
+
shared_ptr<pit::Entry> pitEntry) override;
virtual void
afterReceiveNack(const Face& inFace, const lp::Nack& nack,
+
shared_ptr<pit::Entry> pitEntry) override;
public:
diff --git a/daemon/fw/client-control-strategy.cpp b/daemon/fw/client-control-strategy.cpp
index 044e065..a73291b 100644
--- a/daemon/fw/client-control-strategy.cpp
+++ b/daemon/fw/client-control-strategy.cpp
@@ -66,7 +66,7 @@
return;
}
- this->sendInterest(pitEntry, outFace);
+ this->sendInterest(pitEntry, *outFace);
}
} // namespace fw
diff --git a/daemon/fw/face-table.cpp b/daemon/fw/face-table.cpp
index b4bda23..4cda948 100644
--- a/daemon/fw/face-table.cpp
+++ b/daemon/fw/face-table.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, Regents of the University of California,
+ * Copyright (c) 2014-2016, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -108,7 +108,7 @@
" remote=" << face->getRemoteUri() <<
" local=" << face->getLocalUri());
- m_forwarder.getFib().removeNextHopFromAllEntries(face);
+ m_forwarder.getFib().removeNextHopFromAllEntries(*face);
// defer Face deallocation, so that Transport isn't deallocated during afterStateChange signal
getGlobalIoService().post([face] {});
diff --git a/daemon/fw/forwarder.cpp b/daemon/fw/forwarder.cpp
index 3bb580d..0b4c653 100644
--- a/daemon/fw/forwarder.cpp
+++ b/daemon/fw/forwarder.cpp
@@ -522,7 +522,7 @@
// has Link object?
if (!interest.hasLink()) {
// FIB lookup with Interest name
- const fib::Entry& fibEntry = *m_fib.findLongestPrefixMatch(pitEntry);
+ const fib::Entry& fibEntry = m_fib.findLongestPrefixMatch(pitEntry);
NFD_LOG_TRACE("lookupFib noLinkObject found=" << fibEntry.getPrefix());
return fibEntry;
}
@@ -532,7 +532,7 @@
// in producer region?
if (m_networkRegionTable.isInProducerRegion(link)) {
// FIB lookup with Interest name
- const fib::Entry& fibEntry = *m_fib.findLongestPrefixMatch(pitEntry);
+ const fib::Entry& fibEntry = m_fib.findLongestPrefixMatch(pitEntry);
NFD_LOG_TRACE("lookupFib inProducerRegion found=" << fibEntry.getPrefix());
return fibEntry;
}
@@ -541,13 +541,13 @@
if (interest.hasSelectedDelegation()) {
// FIB lookup with SelectedDelegation
Name selectedDelegation = interest.getSelectedDelegation();
- const fib::Entry& fibEntry = *m_fib.findLongestPrefixMatch(selectedDelegation);
+ const fib::Entry& fibEntry = m_fib.findLongestPrefixMatch(selectedDelegation);
NFD_LOG_TRACE("lookupFib hasSelectedDelegation=" << selectedDelegation << " found=" << fibEntry.getPrefix());
return fibEntry;
}
// FIB lookup with first delegation Name
- const fib::Entry& fibEntry0 = *m_fib.findLongestPrefixMatch(link.getDelegations().begin()->second);
+ const fib::Entry& fibEntry0 = m_fib.findLongestPrefixMatch(link.getDelegations().begin()->second);
// in default-free zone?
bool isDefaultFreeZone = !(fibEntry0.getPrefix().size() == 0 && fibEntry0.hasNextHops());
if (!isDefaultFreeZone) {
@@ -558,7 +558,7 @@
// choose and set SelectedDelegation
for (const std::pair<uint32_t, Name>& delegation : link.getDelegations()) {
const Name& delegationName = delegation.second;
- const fib::Entry& fibEntry = *m_fib.findLongestPrefixMatch(delegationName);
+ const fib::Entry& fibEntry = m_fib.findLongestPrefixMatch(delegationName);
if (fibEntry.hasNextHops()) {
/// \todo Don't modify in-record Interests.
/// Set SelectedDelegation in outgoing Interest pipeline.
diff --git a/daemon/fw/multicast-strategy.cpp b/daemon/fw/multicast-strategy.cpp
index 9b89049..5373d03 100644
--- a/daemon/fw/multicast-strategy.cpp
+++ b/daemon/fw/multicast-strategy.cpp
@@ -46,8 +46,8 @@
const fib::NextHopList& nexthops = fibEntry.getNextHops();
for (fib::NextHopList::const_iterator it = nexthops.begin(); it != nexthops.end(); ++it) {
- shared_ptr<Face> outFace = it->getFace();
- if (canForwardToLegacy(*pitEntry, *outFace)) {
+ Face& outFace = it->getFace();
+ if (canForwardToLegacy(*pitEntry, outFace)) {
this->sendInterest(pitEntry, outFace);
}
}
diff --git a/daemon/fw/ncc-strategy.cpp b/daemon/fw/ncc-strategy.cpp
index a459552..fc9cd20 100644
--- a/daemon/fw/ncc-strategy.cpp
+++ b/daemon/fw/ncc-strategy.cpp
@@ -74,13 +74,13 @@
size_t nUpstreams = nexthops.size();
shared_ptr<Face> bestFace = measurementsEntryInfo->getBestFace();
- if (bestFace != nullptr && fibEntry.hasNextHop(bestFace) &&
+ if (bestFace != nullptr && fibEntry.hasNextHop(*bestFace) &&
canForwardToLegacy(*pitEntry, *bestFace)) {
// TODO Should we use `randlow = 100 + nrand48(h->seed) % 4096U;` ?
deferFirst = measurementsEntryInfo->prediction;
deferRange = time::microseconds((deferFirst.count() + 1) / 2);
--nUpstreams;
- this->sendInterest(pitEntry, bestFace);
+ this->sendInterest(pitEntry, *bestFace);
pitEntryInfo->bestFaceTimeout = scheduler::schedule(
measurementsEntryInfo->prediction,
bind(&NccStrategy::timeoutOnBestFace, this, weak_ptr<pit::Entry>(pitEntry)));
@@ -89,7 +89,7 @@
// use first eligible nexthop
auto firstEligibleNexthop = std::find_if(nexthops.begin(), nexthops.end(),
[&pitEntry] (const fib::NextHop& nexthop) {
- return canForwardToLegacy(*pitEntry, *nexthop.getFace());
+ return canForwardToLegacy(*pitEntry, nexthop.getFace());
});
if (firstEligibleNexthop != nexthops.end()) {
this->sendInterest(pitEntry, firstEligibleNexthop->getFace());
@@ -97,7 +97,7 @@
}
shared_ptr<Face> previousFace = measurementsEntryInfo->previousFace.lock();
- if (previousFace != nullptr && fibEntry.hasNextHop(previousFace) &&
+ if (previousFace != nullptr && fibEntry.hasNextHop(*previousFace) &&
canForwardToLegacy(*pitEntry, *previousFace)) {
--nUpstreams;
}
@@ -135,16 +135,16 @@
this->getMeasurementsEntryInfo(pitEntry);
shared_ptr<Face> previousFace = measurementsEntryInfo->previousFace.lock();
- if (previousFace != nullptr && fibEntry.hasNextHop(previousFace) &&
+ if (previousFace != nullptr && fibEntry.hasNextHop(*previousFace) &&
canForwardToLegacy(*pitEntry, *previousFace)) {
- this->sendInterest(pitEntry, previousFace);
+ this->sendInterest(pitEntry, *previousFace);
}
const fib::NextHopList& nexthops = fibEntry.getNextHops();
bool isForwarded = false;
for (fib::NextHopList::const_iterator it = nexthops.begin(); it != nexthops.end(); ++it) {
- shared_ptr<Face> face = it->getFace();
- if (canForwardToLegacy(*pitEntry, *face)) {
+ Face& face = it->getFace();
+ if (canForwardToLegacy(*pitEntry, face)) {
isForwarded = true;
this->sendInterest(pitEntry, face);
break;
diff --git a/daemon/fw/strategy.hpp b/daemon/fw/strategy.hpp
index 3a11568..386dd7f 100644
--- a/daemon/fw/strategy.hpp
+++ b/daemon/fw/strategy.hpp
@@ -130,7 +130,7 @@
* rather than reusing a Nonce from one of the PIT in-records
*/
VIRTUAL_WITH_TESTS void
- sendInterest(shared_ptr<pit::Entry> pitEntry, shared_ptr<Face> outFace,
+ sendInterest(shared_ptr<pit::Entry> pitEntry, Face& outFace,
bool wantNewNonce = false);
/** \brief decide that a pending Interest cannot be forwarded
@@ -200,11 +200,9 @@
}
inline void
-Strategy::sendInterest(shared_ptr<pit::Entry> pitEntry,
- shared_ptr<Face> outFace,
- bool wantNewNonce)
+Strategy::sendInterest(shared_ptr<pit::Entry> pitEntry, Face& outFace, bool wantNewNonce)
{
- m_forwarder.onOutgoingInterest(pitEntry, *outFace, wantNewNonce);
+ m_forwarder.onOutgoingInterest(pitEntry, outFace, wantNewNonce);
}
inline void