all: Update code to compile with latest time-related changes in ndn-cpp-dev library
Change-Id: I7e859989c833001f49b286d4a9917f4dc740b4a4
diff --git a/README-dev.md b/README-dev.md
index df92b78..bf9771e 100644
--- a/README-dev.md
+++ b/README-dev.md
@@ -12,7 +12,8 @@
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 @@
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 3a39f99..32ad4a4 100644
--- a/daemon/common.hpp
+++ b/daemon/common.hpp
@@ -67,6 +67,8 @@
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 bd61f10..508e26d 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 @@
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> resolver =
shared_ptr<Resolver>(new Resolver(onSuccess, onError,
@@ -126,7 +125,7 @@
void
asyncResolve(const std::string& host, const std::string& port,
- const time::Duration& timeout,
+ const time::seconds& timeout,
const shared_ptr<Resolver>& self)
{
typename resolver::query query(host, port,
diff --git a/daemon/core/scheduler.hpp b/daemon/core/scheduler.hpp
index 6ba4f80..a7f452b 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 <ndn-cpp-dev/util/scheduler.hpp>
namespace nfd {
@@ -35,7 +34,7 @@
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 2c9498f..0000000
--- 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 <ndn-cpp-dev/util/time.hpp>
-
-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 74c109f..e252c84 100644
--- a/daemon/face/ndnlp-partial-message-store.cpp
+++ b/daemon/face/ndnlp-partial-message-store.cpp
@@ -61,7 +61,7 @@
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 e5de5b1..7cd3df8 100644
--- a/daemon/face/ndnlp-partial-message-store.hpp
+++ b/daemon/face/ndnlp-partial-message-store.hpp
@@ -53,7 +53,7 @@
{
public:
PartialMessageStore(Scheduler& scheduler,
- time::Duration idleDuration = time::milliseconds(100));
+ const time::nanoseconds& idleDuration = time::milliseconds(100));
virtual
~PartialMessageStore();
@@ -80,7 +80,7 @@
std::map<uint64_t, shared_ptr<PartialMessage> > 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 4b46ea9..c27f1df 100644
--- a/daemon/face/tcp-channel.cpp
+++ b/daemon/face/tcp-channel.cpp
@@ -51,7 +51,7 @@
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 @@
shared_ptr<ip::tcp::socket> clientSocket =
make_shared<ip::tcp::socket>(boost::ref(getGlobalIoService()));
- shared_ptr<monotonic_deadline_timer> connectTimeoutTimer =
- make_shared<monotonic_deadline_timer>(boost::ref(getGlobalIoService()));
+ shared_ptr<ndn::monotonic_deadline_timer> connectTimeoutTimer =
+ make_shared<ndn::monotonic_deadline_timer>(boost::ref(getGlobalIoService()));
clientSocket->async_connect(remoteEndpoint,
bind(&TcpChannel::handleSuccessfulConnect, this, _1,
@@ -80,13 +80,13 @@
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<ip::tcp::socket> clientSocket =
make_shared<ip::tcp::socket>(boost::ref(getGlobalIoService()));
- shared_ptr<monotonic_deadline_timer> connectTimeoutTimer =
- make_shared<monotonic_deadline_timer>(boost::ref(getGlobalIoService()));
+ shared_ptr<ndn::monotonic_deadline_timer> connectTimeoutTimer =
+ make_shared<ndn::monotonic_deadline_timer>(boost::ref(getGlobalIoService()));
ip::tcp::resolver::query query(remoteHost, remotePort);
shared_ptr<ip::tcp::resolver> resolver =
@@ -170,7 +170,7 @@
void
TcpChannel::handleSuccessfulConnect(const boost::system::error_code& error,
const shared_ptr<ip::tcp::socket>& socket,
- const shared_ptr<monotonic_deadline_timer>& timer,
+ const shared_ptr<ndn::monotonic_deadline_timer>& timer,
const FaceCreatedCallback& onFaceCreated,
const ConnectFailedCallback& onConnectFailed)
{
@@ -199,7 +199,7 @@
void
TcpChannel::handleFailedConnect(const boost::system::error_code& error,
const shared_ptr<ip::tcp::socket>& socket,
- const shared_ptr<monotonic_deadline_timer>& timer,
+ const shared_ptr<ndn::monotonic_deadline_timer>& timer,
const ConnectFailedCallback& onConnectFailed)
{
if (error) { // e.g., cancelled
@@ -218,7 +218,7 @@
TcpChannel::handleEndpointResolution(const boost::system::error_code& error,
ip::tcp::resolver::iterator remoteEndpoint,
const shared_ptr<boost::asio::ip::tcp::socket>& socket,
- const shared_ptr<boost::asio::monotonic_deadline_timer>& timer,
+ const shared_ptr<ndn::monotonic_deadline_timer>& timer,
const FaceCreatedCallback& onFaceCreated,
const ConnectFailedCallback& onConnectFailed,
const shared_ptr<ip::tcp::resolver>& resolver)
diff --git a/daemon/face/tcp-channel.hpp b/daemon/face/tcp-channel.hpp
index 808d0f1..61a9c05 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 <ndn-cpp-dev/util/monotonic_deadline_timer.hpp>
#include "tcp-face.hpp"
@@ -61,7 +60,7 @@
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 @@
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 @@
void
handleSuccessfulConnect(const boost::system::error_code& error,
const shared_ptr<boost::asio::ip::tcp::socket>& socket,
- const shared_ptr<boost::asio::monotonic_deadline_timer>& timer,
+ const shared_ptr<ndn::monotonic_deadline_timer>& timer,
const FaceCreatedCallback& onFaceCreated,
const ConnectFailedCallback& onConnectFailed);
void
handleFailedConnect(const boost::system::error_code& error,
const shared_ptr<boost::asio::ip::tcp::socket>& socket,
- const shared_ptr<boost::asio::monotonic_deadline_timer>& timer,
+ const shared_ptr<ndn::monotonic_deadline_timer>& timer,
const ConnectFailedCallback& onConnectFailed);
void
handleEndpointResolution(const boost::system::error_code& error,
boost::asio::ip::tcp::resolver::iterator remoteEndpoint,
const shared_ptr<boost::asio::ip::tcp::socket>& socket,
- const shared_ptr<boost::asio::monotonic_deadline_timer>& timer,
+ const shared_ptr<ndn::monotonic_deadline_timer>& timer,
const FaceCreatedCallback& onFaceCreated,
const ConnectFailedCallback& onConnectFailed,
const shared_ptr<boost::asio::ip::tcp::resolver>& resolver);
diff --git a/daemon/face/udp-channel.cpp b/daemon/face/udp-channel.cpp
index a9e24f7..9151830 100644
--- a/daemon/face/udp-channel.cpp
+++ b/daemon/face/udp-channel.cpp
@@ -15,7 +15,7 @@
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 81e53ac..26c6cae 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 @@
* \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 @@
* \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 a311d81..5fcfd1c 100644
--- a/daemon/face/udp-factory.cpp
+++ b/daemon/face/udp-factory.cpp
@@ -21,7 +21,7 @@
shared_ptr<UdpChannel>
UdpFactory::createChannel(const udp::Endpoint& endpoint,
- const time::Duration& timeout)
+ const time::seconds& timeout)
{
NFD_LOG_DEBUG("Creating unicast " << endpoint);
@@ -52,7 +52,7 @@
shared_ptr<UdpChannel>
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 695d1e5..969ef8c 100644
--- a/daemon/face/udp-factory.hpp
+++ b/daemon/face/udp-factory.hpp
@@ -56,7 +56,7 @@
*/
shared_ptr<UdpChannel>
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 @@
shared_ptr<UdpChannel>
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 4ab852e..e46bd5a 100644
--- a/daemon/fw/forwarder.cpp
+++ b/daemon/fw/forwarder.cpp
@@ -217,7 +217,7 @@
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 @@
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 @@
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 79d8b1a..d0b43f1 100644
--- a/daemon/fw/ncc-strategy.cpp
+++ b/daemon/fw/ncc-strategy.cpp
@@ -20,9 +20,9 @@
{
}
-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 @@
shared_ptr<MeasurementsEntryInfo> 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<Face> bestFace = measurementsEntryInfo->getBestFace();
@@ -56,7 +56,8 @@
pitEntry->canForwardTo(*bestFace)) {
// TODO Should we use `randlow = 100 + nrand48(h->seed) % 4096U;` ?
deferFirst = measurementsEntryInfo->m_prediction;
- deferRange = static_cast<time::Duration>((deferFirst + time::microseconds(1)) / 2);
+ deferRange = time::nanoseconds((deferFirst.count() +
+ static_cast<time::nanoseconds>(time::microseconds(1)).count()) / 2);
--nUpstreams;
this->sendInterest(pitEntry, bestFace);
pitEntryInfo->m_bestFaceTimeout = scheduler::schedule(
@@ -75,8 +76,8 @@
--nUpstreams;
}
- pitEntryInfo->m_maxInterval = std::max(time::microseconds(1),
- static_cast<time::Duration>((2 * deferRange + nUpstreams - 1) / nUpstreams));
+ pitEntryInfo->m_maxInterval = std::max(static_cast<time::nanoseconds>(time::microseconds(1)),
+ time::nanoseconds((2 * deferRange.count() + nUpstreams - 1) / nUpstreams));
pitEntryInfo->m_propagateTimer = scheduler::schedule(deferFirst,
bind(&NccStrategy::doPropagate, this,
weak_ptr<pit::Entry>(pitEntry), weak_ptr<fib::Entry>(fibEntry)));
@@ -120,8 +121,7 @@
if (isForwarded) {
static unsigned short seed[3];
- time::Duration deferNext = static_cast<time::Duration>(
- 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<pit::Entry>(pitEntry), weak_ptr<fib::Entry>(fibEntry)));
@@ -206,11 +206,11 @@
}
-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 @@
void
NccStrategy::MeasurementsEntryInfo::adjustPredictDown() {
m_prediction = std::max(MIN_PREDICTION,
- static_cast<time::Duration>(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<time::Duration>(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 ff9bcf3..6a41b1a 100644
--- a/daemon/fw/ncc-strategy.hpp
+++ b/daemon/fw/ncc-strategy.hpp
@@ -61,12 +61,12 @@
public:
weak_ptr<Face> m_bestFace;
weak_ptr<Face> 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 @@
bool m_isNewInterest;
EventId m_bestFaceTimeout;
EventId m_propagateTimer;
- time::Duration m_maxInterval;
+ time::nanoseconds m_maxInterval;
};
protected:
@@ -105,10 +105,10 @@
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 bd7d971..fefe30e 100644
--- a/daemon/mgmt/segment-publisher.cpp
+++ b/daemon/mgmt/segment-publisher.cpp
@@ -33,7 +33,7 @@
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 9635488..61a67b1 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<std::time_t>(0) == boost::chrono::system_clock::to_time_t(
- boost::chrono::system_clock::time_point(
- boost::chrono::duration_cast<boost::chrono::system_clock::duration>(
- ndn::nfd::Status::Timestamp::duration::zero()
- )
- )
- ));
-
- return ndn::nfd::Status::Timestamp(
- boost::chrono::duration_cast<ndn::nfd::Status::Timestamp::duration>(
- boost::chrono::system_clock::now().time_since_epoch()
- )
- );
-}
+const time::milliseconds StatusServer::RESPONSE_FRESHNESS = time::milliseconds(5000);
StatusServer::StatusServer(shared_ptr<AppFace> 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 @@
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> data = make_shared<Data>(name);
data->setFreshnessPeriod(RESPONSE_FRESHNESS);
@@ -67,7 +49,7 @@
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 94c8e82..c9a14f5 100644
--- a/daemon/mgmt/status-server.hpp
+++ b/daemon/mgmt/status-server.hpp
@@ -28,11 +28,11 @@
private:
static const Name DATASET_PREFIX;
- static const ndn::Milliseconds RESPONSE_FRESHNESS;
+ static const time::milliseconds RESPONSE_FRESHNESS;
shared_ptr<AppFace> 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 108a050..9e99886 100644
--- a/daemon/table/cs-entry.cpp
+++ b/daemon/table/cs-entry.cpp
@@ -78,7 +78,7 @@
return m_isUnsolicited;
}
-const time::Point&
+const time::steady_clock::TimePoint&
Entry::getStaleTime() const
{
return m_staleAt;
@@ -87,8 +87,7 @@
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 7d31442..062e7f1 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 <ndn-cpp-dev/util/crypto.hpp>
namespace nfd {
@@ -49,9 +48,9 @@
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 @@
printIterators() const;
private:
- time::Point m_staleAt;
+ time::steady_clock::TimePoint m_staleAt;
shared_ptr<const Data> m_dataPacket;
bool m_isUnsolicited;
diff --git a/daemon/table/cs.cpp b/daemon/table/cs.cpp
index a68c541..0e0bb6a 100644
--- a/daemon/table/cs.cpp
+++ b/daemon/table/cs.cpp
@@ -19,7 +19,7 @@
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 @@
shared_ptr<cs::Entry> 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 @@
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 @@
}
}
- 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 53b30d4..be0c7b0 100644
--- a/daemon/table/measurements-accessor.hpp
+++ b/daemon/table/measurements-accessor.hpp
@@ -50,7 +50,7 @@
* 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 @@
}
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 11e4fab..36cca3a 100644
--- a/daemon/table/measurements-entry.cpp
+++ b/daemon/table/measurements-entry.cpp
@@ -11,7 +11,7 @@
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 60a428f..c4b73ce 100644
--- a/daemon/table/measurements-entry.hpp
+++ b/daemon/table/measurements-entry.hpp
@@ -39,7 +39,7 @@
Name m_name;
private: // lifetime
- time::Point m_expiry;
+ time::steady_clock::TimePoint m_expiry;
EventId m_cleanup;
shared_ptr<name_tree::Entry> m_nameTreeEntry;
diff --git a/daemon/table/measurements.cpp b/daemon/table/measurements.cpp
index c284efa..dcc40fe 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 @@
}
void
-Measurements::extendLifetime(measurements::Entry& entry, const time::Duration lifetime)
+Measurements::extendLifetime(measurements::Entry& entry, const time::nanoseconds& lifetime)
{
shared_ptr<measurements::Entry> ret = this->findExactMatch(entry.getName());
if (static_cast<bool>(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 561b301..8d09666 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 @@
* 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:
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 86596df..b3e5438 100644
--- a/daemon/table/pit-entry.cpp
+++ b/daemon/table/pit-entry.cpp
@@ -58,7 +58,7 @@
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 @@
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 @@
}
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 @@
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 5663dce..4d611f9 100644
--- a/daemon/table/pit-face-record.cpp
+++ b/daemon/table/pit-face-record.cpp
@@ -12,8 +12,8 @@
FaceRecord::FaceRecord(shared_ptr<Face> 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 @@
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<ndn::Milliseconds>(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 3ad0462..9bcfbed 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 @@
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 @@
private:
shared_ptr<Face> 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<Face>
@@ -66,13 +65,13 @@
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 b381696..1eba63d 100644
--- a/tests/core/limited-io.cpp
+++ b/tests/core/limited-io.cpp
@@ -13,7 +13,7 @@
NFD_LOG_INIT("LimitedIo");
const int LimitedIo::UNLIMITED_OPS = std::numeric_limits<int>::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::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 0aae290..d3968c2 100644
--- a/tests/core/limited-io.hpp
+++ b/tests/core/limited-io.hpp
@@ -38,7 +38,7 @@
* \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 @@
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 806c982..87c75cf 100644
--- a/tests/core/scheduler.cpp
+++ b/tests/core/scheduler.cpp
@@ -57,18 +57,20 @@
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 @@
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 332e28c..38ee797 100644
--- a/tests/face/tcp.cpp
+++ b/tests/face/tcp.cpp
@@ -349,7 +349,7 @@
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_CHECK(static_cast<bool>(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 5e3a996..d4983bf 100644
--- a/tests/face/udp.cpp
+++ b/tests/face/udp.cpp
@@ -545,7 +545,7 @@
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<UdpChannel::FaceCreatedCallback>(
@@ -553,7 +553,7 @@
static_cast<UdpChannel::ConnectFailedCallback>(
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_CHECK_NE(channel3, channel4);
//
// scheduler
-// .scheduleEvent(time::seconds(0.5),
+// .scheduleEvent(time::milliseconds(500),
// bind(&UdpChannel::connect, channel4,
// "::1", "20070",
// static_cast<UdpChannel::FaceCreatedCallback>(bind(&EndToEndFixture::
@@ -806,7 +806,7 @@
BOOST_CHECK(static_cast<bool>(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 7ec90a5..c96e57a 100644
--- a/tests/fw/forwarder.cpp
+++ b/tests/fw/forwarder.cpp
@@ -24,7 +24,7 @@
Name nameAB ("ndn:/A/B");
Name nameABC("ndn:/A/B/C");
shared_ptr<Interest> interestAB = makeInterest(nameAB);
- interestAB->setInterestLifetime(4000);
+ interestAB->setInterestLifetime(time::seconds(4));
shared_ptr<Data> dataABC = makeData(nameABC);
shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
@@ -317,10 +317,10 @@
BOOST_CHECK_EQUAL(strategyQ->m_beforeSatisfyPendingInterest_count, 1);
shared_ptr<Interest> interest3 = makeInterest("ndn:/A/3");
- interest3->setInterestLifetime(30);
+ interest3->setInterestLifetime(time::milliseconds(30));
forwarder.onInterest(*face1, *interest3);
shared_ptr<Interest> 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 d980c49..044b3ec 100644
--- a/tests/fw/ncc-strategy.cpp
+++ b/tests/fw/ncc-strategy.cpp
@@ -49,7 +49,7 @@
// first Interest: strategy knows nothing and follows routing
shared_ptr<Interest> interest1p = makeInterest("ndn:/0Jm1ajrW/%00");
Interest& interest1 = *interest1p;
- interest1.setInterestLifetime(8000);
+ interest1.setInterestLifetime(time::milliseconds(8000));
shared_ptr<pit::Entry> pitEntry1 = pit.insert(interest1).first;
pitEntry1->insertOrUpdateInRecord(face3, interest1);
@@ -74,7 +74,7 @@
// second Interest: strategy knows face2 is best
shared_ptr<Interest> interest2p = makeInterest("ndn:/0Jm1ajrW/%00%01");
Interest& interest2 = *interest2p;
- interest2.setInterestLifetime(8000);
+ interest2.setInterestLifetime(time::milliseconds(8000));
shared_ptr<pit::Entry> pitEntry2 = pit.insert(interest2).first;
pitEntry2->insertOrUpdateInRecord(face3, interest2);
diff --git a/tests/mgmt/command-validator.cpp b/tests/mgmt/command-validator.cpp
index 3dcae24..e2cf51c 100644
--- a/tests/mgmt/command-validator.cpp
+++ b/tests/mgmt/command-validator.cpp
@@ -84,7 +84,7 @@
generateIdentity(const Name& prefix)
{
m_identityName = prefix;
- m_identityName.append(boost::lexical_cast<std::string>(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 3d8442b..99aa9f8 100644
--- a/tests/mgmt/status-server.cpp
+++ b/tests/mgmt/status-server.cpp
@@ -17,16 +17,6 @@
BOOST_FIXTURE_TEST_SUITE(MgmtStatusServer, BaseFixture)
-static inline ndn::nfd::Status::Timestamp
-now()
-{
- return ndn::nfd::Status::Timestamp(
- boost::chrono::duration_cast<ndn::nfd::Status::Timestamp::duration>(
- boost::chrono::system_clock::now().time_since_epoch()
- )
- );
-}
-
shared_ptr<const Data> g_response;
void
@@ -38,12 +28,12 @@
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> internalFace = make_shared<InternalFace>();
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 @@
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<bool>(g_response));
// verify
@@ -74,10 +64,10 @@
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 cf0929c..5bb6eb7 100644
--- a/tests/table/cs.cpp
+++ b/tests/table/cs.cpp
@@ -176,13 +176,13 @@
Name name2("/insert/fresh");
shared_ptr<Data> data2 = make_shared<Data>(name2);
- data2->setFreshnessPeriod(5000);
+ data2->setFreshnessPeriod(time::milliseconds(5000));
data2->setSignature(fakeSignature);
cs.insert(*data2);
Name name("/insert/expire");
shared_ptr<Data> data = make_shared<Data>(name);
- data->setFreshnessPeriod(500);
+ data->setFreshnessPeriod(time::milliseconds(500));
data->setSignature(fakeSignature);
cs.insert(*data);
@@ -508,7 +508,7 @@
Name name("/insert/nonfresh");
shared_ptr<Data> data = make_shared<Data>(name);
- data->setFreshnessPeriod(500);
+ data->setFreshnessPeriod(time::milliseconds(500));
data->setSignature(fakeSignature);
cs.insert(*data);
@@ -652,7 +652,7 @@
insert(uint32_t id, const Name& name)
{
shared_ptr<Data> data = make_shared<Data>(name);
- data->setFreshnessPeriod(99999);
+ data->setFreshnessPeriod(time::milliseconds(99999));
data->setContent(reinterpret_cast<const uint8_t*>(&id), sizeof(id));
ndn::SignatureSha256WithRsa fakeSignature;
diff --git a/tests/table/pit.cpp b/tests/table/pit.cpp
index bf1e073..17df2d7 100644
--- a/tests/table/pit.cpp
+++ b/tests/table/pit.cpp
@@ -21,16 +21,16 @@
Name name("ndn:/KuYfjtRq");
shared_ptr<Interest> interest = makeInterest(name);
shared_ptr<Interest> interest1 = makeInterest(name);
- interest1->setInterestLifetime(static_cast<ndn::Milliseconds>(2528));
+ interest1->setInterestLifetime(time::milliseconds(2528));
interest1->setNonce(25559);
shared_ptr<Interest> interest2 = makeInterest(name);
- interest2->setInterestLifetime(static_cast<ndn::Milliseconds>(6464));
+ interest2->setInterestLifetime(time::milliseconds(6464));
interest2->setNonce(19004);
shared_ptr<Interest> interest3 = makeInterest(name);
- interest3->setInterestLifetime(static_cast<ndn::Milliseconds>(3585));
+ interest3->setInterestLifetime(time::milliseconds(3585));
interest3->setNonce(24216);
shared_ptr<Interest> interest4 = makeInterest(name);
- interest4->setInterestLifetime(static_cast<ndn::Milliseconds>(8795));
+ interest4->setInterestLifetime(time::milliseconds(8795));
interest4->setNonce(17365);
pit::Entry entry(*interest);
@@ -44,10 +44,10 @@
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_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_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(EntryLifetime)
{
shared_ptr<Interest> 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> face = make_shared<DummyFace>();
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 @@
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 a92fad3..a62b7e7 100644
--- a/tools/ndn-autoconfig.cpp
+++ b/tools/ndn-autoconfig.cpp
@@ -44,7 +44,7 @@
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 @@
connectToHub(uri);
return true;
}
+
+ return false;
}
};
diff --git a/tools/ndn-autoconfigserver.cpp b/tools/ndn-autoconfigserver.cpp
index e7b9975..070b84c 100644
--- a/tools/ndn-autoconfigserver.cpp
+++ b/tools/ndn-autoconfigserver.cpp
@@ -34,7 +34,7 @@
{
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 8ed429d..cb7adfd 100644
--- a/tools/ndn-tlv-peek.cpp
+++ b/tools/ndn-tlv-peek.cpp
@@ -40,9 +40,9 @@
" [-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 @@
{
if (interestLifetime < 0)
usage();
- m_interestLifetime = interestLifetime;
+ m_interestLifetime = ndn::time::milliseconds(interestLifetime);
}
void
@@ -94,7 +94,7 @@
{
if (timeout < 0)
usage();
- m_timeout = timeout;
+ m_timeout = ndn::time::milliseconds(timeout);
}
void
@@ -105,10 +105,10 @@
usage();
}
- int
+ ndn::time::milliseconds
getDefaultInterestLifetime()
{
- return 4000;
+ return ndn::time::seconds(4);
}
ndn::Interest
@@ -124,7 +124,7 @@
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 @@
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 @@
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<boost::asio::io_service> m_ioService;
diff --git a/tools/ndn-tlv-poke.cpp b/tools/ndn-tlv-poke.cpp
index 51a12d9..ba02e5e 100644
--- a/tools/ndn-tlv-poke.cpp
+++ b/tools/ndn-tlv-poke.cpp
@@ -41,8 +41,8 @@
"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 @@
{
if (freshnessPeriod < 0)
usage();
- m_freshnessPeriod = freshnessPeriod;
+ m_freshnessPeriod = ndn::time::milliseconds(freshnessPeriod);
}
void
@@ -84,7 +84,7 @@
{
if (timeout < 0)
usage();
- m_timeout = timeout;
+ m_timeout = ndn::time::milliseconds(timeout);
}
void
@@ -93,10 +93,10 @@
m_prefixName = ndn::Name(prefixName);
}
- ndn::Milliseconds
+ ndn::time::milliseconds
getDefaultTimeout()
{
- return 10000;
+ return ndn::time::seconds(10);
}
ndn::Data
@@ -107,7 +107,7 @@
payloadStream << std::cin.rdbuf();
std::string payload = payloadStream.str();
dataPacket.setContent(reinterpret_cast<const uint8_t*>(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 @@
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 @@
bool m_isUseDigestSha256Set;
ndn::shared_ptr<ndn::Name> 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;