NFD: Keep both the CS of NFD and ndnSIM

Ref: #2231
diff --git a/model/cs/custom-policies/freshness-policy.hpp b/model/cs/custom-policies/freshness-policy.hpp
index ae10862..663ec5b 100644
--- a/model/cs/custom-policies/freshness-policy.hpp
+++ b/model/cs/custom-policies/freshness-policy.hpp
@@ -104,15 +104,14 @@
       inline bool
       insert(typename parent_trie::iterator item)
       {
-        // get_time (item) = Simulator::Now ();
-        Time freshness = MilliSeconds(item->payload()->GetData()->getFreshnessPeriod().count());
-        if (!freshness.IsZero()) {
-          get_freshness(item) = Simulator::Now() + freshness;
+        time::milliseconds freshness = item->payload()->GetData()->getFreshnessPeriod();
+        if (freshness > time::milliseconds::zero()) {
+          get_freshness(item) = Simulator::Now() + MilliSeconds(freshness.count());
 
-          // push item only if freshness is non zero. otherwise, this payload is not controlled by
-          // the policy
-          // note that .size() on this policy would return only number of items with non-infinite
-          // freshness policy
+          // push item only if freshness is non zero. otherwise, this payload is not
+          // controlled by the policy.
+          // Note that .size() on this policy would return only the number of items with
+          // non-infinite freshness policy
           policy_container::insert(*item);
         }
 
@@ -128,8 +127,9 @@
       inline void
       erase(typename parent_trie::iterator item)
       {
-        if (item->payload()->GetData()->getFreshnessPeriod() != time::milliseconds::zero()) {
-          // erase only if freshness is non zero (otherwise an item is not in the policy
+        time::milliseconds freshness = item->payload()->GetData()->getFreshnessPeriod();
+        if (freshness > time::milliseconds::zero()) {
+          // erase only if freshness is positive (otherwise an item is not in the policy)
           policy_container::erase(policy_container::s_iterator_to(*item));
         }
       }
diff --git a/model/ndn-l3-protocol.cpp b/model/ndn-l3-protocol.cpp
index f383477..7412e2c 100644
--- a/model/ndn-l3-protocol.cpp
+++ b/model/ndn-l3-protocol.cpp
@@ -36,6 +36,7 @@
 
 #include "ndn-net-device-face.hpp"
 #include "../helper/ndn-stack-helper.hpp"
+#include "cs/ndn-content-store.hpp"
 
 #include <boost/foreach.hpp>
 
@@ -93,6 +94,8 @@
   shared_ptr<nfd::FaceManager> m_faceManager;
   shared_ptr<nfd::StrategyChoiceManager> m_strategyChoiceManager;
   shared_ptr<nfd::StatusServer> m_statusServer;
+
+  Ptr<ContentStore> m_csFromNdnSim;
 };
 
 L3Protocol::L3Protocol()
@@ -107,11 +110,11 @@
 }
 
 void
-L3Protocol::initialize()
+L3Protocol::initialize(bool shouldUseNfdCs)
 {
   m_impl->m_forwarder = make_shared<nfd::Forwarder>();
 
-  initializeManagement();
+  initializeManagement(shouldUseNfdCs);
 
   m_impl->m_forwarder->getFaceTable().addReserved(make_shared<nfd::NullFace>(), nfd::FACEID_NULL);
   m_impl->m_forwarder->getFaceTable().addReserved(make_shared<nfd::NullFace>(
@@ -120,7 +123,7 @@
 }
 
 void
-L3Protocol::initializeManagement()
+L3Protocol::initializeManagement(bool shouldUseNfdCs)
 {
   m_impl->m_internalFace = make_shared<nfd::InternalFace>();
 
@@ -185,6 +188,11 @@
   if (m_node == nullptr) {
     m_node = GetObject<Node>();
     if (m_node != nullptr) {
+      NS_ASSERT(m_impl->m_forwarder != nullptr);
+      m_impl->m_csFromNdnSim = GetObject<ContentStore>();
+      if (m_impl->m_csFromNdnSim != nullptr) {
+        m_impl->m_forwarder->setCsFromNdnSim(m_impl->m_csFromNdnSim);
+      }
     }
   }
 
diff --git a/model/ndn-l3-protocol.hpp b/model/ndn-l3-protocol.hpp
index 63e4ff2..9ec320f 100644
--- a/model/ndn-l3-protocol.hpp
+++ b/model/ndn-l3-protocol.hpp
@@ -91,7 +91,7 @@
    * \brief Initialize NFD instance
    */
   void
-  initialize();
+  initialize(bool shouldUseNfdCs);
 
   /**
    * \brief Get smart pointer to nfd::Forwarder installed on the node
@@ -158,7 +158,7 @@
 
 private:
   void
-  initializeManagement();
+  initializeManagement(bool isNfd);
 
 private:
   class Impl;