all: Refactoring work with time using boost::chrono

Now the library has two clocks: time::steady_clock and
time::system_clock, following (boost|std)::chrono.  In addition to
standard now() method, the library contains several helpers to convert
to/from UnixTimestamp (microsecond resolution) and IsoString (optional
microsecond resolution).  The IsoString conversions use
boost::posix_time routines, since boost::chrono supports extended IO
support only starting boost version 1.52 (Boost Chrono V2).

This commit breaks compatibility with previous API.  All time-related
Data/Interest calls must explicitly use time units to specify
FreshnessPeriod/InterestLifetime.

Brief usage/conversion guide:

- creation of time units does not support double/float types.  If
  necessary to create time unit from double, ``ndn::duration<double>`` (for
  seconds) needs to be used instead.  In some cases, this would also
  require ``ndn::duration_cast``, if the target is not ``ndn::nanoseconds``.
- ndn::getNow, ndn::ndn_getNowMilliseconds, ndn::time::now are all
  removed in favor of the now() method in a specific clock:

    * time::system_clock::now();
    * time::steady_clock::now();

- When necessary to convert system_clock::TimePoint to unix timestamp,
  ``time::toUnixTimestamp`` can be used.  This method return number of
  milliseconds since UNIX epoch as ``ndn::time::milliseconds`` type.
  Use count() method to obtain number as an integral value.

Change-Id: Icd688bc6766e008d60c3d2888173627874526e47
Refs: #1152
diff --git a/src/management/ndnd-controller.cpp b/src/management/ndnd-controller.cpp
index b3b7821..1d3fb60 100644
--- a/src/management/ndnd-controller.cpp
+++ b/src/management/ndnd-controller.cpp
@@ -139,7 +139,7 @@
 
   Interest interest(interestName);
   interest.setScope(1);
-  interest.setInterestLifetime(1000);
+  interest.setInterestLifetime(time::seconds(1));
   interest.setMustBeFresh(true);
 
   m_face.expressInterest(interest,
@@ -172,7 +172,7 @@
 
   Interest interest(interestName);
   interest.setScope(1);
-  interest.setInterestLifetime(1000);
+  interest.setInterestLifetime(time::seconds(1));
   interest.setMustBeFresh(true);
 
   m_face.expressInterest(interest,
diff --git a/src/management/ndnd-face-instance.hpp b/src/management/ndnd-face-instance.hpp
index 1da6b94..60c07dc 100644
--- a/src/management/ndnd-face-instance.hpp
+++ b/src/management/ndnd-face-instance.hpp
@@ -18,7 +18,7 @@
  * An FaceInstance holds an action and  Name prefix and other fields for an forwarding entry.
  */
 class FaceInstance {
-public:    
+public:
   FaceInstance(const std::string &action,
                int64_t     faceId,
                uint32_t    ipProto,
@@ -26,7 +26,7 @@
                const std::string &port,
                const std::string &multicastInterface,
                uint32_t    multicastTtl,
-               Milliseconds freshnessPeriod) 
+               const time::milliseconds& freshnessPeriod)
     : action_(action)
     , faceId_(faceId)
     , ipProto_(ipProto)
@@ -42,73 +42,79 @@
     : faceId_(-1)
     , ipProto_(-1)
     , multicastTtl_(-1)
-    , freshnessPeriod_(-1)
+    , freshnessPeriod_(time::milliseconds::min())
   {
   }
 
   // Action
-  const std::string& 
+  const std::string&
   getAction() const { return action_; }
 
-  void 
+  void
   setAction(const std::string& action) { action_ = action; wire_.reset(); }
 
   // FaceID
   int64_t
   getFaceId() const { return faceId_; }
 
-  void 
+  void
   setFaceId(int64_t faceId) { faceId_ = faceId; wire_.reset(); }
 
   // IPProto
-  int32_t 
+  int32_t
   getIpProto() const { return ipProto_; }
 
-  void 
+  void
   setIpProto(int32_t ipProto) { ipProto_ = ipProto; wire_.reset(); }
 
   // Host
-  const std::string& 
+  const std::string&
   getHost() const { return host_; }
 
-  void 
+  void
   setHost(const std::string& host) { host_ = host; wire_.reset(); }
 
   // Port
   const std::string&
   getPort() const { return port_; }
 
-  void 
+  void
   setPort(const std::string &port) { port_ = port; wire_.reset(); }
 
   // MulticastInterface
-  const std::string& 
+  const std::string&
   getMulticastInterface() const { return multicastInterface_; }
 
-  void 
-  setMulticastInterface(const std::string& multicastInterface) { multicastInterface_ = multicastInterface; wire_.reset(); }
+  void
+  setMulticastInterface(const std::string& multicastInterface)
+  {
+    multicastInterface_ = multicastInterface; wire_.reset();
+  }
 
   // MulticastTTL
   int32_t
   getMulticastTtl() const { return multicastTtl_; }
 
-  void 
+  void
   setMulticastTtl(int32_t multicastTtl) { multicastTtl_ = multicastTtl; wire_.reset(); }
 
   // Freshness
-  int 
+  const time::milliseconds&
   getFreshnessPeriod() const { return freshnessPeriod_; }
 
-  void 
-  setFreshnessPeriod(int freshnessPeriod) { freshnessPeriod_ = freshnessPeriod; wire_.reset(); }
+  void
+  setFreshnessPeriod(const time::milliseconds& freshnessPeriod)
+  {
+    freshnessPeriod_ = freshnessPeriod; wire_.reset();
+  }
 
   // Wire
   inline const Block&
   wireEncode() const;
-  
-  inline void 
+
+  inline void
   wireDecode(const Block &wire);
-  
+
 private:
   std::string action_;
   int64_t     faceId_;
@@ -117,8 +123,8 @@
   std::string port_;
   std::string multicastInterface_;
   int32_t     multicastTtl_;
-  Milliseconds freshnessPeriod_;
-  
+  time::milliseconds freshnessPeriod_;
+
   mutable Block wire_;
 };
 
@@ -137,7 +143,7 @@
   //                  MulticastInterface?
   //                  MulticastTTL?
   //                  FreshnessPeriod?
-  
+
   wire_ = Block(tlv::ndnd::FaceInstance);
 
   // Action
@@ -160,7 +166,7 @@
       wire_.push_back
         (nonNegativeIntegerBlock(tlv::ndnd::IPProto, ipProto_));
     }
