rib: stop using the global scheduler

Change-Id: I0e205e2f1adf85be49b132b47791b27e4530697a
Refs: #4528
diff --git a/rib/auto-prefix-propagator.cpp b/rib/auto-prefix-propagator.cpp
index 13124d2..a03302a 100644
--- a/rib/auto-prefix-propagator.cpp
+++ b/rib/auto-prefix-propagator.cpp
@@ -25,7 +25,6 @@
 
 #include "auto-prefix-propagator.hpp"
 #include "core/logger.hpp"
-#include "core/scheduler.hpp"
 
 #include <ndn-cxx/security/pib/identity.hpp>
 #include <ndn-cxx/security/pib/identity-container.hpp>
@@ -39,6 +38,7 @@
 
 using ndn::nfd::ControlParameters;
 using ndn::nfd::CommandOptions;
+using ndn::util::scheduler::EventCallback;
 
 const Name LOCAL_REGISTRATION_PREFIX("/localhost");
 const Name LINK_LOCAL_NFD_PREFIX("/localhop/nfd");
@@ -52,9 +52,11 @@
 
 AutoPrefixPropagator::AutoPrefixPropagator(ndn::nfd::Controller& controller,
                                            ndn::KeyChain& keyChain,
+                                           ndn::util::Scheduler& scheduler,
                                            Rib& rib)
   : m_nfdController(controller)
   , m_keyChain(keyChain)
+  , m_scheduler(scheduler)
   , m_rib(rib)
   , m_refreshInterval(PREFIX_PROPAGATION_DEFAULT_REFRESH_INTERVAL)
   , m_baseRetryWait(PREFIX_PROPAGATION_DEFAULT_BASE_RETRY_WAIT)
@@ -279,9 +281,9 @@
 {
   NFD_LOG_INFO("advertise " << parameters.getName());
 
-  scheduler::EventCallback refreshEvent =
+  EventCallback refreshEvent =
     bind(&AutoPrefixPropagator::onRefreshTimer, this, parameters, options);
-  scheduler::EventCallback retryEvent =
+  EventCallback retryEvent =
     bind(&AutoPrefixPropagator::onRetryTimer, this, parameters, options,
          std::min(m_maxRetryWait, retryWaitTime * 2));
 
@@ -388,7 +390,7 @@
 void
 AutoPrefixPropagator::afterPropagateSucceed(const ControlParameters& parameters,
                                             const CommandOptions& options,
-                                            const scheduler::EventCallback& refreshEvent)
+                                            const EventCallback& refreshEvent)
 {
   NFD_LOG_TRACE("success to propagate " << parameters.getName());
 
@@ -402,7 +404,7 @@
 
   // PROPAGATING --> PROPAGATED
   BOOST_ASSERT(entryIt->second.isPropagating());
-  entryIt->second.succeed(scheduler::schedule(m_refreshInterval, refreshEvent));
+  entryIt->second.succeed(m_scheduler, m_scheduler.scheduleEvent(m_refreshInterval, refreshEvent));
 }
 
 void
@@ -410,7 +412,7 @@
                                          const ControlParameters& parameters,
                                          const CommandOptions& options,
                                          time::seconds retryWaitTime,
