Ccnx-grid example
diff --git a/examples/ccnx-grid.cc b/examples/ccnx-grid.cc
new file mode 100644
index 0000000..239654e
--- /dev/null
+++ b/examples/ccnx-grid.cc
@@ -0,0 +1,147 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * 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: Ilya Moiseenko <iliamo@cs.ucla.edu>
+ */
+
+#include "ns3/core-module.h"
+#include "ns3/network-module.h"
+#include "ns3/point-to-point-module.h"
+#include "ns3/NDNabstraction-module.h"
+#include <ns3/point-to-point-grid.h>
+#include "ns3/ipv4-global-routing-helper.h"
+
+#include <iostream>
+#include <sstream>
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("CcnxGrid");
+
+int 
+main (int argc, char *argv[])
+{
+    uint32_t n = 3;
+    
+    Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("10Mbps"));
+    Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("1ms"));
+    
+    Packet::EnableChecking();
+    Packet::EnablePrinting();
+    CommandLine cmd;
+    cmd.Parse (argc, argv);
+
+    PointToPointHelper p2p;
+    InternetStackHelper stack;
+    
+    Ipv4GlobalRoutingHelper ipv4RoutingHelper;
+    // Ptr<Ipv4RoutingHelper> ipv4RoutingHelper = stack.GetRoutingHelper ();
+    stack.SetRoutingHelper (ipv4RoutingHelper);
+    
+    PointToPointGridHelper grid (n, n, p2p);
+    grid.InstallStack (stack);
+    
+    // // Create router nodes, initialize routing database and set up the routing
+    // // tables in the nodes.
+    Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
+    
+    grid.AssignIpv4Addresses (
+                              Ipv4AddressHelper("10.1.0.0", "255.255.255.0"),
+                              Ipv4AddressHelper("10.2.0.0", "255.255.255.0")
+                              );
+    
+    NS_LOG_INFO ("Installing NDN stack");
+    NodeContainer c;
+    
+    for(uint32_t i=0; i<n; i++)
+    {
+        for(uint32_t j=0; j<n; j++)
+        {
+            NS_LOG_INFO ("Adding node i="<<i << " j=" << j);
+            c.Add(grid.GetNode(i,j));
+            
+            int nodeCount = i*n+j+1;
+            std::stringstream ss;
+            ss<<nodeCount;
+            Names::Add (ss.str(), c.Get (c.GetN()-1));
+            NS_LOG_INFO("Eventual name is " << ss.str());
+        }
+    }
+    CcnxStackHelper ccnx;
+    Ptr<CcnxFaceContainer> cf = ccnx.Install (c);
+
+    NS_LOG_INFO ("Installing Applications");
+    CcnxConsumerHelper helper ("/3");
+    ApplicationContainer app = helper.Install ("1");
+    app.Start (Seconds (1.0));
+    app.Stop (Seconds (10.05));
+    
+    CcnxProducerHelper helper2 ("/3",120);
+    ApplicationContainer app2 = helper2.Install("9");
+    app2.Start(Seconds(0.0));
+    app2.Stop(Seconds(15.0));
+    
+    /**
+     * \brief Add forwarding entry in FIB
+     *
+     * \param node Node
+     * \param prefix Routing prefix
+     * \param face Face index
+     * \param metric Routing metric
+     */
+    
+    //2x2 works
+    /*ccnx.AddRoute ("1", "/3", 0, 1);
+    ccnx.AddRoute ("1", "/3", 1, 1);
+    
+    ccnx.AddRoute ("2", "/3", 1, 1);
+    ccnx.AddRoute ("3", "/3", 1, 1);
+    */
+    
+    //3x3
+    
+    ccnx.AddRoute ("1", "/3", 0, 1);
+    ccnx.AddRoute ("1", "/3", 1, 1);
+    
+    ccnx.AddRoute ("2", "/3", 1, 1);
+    
+    ccnx.AddRoute ("3", "/3", 1, 1);
+    
+    ccnx.AddRoute ("4", "/3", 2, 1);
+    
+    ccnx.AddRoute ("6", "/3", 2, 1);
+    
+    ccnx.AddRoute ("7", "/3", 1, 1);
+    
+    ccnx.AddRoute ("8", "/3", 1, 1);
+    
+    
+    NS_LOG_INFO ("FIB dump:\n" << *c.Get(0)->GetObject<CcnxFib> ());
+    NS_LOG_INFO ("FIB dump:\n" << *c.Get(1)->GetObject<CcnxFib> ());
+    
+    
+    
+    Simulator::Stop (Seconds (20));
+    
+    NS_LOG_INFO ("Run Simulation.");
+    Simulator::Run ();
+    Simulator::Destroy ();
+    NS_LOG_INFO ("Done.");
+    
+    return 0;
+
+}
\ No newline at end of file
diff --git a/helper/ccnx-stack-helper.cc b/helper/ccnx-stack-helper.cc
index 6ea2883..0a39a80 100644
--- a/helper/ccnx-stack-helper.cc
+++ b/helper/ccnx-stack-helper.cc
@@ -194,40 +194,38 @@
   node->AggregateObject (ccnx);
 
   Ptr<CcnxPit> pit = ccnx->GetPit();