-  
+
   // Host
   if (!host_.empty())
     {
@@ -190,17 +196,17 @@
     }
 
   // FreshnessPeriod
-  if (freshnessPeriod_ >= 0)
+  if (freshnessPeriod_ >= time::milliseconds::zero())
     {
       wire_.push_back
-        (nonNegativeIntegerBlock(Tlv::FreshnessPeriod, freshnessPeriod_));
+        (nonNegativeIntegerBlock(Tlv::FreshnessPeriod, freshnessPeriod_.count()));
     }
-  
+
   wire_.encode();
-  return wire_;    
+  return wire_;
 }
-  
-inline void 
+
+inline void
 FaceInstance::wireDecode(const Block &wire)
 {
   action_.clear();
@@ -210,7 +216,7 @@
   port_.clear();
   multicastInterface_.clear();
   multicastTtl_ = -1;
-  freshnessPeriod_ = -1;
+  freshnessPeriod_ = time::milliseconds::min();
 
   wire_ = wire;
   wire_.parse();
@@ -278,7 +284,7 @@
   val = wire_.find(Tlv::FreshnessPeriod);
   if (val != wire_.elements_end())
     {
-      freshnessPeriod_ = readNonNegativeInteger(*val);
+      freshnessPeriod_ = time::milliseconds(readNonNegativeInteger(*val));
     }
 }
 
@@ -286,7 +292,7 @@
 operator << (std::ostream &os, const FaceInstance &entry)
 {
   os << "FaceInstance(";
-  
+
   // Action
   if (!entry.getAction().empty())
     {
@@ -330,7 +336,7 @@
     }
 
   // FreshnessPeriod
-  if (entry.getFreshnessPeriod() >= 0)
+  if (entry.getFreshnessPeriod() >= time::milliseconds::zero())
     {
       os << "FreshnessPeriod:" << entry.getFreshnessPeriod() << ", ";
     }
@@ -343,4 +349,3 @@
 } // namespace ndn
 
 #endif // NDN_MANAGEMENT_NDND_FACE_INSTANCE_HPP
