daemon: Fix hop count of data packet received from content store

Change-Id: I3b863344ec040bc61c8100843e13fce814766b1f
Refs: #2764
diff --git a/NFD/daemon/fw/forwarder.cpp b/NFD/daemon/fw/forwarder.cpp
index 85d7b6c..8b8b11f 100644
--- a/NFD/daemon/fw/forwarder.cpp
+++ b/NFD/daemon/fw/forwarder.cpp
@@ -29,6 +29,8 @@
 #include "face/null-face.hpp"
 #include "available-strategies.hpp"
 
+#include "utils/ndn-ns3-packet-tag.hpp"
+
 #include <boost/random/uniform_int_distribution.hpp>
 
 namespace nfd {
@@ -283,11 +285,20 @@
     return;
   }
 
+  // Remove Ptr<Packet> from the Data before inserting into cache, serving two purposes
+  // - reduce amount of memory used by cached entries
+  // - remove all tags that (e.g., hop count tag) that could have been associated with Ptr<Packet>
+  //
+  // Copying of Data is relatively cheap operation, as it copies (mostly) a collection of Blocks
+  // pointing to the same underlying memory buffer.
+  shared_ptr<Data> dataCopyWithoutPacket = make_shared<Data>(data);
+  dataCopyWithoutPacket->removeTag<ns3::ndn::Ns3PacketTag>();
+
   // CS insert
   if (m_csFromNdnSim == nullptr)
-    m_cs.insert(data);
+    m_cs.insert(*dataCopyWithoutPacket);
   else
-    m_csFromNdnSim->Add(data.shared_from_this());
+    m_csFromNdnSim->Add(dataCopyWithoutPacket);
 
   std::set<shared_ptr<Face> > pendingDownstreams;
   // foreach PitEntry