NFD: Redirecting nfd::scheduler to ns3::Simulator and getting rid of GlobalIo
diff --git a/NFD/core/global-io.cpp b/NFD/core/global-io.cpp
deleted file mode 100644
index f8d8270..0000000
--- a/NFD/core/global-io.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014 Regents of the University of California,
- * Arizona Board of Regents,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University,
- * Washington University in St. Louis,
- * Beijing Institute of Technology
- *
- * 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"
-
-namespace nfd {
-
-namespace scheduler {
-// defined in scheduler.cpp
-void
-resetGlobalScheduler();
-} // namespace scheduler
-
-static shared_ptr<boost::asio::io_service> g_ioService;
-
-boost::asio::io_service&
-getGlobalIoService()
-{
- if (!static_cast<bool>(g_ioService)) {
- g_ioService = make_shared<boost::asio::io_service>();
- }
- return *g_ioService;
-}
-
-void
-resetGlobalIoService()
-{
- scheduler::resetGlobalScheduler();
- g_ioService.reset();
-}
-
-} // namespace nfd
diff --git a/NFD/core/global-io.hpp b/NFD/core/global-io.hpp
deleted file mode 100644
index d5030ab..0000000
--- a/NFD/core/global-io.hpp
+++ /dev/null
@@ -1,48 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014 Regents of the University of California,
- * Arizona Board of Regents,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University,
- * Washington University in St. Louis,
- * Beijing Institute of Technology
- *
- * 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_GLOBAL_IO_HPP
-#define NFD_CORE_GLOBAL_IO_HPP
-
-#include "common.hpp"
-
-namespace nfd {
-
-/** \return the global io_service instance
- */
-boost::asio::io_service&
-getGlobalIoService();
-
-#ifdef WITH_TESTS
-/** \brief delete the global io_service instance
- *
- * It will be recreated at the next invocation of getGlobalIoService.
- */
-void
-resetGlobalIoService();
-#endif
-
-} // namespace nfd
-
-#endif // NFD_CORE_GLOBAL_IO_HPP
diff --git a/NFD/core/scheduler.cpp b/NFD/core/scheduler.cpp
index 0979f97..ed6cffd 100644
--- a/NFD/core/scheduler.cpp
+++ b/NFD/core/scheduler.cpp
@@ -24,38 +24,39 @@
*/
#include "scheduler.hpp"
-#include "global-io.hpp"
+
+namespace ns3 {
+
+template<>
+struct EventMemberImplObjTraits<std::function<void()>> {
+ typedef std::function<void()> T;
+ static T&
+ GetReference(T& p)
+ {
+ return p;
+ }
+};
+
+} // namespace ns3
namespace nfd {
namespace scheduler {
-static shared_ptr<Scheduler> g_scheduler;
-
-inline Scheduler&
-getGlobalScheduler()
-{
- if (!static_cast<bool>(g_scheduler)) {
- g_scheduler = make_shared<Scheduler>(ref(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/NFD/core/scheduler.hpp b/NFD/core/scheduler.hpp
index a4b43c1..4ef124c 100644
--- a/NFD/core/scheduler.hpp
+++ b/NFD/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/NFD/daemon/mgmt/internal-face.cpp b/NFD/daemon/mgmt/internal-face.cpp
index 9fad328..f7ce65b 100644
--- a/NFD/daemon/mgmt/internal-face.cpp
+++ b/NFD/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