model+examples: Small corrections with new PIT version, adding an example to use it
diff --git a/apps/ndn-consumer.cc b/apps/ndn-consumer.cc
index 68f4858..3a14e48 100644
--- a/apps/ndn-consumer.cc
+++ b/apps/ndn-consumer.cc
@@ -204,6 +204,7 @@
   InterestHeader interestHeader;
   interestHeader.SetNonce               (m_rand.GetValue ());
   interestHeader.SetName                (nameWithSequence);
+  interestHeader.SetInterestLifetime    (m_interestLifeTime);
 
   // NS_LOG_INFO ("Requesting Interest: \n" << interestHeader);
   NS_LOG_INFO ("> Interest for " << seq);
diff --git a/examples/ndn-simple-pit-policies.cc b/examples/ndn-simple-pit-policies.cc
new file mode 100644
index 0000000..f18b85a
--- /dev/null
+++ b/examples/ndn-simple-pit-policies.cc
@@ -0,0 +1,92 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2012 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: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+// ndn-simple-pit-policies.cc
+#include "ns3/core-module.h"
+#include "ns3/network-module.h"
+#include "ns3/point-to-point-module.h"
+#include "ns3/ndnSIM-module.h"
+
+using namespace ns3;
+
+/**
+ * This scenario simulates a very simple network topology:
+ *
+ *
+ *      +----------+     1Mbps      +--------+     1Mbps      +----------+
+ *      | consumer | <------------> | router | <------------> | producer |
+ *      +----------+         10ms   +--------+          10ms  +----------+
+ *
+ *
+ * Consumer requests data from producer with frequency 10 interests per second
+ * (interests contain constantly increasing sequence number).
+ *
+ * For every received interest, producer replies with a data packet, containing
+ * 1024 bytes of virtual payload.
+ *
+ * To run scenario and see what is happening, use the following command:
+ *
+ *     NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-simple-pit-policies
+ */
+
+int
+main (int argc, char *argv[])
+{
+  // setting default parameters for PointToPoint links and channels
+  Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps"));
+  Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("10ms"));
+  Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20"));
+
+  // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
+  CommandLine cmd;
+  cmd.Parse (argc, argv);
+
+  // Creating nodes
+  NodeContainer nodes;
+  nodes.Create (3);
+
+  // Connecting nodes using two links
+  PointToPointHelper p2p;
+  p2p.Install (nodes.Get (0), nodes.Get (1));
+  p2p.Install (nodes.Get (1), nodes.Get (2));
+
+  // Install NDN stack on all nodes
+  ndn::StackHelper ndnHelper;
+  ndnHelper.SetPit ("ns3::ndn::pit::SerializedSize",
+                    "MaxSize", "300"); // 1000 bytes ~ 10 entries
+  ndnHelper.SetDefaultRoutes (true);
+  ndnHelper.InstallAll ();
+
+  // Installing applications
+
+  // Consumer
+  ndn::AppHelper consumerHelper ("ns3::ndn::ConsumerCbr");
+  // Consumer will request /prefix/0, /prefix/1, ...
+  consumerHelper.SetPrefix ("/prefix");
+  consumerHelper.SetAttribute ("LifeTime", StringValue ("2s"));
+  consumerHelper.SetAttribute ("Frequency", StringValue ("10")); // 10 interests a second
+  consumerHelper.Install (nodes.Get (0)); // first node
+
+  Simulator::Stop (Seconds (5.0));
+
+  Simulator::Run ();
+  Simulator::Destroy ();
+
+  return 0;
+}
diff --git a/examples/wscript b/examples/wscript
index a962ffa..5d61417 100644
--- a/examples/wscript
+++ b/examples/wscript
@@ -6,10 +6,10 @@
 
     obj = bld.create_ns3_program('ndn-grid', ['ndnSIM', 'point-to-point-layout'])
     obj.source = 'ndn-grid.cc'
-    
+
     obj = bld.create_ns3_program('ndn-zipf-mandelbrot', ['ndnSIM', 'point-to-point-layout'])
     obj.source = 'ndn-zipf-mandelbrot.cc'
-    
+
 
     obj = bld.create_ns3_program('ndn-simple-with-content-freshness', ['ndnSIM'])
     obj.source = ['ndn-simple-with-content-freshness.cc',
@@ -41,3 +41,6 @@
 
         obj = bld.create_ns3_program('ndn-tree-app-delay-tracer', ['ndnSIM'])
         obj.source = 'ndn-tree-app-delay-tracer.cc'
+
+    obj = bld.create_ns3_program('ndn-simple-pit-policies', ['ndnSIM'])
+    obj.source = 'ndn-simple-pit-policies.cc'
diff --git a/model/pit/custom-policies/serialized-size-policy.h b/model/pit/custom-policies/serialized-size-policy.h
index 0050ac6..7cfb506 100644
--- a/model/pit/custom-policies/serialized-size-policy.h
+++ b/model/pit/custom-policies/serialized-size-policy.h
@@ -105,15 +105,25 @@
       inline bool
       insert (typename parent_trie::iterator item)
       {
-        if (max_size_ != 0 && current_space_used_ >= max_size_)
+        uint32_t interestSize = item->payload ()->GetInterest ()->GetSerializedSize ();
+
+        // can't use logging here
+        NS_LOG_DEBUG ("Number of entries: " << policy_container::size ()
+                      << ", space used: " << current_space_used_
+                      << ", name: " << item->payload ()->GetPrefix ()
+                      << ", interest size: " << interestSize);
+
+        if (max_size_ != 0 && current_space_used_ + interestSize > max_size_)
           {
+            NS_LOG_DEBUG ("Rejecting PIT entry");
+
             // the current version just fails to add an element, but it also possible
             // to remove the largest element (last element in multi_map policy container)
             return false;
           }
 
-        get_size (item) = item->payload ()->GetInterest ()->GetSerializedSize ();
-        current_space_used_ += get_size (item);
+        get_size (item) = interestSize;
+        current_space_used_ += interestSize;
 
         policy_container::insert (*item);
         return true;
@@ -128,6 +138,8 @@
       inline void
       erase (typename parent_trie::iterator item)
       {
+        NS_LOG_DEBUG ("Erasing entry with name: " << item->payload ()->GetPrefix ());
+
         current_space_used_ -= get_size (item);
         policy_container::erase (policy_container::s_iterator_to (*item));
       }
diff --git a/model/pit/ndn-pit-impl.cc b/model/pit/ndn-pit-impl.cc
index 14b6b2a..3b693f8 100644
--- a/model/pit/ndn-pit-impl.cc
+++ b/model/pit/ndn-pit-impl.cc
@@ -28,9 +28,13 @@
 #include "../../utils/trie/persistent-policy.h"
 #include "../../utils/trie/random-policy.h"
 #include "../../utils/trie/lru-policy.h"
-#include "custom-policies/serialized-size-policy.h"
 
 #include "ns3/log.h"
+
+NS_LOG_COMPONENT_DEFINE ("ndn.pit.PitImpl");
+
+#include "custom-policies/serialized-size-policy.h"
+
 #include "ns3/string.h"
 #include "ns3/uinteger.h"
 #include "ns3/simulator.h"
@@ -38,7 +42,6 @@
 #include <boost/lambda/bind.hpp>
 #include <boost/lambda/lambda.hpp>
 
-NS_LOG_COMPONENT_DEFINE ("ndn.pit.PitImpl");
 
 using namespace boost::tuples;
 using namespace boost;