route: Refresh FIB entries independently of routing table calculation

refs: #2778

Change-Id: I3536faa9c097152bfb99ebc0270221ca359cba35
diff --git a/src/route/fib.hpp b/src/route/fib.hpp
index 3dea4a3..32eba00 100644
--- a/src/route/fib.hpp
+++ b/src/route/fib.hpp
@@ -19,27 +19,27 @@
  * NLSR, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
  *
  **/
-#ifndef NLSR_FIB_HPP
-#define NLSR_FIB_HPP
 
-#include <map>
+#ifndef NLSR_ROUTE_FIB_HPP
+#define NLSR_ROUTE_FIB_HPP
 
-#include <boost/cstdint.hpp>
-
-#include <ndn-cxx/mgmt/nfd/controller.hpp>
-#include <ndn-cxx/util/time.hpp>
 #include "face-map.hpp"
 #include "fib-entry.hpp"
 #include "test-access-control.hpp"
 #include "utility/face-controller.hpp"
 
+#include <ndn-cxx/management/nfd-controller.hpp>
+#include <ndn-cxx/util/time.hpp>
+
 namespace nlsr {
 
 typedef ndn::nfd::Controller::CommandSucceedCallback CommandSucceedCallback;
 typedef ndn::nfd::Controller::CommandFailCallback CommandFailCallback;
+typedef std::function<void(FibEntry&)> afterRefreshCallback;
 
 class AdjacencyList;
 class ConfParameter;
+class FibEntry;
 
 class Fib
 {
@@ -47,27 +47,24 @@
   Fib(ndn::Face& face, ndn::Scheduler& scheduler, AdjacencyList& adjacencyList, ConfParameter& conf,
       ndn::KeyChain& keyChain)
     : m_scheduler(scheduler)
-    , m_table()
     , m_refreshTime(0)
     , m_controller(face, keyChain)
     , m_faceController(face.getIoService(), m_controller)
-    , m_faceMap()
     , m_adjacencyList(adjacencyList)
     , m_confParameter(conf)
   {
   }
 
-  ~Fib()
-  {
-  }
+  void
+  update(const ndn::Name& name, NexthopList& allHops);
+
+  FibEntry*
+  processUpdate(const ndn::Name& name, NexthopList& allHops);
 
   void
   remove(const ndn::Name& name);
 
   void
-  update(const ndn::Name& name, NexthopList& allHops);
-
-  void
   clean();
 
   void
@@ -76,36 +73,13 @@
     m_refreshTime = fert;
   }
 
-private:
-  bool
-  isPrefixUpdatable(const ndn::Name& name);
-
   void
-  addNextHopsToFibEntryAndNfd(FibEntry& entry, NexthopList& hopsToAdd);
-
-  void
-  removeOldNextHopsFromFibEntryAndNfd(FibEntry& entry, const NexthopList& installedHops);
-
-  void
-  removeHop(NexthopList& nl, const std::string& doNotRemoveHopFaceUri,
-            const ndn::Name& name);
-
-  unsigned int
-  getNumberOfFacesForName(NexthopList& nextHopList);
-
-  ndn::EventId
-  scheduleEntryExpiration(const ndn::Name& name, int32_t feSeqNum,
-                          const ndn::time::seconds& expTime);
-
-  void
-  cancelScheduledExpiringEvent(ndn::EventId eid);
-
-public:
-  void
-  registerPrefix(const ndn::Name& namePrefix, const std::string& faceUri,
+  registerPrefix(const ndn::Name& namePrefix,
+                 const std::string& faceUri,
                  uint64_t faceCost,
                  const ndn::time::milliseconds& timeout,
-                 uint64_t flags, uint8_t times);
+                 uint64_t flags,
+                 uint8_t times);
 
   void
   registerPrefix(const ndn::Name& namePrefix,
@@ -129,6 +103,18 @@
               const CommandFailCallback& onFailure);
 
 private:
+  bool
+  isPrefixUpdatable(const ndn::Name& name);
+
+  void
+  addNextHopsToFibEntryAndNfd(FibEntry& entry, NexthopList& hopsToAdd);
+
+  void
+  removeOldNextHopsFromFibEntryAndNfd(FibEntry& entry, const NexthopList& installedHops);
+
+  unsigned int
+  getNumberOfFacesForName(NexthopList& nextHopList);
+
   void
   createFace(const std::string& faceUri,
              const CommandSucceedCallback& onSuccess,
@@ -155,12 +141,8 @@
   unregisterPrefix(const ndn::Name& namePrefix, const std::string& faceUri);
 
   void
-  onRegistration(const ndn::nfd::ControlParameters& commandSuccessResult,
-                 const std::string& message, const std::string& faceUri);
-
-  void
-  onUnregistration(const ndn::nfd::ControlParameters& commandSuccessResult,
-                   const std::string& message);
+  onRegistrationSuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
+                        const std::string& message, const std::string& faceUri);
 
   void
   onRegistrationFailure(const ndn::nfd::ControlResponse& response,
@@ -170,10 +152,14 @@
                         uint8_t times);
 
   void
-  onUnregistrationFailure(const ndn::nfd::ControlResponse& response,
+  onUnregistrationSuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
                           const std::string& message);
 
   void
+  onUnregistrationFailure(const ndn::nfd::ControlResponse& response,
+                               const std::string& message);
+
+  void
   onSetStrategySuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
                        const std::string& message);
 
@@ -183,15 +169,29 @@
                        uint32_t count,
                        const std::string& message);
 
+PUBLIC_WITH_TESTS_ELSE_PRIVATE:
+  void
+  scheduleEntryRefresh(FibEntry& entry, const afterRefreshCallback& refreshCb);
+
+private:
+  void
+  scheduleLoop(FibEntry& entry);
+
+  void
+  cancelEntryRefresh(const FibEntry& entry);
+
+  void
+  refreshEntry(const ndn::Name& name, afterRefreshCallback refreshCb);
+
 private:
   ndn::Scheduler& m_scheduler;
-  std::map<ndn::Name, FibEntry> m_table;
   int32_t m_refreshTime;
   ndn::nfd::Controller m_controller;
   util::FaceController m_faceController;
 
 PUBLIC_WITH_TESTS_ELSE_PRIVATE:
   FaceMap m_faceMap;
+  std::map<ndn::Name, FibEntry> m_table;
 
 private:
   AdjacencyList& m_adjacencyList;
@@ -201,4 +201,5 @@
 };
 
 } // namespace nlsr
-#endif //NLSR_FIB_HPP
+
+#endif // NLSR_ROUTE_FIB_HPP