helper+model: Create helper to select the replacement policy of NFD's CS

Change-Id: I10933b5c96fd95bc395a1d08642a1e07e826dc45
Refs: #3837
diff --git a/helper/ndn-stack-helper.cpp b/helper/ndn-stack-helper.cpp
index 3b5571a..4b9cd90 100644
--- a/helper/ndn-stack-helper.cpp
+++ b/helper/ndn-stack-helper.cpp
@@ -36,6 +36,9 @@
 #include <map>
 #include <boost/lexical_cast.hpp>
 
+#include "ns3/ndnSIM/NFD/daemon/table/cs-policy-priority-fifo.hpp"
+#include "ns3/ndnSIM/NFD/daemon/table/cs-policy-lru.hpp"
+
 NS_LOG_COMPONENT_DEFINE("ndn.StackHelper");
 
 namespace ns3 {
@@ -51,6 +54,11 @@
 {
   setCustomNdnCxxClocks();
 
+  m_csPolicies.insert({"nfd::cs::lru", [] { return make_unique<nfd::cs::LruPolicy>(); }});
+  m_csPolicies.insert({"nfd::cs::priority_fifo", [] () { return make_unique<nfd::cs::PriorityFifoPolicy>(); }});
+
+  m_csPolicyCreationFunc = m_csPolicies["nfd::cs::lru"];
+
   m_ndnFactory.SetTypeId("ns3::ndn::L3Protocol");
   m_contentStoreFactory.SetTypeId("ns3::ndn::cs::Lru");
 
@@ -127,6 +135,22 @@
   m_maxCsSize = maxSize;
 }
 
+void
+StackHelper::setPolicy(const std::string& policy)
+{
+  auto found = m_csPolicies.find(policy);
+  if (found != m_csPolicies.end()) {
+    m_csPolicyCreationFunc = found->second;
+  }
+  else {
+    NS_FATAL_ERROR("Cache replacement policy " << policy << " not found");
+    NS_LOG_DEBUG("Available cache replacement policies: ");
+    for (auto it = m_csPolicies.begin(); it != m_csPolicies.end(); it++) {
+      NS_LOG_DEBUG("    " << it->first);
+    }
+  }
+}
+
 Ptr<FaceContainer>
 StackHelper::Install(const NodeContainer& c) const
 {
@@ -178,6 +202,10 @@
   if (m_maxCsSize == 0) {
     ndn->AggregateObject(m_contentStoreFactory.Create<ContentStore>());
   }
+  // if NFD's CS is enabled, check if a replacement policy has been specified
+  else {
+    ndn->setCsReplacementPolicy(m_csPolicyCreationFunc);
+  }
 
   // Aggregate L3Protocol on node (must be after setting ndnSIM CS)
   node->AggregateObject(ndn);