-    
+    NS_LOG_INFO("NODE #"<<node->GetNDevices());
   for (uint32_t index=0; index < node->GetNDevices (); index++)
     {
+        Ptr<PointToPointNetDevice> device = DynamicCast<PointToPointNetDevice>(node->GetDevice(index));
+        if(device == 0)
+            continue;
+        
       Ptr<CcnxNetDeviceFace> face = Create<CcnxNetDeviceFace> (node->GetDevice (index));
       face->SetNode (node);
       uint32_t __attribute__ ((unused)) face_id = ccnx->AddFace (face);
       NS_LOG_LOGIC ("Node " << node->GetId () << ": added CcnxNetDeviceFace as face #" << face_id);
-
       // 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)
-      Ptr<PointToPointNetDevice> device = node->GetDevice(index)->GetObject<PointToPointNetDevice> ();
+      
       DataRateValue dataRate;
       device->GetAttribute ("DataRate", dataRate);
-      pit->maxBucketsPerFace[face->GetId()] = 0.1 * dataRate.Get().GetBitRate () / 8 / (NDN_DEFAULT_DATA_SIZE + sizeof(CcnxInterestHeader)); 
+      NS_LOG_INFO("DataRate for this link is " << dataRate.Get());
+      pit->maxBucketsPerFace[face->GetId()] = 0.1 * dataRate.Get().GetBitRate () / 8 /(NDN_DEFAULT_DATA_SIZE + sizeof(CcnxInterestHeader));
+      NS_LOG_INFO("maxBucketsPerFace["<<face->GetId()<<"] = " << pit->maxBucketsPerFace[face->GetId()]); 
       pit->leakSize[face->GetId()] = 0.97 * NDN_INTEREST_RESET_PERIOD / SECOND * dataRate.Get().GetBitRate () / 8 / (NDN_DEFAULT_DATA_SIZE + sizeof(CcnxInterestHeader));
-      
-    
+      NS_LOG_INFO("pit->leakSize["<<face->GetId()<<"] = " << pit->leakSize[face->GetId()]);
+        
+        
+      if(face->IsLocal()==true)
+        NS_LOG_INFO("Face #" << face_id << " is turned on");
       face->SetUp ();
       faces->Add (face);
     }
     
-/*    
-    // Assume that we know average data packet size, and this size is equal default size
-    // Set maximum buckets (averaging over 1 second)
-    _pit.maxBucketsPerInterface[*it] = 0.1*_node->macData[*it]->bandwidth / 8 / (NDN_DEFAULT_DATA_SIZE+sizeof(NdnPacket));
-    _pit.leakSize[*it] = 0.97 * NDN_INTEREST_RESET_PERIOD / SECOND * _node->macData[*it]->bandwidth/8 / (NDN_DEFAULT_DATA_SIZE+sizeof(NdnPacket));
-
-  */  
-    m_forwardingHelper.SetForwarding (ccnx, pit);
+  m_forwardingHelper.SetForwarding (ccnx, pit);
   
-    // Ptr<CcnxForwardingStrategy> ccnxForwarding = m_forwarding->Create (node);
-  // ccnx->SetForwardingStrategy (ccnxForwarding);
-
   return faces;
 }
 
@@ -256,8 +254,25 @@
   prefixValue.DeserializeFromString (prefix, MakeCcnxNameComponentsChecker ());
   fib->Add (prefixValue.Get (), face, metric);
 }
