First step of refactoring code (ccnx prefix => ndn prefix)
diff --git a/helper/ndn-stack-helper.cc b/helper/ndn-stack-helper.cc
new file mode 100644
index 0000000..6b0a022
--- /dev/null
+++ b/helper/ndn-stack-helper.cc
@@ -0,0 +1,333 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 UCLA
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author:  Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ *          Ilya Moiseenko <iliamo@cs.ucla.edu> 
+ */
+
+#include "ns3/assert.h"
+#include "ns3/log.h"
+#include "ns3/object.h"
+#include "ns3/names.h"
+#include "ns3/packet-socket-factory.h"
+#include "ns3/config.h"
+#include "ns3/simulator.h"
+#include "ns3/string.h"
+#include "ns3/net-device.h"
+#include "ns3/callback.h"
+#include "ns3/node.h"
+#include "ns3/core-config.h"
+#include "ns3/point-to-point-net-device.h"
+#include "ns3/point-to-point-helper.h"
+
+#include "../model/ndn-net-device-face.h"
+#include "../model/ndn-l3-protocol.h"
+
+#include "ns3/ndn-forwarding-strategy.h"
+#include "ns3/ndn-fib.h"
+#include "ns3/ndn-pit.h"
+#include "ns3/ndn-name-components.h"
+#include "ns3/ndn-content-store.h"
+
+#include "ns3/node-list.h"
+// #include "ns3/loopback-net-device.h"
+
+#include "ns3/data-rate.h"
+
+#include "ndn-face-container.h"
+#include "ndn-stack-helper.h"
+
+#include <limits>
+#include <map>
+#include <boost/foreach.hpp>
+#include <boost/lexical_cast.hpp>
+
+NS_LOG_COMPONENT_DEFINE ("NdnStackHelper");
+
+namespace ns3 {
+    
+NdnStackHelper::NdnStackHelper ()
+  : m_limitsEnabled (false)
+  , m_needSetDefaultRoutes (false)
+{
+  m_ndnFactory.        SetTypeId ("ns3::NdnL3Protocol");
+  m_strategyFactory.    SetTypeId ("ns3::ndnSIM::Flooding");
+  m_contentStoreFactory.SetTypeId ("ns3::NdnContentStoreLru");
+  m_fibFactory.         SetTypeId ("ns3::NdnFib");
+  m_pitFactory.         SetTypeId ("ns3::NdnPit");
+}
+    
+NdnStackHelper::~NdnStackHelper ()
+{
+}
+
+void
+NdnStackHelper::SetNdnAttributes (const std::string &attr1, const std::string &value1,
+                                    const std::string &attr2, const std::string &value2,
+                                    const std::string &attr3, const std::string &value3,
+                                    const std::string &attr4, const std::string &value4)
+{
+  if (attr1 != "")
+      m_ndnFactory.Set (attr1, StringValue (value1));
+  if (attr2 != "")
+      m_ndnFactory.Set (attr2, StringValue (value2));
+  if (attr3 != "")
+      m_ndnFactory.Set (attr3, StringValue (value3));
+  if (attr4 != "")
+      m_ndnFactory.Set (attr4, StringValue (value4));
+}
+
+void 
+NdnStackHelper::SetForwardingStrategy (const std::string &strategy,
+                                        const std::string &attr1, const std::string &value1,
+                                        const std::string &attr2, const std::string &value2,
+                                        const std::string &attr3, const std::string &value3,
+                                        const std::string &attr4, const std::string &value4)
+{
+  m_strategyFactory.SetTypeId (strategy);
+  if (attr1 != "")
+      m_strategyFactory.Set (attr1, StringValue (value1));
+  if (attr2 != "")
+      m_strategyFactory.Set (attr2, StringValue (value2));
+  if (attr3 != "")
+      m_strategyFactory.Set (attr3, StringValue (value3));
+  if (attr4 != "")
+      m_strategyFactory.Set (attr4, StringValue (value4));
+}
+
+void
+NdnStackHelper::SetContentStore (const std::string &contentStore,
+                                  const std::string &attr1, const std::string &value1,
+                                  const std::string &attr2, const std::string &value2,
+                                  const std::string &attr3, const std::string &value3,
+                                  const std::string &attr4, const std::string &value4)
+{
+  m_contentStoreFactory.SetTypeId (contentStore);
+  if (attr1 != "")
+      m_contentStoreFactory.Set (attr1, StringValue (value1));
+  if (attr2 != "")
+      m_contentStoreFactory.Set (attr2, StringValue (value2));
+  if (attr3 != "")
+      m_contentStoreFactory.Set (attr3, StringValue (value3));
+  if (attr4 != "")
+      m_contentStoreFactory.Set (attr4, StringValue (value4));
+}
+
+void
+NdnStackHelper::SetPit (const std::string &pitClass,
+                         const std::string &attr1, const std::string &value1,
+                         const std::string &attr2, const std::string &value2,
+                         const std::string &attr3, const std::string &value3,
+                         const std::string &attr4, const std::string &value4)
+{
+  m_pitFactory.SetTypeId (pitClass);
+  if (attr1 != "")
+      m_pitFactory.Set (attr1, StringValue (value1));
+  if (attr2 != "")
+      m_pitFactory.Set (attr2, StringValue (value2));
+  if (attr3 != "")
+      m_pitFactory.Set (attr3, StringValue (value3));
+  if (attr4 != "")
+      m_pitFactory.Set (attr4, StringValue (value4));
+}
+
+void
+NdnStackHelper::SetFib (const std::string &fibClass,
+                         const std::string &attr1, const std::string &value1,
+                         const std::string &attr2, const std::string &value2,
+                         const std::string &attr3, const std::string &value3,
+                         const std::string &attr4, const std::string &value4)
+{
+  m_fibFactory.SetTypeId (fibClass);
+  if (attr1 != "")
+      m_fibFactory.Set (attr1, StringValue (value1));
+  if (attr2 != "")
+      m_fibFactory.Set (attr2, StringValue (value2));
+  if (attr3 != "")
+      m_fibFactory.Set (attr3, StringValue (value3));
+  if (attr4 != "")
+      m_fibFactory.Set (attr4, StringValue (value4));
+}
+
+void
+NdnStackHelper::SetDefaultRoutes (bool needSet)
+{
+  NS_LOG_FUNCTION (this << needSet);
+  m_needSetDefaultRoutes = needSet;
+}
+
+void
+NdnStackHelper::EnableLimits (bool enable/* = true*/,
+                               Time avgRtt/*=Seconds(0.1)*/,
+                               uint32_t avgContentObject/*=1100*/,
+                               uint32_t avgInterest/*=40*/)
+{
+  NS_LOG_INFO ("EnableLimits: " << enable);
+  m_limitsEnabled = enable;
+  m_avgRtt = avgRtt;
+  m_avgContentObjectSize = avgContentObject;
+  m_avgInterestSize = avgInterest;
+}
+
+Ptr<NdnFaceContainer>
+NdnStackHelper::Install (NodeContainer c) const
+{
+  Ptr<NdnFaceContainer> faces = Create<NdnFaceContainer> ();
+  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
+    {
+      faces->AddAll (Install (*i));
+    }
+  return faces;
+}
+
+Ptr<NdnFaceContainer>
+NdnStackHelper::InstallAll (void) const
+{
+  return Install (NodeContainer::GetGlobal ());
+}
+
+Ptr<NdnFaceContainer>
+NdnStackHelper::Install (Ptr<Node> node) const
+{
+  // NS_ASSERT_MSG (m_forwarding, "SetForwardingHelper() should be set prior calling Install() method");
+  Ptr<NdnFaceContainer> faces = Create<NdnFaceContainer> ();
+  
+  if (node->GetObject<Ndn> () != 0)
+    {
+      NS_FATAL_ERROR ("NdnStackHelper::Install (): Installing " 
+                      "a NdnStack to a node with an existing Ndn object");
+      return 0;
+    }
+
+  // Create NdnL3Protocol
+  Ptr<Ndn> ndn = m_ndnFactory.Create<Ndn> ();
+
+  // Create and aggregate FIB
+  Ptr<NdnFib> fib = m_fibFactory.Create<NdnFib> ();
+  ndn->AggregateObject (fib);
+
+  // Create and aggregate PIT
+  ndn->AggregateObject (m_pitFactory.Create<NdnPit> ());
+  
+  // Create and aggregate forwarding strategy
+  ndn->AggregateObject (m_strategyFactory.Create<NdnForwardingStrategy> ());
+
+  // Create and aggregate content store
+  ndn->AggregateObject (m_contentStoreFactory.Create<NdnContentStore> ());
+
+  // Aggregate NdnL3Protocol on node
+  node->AggregateObject (ndn);
+  
+  for (uint32_t index=0; index < node->GetNDevices (); index++)
+    {
+      Ptr<NetDevice> device = node->GetDevice (index);
+      // This check does not make sense: LoopbackNetDevice is installed only if IP stack is installed,
+      // Normally, ndnSIM works without IP stack, so no reason to check
+      // if (DynamicCast<LoopbackNetDevice> (device) != 0)
+      //   continue; // don't create face for a LoopbackNetDevice
+
+      Ptr<NdnNetDeviceFace> face = CreateObject<NdnNetDeviceFace> (node, device);
+
+      ndn->AddFace (face);
+      NS_LOG_LOGIC ("Node " << node->GetId () << ": added NdnNetDeviceFace as face #" << *face);
+
+      if (m_needSetDefaultRoutes)
+        {
+          // default route with lowest priority possible
+          AddRoute (node, "/", face, std::numeric_limits<int32_t>::max ()); 
+        }
+      
+      if (m_limitsEnabled)
+        {
+          NS_LOG_INFO ("Limits are enabled");
+          Ptr<PointToPointNetDevice> p2p = DynamicCast<PointToPointNetDevice> (device);
+          if (p2p != 0)
+            {
+              // Setup bucket filtering
+              // Assume that we know average data packet size, and this size is equal default size
+              // Set maximum buckets (averaging over 1 second)
+      
+              DataRateValue dataRate; device->GetAttribute ("DataRate", dataRate);
+          
+              NS_LOG_INFO("DataRate for this link is " << dataRate.Get());
+
+              double maxInterestPackets = 1.0  * dataRate.Get ().GetBitRate () / 8.0 / (m_avgContentObjectSize + m_avgInterestSize);
+              NS_LOG_INFO ("Max packets per second: " << maxInterestPackets);
+              NS_LOG_INFO ("Max burst: " << m_avgRtt.ToDouble (Time::S) * maxInterestPackets);
+
+              // Set bucket max to BDP
+              face->SetBucketMax (m_avgRtt.ToDouble (Time::S) * maxInterestPackets); // number of interests allowed
+              face->SetBucketLeak (maxInterestPackets);
+            }
+        }
+        
+      face->SetUp ();
+      faces->Add (face);
+    }
+    
+  return faces;
+}
+
+Ptr<NdnFaceContainer>
+NdnStackHelper::Install (std::string nodeName) const
+{
+  Ptr<Node> node = Names::Find<Node> (nodeName);
+  return Install (node);
+}
+
+
+void
+NdnStackHelper::AddRoute (Ptr<Node> node, std::string prefix, Ptr<NdnFace> face, int32_t metric)
+{
+  NS_LOG_LOGIC ("[" << node->GetId () << "]$ route add " << prefix << " via " << *face << " metric " << metric);
+
+  Ptr<NdnFib>  fib  = node->GetObject<NdnFib> ();
+
+  NdnNameComponentsValue prefixValue;
+  prefixValue.DeserializeFromString (prefix, MakeNdnNameComponentsChecker ());
+  fib->Add (prefixValue.Get (), face, metric);
+}
+
+void
+NdnStackHelper::AddRoute (Ptr<Node> node, std::string prefix, uint32_t faceId, int32_t metric)
+{
+  Ptr<Ndn>     ndn = node->GetObject<Ndn> ();
+  NS_ASSERT_MSG (ndn != 0, "Ndn stack should be installed on the node");
+
+  Ptr<NdnFace> face = ndn->GetFace (faceId);
+  NS_ASSERT_MSG (face != 0, "Face with ID [" << faceId << "] does not exist on node [" << node->GetId () << "]");
+
+  AddRoute (node, prefix, face, metric);
+}
+
+void
+NdnStackHelper::AddRoute (std::string nodeName, std::string prefix, uint32_t faceId, int32_t metric)
+{
+  Ptr<Node> node = Names::Find<Node> (nodeName);
+  NS_ASSERT_MSG (node != 0, "Node [" << nodeName << "] does not exist");
+  
+  Ptr<Ndn>     ndn = node->GetObject<Ndn> ();
+  NS_ASSERT_MSG (ndn != 0, "Ndn stack should be installed on the node");
+
+  Ptr<NdnFace> face = ndn->GetFace (faceId);
+  NS_ASSERT_MSG (face != 0, "Face with ID [" << faceId << "] does not exist on node [" << nodeName << "]");
+
+  AddRoute (node, prefix, face, metric);
+}
+
+
+} // namespace ns3