-                                         const scheduler::EventCallback& retryEvent)
+                                         const EventCallback& retryEvent)
 {
   NFD_LOG_TRACE("fail to propagate " << parameters.getName()
                                      << "\n\t reason:" << response.getText()
@@ -424,7 +426,7 @@
 
   // PROPAGATING --> PROPAGATE_FAIL
   BOOST_ASSERT(entryIt->second.isPropagating());
-  entryIt->second.fail(scheduler::schedule(retryWaitTime, retryEvent));
+  entryIt->second.fail(m_scheduler, m_scheduler.scheduleEvent(retryWaitTime, retryEvent));
 }
 
 void
diff --git a/rib/auto-prefix-propagator.hpp b/rib/auto-prefix-propagator.hpp
index cbbe362..802a105 100644
--- a/rib/auto-prefix-propagator.hpp
+++ b/rib/auto-prefix-propagator.hpp
@@ -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-2018,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -26,15 +26,16 @@
 #ifndef NFD_RIB_AUTO_PREFIX_PROPAGATOR_HPP
 #define NFD_RIB_AUTO_PREFIX_PROPAGATOR_HPP
 
+#include "propagated-entry.hpp"
 #include "rib.hpp"
 #include "core/config-file.hpp"
-#include "propagated-entry.hpp"
 
 #include <ndn-cxx/security/key-chain.hpp>
 #include <ndn-cxx/mgmt/nfd/controller.hpp>
 #include <ndn-cxx/mgmt/nfd/control-command.hpp>
 #include <ndn-cxx/mgmt/nfd/control-parameters.hpp>
 #include <ndn-cxx/mgmt/nfd/command-options.hpp>
+#include <ndn-cxx/util/scheduler.hpp>
 #include <ndn-cxx/util/signal.hpp>
 
 namespace nfd {
@@ -88,6 +89,7 @@
 
   AutoPrefixPropagator(ndn::nfd::Controller& controller,
                        ndn::KeyChain& keyChain,
+                       ndn::util::Scheduler& scheduler,
                        Rib& rib);
   /**
    * @brief load the "auto_prefix_propagate" section from config file
@@ -310,7 +312,7 @@
   void
   afterPropagateSucceed(const ndn::nfd::ControlParameters& parameters,
                         const ndn::nfd::CommandOptions& options,
-                        const scheduler::EventCallback& refreshEvent);
+                        const ndn::util::scheduler::EventCallback& refreshEvent);
 
   /**
    * @brief invoked after propagation fails.
@@ -331,7 +333,7 @@
                      const ndn::nfd::ControlParameters& parameters,
                      const ndn::nfd::CommandOptions& options,
                      time::seconds retryWaitTime,
-                     const scheduler::EventCallback& retryEvent);
+                     const ndn::util::scheduler::EventCallback& retryEvent);
 
   /**
    * @brief invoked after revocation succeeds
@@ -397,6 +399,7 @@
 PUBLIC_WITH_TESTS_ELSE_PRIVATE:
   ndn::nfd::Controller& m_nfdController;
   ndn::KeyChain& m_keyChain;
+  ndn::util::Scheduler& m_scheduler;
   Rib& m_rib;
   ndn::util::signal::ScopedConnection m_afterInsertConnection;
   ndn::util::signal::ScopedConnection m_afterEraseConnection;
diff --git a/rib/propagated-entry.cpp b/rib/propagated-entry.cpp
index dae3934..34a8976 100644
--- a/rib/propagated-entry.cpp
+++ b/rib/propagated-entry.cpp
@@ -50,11 +50,6 @@
   }
 }
 
-PropagatedEntry::PropagatedEntry()
-  : m_propagationStatus(PropagationStatus::NEW)
-{
-}
-
 PropagatedEntry::PropagatedEntry(const PropagatedEntry& other)
   : m_signingIdentity(other.m_signingIdentity)
   , m_propagationStatus(other.m_propagationStatus)
@@ -82,24 +77,27 @@
 }
 
 void
-PropagatedEntry::succeed(const scheduler::EventId& event)
+PropagatedEntry::succeed(ndn::util::Scheduler& scheduler, const ndn::util::scheduler::EventId& event)
 {
   m_propagationStatus = PropagationStatus::PROPAGATED;
-  m_rePropagateEvent = event;
+  m_rePropagateEvent = ndn::util::scheduler::ScopedEventId(scheduler);
+  *m_rePropagateEvent = event;
 }
 
 void
-PropagatedEntry::fail(const scheduler::EventId& event)
+PropagatedEntry::fail(ndn::util::Scheduler& scheduler, const ndn::util::scheduler::EventId& event)
 {
   m_propagationStatus = PropagationStatus::PROPAGATE_FAIL;
-  m_rePropagateEvent = event;
+  m_rePropagateEvent = ndn::util::scheduler::ScopedEventId(scheduler);
+  *m_rePropagateEvent = event;
 }
 
 void
 PropagatedEntry::initialize()
 {
   m_propagationStatus = PropagationStatus::NEW;
-  m_rePropagateEvent.cancel();
+  if (m_rePropagateEvent)
+    m_rePropagateEvent->cancel();
 }
 
 bool
diff --git a/rib/propagated-entry.hpp b/rib/propagated-entry.hpp
index f4e61dd..c4b0601 100644
--- a/rib/propagated-entry.hpp
+++ b/rib/propagated-entry.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-2018,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -26,7 +26,9 @@
 #ifndef NFD_RIB_PROPAGATED_ENTRY_HPP
 #define NFD_RIB_PROPAGATED_ENTRY_HPP
 
-#include "core/scheduler.hpp"
+#include "core/common.hpp"
+
+#include <ndn-cxx/util/scheduler-scoped-event-id.hpp>
 
 namespace nfd {
 namespace rib {
@@ -47,7 +49,6 @@
 
 /**
  * @brief represents an entry for prefix propagation.
- * @sa http://redmine.named-data.net/issues/3211
  *
  * it consists of a PropagationStatus indicates current state of the state machine, as
  * well as an event scheduled for refresh or retry (i.e., the RefreshTimer and the RetryTimer of
@@ -56,7 +57,7 @@
 class PropagatedEntry
 {
 public:
-  PropagatedEntry();
+  PropagatedEntry() = default;
 
   /**
    * @pre other is not in PROPAGATED or PROPAGATE_FAIL state
@@ -95,7 +96,7 @@
    * this is called just after this entry is successfully propagated.
    */
   void
-  succeed(const scheduler::EventId& event);
+  succeed(ndn::util::Scheduler& scheduler, const ndn::util::scheduler::EventId& event);
 
   /**
    * @brief switch the propagation status to PROPAGATE_FAIL, and then set the
@@ -104,7 +105,7 @@
    * this is called just after propagation for this entry fails.
    */
   void
-  fail(const scheduler::EventId& event);
+  fail(ndn::util::Scheduler& scheduler, const ndn::util::scheduler::EventId& event);
 
   /**
    * @brief cancel the events of re-sending propagation commands.
@@ -148,8 +149,8 @@
 
 PUBLIC_WITH_TESTS_ELSE_PRIVATE:
   Name m_signingIdentity;
-  scheduler::ScopedEventId m_rePropagateEvent;
-  PropagationStatus m_propagationStatus;
+  optional<ndn::util::scheduler::ScopedEventId> m_rePropagateEvent;
+  PropagationStatus m_propagationStatus = PropagationStatus::NEW;
 };
 
 } // namespace rib
diff --git a/rib/readvertise/readvertise.cpp b/rib/readvertise/readvertise.cpp
index 7a467ef..09715eb 100644
--- a/rib/readvertise/readvertise.cpp
+++ b/rib/readvertise/readvertise.cpp
@@ -43,9 +43,11 @@
   return std::max(newTime, 0_ms);
 }
 
-Readvertise::Readvertise(Rib& rib, unique_ptr<ReadvertisePolicy> policy,
+Readvertise::Readvertise(Rib& rib, ndn::util::Scheduler& scheduler,
+                         unique_ptr<ReadvertisePolicy> policy,
                          unique_ptr<ReadvertiseDestination> destination)
-  : m_policy(std::move(policy))
+  : m_scheduler(scheduler)
+  , m_policy(std::move(policy))
   , m_destination(std::move(destination))
 {
   m_addRouteConn = rib.afterAddRoute.connect([this] (const auto& r) { this->afterAddRoute(r); });
@@ -73,7 +75,7 @@
 
   ReadvertisedRouteContainer::iterator rrIt;
   bool isNew = false;
-  std::tie(rrIt, isNew) = m_rrs.emplace(action->prefix);
+  std::tie(rrIt, isNew) = m_rrs.emplace(action->prefix, m_scheduler);
 
   if (!isNew && rrIt->signer != action->signer) {
     NFD_LOG_WARN("add-route " << ribRoute.entry->getName() << '(' << ribRoute.route->faceId <<
@@ -159,14 +161,14 @@
     [=] {
       NFD_LOG_DEBUG("advertise " << rrIt->prefix << " success");
       rrIt->retryDelay = RETRY_DELAY_MIN;
-      rrIt->retryEvt = scheduler::schedule(randomizeTimer(m_policy->getRefreshInterval()),
-                                           [=] { advertise(rrIt); });
+      rrIt->retryEvt = m_scheduler.scheduleEvent(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 = scheduler::schedule(randomizeTimer(rrIt->retryDelay),
-                                           [=] { advertise(rrIt); });
+      rrIt->retryEvt = m_scheduler.scheduleEvent(randomizeTimer(rrIt->retryDelay),
+                                                 [=] { advertise(rrIt); });
     });
 }
 
@@ -189,7 +191,8 @@
     [=] (const std::string& msg) {
       NFD_LOG_DEBUG("withdraw " << rrIt->prefix << " failure " << msg);
       rrIt->retryDelay = std::min(RETRY_DELAY_MAX, rrIt->retryDelay * 2);
-      rrIt->retryEvt = scheduler::schedule(randomizeTimer(rrIt->retryDelay), [=] { withdraw(rrIt); });
+      rrIt->retryEvt = m_scheduler.scheduleEvent(randomizeTimer(rrIt->retryDelay),
+                                                 [=] { withdraw(rrIt); });
     });
 }
 
diff --git a/rib/readvertise/readvertise.hpp b/rib/readvertise/readvertise.hpp
index 13a6e59..c1a3b58 100644
--- a/rib/readvertise/readvertise.hpp
+++ b/rib/readvertise/readvertise.hpp
@@ -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-2018,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -30,7 +30,6 @@
 #include "readvertise-policy.hpp"
 #include "readvertised-route.hpp"
 #include "../rib.hpp"
-#include "core/scheduler.hpp"
 
 namespace nfd {
 namespace rib {
@@ -47,6 +46,7 @@
 
 public:
   Readvertise(Rib& rib,
+              ndn::util::Scheduler& scheduler,
               unique_ptr<ReadvertisePolicy> policy,
               unique_ptr<ReadvertiseDestination> destination);
 
@@ -77,6 +77,7 @@
   static const time::milliseconds RETRY_DELAY_MIN;
   static const time::milliseconds RETRY_DELAY_MAX;
 
+  ndn::util::Scheduler& m_scheduler;
   unique_ptr<ReadvertisePolicy> m_policy;
   unique_ptr<ReadvertiseDestination> m_destination;
 
diff --git a/rib/readvertise/readvertised-route.cpp b/rib/readvertise/readvertised-route.cpp
deleted file mode 100644
index 7028697..0000000
--- a/rib/readvertise/readvertised-route.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2017,  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 "readvertised-route.hpp"
-#include "core/random.hpp"
-
-namespace nfd {
-namespace rib {
-
-ReadvertisedRoute::ReadvertisedRoute(const Name& prefix)
-  : prefix(prefix)
-  , nRibRoutes(0)
-{
-}
-
-} // namespace rib
-} // namespace nfd
diff --git a/rib/readvertise/readvertised-route.hpp b/rib/readvertise/readvertised-route.hpp
index 0692ccd..c2ca848 100644
--- a/rib/readvertise/readvertised-route.hpp
+++ b/rib/readvertise/readvertised-route.hpp
@@ -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-2018,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -26,8 +26,10 @@
 #ifndef NFD_RIB_READVERTISE_READVERTISED_ROUTE_HPP
 #define NFD_RIB_READVERTISE_READVERTISED_ROUTE_HPP
 
-#include "core/scheduler.hpp"
+#include "core/common.hpp"
+
 #include <ndn-cxx/security/signing-info.hpp>
+#include <ndn-cxx/util/scheduler-scoped-event-id.hpp>
 
 namespace nfd {
 namespace rib {
@@ -37,15 +39,20 @@
 class ReadvertisedRoute : noncopyable
 {
 public:
-  explicit
-  ReadvertisedRoute(const Name& prefix);
+  ReadvertisedRoute(const Name& prefix, ndn::util::Scheduler& scheduler)
+    : prefix(prefix)
+    , nRibRoutes(0)
+    , retryDelay(0)
+    , retryEvt(scheduler)
+  {
+  }
 
 public:
   Name prefix; ///< readvertised prefix
   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 scheduler::ScopedEventId retryEvt; ///< retry or refresh event
+  mutable ndn::util::scheduler::ScopedEventId retryEvt; ///< retry or refresh event
 };
 
 inline bool
diff --git a/rib/rib-entry.cpp b/rib/rib-entry.cpp
index d59338d..008ac4f 100644
--- a/rib/rib-entry.cpp
+++ b/rib/rib-entry.cpp
@@ -116,8 +116,8 @@
     }
 
     // Cancel any scheduled event
-    NFD_LOG_TRACE("Cancelling expiration eventId: " << route->getExpirationEvent());
-    scheduler::cancel(route->getExpirationEvent());
+    NFD_LOG_TRACE("Cancelling expiration event: " << route->getExpirationEvent());
+    route->cancelExpirationEvent();
 
     return m_routes.erase(route);
   }
diff --git a/rib/rib-manager.cpp b/rib/rib-manager.cpp
index 009b9ad..5ba99b8 100644
--- a/rib/rib-manager.cpp
+++ b/rib/rib-manager.cpp
@@ -27,7 +27,6 @@
 
 #include "core/fib-max-depth.hpp"
 #include "core/logger.hpp"
-#include "core/scheduler.hpp"
 
 #include <ndn-cxx/lp/tags.hpp>
 #include <ndn-cxx/mgmt/nfd/control-command.hpp>
@@ -44,19 +43,22 @@
 static const std::string MGMT_MODULE_NAME = "rib";
 static const Name LOCALHOST_TOP_PREFIX = "/localhost/nfd";
 static const Name LOCALHOP_TOP_PREFIX = "/localhop/nfd";
-static const time::seconds ACTIVE_FACE_FETCH_INTERVAL = time::seconds(300);
+static const time::seconds ACTIVE_FACE_FETCH_INTERVAL = 5_min;
 
 RibManager::RibManager(Rib& rib, ndn::Face& face, ndn::KeyChain& keyChain,
-                       ndn::nfd::Controller& nfdController, Dispatcher& dispatcher)
+                       ndn::nfd::Controller& nfdController, Dispatcher& dispatcher,
+                       ndn::util::Scheduler& scheduler)
   : ManagerBase(dispatcher, MGMT_MODULE_NAME)
   , m_rib(rib)
   , m_keyChain(keyChain)
   , m_nfdController(nfdController)
   , m_dispatcher(dispatcher)
+  , m_scheduler(scheduler)
   , m_faceMonitor(face)
   , m_localhostValidator(face)
   , m_localhopValidator(face)
   , m_isLocalhopEnabled(false)
+  , m_activeFaceFetchEvent(m_scheduler)
 {
   registerCommandHandler<ndn::nfd::RibRegisterCommand>("register",
     bind(&RibManager::registerEntry, this, _2, _3, _4, _5));
@@ -135,8 +137,8 @@
                " origin=" << route.origin << " cost=" << route.cost);
 
   if (expires) {
-    route.setExpirationEvent(scheduler::schedule(
-      *expires, [=] { m_rib.onRouteExpiration(name, route); }));
+    auto event = m_scheduler.scheduleEvent(*expires, [=] { m_rib.onRouteExpiration(name, route); });
+    route.setExpirationEvent(event, m_scheduler);
     NFD_LOG_TRACE("Scheduled unregistration at: " << *route.expires);
   }
 
@@ -455,7 +457,7 @@
 void
 RibManager::scheduleActiveFaceFetch(const time::seconds& timeToWait)
 {
-  m_activeFaceFetchEvent = scheduler::schedule(timeToWait, [this] { this->fetchActiveFaces(); });
+  m_activeFaceFetchEvent = m_scheduler.scheduleEvent(timeToWait, [this] { fetchActiveFaces(); });
 }
 
 void
@@ -473,7 +475,7 @@
   for (auto faceId : m_registeredFaces) {
     if (activeFaceIds.count(faceId) == 0) {
       NFD_LOG_DEBUG("Removing invalid face ID: " << faceId);
-      scheduler::schedule(time::seconds(0), [this, faceId] { this->onFaceDestroyedEvent(faceId); });
+      m_scheduler.scheduleEvent(0_ns, [this, faceId] { this->onFaceDestroyedEvent(faceId); });
     }
   }
 
@@ -488,9 +490,7 @@
 
   if (notification.getKind() == ndn::nfd::FACE_EVENT_DESTROYED) {
     NFD_LOG_DEBUG("Received notification for destroyed faceId: " << notification.getFaceId());
-
-    scheduler::schedule(time::seconds(0),
-                        bind(&RibManager::onFaceDestroyedEvent, this, notification.getFaceId()));
+    m_scheduler.scheduleEvent(0_ns, [this, id = notification.getFaceId()] { onFaceDestroyedEvent(id); });
   }
 }
 
diff --git a/rib/rib-manager.hpp b/rib/rib-manager.hpp
index 0ae96a4..bb1a970 100644
--- a/rib/rib-manager.hpp
+++ b/rib/rib-manager.hpp
@@ -54,8 +54,8 @@
     using std::runtime_error::runtime_error;
   };
 
-  RibManager(Rib& rib, ndn::Face& face, ndn::KeyChain& keyChain,
-             ndn::nfd::Controller& nfdController, Dispatcher& dispatcher);
+  RibManager(Rib& rib, ndn::Face& face, ndn::KeyChain& keyChain, ndn::nfd::Controller& nfdController,
+             Dispatcher& dispatcher, ndn::util::Scheduler& scheduler);
 
   /**
    * @brief Apply localhost_security configuration.
@@ -234,19 +234,9 @@
   void
   scheduleActiveFaceFetch(const time::seconds& timeToWait);
 
-  /**
-   * @brief remove invalid faces
-   *
-   * @param status Face dataset
-  */
   void
   removeInvalidFaces(const std::vector<ndn::nfd::FaceStatus>& activeFaces);
 
-  /**
-   * @brief response to face events
-   *
-   * @param notification
-   */
   void
   onNotification(const ndn::nfd::FaceEventNotification& notification);
 
@@ -255,21 +245,16 @@
   ndn::KeyChain& m_keyChain;
   ndn::nfd::Controller& m_nfdController;
   Dispatcher& m_dispatcher;
+  ndn::util::Scheduler& m_scheduler;
 
   ndn::nfd::FaceMonitor m_faceMonitor;
   ndn::ValidatorConfig m_localhostValidator;
   ndn::ValidatorConfig m_localhopValidator;
   bool m_isLocalhopEnabled;
 
-  static const std::map<RibManager::RibUpdateResult, RibManager::SlAnnounceResult> RIB_RESULT_TO_SL_ANNOUNCE_RESULT;
-
-private:
-  scheduler::ScopedEventId m_activeFaceFetchEvent;
-
-  typedef std::set<uint64_t> FaceIdSet;
-  /** \brief contains FaceIds with one or more Routes in the RIB
-  */
-  FaceIdSet m_registeredFaces;
+  ndn::util::scheduler::ScopedEventId m_activeFaceFetchEvent;
+  using FaceIdSet = std::set<uint64_t>;
+  FaceIdSet m_registeredFaces; ///< contains FaceIds with one or more Routes in the RIB
 };
 
 std::ostream&
diff --git a/rib/rib.cpp b/rib/rib.cpp
index 5385cf1..d209f63 100644
--- a/rib/rib.cpp
+++ b/rib/rib.cpp
@@ -51,8 +51,6 @@
 {
 }
 
-Rib::~Rib() = default;
-
 void
 Rib::setFibUpdater(FibUpdater* updater)
 {
@@ -107,16 +105,12 @@
     else {
       // Route exists, update fields
       // First cancel old scheduled event, if any, then set the EventId to new one
-      if (static_cast<bool>(entryIt->getExpirationEvent())) {
-        NFD_LOG_TRACE("Cancelling expiration event for " << entry->getName() << " "
-                                                         << (*entryIt));
-        scheduler::cancel(entryIt->getExpirationEvent());
+      if (entryIt->getExpirationEvent()) {
+        NFD_LOG_TRACE("Cancelling expiration event for " << entry->getName() << " " << *entryIt);
+        entryIt->cancelExpirationEvent();
       }
 
       *entryIt = route;
-
-      // No checks are required here as the iterator needs to be updated in all cases.
-      entryIt->setExpirationEvent(route.getExpirationEvent());
     }
   }
   else {
diff --git a/rib/rib.hpp b/rib/rib.hpp
index a2539b8..5beea2d 100644
--- a/rib/rib.hpp
+++ b/rib/rib.hpp
@@ -38,8 +38,8 @@
 
 class FibUpdater;
 
-  /** \brief references a route
-   */
+/** \brief references a route
+ */
 struct RibRouteRef
 {
   shared_ptr<RibEntry> entry;
@@ -68,8 +68,6 @@
 
   Rib();
 
-  ~Rib();
-
   void
   setFibUpdater(FibUpdater* updater);
 
diff --git a/rib/route.hpp b/rib/route.hpp
index 8106406..cc4ff02 100644
--- a/rib/route.hpp
+++ b/rib/route.hpp
@@ -26,11 +26,12 @@
 #ifndef NFD_RIB_ROUTE_HPP
 #define NFD_RIB_ROUTE_HPP
 
-#include "core/scheduler.hpp"
+#include "core/common.hpp"
 
 #include <ndn-cxx/encoding/nfd-constants.hpp>
 #include <ndn-cxx/mgmt/nfd/route-flags-traits.hpp>
 #include <ndn-cxx/prefix-announcement.hpp>
+#include <ndn-cxx/util/scheduler.hpp>
 
 #include <type_traits>
 
@@ -52,18 +53,26 @@
    */
   Route(const ndn::PrefixAnnouncement& ann, uint64_t faceId);
 
-  void
-  setExpirationEvent(const scheduler::EventId eid)
-  {
-    m_expirationEvent = eid;
-  }
-
-  const scheduler::EventId&
+  const ndn::util::scheduler::EventId&
   getExpirationEvent() const
   {
     return m_expirationEvent;
   }
 
+  void
+  setExpirationEvent(const ndn::util::scheduler::EventId& eid, ndn::util::Scheduler& scheduler)
+  {
+    m_expirationEvent = eid;
+    m_scheduler = &scheduler;
+  }
+
+  void
+  cancelExpirationEvent() const
+  {
+    if (m_scheduler)
+      m_scheduler->cancelEvent(m_expirationEvent);
+  }
+
   std::underlying_type<ndn::nfd::RouteFlags>::type
   getFlags() const
   {
@@ -94,7 +103,8 @@
   time::steady_clock::TimePoint annExpires;
 
 private:
-  scheduler::EventId m_expirationEvent;
+  ndn::util::scheduler::EventId m_expirationEvent;
+  ndn::util::Scheduler* m_scheduler;
 };
 
 bool
diff --git a/rib/service.cpp b/rib/service.cpp
index 7557f2f..48ff69c 100644
--- a/rib/service.cpp
+++ b/rib/service.cpp
@@ -105,10 +105,11 @@
                  const ConfigParseFunc& configParse)
   : m_keyChain(keyChain)
   , m_face(std::move(localNfdTransport), getGlobalIoService(), m_keyChain)
+  , m_scheduler(m_face.getIoService())
   , m_nfdController(m_face, m_keyChain)
   , m_fibUpdater(m_rib, m_nfdController)
   , m_dispatcher(m_face, m_keyChain)
-  , m_ribManager(m_rib, m_face, m_keyChain, m_nfdController, m_dispatcher)
+  , m_ribManager(m_rib, m_face, m_keyChain, m_nfdController, m_dispatcher, m_scheduler)
 {
   if (s_instance != nullptr) {
     BOOST_THROW_EXCEPTION(std::logic_error("RIB service cannot be instantiated more than once"));
@@ -194,7 +195,8 @@
     }
     else if (key == CFG_PREFIX_PROPAGATE) {
       if (m_prefixPropagator == nullptr) {
-        m_prefixPropagator = make_unique<AutoPrefixPropagator>(m_nfdController, m_keyChain, m_rib);
+        m_prefixPropagator = make_unique<AutoPrefixPropagator>(m_nfdController, m_keyChain,
+                                                               m_scheduler, m_rib);
       }
       m_prefixPropagator->loadConfig(item.second);
       m_prefixPropagator->enable();
@@ -216,6 +218,7 @@
     NFD_LOG_DEBUG("Enabling readvertise-to-nlsr");
     m_readvertiseNlsr = make_unique<Readvertise>(
       m_rib,
+      m_scheduler,
       make_unique<ClientToNlsrReadvertisePolicy>(),
       make_unique<NfdRibReadvertiseDestination>(m_nfdController, READVERTISE_NLSR_PREFIX, m_rib));
   }
diff --git a/rib/service.hpp b/rib/service.hpp
index 135df58..0b06013 100644
--- a/rib/service.hpp
+++ b/rib/service.hpp
@@ -35,6 +35,7 @@
 #include <ndn-cxx/mgmt/nfd/controller.hpp>
 #include <ndn-cxx/security/key-chain.hpp>
 #include <ndn-cxx/transport/transport.hpp>
+#include <ndn-cxx/util/scheduler.hpp>
 
 namespace nfd {
 namespace rib {
@@ -110,6 +111,7 @@
 
   ndn::KeyChain& m_keyChain;
   ndn::Face m_face;
+  ndn::util::Scheduler m_scheduler;
   ndn::nfd::Controller m_nfdController;
 
   Rib m_rib;