-
-
+/*
+void
+CcnxStackHelper::AddRoute (Ptr<Node> node, std::string prefix, uint32_t faceId, int32_t metric)
+{
+    NS_LOG_LOGIC ("[" << nodeName << "]$ route add " << prefix << " via " << faceId << " metric " << metric);
+    
+  NS_ASSERT_MSG (node != 0, "Node does not exist");
+        
+  Ptr<Ccnx>     ccnx = node->GetObject<Ccnx> ();
+  Ptr<CcnxFib>  fib  = node->GetObject<CcnxFib> ();
+  Ptr<CcnxFace> face = ccnx->GetFace (faceId);
+  NS_ASSERT_MSG (node != 0, "Face with ID [" << faceId << "] does not exist on node [" << nodeName << "]");
+        
+  CcnxNameComponentsValue prefixValue;
+  prefixValue.DeserializeFromString (prefix, MakeCcnxNameComponentsChecker ());
+  fib->Add (prefixValue.Get (), face, metric);
+}
+*/
+    
 static void
 CcnxL3ProtocolRxTxSink (Ptr<const Packet> p, Ptr<Ccnx> ccnx, uint32_t face)
 {
diff --git a/helper/ccnx-stack-helper.h b/helper/ccnx-stack-helper.h
index a728860..eebbf0b 100644
--- a/helper/ccnx-stack-helper.h
+++ b/helper/ccnx-stack-helper.h
@@ -153,7 +153,10 @@
    */
   void
   AddRoute (std::string nodeName, std::string prefix, uint32_t faceId, int32_t metric);
-
+/*
+  void
+  AddRoute (Ptr<Node> node, std::string prefix, uint32_t faceId, int32_t metric);
+  */  
 private:
    CcnxForwardingHelper m_forwardingHelper;
     
diff --git a/model/ccnx-l3-protocol.cc b/model/ccnx-l3-protocol.cc
index e5f7f0c..4b832a4 100644
--- a/model/ccnx-l3-protocol.cc
+++ b/model/ccnx-l3-protocol.cc
@@ -279,11 +279,16 @@
   if ((header->IsNack()) && (pitEntry != m_pit->end ()))
     {
       //m_pit->erase (pitEntry);
+        NS_LOG_INFO("TRUE");
         m_pit->modify(pitEntry, CcnxPitEntry::DeleteIncoming(incomingFace));
     }
     
     NS_LOG_INFO("Before WasRecentlySatisfied");
-  if (m_rit->WasRecentlySatisfied (*header))
+    if (m_rit->WasRecentlySatisfied (*header))
+    {
+        return;
+    }
+  /*if (m_rit->WasRecentlySatisfied (*header))
     {
         NS_LOG_INFO("Entering WasRecentlySatisfied");
       // duplicate interests (same nonce) from applications are just ignored
@@ -300,11 +305,12 @@
                                m_node->GetObject<Ccnx> (), incomingFace);
         
       bool isMine = false;
-      TypeId tid = TypeId ("ns3::CcnxProducer");
+      //TypeId tid = TypeId ("ns3::CcnxProducer");
       for(uint32_t i=0; i<m_node->GetNApplications();i++)
         {
             Ptr<Application> app = m_node->GetApplication(i);
-            if(app->GetTypeId() == tid)
+            NS_LOG_INFO("ApplicationName = " << app->GetTypeId().GetName());
+            if(app->GetTypeId().GetName() == "ns3::CcnxProducer")
               {
                 if((DynamicCast<CcnxProducer>(app))->GetPrefix () == header->GetName ())
                 {
@@ -423,7 +429,7 @@
         
       if(pitEntry->m_fibEntry.m_faces.size() == 0)  
         return;
-    }
+    }*/
     
   // Otherwise,
   // propagate the interest
diff --git a/wscript b/wscript
index f462373..bd94d0f 100644
--- a/wscript
+++ b/wscript
@@ -61,6 +61,8 @@
         obj = bld.create_ns3_program('ccnx-routing-simple', ['NDNabstraction', 'point-to-point-layout'])
         obj.source = 'examples/ccnx-routing-simple.cc'
         
+        obj = bld.create_ns3_program('ccnx-grid', ['NDNabstraction', 'point-to-point-layout'])
+        obj.source = 'examples/ccnx-grid.cc'
 
     #     for path in ["examples"]:
     #         anode = bld.path.find_dir (path)