From eb3197fa353af1a28c573676072c868b52535bdf Mon Sep 17 00:00:00 2001 From: Alexander Afanasyev Date: Mon, 17 Mar 2014 19:28:18 -0700 Subject: [PATCH] all: Update code to compile with latest time-related changes in ndn-cpp-dev library Change-Id: I7e859989c833001f49b286d4a9917f4dc740b4a4 --- README-dev.md | 6 +- daemon/common.hpp | 2 + daemon/core/resolver.hpp | 5 +- daemon/core/scheduler.hpp | 3 +- daemon/core/time.hpp | 28 --------- daemon/face/ndnlp-partial-message-store.cpp | 2 +- daemon/face/ndnlp-partial-message-store.hpp | 4 +- daemon/face/tcp-channel.cpp | 18 +++--- daemon/face/tcp-channel.hpp | 11 ++-- daemon/face/udp-channel.cpp | 2 +- daemon/face/udp-channel.hpp | 5 +- daemon/face/udp-factory.cpp | 4 +- daemon/face/udp-factory.hpp | 4 +- daemon/fw/forwarder.cpp | 8 +-- daemon/fw/ncc-strategy.cpp | 30 +++++----- daemon/fw/ncc-strategy.hpp | 16 ++--- daemon/mgmt/segment-publisher.cpp | 2 +- daemon/mgmt/status-server.cpp | 32 +++------- daemon/mgmt/status-server.hpp | 4 +- daemon/table/cs-entry.cpp | 5 +- daemon/table/cs-entry.hpp | 7 +-- daemon/table/cs.cpp | 8 +-- daemon/table/measurements-accessor.hpp | 4 +- daemon/table/measurements-entry.cpp | 2 +- daemon/table/measurements-entry.hpp | 2 +- daemon/table/measurements.cpp | 6 +- daemon/table/measurements.hpp | 5 +- daemon/table/pit-entry.cpp | 10 ++-- daemon/table/pit-face-record.cpp | 12 ++-- daemon/table/pit-face-record.hpp | 13 ++-- tests/core/limited-io.cpp | 6 +- tests/core/limited-io.hpp | 4 +- tests/core/scheduler.cpp | 14 +++-- tests/face/tcp.cpp | 4 +- tests/face/udp.cpp | 8 +-- tests/fw/forwarder.cpp | 6 +- tests/fw/ncc-strategy.cpp | 4 +- tests/mgmt/command-validator.cpp | 2 +- tests/mgmt/status-server.cpp | 26 +++----- tests/table/cs.cpp | 8 +-- tests/table/pit.cpp | 66 ++++++++++----------- tools/ndn-autoconfig.cpp | 4 +- tools/ndn-autoconfigserver.cpp | 2 +- tools/ndn-tlv-peek.cpp | 22 +++---- tools/ndn-tlv-poke.cpp | 28 ++++----- 45 files changed, 204 insertions(+), 260 deletions(-) delete mode 100644 daemon/core/time.hpp diff --git a/README-dev.md b/README-dev.md index df92b785..bf9771e5 100644 --- a/README-dev.md +++ b/README-dev.md @@ -12,7 +12,8 @@ Include the following header into all .hpp and .cpp files: Recommendations --------------- -The following code style recommendations are highly advised: https://github.com/cawka/docs-ndn/blob/master/cpp.rst +NFD code is subject to the code style, defined here: +http://redmine.named-data.net/projects/nfd/wiki/CodeStyle Running unit-tests ------------------ @@ -46,4 +47,5 @@ command: There are many more command line options available, information about which can be obtained either from the command line using ``--help`` -switch, or online on Boost.Test library website (http://www.boost.org/doc/libs/1_55_0/libs/test/doc/html/). +switch, or online on Boost.Test library website +(http://www.boost.org/doc/libs/1_48_0/libs/test/doc/html/). diff --git a/daemon/common.hpp b/daemon/common.hpp index 3a39f993..32ad4a40 100644 --- a/daemon/common.hpp +++ b/daemon/common.hpp @@ -67,6 +67,8 @@ namespace tlv { using namespace ndn::Tlv; } +namespace time = ndn::time; + } // namespace nfd #endif // NFD_COMMON_HPP diff --git a/daemon/core/resolver.hpp b/daemon/core/resolver.hpp index bd61f102..508e26d8 100644 --- a/daemon/core/resolver.hpp +++ b/daemon/core/resolver.hpp @@ -9,7 +9,6 @@ #include "common.hpp" #include "core/global-io.hpp" -#include "core/time.hpp" #include "core/scheduler.hpp" namespace nfd { @@ -73,7 +72,7 @@ public: const SuccessCallback& onSuccess, const ErrorCallback& onError, const nfd::resolver::AddressSelector& addressSelector = nfd::resolver::AnyAddress(), - const time::Duration& timeout = time::seconds(4.0)) + const time::seconds& timeout = time::seconds(4)) { shared_ptr resolver = shared_ptr(new Resolver(onSuccess, onError, @@ -126,7 +125,7 @@ private: void asyncResolve(const std::string& host, const std::string& port, - const time::Duration& timeout, + const time::seconds& timeout, const shared_ptr& self) { typename resolver::query query(host, port, diff --git a/daemon/core/scheduler.hpp b/daemon/core/scheduler.hpp index 6ba4f80d..a7f452b3 100644 --- a/daemon/core/scheduler.hpp +++ b/daemon/core/scheduler.hpp @@ -8,7 +8,6 @@ #define NFD_CORE_SCHEDULER_HPP #include "global-io.hpp" -#include "time.hpp" #include namespace nfd { @@ -35,7 +34,7 @@ Scheduler& getGlobalScheduler(); inline EventId -schedule(const time::Duration& after, const Scheduler::Event& event) +schedule(const time::nanoseconds& after, const Scheduler::Event& event) { return getGlobalScheduler().scheduleEvent(after, event); } diff --git a/daemon/core/time.hpp b/daemon/core/time.hpp deleted file mode 100644 index 2c9498fb..00000000 --- a/daemon/core/time.hpp +++ /dev/null @@ -1,28 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (C) 2014 Named Data Networking Project - * See COPYING for copyright and distribution information. - */ - -#ifndef NFD_CORE_TIME_H -#define NFD_CORE_TIME_H - -#include "common.hpp" -#include - -namespace nfd { -namespace time { - -using ndn::time::Duration; -using ndn::time::Point; -using ndn::time::monotonic_clock; -using ndn::time::now; -using ndn::time::seconds; -using ndn::time::milliseconds; -using ndn::time::microseconds; -using ndn::time::nanoseconds; - -} // namespace time -} // namespace nfd - -#endif // NFD_CORE_TIME_H diff --git a/daemon/face/ndnlp-partial-message-store.cpp b/daemon/face/ndnlp-partial-message-store.cpp index 74c109f7..e252c841 100644 --- a/daemon/face/ndnlp-partial-message-store.cpp +++ b/daemon/face/ndnlp-partial-message-store.cpp @@ -61,7 +61,7 @@ PartialMessage::reassemble() return Block(buffer); } -PartialMessageStore::PartialMessageStore(Scheduler& scheduler, time::Duration idleDuration) +PartialMessageStore::PartialMessageStore(Scheduler& scheduler, const time::nanoseconds& idleDuration) : m_scheduler(scheduler) , m_idleDuration(idleDuration) { diff --git a/daemon/face/ndnlp-partial-message-store.hpp b/daemon/face/ndnlp-partial-message-store.hpp index e5de5b10..7cd3df8d 100644 --- a/daemon/face/ndnlp-partial-message-store.hpp +++ b/daemon/face/ndnlp-partial-message-store.hpp @@ -53,7 +53,7 @@ class PartialMessageStore : noncopyable { public: PartialMessageStore(Scheduler& scheduler, - time::Duration idleDuration = time::milliseconds(100)); + const time::nanoseconds& idleDuration = time::milliseconds(100)); virtual ~PartialMessageStore(); @@ -80,7 +80,7 @@ private: std::map > m_partialMessages; Scheduler& m_scheduler; - time::Duration m_idleDuration; + time::nanoseconds m_idleDuration; }; } // namespace ndnlp diff --git a/daemon/face/tcp-channel.cpp b/daemon/face/tcp-channel.cpp index 4b46ea97..c27f1df3 100644 --- a/daemon/face/tcp-channel.cpp +++ b/daemon/face/tcp-channel.cpp @@ -51,7 +51,7 @@ void TcpChannel::connect(const tcp::Endpoint& remoteEndpoint, const TcpChannel::FaceCreatedCallback& onFaceCreated, const TcpChannel::ConnectFailedCallback& onConnectFailed, - const time::Duration& timeout/* = time::seconds(4)*/) + const time::seconds& timeout/* = time::seconds(4)*/) { ChannelFaceMap::iterator i = m_channelFaces.find(remoteEndpoint); if (i != m_channelFaces.end()) { @@ -62,8 +62,8 @@ TcpChannel::connect(const tcp::Endpoint& remoteEndpoint, shared_ptr clientSocket = make_shared(boost::ref(getGlobalIoService())); - shared_ptr connectTimeoutTimer = - make_shared(boost::ref(getGlobalIoService())); + shared_ptr connectTimeoutTimer = + make_shared(boost::ref(getGlobalIoService())); clientSocket->async_connect(remoteEndpoint, bind(&TcpChannel::handleSuccessfulConnect, this, _1, @@ -80,13 +80,13 @@ void TcpChannel::connect(const std::string& remoteHost, const std::string& remotePort, const TcpChannel::FaceCreatedCallback& onFaceCreated, const TcpChannel::ConnectFailedCallback& onConnectFailed, - const time::Duration& timeout/* = time::seconds(4)*/) + const time::seconds& timeout/* = time::seconds(4)*/) { shared_ptr clientSocket = make_shared(boost::ref(getGlobalIoService())); - shared_ptr connectTimeoutTimer = - make_shared(boost::ref(getGlobalIoService())); + shared_ptr connectTimeoutTimer = + make_shared(boost::ref(getGlobalIoService())); ip::tcp::resolver::query query(remoteHost, remotePort); shared_ptr resolver = @@ -170,7 +170,7 @@ TcpChannel::handleSuccessfulAccept(const boost::system::error_code& error, void TcpChannel::handleSuccessfulConnect(const boost::system::error_code& error, const shared_ptr& socket, - const shared_ptr& timer, + const shared_ptr& timer, const FaceCreatedCallback& onFaceCreated, const ConnectFailedCallback& onConnectFailed) { @@ -199,7 +199,7 @@ TcpChannel::handleSuccessfulConnect(const boost::system::error_code& error, void TcpChannel::handleFailedConnect(const boost::system::error_code& error, const shared_ptr& socket, - const shared_ptr& timer, + const shared_ptr& timer, const ConnectFailedCallback& onConnectFailed) { if (error) { // e.g., cancelled @@ -218,7 +218,7 @@ void TcpChannel::handleEndpointResolution(const boost::system::error_code& error, ip::tcp::resolver::iterator remoteEndpoint, const shared_ptr& socket, - const shared_ptr& timer, + const shared_ptr& timer, const FaceCreatedCallback& onFaceCreated, const ConnectFailedCallback& onConnectFailed, const shared_ptr& resolver) diff --git a/daemon/face/tcp-channel.hpp b/daemon/face/tcp-channel.hpp index 808d0f1d..61a9c051 100644 --- a/daemon/face/tcp-channel.hpp +++ b/daemon/face/tcp-channel.hpp @@ -8,7 +8,6 @@ #define NFD_FACE_TCP_CHANNEL_HPP #include "channel.hpp" -#include "core/time.hpp" #include #include "tcp-face.hpp" @@ -61,7 +60,7 @@ public: connect(const tcp::Endpoint& remoteEndpoint, const FaceCreatedCallback& onFaceCreated, const ConnectFailedCallback& onConnectFailed, - const time::Duration& timeout = time::seconds(4)); + const time::seconds& timeout = time::seconds(4)); /** * \brief Create a face by establishing connection to the specified @@ -78,7 +77,7 @@ public: connect(const std::string& remoteHost, const std::string& remotePort, const FaceCreatedCallback& onFaceCreated, const ConnectFailedCallback& onConnectFailed, - const time::Duration& timeout = time::seconds(4)); + const time::seconds& timeout = time::seconds(4)); /** * \brief Get number of faces in the channel @@ -103,21 +102,21 @@ private: void handleSuccessfulConnect(const boost::system::error_code& error, const shared_ptr& socket, - const shared_ptr& timer, + const shared_ptr& timer, const FaceCreatedCallback& onFaceCreated, const ConnectFailedCallback& onConnectFailed); void handleFailedConnect(const boost::system::error_code& error, const shared_ptr& socket, - const shared_ptr& timer, + const shared_ptr& timer, const ConnectFailedCallback& onConnectFailed); void handleEndpointResolution(const boost::system::error_code& error, boost::asio::ip::tcp::resolver::iterator remoteEndpoint, const shared_ptr& socket, - const shared_ptr& timer, + const shared_ptr& timer, const FaceCreatedCallback& onFaceCreated, const ConnectFailedCallback& onConnectFailed, const shared_ptr& resolver); diff --git a/daemon/face/udp-channel.cpp b/daemon/face/udp-channel.cpp index a9e24f7d..91518307 100644 --- a/daemon/face/udp-channel.cpp +++ b/daemon/face/udp-channel.cpp @@ -15,7 +15,7 @@ NFD_LOG_INIT("UdpChannel"); using namespace boost::asio; UdpChannel::UdpChannel(const udp::Endpoint& localEndpoint, - const time::Duration& timeout) + const time::seconds& timeout) : m_localEndpoint(localEndpoint) , m_isListening(false) , m_idleFaceTimeout(timeout) diff --git a/daemon/face/udp-channel.hpp b/daemon/face/udp-channel.hpp index 81e53ac5..26c6caee 100644 --- a/daemon/face/udp-channel.hpp +++ b/daemon/face/udp-channel.hpp @@ -8,7 +8,6 @@ #define NFD_FACE_UDP_CHANNEL_HPP #include "channel.hpp" -#include "core/time.hpp" #include "core/global-io.hpp" #include "core/scheduler.hpp" #include "udp-face.hpp" @@ -46,7 +45,7 @@ public: * \throw UdpChannel::Error if bind on the socket fails */ UdpChannel(const udp::Endpoint& localEndpoint, - const time::Duration& timeout); + const time::seconds& timeout); virtual ~UdpChannel(); @@ -156,7 +155,7 @@ private: * \brief every time m_idleFaceTimeout expires all the idle (and not permanent) * faces will be removed */ - time::Duration m_idleFaceTimeout; + time::seconds m_idleFaceTimeout; EventId m_closeIdleFaceEvent; diff --git a/daemon/face/udp-factory.cpp b/daemon/face/udp-factory.cpp index a311d81b..5fcfd1ca 100644 --- a/daemon/face/udp-factory.cpp +++ b/daemon/face/udp-factory.cpp @@ -21,7 +21,7 @@ UdpFactory::UdpFactory(const std::string& defaultPort/* = "6363"*/) shared_ptr UdpFactory::createChannel(const udp::Endpoint& endpoint, - const time::Duration& timeout) + const time::seconds& timeout) { NFD_LOG_DEBUG("Creating unicast " << endpoint); @@ -52,7 +52,7 @@ UdpFactory::createChannel(const udp::Endpoint& endpoint, shared_ptr UdpFactory::createChannel(const std::string& localHost, const std::string& localPort, - const time::Duration& timeout) + const time::seconds& timeout) { return createChannel(UdpResolver::syncResolve(localHost, localPort), timeout); diff --git a/daemon/face/udp-factory.hpp b/daemon/face/udp-factory.hpp index 695d1e5d..969ef8c6 100644 --- a/daemon/face/udp-factory.hpp +++ b/daemon/face/udp-factory.hpp @@ -56,7 +56,7 @@ public: */ shared_ptr createChannel(const udp::Endpoint& localEndpoint, - const time::Duration& timeout = time::seconds(600)); + const time::seconds& timeout = time::seconds(600)); /** * \brief Create UDP-based channel using specified host and port number @@ -81,7 +81,7 @@ public: shared_ptr createChannel(const std::string& localHost, const std::string& localPort, - const time::Duration& timeout = time::seconds(600)); + const time::seconds& timeout = time::seconds(600)); /** * \brief Create MulticastUdpFace using udp::Endpoint diff --git a/daemon/fw/forwarder.cpp b/daemon/fw/forwarder.cpp index 4ab852eb..e46bd5a1 100644 --- a/daemon/fw/forwarder.cpp +++ b/daemon/fw/forwarder.cpp @@ -217,7 +217,7 @@ Forwarder::onIncomingData(Face& inFace, const Data& data) const pit::InRecordCollection& inRecords = pitEntry->getInRecords(); for (pit::InRecordCollection::const_iterator it = inRecords.begin(); it != inRecords.end(); ++it) { - if (it->getExpiry() > time::now()) { + if (it->getExpiry() > time::steady_clock::now()) { pendingDownstreams.insert(it->getFace()); } } @@ -293,8 +293,8 @@ Forwarder::setUnsatisfyTimer(shared_ptr pitEntry) std::max_element(inRecords.begin(), inRecords.end(), &compare_InRecord_expiry); - time::Point lastExpiry = lastExpiring->getExpiry(); - time::Duration lastExpiryFromNow = lastExpiry - time::now(); + time::steady_clock::TimePoint lastExpiry = lastExpiring->getExpiry(); + time::nanoseconds lastExpiryFromNow = lastExpiry - time::steady_clock::now(); if (lastExpiryFromNow <= time::seconds(0)) { // TODO all InRecords are already expired; will this happen? } @@ -312,7 +312,7 @@ Forwarder::setStragglerTimer(shared_ptr pitEntry) return; } - time::Duration stragglerTime = time::milliseconds(100); + time::nanoseconds stragglerTime = time::milliseconds(100); pitEntry->m_stragglerTimer = scheduler::schedule(stragglerTime, bind(&Pit::erase, &m_pit, pitEntry)); diff --git a/daemon/fw/ncc-strategy.cpp b/daemon/fw/ncc-strategy.cpp index 79d8b1a4..d0b43f16 100644 --- a/daemon/fw/ncc-strategy.cpp +++ b/daemon/fw/ncc-strategy.cpp @@ -20,9 +20,9 @@ NccStrategy::~NccStrategy() { } -const time::Duration NccStrategy::DEFER_FIRST_WITHOUT_BEST_FACE = time::microseconds(4000); -const time::Duration NccStrategy::DEFER_RANGE_WITHOUT_BEST_FACE = time::microseconds(75000); -const time::Duration NccStrategy::MEASUREMENTS_LIFETIME = time::seconds(16); +const time::nanoseconds NccStrategy::DEFER_FIRST_WITHOUT_BEST_FACE = time::microseconds(4000); +const time::nanoseconds NccStrategy::DEFER_RANGE_WITHOUT_BEST_FACE = time::microseconds(75000); +const time::nanoseconds NccStrategy::MEASUREMENTS_LIFETIME = time::seconds(16); void NccStrategy::afterReceiveInterest(const Face& inFace, @@ -47,8 +47,8 @@ NccStrategy::afterReceiveInterest(const Face& inFace, shared_ptr measurementsEntryInfo = this->getMeasurementsEntryInfo(pitEntry); - time::Duration deferFirst = DEFER_FIRST_WITHOUT_BEST_FACE; - time::Duration deferRange = DEFER_RANGE_WITHOUT_BEST_FACE; + time::nanoseconds deferFirst = DEFER_FIRST_WITHOUT_BEST_FACE; + time::nanoseconds deferRange = DEFER_RANGE_WITHOUT_BEST_FACE; size_t nUpstreams = nexthops.size(); shared_ptr bestFace = measurementsEntryInfo->getBestFace(); @@ -56,7 +56,8 @@ NccStrategy::afterReceiveInterest(const Face& inFace, pitEntry->canForwardTo(*bestFace)) { // TODO Should we use `randlow = 100 + nrand48(h->seed) % 4096U;` ? deferFirst = measurementsEntryInfo->m_prediction; - deferRange = static_cast((deferFirst + time::microseconds(1)) / 2); + deferRange = time::nanoseconds((deferFirst.count() + + static_cast(time::microseconds(1)).count()) / 2); --nUpstreams; this->sendInterest(pitEntry, bestFace); pitEntryInfo->m_bestFaceTimeout = scheduler::schedule( @@ -75,8 +76,8 @@ NccStrategy::afterReceiveInterest(const Face& inFace, --nUpstreams; } - pitEntryInfo->m_maxInterval = std::max(time::microseconds(1), - static_cast((2 * deferRange + nUpstreams - 1) / nUpstreams)); + pitEntryInfo->m_maxInterval = std::max(static_cast(time::microseconds(1)), + time::nanoseconds((2 * deferRange.count() + nUpstreams - 1) / nUpstreams)); pitEntryInfo->m_propagateTimer = scheduler::schedule(deferFirst, bind(&NccStrategy::doPropagate, this, weak_ptr(pitEntry), weak_ptr(fibEntry))); @@ -120,8 +121,7 @@ NccStrategy::doPropagate(weak_ptr pitEntryWeak, weak_ptr if (isForwarded) { static unsigned short seed[3]; - time::Duration deferNext = static_cast( - nrand48(seed) % pitEntryInfo->m_maxInterval); + time::nanoseconds deferNext = time::nanoseconds(nrand48(seed) % pitEntryInfo->m_maxInterval.count()); pitEntryInfo->m_propagateTimer = scheduler::schedule(deferNext, bind(&NccStrategy::doPropagate, this, weak_ptr(pitEntry), weak_ptr(fibEntry))); @@ -206,11 +206,11 @@ NccStrategy::getMeasurementsEntryInfo(shared_ptr entry) } -const time::Duration NccStrategy::MeasurementsEntryInfo::INITIAL_PREDICTION = +const time::nanoseconds NccStrategy::MeasurementsEntryInfo::INITIAL_PREDICTION = time::microseconds(8192); -const time::Duration NccStrategy::MeasurementsEntryInfo::MIN_PREDICTION = +const time::nanoseconds NccStrategy::MeasurementsEntryInfo::MIN_PREDICTION = time::microseconds(127); -const time::Duration NccStrategy::MeasurementsEntryInfo::MAX_PREDICTION = +const time::nanoseconds NccStrategy::MeasurementsEntryInfo::MAX_PREDICTION = time::microseconds(160000); NccStrategy::MeasurementsEntryInfo::MeasurementsEntryInfo() @@ -253,13 +253,13 @@ NccStrategy::MeasurementsEntryInfo::updateBestFace(const Face& face) { void NccStrategy::MeasurementsEntryInfo::adjustPredictDown() { m_prediction = std::max(MIN_PREDICTION, - static_cast(m_prediction - (m_prediction >> ADJUST_PREDICT_DOWN_SHIFT))); + time::nanoseconds(m_prediction.count() - (m_prediction.count() >> ADJUST_PREDICT_DOWN_SHIFT))); } void NccStrategy::MeasurementsEntryInfo::adjustPredictUp() { m_prediction = std::min(MAX_PREDICTION, - static_cast(m_prediction + (m_prediction >> ADJUST_PREDICT_UP_SHIFT))); + time::nanoseconds(m_prediction.count() + (m_prediction.count() >> ADJUST_PREDICT_UP_SHIFT))); } void diff --git a/daemon/fw/ncc-strategy.hpp b/daemon/fw/ncc-strategy.hpp index ff9bcf3b..6a41b1a5 100644 --- a/daemon/fw/ncc-strategy.hpp +++ b/daemon/fw/ncc-strategy.hpp @@ -61,12 +61,12 @@ protected: public: weak_ptr m_bestFace; weak_ptr m_previousFace; - time::Duration m_prediction; + time::nanoseconds m_prediction; - static const time::Duration INITIAL_PREDICTION; - static const time::Duration MIN_PREDICTION; + static const time::nanoseconds INITIAL_PREDICTION; + static const time::nanoseconds MIN_PREDICTION; static const int ADJUST_PREDICT_DOWN_SHIFT = 7; - static const time::Duration MAX_PREDICTION; + static const time::nanoseconds MAX_PREDICTION; static const int ADJUST_PREDICT_UP_SHIFT = 3; }; @@ -83,7 +83,7 @@ protected: bool m_isNewInterest; EventId m_bestFaceTimeout; EventId m_propagateTimer; - time::Duration m_maxInterval; + time::nanoseconds m_maxInterval; }; protected: @@ -105,10 +105,10 @@ public: static const Name STRATEGY_NAME; protected: - static const time::Duration DEFER_FIRST_WITHOUT_BEST_FACE; - static const time::Duration DEFER_RANGE_WITHOUT_BEST_FACE; + static const time::nanoseconds DEFER_FIRST_WITHOUT_BEST_FACE; + static const time::nanoseconds DEFER_RANGE_WITHOUT_BEST_FACE; static const int UPDATE_MEASUREMENTS_N_LEVELS = 2; - static const time::Duration MEASUREMENTS_LIFETIME; + static const time::nanoseconds MEASUREMENTS_LIFETIME; }; } // namespace fw diff --git a/daemon/mgmt/segment-publisher.cpp b/daemon/mgmt/segment-publisher.cpp index bd7d971f..fefe30e8 100644 --- a/daemon/mgmt/segment-publisher.cpp +++ b/daemon/mgmt/segment-publisher.cpp @@ -33,7 +33,7 @@ void SegmentPublisher::publish() { Name segmentPrefix(m_prefix); - segmentPrefix.appendSegment(ndn::ndn_getNowMilliseconds()); + segmentPrefix.appendSegment(time::toUnixTimestamp(time::system_clock::now()).count()); static const size_t MAX_SEGMENT_SIZE = MAX_NDN_PACKET_SIZE >> 1; diff --git a/daemon/mgmt/status-server.cpp b/daemon/mgmt/status-server.cpp index 9635488a..61a67b14 100644 --- a/daemon/mgmt/status-server.cpp +++ b/daemon/mgmt/status-server.cpp @@ -11,31 +11,12 @@ namespace nfd { const Name StatusServer::DATASET_PREFIX = "ndn:/localhost/nfd/status"; -const ndn::Milliseconds StatusServer::RESPONSE_FRESHNESS = 5000; - -static inline ndn::nfd::Status::Timestamp -now() -{ - // make sure boost::chrono::system_clock's epoch is UNIX epoch - BOOST_ASSERT(static_cast(0) == boost::chrono::system_clock::to_time_t( - boost::chrono::system_clock::time_point( - boost::chrono::duration_cast( - ndn::nfd::Status::Timestamp::duration::zero() - ) - ) - )); - - return ndn::nfd::Status::Timestamp( - boost::chrono::duration_cast( - boost::chrono::system_clock::now().time_since_epoch() - ) - ); -} +const time::milliseconds StatusServer::RESPONSE_FRESHNESS = time::milliseconds(5000); StatusServer::StatusServer(shared_ptr face, Forwarder& forwarder) : m_face(face) , m_forwarder(forwarder) - , m_startTimestamp(now()) + , m_startTimestamp(time::system_clock::now()) { m_face->setInterestFilter(DATASET_PREFIX, bind(&StatusServer::onInterest, this, _2)); } @@ -44,9 +25,10 @@ void StatusServer::onInterest(const Interest& interest) const { Name name(DATASET_PREFIX); - // TODO use NumberComponent - name.append(ndn::Name::Component::fromNumberWithMarker(ndn::ndn_getNowMilliseconds(), 0x00)); - name.append(ndn::Name::Component::fromNumberWithMarker(0, 0x00)); + /// \todo use NumberComponent + name.append(Name::Component::fromNumberWithMarker( + time::toUnixTimestamp(time::system_clock::now()).count(), 0x00)); + name.append(Name::Component::fromNumberWithMarker(0, 0x00)); shared_ptr data = make_shared(name); data->setFreshnessPeriod(RESPONSE_FRESHNESS); @@ -67,7 +49,7 @@ StatusServer::collectStatus() const status->setNfdVersion(NFD_VERSION); status->setStartTimestamp(m_startTimestamp); - status->setCurrentTimestamp(now()); + status->setCurrentTimestamp(time::system_clock::now()); status->setNNameTreeEntries(m_forwarder.getNameTree().size()); status->setNFibEntries(m_forwarder.getFib().size()); diff --git a/daemon/mgmt/status-server.hpp b/daemon/mgmt/status-server.hpp index 94c8e82a..c9a14f5e 100644 --- a/daemon/mgmt/status-server.hpp +++ b/daemon/mgmt/status-server.hpp @@ -28,11 +28,11 @@ private: private: static const Name DATASET_PREFIX; - static const ndn::Milliseconds RESPONSE_FRESHNESS; + static const time::milliseconds RESPONSE_FRESHNESS; shared_ptr m_face; Forwarder& m_forwarder; - ndn::nfd::Status::Timestamp m_startTimestamp; + time::system_clock::TimePoint m_startTimestamp; }; } // namespace nfd diff --git a/daemon/table/cs-entry.cpp b/daemon/table/cs-entry.cpp index 108a0506..9e998863 100644 --- a/daemon/table/cs-entry.cpp +++ b/daemon/table/cs-entry.cpp @@ -78,7 +78,7 @@ Entry::isUnsolicited() const return m_isUnsolicited; } -const time::Point& +const time::steady_clock::TimePoint& Entry::getStaleTime() const { return m_staleAt; @@ -87,8 +87,7 @@ Entry::getStaleTime() const void Entry::updateStaleTime() { - time::Duration freshness = time::milliseconds(m_dataPacket->getFreshnessPeriod()); - m_staleAt = time::now() + freshness; + m_staleAt = time::steady_clock::now() + m_dataPacket->getFreshnessPeriod(); } bool diff --git a/daemon/table/cs-entry.hpp b/daemon/table/cs-entry.hpp index 7d31442f..062e7f12 100644 --- a/daemon/table/cs-entry.hpp +++ b/daemon/table/cs-entry.hpp @@ -10,7 +10,6 @@ #define NFD_TABLE_CS_ENTRY_HPP #include "common.hpp" -#include "core/time.hpp" #include namespace nfd { @@ -49,9 +48,9 @@ public: wasRefreshedByDuplicate() const; /** \brief returns the absolute time when Data becomes expired - * \return{ Time (resolution up to milliseconds) } + * \return{ Time (resolution up to time::milliseconds) } */ - const time::Point& + const time::steady_clock::TimePoint& getStaleTime() const; /** \brief returns the Data packet stored in the CS entry @@ -102,7 +101,7 @@ private: printIterators() const; private: - time::Point m_staleAt; + time::steady_clock::TimePoint m_staleAt; shared_ptr m_dataPacket; bool m_isUnsolicited; diff --git a/daemon/table/cs.cpp b/daemon/table/cs.cpp index a68c5415..0e0bb6a8 100644 --- a/daemon/table/cs.cpp +++ b/daemon/table/cs.cpp @@ -19,7 +19,7 @@ namespace nfd { Cs::Cs(int nMaxPackets) : m_nMaxPackets(nMaxPackets) { - srand (time::now()); + srand (time::toUnixTimestamp(time::system_clock::now()).count()); SkipListLayer* zeroLayer = new SkipListLayer(); m_skipList.push_back(zeroLayer); } @@ -304,7 +304,7 @@ Cs::evictItem() shared_ptr entry = m_contentByStaleness.top(); //because stale time could be updated by the duplicate packet - if (entry->getStaleTime() < time::now()) + if (entry->getStaleTime() < time::steady_clock::now()) { m_contentByStaleness.pop(); bool isErased = eraseFromSkipList(entry); @@ -312,7 +312,7 @@ Cs::evictItem() if (isErased) return true; } - else if ( (entry->getStaleTime() > time::now()) && entry->wasRefreshedByDuplicate() ) + else if ( (entry->getStaleTime() > time::steady_clock::now()) && entry->wasRefreshedByDuplicate() ) { m_contentByStaleness.pop(); m_contentByStaleness.push(entry); // place in a right order @@ -607,7 +607,7 @@ Cs::doesComplyWithSelectors(const Interest& interest, shared_ptr entr } } - if (interest.getMustBeFresh() && entry->getStaleTime() < time::now()) + if (interest.getMustBeFresh() && entry->getStaleTime() < time::steady_clock::now()) { NFD_LOG_DEBUG("violates mustBeFresh"); return false; diff --git a/daemon/table/measurements-accessor.hpp b/daemon/table/measurements-accessor.hpp index 53b30d44..be0c7b0b 100644 --- a/daemon/table/measurements-accessor.hpp +++ b/daemon/table/measurements-accessor.hpp @@ -50,7 +50,7 @@ public: * The entry will be kept until at least now()+lifetime. */ void - extendLifetime(measurements::Entry& entry, const time::Duration& lifetime); + extendLifetime(measurements::Entry& entry, const time::nanoseconds& lifetime); private: /** \brief perform access control to Measurements entry @@ -91,7 +91,7 @@ MeasurementsAccessor::getParent(shared_ptr child) } inline void -MeasurementsAccessor::extendLifetime(measurements::Entry& entry, const time::Duration& lifetime) +MeasurementsAccessor::extendLifetime(measurements::Entry& entry, const time::nanoseconds& lifetime) { m_measurements.extendLifetime(entry, lifetime); } diff --git a/daemon/table/measurements-entry.cpp b/daemon/table/measurements-entry.cpp index 11e4fabd..36cca3a0 100644 --- a/daemon/table/measurements-entry.cpp +++ b/daemon/table/measurements-entry.cpp @@ -11,7 +11,7 @@ namespace measurements { Entry::Entry(const Name& name) : m_name(name) - , m_expiry(0) + , m_expiry(time::steady_clock::TimePoint::min()) { } diff --git a/daemon/table/measurements-entry.hpp b/daemon/table/measurements-entry.hpp index 60a428fb..c4b73cee 100644 --- a/daemon/table/measurements-entry.hpp +++ b/daemon/table/measurements-entry.hpp @@ -39,7 +39,7 @@ private: Name m_name; private: // lifetime - time::Point m_expiry; + time::steady_clock::TimePoint m_expiry; EventId m_cleanup; shared_ptr m_nameTreeEntry; diff --git a/daemon/table/measurements.cpp b/daemon/table/measurements.cpp index c284efae..dcc40fed 100644 --- a/daemon/table/measurements.cpp +++ b/daemon/table/measurements.cpp @@ -11,7 +11,7 @@ namespace nfd { -const time::Duration Measurements::s_defaultLifetime = time::seconds(4); +const time::nanoseconds Measurements::s_defaultLifetime = time::seconds(4); Measurements::Measurements(NameTree& nameTree) : m_nameTree(nameTree) @@ -101,12 +101,12 @@ Measurements::findExactMatch(const Name& name) const } void -Measurements::extendLifetime(measurements::Entry& entry, const time::Duration lifetime) +Measurements::extendLifetime(measurements::Entry& entry, const time::nanoseconds& lifetime) { shared_ptr ret = this->findExactMatch(entry.getName()); if (static_cast(ret)) { - time::Point expiry = time::now() + lifetime; + time::steady_clock::TimePoint expiry = time::steady_clock::now() + lifetime; if (ret->m_expiry >= expiry) // has longer lifetime, not extending return; scheduler::cancel(entry.m_cleanup); diff --git a/daemon/table/measurements.hpp b/daemon/table/measurements.hpp index 561b301d..8d096661 100644 --- a/daemon/table/measurements.hpp +++ b/daemon/table/measurements.hpp @@ -8,7 +8,6 @@ #define NFD_TABLE_MEASUREMENTS_HPP #include "measurements-entry.hpp" -#include "core/time.hpp" #include "name-tree.hpp" namespace nfd { @@ -65,7 +64,7 @@ public: * The entry will be kept until at least now()+lifetime. */ void - extendLifetime(measurements::Entry& entry, const time::Duration lifetime); + extendLifetime(measurements::Entry& entry, const time::nanoseconds& lifetime); size_t size() const; @@ -80,7 +79,7 @@ private: private: NameTree& m_nameTree; size_t m_nItems; - static const time::Duration s_defaultLifetime; + static const time::nanoseconds s_defaultLifetime; }; inline size_t diff --git a/daemon/table/pit-entry.cpp b/daemon/table/pit-entry.cpp index 86596df5..b3e54388 100644 --- a/daemon/table/pit-entry.cpp +++ b/daemon/table/pit-entry.cpp @@ -58,7 +58,7 @@ predicate_FaceRecord_Face(const FaceRecord& faceRecord, const Face* face) static inline bool predicate_FaceRecord_ne_Face_and_unexpired(const FaceRecord& faceRecord, - const Face* face, time::Point now) + const Face* face, const time::steady_clock::TimePoint& now) { return faceRecord.getFace().get() != face && faceRecord.getExpiry() >= now; } @@ -70,14 +70,14 @@ Entry::canForwardTo(const Face& face) const m_outRecords.begin(), m_outRecords.end(), bind(&predicate_FaceRecord_Face, _1, &face)); bool hasUnexpiredOutRecord = outIt != m_outRecords.end() && - outIt->getExpiry() >= time::now(); + outIt->getExpiry() >= time::steady_clock::now(); if (hasUnexpiredOutRecord) { return false; } InRecordCollection::const_iterator inIt = std::find_if( m_inRecords.begin(), m_inRecords.end(), - bind(&predicate_FaceRecord_ne_Face_and_unexpired, _1, &face, time::now())); + bind(&predicate_FaceRecord_ne_Face_and_unexpired, _1, &face, time::steady_clock::now())); bool hasUnexpiredOtherInRecord = inIt != m_inRecords.end(); if (!hasUnexpiredOtherInRecord) { return false; @@ -162,7 +162,7 @@ Entry::deleteOutRecord(shared_ptr face) } static inline bool -predicate_FaceRecord_unexpired(const FaceRecord& faceRecord, time::Point now) +predicate_FaceRecord_unexpired(const FaceRecord& faceRecord, const time::steady_clock::TimePoint& now) { return faceRecord.getExpiry() >= now; } @@ -171,7 +171,7 @@ bool Entry::hasUnexpiredOutRecords() const { OutRecordCollection::const_iterator it = std::find_if(m_outRecords.begin(), - m_outRecords.end(), bind(&predicate_FaceRecord_unexpired, _1, time::now())); + m_outRecords.end(), bind(&predicate_FaceRecord_unexpired, _1, time::steady_clock::now())); return it != m_outRecords.end(); } diff --git a/daemon/table/pit-face-record.cpp b/daemon/table/pit-face-record.cpp index 5663dcec..4d611f92 100644 --- a/daemon/table/pit-face-record.cpp +++ b/daemon/table/pit-face-record.cpp @@ -12,8 +12,8 @@ namespace pit { FaceRecord::FaceRecord(shared_ptr face) : m_face(face) , m_lastNonce(0) - , m_lastRenewed(0) - , m_expiry(0) + , m_lastRenewed(time::steady_clock::TimePoint::min()) + , m_expiry(time::steady_clock::TimePoint::min()) { } @@ -29,11 +29,11 @@ void FaceRecord::update(const Interest& interest) { m_lastNonce = interest.getNonce(); - m_lastRenewed = time::now(); + m_lastRenewed = time::steady_clock::now(); - const ndn::Milliseconds DEFAULT_INTEREST_LIFETIME = static_cast(4000); - ndn::Milliseconds lifetime = interest.getInterestLifetime(); - if (lifetime < 0) { + static const time::milliseconds DEFAULT_INTEREST_LIFETIME = time::milliseconds(4000); + time::milliseconds lifetime = interest.getInterestLifetime(); + if (lifetime < time::milliseconds::zero()) { lifetime = DEFAULT_INTEREST_LIFETIME; } m_expiry = m_lastRenewed + time::milliseconds(lifetime); diff --git a/daemon/table/pit-face-record.hpp b/daemon/table/pit-face-record.hpp index 3ad04629..9bcfbed5 100644 --- a/daemon/table/pit-face-record.hpp +++ b/daemon/table/pit-face-record.hpp @@ -8,7 +8,6 @@ #define NFD_TABLE_PIT_FACE_RECORD_HPP #include "face/face.hpp" -#include "core/time.hpp" #include "strategy-info-host.hpp" namespace nfd { @@ -34,13 +33,13 @@ public: uint32_t getLastNonce() const; - time::Point + time::steady_clock::TimePoint getLastRenewed() const; /** \brief gives the time point this record expires * \return getLastRenewed() + InterestLifetime */ - time::Point + time::steady_clock::TimePoint getExpiry() const; /// updates lastNonce, lastRenewed, expiry fields @@ -50,8 +49,8 @@ public: private: shared_ptr m_face; uint32_t m_lastNonce; - time::Point m_lastRenewed; - time::Point m_expiry; + time::steady_clock::TimePoint m_lastRenewed; + time::steady_clock::TimePoint m_expiry; }; inline shared_ptr @@ -66,13 +65,13 @@ FaceRecord::getLastNonce() const return m_lastNonce; } -inline time::Point +inline time::steady_clock::TimePoint FaceRecord::getLastRenewed() const { return m_lastRenewed; } -inline time::Point +inline time::steady_clock::TimePoint FaceRecord::getExpiry() const { return m_expiry; diff --git a/tests/core/limited-io.cpp b/tests/core/limited-io.cpp index b3816969..1eba63da 100644 --- a/tests/core/limited-io.cpp +++ b/tests/core/limited-io.cpp @@ -13,7 +13,7 @@ namespace tests { NFD_LOG_INIT("LimitedIo"); const int LimitedIo::UNLIMITED_OPS = std::numeric_limits::max(); -const time::Duration LimitedIo::UNLIMITED_TIME = time::nanoseconds(-1); +const time::nanoseconds LimitedIo::UNLIMITED_TIME = time::nanoseconds::min(); LimitedIo::LimitedIo() : m_isRunning(false) @@ -22,14 +22,14 @@ LimitedIo::LimitedIo() } LimitedIo::StopReason -LimitedIo::run(int nOpsLimit, time::Duration nTimeLimit) +LimitedIo::run(int nOpsLimit, const time::nanoseconds& nTimeLimit) { BOOST_ASSERT(!m_isRunning); m_isRunning = true; m_reason = NO_WORK; m_nOpsRemaining = nOpsLimit; - if (nTimeLimit != UNLIMITED_TIME) { + if (nTimeLimit >= time::nanoseconds::zero()) { m_timeout = scheduler::schedule(nTimeLimit, bind(&LimitedIo::afterTimeout, this)); } diff --git a/tests/core/limited-io.hpp b/tests/core/limited-io.hpp index 0aae2900..d3968c2a 100644 --- a/tests/core/limited-io.hpp +++ b/tests/core/limited-io.hpp @@ -38,7 +38,7 @@ public: * \param nTimeLimit time limit, pass UNLIMITED_TIME for no limit */ StopReason - run(int nOpsLimit, time::Duration nTimeLimit); + run(int nOpsLimit, const time::nanoseconds& nTimeLimit); /// count an operation void @@ -53,7 +53,7 @@ private: public: static const int UNLIMITED_OPS; - static const time::Duration UNLIMITED_TIME; + static const time::nanoseconds UNLIMITED_TIME; private: bool m_isRunning; diff --git a/tests/core/scheduler.cpp b/tests/core/scheduler.cpp index 806c982a..87c75cf5 100644 --- a/tests/core/scheduler.cpp +++ b/tests/core/scheduler.cpp @@ -57,18 +57,20 @@ struct SchedulerFixture : protected BaseFixture BOOST_FIXTURE_TEST_CASE(Events, SchedulerFixture) { - scheduler::schedule(time::seconds(0.5), bind(&SchedulerFixture::event1, this)); + scheduler::schedule(time::milliseconds(500), bind(&SchedulerFixture::event1, this)); - EventId i = scheduler::schedule(time::seconds(1.0), bind(&SchedulerFixture::event2, this)); + EventId i = scheduler::schedule(time::seconds(1), bind(&SchedulerFixture::event2, this)); scheduler::cancel(i); - scheduler::schedule(time::seconds(0.25), bind(&SchedulerFixture::event3, this)); + scheduler::schedule(time::milliseconds(250), bind(&SchedulerFixture::event3, this)); - i = scheduler::schedule(time::seconds(0.05), bind(&SchedulerFixture::event2, this)); + i = scheduler::schedule(time::milliseconds(50), bind(&SchedulerFixture::event2, this)); scheduler::cancel(i); // TODO deprecate periodic event - i = scheduler::getGlobalScheduler().schedulePeriodicEvent(time::seconds(0.3), time::seconds(0.1), bind(&SchedulerFixture::event4, this)); + i = scheduler::getGlobalScheduler().schedulePeriodicEvent(time::milliseconds(300), + time::milliseconds(100), + bind(&SchedulerFixture::event4, this)); scheduler::schedule(time::seconds(1), bind(&scheduler::cancel, i)); g_io.run(); @@ -98,7 +100,7 @@ struct SelfCancelFixture : protected BaseFixture BOOST_FIXTURE_TEST_CASE(SelfCancel, SelfCancelFixture) { - m_selfEventId = scheduler::schedule(time::seconds(0.1), + m_selfEventId = scheduler::schedule(time::milliseconds(100), bind(&SelfCancelFixture::cancelSelf, this)); BOOST_REQUIRE_NO_THROW(g_io.run()); diff --git a/tests/face/tcp.cpp b/tests/face/tcp.cpp index 332e28cc..38ee7978 100644 --- a/tests/face/tcp.cpp +++ b/tests/face/tcp.cpp @@ -349,7 +349,7 @@ BOOST_FIXTURE_TEST_CASE(MultipleAccepts, EndToEndFixture) bind(&EndToEndFixture::channel_onConnectFailed, this, _1)), time::seconds(4))); - scheduler::schedule(time::seconds(0.5), + scheduler::schedule(time::milliseconds(500), bind(&EndToEndFixture::checkFaceList, this, 4)); BOOST_CHECK_MESSAGE(m_limitedIo.run(4,// 2 connects and 2 accepts @@ -385,7 +385,7 @@ BOOST_FIXTURE_TEST_CASE(FaceClosing, EndToEndFixture) BOOST_CHECK(static_cast(m_face2)); // Face::close must be invoked during io run to be counted as an op - scheduler::schedule(time::seconds(0.1), bind(&Face::close, m_face1)); + scheduler::schedule(time::milliseconds(100), bind(&Face::close, m_face1)); BOOST_CHECK_MESSAGE(m_limitedIo.run(2, time::seconds(10)) == LimitedIo::EXCEED_OPS, "FaceClosing error: cannot properly close faces"); diff --git a/tests/face/udp.cpp b/tests/face/udp.cpp index 5e3a996d..d4983bf5 100644 --- a/tests/face/udp.cpp +++ b/tests/face/udp.cpp @@ -545,7 +545,7 @@ BOOST_FIXTURE_TEST_CASE(MultipleAccepts, EndToEndFixture) BOOST_CHECK_NE(channel3, channel4); - scheduler::schedule(time::seconds(0.5), + scheduler::schedule(time::milliseconds(500), bind(&UdpChannel::connect, channel4, "127.0.0.1", "20070", // does not work without static_cast static_cast( @@ -553,7 +553,7 @@ BOOST_FIXTURE_TEST_CASE(MultipleAccepts, EndToEndFixture) static_cast( bind(&EndToEndFixture::channel_onConnectFailed, this, _1)))); - scheduler::schedule(time::seconds(0.4), bind(&EndToEndFixture::checkFaceList, this, 2)); + scheduler::schedule(time::milliseconds(400), bind(&EndToEndFixture::checkFaceList, this, 2)); BOOST_CHECK_MESSAGE(m_limitedIo.run(2,// 2 connects time::seconds(4)) == LimitedIo::EXCEED_OPS, @@ -727,7 +727,7 @@ BOOST_FIXTURE_TEST_CASE(MultipleAccepts, EndToEndFixture) // BOOST_CHECK_NE(channel3, channel4); // // scheduler -// .scheduleEvent(time::seconds(0.5), +// .scheduleEvent(time::milliseconds(500), // bind(&UdpChannel::connect, channel4, // "::1", "20070", // static_cast(bind(&EndToEndFixture:: @@ -806,7 +806,7 @@ BOOST_FIXTURE_TEST_CASE(FaceClosing, EndToEndFixture) BOOST_CHECK(static_cast(m_face2)); // Face::close must be invoked during io run to be counted as an op - scheduler::schedule(time::seconds(0.1), bind(&Face::close, m_face2)); + scheduler::schedule(time::milliseconds(100), bind(&Face::close, m_face2)); BOOST_CHECK_MESSAGE(m_limitedIo.run(1, time::seconds(4)) == LimitedIo::EXCEED_OPS, "FaceClosing error: cannot properly close faces"); diff --git a/tests/fw/forwarder.cpp b/tests/fw/forwarder.cpp index 7ec90a52..c96e57a1 100644 --- a/tests/fw/forwarder.cpp +++ b/tests/fw/forwarder.cpp @@ -24,7 +24,7 @@ BOOST_AUTO_TEST_CASE(SimpleExchange) Name nameAB ("ndn:/A/B"); Name nameABC("ndn:/A/B/C"); shared_ptr interestAB = makeInterest(nameAB); - interestAB->setInterestLifetime(4000); + interestAB->setInterestLifetime(time::seconds(4)); shared_ptr dataABC = makeData(nameABC); shared_ptr face1 = make_shared(); @@ -317,10 +317,10 @@ BOOST_AUTO_TEST_CASE(StrategyDispatch) BOOST_CHECK_EQUAL(strategyQ->m_beforeSatisfyPendingInterest_count, 1); shared_ptr interest3 = makeInterest("ndn:/A/3"); - interest3->setInterestLifetime(30); + interest3->setInterestLifetime(time::milliseconds(30)); forwarder.onInterest(*face1, *interest3); shared_ptr interest4 = makeInterest("ndn:/B/4"); - interest4->setInterestLifetime(5000); + interest4->setInterestLifetime(time::milliseconds(5000)); forwarder.onInterest(*face1, *interest4); strategyP->m_beforeExpirePendingInterest_count = 0; diff --git a/tests/fw/ncc-strategy.cpp b/tests/fw/ncc-strategy.cpp index d980c496..044b3ec4 100644 --- a/tests/fw/ncc-strategy.cpp +++ b/tests/fw/ncc-strategy.cpp @@ -49,7 +49,7 @@ BOOST_AUTO_TEST_CASE(FavorRespondingUpstream) // first Interest: strategy knows nothing and follows routing shared_ptr interest1p = makeInterest("ndn:/0Jm1ajrW/%00"); Interest& interest1 = *interest1p; - interest1.setInterestLifetime(8000); + interest1.setInterestLifetime(time::milliseconds(8000)); shared_ptr pitEntry1 = pit.insert(interest1).first; pitEntry1->insertOrUpdateInRecord(face3, interest1); @@ -74,7 +74,7 @@ BOOST_AUTO_TEST_CASE(FavorRespondingUpstream) // second Interest: strategy knows face2 is best shared_ptr interest2p = makeInterest("ndn:/0Jm1ajrW/%00%01"); Interest& interest2 = *interest2p; - interest2.setInterestLifetime(8000); + interest2.setInterestLifetime(time::milliseconds(8000)); shared_ptr pitEntry2 = pit.insert(interest2).first; pitEntry2->insertOrUpdateInRecord(face3, interest2); diff --git a/tests/mgmt/command-validator.cpp b/tests/mgmt/command-validator.cpp index 3dcae241..e2cf51c0 100644 --- a/tests/mgmt/command-validator.cpp +++ b/tests/mgmt/command-validator.cpp @@ -84,7 +84,7 @@ public: generateIdentity(const Name& prefix) { m_identityName = prefix; - m_identityName.append(boost::lexical_cast(ndn::time::now())); + m_identityName.appendVersion(); const Name certName = m_keys.createIdentity(m_identityName); diff --git a/tests/mgmt/status-server.cpp b/tests/mgmt/status-server.cpp index 3d8442b2..99aa9f81 100644 --- a/tests/mgmt/status-server.cpp +++ b/tests/mgmt/status-server.cpp @@ -17,16 +17,6 @@ namespace tests { BOOST_FIXTURE_TEST_SUITE(MgmtStatusServer, BaseFixture) -static inline ndn::nfd::Status::Timestamp -now() -{ - return ndn::nfd::Status::Timestamp( - boost::chrono::duration_cast( - boost::chrono::system_clock::now().time_since_epoch() - ) - ); -} - shared_ptr g_response; void @@ -38,12 +28,12 @@ interceptResponse(const Data& data) BOOST_AUTO_TEST_CASE(Status) { // initialize - ndn::nfd::Status::Timestamp t1 = now(); + time::system_clock::TimePoint t1 = time::system_clock::now(); Forwarder forwarder; shared_ptr internalFace = make_shared(); internalFace->onReceiveData += &interceptResponse; StatusServer statusServer(internalFace, boost::ref(forwarder)); - ndn::nfd::Status::Timestamp t2 = now(); + time::system_clock::TimePoint t2 = time::system_clock::now(); // populate tables forwarder.getFib().insert("ndn:/fib1"); @@ -64,9 +54,9 @@ BOOST_AUTO_TEST_CASE(Status) request->setChildSelector(1); g_response.reset(); - ndn::nfd::Status::Timestamp t3 = now(); + time::system_clock::TimePoint t3 = time::system_clock::now(); internalFace->sendInterest(*request); - ndn::nfd::Status::Timestamp t4 = now(); + time::system_clock::TimePoint t4 = time::system_clock::now(); BOOST_REQUIRE(static_cast(g_response)); // verify @@ -74,10 +64,10 @@ BOOST_AUTO_TEST_CASE(Status) BOOST_REQUIRE_NO_THROW(status.wireDecode(g_response->getContent())); BOOST_CHECK_EQUAL(status.getNfdVersion(), NFD_VERSION); - BOOST_CHECK_GE(status.getStartTimestamp(), t1); - BOOST_CHECK_LE(status.getStartTimestamp(), t2); - BOOST_CHECK_GE(status.getCurrentTimestamp(), t3); - BOOST_CHECK_LE(status.getCurrentTimestamp(), t4); + BOOST_CHECK_GE(time::toUnixTimestamp(status.getStartTimestamp()), time::toUnixTimestamp(t1)); + BOOST_CHECK_LE(time::toUnixTimestamp(status.getStartTimestamp()), time::toUnixTimestamp(t2)); + BOOST_CHECK_GE(time::toUnixTimestamp(status.getCurrentTimestamp()), time::toUnixTimestamp(t3)); + BOOST_CHECK_LE(time::toUnixTimestamp(status.getCurrentTimestamp()), time::toUnixTimestamp(t4)); // StatusServer under test isn't added to Forwarder, // so request and response won't affect table size diff --git a/tests/table/cs.cpp b/tests/table/cs.cpp index cf0929cd..5bb6eb70 100644 --- a/tests/table/cs.cpp +++ b/tests/table/cs.cpp @@ -176,13 +176,13 @@ BOOST_AUTO_TEST_CASE(StalenessQueue) Name name2("/insert/fresh"); shared_ptr data2 = make_shared(name2); - data2->setFreshnessPeriod(5000); + data2->setFreshnessPeriod(time::milliseconds(5000)); data2->setSignature(fakeSignature); cs.insert(*data2); Name name("/insert/expire"); shared_ptr data = make_shared(name); - data->setFreshnessPeriod(500); + data->setFreshnessPeriod(time::milliseconds(500)); data->setSignature(fakeSignature); cs.insert(*data); @@ -508,7 +508,7 @@ BOOST_AUTO_TEST_CASE(MustBeFreshSelector) Name name("/insert/nonfresh"); shared_ptr data = make_shared(name); - data->setFreshnessPeriod(500); + data->setFreshnessPeriod(time::milliseconds(500)); data->setSignature(fakeSignature); cs.insert(*data); @@ -652,7 +652,7 @@ protected: insert(uint32_t id, const Name& name) { shared_ptr data = make_shared(name); - data->setFreshnessPeriod(99999); + data->setFreshnessPeriod(time::milliseconds(99999)); data->setContent(reinterpret_cast(&id), sizeof(id)); ndn::SignatureSha256WithRsa fakeSignature; diff --git a/tests/table/pit.cpp b/tests/table/pit.cpp index bf1e0736..17df2d77 100644 --- a/tests/table/pit.cpp +++ b/tests/table/pit.cpp @@ -21,16 +21,16 @@ BOOST_AUTO_TEST_CASE(EntryInOutRecords) Name name("ndn:/KuYfjtRq"); shared_ptr interest = makeInterest(name); shared_ptr interest1 = makeInterest(name); - interest1->setInterestLifetime(static_cast(2528)); + interest1->setInterestLifetime(time::milliseconds(2528)); interest1->setNonce(25559); shared_ptr interest2 = makeInterest(name); - interest2->setInterestLifetime(static_cast(6464)); + interest2->setInterestLifetime(time::milliseconds(6464)); interest2->setNonce(19004); shared_ptr interest3 = makeInterest(name); - interest3->setInterestLifetime(static_cast(3585)); + interest3->setInterestLifetime(time::milliseconds(3585)); interest3->setNonce(24216); shared_ptr interest4 = makeInterest(name); - interest4->setInterestLifetime(static_cast(8795)); + interest4->setInterestLifetime(time::milliseconds(8795)); interest4->setNonce(17365); pit::Entry entry(*interest); @@ -44,10 +44,10 @@ BOOST_AUTO_TEST_CASE(EntryInOutRecords) BOOST_CHECK_EQUAL(outRecords1.size(), 0); // insert InRecord - time::Point before1 = time::now(); + time::steady_clock::TimePoint before1 = time::steady_clock::now(); pit::InRecordCollection::iterator in1 = entry.insertOrUpdateInRecord(face1, *interest1); - time::Point after1 = time::now(); + time::steady_clock::TimePoint after1 = time::steady_clock::now(); const pit::InRecordCollection& inRecords2 = entry.getInRecords(); BOOST_CHECK_EQUAL(inRecords2.size(), 1); BOOST_CHECK(in1 == inRecords2.begin()); @@ -55,15 +55,15 @@ BOOST_AUTO_TEST_CASE(EntryInOutRecords) BOOST_CHECK_EQUAL(in1->getLastNonce(), interest1->getNonce()); BOOST_CHECK_GE(in1->getLastRenewed(), before1); BOOST_CHECK_LE(in1->getLastRenewed(), after1); - BOOST_CHECK_LE(std::abs(in1->getExpiry() - in1->getLastRenewed() - - time::milliseconds(interest1->getInterestLifetime())), - (after1 - before1)); + BOOST_CHECK_LE(in1->getExpiry() - in1->getLastRenewed() + - interest1->getInterestLifetime(), + (after1 - before1)); // insert OutRecord - time::Point before2 = time::now(); + time::steady_clock::TimePoint before2 = time::steady_clock::now(); pit::OutRecordCollection::iterator out1 = entry.insertOrUpdateOutRecord(face1, *interest1); - time::Point after2 = time::now(); + time::steady_clock::TimePoint after2 = time::steady_clock::now(); const pit::OutRecordCollection& outRecords2 = entry.getOutRecords(); BOOST_CHECK_EQUAL(outRecords2.size(), 1); BOOST_CHECK(out1 == outRecords2.begin()); @@ -71,23 +71,23 @@ BOOST_AUTO_TEST_CASE(EntryInOutRecords) BOOST_CHECK_EQUAL(out1->getLastNonce(), interest1->getNonce()); BOOST_CHECK_GE(out1->getLastRenewed(), before2); BOOST_CHECK_LE(out1->getLastRenewed(), after2); - BOOST_CHECK_LE(std::abs(out1->getExpiry() - out1->getLastRenewed() - - time::milliseconds(interest1->getInterestLifetime())), - (after2 - before2)); + BOOST_CHECK_LE(out1->getExpiry() - out1->getLastRenewed() + - interest1->getInterestLifetime(), + (after2 - before2)); // update InRecord - time::Point before3 = time::now(); + time::steady_clock::TimePoint before3 = time::steady_clock::now(); pit::InRecordCollection::iterator in2 = entry.insertOrUpdateInRecord(face1, *interest2); - time::Point after3 = time::now(); + time::steady_clock::TimePoint after3 = time::steady_clock::now(); const pit::InRecordCollection& inRecords3 = entry.getInRecords(); BOOST_CHECK_EQUAL(inRecords3.size(), 1); BOOST_CHECK(in2 == inRecords3.begin()); BOOST_CHECK_EQUAL(in2->getFace(), face1); BOOST_CHECK_EQUAL(in2->getLastNonce(), interest2->getNonce()); - BOOST_CHECK_LE(std::abs(in2->getExpiry() - in2->getLastRenewed() - - time::milliseconds(interest2->getInterestLifetime())), - (after3 - before3)); + BOOST_CHECK_LE(in2->getExpiry() - in2->getLastRenewed() + - interest2->getInterestLifetime(), + (after3 - before3)); // insert another InRecord pit::InRecordCollection::iterator in3 = @@ -130,16 +130,16 @@ BOOST_AUTO_TEST_CASE(EntryNonce) BOOST_AUTO_TEST_CASE(EntryLifetime) { shared_ptr interest = makeInterest("ndn:/7oIEurbgy6"); - BOOST_ASSERT(interest->getInterestLifetime() < 0); // library uses -1 to indicate unset lifetime + BOOST_ASSERT(interest->getInterestLifetime() < time::milliseconds::zero()); // library uses -1 to indicate unset lifetime shared_ptr face = make_shared(); pit::Entry entry(*interest); pit::InRecordCollection::iterator inIt = entry.insertOrUpdateInRecord(face, *interest); - BOOST_CHECK_GT(inIt->getExpiry(), time::now()); + BOOST_CHECK_GT(inIt->getExpiry(), time::steady_clock::now()); pit::OutRecordCollection::iterator outIt = entry.insertOrUpdateOutRecord(face, *interest); - BOOST_CHECK_GT(outIt->getExpiry(), time::now()); + BOOST_CHECK_GT(outIt->getExpiry(), time::steady_clock::now()); } BOOST_AUTO_TEST_CASE(EntryCanForwardTo) @@ -174,27 +174,27 @@ BOOST_AUTO_TEST_CASE(Insert) exclude2.excludeOne(Name::Component("FG1Ni6nYcf")); // base - Interest interestA(name1, -1, -1, exclude0, -1, false, -1, -1.0, 0); + Interest interestA(name1, -1, -1, exclude0, -1, false, -1, time::milliseconds::min(), 0); // A+exclude1 - Interest interestB(name1, -1, -1, exclude1, -1, false, -1, -1.0, 0); + Interest interestB(name1, -1, -1, exclude1, -1, false, -1, time::milliseconds::min(), 0); // A+exclude2 - Interest interestC(name1, -1, -1, exclude2, -1, false, -1, -1.0, 0); + Interest interestC(name1, -1, -1, exclude2, -1, false, -1, time::milliseconds::min(), 0); // A+MinSuffixComponents - Interest interestD(name1, 2, -1, exclude0, -1, false, -1, -1.0, 0); + Interest interestD(name1, 2, -1, exclude0, -1, false, -1, time::milliseconds::min(), 0); // A+MaxSuffixComponents - Interest interestE(name1, -1, 4, exclude0, -1, false, -1, -1.0, 0); + Interest interestE(name1, -1, 4, exclude0, -1, false, -1, time::milliseconds::min(), 0); // A+ChildSelector - Interest interestF(name1, -1, -1, exclude0, 1, false, -1, -1.0, 0); + Interest interestF(name1, -1, -1, exclude0, 1, false, -1, time::milliseconds::min(), 0); // A+MustBeFresh - Interest interestG(name1, -1, -1, exclude0, -1, true, -1, -1.0, 0); + Interest interestG(name1, -1, -1, exclude0, -1, true, -1, time::milliseconds::min(), 0); // A+Scope - Interest interestH(name1, -1, -1, exclude0, -1, false, 2, -1.0, 0); + Interest interestH(name1, -1, -1, exclude0, -1, false, 2, time::milliseconds::min(), 0); // A+InterestLifetime - Interest interestI(name1, -1, -1, exclude0, -1, false, -1, 2000, 0); + Interest interestI(name1, -1, -1, exclude0, -1, false, -1, time::milliseconds(2000), 0); // A+Nonce - Interest interestJ(name1, -1, -1, exclude0, -1, false, -1, -1.0, 2192); + Interest interestJ(name1, -1, -1, exclude0, -1, false, -1, time::milliseconds::min(), 2192); // different Name+exclude1 - Interest interestK(name2, -1, -1, exclude1, -1, false, -1, -1.0, 0); + Interest interestK(name2, -1, -1, exclude1, -1, false, -1, time::milliseconds::min(), 0); NameTree nameTree(16); Pit pit(nameTree); diff --git a/tools/ndn-autoconfig.cpp b/tools/ndn-autoconfig.cpp index a92fad35..a62b7e7b 100644 --- a/tools/ndn-autoconfig.cpp +++ b/tools/ndn-autoconfig.cpp @@ -44,7 +44,7 @@ public: discoverHubStage1() { ndn::Interest interest(ndn::Name("/localhop/ndn-autoconf/hub")); - interest.setInterestLifetime(4000); // 4 seconds + interest.setInterestLifetime(ndn::time::milliseconds(4000)); // 4 seconds interest.setMustBeFresh(true); std::cerr << "Stage 1: Trying muticast discovery..." << std::endl; @@ -249,6 +249,8 @@ public: connectToHub(uri); return true; } + + return false; } }; diff --git a/tools/ndn-autoconfigserver.cpp b/tools/ndn-autoconfigserver.cpp index e7b99758..070b84c4 100644 --- a/tools/ndn-autoconfigserver.cpp +++ b/tools/ndn-autoconfigserver.cpp @@ -34,7 +34,7 @@ public: { size_t total_len = 0; ndn::Data data(ndn::Name(interest.getName()).appendVersion()); - data.setFreshnessPeriod(1000); // 1 sec + data.setFreshnessPeriod(time::hours(1)); // 1 hour // create and encode uri block Block uriBlock = dataBlock(tlv::nfd::Uri, diff --git a/tools/ndn-tlv-peek.cpp b/tools/ndn-tlv-peek.cpp index 8ed429db..cb7adfde 100644 --- a/tools/ndn-tlv-peek.cpp +++ b/tools/ndn-tlv-peek.cpp @@ -40,9 +40,9 @@ public: " [-r] - set ChildSelector to select rightmost child\n" " [-m min] - set MinSuffixComponents\n" " [-M max] - set MaxSuffixComponents\n" - " [-l lifetime] - set InterestLifetime in milliseconds\n" + " [-l lifetime] - set InterestLifetime in time::milliseconds\n" " [-p] - print payload only, not full packet\n" - " [-w timeout] - set Timeout in milliseconds\n" + " [-w timeout] - set Timeout in time::milliseconds\n" " [-h] - print help and exit\n\n"; exit(1); } @@ -80,7 +80,7 @@ public: { if (interestLifetime < 0) usage(); - m_interestLifetime = interestLifetime; + m_interestLifetime = ndn::time::milliseconds(interestLifetime); } void @@ -94,7 +94,7 @@ public: { if (timeout < 0) usage(); - m_timeout = timeout; + m_timeout = ndn::time::milliseconds(timeout); } void @@ -105,10 +105,10 @@ public: usage(); } - int + ndn::time::milliseconds getDefaultInterestLifetime() { - return 4000; + return ndn::time::seconds(4); } ndn::Interest @@ -124,7 +124,7 @@ public: interestPacket.setMinSuffixComponents(m_minSuffixComponents); if (m_maxSuffixComponents >= 0) interestPacket.setMaxSuffixComponents(m_maxSuffixComponents); - if (m_interestLifetime < 0) + if (m_interestLifetime < ndn::time::milliseconds::zero()) interestPacket.setInterestLifetime(getDefaultInterestLifetime()); else interestPacket.setInterestLifetime(m_interestLifetime); @@ -163,9 +163,9 @@ public: this, _1, _2), ndn::func_lib::bind(&NdnTlvPeek::onTimeout, this, _1)); - if (m_timeout < 0) + if (m_timeout < ndn::time::milliseconds::zero()) { - if (m_interestLifetime < 0) + if (m_interestLifetime < ndn::time::milliseconds::zero()) m_face.processEvents(getDefaultInterestLifetime()); else m_face.processEvents(m_interestLifetime); @@ -193,9 +193,9 @@ private: bool m_isChildSelectorRightmost; int m_minSuffixComponents; int m_maxSuffixComponents; - int m_interestLifetime; + ndn::time::milliseconds m_interestLifetime; bool m_isPayloadOnlySet; - int m_timeout; + ndn::time::milliseconds m_timeout; std::string m_prefixName; bool m_isDataReceived; ndn::ptr_lib::shared_ptr m_ioService; diff --git a/tools/ndn-tlv-poke.cpp b/tools/ndn-tlv-poke.cpp index 51a12d9e..ba02e5e8 100644 --- a/tools/ndn-tlv-poke.cpp +++ b/tools/ndn-tlv-poke.cpp @@ -41,8 +41,8 @@ public: "SignatureSha256WithRsa\n" " [-i identity] - set identity to be used for signing\n" " [-F] - set FinalBlockId to the last component of Name\n" - " [-x] - set FreshnessPeriod in milliseconds\n" - " [-w timeout] - set Timeout in milliseconds\n" + " [-x] - set FreshnessPeriod in time::milliseconds\n" + " [-w timeout] - set Timeout in time::milliseconds\n" " [-h] - print help and exit\n\n"; exit(1); } @@ -76,7 +76,7 @@ public: { if (freshnessPeriod < 0) usage(); - m_freshnessPeriod = freshnessPeriod; + m_freshnessPeriod = ndn::time::milliseconds(freshnessPeriod); } void @@ -84,7 +84,7 @@ public: { if (timeout < 0) usage(); - m_timeout = timeout; + m_timeout = ndn::time::milliseconds(timeout); } void @@ -93,10 +93,10 @@ public: m_prefixName = ndn::Name(prefixName); } - ndn::Milliseconds + ndn::time::milliseconds getDefaultTimeout() { - return 10000; + return ndn::time::seconds(10); } ndn::Data @@ -107,7 +107,7 @@ public: payloadStream << std::cin.rdbuf(); std::string payload = payloadStream.str(); dataPacket.setContent(reinterpret_cast(payload.c_str()), payload.length()); - if (m_freshnessPeriod >= 0) + if (m_freshnessPeriod >= ndn::time::milliseconds::zero()) dataPacket.setFreshnessPeriod(m_freshnessPeriod); if (m_isLastAsFinalBlockIdSet) { @@ -162,12 +162,12 @@ public: else { m_face.setInterestFilter(m_prefixName, - ndn::func_lib::bind(&NdnTlvPoke::onInterest, - this, _1, _2, dataPacket), - ndn::func_lib::bind(&NdnTlvPoke::onRegisterFailed, - this, _1, _2)); + ndn::bind(&NdnTlvPoke::onInterest, + this, _1, _2, dataPacket), + ndn::bind(&NdnTlvPoke::onRegisterFailed, + this, _1, _2)); } - if (m_timeout < 0) + if (m_timeout < ndn::time::milliseconds::zero()) m_face.processEvents(getDefaultTimeout()); else m_face.processEvents(m_timeout); @@ -193,8 +193,8 @@ private: bool m_isUseDigestSha256Set; ndn::shared_ptr m_identityName; bool m_isLastAsFinalBlockIdSet; - ndn::Milliseconds m_freshnessPeriod; - ndn::Milliseconds m_timeout; + ndn::time::milliseconds m_freshnessPeriod; + ndn::time::milliseconds m_timeout; ndn::Name m_prefixName; bool m_isDataSent; ndn::Face m_face;