core+daemon: eliminate scheduler::{schedule,cancel} wrappers

Also move core/global-io.hpp to daemon/global.hpp

Refs: #4528, #4883
Change-Id: I0b99029f1a19d7451aab57099cd3303b7eb42ff3
This commit is contained in:
Davide Pesavento authored and Junxiao Shi committed 2019-03-19 11:29:56 -06:00
1 parent 2d83a86255
commit 3dade00499
101 files changed
+338 -514

No files matched your search

+4
View File
@@ -66,7 +66,9 @@
#include <ndn-cxx/net/face-uri.hpp>
#include <ndn-cxx/util/backports.hpp>
#include <ndn-cxx/util/exception.hpp>
#include <ndn-cxx/util/scheduler.hpp>
#include <ndn-cxx/util/signal.hpp>
#include <ndn-cxx/util/time.hpp>
#include <boost/asio.hpp>
#include <boost/assert.hpp>
@@ -106,6 +108,7 @@ using ndn::FaceUri;
using ndn::Interest;
using ndn::Name;
using ndn::PartialName;
using ndn::Scheduler;
// Not using a namespace alias (namespace tlv = ndn::tlv), because
// it doesn't allow NFD to add other members to the namespace
@@ -115,6 +118,7 @@ using namespace ndn::tlv;
namespace lp = ndn::lp;
namespace name = ndn::name;
namespace scheduler = ndn::scheduler;
namespace signal = ndn::util::signal;
namespace time = ndn::time;
using namespace ndn::time_literals;
-58
View File
@@ -1,58 +0,0 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
* Washington University in St. Louis,
* Beijing Institute of Technology,
* The University of Memphis.
*
* This file is part of NFD (Named Data Networking Forwarding Daemon).
* See AUTHORS.md for complete list of NFD authors and contributors.
*
* NFD is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
#include "scheduler.hpp"
#include "global-io.hpp"
namespace nfd {
namespace scheduler {
static thread_local unique_ptr<Scheduler> g_scheduler;
Scheduler&
getGlobalScheduler()
{
if (g_scheduler == nullptr) {
g_scheduler = make_unique<Scheduler>(getGlobalIoService());
}
return *g_scheduler;
}
EventId
schedule(time::nanoseconds after, const EventCallback& event)
{
return getGlobalScheduler().scheduleEvent(after, event);
}
#ifdef WITH_TESTS
void
resetGlobalScheduler()
{
g_scheduler.reset();
}
#endif
} // namespace scheduler
} // namespace nfd
-57
View File
@@ -1,57 +0,0 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
* Washington University in St. Louis,
* Beijing Institute of Technology,
* The University of Memphis.
*
* This file is part of NFD (Named Data Networking Forwarding Daemon).
* See AUTHORS.md for complete list of NFD authors and contributors.
*
* NFD is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef NFD_CORE_SCHEDULER_HPP
#define NFD_CORE_SCHEDULER_HPP
#include "common.hpp"
#include <ndn-cxx/util/scheduler.hpp>
namespace nfd {
namespace scheduler {
using ndn::util::scheduler::Scheduler;
using ndn::util::scheduler::EventId;
using ndn::util::scheduler::ScopedEventId;
using ndn::util::scheduler::EventCallback;
/** \brief Schedule an event.
*/
EventId
schedule(time::nanoseconds after, const EventCallback& event);
/** \brief Cancel a scheduled event.
*/
inline void
cancel(EventId eventId)
{
eventId.cancel();
}
} // namespace scheduler
} // namespace nfd
#endif // NFD_CORE_SCHEDULER_HPP
+1 -1
View File
@@ -28,7 +28,7 @@
#include "transport.hpp"
#include "socket-utils.hpp"
#include "core/global-io.hpp"
#include "daemon/global.hpp"
#include <array>
+1 -1
View File
@@ -27,7 +27,7 @@
#include "ethernet-protocol.hpp"
#include "generic-link-service.hpp"
#include "unicast-ethernet-transport.hpp"
#include "core/global-io.hpp"
#include "daemon/global.hpp"
#include <boost/range/adaptor/map.hpp>
#include <pcap/pcap.h>
+1 -1
View File
@@ -25,7 +25,7 @@
#include "ethernet-transport.hpp"
#include "ethernet-protocol.hpp"
#include "core/global-io.hpp"
#include "daemon/global.hpp"
#include <pcap/pcap.h>
+1 -1
View File
@@ -26,7 +26,7 @@
#include "face-system.hpp"
#include "protocol-factory.hpp"
#include "netdev-bound.hpp"
#include "core/global-io.hpp"
#include "daemon/global.hpp"
#include "fw/face-table.hpp"
namespace nfd {
+3 -3
View File
@@ -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-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -26,7 +26,7 @@
#include "internal-face.hpp"
#include "generic-link-service.hpp"
#include "internal-transport.hpp"
#include "core/global-io.hpp"
#include "daemon/global.hpp"
namespace nfd {
namespace face {
+2 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2018, Regents of the University of California,
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -24,7 +24,7 @@
*/
#include "internal-transport.hpp"
#include "core/global-io.hpp"
#include "daemon/global.hpp"
namespace nfd {
namespace face {
+2 -1
View File
@@ -25,6 +25,7 @@
#include "lp-reassembler.hpp"
#include "link-service.hpp"
#include "daemon/global.hpp"
#include <numeric>
@@ -113,7 +114,7 @@ LpReassembler::receiveFragment(EndpointId remoteEndpoint, const lp::Packet& pack
}
// set drop timer
pp.dropTimer = scheduler::schedule(m_options.reassemblyTimeout, [=] { timeoutPartialPacket(key); });
pp.dropTimer = getScheduler().schedule(m_options.reassemblyTimeout, [=] { timeoutPartialPacket(key); });
return FALSE_RETURN;
}
+1 -2
View File
@@ -26,7 +26,6 @@
#ifndef NFD_DAEMON_FACE_LP_REASSEMBLER_HPP
#define NFD_DAEMON_FACE_LP_REASSEMBLER_HPP
#include "core/scheduler.hpp"
#include "face-log.hpp"
#include "transport.hpp"
@@ -125,8 +124,8 @@ private:
private:
Options m_options;
std::map<Key, PartialPacket> m_partialPackets;
const LinkService* m_linkService;
std::map<Key, PartialPacket> m_partialPackets;
};
std::ostream&
+5 -4
View File
@@ -26,6 +26,7 @@
#include "lp-reliability.hpp"
#include "generic-link-service.hpp"
#include "transport.hpp"
#include "daemon/global.hpp"
namespace nfd {
namespace face {
@@ -38,7 +39,6 @@ LpReliability::LpReliability(const LpReliability::Options& options, GenericLinkS
, m_isIdleAckTimerRunning(false)
{
BOOST_ASSERT(m_linkService != nullptr);
BOOST_ASSERT(m_options.idleAckTimerPeriod > 0_ns);
}
@@ -81,7 +81,8 @@ LpReliability::handleOutgoing(std::vector<lp::Packet>& frags, lp::Packet&& pkt,
std::forward_as_tuple(txSeq),
std::forward_as_tuple(frag));
unackedFragsIt->second.sendTime = sendTime;
unackedFragsIt->second.rtoTimer = scheduler::schedule(m_rto.computeRto(), [=] { onLpPacketLost(txSeq); });
unackedFragsIt->second.rtoTimer = getScheduler().schedule(m_rto.computeRto(),
[=] { onLpPacketLost(txSeq); });
unackedFragsIt->second.netPkt = netPkt;
if (m_unackedFrags.size() == 1) {
@@ -199,7 +200,7 @@ LpReliability::startIdleAckTimer()
BOOST_ASSERT(!m_isIdleAckTimerRunning);
m_isIdleAckTimerRunning = true;
m_idleAckTimer = scheduler::schedule(m_options.idleAckTimerPeriod, [this] {
m_idleAckTimer = getScheduler().schedule(m_options.idleAckTimerPeriod, [this] {
while (!m_ackQueue.empty()) {
m_linkService->requestIdlePacket();
}
@@ -304,7 +305,7 @@ LpReliability::onLpPacketLost(lp::Sequence txSeq)
m_linkService->sendLpPacket(lp::Packet(newTxFrag.pkt));
// Start RTO timer for this sequence
newTxFrag.rtoTimer = scheduler::schedule(m_rto.computeRto(), [=] { onLpPacketLost(newTxSeq); });
newTxFrag.rtoTimer = getScheduler().schedule(m_rto.computeRto(), [=] { onLpPacketLost(newTxSeq); });
}
return removedThisTxSeq;
+1 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2018, Regents of the University of California,
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -27,7 +27,6 @@
#define NFD_DAEMON_FACE_LP_RELIABILITY_HPP
#include "core/rtt-estimator.hpp"
#include "core/scheduler.hpp"
#include <ndn-cxx/lp/packet.hpp>
#include <ndn-cxx/lp/sequence.hpp>
+1 -1
View File
@@ -24,7 +24,7 @@
*/
#include "multicast-ethernet-transport.hpp"
#include "core/global-io.hpp"
#include "daemon/global.hpp"
#include <cerrno> // for errno
#include <cstring> // for memcpy(), strerror(), strncpy()
+2 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2018, Regents of the University of California,
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -28,7 +28,7 @@
#include "transport.hpp"
#include "socket-utils.hpp"
#include "core/global-io.hpp"
#include "daemon/global.hpp"
#include <queue>
+4 -4
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2018, Regents of the University of California,
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -24,9 +24,9 @@
*/
#include "tcp-channel.hpp"
#include "core/global-io.hpp"
#include "generic-link-service.hpp"
#include "tcp-transport.hpp"
#include "daemon/global.hpp"
namespace nfd {
namespace face {
@@ -84,7 +84,7 @@ TcpChannel::connect(const tcp::Endpoint& remoteEndpoint,
}
auto clientSocket = make_shared<ip::tcp::socket>(std::ref(getGlobalIoService()));
auto timeoutEvent = scheduler::schedule(timeout, [=] {
auto timeoutEvent = getScheduler().schedule(timeout, [=] {
handleConnectTimeout(remoteEndpoint, clientSocket, onConnectFailed);
});
@@ -187,7 +187,7 @@ TcpChannel::handleConnect(const boost::system::error_code& error,
const FaceCreatedCallback& onFaceCreated,
const FaceCreationFailedCallback& onConnectFailed)
{
scheduler::cancel(connectTimeoutEvent);
connectTimeoutEvent.cancel();
if (error) {
if (error != boost::asio::error::operation_aborted) {
+1 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2018, Regents of the University of California,
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -27,7 +27,6 @@
#define NFD_DAEMON_FACE_TCP_CHANNEL_HPP
#include "channel.hpp"
#include "core/scheduler.hpp"
namespace nfd {
+9 -5
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2018, Regents of the University of California,
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -24,6 +24,7 @@
*/
#include "tcp-transport.hpp"
#include "daemon/global.hpp"
#if defined(__linux__)
#include <linux/sockios.h>
@@ -39,7 +40,9 @@ time::milliseconds TcpTransport::s_initialReconnectWait = 1_s;
time::milliseconds TcpTransport::s_maxReconnectWait = 5_min;
float TcpTransport::s_reconnectWaitMultiplier = 2.0f;
TcpTransport::TcpTransport(protocol::socket&& socket, ndn::nfd::FacePersistency persistency, ndn::nfd::FaceScope faceScope)
TcpTransport::TcpTransport(protocol::socket&& socket,
ndn::nfd::FacePersistency persistency,
ndn::nfd::FaceScope faceScope)
: StreamTransport(std::move(socket))
, m_remoteEndpoint(m_socket.remote_endpoint())
, m_nextReconnectWait(s_initialReconnectWait)
@@ -103,8 +106,8 @@ TcpTransport::handleError(const boost::system::error_code& error)
this->setState(TransportState::DOWN);
// cancel all outstanding operations
boost::system::error_code error;
m_socket.cancel(error);
boost::system::error_code ec;
m_socket.cancel(ec);
// do this asynchronously because there could be some callbacks still pending
getGlobalIoService().post([this] { reconnect(); });
@@ -134,7 +137,8 @@ TcpTransport::reconnect()
this->resetReceiveBuffer();
this->resetSendQueue();
m_reconnectEvent = scheduler::schedule(m_nextReconnectWait, [this] { this->handleReconnectTimeout(); });
m_reconnectEvent = getScheduler().schedule(m_nextReconnectWait,
[this] { this->handleReconnectTimeout(); });
m_socket.async_connect(m_remoteEndpoint, [this] (const auto& e) { this->handleReconnect(e); });
}
+1 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2018, Regents of the University of California,
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -27,7 +27,6 @@
#define NFD_DAEMON_FACE_TCP_TRANSPORT_HPP
#include "stream-transport.hpp"
#include "core/scheduler.hpp"
namespace nfd {
namespace face {
+2 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2018, Regents of the University of California,
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -26,7 +26,7 @@
#include "udp-channel.hpp"
#include "generic-link-service.hpp"
#include "unicast-udp-transport.hpp"
#include "core/global-io.hpp"
#include "daemon/global.hpp"
namespace nfd {
namespace face {
+1 -1
View File
@@ -26,7 +26,7 @@
#include "udp-factory.hpp"
#include "generic-link-service.hpp"
#include "multicast-udp-transport.hpp"
#include "core/global-io.hpp"
#include "daemon/global.hpp"
#include <boost/range/adaptor/map.hpp>
#include <boost/range/algorithm/copy.hpp>
+3 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2018, Regents of the University of California,
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -24,6 +24,7 @@
*/
#include "unicast-ethernet-transport.hpp"
#include "daemon/global.hpp"
#include <stdio.h> // for snprintf()
@@ -95,7 +96,7 @@ UnicastEthernetTransport::afterChangePersistency(ndn::nfd::FacePersistency oldPe
void
UnicastEthernetTransport::scheduleClosureWhenIdle()
{
m_closeIfIdleEvent = scheduler::schedule(m_idleTimeout, [this] {
m_closeIfIdleEvent = getScheduler().schedule(m_idleTimeout, [this] {
if (!hasRecentlyReceived()) {
NFD_LOG_FACE_INFO("Closing due to inactivity");
this->close();
+1 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2018, Regents of the University of California,
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -27,7 +27,6 @@
#define NFD_DAEMON_FACE_UNICAST_ETHERNET_TRANSPORT_HPP
#include "ethernet-transport.hpp"
#include "core/scheduler.hpp"
namespace nfd {
namespace face {
+3 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2018, Regents of the University of California,
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -25,6 +25,7 @@
#include "unicast-udp-transport.hpp"
#include "udp-protocol.hpp"
#include "daemon/global.hpp"
#ifdef __linux__
#include <cerrno> // for errno
@@ -109,7 +110,7 @@ UnicastUdpTransport::afterChangePersistency(ndn::nfd::FacePersistency oldPersist
void
UnicastUdpTransport::scheduleClosureWhenIdle()
{
m_closeIfIdleEvent = scheduler::schedule(m_idleTimeout, [this] {
m_closeIfIdleEvent = getScheduler().schedule(m_idleTimeout, [this] {
if (!hasRecentlyReceived()) {
NFD_LOG_FACE_INFO("Closing due to inactivity");
this->close();
+1 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2018, Regents of the University of California,
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -27,7 +27,6 @@
#define NFD_DAEMON_FACE_UNICAST_UDP_TRANSPORT_HPP
#include "datagram-transport.hpp"
#include "core/scheduler.hpp"
namespace nfd {
namespace face {
+1 -1
View File
@@ -26,7 +26,7 @@
#include "unix-stream-channel.hpp"
#include "generic-link-service.hpp"
#include "unix-stream-transport.hpp"
#include "core/global-io.hpp"
#include "daemon/global.hpp"
#include <boost/filesystem.hpp>
#include <sys/stat.h> // for chmod()
+2 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2018, Regents of the University of California,
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -26,7 +26,7 @@
#include "websocket-channel.hpp"
#include "generic-link-service.hpp"
#include "websocket-transport.hpp"
#include "core/global-io.hpp"
#include "daemon/global.hpp"
namespace nfd {
namespace face {
+3 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2018, Regents of the University of California,
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -24,6 +24,7 @@
*/
#include "websocket-transport.hpp"
#include "daemon/global.hpp"
namespace nfd {
namespace face {
@@ -109,7 +110,7 @@ WebSocketTransport::receiveMessage(const std::string& msg)
void
WebSocketTransport::schedulePing()
{
m_pingEventId = scheduler::schedule(m_pingInterval, [this] { sendPing(); });
m_pingEventId = getScheduler().schedule(m_pingInterval, [this] { sendPing(); });
}
void
+2 -3
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2017, Regents of the University of California,
/*
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -28,7 +28,6 @@
#include "transport.hpp"
#include "websocketpp.hpp"
#include "core/scheduler.hpp"
namespace nfd {
namespace face {
+3 -3
View File
@@ -26,6 +26,7 @@
#include "access-strategy.hpp"
#include "algorithm.hpp"
#include "core/logger.hpp"
#include "daemon/global.hpp"
namespace nfd {
namespace fw {
@@ -42,8 +43,7 @@ AccessStrategy::AccessStrategy(Forwarder& forwarder, const Name& name)
NDN_THROW(std::invalid_argument("AccessStrategy does not accept parameters"));
}
if (parsed.version && *parsed.version != getStrategyName()[-1].toVersion()) {
NDN_THROW(std::invalid_argument(
"AccessStrategy does not support version " + to_string(*parsed.version)));
NDN_THROW(std::invalid_argument("AccessStrategy does not support version " + to_string(*parsed.version)));
}
this->setInstanceName(makeInstanceName(name, getStrategyName()));
}
@@ -153,7 +153,7 @@ AccessStrategy::sendToLastNexthop(const Face& inFace, const Interest& interest,
// schedule RTO timeout
PitInfo* pi = pitEntry->insertStrategyInfo<PitInfo>().first;
pi->rtoTimer = scheduler::schedule(rto,
pi->rtoTimer = getScheduler().schedule(rto,
bind(&AccessStrategy::afterRtoTimeout, this, weak_ptr<pit::Entry>(pitEntry),
inFace.getId(), mi.lastNexthop));
+12 -12
View File
@@ -24,6 +24,7 @@
*/
#include "asf-measurements.hpp"
#include "daemon/global.hpp"
namespace nfd {
namespace fw {
@@ -73,7 +74,7 @@ FaceInfo::FaceInfo()
FaceInfo::~FaceInfo()
{
cancelTimeoutEvent();
scheduler::cancel(m_measurementExpirationId);
m_measurementExpirationId.cancel();
}
void
@@ -92,7 +93,7 @@ FaceInfo::setTimeoutEvent(const scheduler::EventId& id, const Name& interestName
void
FaceInfo::cancelTimeoutEvent()
{
scheduler::cancel(m_timeoutEventId);
m_timeoutEventId.cancel();
m_isTimeoutScheduled = false;
}
@@ -114,7 +115,7 @@ void
FaceInfo::recordRtt(const shared_ptr<pit::Entry>& pitEntry, const Face& inFace)
{
// Calculate RTT
pit::OutRecordCollection::const_iterator outRecord = pitEntry->getOutRecord(inFace, 0);
auto outRecord = pitEntry->getOutRecord(inFace, 0);
if (outRecord == pitEntry->out_end()) { // no out-record
NFD_LOG_TRACE(pitEntry->getInterest() << " dataFrom inFace=" << inFace.getId() << " no-out-record");
@@ -122,7 +123,7 @@ FaceInfo::recordRtt(const shared_ptr<pit::Entry>& pitEntry, const Face& inFace)
}
time::steady_clock::Duration steadyRtt = time::steady_clock::now() - outRecord->getLastRenewed();
RttEstimator::Duration durationRtt = time::duration_cast<RttEstimator::Duration>(steadyRtt);
auto durationRtt = time::duration_cast<RttEstimator::Duration>(steadyRtt);
m_rttStats.addRttMeasurement(durationRtt);
@@ -148,10 +149,9 @@ NamespaceInfo::NamespaceInfo()
}
FaceInfo*
NamespaceInfo::getFaceInfo(const fib::Entry& fibEntry, FaceId faceId)
NamespaceInfo::getFaceInfo(const fib::Entry&, FaceId faceId)
{
FaceInfoTable::iterator it = m_fit.find(faceId);
auto it = m_fit.find(faceId);
if (it != m_fit.end()) {
return &it->second;
}
@@ -161,10 +161,9 @@ NamespaceInfo::getFaceInfo(const fib::Entry& fibEntry, FaceId faceId)
}
FaceInfo&
NamespaceInfo::getOrCreateFaceInfo(const fib::Entry& fibEntry, FaceId faceId)
NamespaceInfo::getOrCreateFaceInfo(const fib::Entry&, FaceId faceId)
{
FaceInfoTable::iterator it = m_fit.find(faceId);
auto it = m_fit.find(faceId);
FaceInfo* info = nullptr;
if (it == m_fit.end()) {
@@ -190,10 +189,11 @@ void
NamespaceInfo::extendFaceInfoLifetime(FaceInfo& info, FaceId faceId)
{
// Cancel previous expiration
scheduler::cancel(info.getMeasurementExpirationEventId());
info.getMeasurementExpirationEventId().cancel();
// Refresh measurement
auto id = scheduler::schedule(AsfMeasurements::MEASUREMENTS_LIFETIME, [=] { expireFaceInfo(faceId); });
auto id = getScheduler().schedule(AsfMeasurements::MEASUREMENTS_LIFETIME,
[=] { expireFaceInfo(faceId); });
info.setMeasurementExpirationEventId(id);
}
+5 -6
View File
@@ -25,6 +25,7 @@
#include "asf-probing-module.hpp"
#include "algorithm.hpp"
#include "daemon/global.hpp"
#include <ndn-cxx/util/random.hpp>
@@ -50,7 +51,7 @@ ProbingModule::scheduleProbe(const fib::Entry& fibEntry, const time::millisecond
Name prefix = fibEntry.getPrefix();
// Set the probing flag for the namespace to true after passed interval of time
scheduler::schedule(interval, [this, prefix] {
getScheduler().schedule(interval, [this, prefix] {
NamespaceInfo* info = m_measurements.getNamespaceInfo(prefix);
if (info == nullptr) {
@@ -65,10 +66,8 @@ ProbingModule::scheduleProbe(const fib::Entry& fibEntry, const time::millisecond
}
Face*
ProbingModule::getFaceToProbe(const Face& inFace,
const Interest& interest,
const fib::Entry& fibEntry,
const Face& faceUsed)
ProbingModule::getFaceToProbe(const Face& inFace, const Interest& interest,
const fib::Entry& fibEntry, const Face& faceUsed)
{
FaceInfoFacePairSet rankedFaces(
[] (const auto& pairLhs, const auto& pairRhs) -> bool {
@@ -83,7 +82,7 @@ ProbingModule::getFaceToProbe(const Face& inFace,
// 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()) {
for (const auto& hop : fibEntry.getNextHops()) {
Face& hopFace = hop.getFace();
// Don't send probe Interest back to the incoming face or use the same face
+3 -3
View File
@@ -26,6 +26,7 @@
#include "asf-strategy.hpp"
#include "algorithm.hpp"
#include "core/logger.hpp"
#include "daemon/global.hpp"
namespace nfd {
namespace fw {
@@ -226,9 +227,8 @@ AsfStrategy::forwardInterest(const Interest& interest,
NFD_LOG_TRACE("Scheduling timeout for " << fibEntry.getPrefix() << " to: " << egress
<< " in " << time::duration_cast<time::milliseconds>(timeout) << " ms");
scheduler::EventId id = scheduler::schedule(timeout,
bind(&AsfStrategy::onTimeout, this, interest.getName(), egress.face.getId()));
auto id = getScheduler().schedule(timeout, bind(&AsfStrategy::onTimeout, this,
interest.getName(), egress.face.getId()));
faceInfo.setTimeoutEvent(id, interest.getName());
}
}
+2 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2018, Regents of the University of California,
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -24,8 +24,8 @@
*/
#include "face-table.hpp"
#include "core/global-io.hpp"
#include "core/logger.hpp"
#include "daemon/global.hpp"
#include "face/channel.hpp"
#include <ndn-cxx/util/concepts.hpp>
+6 -6
View File
@@ -29,6 +29,7 @@
#include "best-route-strategy2.hpp"
#include "strategy.hpp"
#include "core/logger.hpp"
#include "daemon/global.hpp"
#include "table/cleanup.hpp"
#include <ndn-cxx/lp/tags.hpp>
@@ -44,7 +45,7 @@ getDefaultStrategyName()
}
Forwarder::Forwarder()
: m_unsolicitedDataPolicy(new fw::DefaultUnsolicitedDataPolicy())
: m_unsolicitedDataPolicy(make_unique<fw::DefaultUnsolicitedDataPolicy>())
, m_fib(m_nameTree)
, m_pit(m_nameTree)
, m_measurements(m_nameTree)
@@ -241,7 +242,7 @@ Forwarder::onInterestFinalize(const shared_ptr<pit::Entry>& pitEntry)
<< (pitEntry->isSatisfied ? " satisfied" : " unsatisfied"));
// Dead Nonce List insert if necessary
this->insertDeadNonceList(*pitEntry, 0);
this->insertDeadNonceList(*pitEntry, nullptr);
// Increment satisfied/unsatisfied Interests counter
if (pitEntry->isSatisfied) {
@@ -252,7 +253,7 @@ Forwarder::onInterestFinalize(const shared_ptr<pit::Entry>& pitEntry)
}
// PIT delete
scheduler::cancel(pitEntry->expiryTimer);
pitEntry->expiryTimer.cancel();
m_pit.erase(pitEntry.get());
}
@@ -507,9 +508,8 @@ Forwarder::setExpiryTimer(const shared_ptr<pit::Entry>& pitEntry, time::millisec
BOOST_ASSERT(pitEntry);
BOOST_ASSERT(duration >= 0_ms);
scheduler::cancel(pitEntry->expiryTimer);
pitEntry->expiryTimer = scheduler::schedule(duration, [=] { onInterestFinalize(pitEntry); });
pitEntry->expiryTimer.cancel();
pitEntry->expiryTimer = getScheduler().schedule(duration, [=] { onInterestFinalize(pitEntry); });
}
void
+4 -6
View File
@@ -26,11 +26,9 @@
#ifndef NFD_DAEMON_FW_FORWARDER_HPP
#define NFD_DAEMON_FW_FORWARDER_HPP
#include "core/common.hpp"
#include "core/scheduler.hpp"
#include "forwarder-counters.hpp"
#include "face-table.hpp"
#include "face-endpoint.hpp"
#include "face-table.hpp"
#include "forwarder-counters.hpp"
#include "unsolicited-data-policy.hpp"
#include "table/fib.hpp"
#include "table/pit.hpp"
@@ -46,9 +44,9 @@ namespace fw {
class Strategy;
} // namespace fw
/** \brief main class of NFD
/** \brief Main class of NFD forwarding engine.
*
* Forwarder owns all faces and tables, and implements forwarding pipelines.
* Forwarder owns all faces and tables, and implements the forwarding pipelines.
*/
class Forwarder
{
+8 -8
View File
@@ -25,6 +25,7 @@
#include "ncc-strategy.hpp"
#include "algorithm.hpp"
#include "daemon/global.hpp"
#include <ndn-cxx/util/random.hpp>
@@ -90,8 +91,7 @@ NccStrategy::afterReceiveInterest(const FaceEndpoint& ingress, const Interest& i
deferRange = time::microseconds((deferFirst.count() + 1) / 2);
--nUpstreams;
this->sendInterest(pitEntry, FaceEndpoint(*bestFace, 0), interest);
pitEntryInfo->bestFaceTimeout = scheduler::schedule(
meInfo.prediction,
pitEntryInfo->bestFaceTimeout = getScheduler().schedule(meInfo.prediction,
bind(&NccStrategy::timeoutOnBestFace, this, weak_ptr<pit::Entry>(pitEntry)));
}
else {
@@ -128,7 +128,7 @@ NccStrategy::afterReceiveInterest(const FaceEndpoint& ingress, const Interest& i
// this maxInterval would be used to determine when the next doPropagate would happen.
pitEntryInfo->maxInterval = deferFirst;
}
pitEntryInfo->propagateTimer = scheduler::schedule(deferFirst,
pitEntryInfo->propagateTimer = getScheduler().schedule(deferFirst,
bind(&NccStrategy::doPropagate, this, ingress.face.getId(), weak_ptr<pit::Entry>(pitEntry)));
}
@@ -178,7 +178,7 @@ NccStrategy::doPropagate(FaceId inFaceId, weak_ptr<pit::Entry> pitEntryWeak)
if (isForwarded) {
std::uniform_int_distribution<time::nanoseconds::rep> dist(0, pitEntryInfo->maxInterval.count() - 1);
time::nanoseconds deferNext(dist(ndn::random::getRandomNumberEngine()));
pitEntryInfo->propagateTimer = scheduler::schedule(deferNext,
pitEntryInfo->propagateTimer = getScheduler().schedule(deferNext,
bind(&NccStrategy::doPropagate, this, inFaceId, weak_ptr<pit::Entry>(pitEntry)));
}
}
@@ -233,14 +233,14 @@ NccStrategy::beforeSatisfyInterest(const shared_ptr<pit::Entry>& pitEntry,
PitEntryInfo* pitEntryInfo = pitEntry->getStrategyInfo<PitEntryInfo>();
if (pitEntryInfo != nullptr) {
scheduler::cancel(pitEntryInfo->propagateTimer);
pitEntryInfo->propagateTimer.cancel();
// Verify that the best face satisfied the interest before canceling the timeout call
MeasurementsEntryInfo& meInfo = this->getMeasurementsEntryInfo(pitEntry);
shared_ptr<Face> bestFace = meInfo.getBestFace();
if (bestFace.get() == &ingress.face)
scheduler::cancel(pitEntryInfo->bestFaceTimeout);
pitEntryInfo->bestFaceTimeout.cancel();
}
}
@@ -337,8 +337,8 @@ NccStrategy::MeasurementsEntryInfo::ageBestFace()
NccStrategy::PitEntryInfo::~PitEntryInfo()
{
scheduler::cancel(this->bestFaceTimeout);
scheduler::cancel(this->propagateTimer);
bestFaceTimeout.cancel();
propagateTimer.cancel();
}
} // namespace fw
+1 -1
View File
@@ -27,7 +27,7 @@
#include "algorithm.hpp"
#include "core/logger.hpp"
#include "core/global-io.hpp"
#include "daemon/global.hpp"
#include "rib/service.hpp"
#include <ndn-cxx/lp/empty-value.hpp>
+5 -3
View File
@@ -51,7 +51,9 @@ public: // registry
BOOST_ASSERT(strategyName.at(-1).isVersion());
Registry& registry = getRegistry();
BOOST_ASSERT(registry.count(strategyName) == 0);
registry[strategyName] = &make_unique<S, Forwarder&, const Name&>;
registry[strategyName] = [] (auto&&... args) {
return make_unique<S>(std::forward<decltype(args)>(args)...);
};
}
/** \return whether a strategy instance can be created from \p instanceName
@@ -81,9 +83,9 @@ public: // registry
listRegistered();
public: // constructor, destructor, strategy name
/** \brief construct a strategy instance
/** \brief Construct a strategy instance.
* \param forwarder a reference to the forwarder, used to enable actions and accessors.
* \note Strategy subclass constructor should not retain a reference to the forwarder.
* \note Strategy subclass constructor must not retain a reference to \p forwarder.
*/
explicit
Strategy(Forwarder& forwarder);
+24 -19
View File
@@ -23,11 +23,12 @@
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
#include "global-io.hpp"
#include "daemon/global.hpp"
namespace nfd {
static thread_local unique_ptr<boost::asio::io_service> g_ioService;
static thread_local unique_ptr<Scheduler> g_scheduler;
static boost::asio::io_service* g_mainIoService = nullptr;
static boost::asio::io_service* g_ribIoService = nullptr;
@@ -40,32 +41,24 @@ getGlobalIoService()
return *g_ioService;
}
#ifdef WITH_TESTS
namespace scheduler {
void
resetGlobalScheduler(); // defined in scheduler.cpp
} // namespace scheduler
Scheduler&
getScheduler()
{
if (g_scheduler == nullptr) {
g_scheduler = make_unique<Scheduler>(getGlobalIoService());
}
return *g_scheduler;
}
#ifdef WITH_TESTS
void
resetGlobalIoService()
{
scheduler::resetGlobalScheduler();
g_scheduler.reset();
g_ioService.reset();
}
#endif
void
setMainIoService(boost::asio::io_service* mainIo)
{
g_mainIoService = mainIo;
}
void
setRibIoService(boost::asio::io_service* ribIo)
{
g_ribIoService = ribIo;
}
boost::asio::io_service&
getMainIoService()
{
@@ -80,6 +73,18 @@ getRibIoService()
return *g_ribIoService;
}
void
setMainIoService(boost::asio::io_service* mainIo)
{
g_mainIoService = mainIo;
}
void
setRibIoService(boost::asio::io_service* ribIo)
{
g_ribIoService = ribIo;
}
void
runOnMainIoService(const std::function<void()>& f)
{
+27 -22
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2018 Regents of the University of California,
* Copyright (c) 2014-2019 Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -22,33 +22,22 @@
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
**/
#ifndef NFD_CORE_GLOBAL_IO_HPP
#define NFD_CORE_GLOBAL_IO_HPP
#ifndef NFD_DAEMON_GLOBAL_HPP
#define NFD_DAEMON_GLOBAL_HPP
#include "common.hpp"
#include "core/common.hpp"
namespace nfd {
/** \return the global io_service instance
/** \brief Returns the global io_service instance for the calling thread.
*/
boost::asio::io_service&
getGlobalIoService();
void
setMainIoService(boost::asio::io_service* mainIo);
void
setRibIoService(boost::asio::io_service* ribIo);
/** \brief run a function on the main io_service instance
/** \brief Returns the global Scheduler instance for the calling thread.
*/
void
runOnMainIoService(const std::function<void()>& f);
/** \brief run a function on the RIB io_service instance
*/
void
runOnRibIoService(const std::function<void()>& f);
Scheduler&
getScheduler();
boost::asio::io_service&
getMainIoService();
@@ -56,10 +45,26 @@ getMainIoService();
boost::asio::io_service&
getRibIoService();
void
setMainIoService(boost::asio::io_service* mainIo);
void
setRibIoService(boost::asio::io_service* ribIo);
/** \brief Run a function on the main io_service instance.
*/
void
runOnMainIoService(const std::function<void()>& f);
/** \brief Run a function on the RIB io_service instance.
*/
void
runOnRibIoService(const std::function<void()>& f);
#ifdef WITH_TESTS
/** \brief delete the global io_service instance
/** \brief Destroy the global io_service instance.
*
* It will be recreated at the next invocation of getGlobalIoService.
* It will be recreated at the next invocation of getGlobalIoService().
*/
void
resetGlobalIoService();
@@ -67,4 +72,4 @@ resetGlobalIoService();
} // namespace nfd
#endif // NFD_CORE_GLOBAL_IO_HPP
#endif // NFD_DAEMON_GLOBAL_HPP
+1 -1
View File
@@ -26,10 +26,10 @@
#include "nfd.hpp"
#include "rib/service.hpp"
#include "core/global-io.hpp"
#include "core/logger.hpp"
#include "core/privilege-helper.hpp"
#include "core/version.hpp"
#include "daemon/global.hpp"
#include <string.h> // for strsignal()
+5 -6
View File
@@ -47,8 +47,7 @@ static const time::seconds ACTIVE_FACE_FETCH_INTERVAL = 5_min;
const Name RibManager::LOCALHOP_TOP_PREFIX = "/localhop/nfd";
RibManager::RibManager(rib::Rib& rib, ndn::Face& face, ndn::KeyChain& keyChain,
ndn::nfd::Controller& nfdController, Dispatcher& dispatcher,
ndn::util::Scheduler& scheduler)
ndn::nfd::Controller& nfdController, Dispatcher& dispatcher, Scheduler& scheduler)
: ManagerBase(MGMT_MODULE_NAME, dispatcher)
, m_rib(rib)
, m_keyChain(keyChain)
@@ -137,7 +136,7 @@ RibManager::beginAddRoute(const Name& name, Route route, optional<time::nanoseco
" origin=" << route.origin << " cost=" << route.cost);
if (expires) {
auto event = m_scheduler.scheduleEvent(*expires, [=] { m_rib.onRouteExpiration(name, route); });
auto event = m_scheduler.schedule(*expires, [=] { m_rib.onRouteExpiration(name, route); });
route.setExpirationEvent(event);
NFD_LOG_TRACE("Scheduled unregistration at: " << *route.expires);
}
@@ -459,7 +458,7 @@ RibManager::onFaceDestroyedEvent(uint64_t faceId)
void
RibManager::scheduleActiveFaceFetch(const time::seconds& timeToWait)
{
m_activeFaceFetchEvent = m_scheduler.scheduleEvent(timeToWait, [this] { fetchActiveFaces(); });
m_activeFaceFetchEvent = m_scheduler.schedule(timeToWait, [this] { fetchActiveFaces(); });
}
void
@@ -477,7 +476,7 @@ RibManager::removeInvalidFaces(const std::vector<ndn::nfd::FaceStatus>& activeFa
for (auto faceId : m_registeredFaces) {
if (activeFaceIds.count(faceId) == 0) {
NFD_LOG_DEBUG("Removing invalid face ID: " << faceId);
m_scheduler.scheduleEvent(0_ns, [this, faceId] { this->onFaceDestroyedEvent(faceId); });
m_scheduler.schedule(0_ns, [this, faceId] { this->onFaceDestroyedEvent(faceId); });
}
}
@@ -492,7 +491,7 @@ RibManager::onNotification(const ndn::nfd::FaceEventNotification& notification)
if (notification.getKind() == ndn::nfd::FACE_EVENT_DESTROYED) {
NFD_LOG_DEBUG("Received notification for destroyed faceId: " << notification.getFaceId());
m_scheduler.scheduleEvent(0_ns, [this, id = notification.getFaceId()] { onFaceDestroyedEvent(id); });
m_scheduler.schedule(0_ns, [this, id = notification.getFaceId()] { onFaceDestroyedEvent(id); });
}
}
+3 -4
View File
@@ -51,8 +51,7 @@ class RibManager : public ManagerBase
{
public:
RibManager(rib::Rib& rib, ndn::Face& face, ndn::KeyChain& keyChain,
ndn::nfd::Controller& nfdController, Dispatcher& dispatcher,
ndn::util::Scheduler& scheduler);
ndn::nfd::Controller& nfdController, Dispatcher& dispatcher, Scheduler& scheduler);
/**
* @brief Apply localhost_security configuration.
@@ -246,14 +245,14 @@ private:
ndn::KeyChain& m_keyChain;
ndn::nfd::Controller& m_nfdController;
Dispatcher& m_dispatcher;
ndn::util::Scheduler& m_scheduler;
Scheduler& m_scheduler;
ndn::nfd::FaceMonitor m_faceMonitor;
ndn::ValidatorConfig m_localhostValidator;
ndn::ValidatorConfig m_localhopValidator;
bool m_isLocalhopEnabled;
ndn::util::scheduler::ScopedEventId m_activeFaceFetchEvent;
scheduler::ScopedEventId m_activeFaceFetchEvent;
using FaceIdSet = std::set<uint64_t>;
FaceIdSet m_registeredFaces; ///< contains FaceIds with one or more Routes in the RIB
};
+2 -3
View File
@@ -24,9 +24,8 @@
*/
#include "nfd.hpp"
#include "global.hpp"
#include "core/config-file.hpp"
#include "core/global-io.hpp"
#include "core/log-config-section.hpp"
#include "core/privilege-helper.hpp"
#include "face/face-system.hpp"
@@ -89,7 +88,7 @@ Nfd::initialize()
m_netmon->onNetworkStateChanged.connect([this] {
// delay stages, so if multiple events are triggered in short sequence,
// only one auto-detection procedure is triggered
m_reloadConfigEvent = scheduler::schedule(5_s,
m_reloadConfigEvent = getScheduler().schedule(5_s,
[this] {
NFD_LOG_INFO("Network change detected, reloading face section of the config file...");
this->reloadConfigFileFaceSection();
+1 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2018, Regents of the University of California,
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -27,7 +27,6 @@
#define NFD_DAEMON_NFD_HPP
#include "core/config-file.hpp"
#include "core/scheduler.hpp"
#include <ndn-cxx/net/network-monitor.hpp>
#include <ndn-cxx/security/key-chain.hpp>
+7 -7
View File
@@ -44,7 +44,7 @@ randomizeTimer(time::milliseconds baseTimer)
return std::max(newTime, 0_ms);
}
Readvertise::Readvertise(Rib& rib, ndn::util::Scheduler& scheduler,
Readvertise::Readvertise(Rib& rib, Scheduler& scheduler,
unique_ptr<ReadvertisePolicy> policy,
unique_ptr<ReadvertiseDestination> destination)
: m_scheduler(scheduler)
@@ -162,14 +162,14 @@ Readvertise::advertise(ReadvertisedRouteContainer::iterator rrIt)
[=] {
NFD_LOG_DEBUG("advertise " << rrIt->prefix << " success");
rrIt->retryDelay = RETRY_DELAY_MIN;
rrIt->retryEvt = m_scheduler.scheduleEvent(randomizeTimer(m_policy->getRefreshInterval()),
[=] { advertise(rrIt); });
rrIt->retryEvt = m_scheduler.schedule(randomizeTimer(m_policy->getRefreshInterval()),
[=] { advertise(rrIt); });
},
[=] (const std::string& msg) {
NFD_LOG_DEBUG("advertise " << rrIt->prefix << " failure " << msg);
rrIt->retryDelay = std::min(RETRY_DELAY_MAX, rrIt->retryDelay * 2);
rrIt->retryEvt = m_scheduler.scheduleEvent(randomizeTimer(rrIt->retryDelay),
[=] { advertise(rrIt); });
rrIt->retryEvt = m_scheduler.schedule(randomizeTimer(rrIt->retryDelay),
[=] { advertise(rrIt); });
});
}
@@ -192,8 +192,8 @@ Readvertise::withdraw(ReadvertisedRouteContainer::iterator rrIt)
[=] (const std::string& msg) {
NFD_LOG_DEBUG("withdraw " << rrIt->prefix << " failure " << msg);
rrIt->retryDelay = std::min(RETRY_DELAY_MAX, rrIt->retryDelay * 2);
rrIt->retryEvt = m_scheduler.scheduleEvent(randomizeTimer(rrIt->retryDelay),
[=] { withdraw(rrIt); });
rrIt->retryEvt = m_scheduler.schedule(randomizeTimer(rrIt->retryDelay),
[=] { withdraw(rrIt); });
});
}
+2 -3
View File
@@ -45,8 +45,7 @@ class Readvertise : noncopyable
{
public:
Readvertise(Rib& rib,
ndn::util::Scheduler& scheduler,
Readvertise(Rib& rib, Scheduler& scheduler,
unique_ptr<ReadvertisePolicy> policy,
unique_ptr<ReadvertiseDestination> destination);
@@ -77,7 +76,7 @@ private:
static const time::milliseconds RETRY_DELAY_MIN;
static const time::milliseconds RETRY_DELAY_MAX;
ndn::util::Scheduler& m_scheduler;
Scheduler& m_scheduler;
unique_ptr<ReadvertisePolicy> m_policy;
unique_ptr<ReadvertiseDestination> m_destination;
@@ -52,7 +52,7 @@ public:
mutable ndn::security::SigningInfo signer; ///< signer for commands
mutable size_t nRibRoutes; ///< number of RIB routes that cause the readvertisement
mutable time::milliseconds retryDelay; ///< retry interval (not used for refresh)
mutable ndn::util::scheduler::ScopedEventId retryEvt; ///< retry or refresh event
mutable scheduler::ScopedEventId retryEvt; ///< retry or refresh event
};
inline bool
+3 -3
View File
@@ -53,14 +53,14 @@ public:
*/
Route(const ndn::PrefixAnnouncement& ann, uint64_t faceId);
const ndn::util::scheduler::EventId&
const scheduler::EventId&
getExpirationEvent() const
{
return m_expirationEvent;
}
void
setExpirationEvent(const ndn::util::scheduler::EventId& eid)
setExpirationEvent(const scheduler::EventId& eid)
{
m_expirationEvent = eid;
}
@@ -101,7 +101,7 @@ public:
time::steady_clock::TimePoint annExpires;
private:
ndn::util::scheduler::EventId m_expirationEvent;
scheduler::EventId m_expirationEvent;
};
bool
+1 -1
View File
@@ -31,8 +31,8 @@
#include "readvertise/nfd-rib-readvertise-destination.hpp"
#include "readvertise/readvertise.hpp"
#include "core/global-io.hpp"
#include "core/logger.hpp"
#include "daemon/global.hpp"
#include <boost/property_tree/info_parser.hpp>
#include <ndn-cxx/transport/tcp-transport.hpp>
+1 -1
View File
@@ -111,7 +111,7 @@ private:
ndn::KeyChain& m_keyChain;
ndn::Face m_face;
ndn::util::Scheduler m_scheduler;
Scheduler m_scheduler;
ndn::nfd::Controller m_nfdController;
Rib m_rib;
+5 -4
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2018, Regents of the University of California,
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -25,6 +25,7 @@
#include "cs-policy-priority-fifo.hpp"
#include "cs.hpp"
#include "daemon/global.hpp"
namespace nfd {
namespace cs {
@@ -117,8 +118,8 @@ PriorityFifoPolicy::attachQueue(iterator i)
}
else {
entryInfo->queueType = QUEUE_FIFO;
entryInfo->moveStaleEventId = scheduler::schedule(i->getData().getFreshnessPeriod(),
[=] { moveToStaleQueue(i); });
entryInfo->moveStaleEventId = getScheduler().schedule(i->getData().getFreshnessPeriod(),
[=] { moveToStaleQueue(i); });
}
Queue& queue = m_queues[entryInfo->queueType];
@@ -133,7 +134,7 @@ PriorityFifoPolicy::detachQueue(iterator i)
EntryInfo* entryInfo = m_entryInfoMap[i];
if (entryInfo->queueType == QUEUE_FIFO) {
scheduler::cancel(entryInfo->moveStaleEventId);
entryInfo->moveStaleEventId.cancel();
}
m_queues[entryInfo->queueType].erase(entryInfo->queueIt);
+2 -4
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2018, Regents of the University of California,
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -27,7 +27,6 @@
#define NFD_DAEMON_TABLE_CS_POLICY_PRIORITY_FIFO_HPP
#include "cs-policy.hpp"
#include "core/scheduler.hpp"
#include <list>
@@ -80,8 +79,7 @@ class PriorityFifoPolicy : public Policy
public:
PriorityFifoPolicy();
virtual
~PriorityFifoPolicy();
~PriorityFifoPolicy() override;
public:
static const std::string POLICY_NAME;
+2 -4
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2018, Regents of the University of California,
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -44,10 +44,8 @@ makeDefaultPolicy()
}
Cs::Cs(size_t nMaxPackets)
: m_shouldAdmit(true)
, m_shouldServe(true)
{
this->setPolicyImpl(makeDefaultPolicy());
setPolicyImpl(makeDefaultPolicy());
m_policy->setLimit(nMaxPackets);
}
+4 -4
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2018, Regents of the University of California,
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -29,7 +29,7 @@
#include "cs-policy.hpp"
#include "cs-internal.hpp"
#include "cs-entry-impl.hpp"
#include <ndn-cxx/util/signal.hpp>
#include <boost/iterator/transform_iterator.hpp>
namespace nfd {
@@ -210,8 +210,8 @@ private:
unique_ptr<Policy> m_policy;
signal::ScopedConnection m_beforeEvictConnection;
bool m_shouldAdmit; ///< if false, no Data will be admitted
bool m_shouldServe; ///< if false, all lookups will miss
bool m_shouldAdmit = true; ///< if false, no Data will be admitted
bool m_shouldServe = true; ///< if false, all lookups will miss
};
} // namespace cs
+7 -6
View File
@@ -26,6 +26,7 @@
#include "dead-nonce-list.hpp"
#include "core/city-hash.hpp"
#include "core/logger.hpp"
#include "daemon/global.hpp"
namespace nfd {
@@ -58,14 +59,14 @@ DeadNonceList::DeadNonceList(time::nanoseconds lifetime)
m_queue.push_back(MARK);
}
m_markEvent = scheduler::schedule(m_markInterval, [this] { mark(); });
m_adjustCapacityEvent = scheduler::schedule(m_adjustCapacityInterval, [this] { adjustCapacity(); });
m_markEvent = getScheduler().schedule(m_markInterval, [this] { mark(); });
m_adjustCapacityEvent = getScheduler().schedule(m_adjustCapacityInterval, [this] { adjustCapacity(); });
}
DeadNonceList::~DeadNonceList()
{
scheduler::cancel(m_markEvent);
scheduler::cancel(m_adjustCapacityEvent);
m_markEvent.cancel();
m_adjustCapacityEvent.cancel();
BOOST_ASSERT_MSG(DEFAULT_LIFETIME >= MIN_LIFETIME, "DEFAULT_LIFETIME is too small");
static_assert(INITIAL_CAPACITY >= MIN_CAPACITY, "INITIAL_CAPACITY is too small");
@@ -124,7 +125,7 @@ DeadNonceList::mark()
NFD_LOG_TRACE("mark nMarks=" << nMarks);
m_markEvent = scheduler::schedule(m_markInterval, [this] { mark(); });
m_markEvent = getScheduler().schedule(m_markInterval, [this] { mark(); });
}
void
@@ -145,7 +146,7 @@ DeadNonceList::adjustCapacity()
m_actualMarkCounts.clear();
this->evictEntries();
m_adjustCapacityEvent = scheduler::schedule(m_adjustCapacityInterval, [this] { adjustCapacity(); });
m_adjustCapacityEvent = getScheduler().schedule(m_adjustCapacityInterval, [this] { adjustCapacity(); });
}
void
-1
View File
@@ -27,7 +27,6 @@
#define NFD_DAEMON_TABLE_DEAD_NONCE_LIST_HPP
#include "core/common.hpp"
#include "core/scheduler.hpp"
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/hashed_index.hpp>
-1
View File
@@ -27,7 +27,6 @@
#define NFD_DAEMON_TABLE_MEASUREMENTS_ENTRY_HPP
#include "strategy-info-host.hpp"
#include "core/scheduler.hpp"
namespace nfd {
+4 -3
View File
@@ -27,6 +27,7 @@
#include "name-tree.hpp"
#include "pit-entry.hpp"
#include "fib-entry.hpp"
#include "daemon/global.hpp"
namespace nfd {
namespace measurements {
@@ -49,7 +50,7 @@ Measurements::get(name_tree::Entry& nte)
entry = nte.getMeasurementsEntry();
entry->m_expiry = time::steady_clock::now() + getInitialLifetime();
entry->m_cleanup = scheduler::schedule(getInitialLifetime(), [=] { cleanup(*entry); });
entry->m_cleanup = getScheduler().schedule(getInitialLifetime(), [=] { cleanup(*entry); });
return *entry;
}
@@ -133,9 +134,9 @@ Measurements::extendLifetime(Entry& entry, const time::nanoseconds& lifetime)
return;
}
scheduler::cancel(entry.m_cleanup);
entry.m_cleanup.cancel();
entry.m_expiry = expiry;
entry.m_cleanup = scheduler::schedule(lifetime, [&] { cleanup(entry); });
entry.m_cleanup = getScheduler().schedule(lifetime, [&] { cleanup(entry); });
}
void
-1
View File
@@ -28,7 +28,6 @@
#include "pit-in-record.hpp"
#include "pit-out-record.hpp"
#include "core/scheduler.hpp"
#include <list>
-86
View File
@@ -1,86 +0,0 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
* Washington University in St. Louis,
* Beijing Institute of Technology,
* The University of Memphis.
*
* This file is part of NFD (Named Data Networking Forwarding Daemon).
* See AUTHORS.md for complete list of NFD authors and contributors.
*
* NFD is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
#include "core/scheduler.hpp"
#include "tests/test-common.hpp"
#include <thread>
namespace nfd {
namespace scheduler {
// defined in scheduler.cpp
Scheduler&
getGlobalScheduler();
} // namespace scheduler
namespace tests {
BOOST_FIXTURE_TEST_SUITE(TestScheduler, BaseFixture)
BOOST_AUTO_TEST_CASE(ScheduleCancel)
{
int count1 = 0, count2 = 0, count3 = 0;
scheduler::schedule(500_ms, [&] {
BOOST_CHECK_EQUAL(count3, 1);
++count1;
});
scheduler::EventId eid = scheduler::schedule(1_s, [&] { ++count2; });
scheduler::cancel(eid);
scheduler::schedule(250_ms, [&] {
BOOST_CHECK_EQUAL(count1, 0);
++count3;
});
{
scheduler::ScopedEventId se = scheduler::schedule(50_ms, [&] { ++count2; });
} // se goes out of scope, canceling the event
g_io.run();
BOOST_CHECK_EQUAL(count1, 1);
BOOST_CHECK_EQUAL(count2, 0);
BOOST_CHECK_EQUAL(count3, 1);
}
BOOST_AUTO_TEST_CASE(ThreadLocalScheduler)
{
scheduler::Scheduler* s1 = &scheduler::getGlobalScheduler();
scheduler::Scheduler* s2 = nullptr;
std::thread t([&s2] { s2 = &scheduler::getGlobalScheduler(); });
t.join();
BOOST_CHECK(s1 != nullptr);
BOOST_CHECK(s2 != nullptr);
BOOST_CHECK(s1 != s2);
}
BOOST_AUTO_TEST_SUITE_END() // TestScheduler
} // namespace tests
} // namespace nfd
+2 -1
View File
@@ -27,7 +27,8 @@
#define NFD_TESTS_DAEMON_FACE_CHANNEL_FIXTURE_HPP
#include "face/channel.hpp"
#include "tests/limited-io.hpp"
#include "tests/daemon/limited-io.hpp"
#include <type_traits>
+2 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2018, Regents of the University of California,
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -29,7 +29,7 @@
#include "face/multicast-ethernet-transport.hpp"
#include "face/unicast-ethernet-transport.hpp"
#include "tests/limited-io.hpp"
#include "tests/daemon/limited-io.hpp"
#include "test-netif.hpp"
namespace nfd {
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2018, Regents of the University of California,
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -27,6 +27,8 @@
#include "ethernet-fixture.hpp"
#include "daemon/global.hpp"
namespace nfd {
namespace face {
namespace tests {
@@ -66,7 +68,7 @@ BOOST_AUTO_TEST_CASE(NetifStateChange)
BOOST_CHECK_EQUAL(transport->getState(), TransportState::UP);
// simulate 'ip link set IFNAME down'
scheduler::schedule(10_ms, [=] { netif->setState(ndn::net::InterfaceState::DOWN); });
getScheduler().schedule(10_ms, [=] { netif->setState(ndn::net::InterfaceState::DOWN); });
transport->afterStateChange.connectSingleShot([&] (TransportState oldState, TransportState newState) {
BOOST_CHECK_EQUAL(oldState, TransportState::UP);
BOOST_CHECK_EQUAL(newState, TransportState::DOWN);
@@ -76,8 +78,8 @@ BOOST_AUTO_TEST_CASE(NetifStateChange)
BOOST_CHECK_EQUAL(transport->getState(), TransportState::DOWN);
// simulate 'ip link set IFNAME up'
scheduler::schedule(10_ms, [=] { netif->setState(ndn::net::InterfaceState::NO_CARRIER); });
scheduler::schedule(80_ms, [=] { netif->setState(ndn::net::InterfaceState::RUNNING); });
getScheduler().schedule(10_ms, [=] { netif->setState(ndn::net::InterfaceState::NO_CARRIER); });
getScheduler().schedule(80_ms, [=] { netif->setState(ndn::net::InterfaceState::RUNNING); });
transport->afterStateChange.connectSingleShot([&] (TransportState oldState, TransportState newState) {
BOOST_CHECK_EQUAL(oldState, TransportState::DOWN);
BOOST_CHECK_EQUAL(newState, TransportState::UP);
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2018, Regents of the University of California,
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -30,7 +30,7 @@
#include "face/face.hpp"
#include "dummy-receive-link-service.hpp"
#include "tests/limited-io.hpp"
#include "tests/daemon/limited-io.hpp"
namespace nfd {
namespace face {
+2 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2018, Regents of the University of California,
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -27,7 +27,7 @@
#include "face-system-fixture.hpp"
#include "factory-test-common.hpp"
#include "tests/limited-io.hpp"
#include "tests/daemon/limited-io.hpp"
namespace nfd {
namespace face {
+2 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2018, Regents of the University of California,
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -30,7 +30,7 @@
#include "face/face.hpp"
#include "dummy-receive-link-service.hpp"
#include "tests/limited-io.hpp"
#include "tests/daemon/limited-io.hpp"
namespace nfd {
namespace face {
+1 -1
View File
@@ -24,7 +24,7 @@
*/
#include "test-netif.hpp"
#include "core/global-io.hpp"
#include "daemon/global.hpp"
namespace nfd {
namespace face {
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2017, Regents of the University of California,
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -30,7 +30,7 @@
#include "face/face.hpp"
#include "dummy-receive-link-service.hpp"
#include "tests/limited-io.hpp"
#include "tests/daemon/limited-io.hpp"
namespace nfd {
namespace face {
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2017, Regents of the University of California,
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -30,7 +30,7 @@
#include "face/face.hpp"
#include "dummy-receive-link-service.hpp"
#include "tests/limited-io.hpp"
#include "tests/daemon/limited-io.hpp"
#include <boost/filesystem.hpp>
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2018, Regents of the University of California,
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -30,7 +30,7 @@
#include "face/face.hpp"
#include "dummy-receive-link-service.hpp"
#include "tests/limited-io.hpp"
#include "tests/daemon/limited-io.hpp"
namespace nfd {
namespace face {
+2 -1
View File
@@ -24,6 +24,7 @@
*/
#include "fw/asf-measurements.hpp"
#include "daemon/global.hpp"
#include "tests/daemon/face/dummy-face.hpp"
#include "tests/test-common.hpp"
@@ -85,7 +86,7 @@ BOOST_FIXTURE_TEST_CASE(Basic, UnitTestTimeFixture)
{
FaceInfo info;
scheduler::EventId id = scheduler::schedule(time::seconds(1), []{});
auto id = getScheduler().schedule(1_s, []{});
ndn::Name interestName("/ndn/interest");
// Receive Interest and forward to next hop; should update RTO information
+4 -3
View File
@@ -24,6 +24,7 @@
*/
#include "fw/best-route-strategy2.hpp"
#include "daemon/global.hpp"
#include "tests/test-common.hpp"
#include "tests/daemon/face/dummy-face.hpp"
@@ -108,17 +109,17 @@ BOOST_AUTO_TEST_CASE(Forward)
size_t nSent = strategy.sendInterestHistory.size();
if (nSent > nSentLast) {
BOOST_CHECK_EQUAL(nSent - nSentLast, 1);
time::steady_clock::TimePoint timeSent = time::steady_clock::now();
auto timeSent = time::steady_clock::now();
BOOST_CHECK_GE(timeSent - timeSentLast, TICK * 8);
nSentLast = nSent;
timeSentLast = timeSent;
}
retxFrom4Evt = scheduler::schedule(TICK * 5, periodicalRetxFrom4);
retxFrom4Evt = getScheduler().schedule(TICK * 5, periodicalRetxFrom4);
};
periodicalRetxFrom4();
this->advanceClocks(TICK, BestRouteStrategy2::RETX_SUPPRESSION_MAX * 16);
scheduler::cancel(retxFrom4Evt);
retxFrom4Evt.cancel();
// nexthops for accepted retransmissions: follow FIB cost,
// later forward to an eligible upstream with earliest out-record
+2 -1
View File
@@ -24,6 +24,7 @@
*/
#include "fw/forwarder.hpp"
#include "daemon/global.hpp"
#include "tests/test-common.hpp"
#include "tests/daemon/face/dummy-face.hpp"
@@ -545,7 +546,7 @@ BOOST_FIXTURE_TEST_CASE(InterestLoopWithShortLifetime, UnitTestTimeFixture) // B
face2->afterSend.connect([face1, face2] (uint32_t pktType) {
if (pktType == tlv::Interest) {
auto interest = make_shared<Interest>(face2->sentInterests.back());
scheduler::schedule(time::milliseconds(170), [face1, interest] { face1->receiveInterest(*interest); });
getScheduler().schedule(170_ms, [face1, interest] { face1->receiveInterest(*interest); });
}
});
+6 -5
View File
@@ -24,10 +24,11 @@
*/
#include "fw/multicast-strategy.hpp"
#include "strategy-tester.hpp"
#include "tests/daemon/face/dummy-face.hpp"
#include "daemon/global.hpp"
#include "tests/daemon/face/dummy-face.hpp"
#include "tests/test-common.hpp"
#include "strategy-tester.hpp"
namespace nfd {
namespace fw {
@@ -108,17 +109,17 @@ BOOST_AUTO_TEST_CASE(Forward2)
if (nSent > nSentLast) {
// Multicast strategy should multicast the interest to other two faces
BOOST_CHECK_EQUAL(nSent - nSentLast, 2);
time::steady_clock::TimePoint timeSent = time::steady_clock::now();
auto timeSent = time::steady_clock::now();
BOOST_CHECK_GE(timeSent - timeSentLast, TICK * 8);
nSentLast = nSent;
timeSentLast = timeSent;
}
retxFrom4Evt = scheduler::schedule(TICK * 5, periodicalRetxFrom4);
retxFrom4Evt = getScheduler().schedule(TICK * 5, periodicalRetxFrom4);
};
periodicalRetxFrom4();
this->advanceClocks(TICK, MulticastStrategy::RETX_SUPPRESSION_MAX * 16);
scheduler::cancel(retxFrom4Evt);
retxFrom4Evt.cancel();
}
BOOST_AUTO_TEST_CASE(RejectLoopback)
+2 -4
View File
@@ -24,12 +24,10 @@
*/
#include "fw/ncc-strategy.hpp"
#include "tests/daemon/face/dummy-face.hpp"
#include "strategy-tester.hpp"
#include "topology-tester.hpp"
#include "tests/daemon/face/dummy-face.hpp"
#include "tests/limited-io.hpp"
#include "tests/test-common.hpp"
namespace nfd {
namespace fw {
+1 -2
View File
@@ -31,12 +31,11 @@
#include "fw/best-route-strategy2.hpp"
#include "fw/multicast-strategy.hpp"
#include "tests/test-common.hpp"
#include "tests/limited-io.hpp"
#include "choose-strategy.hpp"
#include "strategy-tester.hpp"
#include "topology-tester.hpp"
#include "tests/daemon/face/dummy-face.hpp"
#include <boost/mpl/vector.hpp>
namespace nfd {
+1 -2
View File
@@ -34,11 +34,10 @@
#include "fw/best-route-strategy2.hpp"
#include "fw/multicast-strategy.hpp"
#include "tests/test-common.hpp"
#include "tests/limited-io.hpp"
#include "choose-strategy.hpp"
#include "strategy-tester.hpp"
#include "tests/daemon/face/dummy-face.hpp"
#include <boost/mpl/copy_if.hpp>
#include <boost/mpl/vector.hpp>
+1 -2
View File
@@ -35,11 +35,10 @@
#include "fw/multicast-strategy.hpp"
#include "fw/ncc-strategy.hpp"
#include "tests/test-common.hpp"
#include "tests/limited-io.hpp"
#include "choose-strategy.hpp"
#include "strategy-tester.hpp"
#include "tests/daemon/face/dummy-face.hpp"
#include <boost/mpl/copy_if.hpp>
#include <boost/mpl/vector.hpp>
+2 -1
View File
@@ -27,7 +27,8 @@
#define NFD_TESTS_DAEMON_FW_STRATEGY_TESTER_HPP
#include "fw/strategy.hpp"
#include "tests/limited-io.hpp"
#include "tests/daemon/limited-io.hpp"
namespace nfd {
namespace fw {
+5 -3
View File
@@ -24,6 +24,7 @@
*/
#include "topology-tester.hpp"
#include "daemon/global.hpp"
#include "face/generic-link-service.hpp"
#include <ndn-cxx/encoding/encoding-buffer-fwd.hpp>
@@ -98,7 +99,7 @@ TopologyLink::transmit(TopologyNode i, const Block& packet)
void
TopologyLink::scheduleReceive(InternalTransportBase* recipient, const Block& packet)
{
scheduler::schedule(m_delay, [packet, recipient] {
getScheduler().schedule(m_delay, [packet, recipient] {
recipient->receiveFromLink(packet);
});
}
@@ -271,8 +272,9 @@ TopologyTester::addIntervalConsumer(ndn::Face& face, const Name& prefix,
face.expressInterest(*interest, nullptr, nullptr, nullptr);
if (n > 1) {
scheduler::schedule(interval,
[=, &face] { addIntervalConsumer(face, prefix, interval, n - 1, seq); });
getScheduler().schedule(interval, [=, &face] {
addIntervalConsumer(face, prefix, interval, n - 1, seq);
});
}
}
@@ -23,27 +23,37 @@
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
#include "core/global-io.hpp"
#include "core/scheduler.hpp"
#include "daemon/global.hpp"
#include "tests/rib-io-fixture.hpp"
#include "tests/test-common.hpp"
#include "tests/daemon/rib-io-fixture.hpp"
#include <thread>
namespace nfd {
namespace tests {
BOOST_FIXTURE_TEST_SUITE(TestGlobalIo, BaseFixture)
BOOST_FIXTURE_TEST_SUITE(TestGlobal, BaseFixture)
BOOST_AUTO_TEST_CASE(ThreadLocalGlobalIoService)
BOOST_AUTO_TEST_CASE(ThreadLocalIoService)
{
boost::asio::io_service* s1 = &getGlobalIoService();
boost::asio::io_service* s2 = nullptr;
std::thread t([&s2] {
s2 = &getGlobalIoService();
});
std::thread t([&s2] { s2 = &getGlobalIoService(); });
t.join();
BOOST_CHECK(s1 != nullptr);
BOOST_CHECK(s2 != nullptr);
BOOST_CHECK(s1 != s2);
}
BOOST_AUTO_TEST_CASE(ThreadLocalScheduler)
{
scheduler::Scheduler* s1 = &getScheduler();
scheduler::Scheduler* s2 = nullptr;
std::thread t([&s2] { s2 = &getScheduler(); });
t.join();
BOOST_CHECK(s1 != nullptr);
@@ -115,7 +125,7 @@ BOOST_FIXTURE_TEST_CASE(AdvanceClocks, RibIoTimeFixture)
hasRibRun = false;
bool hasMainRun = false;
scheduler::schedule(250_ms, [&] {
getScheduler().schedule(250_ms, [&] {
hasMainRun = true;
runOnRibIoService([&] { hasRibRun = true; });
});
@@ -127,7 +137,7 @@ BOOST_FIXTURE_TEST_CASE(AdvanceClocks, RibIoTimeFixture)
BOOST_CHECK_EQUAL(hasRibRun, true);
}
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE_END() // TestGlobal
} // namespace tests
} // namespace nfd
@@ -24,8 +24,8 @@
*/
#include "limited-io.hpp"
#include "core/global-io.hpp"
#include "core/logger.hpp"
#include "daemon/global.hpp"
#include <boost/exception/diagnostic_information.hpp>
@@ -39,8 +39,6 @@ const time::nanoseconds LimitedIo::UNLIMITED_TIME = time::nanoseconds::min();
LimitedIo::LimitedIo(UnitTestTimeFixture* uttf)
: m_uttf(uttf)
, m_nOpsRemaining(0)
, m_isRunning(false)
{
}
@@ -58,7 +56,7 @@ LimitedIo::run(int nOpsLimit, const time::nanoseconds& timeLimit, const time::na
m_reason = NO_WORK;
m_nOpsRemaining = nOpsLimit;
if (timeLimit >= 0_ns) {
m_timeout = scheduler::schedule(timeLimit, [this] { afterTimeout(); });
m_timeout = getScheduler().schedule(timeLimit, [this] { afterTimeout(); });
}
try {
@@ -79,7 +77,7 @@ LimitedIo::run(int nOpsLimit, const time::nanoseconds& timeLimit, const time::na
}
getGlobalIoService().reset();
scheduler::cancel(m_timeout);
m_timeout.cancel();
m_isRunning = false;
return m_reason;
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2018, Regents of the University of California,
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -23,11 +23,10 @@
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef NFD_TESTS_LIMITED_IO_HPP
#define NFD_TESTS_LIMITED_IO_HPP
#ifndef NFD_TESTS_DAEMON_LIMITED_IO_HPP
#define NFD_TESTS_DAEMON_LIMITED_IO_HPP
#include "test-common.hpp"
#include "core/scheduler.hpp"
#include "tests/test-common.hpp"
#include <exception>
@@ -41,12 +40,10 @@ namespace tests {
class LimitedIo : noncopyable
{
public:
/** \brief construct with UnitTestTimeFixture
*/
explicit
LimitedIo(UnitTestTimeFixture* uttf = nullptr);
/// indicates why .run returns
/// indicates why run() returns
enum StopReason {
/// g_io.run() returns normally because there's no work to do
NO_WORK,
@@ -105,13 +102,13 @@ public:
private:
UnitTestTimeFixture* m_uttf;
StopReason m_reason;
int m_nOpsRemaining;
int m_nOpsRemaining = 0;
scheduler::EventId m_timeout;
std::exception_ptr m_lastException;
bool m_isRunning;
bool m_isRunning = false;
};
} // namespace tests
} // namespace nfd
#endif // NFD_TESTS_LIMITED_IO_HPP
#endif // NFD_TESTS_DAEMON_LIMITED_IO_HPP
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2018, Regents of the University of California,
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -24,6 +24,7 @@
*/
#include "face-manager-command-fixture.hpp"
#include "daemon/global.hpp"
#include <ndn-cxx/net/network-monitor-stub.hpp>
+1 -1
View File
@@ -54,7 +54,7 @@ CommandInterestSignerFixture::makeControlCommandRequest(Name commandName,
}
ManagerCommonFixture::ManagerCommonFixture()
: m_face(getGlobalIoService(), m_keyChain, {true, true})
: m_face(g_io, m_keyChain, {true, true})
, m_dispatcher(m_face, m_keyChain, ndn::security::SigningInfo())
, m_responses(m_face.sentData)
{
@@ -163,7 +163,7 @@ public:
private:
ndn::util::DummyClientFace m_face;
ndn::util::Scheduler m_scheduler;
Scheduler m_scheduler;
ndn::nfd::Controller m_nfdController;
Dispatcher m_dispatcher;
rib::FibUpdater m_fibUpdater;
+1 -1
View File
@@ -205,7 +205,7 @@ protected:
std::vector<Interest>& m_commands;
ConfigurationStatus m_status;
ndn::util::Scheduler m_scheduler;
Scheduler m_scheduler;
ndn::nfd::Controller m_nfdController;
rib::Rib m_rib;
rib::FibUpdater m_fibUpdater;
@@ -24,6 +24,7 @@
*/
#include "rib-io-fixture.hpp"
#include "daemon/global.hpp"
#include <boost/exception/diagnostic_information.hpp>
@@ -23,8 +23,8 @@
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef NFD_TESTS_RIB_IO_FIXTURE_HPP
#define NFD_TESTS_RIB_IO_FIXTURE_HPP
#ifndef NFD_TESTS_DAEMON_RIB_IO_FIXTURE_HPP
#define NFD_TESTS_DAEMON_RIB_IO_FIXTURE_HPP
#include "tests/test-common.hpp"
@@ -102,4 +102,4 @@ protected:
} // namespace tests
} // namespace nfd
#endif // NFD_TESTS_RIB_IO_FIXTURE_HPP
#endif // NFD_TESTS_DAEMON_RIB_IO_FIXTURE_HPP
@@ -58,7 +58,7 @@ public:
protected:
ndn::util::DummyClientFace face;
ndn::util::Scheduler scheduler;
Scheduler scheduler;
ndn::nfd::Controller controller;
Rib rib;
NfdRibReadvertiseDestination dest;
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2018, Regents of the University of California,
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -159,7 +159,7 @@ protected:
private:
ndn::util::DummyClientFace m_face;
ndn::util::Scheduler m_scheduler;
Scheduler m_scheduler;
Rib m_rib;
};
+4 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2018, Regents of the University of California,
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -24,8 +24,10 @@
*/
#include "rib/service.hpp"
#include "tests/rib-io-fixture.hpp"
#include "daemon/global.hpp"
#include "tests/test-common.hpp"
#include "tests/daemon/rib-io-fixture.hpp"
namespace nfd {
namespace rib {
+4 -4
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2016, Regents of the University of California,
/*
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -24,6 +24,7 @@
*/
#include "table/dead-nonce-list.hpp"
#include "daemon/global.hpp"
#include "tests/test-common.hpp"
@@ -85,8 +86,7 @@ protected:
}
if (addNonceInterval > time::nanoseconds::zero()) {
addNonceEvent = scheduler::schedule(addNonceInterval,
bind(&PeriodicalInsertionFixture::addNonce, this));
addNonceEvent = getScheduler().schedule(addNonceInterval, [this] { addNonce(); });
}
}
+1 -1
View File
@@ -23,7 +23,7 @@
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
#include "core/global-io.hpp"
#include "daemon/global.hpp"
#include "face/face.hpp"
#include "face/tcp-channel.hpp"
#include "face/udp-channel.hpp"
+3 -1
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2018, Regents of the University of California,
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -24,6 +24,8 @@
*/
#include "test-common.hpp"
#include "daemon/global.hpp"
#include <ndn-cxx/security/signature-sha256-with-rsa.hpp>
namespace nfd {
+9 -9
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2018, Regents of the University of California,
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -28,7 +28,7 @@
#include "boost-test.hpp"
#include "core/global-io.hpp"
#include "core/common.hpp"
#include <ndn-cxx/prefix-announcement.hpp>
#include <ndn-cxx/util/time-unit-test-clock.hpp>
@@ -157,22 +157,22 @@ makeNack(const Name& name, uint32_t nonce, lp::NackReason reason);
* \param index name component index
* \param a arguments to name::Component constructor
*/
template<typename...A>
template<typename... A>
void
setNameComponent(Name& name, ssize_t index, const A& ...a)
setNameComponent(Name& name, ssize_t index, A&&... a)
{
Name name2 = name.getPrefix(index);
name2.append(name::Component(a...));
name2.append(name::Component(std::forward<A>(a)...));
name2.append(name.getSubName(name2.size()));
name = name2;
name = std::move(name2);
}
template<typename Packet, typename...A>
template<typename Packet, typename... A>
void
setNameComponent(Packet& packet, ssize_t index, const A& ...a)
setNameComponent(Packet& packet, ssize_t index, A&&... a)
{
Name name = packet.getName();
setNameComponent(name, index, a...);
setNameComponent(name, index, std::forward<A>(a)...);
packet.setName(name);
}
+8 -8
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2018, Regents of the University of California,
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -24,7 +24,6 @@
*/
#include "nfdc/status-report.hpp"
#include "core/scheduler.hpp"
#include "status-fixture.hpp"
@@ -49,9 +48,9 @@ module2
class DummyModule : public Module
{
public:
explicit
DummyModule(const std::string& moduleName)
DummyModule(const std::string& moduleName, boost::asio::io_service& io)
: m_moduleName(moduleName)
, m_scheduler(io)
, m_res(0)
, m_delay(time::milliseconds(1))
{
@@ -70,13 +69,13 @@ public:
}
void
fetchStatus(Controller& controller,
fetchStatus(Controller&,
const std::function<void()>& onSuccess,
const Controller::DatasetFailCallback& onFailure,
const CommandOptions& options) final
const CommandOptions&) final
{
++nFetchStatusCalls;
scheduler::schedule(m_delay, [=] {
m_scheduler.schedule(m_delay, [=] {
if (m_res == 0) {
onSuccess();
}
@@ -103,6 +102,7 @@ public:
private:
std::string m_moduleName;
Scheduler m_scheduler;
uint32_t m_res;
time::nanoseconds m_delay;
};
@@ -133,7 +133,7 @@ protected:
DummyModule&
addModule(const std::string& moduleName)
{
report.sections.push_back(make_unique<DummyModule>(moduleName));
report.sections.push_back(make_unique<DummyModule>(moduleName, g_io));
return static_cast<DummyModule&>(*report.sections.back());
}
+4
View File
@@ -62,6 +62,10 @@ def build(bld):
src += node.ant_glob('face/unix*.cpp')
if bld.env.HAVE_WEBSOCKET:
src += node.ant_glob('face/websocket*.cpp')
if module == 'core' or module == 'tools':
src += ['../daemon/global.cpp']
if module == 'rib':
src += ['daemon/limited-io.cpp', 'daemon/rib-io-fixture.cpp']
objmod = 'daemon' if module == 'rib' else module
# unit-tests binary for the module
Loaded 100 of 101 files, more files were not shown because too many files have changed in this diff. Show more