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
diff --git a/daemon/mgmt/fib-manager.cpp b/daemon/mgmt/fib-manager.cpp
index 09e184a..b7ac209 100644
--- a/daemon/mgmt/fib-manager.cpp
+++ b/daemon/mgmt/fib-manager.cpp
@@ -61,11 +61,10 @@
<< " faceid: " << faceId
<< " cost: " << cost);
- auto face = m_getFace(faceId);
- if (static_cast<bool>(face)) {
- auto entry = m_fib.insert(prefix).first;
-
- entry->addNextHop(face, cost);
+ shared_ptr<Face> face = m_getFace(faceId);
+ if (face != nullptr) {
+ fib::Entry* entry = m_fib.insert(prefix).first;
+ entry->addNextHop(*face, cost);
NFD_LOG_DEBUG("add-nexthop result: OK"
<< " prefix:" << prefix
@@ -90,11 +89,11 @@
NFD_LOG_TRACE("remove-nexthop prefix: " << parameters.getName()
<< " faceid: " << parameters.getFaceId());
- auto face = m_getFace(parameters.getFaceId());
- if (static_cast<bool>(face)) {
- auto entry = m_fib.findExactMatch(parameters.getName());
- if (static_cast<bool>(entry)) {
- entry->removeNextHop(face);
+ shared_ptr<Face> face = m_getFace(parameters.getFaceId());
+ if (face != nullptr) {
+ fib::Entry* entry = m_fib.findExactMatch(parameters.getName());
+ if (entry != nullptr) {
+ entry->removeNextHop(*face);
NFD_LOG_DEBUG("remove-nexthop result: OK prefix: " << parameters.getName()
<< " faceid: " << parameters.getFaceId());
@@ -124,7 +123,7 @@
for (auto&& next : nextHops) {
ndn::nfd::NextHopRecord nextHopRecord;
- nextHopRecord.setFaceId(next.getFace()->getId());
+ nextHopRecord.setFaceId(next.getFace().getId());
nextHopRecord.setCost(next.getCost());
record.addNextHopRecord(nextHopRecord);
diff --git a/daemon/nfd.cpp b/daemon/nfd.cpp
index 5d9ce22..65fa80a 100644
--- a/daemon/nfd.cpp
+++ b/daemon/nfd.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,
@@ -194,8 +194,7 @@
// add FIB entry for NFD Management Protocol
Name topPrefix("/localhost/nfd");
- auto entry = m_forwarder->getFib().insert(topPrefix).first;
- entry->addNextHop(m_internalFace, 0);
+ m_forwarder->getFib().insert(topPrefix).first->addNextHop(*m_internalFace, 0);
m_dispatcher->addTopPrefix(topPrefix, false);
}
diff --git a/daemon/table/fib-entry.cpp b/daemon/table/fib-entry.cpp
index b2ea76c..cb37b0f 100644
--- a/daemon/table/fib-entry.cpp
+++ b/daemon/table/fib-entry.cpp
@@ -1,12 +1,12 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014, Regents of the University of California,
- * Arizona Board of Regents,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University,
- * Washington University in St. Louis,
- * Beijing Institute of Technology,
- * The University of Memphis
+ * Copyright (c) 2014-2016, 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.
@@ -34,40 +34,37 @@
}
NextHopList::iterator
-Entry::findNextHop(Face& face)
+Entry::findNextHop(const Face& face)
{
return std::find_if(m_nextHops.begin(), m_nextHops.end(),
[&face] (const NextHop& nexthop) {
- return nexthop.getFace().get() == &face;
+ return &nexthop.getFace() == &face;
});
}
bool
-Entry::hasNextHop(shared_ptr<Face> face) const
+Entry::hasNextHop(const Face& face) const
{
- return const_cast<Entry*>(this)->findNextHop(*face) != m_nextHops.end();
+ return const_cast<Entry*>(this)->findNextHop(face) != m_nextHops.end();
}
void
-Entry::addNextHop(shared_ptr<Face> face, uint64_t cost)
+Entry::addNextHop(Face& face, uint64_t cost)
{
- auto it = this->findNextHop(*face);
+ auto it = this->findNextHop(face);
if (it == m_nextHops.end()) {
- m_nextHops.push_back(fib::NextHop(face));
- it = m_nextHops.end();
- --it;
+ m_nextHops.emplace_back(face);
+ it = std::prev(m_nextHops.end());
}
- // now it refers to the NextHop for face
it->setCost(cost);
-
this->sortNextHops();
}
void
-Entry::removeNextHop(shared_ptr<Face> face)
+Entry::removeNextHop(const Face& face)
{
- auto it = this->findNextHop(*face);
+ auto it = this->findNextHop(face);
if (it != m_nextHops.end()) {
m_nextHops.erase(it);
}
diff --git a/daemon/table/fib-entry.hpp b/daemon/table/fib-entry.hpp
index 9106d9f..8f83266 100644
--- a/daemon/table/fib-entry.hpp
+++ b/daemon/table/fib-entry.hpp
@@ -67,37 +67,33 @@
bool
hasNextHops() const;
- /** \return whether there is a NextHop record for face
- *
- * \todo change parameter type to Face&
+ /** \return whether there is a NextHop record for \p face
*/
bool
- hasNextHop(shared_ptr<Face> face) const;
+ hasNextHop(const Face& face) const;
/** \brief adds a NextHop record
*
- * If a NextHop record for face already exists, its cost is updated.
- * \note shared_ptr is passed by value because this function will take shared ownership
+ * If a NextHop record for \p face already exists, its cost is updated.
*/
void
- addNextHop(shared_ptr<Face> face, uint64_t cost);
+ addNextHop(Face& face, uint64_t cost);
/** \brief removes a NextHop record
*
* If no NextHop record for face exists, do nothing.
- *
- * \todo change parameter type to Face&
*/
void
- removeNextHop(shared_ptr<Face> face);
+ removeNextHop(const Face& face);
private:
- /** @note This method is non-const because normal iterator is needed by callers.
+ /** \note This method is non-const because mutable iterators are needed by callers.
*/
NextHopList::iterator
- findNextHop(Face& face);
+ findNextHop(const Face& face);
- /// sorts the nexthop list
+ /** \brief sorts the nexthop list
+ */
void
sortNextHops();
diff --git a/daemon/table/fib-nexthop.cpp b/daemon/table/fib-nexthop.cpp
index 235fc79..e554362 100644
--- a/daemon/table/fib-nexthop.cpp
+++ b/daemon/table/fib-nexthop.cpp
@@ -1,12 +1,12 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014, Regents of the University of California,
- * Arizona Board of Regents,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University,
- * Washington University in St. Louis,
- * Beijing Institute of Technology,
- * The University of Memphis
+ * Copyright (c) 2014-2016, 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.
@@ -28,29 +28,11 @@
namespace nfd {
namespace fib {
-NextHop::NextHop(shared_ptr<Face> face)
- : m_face(face)
+NextHop::NextHop(Face& face)
+ : m_face(&face)
, m_cost(0)
{
}
-const shared_ptr<Face>&
-NextHop::getFace() const
-{
- return m_face;
-}
-
-void
-NextHop::setCost(uint64_t cost)
-{
- m_cost = cost;
-}
-
-uint64_t
-NextHop::getCost() const
-{
- return m_cost;
-}
-
} // namespace fib
} // namespace nfd
diff --git a/daemon/table/fib-nexthop.hpp b/daemon/table/fib-nexthop.hpp
index 9f7ed93..c8c006e 100644
--- a/daemon/table/fib-nexthop.hpp
+++ b/daemon/table/fib-nexthop.hpp
@@ -1,12 +1,12 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014, Regents of the University of California,
- * Arizona Board of Regents,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University,
- * Washington University in St. Louis,
- * Beijing Institute of Technology,
- * The University of Memphis
+ * Copyright (c) 2014-2016, 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.
@@ -39,19 +39,28 @@
{
public:
explicit
- NextHop(shared_ptr<Face> face);
+ NextHop(Face& face);
- const shared_ptr<Face>&
- getFace() const;
-
- void
- setCost(uint64_t cost);
+ Face&
+ getFace() const
+ {
+ return *m_face;
+ }
uint64_t
- getCost() const;
+ getCost() const
+ {
+ return m_cost;
+ }
+
+ void
+ setCost(uint64_t cost)
+ {
+ m_cost = cost;
+ }
private:
- shared_ptr<Face> m_face;
+ Face* m_face;
uint64_t m_cost;
};
diff --git a/daemon/table/fib.cpp b/daemon/table/fib.cpp
index 946652e..2df3122 100644
--- a/daemon/table/fib.cpp
+++ b/daemon/table/fib.cpp
@@ -32,8 +32,9 @@
#include <type_traits>
namespace nfd {
+namespace fib {
-const shared_ptr<fib::Entry> Fib::s_emptyEntry = make_shared<fib::Entry>(Name());
+const unique_ptr<Entry> Fib::s_emptyEntry = make_unique<Entry>(Name());
// http://en.cppreference.com/w/cpp/concept/ForwardIterator
BOOST_CONCEPT_ASSERT((boost::ForwardIterator<Fib::const_iterator>));
@@ -57,39 +58,38 @@
}
static inline bool
-predicate_NameTreeEntry_hasFibEntry(const name_tree::Entry& entry)
+predicate_NameTreeEntry_hasFibEntry(const name_tree::Entry& nte)
{
- return entry.getFibEntry() != nullptr;
+ return nte.getFibEntry() != nullptr;
}
-shared_ptr<fib::Entry>
+const Entry&
Fib::findLongestPrefixMatch(const Name& prefix) const
{
- shared_ptr<name_tree::Entry> nameTreeEntry =
+ shared_ptr<name_tree::Entry> nte =
m_nameTree.findLongestPrefixMatch(prefix, &predicate_NameTreeEntry_hasFibEntry);
- if (nameTreeEntry != nullptr) {
- return nameTreeEntry->getFibEntry();
+ if (nte != nullptr) {
+ return *nte->getFibEntry();
}
- return s_emptyEntry;
+ return *s_emptyEntry;
}
-shared_ptr<fib::Entry>
-Fib::findLongestPrefixMatch(shared_ptr<name_tree::Entry> nameTreeEntry) const
+const Entry&
+Fib::findLongestPrefixMatch(shared_ptr<name_tree::Entry> nte) const
{
- shared_ptr<fib::Entry> entry = nameTreeEntry->getFibEntry();
+ Entry* entry = nte->getFibEntry();
if (entry != nullptr)
- return entry;
+ return *entry;
- nameTreeEntry = m_nameTree.findLongestPrefixMatch(nameTreeEntry,
- &predicate_NameTreeEntry_hasFibEntry);
- if (nameTreeEntry != nullptr) {
- return nameTreeEntry->getFibEntry();
+ nte = m_nameTree.findLongestPrefixMatch(nte, &predicate_NameTreeEntry_hasFibEntry);
+ if (nte != nullptr) {
+ return *nte->getFibEntry();
}
- return s_emptyEntry;
+ return *s_emptyEntry;
}
-shared_ptr<fib::Entry>
+const Entry&
Fib::findLongestPrefixMatch(const pit::Entry& pitEntry) const
{
shared_ptr<name_tree::Entry> nte = m_nameTree.findLongestPrefixMatch(pitEntry);
@@ -97,82 +97,81 @@
return findLongestPrefixMatch(nte);
}
-shared_ptr<fib::Entry>
+const Entry&
Fib::findLongestPrefixMatch(const measurements::Entry& measurementsEntry) const
{
- shared_ptr<name_tree::Entry> nameTreeEntry = m_nameTree.lookup(measurementsEntry);
- BOOST_ASSERT(nameTreeEntry != nullptr);
-
- return findLongestPrefixMatch(nameTreeEntry);
+ shared_ptr<name_tree::Entry> nte = m_nameTree.lookup(measurementsEntry);
+ BOOST_ASSERT(nte != nullptr);
+ return findLongestPrefixMatch(nte);
}
-shared_ptr<fib::Entry>
-Fib::findExactMatch(const Name& prefix) const
+Entry*
+Fib::findExactMatch(const Name& prefix)
{
- shared_ptr<name_tree::Entry> nameTreeEntry = m_nameTree.findExactMatch(prefix);
- if (nameTreeEntry != nullptr)
- return nameTreeEntry->getFibEntry();
+ shared_ptr<name_tree::Entry> nte = m_nameTree.findExactMatch(prefix);
+ if (nte != nullptr)
+ return nte->getFibEntry();
return nullptr;
}
-std::pair<shared_ptr<fib::Entry>, bool>
+std::pair<Entry*, bool>
Fib::insert(const Name& prefix)
{
- shared_ptr<name_tree::Entry> nameTreeEntry = m_nameTree.lookup(prefix);
- shared_ptr<fib::Entry> entry = nameTreeEntry->getFibEntry();
- if (entry != nullptr)
+ shared_ptr<name_tree::Entry> nte = m_nameTree.lookup(prefix);
+ Entry* entry = nte->getFibEntry();
+ if (entry != nullptr) {
return std::make_pair(entry, false);
+ }
- entry = make_shared<fib::Entry>(prefix);
- nameTreeEntry->setFibEntry(entry);
+ nte->setFibEntry(make_unique<Entry>(prefix));
++m_nItems;
- return std::make_pair(entry, true);
+ return std::make_pair(nte->getFibEntry(), true);
}
void
-Fib::erase(shared_ptr<name_tree::Entry> nameTreeEntry)
+Fib::erase(shared_ptr<name_tree::Entry> nte)
{
- nameTreeEntry->setFibEntry(shared_ptr<fib::Entry>());
- m_nameTree.eraseEntryIfEmpty(nameTreeEntry);
+ nte->setFibEntry(nullptr);
+ m_nameTree.eraseEntryIfEmpty(nte);
--m_nItems;
}
void
Fib::erase(const Name& prefix)
{
- shared_ptr<name_tree::Entry> nameTreeEntry = m_nameTree.findExactMatch(prefix);
- if (nameTreeEntry != nullptr) {
- this->erase(nameTreeEntry);
+ shared_ptr<name_tree::Entry> nte = m_nameTree.findExactMatch(prefix);
+ if (nte != nullptr) {
+ this->erase(nte);
}
}
void
-Fib::erase(const fib::Entry& entry)
+Fib::erase(const Entry& entry)
{
- shared_ptr<name_tree::Entry> nameTreeEntry = m_nameTree.lookup(entry);
- if (nameTreeEntry != nullptr) {
- this->erase(nameTreeEntry);
+ shared_ptr<name_tree::Entry> nte = m_nameTree.lookup(entry);
+ if (nte != nullptr) {
+ this->erase(nte);
}
}
void
-Fib::removeNextHopFromAllEntries(shared_ptr<Face> face)
+Fib::removeNextHopFromAllEntries(const Face& face)
{
- std::list<fib::Entry*> toErase;
+ std::list<Entry*> toErase;
auto&& enumerable = m_nameTree.fullEnumerate(&predicate_NameTreeEntry_hasFibEntry);
for (const name_tree::Entry& nte : enumerable) {
- shared_ptr<fib::Entry> entry = nte.getFibEntry();
+ Entry* entry = nte.getFibEntry();
entry->removeNextHop(face);
if (!entry->hasNextHops()) {
- toErase.push_back(entry.get());
+ toErase.push_back(entry);
// entry needs to be erased, but we must wait until the enumeration ends,
// because otherwise NameTree iterator would be invalidated
}
}
- for (fib::Entry* entry : toErase) {
+ for (Entry* entry : toErase) {
this->erase(*entry);
}
}
@@ -183,4 +182,5 @@
return const_iterator(m_nameTree.fullEnumerate(&predicate_NameTreeEntry_hasFibEntry).begin());
}
+} // namespace fib
} // namespace nfd
diff --git a/daemon/table/fib.hpp b/daemon/table/fib.hpp
index bde7428..bfe6684 100644
--- a/daemon/table/fib.hpp
+++ b/daemon/table/fib.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, Regents of the University of California,
+ * Copyright (c) 2014-2016, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -33,13 +33,14 @@
namespace measurements {
class Entry;
-}
+} // namespace measurements
namespace pit {
class Entry;
-}
+} // namespace pit
-/** \class Fib
- * \brief represents the FIB
+namespace fib {
+
+/** \brief represents the Forwarding Information Base (FIB)
*/
class Fib : noncopyable
{
@@ -53,44 +54,54 @@
size() const;
public: // lookup
- /// performs a longest prefix match
- shared_ptr<fib::Entry>
+ /** \brief performs a longest prefix match
+ */
+ const Entry&
findLongestPrefixMatch(const Name& prefix) const;
- /// performs a longest prefix match
- shared_ptr<fib::Entry>
+ /** \brief performs a longest prefix match
+ *
+ * This is equivalent to .findLongestPrefixMatch(pitEntry.getName())
+ */
+ const Entry&
findLongestPrefixMatch(const pit::Entry& pitEntry) const;
- /// performs a longest prefix match
- shared_ptr<fib::Entry>
+ /** \brief performs a longest prefix match
+ *
+ * This is equivalent to .findLongestPrefixMatch(measurementsEntry.getName())
+ */
+ const Entry&
findLongestPrefixMatch(const measurements::Entry& measurementsEntry) const;
- shared_ptr<fib::Entry>
- findExactMatch(const Name& prefix) const;
+ /** \brief performs an exact match lookup
+ */
+ Entry*
+ findExactMatch(const Name& prefix);
public: // mutation
/** \brief inserts a FIB entry for prefix
+ *
* If an entry for exact same prefix exists, that entry is returned.
- * \return{ the entry, and true for new entry, false for existing entry }
+ * \return the entry, and true for new entry or false for existing entry
*/
- std::pair<shared_ptr<fib::Entry>, bool>
+ std::pair<Entry*, bool>
insert(const Name& prefix);
void
erase(const Name& prefix);
void
- erase(const fib::Entry& entry);
+ erase(const Entry& entry);
- /** \brief removes the NextHop record for face in all entrites
+ /** \brief removes the NextHop record for face in all entries
*
- * This is usually invoked when face goes away.
+ * This is usually invoked when face is destroyed.
* Removing the last NextHop in a FIB entry will erase the FIB entry.
*
* \todo change parameter type to Face&
*/
void
- removeNextHopFromAllEntries(shared_ptr<Face> face);
+ removeNextHopFromAllEntries(const Face& face);
public: // enumeration
class const_iterator;
@@ -110,7 +121,7 @@
const_iterator
end() const;
- class const_iterator : public std::iterator<std::forward_iterator_tag, const fib::Entry>
+ class const_iterator : public std::iterator<std::forward_iterator_tag, const Entry>
{
public:
const_iterator() = default;
@@ -120,10 +131,10 @@
~const_iterator();
- const fib::Entry&
+ const Entry&
operator*() const;
- shared_ptr<fib::Entry>
+ const Entry*
operator->() const;
const_iterator&
@@ -143,8 +154,8 @@
};
private:
- shared_ptr<fib::Entry>
- findLongestPrefixMatch(shared_ptr<name_tree::Entry> nameTreeEntry) const;
+ const Entry&
+ findLongestPrefixMatch(shared_ptr<name_tree::Entry> nte) const;
void
erase(shared_ptr<name_tree::Entry> nameTreeEntry);
@@ -153,13 +164,12 @@
NameTree& m_nameTree;
size_t m_nItems;
- /** \brief The empty FIB entry.
+ /** \brief the empty FIB entry.
*
* This entry has no nexthops.
* It is returned by findLongestPrefixMatch if nothing is matched.
- * Returning empty entry instead of nullptr makes forwarding and strategy implementation easier.
*/
- static const shared_ptr<fib::Entry> s_emptyEntry;
+ static const unique_ptr<Entry> s_emptyEntry;
};
inline size_t
@@ -189,7 +199,7 @@
Fib::const_iterator
Fib::const_iterator::operator++(int)
{
- Fib::const_iterator temp(*this);
+ const_iterator temp(*this);
++(*this);
return temp;
}
@@ -201,30 +211,34 @@
return *this;
}
-inline const fib::Entry&
+inline const Entry&
Fib::const_iterator::operator*() const
{
- return *this->operator->();
+ return *m_nameTreeIterator->getFibEntry();
}
-inline shared_ptr<fib::Entry>
+inline const Entry*
Fib::const_iterator::operator->() const
{
return m_nameTreeIterator->getFibEntry();
}
inline bool
-Fib::const_iterator::operator==(const Fib::const_iterator& other) const
+Fib::const_iterator::operator==(const const_iterator& other) const
{
return m_nameTreeIterator == other.m_nameTreeIterator;
}
inline bool
-Fib::const_iterator::operator!=(const Fib::const_iterator& other) const
+Fib::const_iterator::operator!=(const const_iterator& other) const
{
return m_nameTreeIterator != other.m_nameTreeIterator;
}
+} // namespace fib
+
+using fib::Fib;
+
} // namespace nfd
#endif // NFD_DAEMON_TABLE_FIB_HPP
diff --git a/daemon/table/name-tree-entry.cpp b/daemon/table/name-tree-entry.cpp
index 889ed97..87853f2 100644
--- a/daemon/table/name-tree-entry.cpp
+++ b/daemon/table/name-tree-entry.cpp
@@ -65,14 +65,14 @@
}
void
-Entry::setFibEntry(shared_ptr<fib::Entry> fibEntry)
+Entry::setFibEntry(unique_ptr<fib::Entry> fibEntry)
{
BOOST_ASSERT(fibEntry == nullptr || fibEntry->m_nameTreeEntry.expired());
if (m_fibEntry != nullptr) {
m_fibEntry->m_nameTreeEntry.reset();
}
- m_fibEntry = fibEntry;
+ m_fibEntry = std::move(fibEntry);
if (m_fibEntry != nullptr) {
m_fibEntry->m_nameTreeEntry = this->shared_from_this();
diff --git a/daemon/table/name-tree-entry.hpp b/daemon/table/name-tree-entry.hpp
index 378d285..c650587 100644
--- a/daemon/table/name-tree-entry.hpp
+++ b/daemon/table/name-tree-entry.hpp
@@ -96,9 +96,9 @@
public: // attached table entries
void
- setFibEntry(shared_ptr<fib::Entry> fibEntry);
+ setFibEntry(unique_ptr<fib::Entry> fibEntry);
- shared_ptr<fib::Entry>
+ fib::Entry*
getFibEntry() const;
void
@@ -133,7 +133,7 @@
Name m_prefix;
shared_ptr<Entry> m_parent; // Pointing to the parent entry.
std::vector<shared_ptr<Entry> > m_children; // Children pointers.
- shared_ptr<fib::Entry> m_fibEntry;
+ unique_ptr<fib::Entry> m_fibEntry;
std::vector<shared_ptr<pit::Entry> > m_pitEntries;
shared_ptr<measurements::Entry> m_measurementsEntry;
shared_ptr<strategy_choice::Entry> m_strategyChoiceEntry;
@@ -187,10 +187,10 @@
return !m_children.empty();
}
-inline shared_ptr<fib::Entry>
+inline fib::Entry*
Entry::getFibEntry() const
{
- return m_fibEntry;
+ return m_fibEntry.get();
}
inline bool
diff --git a/daemon/table/name-tree.cpp b/daemon/table/name-tree.cpp
index 87d4154..796e701 100644
--- a/daemon/table/name-tree.cpp
+++ b/daemon/table/name-tree.cpp
@@ -244,7 +244,7 @@
NameTree::lookup(const fib::Entry& fibEntry) const
{
shared_ptr<name_tree::Entry> nte = this->getEntry(fibEntry);
- BOOST_ASSERT(nte == nullptr || nte->getFibEntry().get() == &fibEntry);
+ BOOST_ASSERT(nte == nullptr || nte->getFibEntry() == &fibEntry);
return nte;
}
diff --git a/tests/daemon/fw/best-route-strategy2.t.cpp b/tests/daemon/fw/best-route-strategy2.t.cpp
index a3b2aba..ac5c3ef 100644
--- a/tests/daemon/fw/best-route-strategy2.t.cpp
+++ b/tests/daemon/fw/best-route-strategy2.t.cpp
@@ -75,10 +75,10 @@
BOOST_AUTO_TEST_CASE(Forward)
{
- shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first;
- fibEntry->addNextHop(face1, 10);
- fibEntry->addNextHop(face2, 20);
- fibEntry->addNextHop(face3, 30);
+ fib::Entry& fibEntry = *fib.insert(Name()).first;
+ fibEntry.addNextHop(*face1, 10);
+ fibEntry.addNextHop(*face2, 20);
+ fibEntry.addNextHop(*face3, 30);
shared_ptr<Interest> interest = makeInterest("ndn:/BzgFBchqA");
shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
@@ -127,7 +127,7 @@
BOOST_CHECK_EQUAL(strategy.sendInterestHistory[4].outFaceId, face1->getId());
BOOST_CHECK_EQUAL(strategy.sendInterestHistory[5].outFaceId, face3->getId());
- fibEntry->removeNextHop(face1);
+ fibEntry.removeNextHop(*face1);
strategy.sendInterestHistory.clear();
for (int i = 0; i < 3; ++i) {
@@ -153,10 +153,10 @@
return "/P";
}
- shared_ptr<fib::Entry>
- makeFibEntry(BestRouteStrategy2Fixture* fixture)
+ void
+ insertFibEntry(BestRouteStrategy2Fixture* fixture)
{
- return fixture->fib.insert(Name()).first;
+ fixture->fib.insert(Name());
}
};
@@ -169,12 +169,10 @@
return "/P";
}
- shared_ptr<fib::Entry>
- makeFibEntry(BestRouteStrategy2Fixture* fixture)
+ void
+ insertFibEntry(BestRouteStrategy2Fixture* fixture)
{
- shared_ptr<fib::Entry> fibEntry = fixture->fib.insert(Name()).first;
- fibEntry->addNextHop(fixture->face1, 10);
- return fibEntry;
+ fixture->fib.insert(Name()).first->addNextHop(*fixture->face1, 10);
}
};
@@ -187,13 +185,11 @@
return "/localhop/P";
}
- shared_ptr<fib::Entry>
- makeFibEntry(BestRouteStrategy2Fixture* fixture)
+ void
+ insertFibEntry(BestRouteStrategy2Fixture* fixture)
{
- shared_ptr<fib::Entry> fibEntry = fixture->fib.insert("/localhop").first;
- fibEntry->addNextHop(fixture->face2, 10);
+ fixture->fib.insert("/localhop").first->addNextHop(*fixture->face2, 10);
// face1 and face2 are both non-local; Interest from face1 cannot be forwarded to face2
- return fibEntry;
}
};
@@ -202,13 +198,12 @@
BOOST_AUTO_TEST_CASE_TEMPLATE(IncomingInterest, Scenario, NoRouteScenarios)
{
Scenario scenario;
+ scenario.insertFibEntry(this);
shared_ptr<Interest> interest = makeInterest(scenario.getInterestName());
shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
pitEntry->insertOrUpdateInRecord(face1, *interest);
- shared_ptr<fib::Entry> fibEntry = scenario.makeFibEntry(this);
-
strategy.afterReceiveInterest(*face1, *interest, pitEntry);
BOOST_REQUIRE_EQUAL(strategy.rejectPendingInterestHistory.size(), 1);
@@ -226,10 +221,10 @@
BOOST_AUTO_TEST_CASE(OneUpstream) // one upstream, send Nack when Nack arrives
{
- shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first;
- fibEntry->addNextHop(face3, 10);
- fibEntry->addNextHop(face4, 20);
- fibEntry->addNextHop(face5, 30);
+ fib::Entry& fibEntry = *fib.insert(Name()).first;
+ fibEntry.addNextHop(*face3, 10);
+ fibEntry.addNextHop(*face4, 20);
+ fibEntry.addNextHop(*face5, 30);
shared_ptr<Interest> interest1 = makeInterest("/McQYjMbm", 992);
shared_ptr<Interest> interest2 = makeInterest("/McQYjMbm", 114);
@@ -256,10 +251,10 @@
BOOST_AUTO_TEST_CASE(TwoUpstreams) // two upstreams, send Nack when both Nacks arrive
{
- shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first;
- fibEntry->addNextHop(face3, 10);
- fibEntry->addNextHop(face4, 20);
- fibEntry->addNextHop(face5, 30);
+ fib::Entry& fibEntry = *fib.insert(Name()).first;
+ fibEntry.addNextHop(*face3, 10);
+ fibEntry.addNextHop(*face4, 20);
+ fibEntry.addNextHop(*face5, 30);
shared_ptr<Interest> interest1 = makeInterest("/aS9FAyUV19", 286);
shared_ptr<pit::Entry> pitEntry = pit.insert(*interest1).first;
@@ -285,10 +280,10 @@
BOOST_AUTO_TEST_CASE(Timeout) // two upstreams, one times out, don't send Nack
{
- shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first;
- fibEntry->addNextHop(face3, 10);
- fibEntry->addNextHop(face4, 20);
- fibEntry->addNextHop(face5, 30);
+ fib::Entry& fibEntry = *fib.insert(Name()).first;
+ fibEntry.addNextHop(*face3, 10);
+ fibEntry.addNextHop(*face4, 20);
+ fibEntry.addNextHop(*face5, 30);
shared_ptr<Interest> interest1 = makeInterest("/sIYw0TXWDj", 115);
interest1->setInterestLifetime(time::milliseconds(400));
@@ -429,10 +424,10 @@
{
Combination combination;
- shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first;
- fibEntry->addNextHop(face3, 10);
- fibEntry->addNextHop(face4, 20);
- fibEntry->addNextHop(face5, 30);
+ fib::Entry& fibEntry = *fib.insert(Name()).first;
+ fibEntry.addNextHop(*face3, 10);
+ fibEntry.addNextHop(*face4, 20);
+ fibEntry.addNextHop(*face5, 30);
shared_ptr<Interest> interest1 = makeInterest("/F6sEwB24I", 282);
shared_ptr<pit::Entry> pitEntry = pit.insert(*interest1).first;
diff --git a/tests/daemon/fw/client-control-strategy.t.cpp b/tests/daemon/fw/client-control-strategy.t.cpp
index 0305b47..0a31244 100644
--- a/tests/daemon/fw/client-control-strategy.t.cpp
+++ b/tests/daemon/fw/client-control-strategy.t.cpp
@@ -54,8 +54,8 @@
forwarder.addFace(face4);
Fib& fib = forwarder.getFib();
- shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first;
- fibEntry->addNextHop(face2, 0);
+ fib::Entry& fibEntry = *fib.insert(Name()).first;
+ fibEntry.addNextHop(*face2, 0);
Pit& pit = forwarder.getPit();
diff --git a/tests/daemon/fw/dummy-strategy.hpp b/tests/daemon/fw/dummy-strategy.hpp
index ca6a858..17831fd 100644
--- a/tests/daemon/fw/dummy-strategy.hpp
+++ b/tests/daemon/fw/dummy-strategy.hpp
@@ -63,7 +63,7 @@
}
if (interestOutFace) {
- this->sendInterest(pitEntry, interestOutFace);
+ this->sendInterest(pitEntry, *interestOutFace);
}
else {
this->rejectPendingInterest(pitEntry);
diff --git a/tests/daemon/fw/forwarder.t.cpp b/tests/daemon/fw/forwarder.t.cpp
index 1a4de92..7f2bc41 100644
--- a/tests/daemon/fw/forwarder.t.cpp
+++ b/tests/daemon/fw/forwarder.t.cpp
@@ -39,12 +39,9 @@
{
Forwarder forwarder;
- Name nameA("ndn:/A");
- Name nameAB("ndn:/A/B");
- Name nameABC("ndn:/A/B/C");
- shared_ptr<Interest> interestAB = makeInterest(nameAB);
+ shared_ptr<Interest> interestAB = makeInterest("/A/B");
interestAB->setInterestLifetime(time::seconds(4));
- shared_ptr<Data> dataABC = makeData(nameABC);
+ shared_ptr<Data> dataABC = makeData("/A/B/C");
auto face1 = make_shared<DummyFace>();
auto face2 = make_shared<DummyFace>();
@@ -52,15 +49,14 @@
forwarder.addFace(face2);
Fib& fib = forwarder.getFib();
- shared_ptr<fib::Entry> fibEntry = fib.insert(Name("ndn:/A")).first;
- fibEntry->addNextHop(face2, 0);
+ fib.insert("/A").first->addNextHop(*face2, 0);
BOOST_CHECK_EQUAL(forwarder.getCounters().nInInterests, 0);
BOOST_CHECK_EQUAL(forwarder.getCounters().nOutInterests, 0);
face1->receiveInterest(*interestAB);
this->advanceClocks(time::milliseconds(100), time::seconds(1));
BOOST_REQUIRE_EQUAL(face2->sentInterests.size(), 1);
- BOOST_CHECK_EQUAL(face2->sentInterests[0].getName(), nameAB);
+ BOOST_CHECK_EQUAL(face2->sentInterests[0].getName(), "/A/B");
BOOST_REQUIRE(face2->sentInterests[0].getTag<lp::IncomingFaceIdTag>() != nullptr);
BOOST_CHECK_EQUAL(*face2->sentInterests[0].getTag<lp::IncomingFaceIdTag>(), face1->getId());
BOOST_CHECK_EQUAL(forwarder.getCounters().nInInterests, 1);
@@ -71,7 +67,7 @@
face2->receiveData(*dataABC);
this->advanceClocks(time::milliseconds(100), time::seconds(1));
BOOST_REQUIRE_EQUAL(face1->sentData.size(), 1);
- BOOST_CHECK_EQUAL(face1->sentData[0].getName(), nameABC);
+ BOOST_CHECK_EQUAL(face1->sentData[0].getName(), "/A/B/C");
BOOST_REQUIRE(face1->sentData[0].getTag<lp::IncomingFaceIdTag>() != nullptr);
BOOST_CHECK_EQUAL(*face1->sentData[0].getTag<lp::IncomingFaceIdTag>(), face2->getId());
BOOST_CHECK_EQUAL(forwarder.getCounters().nInData, 1);
@@ -89,14 +85,13 @@
forwarder.addFace(face2);
forwarder.addFace(face3);
- shared_ptr<Interest> interestA = makeInterest("ndn:/A");
+ shared_ptr<Interest> interestA = makeInterest("/A");
interestA->setInterestLifetime(time::seconds(4));
- shared_ptr<Data> dataA = makeData("ndn:/A");
+ shared_ptr<Data> dataA = makeData("/A");
dataA->setTag(make_shared<lp::IncomingFaceIdTag>(face3->getId()));
Fib& fib = forwarder.getFib();
- shared_ptr<fib::Entry> fibEntry = fib.insert(Name("ndn:/A")).first;
- fibEntry->addNextHop(face2, 0);
+ fib.insert("/A").first->addNextHop(*face2, 0);
Pit& pit = forwarder.getPit();
BOOST_CHECK_EQUAL(pit.size(), 0);
@@ -130,7 +125,7 @@
forwarder.addFace(face3);
Pit& pit = forwarder.getPit();
- auto interestA1 = makeInterest("ndn:/A");
+ auto interestA1 = makeInterest("/A");
interestA1->setNonce(8378);
shared_ptr<pit::Entry> pitA = pit.insert(*interestA1).first;
pit::InRecordCollection::iterator inA1 = pitA->insertOrUpdateInRecord(face1, *interestA1);
@@ -153,7 +148,7 @@
BOOST_CHECK_EQUAL(face1->sentInterests.back().getNonce(), 8378);
this->advanceClocks(time::seconds(2));
- auto interestA2 = makeInterest("ndn:/A");
+ auto interestA2 = makeInterest("/A");
interestA2->setNonce(9102);
pitA->insertOrUpdateInRecord(face2, *interestA2);
@@ -644,8 +639,7 @@
forwarder.addFace(face4);
Fib& fib = forwarder.getFib();
- shared_ptr<fib::Entry> fibEntry = fib.insert(Name("/zT4XwK0Hnx")).first;
- fibEntry->addNextHop(face4, 0);
+ fib.insert("/zT4XwK0Hnx").first->addNextHop(*face4, 0);
// receive Interest on face1
face1->sentNacks.clear();
@@ -699,8 +693,7 @@
});
Fib& fib = forwarder.getFib();
- shared_ptr<fib::Entry> fibEntry = fib.insert(Name("ndn:/A")).first;
- fibEntry->addNextHop(face2, 0);
+ fib.insert("/A").first->addNextHop(*face2, 0);
// receive an Interest
shared_ptr<Interest> interest = makeInterest("ndn:/A/1");
@@ -758,8 +751,7 @@
// consumer region
nrt.clear();
nrt.insert("/arizona/cs/avenir");
- shared_ptr<fib::Entry> fibRoot = fib.insert("/").first;
- fibRoot->addNextHop(face2, 10);
+ fib.insert("/").first->addNextHop(*face2, 10);
auto interest1 = makeInterest("/net/ndnsim/www/1.html");
interest1->setLink(link->wireEncode());
@@ -769,15 +761,13 @@
BOOST_CHECK_EQUAL(forwarder.lookupFib(*pit1).getPrefix(), "/");
BOOST_CHECK_EQUAL(interest1->hasSelectedDelegation(), false);
- fibRoot->removeNextHop(face2);
+ fib.insert("/").first->removeNextHop(*face2);
// first default-free router, both delegations are available
nrt.clear();
nrt.insert("/arizona/cs/hobo");
- shared_ptr<fib::Entry> fibTelia = fib.insert("/telia").first;
- fibTelia->addNextHop(face2, 10);
- shared_ptr<fib::Entry> fibUcla = fib.insert("/ucla").first;
- fibUcla->addNextHop(face2, 10);
+ fib.insert("/telia").first->addNextHop(*face2, 10);
+ fib.insert("/ucla").first->addNextHop(*face2, 10);
auto interest2 = makeInterest("/net/ndnsim/www/2.html");
interest2->setLink(link->wireEncode());
@@ -788,14 +778,13 @@
BOOST_REQUIRE_EQUAL(interest2->hasSelectedDelegation(), true);
BOOST_CHECK_EQUAL(interest2->getSelectedDelegation(), "/telia/terabits");
- fib.erase(*fibTelia);
- fib.erase(*fibUcla);
+ fib.erase("/telia");
+ fib.erase("/ucla");
// first default-free router, only second delegation is available
nrt.clear();
nrt.insert("/arizona/cs/hobo");
- fibUcla = fib.insert("/ucla").first;
- fibUcla->addNextHop(face2, 10);
+ fib.insert("/ucla").first->addNextHop(*face2, 10);
auto interest3 = makeInterest("/net/ndnsim/www/3.html");
interest3->setLink(link->wireEncode());
@@ -806,15 +795,13 @@
BOOST_REQUIRE_EQUAL(interest3->hasSelectedDelegation(), true);
BOOST_CHECK_EQUAL(interest3->getSelectedDelegation(), "/ucla/cs");
- fib.erase(*fibUcla);
+ fib.erase("/ucla");
// default-free router, chosen SelectedDelegation
nrt.clear();
nrt.insert("/ucsd/caida/click");
- fibTelia = fib.insert("/telia").first;
- fibTelia->addNextHop(face2, 10);
- fibUcla = fib.insert("/ucla").first;
- fibUcla->addNextHop(face2, 10);
+ fib.insert("/telia").first->addNextHop(*face2, 10);
+ fib.insert("/ucla").first->addNextHop(*face2, 10);
auto interest4 = makeInterest("/net/ndnsim/www/4.html");
interest4->setLink(link->wireEncode());
@@ -826,17 +813,15 @@
BOOST_REQUIRE_EQUAL(interest4->hasSelectedDelegation(), true);
BOOST_CHECK_EQUAL(interest4->getSelectedDelegation(), "/ucla/cs");
- fib.erase(*fibTelia);
- fib.erase(*fibUcla);
+ fib.erase("/telia");
+ fib.erase("/ucla");
// producer region
nrt.clear();
nrt.insert("/ucla/cs/spurs");
- fibRoot->addNextHop(face2, 10);
- fibUcla = fib.insert("/ucla").first;
- fibUcla->addNextHop(face2, 10);
- shared_ptr<fib::Entry> fibNdnsim = fib.insert("/net/ndnsim").first;
- fibNdnsim->addNextHop(face2, 10);
+ fib.insert("/").first->addNextHop(*face2, 10);
+ fib.insert("/ucla").first->addNextHop(*face2, 10);
+ fib.insert("/net/ndnsim").first->addNextHop(*face2, 10);
auto interest5 = makeInterest("/net/ndnsim/www/5.html");
interest5->setLink(link->wireEncode());
@@ -848,9 +833,9 @@
BOOST_REQUIRE_EQUAL(interest5->hasSelectedDelegation(), true);
BOOST_CHECK_EQUAL(interest5->getSelectedDelegation(), "/ucla/cs");
- fibRoot->removeNextHop(face2);
- fib.erase(*fibUcla);
- fib.erase(*fibNdnsim);
+ fib.insert("/").first->removeNextHop(*face2);
+ fib.erase("/ucla");
+ fib.erase("/ndnsim");
}
diff --git a/tests/daemon/fw/multicast-strategy.t.cpp b/tests/daemon/fw/multicast-strategy.t.cpp
index 5204821..2800dc7 100644
--- a/tests/daemon/fw/multicast-strategy.t.cpp
+++ b/tests/daemon/fw/multicast-strategy.t.cpp
@@ -52,10 +52,10 @@
forwarder.addFace(face3);
Fib& fib = forwarder.getFib();
- shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first;
- fibEntry->addNextHop(face1, 0);
- fibEntry->addNextHop(face2, 0);
- fibEntry->addNextHop(face3, 0);
+ fib::Entry& fibEntry = *fib.insert(Name()).first;
+ fibEntry.addNextHop(*face1, 0);
+ fibEntry.addNextHop(*face2, 0);
+ fibEntry.addNextHop(*face3, 0);
shared_ptr<Interest> interest = makeInterest("ndn:/H0D6i5fc");
Pit& pit = forwarder.getPit();
@@ -88,8 +88,8 @@
forwarder.addFace(face2);
Fib& fib = forwarder.getFib();
- shared_ptr<fib::Entry> fibEntry = fib.insert("ndn:/localhop/uS09bub6tm").first;
- fibEntry->addNextHop(face2, 0);
+ fib::Entry& fibEntry = *fib.insert("ndn:/localhop/uS09bub6tm").first;
+ fibEntry.addNextHop(*face2, 0);
shared_ptr<Interest> interest = makeInterest("ndn:/localhop/uS09bub6tm/eG3MMoP6z");
Pit& pit = forwarder.getPit();
@@ -111,8 +111,8 @@
forwarder.addFace(face1);
Fib& fib = forwarder.getFib();
- shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first;
- fibEntry->addNextHop(face1, 0);
+ fib::Entry& fibEntry = *fib.insert(Name()).first;
+ fibEntry.addNextHop(*face1, 0);
shared_ptr<Interest> interest = makeInterest("ndn:/H0D6i5fc");
Pit& pit = forwarder.getPit();
diff --git a/tests/daemon/fw/ncc-strategy.t.cpp b/tests/daemon/fw/ncc-strategy.t.cpp
index 9fec06b..b624c74 100644
--- a/tests/daemon/fw/ncc-strategy.t.cpp
+++ b/tests/daemon/fw/ncc-strategy.t.cpp
@@ -62,9 +62,9 @@
forwarder.addFace(face3);
Fib& fib = forwarder.getFib();
- shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first;
- fibEntry->addNextHop(face1, 10);
- fibEntry->addNextHop(face2, 20);
+ fib::Entry& fibEntry = *fib.insert(Name()).first;
+ fibEntry.addNextHop(*face1, 10);
+ fibEntry.addNextHop(*face2, 20);
StrategyChoice& strategyChoice = forwarder.getStrategyChoice();
strategyChoice.install(strategy);
@@ -126,8 +126,8 @@
forwarder.addFace(face3);
Fib& fib = forwarder.getFib();
- shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first;
- fibEntry->addNextHop(face1, 10);
+ fib::Entry& fibEntry = *fib.insert(Name()).first;
+ fibEntry.addNextHop(*face1, 10);
StrategyChoice& strategyChoice = forwarder.getStrategyChoice();
strategyChoice.install(strategy);
@@ -162,7 +162,7 @@
strategy->afterReceiveInterest(*face3, *interest2, pitEntry2);
// FIB entry is changed before doPropagate executes
- fibEntry->addNextHop(face2, 20);
+ fibEntry.addNextHop(*face2, 20);
this->advanceClocks(time::milliseconds(10), time::milliseconds(1000));// should not crash
}
@@ -182,9 +182,9 @@
forwarder.addFace(face3);
Fib& fib = forwarder.getFib();
- shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first;
- fibEntry->addNextHop(face1, 10);
- fibEntry->addNextHop(face2, 20);
+ fib::Entry& fibEntry = *fib.insert(Name()).first;
+ fibEntry.addNextHop(*face1, 10);
+ fibEntry.addNextHop(*face2, 20);
StrategyChoice& strategyChoice = forwarder.getStrategyChoice();
strategyChoice.install(strategy);
@@ -242,8 +242,8 @@
forwarder.addFace(face2);
Fib& fib = forwarder.getFib();
- shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first;
- fibEntry->addNextHop(face2, 10);
+ fib::Entry& fibEntry = *fib.insert(Name()).first;
+ fibEntry.addNextHop(*face2, 10);
StrategyChoice& strategyChoice = forwarder.getStrategyChoice();
strategyChoice.install(strategy);
@@ -292,9 +292,9 @@
forwarder.addFace(face2);
Fib& fib = forwarder.getFib();
- shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first;
- fibEntry->addNextHop(face1, 10); // face1 is top-ranked nexthop
- fibEntry->addNextHop(face2, 20);
+ fib::Entry& fibEntry = *fib.insert(Name()).first;
+ fibEntry.addNextHop(*face1, 10); // face1 is top-ranked nexthop
+ fibEntry.addNextHop(*face2, 20);
StrategyChoice& strategyChoice = forwarder.getStrategyChoice();
strategyChoice.install(strategy);
diff --git a/tests/daemon/fw/strategy-tester.hpp b/tests/daemon/fw/strategy-tester.hpp
index ed831ff..da79517 100644
--- a/tests/daemon/fw/strategy-tester.hpp
+++ b/tests/daemon/fw/strategy-tester.hpp
@@ -53,7 +53,7 @@
protected:
virtual void
sendInterest(shared_ptr<pit::Entry> pitEntry,
- shared_ptr<Face> outFace,
+ Face& outFace,
bool wantNewNonce = false) override;
virtual void
@@ -91,12 +91,12 @@
template<typename S>
inline void
StrategyTester<S>::sendInterest(shared_ptr<pit::Entry> pitEntry,
- shared_ptr<Face> outFace,
+ Face& outFace,
bool wantNewNonce)
{
- SendInterestArgs args{pitEntry, outFace->getId(), wantNewNonce};
+ SendInterestArgs args{pitEntry, outFace.getId(), wantNewNonce};
sendInterestHistory.push_back(args);
- pitEntry->insertOrUpdateOutRecord(outFace, pitEntry->getInterest());
+ pitEntry->insertOrUpdateOutRecord(outFace.shared_from_this(), pitEntry->getInterest());
afterAction();
}
diff --git a/tests/daemon/fw/topology-tester.cpp b/tests/daemon/fw/topology-tester.cpp
index b1eeb6a..9224b40 100644
--- a/tests/daemon/fw/topology-tester.cpp
+++ b/tests/daemon/fw/topology-tester.cpp
@@ -184,8 +184,7 @@
{
Forwarder& forwarder = this->getForwarder(i);
Fib& fib = forwarder.getFib();
- shared_ptr<fib::Entry> fibEntry = fib.insert(prefix).first;
- fibEntry->addNextHop(const_cast<Face&>(face).shared_from_this(), cost);
+ fib.insert(prefix).first->addNextHop(const_cast<Face&>(face), cost);
}
void
diff --git a/tests/daemon/mgmt/fib-manager.t.cpp b/tests/daemon/mgmt/fib-manager.t.cpp
index ee56cf7..9e5f285 100644
--- a/tests/daemon/mgmt/fib-manager.t.cpp
+++ b/tests/daemon/mgmt/fib-manager.t.cpp
@@ -94,19 +94,19 @@
checkNextHop(const Name& prefix, ssize_t expectedNNextHops = -1,
FaceId faceId = face::FACEID_NULL, int32_t expectedCost = -1)
{
- auto entry = m_fib.findExactMatch(prefix);
- if (!static_cast<bool>(entry)) {
+ const fib::Entry* entry = m_fib.findExactMatch(prefix);
+ if (entry == nullptr) {
return CheckNextHopResult::NO_FIB_ENTRY;
}
- auto nextHops = entry->getNextHops();
+ const fib::NextHopList& nextHops = entry->getNextHops();
if (expectedNNextHops != -1 && nextHops.size() != static_cast<size_t>(expectedNNextHops)) {
return CheckNextHopResult::WRONG_N_NEXTHOPS;
}
if (faceId != face::FACEID_NULL) {
for (auto&& record : nextHops) {
- if (record.getFace()->getId() == faceId) {
+ if (record.getFace().getId() == faceId) {
return expectedCost != -1 && record.getCost() != static_cast<uint32_t>(expectedCost) ?
CheckNextHopResult::WRONG_COST : CheckNextHopResult::OK;
}
@@ -285,10 +285,10 @@
BOOST_REQUIRE_NE(face2, face::INVALID_FACEID);
BOOST_REQUIRE_NE(face3, face::INVALID_FACEID);
- shared_ptr<fib::Entry> entry = m_fib.insert("/hello").first;
- entry->addNextHop(m_faceTable.get(face1), 101);
- entry->addNextHop(m_faceTable.get(face2), 202);
- entry->addNextHop(m_faceTable.get(face3), 303);
+ fib::Entry* entry = m_fib.insert("/hello").first;
+ entry->addNextHop(*m_faceTable.get(face1), 101);
+ entry->addNextHop(*m_faceTable.get(face2), 202);
+ entry->addNextHop(*m_faceTable.get(face3), 303);
testRemoveNextHop(makeParameters("/hello", face1));
BOOST_REQUIRE_EQUAL(m_responses.size(), 1);
@@ -340,9 +340,9 @@
receiveInterest(command);
};
- shared_ptr<fib::Entry> entry = m_fib.insert("/hello").first;
- entry->addNextHop(m_faceTable.get(face1), 101);
- entry->addNextHop(m_faceTable.get(face2), 202);
+ fib::Entry* entry = m_fib.insert("/hello").first;
+ entry->addNextHop(*m_faceTable.get(face1), 101);
+ entry->addNextHop(*m_faceTable.get(face2), 202);
testWithImplicitFaceId(ControlParameters().setName("/hello").setFaceId(0), face1);
BOOST_REQUIRE_EQUAL(m_responses.size(), 1);
@@ -372,7 +372,7 @@
receiveInterest(command);
};
- m_fib.insert("/hello").first->addNextHop(m_faceTable.get(face1), 101);
+ m_fib.insert("/hello").first->addNextHop(*m_faceTable.get(face1), 101);
testRemoveNextHop(makeParameters("/hello", face2 + 100));
BOOST_REQUIRE_EQUAL(m_responses.size(), 1); // face does not exist
@@ -446,9 +446,9 @@
for (size_t i = 0 ; i < nEntries ; i ++) {
Name prefix = Name("test").appendSegment(i);
actualPrefixes.insert(prefix);
- auto fibEntry = m_fib.insert(prefix).first;
- fibEntry->addNextHop(m_faceTable.get(addFace()), std::numeric_limits<uint8_t>::max() - 1);
- fibEntry->addNextHop(m_faceTable.get(addFace()), std::numeric_limits<uint8_t>::max() - 2);
+ fib::Entry* fibEntry = m_fib.insert(prefix).first;
+ fibEntry->addNextHop(*m_faceTable.get(addFace()), std::numeric_limits<uint8_t>::max() - 1);
+ fibEntry->addNextHop(*m_faceTable.get(addFace()), std::numeric_limits<uint8_t>::max() - 2);
}
receiveInterest(makeInterest("/localhost/nfd/fib/list"));
@@ -476,7 +476,7 @@
const auto& nextHops = matchedEntry->getNextHops();
for (auto&& next : nextHops) {
ndn::nfd::NextHopRecord nextHopRecord;
- nextHopRecord.setFaceId(next.getFace()->getId());
+ nextHopRecord.setFaceId(next.getFace().getId());
nextHopRecord.setCost(next.getCost());
record.addNextHopRecord(nextHopRecord);
}
diff --git a/tests/daemon/table/fib.t.cpp b/tests/daemon/table/fib.t.cpp
index 30846f4..7071c19 100644
--- a/tests/daemon/table/fib.t.cpp
+++ b/tests/daemon/table/fib.t.cpp
@@ -31,174 +31,142 @@
#include "tests/test-common.hpp"
namespace nfd {
+namespace fib {
namespace tests {
+using namespace nfd::tests;
+
BOOST_AUTO_TEST_SUITE(Table)
BOOST_FIXTURE_TEST_SUITE(TestFib, BaseFixture)
-BOOST_AUTO_TEST_CASE(Entry)
+BOOST_AUTO_TEST_CASE(FibEntry)
{
Name prefix("ndn:/pxWhfFza");
shared_ptr<Face> face1 = make_shared<DummyFace>();
shared_ptr<Face> face2 = make_shared<DummyFace>();
- fib::Entry entry(prefix);
+ Entry entry(prefix);
BOOST_CHECK_EQUAL(entry.getPrefix(), prefix);
- const fib::NextHopList& nexthops1 = entry.getNextHops();
// []
- BOOST_CHECK_EQUAL(nexthops1.size(), 0);
+ BOOST_CHECK_EQUAL(entry.getNextHops().size(), 0);
- entry.addNextHop(face1, 20);
- const fib::NextHopList& nexthops2 = entry.getNextHops();
+ entry.addNextHop(*face1, 20);
// [(face1,20)]
- BOOST_CHECK_EQUAL(nexthops2.size(), 1);
- BOOST_CHECK_EQUAL(nexthops2.begin()->getFace(), face1);
- BOOST_CHECK_EQUAL(nexthops2.begin()->getCost(), 20);
+ BOOST_CHECK_EQUAL(entry.getNextHops().size(), 1);
+ BOOST_CHECK_EQUAL(&entry.getNextHops().begin()->getFace(), face1.get());
+ BOOST_CHECK_EQUAL(entry.getNextHops().begin()->getCost(), 20);
- entry.addNextHop(face1, 30);
- const fib::NextHopList& nexthops3 = entry.getNextHops();
+ entry.addNextHop(*face1, 30);
// [(face1,30)]
- BOOST_CHECK_EQUAL(nexthops3.size(), 1);
- BOOST_CHECK_EQUAL(nexthops3.begin()->getFace(), face1);
- BOOST_CHECK_EQUAL(nexthops3.begin()->getCost(), 30);
+ BOOST_CHECK_EQUAL(entry.getNextHops().size(), 1);
+ BOOST_CHECK_EQUAL(&entry.getNextHops().begin()->getFace(), face1.get());
+ BOOST_CHECK_EQUAL(entry.getNextHops().begin()->getCost(), 30);
- entry.addNextHop(face2, 40);
- const fib::NextHopList& nexthops4 = entry.getNextHops();
+ entry.addNextHop(*face2, 40);
// [(face1,30), (face2,40)]
- BOOST_CHECK_EQUAL(nexthops4.size(), 2);
- int i = -1;
- for (fib::NextHopList::const_iterator it = nexthops4.begin();
- it != nexthops4.end(); ++it) {
- ++i;
- switch (i) {
- case 0:
- BOOST_CHECK_EQUAL(it->getFace(), face1);
- BOOST_CHECK_EQUAL(it->getCost(), 30);
- break;
- case 1:
- BOOST_CHECK_EQUAL(it->getFace(), face2);
- BOOST_CHECK_EQUAL(it->getCost(), 40);
- break;
- }
+ BOOST_CHECK_EQUAL(entry.getNextHops().size(), 2);
+ {
+ NextHopList::const_iterator it = entry.getNextHops().begin();
+ BOOST_REQUIRE(it != entry.getNextHops().end());
+ BOOST_CHECK_EQUAL(&it->getFace(), face1.get());
+ BOOST_CHECK_EQUAL(it->getCost(), 30);
+
+ ++it;
+ BOOST_REQUIRE(it != entry.getNextHops().end());
+ BOOST_CHECK_EQUAL(&it->getFace(), face2.get());
+ BOOST_CHECK_EQUAL(it->getCost(), 40);
+
+ ++it;
+ BOOST_CHECK(it == entry.getNextHops().end());
}
- entry.addNextHop(face2, 10);
- const fib::NextHopList& nexthops5 = entry.getNextHops();
+ entry.addNextHop(*face2, 10);
// [(face2,10), (face1,30)]
- BOOST_CHECK_EQUAL(nexthops5.size(), 2);
- i = -1;
- for (fib::NextHopList::const_iterator it = nexthops5.begin();
- it != nexthops5.end(); ++it) {
- ++i;
- switch (i) {
- case 0:
- BOOST_CHECK_EQUAL(it->getFace(), face2);
- BOOST_CHECK_EQUAL(it->getCost(), 10);
- break;
- case 1:
- BOOST_CHECK_EQUAL(it->getFace(), face1);
- BOOST_CHECK_EQUAL(it->getCost(), 30);
- break;
- }
+ BOOST_CHECK_EQUAL(entry.getNextHops().size(), 2);
+ {
+ NextHopList::const_iterator it = entry.getNextHops().begin();
+ BOOST_REQUIRE(it != entry.getNextHops().end());
+ BOOST_CHECK_EQUAL(&it->getFace(), face2.get());
+ BOOST_CHECK_EQUAL(it->getCost(), 10);
+
+ ++it;
+ BOOST_REQUIRE(it != entry.getNextHops().end());
+ BOOST_CHECK_EQUAL(&it->getFace(), face1.get());
+ BOOST_CHECK_EQUAL(it->getCost(), 30);
+
+ ++it;
+ BOOST_CHECK(it == entry.getNextHops().end());
}
- entry.removeNextHop(face1);
- const fib::NextHopList& nexthops6 = entry.getNextHops();
+ entry.removeNextHop(*face1);
// [(face2,10)]
- BOOST_CHECK_EQUAL(nexthops6.size(), 1);
- BOOST_CHECK_EQUAL(nexthops6.begin()->getFace(), face2);
- BOOST_CHECK_EQUAL(nexthops6.begin()->getCost(), 10);
+ BOOST_CHECK_EQUAL(entry.getNextHops().size(), 1);
+ BOOST_CHECK_EQUAL(entry.getNextHops().begin()->getFace().getId(), face2->getId());
+ BOOST_CHECK_EQUAL(entry.getNextHops().begin()->getCost(), 10);
- entry.removeNextHop(face1);
- const fib::NextHopList& nexthops7 = entry.getNextHops();
+ entry.removeNextHop(*face1);
// [(face2,10)]
- BOOST_CHECK_EQUAL(nexthops7.size(), 1);
- BOOST_CHECK_EQUAL(nexthops7.begin()->getFace(), face2);
- BOOST_CHECK_EQUAL(nexthops7.begin()->getCost(), 10);
+ BOOST_CHECK_EQUAL(entry.getNextHops().size(), 1);
+ BOOST_CHECK_EQUAL(entry.getNextHops().begin()->getFace().getId(), face2->getId());
+ BOOST_CHECK_EQUAL(entry.getNextHops().begin()->getCost(), 10);
- entry.removeNextHop(face2);
- const fib::NextHopList& nexthops8 = entry.getNextHops();
+ entry.removeNextHop(*face2);
// []
- BOOST_CHECK_EQUAL(nexthops8.size(), 0);
+ BOOST_CHECK_EQUAL(entry.getNextHops().size(), 0);
- entry.removeNextHop(face2);
- const fib::NextHopList& nexthops9 = entry.getNextHops();
+ entry.removeNextHop(*face2);
// []
- BOOST_CHECK_EQUAL(nexthops9.size(), 0);
+ BOOST_CHECK_EQUAL(entry.getNextHops().size(), 0);
}
BOOST_AUTO_TEST_CASE(Insert_LongestPrefixMatch)
{
- Name nameEmpty;
- Name nameA ("ndn:/A");
- Name nameAB ("ndn:/A/B");
- Name nameABC ("ndn:/A/B/C");
- Name nameABCD("ndn:/A/B/C/D");
- Name nameE ("ndn:/E");
-
- std::pair<shared_ptr<fib::Entry>, bool> insertRes;
- shared_ptr<fib::Entry> entry;
-
NameTree nameTree;
Fib fib(nameTree);
+
// []
BOOST_CHECK_EQUAL(fib.size(), 0);
+ BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch("/A").getPrefix(), "/"); // the empty entry
- entry = fib.findLongestPrefixMatch(nameA);
- BOOST_REQUIRE(static_cast<bool>(entry)); // the empty entry
-
- insertRes = fib.insert(nameEmpty);
+ std::pair<Entry*, bool> insertRes = fib.insert("/");
BOOST_CHECK_EQUAL(insertRes.second, true);
- BOOST_CHECK_EQUAL(insertRes.first->getPrefix(), nameEmpty);
+ BOOST_REQUIRE(insertRes.first != nullptr);
+ BOOST_CHECK_EQUAL(insertRes.first->getPrefix(), "/");
// ['/']
BOOST_CHECK_EQUAL(fib.size(), 1);
- entry = fib.findLongestPrefixMatch(nameA);
- BOOST_REQUIRE(static_cast<bool>(entry));
- BOOST_CHECK_EQUAL(entry->getPrefix(), nameEmpty);
+ BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch("/A").getPrefix(), "/");
- insertRes = fib.insert(nameA);
+ insertRes = fib.insert("/A");
BOOST_CHECK_EQUAL(insertRes.second, true);
- BOOST_CHECK_EQUAL(insertRes.first->getPrefix(), nameA);
+ BOOST_REQUIRE(insertRes.first != nullptr);
+ BOOST_CHECK_EQUAL(insertRes.first->getPrefix(), "/A");
// ['/', '/A']
BOOST_CHECK_EQUAL(fib.size(), 2);
- insertRes = fib.insert(nameA);
+ insertRes = fib.insert("/A");
BOOST_CHECK_EQUAL(insertRes.second, false);
- BOOST_CHECK_EQUAL(insertRes.first->getPrefix(), nameA);
+ BOOST_REQUIRE(insertRes.first != nullptr);
+ BOOST_CHECK_EQUAL(insertRes.first->getPrefix(), "/A");
// ['/', '/A']
BOOST_CHECK_EQUAL(fib.size(), 2);
- entry = fib.findLongestPrefixMatch(nameA);
- BOOST_REQUIRE(static_cast<bool>(entry));
- BOOST_CHECK_EQUAL(entry->getPrefix(), nameA);
+ BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch("/A").getPrefix(), "/A");
- entry = fib.findLongestPrefixMatch(nameABCD);
- BOOST_REQUIRE(static_cast<bool>(entry));
- BOOST_CHECK_EQUAL(entry->getPrefix(), nameA);
+ BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch("/A/B/C/D").getPrefix(), "/A");
- insertRes = fib.insert(nameABC);
+ insertRes = fib.insert("/A/B/C");
BOOST_CHECK_EQUAL(insertRes.second, true);
- BOOST_CHECK_EQUAL(insertRes.first->getPrefix(), nameABC);
+ BOOST_REQUIRE(insertRes.first != nullptr);
+ BOOST_CHECK_EQUAL(insertRes.first->getPrefix(), "/A/B/C");
// ['/', '/A', '/A/B/C']
BOOST_CHECK_EQUAL(fib.size(), 3);
- entry = fib.findLongestPrefixMatch(nameA);
- BOOST_REQUIRE(static_cast<bool>(entry));
- BOOST_CHECK_EQUAL(entry->getPrefix(), nameA);
-
- entry = fib.findLongestPrefixMatch(nameAB);
- BOOST_REQUIRE(static_cast<bool>(entry));
- BOOST_CHECK_EQUAL(entry->getPrefix(), nameA);
-
- entry = fib.findLongestPrefixMatch(nameABCD);
- BOOST_REQUIRE(static_cast<bool>(entry));
- BOOST_CHECK_EQUAL(entry->getPrefix(), nameABC);
-
- entry = fib.findLongestPrefixMatch(nameE);
- BOOST_REQUIRE(static_cast<bool>(entry));
- BOOST_CHECK_EQUAL(entry->getPrefix(), nameEmpty);
+ BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch("/A").getPrefix(), "/A");
+ BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch("/A/B").getPrefix(), "/A");
+ BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch("/A/B/C/D").getPrefix(), "/A/B/C");
+ BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch("/E").getPrefix(), "/");
}
BOOST_AUTO_TEST_CASE(LongestPrefixMatchWithPitEntry)
@@ -221,21 +189,13 @@
shared_ptr<Interest> interestADE = makeInterest(fullNameADE);
shared_ptr<pit::Entry> pitADE = pit.insert(*interestADE).first;
- size_t nNameTreeEntries = nameTree.size();
+ size_t nNameTreeEntriesBefore = nameTree.size();
- shared_ptr<fib::Entry> entry = fib.findLongestPrefixMatch(*pitAB);
- BOOST_REQUIRE(entry != nullptr);
- BOOST_CHECK_EQUAL(entry->getPrefix(), "/A");
+ BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch(*pitAB).getPrefix(), "/A");
+ BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch(*pitABC).getPrefix(), fullNameABC);
+ BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch(*pitADE).getPrefix(), "/A");
- entry = fib.findLongestPrefixMatch(*pitABC);
- BOOST_REQUIRE(entry != nullptr);
- BOOST_CHECK_EQUAL(entry->getPrefix(), fullNameABC);
-
- entry = fib.findLongestPrefixMatch(*pitADE);
- BOOST_REQUIRE(entry != nullptr);
- BOOST_CHECK_EQUAL(entry->getPrefix(), "/A");
-
- BOOST_CHECK_EQUAL(nameTree.size(), nNameTreeEntries);
+ BOOST_CHECK_EQUAL(nameTree.size(), nNameTreeEntriesBefore);
}
BOOST_AUTO_TEST_CASE(LongestPrefixMatchWithMeasurementsEntry)
@@ -250,79 +210,57 @@
shared_ptr<measurements::Entry> mAB = measurements.get("/A/B");
shared_ptr<measurements::Entry> mABCD = measurements.get("/A/B/C/D");
- shared_ptr<fib::Entry> entry = fib.findLongestPrefixMatch(*mAB);
- BOOST_REQUIRE(entry != nullptr);
- BOOST_CHECK_EQUAL(entry->getPrefix(), "/A");
-
- entry = fib.findLongestPrefixMatch(*mABCD);
- BOOST_REQUIRE(entry != nullptr);
- BOOST_CHECK_EQUAL(entry->getPrefix(), "/A/B/C");
+ BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch(*mAB).getPrefix(), "/A");
+ BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch(*mABCD).getPrefix(), "/A/B/C");
}
BOOST_AUTO_TEST_CASE(RemoveNextHopFromAllEntries)
{
shared_ptr<Face> face1 = make_shared<DummyFace>();
shared_ptr<Face> face2 = make_shared<DummyFace>();
- Name nameEmpty("ndn:/");
- Name nameA("ndn:/A");
- Name nameB("ndn:/B");
-
- std::pair<shared_ptr<fib::Entry>, bool> insertRes;
- shared_ptr<fib::Entry> entry;
NameTree nameTree;
Fib fib(nameTree);
// {}
- insertRes = fib.insert(nameA);
- insertRes.first->addNextHop(face1, 0);
- insertRes.first->addNextHop(face2, 0);
+ Entry* entryA = fib.insert("/A").first;
+ entryA->addNextHop(*face1, 0);
+ entryA->addNextHop(*face2, 0);
// {'/A':[1,2]}
- insertRes = fib.insert(nameB);
- insertRes.first->addNextHop(face1, 0);
+ Entry* entryB = fib.insert("/B").first;
+ entryB->addNextHop(*face1, 0);
// {'/A':[1,2], '/B':[1]}
BOOST_CHECK_EQUAL(fib.size(), 2);
- insertRes = fib.insert("/C");
- insertRes.first->addNextHop(face2, 1);
+ Entry* entryC = fib.insert("/C").first;
+ entryC->addNextHop(*face2, 1);
// {'/A':[1,2], '/B':[1], '/C':[2]}
BOOST_CHECK_EQUAL(fib.size(), 3);
- insertRes = fib.insert("/B/1");
- insertRes.first->addNextHop(face1, 0);
+ Entry* entryB1 = fib.insert("/B/1").first;
+ entryB1->addNextHop(*face1, 0);
// {'/A':[1,2], '/B':[1], '/B/1':[1], '/C':[2]}
BOOST_CHECK_EQUAL(fib.size(), 4);
- insertRes = fib.insert("/B/1/2");
- insertRes.first->addNextHop(face1, 0);
+ Entry* entryB12 = fib.insert("/B/1/2").first;
+ entryB12->addNextHop(*face1, 0);
// {'/A':[1,2], '/B':[1], '/B/1':[1], '/B/1/2':[1], '/C':[2]}
BOOST_CHECK_EQUAL(fib.size(), 5);
- insertRes = fib.insert("/B/1/2/3");
- insertRes.first->addNextHop(face1, 0);
- // {'/A':[1,2], '/B':[1], '/B/1':[1], '/B/1/2':[1], '/B/1/3':[1], '/C':[2]}
- BOOST_CHECK_EQUAL(fib.size(), 6);
-
- insertRes = fib.insert("/B/1/2/3/4");
- insertRes.first->addNextHop(face1, 0);
- // {'/A':[1,2], '/B':[1], '/B/1':[1], '/B/1/2':[1], '/B/1/2/3':[1], '/B/1/2/3/4':[1], '/C':[2]}
- BOOST_CHECK_EQUAL(fib.size(), 7);
-
/////////////
- fib.removeNextHopFromAllEntries(face1);
+ fib.removeNextHopFromAllEntries(*face1);
// {'/A':[2], '/C':[2]}
BOOST_CHECK_EQUAL(fib.size(), 2);
- entry = fib.findLongestPrefixMatch(nameA);
- BOOST_CHECK_EQUAL(entry->getPrefix(), nameA);
- const fib::NextHopList& nexthopsA = entry->getNextHops();
+ const Entry& foundA = fib.findLongestPrefixMatch("/A");
+ BOOST_CHECK_EQUAL(foundA.getPrefix(), "/A");
+ const NextHopList& nexthopsA = foundA.getNextHops();
BOOST_CHECK_EQUAL(nexthopsA.size(), 1);
- BOOST_CHECK_EQUAL(nexthopsA.begin()->getFace(), face2);
+ BOOST_CHECK_EQUAL(&nexthopsA.begin()->getFace(), face2.get());
- entry = fib.findLongestPrefixMatch(nameB);
- BOOST_CHECK_EQUAL(entry->getPrefix(), nameEmpty);
+ BOOST_CHECK_EQUAL(fib.findLongestPrefixMatch("/B").getPrefix(), "/");
}
BOOST_AUTO_TEST_CASE(RemoveNextHopFromManyEntries)
@@ -332,40 +270,32 @@
shared_ptr<Face> face1 = make_shared<DummyFace>();
for (uint64_t i = 0; i < 300; ++i) {
- shared_ptr<fib::Entry> entry = fib.insert(Name("/P").appendVersion(i)).first;
- entry->addNextHop(face1, 0);
+ Entry* entry = fib.insert(Name("/P").appendVersion(i)).first;
+ entry->addNextHop(*face1, 0);
}
BOOST_CHECK_EQUAL(fib.size(), 300);
- fib.removeNextHopFromAllEntries(face1);
+ fib.removeNextHopFromAllEntries(*face1);
BOOST_CHECK_EQUAL(fib.size(), 0);
}
void
-validateFindExactMatch(const Fib& fib, const Name& target)
+validateFindExactMatch(Fib& fib, const Name& target)
{
- shared_ptr<fib::Entry> entry = fib.findExactMatch(target);
- if (static_cast<bool>(entry))
- {
- BOOST_CHECK_EQUAL(entry->getPrefix(), target);
- }
- else
- {
- BOOST_FAIL("No entry found for " << target);
- }
+ const Entry* entry = fib.findExactMatch(target);
+ BOOST_REQUIRE_MESSAGE(entry != nullptr, "No entry found for " << target);
+ BOOST_CHECK_EQUAL(entry->getPrefix(), target);
}
void
-validateNoExactMatch(const Fib& fib, const Name& target)
+validateNoExactMatch(Fib& fib, const Name& target)
{
- shared_ptr<fib::Entry> entry = fib.findExactMatch(target);
- if (static_cast<bool>(entry))
- {
- BOOST_FAIL("Found unexpected entry for " << target);
- }
+ const Entry* entry = fib.findExactMatch(target);
+ BOOST_CHECK_MESSAGE(entry == nullptr,
+ "Found unexpected entry for " << target);
}
-BOOST_AUTO_TEST_CASE(FindExactMatch)
+BOOST_AUTO_TEST_CASE(ExactMatch)
{
NameTree nameTree;
Fib fib(nameTree);
@@ -376,20 +306,27 @@
validateFindExactMatch(fib, "/A");
validateFindExactMatch(fib, "/A/B");
validateFindExactMatch(fib, "/A/B/C");
+
validateNoExactMatch(fib, "/");
-
validateNoExactMatch(fib, "/does/not/exist");
+}
- NameTree gapNameTree;
- Fib gapFib(nameTree);
+BOOST_AUTO_TEST_CASE(ExactMatchGap)
+{
+ NameTree nameTree;
+ Fib fib(nameTree);
fib.insert("/X");
fib.insert("/X/Y/Z");
- validateNoExactMatch(gapFib, "/X/Y");
+ validateNoExactMatch(fib, "/X/Y");
+}
- NameTree emptyNameTree;
- Fib emptyFib(emptyNameTree);
- validateNoExactMatch(emptyFib, "/nothing/here");
+BOOST_AUTO_TEST_CASE(ExactMatchEmpty)
+{
+ NameTree nameTree;
+ Fib fib(nameTree);
+ validateNoExactMatch(fib, "/");
+ validateNoExactMatch(fib, "/nothing/here");
}
void
@@ -397,24 +334,12 @@
{
fib.erase(target);
- shared_ptr<fib::Entry> entry = fib.findExactMatch(target);
- if (static_cast<bool>(entry))
- {
- BOOST_FAIL("Found \"removed\" entry for " << target);
- }
+ const Entry* entry = fib.findExactMatch(target);
+ BOOST_CHECK_MESSAGE(entry == nullptr, "Found \"removed\" entry for " << target);
}
BOOST_AUTO_TEST_CASE(Erase)
{
- NameTree emptyNameTree;
- Fib emptyFib(emptyNameTree);
-
- emptyFib.erase("/does/not/exist"); // crash test
-
- validateErase(emptyFib, "/");
-
- emptyFib.erase("/still/does/not/exist"); // crash test
-
NameTree nameTree;
Fib fib(nameTree);
fib.insert("/");
@@ -439,15 +364,28 @@
validateErase(fib, "/");
validateNoExactMatch(fib, "/");
+}
- NameTree gapNameTree;
- Fib gapFib(gapNameTree);
- gapFib.insert("/X");
- gapFib.insert("/X/Y/Z");
+BOOST_AUTO_TEST_CASE(EraseGap)
+{
+ NameTree nameTree;
+ Fib fib(nameTree);
+ fib.insert("/X");
+ fib.insert("/X/Y/Z");
- gapFib.erase("/X/Y"); //should do nothing
- validateFindExactMatch(gapFib, "/X");
- validateFindExactMatch(gapFib, "/X/Y/Z");
+ fib.erase("/X/Y"); //should do nothing
+ validateFindExactMatch(fib, "/X");
+ validateFindExactMatch(fib, "/X/Y/Z");
+}
+
+BOOST_AUTO_TEST_CASE(EraseEmpty)
+{
+ NameTree nameTree;
+ Fib fib(nameTree);
+
+ BOOST_CHECK_NO_THROW(fib.erase("/does/not/exist"));
+ validateErase(fib, "/");
+ BOOST_CHECK_NO_THROW(fib.erase("/still/does/not/exist"));
}
BOOST_AUTO_TEST_CASE(EraseNameTreeEntry)
@@ -456,8 +394,8 @@
Fib fib(nameTree);
size_t nNameTreeEntriesBefore = nameTree.size();
- fib.insert("ndn:/A/B/C");
- fib.erase("ndn:/A/B/C");
+ fib.insert("/A/B/C");
+ fib.erase("/A/B/C");
BOOST_CHECK_EQUAL(nameTree.size(), nNameTreeEntriesBefore);
}
@@ -475,11 +413,7 @@
fib.insert(nameABC);
fib.insert(nameRoot);
- std::set<Name> expected;
- expected.insert(nameA);
- expected.insert(nameAB);
- expected.insert(nameABC);
- expected.insert(nameRoot);
+ std::set<Name> expected{nameA, nameAB, nameABC, nameRoot};
for (Fib::const_iterator it = fib.begin(); it != fib.end(); it++) {
bool isInSet = expected.find(it->getPrefix()) != expected.end();
@@ -494,4 +428,5 @@
BOOST_AUTO_TEST_SUITE_END() // Table
} // namespace tests
+} // namespace fib
} // namespace nfd
diff --git a/tests/daemon/table/measurements.t.cpp b/tests/daemon/table/measurements.t.cpp
index bbf1903..c8b2e27 100644
--- a/tests/daemon/table/measurements.t.cpp
+++ b/tests/daemon/table/measurements.t.cpp
@@ -70,8 +70,8 @@
{
Fib fib(nameTree);
- shared_ptr<fib::Entry> fibA = fib.insert("/A").first;
- shared_ptr<fib::Entry> fibAB = fib.insert("/A/B").first;
+ const fib::Entry* fibA = fib.insert("/A").first;
+ const fib::Entry* fibAB = fib.insert("/A/B").first;
shared_ptr<measurements::Entry> entryA = measurements.get(*fibA);
BOOST_REQUIRE(entryA != nullptr);
@@ -86,9 +86,9 @@
{
Fib fib(nameTree);
- shared_ptr<fib::Entry> fib0 = fib.findLongestPrefixMatch("/");
+ const fib::Entry& fib0 = fib.findLongestPrefixMatch("/");
- shared_ptr<measurements::Entry> entry0 = measurements.get(*fib0);
+ shared_ptr<measurements::Entry> entry0 = measurements.get(fib0);
BOOST_REQUIRE(entry0 != nullptr);
BOOST_CHECK_EQUAL(entry0->getName(), "/");
}
diff --git a/tests/daemon/table/name-tree.t.cpp b/tests/daemon/table/name-tree.t.cpp
index 2a5bd40..a79e2d5 100644
--- a/tests/daemon/table/name-tree.t.cpp
+++ b/tests/daemon/table/name-tree.t.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,
@@ -66,8 +66,8 @@
std::vector<shared_ptr<name_tree::Entry> >& childList = npe->getChildren();
BOOST_CHECK_EQUAL(childList.size(), static_cast<size_t>(0));
- shared_ptr<fib::Entry> fib = npe->getFibEntry();
- BOOST_CHECK(!static_cast<bool>(fib));
+ fib::Entry* fib = npe->getFibEntry();
+ BOOST_CHECK(fib == nullptr);
const std::vector< shared_ptr<pit::Entry> >& pitList = npe->getPitEntries();
BOOST_CHECK_EQUAL(pitList.size(), static_cast<size_t>(0));
@@ -84,14 +84,12 @@
// Insert FIB
- shared_ptr<fib::Entry> fibEntry(new fib::Entry(prefix));
- shared_ptr<fib::Entry> fibEntryParent(new fib::Entry(parentName));
+ npe->setFibEntry(make_unique<fib::Entry>(prefix));
+ BOOST_REQUIRE(npe->getFibEntry() != nullptr);
+ BOOST_CHECK_EQUAL(npe->getFibEntry()->getPrefix(), prefix);
- npe->setFibEntry(fibEntry);
- BOOST_CHECK_EQUAL(npe->getFibEntry(), fibEntry);
-
- npe->setFibEntry(shared_ptr<fib::Entry>());
- BOOST_CHECK(!static_cast<bool>(npe->getFibEntry()));
+ npe->setFibEntry(nullptr);
+ BOOST_CHECK(npe->getFibEntry() == nullptr);
// Insert a PIT