NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
ndn::time Namespace Reference

Classes

class  CustomClock
 Class implementing custom system or steady clock behavior. More...
 
class  steady_clock
 Steady clock. More...
 
class  system_clock
 System clock. More...
 
class  UnitTestClock
 Clock that can be used in unit tests for time-dependent tests independent of wall clock. More...
 
class  UnitTestClockTraits
 Traits for UnitTestClock, defining default behavior for different clocks. More...
 
class  UnitTestClockTraits< system_clock >
 Specialization of UnitTestClockTraits for system_clock. More...
 

Typedefs

using CustomSystemClock = CustomClock< system_clock >
 
using CustomSteadyClock = CustomClock< steady_clock >
 
using UnitTestSystemClock = UnitTestClock< system_clock >
 
using UnitTestSteadyClock = UnitTestClock< steady_clock >
 
typedef boost::chrono::steady_clock base_steady_clock
 
using days = duration< int_fast32_t, boost::ratio< 86400 > >
 

Functions

void setCustomClocks (shared_ptr< CustomSteadyClock > steadyClock=nullptr, shared_ptr< CustomSystemClock > systemClock=nullptr)
 Set custom system and steady clocks. More...
 
const system_clock::TimePointgetUnixEpoch ()
 Get system_clock::TimePoint representing UNIX time epoch (00:00:00 on Jan 1, 1970) More...
 
milliseconds toUnixTimestamp (const system_clock::TimePoint &point)
 Convert system_clock::TimePoint to UNIX timestamp. More...
 
system_clock::TimePoint fromUnixTimestamp (milliseconds duration)
 Convert UNIX timestamp to system_clock::TimePoint. More...
 
static boost::posix_time::ptime convertToPosixTime (const system_clock::TimePoint &timePoint)
 
std::string toIsoString (const system_clock::TimePoint &timePoint)
 Convert to the ISO string representation of the time (YYYYMMDDTHHMMSS,fffffffff) More...
 
static system_clock::TimePoint convertToTimePoint (const boost::posix_time::ptime &ptime)
 
system_clock::TimePoint fromIsoString (const std::string &isoString)
 Convert from the ISO string (YYYYMMDDTHHMMSS,fffffffff) representation to the internal time format. More...
 
std::string toString (const system_clock::TimePoint &timePoint, const std::string &format="%Y-%m-%d %H:%M:%S", const std::locale &locale=std::locale("C"))
 Convert time point to string with specified format. More...
 
system_clock::TimePoint fromString (const std::string &timePointStr, const std::string &format="%Y-%m-%d %H:%M:%S", const std::locale &locale=std::locale("C"))
 Convert from string of specified format into time point. More...
 
template<typename Rep , typename Period , typename = std::enable_if_t<std::numeric_limits<Rep>::is_signed>>
constexpr duration< Rep, Period > abs (duration< Rep, Period > d)
 

Variables

static shared_ptr< CustomSystemClockg_systemClock
 
static shared_ptr< CustomSteadyClockg_steadyClock
 

Typedef Documentation

◆ CustomSystemClock

Definition at line 53 of file time-custom-clock.hpp.

◆ CustomSteadyClock

Definition at line 54 of file time-custom-clock.hpp.

◆ UnitTestSystemClock

◆ UnitTestSteadyClock

◆ base_steady_clock

typedef boost::chrono::steady_clock ndn::time::base_steady_clock

Definition at line 76 of file time.cpp.

◆ days

using ndn::time::days = typedef duration<int_fast32_t, boost::ratio<86400> >

Definition at line 36 of file time.hpp.

Function Documentation

◆ setCustomClocks()

void ndn::time::setCustomClocks ( shared_ptr< CustomSteadyClock steadyClock = nullptr,
shared_ptr< CustomSystemClock systemClock = nullptr 
)

Set custom system and steady clocks.

When steadyClock or systemClock set to nullptr, the default implementation of the corresponding clock will be used

Definition at line 36 of file time.cpp.

References g_steadyClock, g_systemClock, and nonstd::optional_lite::std11::move().

Referenced by ns3::ndn::StackHelper::setCustomNdnCxxClocks().

◆ getUnixEpoch()

const system_clock::TimePoint & ndn::time::getUnixEpoch ( )

Get system_clock::TimePoint representing UNIX time epoch (00:00:00 on Jan 1, 1970)

Definition at line 106 of file time.cpp.

Referenced by convertToPosixTime(), ndn::name::Component::fromTimestamp(), fromUnixTimestamp(), ndn::name::Component::toTimestamp(), and toUnixTimestamp().