-
diff --git a/src/management/ndnd-forwarding-entry.hpp b/src/management/ndnd-forwarding-entry.hpp
index 3d262f1..03272b1 100644
--- a/src/management/ndnd-forwarding-entry.hpp
+++ b/src/management/ndnd-forwarding-entry.hpp
@@ -20,12 +20,12 @@
  * An ForwardingEntry holds an action and  Name prefix and other fields for an forwarding entry.
  */
 class ForwardingEntry {
-public:    
+public:
   ForwardingEntry(const std::string& action,
                   const Name& prefix,
                   int faceId = -1,
                   const ForwardingFlags& forwardingFlags = ForwardingFlags(),
-                  int freshnessPeriod = -1) 
+                  time::milliseconds freshnessPeriod = time::milliseconds::min())
     : action_(action)
     , prefix_(prefix)
     , faceId_(faceId)
@@ -36,52 +36,52 @@
 
   ForwardingEntry()
   : faceId_(-1)
-  , freshnessPeriod_(-1)
+  , freshnessPeriod_(time::milliseconds::min())
   {
   }
-  
-  const std::string& 
+
+  const std::string&
   getAction() const { return action_; }
 
-  void 
+  void
   setAction(const std::string& action) { action_ = action; wire_.reset(); }
-    
-  const Name& 
+
+  const Name&
   getPrefix() const { return prefix_; }
-  
+
   void
   setPrefix(const Name &prefix) { prefix_ = prefix; wire_.reset(); }
-  
-  int 
+
+  int
   getFaceId() const { return faceId_; }
 
-  void 
+  void
   setFaceId(int faceId) { faceId_ = faceId; wire_.reset(); }
-      
-  const ForwardingFlags& 
+
+  const ForwardingFlags&
   getForwardingFlags() const { return forwardingFlags_; }
 
-  void 
+  void
   setForwardingFlags(const ForwardingFlags& forwardingFlags) { forwardingFlags_ = forwardingFlags; wire_.reset(); }
-      
-  int 
+
+  const time::milliseconds&
   getFreshnessPeriod() const { return freshnessPeriod_; }
 
-  void 
-  setFreshnessPeriod(int freshnessPeriod) { freshnessPeriod_ = freshnessPeriod; wire_.reset(); }
+  void
+  setFreshnessPeriod(const time::milliseconds& freshnessPeriod) { freshnessPeriod_ = freshnessPeriod; wire_.reset(); }
 
   inline const Block&
   wireEncode() const;
-  
-  inline void 
+
+  inline void
   wireDecode(const Block &wire);
-  
+
 private:
   std::string action_;   /**< empty for none. */
   Name prefix_;
   int faceId_;           /**< -1 for none. */
   ForwardingFlags forwardingFlags_;
-  int freshnessPeriod_; /**< -1 for none. */
+  time::milliseconds freshnessPeriod_; /**< time::milliseconds::min() for none. */
 
   mutable Block wire_;
 };
@@ -98,7 +98,7 @@
   //                       FaceID?
   //                       ForwardingFlags?
   //                       FreshnessPeriod?
-  
+
   wire_ = Block(tlv::ndnd::ForwardingEntry);
 
   // Action
@@ -124,24 +124,24 @@
     (forwardingFlags_.wireEncode());
 
   // FreshnessPeriod
-  if (freshnessPeriod_ >= 0)
+  if (freshnessPeriod_ >= time::milliseconds::zero())
     {
       wire_.push_back
-        (nonNegativeIntegerBlock(Tlv::FreshnessPeriod, freshnessPeriod_));
+        (nonNegativeIntegerBlock(Tlv::FreshnessPeriod, freshnessPeriod_.count()));
     }
-  
+
   wire_.encode();
-  return wire_;    
+  return wire_;
 }
-  
-inline void 
+
+inline void
 ForwardingEntry::wireDecode(const Block &wire)
 {
   action_.clear();
   prefix_.clear();
   faceId_ = -1;
   forwardingFlags_ = ForwardingFlags();
-  freshnessPeriod_ = -1;
+  freshnessPeriod_ = time::milliseconds::min();
 
   wire_ = wire;
   wire_.parse();
@@ -185,7 +185,7 @@
   val = wire_.find(Tlv::FreshnessPeriod);
   if (val != wire_.elements_end())
     {
-      freshnessPeriod_ = readNonNegativeInteger(*val);
+      freshnessPeriod_ = time::milliseconds(readNonNegativeInteger(*val));
     }
 }
 
