core: global io_service and scheduler
Scheduler and time are imported from ndn-cpp-dev.
Forwarder is using the new scheduler API.
Face system is not transitioned yet.
refs #1290
Change-Id: I5679cb50bbf9890a105f663b038f13951403c2b6
diff --git a/daemon/fw/forwarder.cpp b/daemon/fw/forwarder.cpp
index 8f6f015..4cc93d0 100644
--- a/daemon/fw/forwarder.cpp
+++ b/daemon/fw/forwarder.cpp
@@ -14,10 +14,8 @@
const Name Forwarder::s_localhostName("ndn:/localhost");
-Forwarder::Forwarder(boost::asio::io_service& ioService)
- : m_scheduler(ioService)
- , m_lastFaceId(0)
- , m_measurements(ioService)
+Forwarder::Forwarder()
+ : m_lastFaceId(0)
{
m_strategy = make_shared<fw::BestRouteStrategy>(boost::ref(*this));
}
@@ -43,12 +41,12 @@
m_faces.erase(faceId);
face->setId(INVALID_FACEID);
NFD_LOG_INFO("removeFace id=" << faceId);
-
+
// XXX This clears all subscriptions, because EventEmitter
// does not support only removing Forwarder's subscription
face->onReceiveInterest.clear();
face->onReceiveData .clear();
-
+
m_fib.removeNextHopFromAllEntries(face);
}
@@ -77,7 +75,7 @@
// receive Interest
NFD_LOG_DEBUG("onIncomingInterest face=" << inFace.getId() << " interest=" << interest.getName());
const_cast<Interest&>(interest).setIncomingFaceId(inFace.getId());
-
+
// /localhost scope control
bool violatesLocalhost = !inFace.isLocal() &&
s_localhostName.isPrefixOf(interest.getName());
@@ -86,12 +84,12 @@
<< " interest=" << interest.getName() << " violates /localhost");
return;
}
-
+
// PIT insert
std::pair<shared_ptr<pit::Entry>, bool>
pitInsertResult = m_pit.insert(interest);
shared_ptr<pit::Entry> pitEntry = pitInsertResult.first;
-
+
// detect loop and record Nonce
bool isLoop = ! pitEntry->addNonce(interest.getNonce());
if (isLoop) {
@@ -99,13 +97,13 @@
this->onInterestLoop(inFace, interest, pitEntry);
return;
}
-
+
// cancel unsatisfy & straggler timer
this->cancelUnsatisfyAndStragglerTimer(pitEntry);
-
+
const pit::InRecordCollection& inRecords = pitEntry->getInRecords();
bool isPending = inRecords.begin() == inRecords.end();
-
+
if (!isPending) {
// CS lookup
const Data* csMatch = m_cs.find(interest);
@@ -117,23 +115,23 @@
return;
}
}
-
+
// insert InRecord
pit::InRecordCollection::iterator inRecordIt =
pitEntry->insertOrUpdateInRecord(inFace.shared_from_this(), interest);
-
+
// app chosen nexthops
bool isAppChosenNexthops = false; // TODO get from local control header
if (isAppChosenNexthops) {
// TODO foreach chosen nexthop: goto outgoing Interest pipeline
return;
}
-
+
// FIB lookup
shared_ptr<fib::Entry> fibEntry
= m_fib.findLongestPrefixMatch(interest.getName());
// TODO use Fib::findParent(pitEntry)
-
+
// dispatch to strategy
this->dispatchToStrategy(inFace, interest, fibEntry, pitEntry);
}
@@ -155,14 +153,14 @@
// pick Interest
const Interest& interest = pitEntry->getInterest();
// TODO pick the last incoming Interest
-
+
// insert OutRecord
pit::OutRecordCollection::iterator outRecordIt =
pitEntry->insertOrUpdateOutRecord(outFace.shared_from_this(), interest);
-
+
// set PIT unsatisfy timer
this->setUnsatisfyTimer(pitEntry);
-
+
// send Interest
outFace.sendInterest(interest);
}
@@ -183,7 +181,7 @@
// invoke PIT unsatisfied callback
// TODO
-
+
// PIT delete
m_pit.remove(pitEntry);
}
@@ -194,7 +192,7 @@
// receive Data
NFD_LOG_DEBUG("onIncomingData face=" << inFace.getId() << " data=" << data.getName());
const_cast<Data&>(data).setIncomingFaceId(inFace.getId());
-
+
// /localhost scope control
bool violatesLocalhost = !inFace.isLocal() &&
s_localhostName.isPrefixOf(data.getName());
@@ -203,7 +201,7 @@
<< " interest=" << data.getName() << " violates /localhost");
return;
}
-
+
// PIT match
shared_ptr<pit::DataMatchResult> pitMatches = m_pit.findAllDataMatches(data);
if (pitMatches->begin() == pitMatches->end()) {
@@ -211,20 +209,20 @@
this->onDataUnsolicited(inFace, data);
return;
}
-
+
// CS insert
m_cs.insert(data);
-
+
std::set<shared_ptr<Face> > pendingDownstreams;
// foreach PitEntry
for (pit::DataMatchResult::iterator it = pitMatches->begin();
it != pitMatches->end(); ++it) {
shared_ptr<pit::Entry> pitEntry = *it;
NFD_LOG_DEBUG("onIncomingData matching=" << pitEntry->getName());
-
+
// cancel unsatisfy & straggler timer
this->cancelUnsatisfyAndStragglerTimer(pitEntry);
-
+
// remember pending downstreams
const pit::InRecordCollection& inRecords = pitEntry->getInRecords();
for (pit::InRecordCollection::const_iterator it = inRecords.begin();
@@ -233,18 +231,18 @@
pendingDownstreams.insert(it->getFace());
}
}
-
+
// mark PIT satisfied
pitEntry->deleteInRecords();
pitEntry->deleteOutRecord(inFace.shared_from_this());
-
+
// set PIT straggler timer
this->setStragglerTimer(pitEntry);
-
+
// invoke PIT satisfy callback
// TODO
}
-
+
// foreach pending downstream
for (std::set<shared_ptr<Face> >::iterator it = pendingDownstreams.begin();
it != pendingDownstreams.end(); ++it) {
@@ -273,7 +271,7 @@
// traffic manager
// pass through
-
+
// send Data
outFace.sendData(data);
}
@@ -297,8 +295,8 @@
if (lastExpiryFromNow <= time::seconds(0)) {
// TODO all InRecords are already expired; will this happen?
}
-
- pitEntry->m_unsatisfyTimer = m_scheduler.scheduleEvent(lastExpiryFromNow,
+
+ pitEntry->m_unsatisfyTimer = scheduler::schedule(lastExpiryFromNow,
bind(&Forwarder::onInterestUnsatisfied, this, pitEntry));
}
@@ -306,16 +304,16 @@
Forwarder::setStragglerTimer(shared_ptr<pit::Entry> pitEntry)
{
time::Duration stragglerTime = time::milliseconds(100);
-
- pitEntry->m_stragglerTimer = m_scheduler.scheduleEvent(stragglerTime,
+
+ pitEntry->m_stragglerTimer = scheduler::schedule(stragglerTime,
bind(&Pit::remove, &m_pit, pitEntry));
}
void
Forwarder::cancelUnsatisfyAndStragglerTimer(shared_ptr<pit::Entry> pitEntry)
{
- m_scheduler.cancelEvent(pitEntry->m_unsatisfyTimer);
- m_scheduler.cancelEvent(pitEntry->m_stragglerTimer);
+ scheduler::cancel(pitEntry->m_unsatisfyTimer);
+ scheduler::cancel(pitEntry->m_stragglerTimer);
}
void