◆ toUnixTimestamp()

milliseconds ndn::time::toUnixTimestamp ( const system_clock::TimePoint point)

◆ fromUnixTimestamp()

system_clock::TimePoint ndn::time::fromUnixTimestamp ( milliseconds  duration)

Convert UNIX timestamp to system_clock::TimePoint.

Definition at line 119 of file time.cpp.

References getUnixEpoch().

Referenced by ndn::nfd::ForwarderStatus::wireDecode().

◆ convertToPosixTime()

static boost::posix_time::ptime ndn::time::convertToPosixTime ( const system_clock::TimePoint timePoint)
static

Definition at line 125 of file time.cpp.

References getUnixEpoch().

Referenced by toIsoString(), and toString().

◆ toIsoString()

std::string ndn::time::toIsoString ( const system_clock::TimePoint timePoint)

Convert to the ISO string representation of the time (YYYYMMDDTHHMMSS,fffffffff)

If timePoint contains doesn't contain fractional seconds, the output format is YYYYMMDDTHHMMSS

Examples:

  • with fractional nanoseconds: 20020131T100001,123456789
  • with fractional microseconds: 20020131T100001,123456
  • with fractional milliseconds: 20020131T100001,123
  • without fractional seconds: 20020131T100001

Definition at line 145 of file time.cpp.

References convertToPosixTime().

Referenced by ndn::security::v2::CertificateCache::insert(), ndn::security::v2::operator<<(), ndn::security::operator<<(), and ndn::security::ValidityPeriod::wireEncode().

◆ convertToTimePoint()

static system_clock::TimePoint ndn::time::convertToTimePoint ( const boost::posix_time::ptime &  ptime)
static

Definition at line 151 of file time.cpp.

Referenced by fromIsoString(), and fromString().

◆ fromIsoString()

system_clock::TimePoint ndn::time::fromIsoString ( const std::string &  isoString)

Convert from the ISO string (YYYYMMDDTHHMMSS,fffffffff) representation to the internal time format.

Examples of accepted ISO strings:

  • with fractional nanoseconds: 20020131T100001,123456789
  • with fractional microseconds: 20020131T100001,123456
  • with fractional milliseconds: 20020131T100001,123
  • without fractional seconds: 20020131T100001

Definition at line 164 of file time.cpp.

References convertToTimePoint().

Referenced by ndn::security::ValidityPeriod::wireDecode().

◆ toString()

std::string ndn::time::toString ( const system_clock::TimePoint timePoint,
const std::string &  format = "%Y-%m-%d %H:%M:%S",
const std::locale &  locale = std::locale("C") 
)

Convert time point to string with specified format.

By default, Y-m-d H:M:S is used, producing dates like 2014-04-10 22:51:00

Parameters
timePointtime point of system_clock
formatdesired output format (default: Y-m-d H:M:S)
localedesired locale (default: "C" locale)
See also
https://www.boost.org/doc/libs/1_58_0/doc/html/date_time/date_time_io.html#date_time.format_flags describes possible formatting flags

Definition at line 170 of file time.cpp.

References convertToPosixTime().

◆ fromString()

system_clock::TimePoint ndn::time::fromString ( const std::string &  timePointStr,
const std::string &  format = "%Y-%m-%d %H:%M:%S",
const std::locale &  locale = std::locale("C") 
)

Convert from string of specified format into time point.

By default, Y-m-d H:M:S is used, accepting dates like 2014-04-10 22:51:00

Parameters
timePointStrstring representing time point
formatinput output format (default: Y-m-d H:M:S)
localeinput locale (default: "C" locale)
See also
https://www.boost.org/doc/libs/1_58_0/doc/html/date_time/date_time_io.html#date_time.format_flags describes possible formatting flags

Definition at line 185 of file time.cpp.

References convertToTimePoint().

◆ abs()

template<typename Rep , typename Period , typename = std::enable_if_t<std::numeric_limits<Rep>::is_signed>>
constexpr duration<Rep, Period> ndn::time::abs ( duration< Rep, Period >  d)
constexpr
Returns
the absolute value of the duration d
Note
The function does not participate in the overload resolution unless std::numeric_limits<Rep>::is_signed is true.

Definition at line 50 of file time.hpp.

Referenced by ndn::util::RttEstimator::addMeasurement(), and ns3::AnnotatedTopologyReader::Read().

Variable Documentation

◆ g_systemClock

shared_ptr<CustomSystemClock> ndn::time::g_systemClock
static

◆ g_steadyClock

shared_ptr<CustomSteadyClock> ndn::time::g_steadyClock
static