@@ -193,7 +193,7 @@
 operator << (std::ostream &os, const ForwardingEntry &entry)
 {
   os << "ForwardingEntry(";
-  
+
   // Action
   if (!entry.getAction().empty())
     {
@@ -213,7 +213,7 @@
   os << "ForwardingFlags:" << entry.getForwardingFlags() << ", ";
 
   // FreshnessPeriod
-  if (entry.getFreshnessPeriod() >= 0)
+  if (entry.getFreshnessPeriod() >= time::milliseconds::zero())
     {
       os << "FreshnessPeriod:" << entry.getFreshnessPeriod() << ", ";
     }
diff --git a/src/management/nfd-status.hpp b/src/management/nfd-status.hpp
index fa7f884..e00c705 100644
--- a/src/management/nfd-status.hpp
+++ b/src/management/nfd-status.hpp
@@ -44,8 +44,6 @@
   wireDecode(const Block& payload);
 
 public:
-  typedef boost::chrono::time_point<boost::chrono::system_clock, boost::chrono::seconds> Timestamp;
-
   int
   getNfdVersion() const
   {
@@ -58,26 +56,26 @@
     m_nfdVersion = nfdVersion;
   }
 
-  Timestamp
+  const time::system_clock::TimePoint&
   getStartTimestamp() const
   {
     return m_startTimestamp;
   }
 
   void
-  setStartTimestamp(Timestamp startTimestamp)
+  setStartTimestamp(const time::system_clock::TimePoint& startTimestamp)
   {
     m_startTimestamp = startTimestamp;
   }
 
-  Timestamp
+  const time::system_clock::TimePoint&
   getCurrentTimestamp() const
   {
     return m_currentTimestamp;
   }
 
   void
-  setCurrentTimestamp(Timestamp currentTimestamp)
+  setCurrentTimestamp(const time::system_clock::TimePoint& currentTimestamp)
   {
     m_currentTimestamp = currentTimestamp;
   }
@@ -192,8 +190,8 @@
 
 private:
   int       m_nfdVersion;
-  Timestamp m_startTimestamp;
-  Timestamp m_currentTimestamp;
+  time::system_clock::TimePoint m_startTimestamp;
+  time::system_clock::TimePoint m_currentTimestamp;
   size_t    m_nNameTreeEntries;
   size_t    m_nFibEntries;
   size_t    m_nPitEntries;
@@ -205,24 +203,22 @@
   int       m_nOutDatas;
 };
 
-BOOST_STATIC_ASSERT((boost::is_same<Status::Timestamp::period, boost::ratio<1> >::value));
-
 inline
 Status::Status()
-{
-  m_nfdVersion = 0;
-  m_startTimestamp = Timestamp::min();
-  m_currentTimestamp = Timestamp::min();
-  m_nNameTreeEntries = 0;
-  m_nFibEntries = 0;
-  m_nPitEntries = 0;
-  m_nMeasurementsEntries = 0;
-  m_nCsEntries = 0;
-  m_nInInterests = 0;
-  m_nOutInterests = 0;
-  m_nInDatas = 0;
-  m_nOutDatas = 0;
-}
+  : m_nfdVersion(0)
+  , m_startTimestamp(time::system_clock::TimePoint::min())
+  , m_currentTimestamp(time::system_clock::TimePoint::min())
+  , m_nNameTreeEntries(0)
+  , m_nFibEntries(0)
+  , m_nPitEntries(0)
+  , m_nMeasurementsEntries(0)
+  , m_nCsEntries(0)
+  , m_nInInterests(0)
+  , m_nOutInterests(0)
+  , m_nInDatas(0)
+  , m_nOutDatas(0)
+  {
+  }
 
 template<bool T>
 inline size_t
@@ -249,9 +245,9 @@
   total_len += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NNameTreeEntries,
                                               m_nNameTreeEntries);
   total_len += prependNonNegativeIntegerBlock(encoder, tlv::nfd::CurrentTimestamp,
-               m_currentTimestamp.time_since_epoch().count());
+                                              time::toUnixTimestamp(m_currentTimestamp).count());
   total_len += prependNonNegativeIntegerBlock(encoder, tlv::nfd::StartTimestamp,
-               m_startTimestamp.time_since_epoch().count());
+                                              time::toUnixTimestamp(m_startTimestamp).count());
   total_len += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NfdVersion,
                                               m_nfdVersion);
 
