src: Expiration time change for LSA and Fib entry

Changed lifetime of LSA and FIB Entry to ndn::time::system_clock::TimePoint
type expiration timepoint. And refreshing event is scheduled at that timepoint

Refs: #1594

Change-Id: Ib31fe7ca79e79174eb3a5a4956ed5334da093b1b
diff --git a/src/route/fib-entry.cpp b/src/route/fib-entry.cpp
index ba2731f..f35bae7 100644
--- a/src/route/fib-entry.cpp
+++ b/src/route/fib-entry.cpp
@@ -37,6 +37,7 @@
 FibEntry::writeLog()
 {
   _LOG_DEBUG("Name Prefix: " << m_name);
+  _LOG_DEBUG("Time to Refresh: " << m_expirationTimePoint);
   _LOG_DEBUG("Seq No: " << m_seqNo);
   m_nexthopList.writeLog();
 }
@@ -45,7 +46,7 @@
 operator<<(ostream& os, FibEntry fe)
 {
   os << "Name Prefix: " << fe.getName() << endl;
-  os << "Time to Refresh: " << fe.getTimeToRefresh() << endl;
+  os << "Time to Refresh: " << fe.getExpirationTimePoint() << endl;
   os << fe.getNexthopList() << endl;
   return os;
 }
diff --git a/src/route/fib-entry.hpp b/src/route/fib-entry.hpp
index 14d3772..35da960 100644
--- a/src/route/fib-entry.hpp
+++ b/src/route/fib-entry.hpp
@@ -6,6 +6,7 @@
 #include <boost/cstdint.hpp>
 
 #include <ndn-cxx/util/scheduler.hpp>
+#include <ndn-cxx/util/time.hpp>
 
 #include "nexthop.hpp"
 #include "nexthop-list.hpp"
@@ -17,14 +18,14 @@
 public:
   FibEntry()
     : m_name()
-    , m_timeToRefresh(0)
+    , m_expirationTimePoint()
     , m_seqNo(0)
     , m_nexthopList()
   {
   }
 
   FibEntry(const ndn::Name& name)
-    : m_timeToRefresh(0)
+    : m_expirationTimePoint()
     , m_seqNo(0)
     , m_nexthopList()
   {
@@ -43,16 +44,16 @@
     return m_nexthopList;
   }
 
-  int32_t
-  getTimeToRefresh() const
+  const ndn::time::system_clock::TimePoint&
+  getExpirationTimePoint() const
   {
-    return m_timeToRefresh;
+    return m_expirationTimePoint;
   }
 
   void
-  setTimeToRefresh(int32_t ttr)
+  setExpirationTimePoint(const ndn::time::system_clock::TimePoint& ttr)
   {
-    m_timeToRefresh = ttr;
+    m_expirationTimePoint = ttr;
   }
 
   void
@@ -87,7 +88,7 @@
 
 private:
   ndn::Name m_name;
-  int32_t m_timeToRefresh;
+  ndn::time::system_clock::TimePoint m_expirationTimePoint;
   ndn::EventId m_expiringEventId;
   int32_t m_seqNo;
   NexthopList m_nexthopList;
diff --git a/src/route/fib.cpp b/src/route/fib.cpp
index 17269dc..633eaa8 100644
--- a/src/route/fib.cpp
+++ b/src/route/fib.cpp
@@ -32,13 +32,13 @@
 
 ndn::EventId
 Fib::scheduleEntryRefreshing(const ndn::Name& name, int32_t feSeqNum,
-                             int32_t refreshTime)
+                             const ndn::time::seconds& expTime)
 {
   std::cout << "Fib::scheduleEntryRefreshing Called" << std::endl;
   std::cout << "Name: " << name << " Seq Num: " << feSeqNum << std::endl;
   _LOG_DEBUG("Fib::scheduleEntryRefreshing Called");
   _LOG_DEBUG("Name: " << name << " Seq Num: " << feSeqNum);
-  return m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(refreshTime),
+  return m_nlsr.getScheduler().scheduleEvent(expTime,
                                              ndn::bind(&Fib::refreshEntry, this,
                                                        name, feSeqNum));
 }
@@ -67,7 +67,7 @@
       it->setSeqNo(feSeqNum + 1);
       it->setExpiringEventId(scheduleEntryRefreshing(it->getName() ,
                                                      it->getSeqNo(),
-                                                     m_refreshTime));
+                                                     ndn::time::seconds(m_refreshTime)));
     }
   }
 }
@@ -128,9 +128,12 @@
                        std::ceil(nhit->getRouteCost()), m_refreshTime);
       }
       newEntry.getNexthopList().sort();
-      newEntry.setTimeToRefresh(m_refreshTime);
+      ndn::time::system_clock::TimePoint expirationTimePoint = ndn::time::system_clock::now();
+      expirationTimePoint = expirationTimePoint + ndn::time::seconds(m_refreshTime);
+      newEntry.setExpirationTimePoint(expirationTimePoint);
       newEntry.setSeqNo(1);
-      newEntry.setExpiringEventId(scheduleEntryRefreshing(name , 1, m_refreshTime));
+      newEntry.setExpiringEventId(scheduleEntryRefreshing(name , 1,
+                                                          ndn::time::seconds(m_refreshTime)));
       m_table.push_back(newEntry);
     }
   }
@@ -156,14 +159,17 @@
                          std::ceil(nhit->getRouteCost()), m_refreshTime);
         }
       }
-      it->setTimeToRefresh(m_refreshTime);
+      ndn::time::system_clock::TimePoint expirationTimePoint = ndn::time::system_clock::now();
+      expirationTimePoint = expirationTimePoint + ndn::time::seconds(m_refreshTime);
+      it->setExpirationTimePoint(expirationTimePoint);
       std::cout << "Cancellling Scheduled event" << std::endl;
       std::cout << "Name: " << name << "Seq num: " << it->getSeqNo() << std::endl;
       _LOG_DEBUG("Cancelling Scheduled event. Name: " << name);
       cancelScheduledExpiringEvent(it->getExpiringEventId());
       it->setSeqNo(it->getSeqNo() + 1);
       (*it).setExpiringEventId(scheduleEntryRefreshing(it->getName() ,
-                                                       it->getSeqNo(), m_refreshTime));
+                                                       it->getSeqNo(),
+                                                       ndn::time::seconds(m_refreshTime)));
     }
     else {
       remove(name);
diff --git a/src/route/fib.hpp b/src/route/fib.hpp
index d144e1f..02aa400 100644
--- a/src/route/fib.hpp
+++ b/src/route/fib.hpp
@@ -5,6 +5,7 @@
 #include <boost/cstdint.hpp>
 
 #include <ndn-cxx/management/nfd-controller.hpp>
+#include <ndn-cxx/util/time.hpp>
 #include "face-map.hpp"
 #include "fib-entry.hpp"
 
@@ -56,7 +57,7 @@
 
   ndn::EventId
   scheduleEntryRefreshing(const ndn::Name& name, int32_t feSeqNum,
-                          int32_t refreshTime);
+                          const ndn::time::seconds& expTime);
 
   void
   cancelScheduledExpiringEvent(ndn::EventId eid);