[ndnSIM] core: Redirecting nfd::scheduler to ns3::Simulator and getting rid of GlobalIo
diff --git a/core/global-io.cpp b/core/global-io.cpp
deleted file mode 100644
index 48566f6..0000000
--- a/core/global-io.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2015,  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 "global-io.hpp"
-#include <boost/thread/tss.hpp>
-
-namespace nfd {
-
-namespace scheduler {
-// defined in scheduler.cpp
-void
-resetGlobalScheduler();
-} // namespace scheduler
-
-
-static boost::thread_specific_ptr<boost::asio::io_service> g_ioService;
-
-boost::asio::io_service&
-getGlobalIoService()
-{
-  if (g_ioService.get() == nullptr) {
-    g_ioService.reset(new boost::asio::io_service());
-  }
-  return *g_ioService;
-}
-
-void
-resetGlobalIoService()
-{
-  scheduler::resetGlobalScheduler();
-  g_ioService.reset();
-}
-
-} // namespace nfd
diff --git a/core/global-io.hpp b/core/global-io.hpp
index d5030ab..ef90b18 100644
--- a/core/global-io.hpp
+++ b/core/global-io.hpp
@@ -29,18 +29,24 @@
 
 namespace nfd {
 
-/** \return the global io_service instance
+/** \return *nullptr (kept for interface compatibility)
  */
-boost::asio::io_service&
-getGlobalIoService();
+inline boost::asio::io_service&
+getGlobalIoService()
+{
+  return *static_cast<boost::asio::io_service*>(nullptr);
+}
 
 #ifdef WITH_TESTS
 /** \brief delete the global io_service instance
  *
  *  It will be recreated at the next invocation of getGlobalIoService.
  */
-void
-resetGlobalIoService();
+inline void
+resetGlobalIoService()
+{
+  // noop
+}
 #endif
 
 } // namespace nfd
diff --git a/core/scheduler.cpp b/core/scheduler.cpp
index 177045f..504a53c 100644
--- a/core/scheduler.cpp
+++ b/core/scheduler.cpp
@@ -24,41 +24,43 @@
  */
 
 #include "scheduler.hpp"
-#include "global-io.hpp"
 
-#include <boost/thread/tss.hpp>
+namespace ns3 {
+
+/// @cond include_hidden
+
+template<>
+struct EventMemberImplObjTraits<std::function<void()>> {
+  typedef std::function<void()> T;
+  static T&
+  GetReference(T& p)
+  {
+    return p;
+  }
+};
+
+/// @endcond
+
+} // namespace ns3
 
 namespace nfd {
 namespace scheduler {
 
-static boost::thread_specific_ptr<Scheduler> g_scheduler;
-
-Scheduler&
-getGlobalScheduler()
-{
-  if (g_scheduler.get() == nullptr) {
-    g_scheduler.reset(new Scheduler(getGlobalIoService()));
-  }
-
-  return *g_scheduler;
-}
-
 EventId
-schedule(const time::nanoseconds& after, const Scheduler::Event& event)
+schedule(const time::nanoseconds& after, const std::function<void()>& event)
 {
-  return getGlobalScheduler().scheduleEvent(after, event);
+  ns3::EventId id = ns3::Simulator::Schedule(ns3::NanoSeconds(after.count()),
+                                             &std::function<void()>::operator(), event);
+  return std::make_shared<ns3::EventId>(id);
 }
 
 void
 cancel(const EventId& eventId)
 {
-  getGlobalScheduler().cancelEvent(eventId);
-}
-
-void
-resetGlobalScheduler()
-{
-  g_scheduler.reset();
+  if (eventId != nullptr) {
+    ns3::Simulator::Remove(*eventId);
+    const_cast<EventId&>(eventId).reset();
+  }
 }
 
 ScopedEventId::ScopedEventId()
diff --git a/core/scheduler.hpp b/core/scheduler.hpp
index b846c64..8c9db68 100644
--- a/core/scheduler.hpp
+++ b/core/scheduler.hpp
@@ -27,22 +27,21 @@
 #define NFD_CORE_SCHEDULER_HPP
 
 #include "common.hpp"
-#include <ndn-cxx/util/scheduler.hpp>
+
+#include "ns3/simulator.h"
 
 namespace nfd {
 namespace scheduler {
 
-using ndn::Scheduler;
-
 /** \class EventId
  *  \brief Opaque type (shared_ptr) representing ID of a scheduled event
  */
-using ndn::EventId;
+typedef std::shared_ptr<ns3::EventId> EventId;
 
 /** \brief schedule an event
  */
 EventId
-schedule(const time::nanoseconds& after, const Scheduler::Event& event);
+schedule(const time::nanoseconds& after, const std::function<void()>& event);
 
 /** \brief cancel a scheduled event
  */
diff --git a/daemon/mgmt/internal-face.cpp b/daemon/mgmt/internal-face.cpp
index 7569fb9..482ed39 100644
--- a/daemon/mgmt/internal-face.cpp
+++ b/daemon/mgmt/internal-face.cpp
@@ -25,7 +25,7 @@
 
 #include "internal-face.hpp"
 #include "core/logger.hpp"
-#include "core/global-io.hpp"
+#include "core/scheduler.hpp"
 
 namespace nfd {
 
@@ -43,8 +43,8 @@
 
   // Invoke .processInterest a bit later,
   // to avoid potential problems in forwarding pipelines.
-  getGlobalIoService().post(bind(&InternalFace::processInterest,
-                                 this, interest.shared_from_this()));
+  scheduler::schedule(time::seconds(0),
+                      bind(&InternalFace::processInterest, this, interest.shared_from_this()));
 }
 
 void