@@ -262,8 +258,8 @@
 Status::wireDecode(const Block& payload)
 {
   m_nfdVersion = 0;
-  m_startTimestamp = Timestamp::min();
-  m_currentTimestamp = Timestamp::min();
+  m_startTimestamp = time::system_clock::TimePoint::min();
+  m_currentTimestamp = time::system_clock::TimePoint::min();
   m_nNameTreeEntries = 0;
   m_nFibEntries = 0;
   m_nPitEntries = 0;
@@ -288,12 +284,12 @@
 
   val = payload.find(tlv::nfd::StartTimestamp);
   if (val != payload.elements_end()) {
-    m_startTimestamp = Timestamp(boost::chrono::seconds(readNonNegativeInteger(*val)));
+    m_startTimestamp = time::fromUnixTimestamp(time::milliseconds(readNonNegativeInteger(*val)));
   }
 
   val = payload.find(tlv::nfd::CurrentTimestamp);
   if (val != payload.elements_end()) {
-    m_currentTimestamp = Timestamp(boost::chrono::seconds(readNonNegativeInteger(*val)));
+    m_currentTimestamp = time::fromUnixTimestamp(time::milliseconds(readNonNegativeInteger(*val)));
   }
 
   val = payload.find(tlv::nfd::NNameTreeEntries);
diff --git a/src/management/nrd-prefix-reg-options.hpp b/src/management/nrd-prefix-reg-options.hpp
index 412194b..c80d04b 100644
--- a/src/management/nrd-prefix-reg-options.hpp
+++ b/src/management/nrd-prefix-reg-options.hpp
@@ -26,13 +26,13 @@
  */
 class PrefixRegOptions {
 public:
-  struct Error : public Tlv::Error { Error(const std::string &what) : Tlv::Error(what) {} };
+  struct Error : public Tlv::Error { Error(const std::string& what) : Tlv::Error(what) {} };
 
   PrefixRegOptions()
-    : m_faceId (INVALID_FACE_ID)
-    , m_flags (DEFAULT_FLAGS)
-    , m_cost (DEFAULT_COST)
-    , m_expirationPeriod (-1)
+    : m_faceId(INVALID_FACE_ID)
+    , m_flags(DEFAULT_FLAGS)
+    , m_cost(DEFAULT_COST)
+    , m_expirationPeriod(time::milliseconds::min())
   {
   }
 
@@ -117,14 +117,14 @@
 
   //
 
-  Milliseconds
+  const time::milliseconds&
   getExpirationPeriod() const
   {
     return m_expirationPeriod;
   }
 
   PrefixRegOptions&
-  setExpirationPeriod(Milliseconds expirationPeriod)
+  setExpirationPeriod(const time::milliseconds& expirationPeriod)
   {
     m_expirationPeriod = expirationPeriod;
     m_wire.reset();
@@ -152,7 +152,7 @@
   uint64_t m_faceId;
   uint64_t m_flags;
   uint64_t m_cost;
-  Milliseconds m_expirationPeriod;
+  time::milliseconds m_expirationPeriod;
   std::string m_protocol;
 
   mutable Block m_wire;
@@ -184,10 +184,11 @@
     }
 
   // ExpirationPeriod
-  if (m_expirationPeriod > 0)
+  if (m_expirationPeriod > time::milliseconds::zero())
     {
       total_len += prependNonNegativeIntegerBlock(block,
-                                                  tlv::nrd::ExpirationPeriod, m_expirationPeriod);
+                                                  tlv::nrd::ExpirationPeriod,
+                                                  m_expirationPeriod.count());
     }
 
   // Cost
@@ -247,7 +248,7 @@
   m_faceId = INVALID_FACE_ID;
   m_flags = DEFAULT_FLAGS;
   m_cost = DEFAULT_COST;
-  m_expirationPeriod = -1;
+  m_expirationPeriod = time::milliseconds::min();
   m_protocol.clear();
 
   m_wire = wire;
@@ -289,7 +290,7 @@
   val = m_wire.find(tlv::nrd::ExpirationPeriod);
   if (val != m_wire.elements_end())
     {
-      m_expirationPeriod = readNonNegativeInteger(*val);
+      m_expirationPeriod = time::milliseconds(readNonNegativeInteger(*val));
     }
 
   // Protocol