Merge remote-tracking branch 'git.irl/master'
diff --git a/apps/ccnx-consumer-cbr.cc b/apps/ccnx-consumer-cbr.cc
new file mode 100644
index 0000000..5a2a759
--- /dev/null
+++ b/apps/ccnx-consumer-cbr.cc
@@ -0,0 +1,126 @@
+/* -*-  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 "ccnx-consumer-cbr.h"
+#include "ns3/ptr.h"
+#include "ns3/log.h"
+#include "ns3/simulator.h"
+#include "ns3/packet.h"
+#include "ns3/callback.h"
+#include "ns3/string.h"
+#include "ns3/boolean.h"
+#include "ns3/uinteger.h"
+#include "ns3/double.h"
+
+#include "ns3/ccnx.h"
+#include "../model/ccnx-local-face.h"
+#include "ns3/ccnx-interest-header.h"
+#include "ns3/ccnx-content-object-header.h"
+
+NS_LOG_COMPONENT_DEFINE ("CcnxConsumerCbr");
+
+namespace ns3
+{    
+    
+NS_OBJECT_ENSURE_REGISTERED (CcnxConsumerCbr);
+    
+TypeId
+CcnxConsumerCbr::GetTypeId (void)
+{
+  static TypeId tid = TypeId ("ns3::CcnxConsumerCbr")
+    .SetParent<CcnxConsumer> ()
+    .AddConstructor<CcnxConsumerCbr> ()
+
+    .AddAttribute ("MeanRate", "Mean data packet rate (relies on the PayloadSize parameter)",
+                   StringValue ("100Kbps"),
+                   MakeDataRateAccessor (&CcnxConsumerCbr::GetDesiredRate, &CcnxConsumerCbr::SetDesiredRate),
+                   MakeDataRateChecker ())
+    ;
+
+  return tid;
+}
+    
+CcnxConsumerCbr::CcnxConsumerCbr ()
+  : m_desiredRate ("100Kbps")
+{
+  NS_LOG_FUNCTION_NOARGS ();
+
+  UpdateMean ();
+}
+
+
+void
+CcnxConsumerCbr::UpdateMean ()
+{
+  double mean = 8.0 * m_payloadSize / m_desiredRate.GetBitRate ();
+  m_randExp = ExponentialVariable (mean, 100 * mean); // set upper limit to inter-arrival time
+}
+
+void
+CcnxConsumerCbr::SetPayloadSize (uint32_t payload)
+{
+  CcnxConsumer::SetPayloadSize (payload);
+  UpdateMean ();
+}
+
+void
+CcnxConsumerCbr::SetDesiredRate (DataRate rate)
+{
+  m_desiredRate = rate;
+  UpdateMean ();
+}
+
+DataRate
+CcnxConsumerCbr::GetDesiredRate () const
+{
+  return m_desiredRate;
+}
+
+
+void
+CcnxConsumerCbr::ScheduleNextPacket ()
+{
+  // double mean = 8.0 * m_payloadSize / m_desiredRate.GetBitRate ();
+
+  if (!m_sendEvent.IsRunning ())
+    m_sendEvent = Simulator::Schedule (
+                                       Seconds(m_randExp.GetValue ()),
+                                       // Seconds(mean),
+                                       &CcnxConsumer::SendPacket, this);
+}
+
+///////////////////////////////////////////////////
+//          Process incoming packets             //
+///////////////////////////////////////////////////
+
+// void
+// CcnxConsumer::OnContentObject (const Ptr<const CcnxContentObjectHeader> &contentObject,
+//                                const Ptr<const Packet> &payload)
+// {
+//   CcnxConsumer::OnContentObject (contentObject, payload); // tracing inside
+// }
+
+// void
+// CcnxConsumer::OnNack (const Ptr<const CcnxInterestHeader> &interest)
+// {
+//   CcnxConsumer::OnNack (interest); // tracing inside
+// }
+
+} // namespace ns3
diff --git a/apps/ccnx-consumer-cbr.h b/apps/ccnx-consumer-cbr.h
new file mode 100644
index 0000000..59a06d7
--- /dev/null
+++ b/apps/ccnx-consumer-cbr.h
@@ -0,0 +1,83 @@
+/* -*-  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>
+ *         Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef CCNX_CONSUMER_CBR_H
+#define CCNX_CONSUMER_CBR_H
+
+#include "ccnx-consumer.h"
+
+namespace ns3 
+{
+
+/**
+ * @ingroup ccnx
+ * \brief CCNx application for sending out Interest packets at a "constant" rate (Poisson process)
+ */
+class CcnxConsumerCbr: public CcnxConsumer
+{
+public: 
+  static TypeId GetTypeId ();
+        
+  /**
+   * \brief Default constructor 
+   * Sets up randomizer function and packet sequence number
+   */
+  CcnxConsumerCbr ();
+
+  // From CcnxApp
+  // virtual void
+  // OnInterest (const Ptr<const CcnxInterestHeader> &interest);
+
+  // virtual void
+  // OnNack (const Ptr<const CcnxInterestHeader> &interest);
+
+  // virtual void
+  // OnContentObject (const Ptr<const CcnxContentObjectHeader> &contentObject,
+  //                  const Ptr<const Packet> &payload);
+
+protected:
+  /**
+   * \brief Constructs the Interest packet and sends it using a callback to the underlying CCNx protocol
+   */
+  virtual void
+  ScheduleNextPacket ();
+  
+private:
+  void
+  UpdateMean ();
+
+  virtual void
+  SetPayloadSize (uint32_t payload);
+
+  void
+  SetDesiredRate (DataRate rate);
+
+  DataRate
+  GetDesiredRate () const;
+  
+protected:
+  ExponentialVariable m_randExp; // packet inter-arrival time generation (Poisson process)
+  DataRate            m_desiredRate;    // Desired data packet rate
+};
+
+} // namespace ns3
+
+#endif
diff --git a/apps/ccnx-consumer-window.cc b/apps/ccnx-consumer-window.cc
new file mode 100644
index 0000000..57ca8f5
--- /dev/null
+++ b/apps/ccnx-consumer-window.cc
@@ -0,0 +1,123 @@
+/* -*-  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: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "ccnx-consumer-window.h"
+#include "ns3/ptr.h"
+#include "ns3/log.h"
+#include "ns3/simulator.h"
+#include "ns3/packet.h"
+#include "ns3/callback.h"
+#include "ns3/string.h"
+#include "ns3/uinteger.h"
+#include "ns3/double.h"
+
+NS_LOG_COMPONENT_DEFINE ("CcnxConsumerWindow");
+
+namespace ns3
+{    
+    
+NS_OBJECT_ENSURE_REGISTERED (CcnxConsumerWindow);
+    
+TypeId
+CcnxConsumerWindow::GetTypeId (void)
+{
+  static TypeId tid = TypeId ("ns3::CcnxConsumerWindow")
+    .SetParent<CcnxConsumer> ()
+    .AddConstructor<CcnxConsumerWindow> ()
+
+    .AddAttribute ("Window", "Initial size of the window",
+                   StringValue ("1000"),
+                   MakeUintegerAccessor (&CcnxConsumerWindow::GetWindow, &CcnxConsumerWindow::SetWindow),
+                   MakeUintegerChecker<uint32_t> ())
+    ;
+
+  return tid;
+}
+
+CcnxConsumerWindow::CcnxConsumerWindow ()
+  : m_inFlight (0)
+{
+}
+
+void
+CcnxConsumerWindow::SetWindow (uint32_t window)
+{
+  m_window = window;
+}
+
+uint32_t
+CcnxConsumerWindow::GetWindow () const
+{
+  return m_window;
+}
+
+void
+CcnxConsumerWindow::ScheduleNextPacket ()
+{
+  if (m_window == 0 || m_inFlight >= m_window)
+    {
+      if (!m_sendEvent.IsRunning ())
+        m_sendEvent = Simulator::Schedule (Seconds (m_rtt->RetransmitTimeout ().ToDouble (Time::S) * 0.1), &CcnxConsumer::SendPacket, this);
+      return;
+    }
+  
+  // std::cout << "Window: " << m_window << ", InFlight: " << m_inFlight << "\n";
+  m_inFlight++;
+  if (!m_sendEvent.IsRunning ())
+    m_sendEvent = Simulator::ScheduleNow (&CcnxConsumer::SendPacket, this);
+}
+
+///////////////////////////////////////////////////
+//          Process incoming packets             //
+///////////////////////////////////////////////////
+
+void
+CcnxConsumerWindow::OnContentObject (const Ptr<const CcnxContentObjectHeader> &contentObject,
+                               const Ptr<const Packet> &payload)
+{
+  CcnxConsumer::OnContentObject (contentObject, payload);
+
+  m_window = m_window + 1;
+  
+  if (m_inFlight > 0) m_inFlight--;
+  ScheduleNextPacket ();
+}
+
+void
+CcnxConsumerWindow::OnNack (const Ptr<const CcnxInterestHeader> &interest)
+{
+  CcnxConsumer::OnNack (interest);
+  if (m_inFlight > 0) m_inFlight--;
+
+  if (m_window > 0)
+    {
+      // m_window = 0.5 * m_window;//m_window - 1;
+      m_window = m_window - 1;
+    }
+}
+
+void
+CcnxConsumerWindow::OnTimeout (uint32_t sequenceNumber)
+{
+  if (m_inFlight > 0) m_inFlight--;
+  CcnxConsumer::OnTimeout (sequenceNumber);
+}
+
+} // namespace ns3
diff --git a/apps/ccnx-consumer-window.h b/apps/ccnx-consumer-window.h
new file mode 100644
index 0000000..47099f6
--- /dev/null
+++ b/apps/ccnx-consumer-window.h
@@ -0,0 +1,79 @@
+/* -*-  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>
+ *         Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef CCNX_CONSUMER_WINDOW_H
+#define CCNX_CONSUMER_WINDOW_H
+
+#include "ccnx-consumer.h"
+
+namespace ns3 
+{
+
+/**
+ * @ingroup ccnx
+ * \brief CCNx application for sending out Interest packets (window-based)
+ */
+class CcnxConsumerWindow: public CcnxConsumer
+{
+public: 
+  static TypeId GetTypeId ();
+        
+  /**
+   * \brief Default constructor 
+   */
+  CcnxConsumerWindow ();
+
+  // From CcnxApp
+  // virtual void
+  // OnInterest (const Ptr<const CcnxInterestHeader> &interest);
+
+  virtual void
+  OnNack (const Ptr<const CcnxInterestHeader> &interest);
+
+  virtual void
+  OnContentObject (const Ptr<const CcnxContentObjectHeader> &contentObject,
+                   const Ptr<const Packet> &payload);
+
+  virtual void
+  OnTimeout (uint32_t sequenceNumber);
+ 
+protected:
+  /**
+   * \brief Constructs the Interest packet and sends it using a callback to the underlying CCNx protocol
+   */
+  virtual void
+  ScheduleNextPacket ();
+  
+private:
+  virtual void
+  SetWindow (uint32_t window);
+
+  uint32_t
+  GetWindow () const;
+  
+protected:
+  uint32_t m_window;
+  uint32_t m_inFlight;
+};
+
+} // namespace ns3
+
+#endif
diff --git a/apps/ccnx-consumer.cc b/apps/ccnx-consumer.cc
index ae56040..b5984e7 100644
--- a/apps/ccnx-consumer.cc
+++ b/apps/ccnx-consumer.cc
@@ -53,27 +53,19 @@
 {
   static TypeId tid = TypeId ("ns3::CcnxConsumer")
     .SetParent<CcnxApp> ()
-    .AddConstructor<CcnxConsumer> ()
     .AddAttribute ("StartSeq", "Initial sequence number",
                    IntegerValue (0),
                    MakeIntegerAccessor(&CcnxConsumer::m_seq),
                    MakeIntegerChecker<int32_t>())
 
-    .AddAttribute ("Size", "Amount of data in megabytes to request (relies on PayloadSize parameter)",
-                   DoubleValue (-1), // don't impose limit by default
-                   MakeDoubleAccessor (&CcnxConsumer::GetMaxSize, &CcnxConsumer::SetMaxSize),
-                   MakeDoubleChecker<double> ())
-
-    ///////
     .AddAttribute ("PayloadSize", "Average size of content object size (to calculate interest generation rate)",
                    UintegerValue (1040),
                    MakeUintegerAccessor (&CcnxConsumer::GetPayloadSize, &CcnxConsumer::SetPayloadSize),
                    MakeUintegerChecker<uint32_t>())
-    .AddAttribute ("MeanRate", "Mean data packet rate (relies on the PayloadSize parameter)",
-                   StringValue ("100Kbps"),
-                   MakeDataRateAccessor (&CcnxConsumer::GetDesiredRate, &CcnxConsumer::SetDesiredRate),
-                   MakeDataRateChecker ())
-    ///////
+    .AddAttribute ("Size", "Amount of data in megabytes to request (relies on PayloadSize parameter)",
+                   DoubleValue (-1), // don't impose limit by default
+                   MakeDoubleAccessor (&CcnxConsumer::GetMaxSize, &CcnxConsumer::SetMaxSize),
+                   MakeDoubleChecker<double> ())
 
     .AddAttribute ("Prefix","CcnxName of the Interest",
                    StringValue ("/"),
@@ -100,11 +92,6 @@
                    MakeCcnxNameComponentsAccessor (&CcnxConsumer::m_exclude),
                    MakeCcnxNameComponentsChecker ())
 
-    .AddAttribute ("RTO",
-                   "Initial retransmission timeout",
-                   StringValue ("1s"),
-                   MakeTimeAccessor (&CcnxConsumer::m_rto),
-                   MakeTimeChecker ())
     .AddAttribute ("RetxTimer",
                    "Timeout defining how frequent retransmission timeouts should be checked",
                    StringValue ("1s"),
@@ -120,13 +107,12 @@
     
 CcnxConsumer::CcnxConsumer ()
   : m_rand (0, std::numeric_limits<uint32_t>::max ())
-  , m_desiredRate ("10Kbps")
   , m_payloadSize (1040)
   , m_seq (0)
 {
   NS_LOG_FUNCTION_NOARGS ();
-
-  UpdateMean (); // not necessary (will be called by ns3 object system anyways), but doesn't hurt
+  
+  m_rtt = CreateObject<RttMeanDeviation> (); 
 }
 
 void
@@ -154,43 +140,25 @@
 
   boost::mutex::scoped_lock (m_seqTimeoutsGuard);
 
+  Time rto = m_rtt->RetransmitTimeout ();
+  
   while (!m_seqTimeouts.empty ())
     {
       SeqTimeoutsContainer::index<i_timestamp>::type::iterator entry =
         m_seqTimeouts.get<i_timestamp> ().begin ();
-      if (entry->time + m_rto <= now) // timeout expired?
+      if (entry->time + rto <= now) // timeout expired?
         {
-          m_retxSeqs.insert (entry->seq);
-          m_seqTimeouts.get<i_timestamp> ().modify (entry,
-                                                    ll::bind(&SeqTimeout::time, ll::_1) = now);
+          m_seqTimeouts.get<i_timestamp> ().erase (entry);
+          OnTimeout (entry->seq);
         }
       else
         break; // nothing else to do. All later packets need not be retransmitted
     }
 
-  if (m_retxSeqs.size () > 0)
-    {
-      ScheduleNextPacket ();
-    }
-  
   m_retxEvent = Simulator::Schedule (m_retxTimer,
                                      &CcnxConsumer::CheckRetxTimeout, this); 
 }
 
-void
-CcnxConsumer::UpdateMean ()
-{
-  double mean = 8.0 * m_payloadSize / m_desiredRate.GetBitRate ();
-  m_randExp = ExponentialVariable (mean, 10000 * mean); // set upper limit to inter-arrival time
-}
-
-void
-CcnxConsumer::SetPayloadSize (uint32_t payload)
-{
-  m_payloadSize = payload;
-  UpdateMean ();
-}
-
 uint32_t
 CcnxConsumer::GetPayloadSize () const
 {
@@ -198,16 +166,9 @@
 }
 
 void
-CcnxConsumer::SetDesiredRate (DataRate rate)
+CcnxConsumer::SetPayloadSize (uint32_t payload)
 {
-  m_desiredRate = rate;
-  UpdateMean ();
-}
-
-DataRate
-CcnxConsumer::GetDesiredRate () const
-{
-  return m_desiredRate;
+  m_payloadSize = payload;
 }
 
 double
@@ -232,16 +193,6 @@
   NS_LOG_DEBUG ("MaxSeqNo: " << m_seqMax);
 }
 
-
-void
-CcnxConsumer::ScheduleNextPacket ()
-{
-  if (!m_sendEvent.IsRunning ())
-    m_sendEvent = Simulator::Schedule (
-                                       Seconds(m_randExp.GetValue ()),
-                                       &CcnxConsumer::SendPacket, this);
-}
-
 // Application Methods
 void 
 CcnxConsumer::StartApplication () // Called at time specified by Start
@@ -279,6 +230,12 @@
   
   if (m_retxSeqs.size () != 0)
     {
+      // for (RetxSeqsContainer::const_iterator i=m_retxSeqs.begin (); i!=m_retxSeqs.end (); i++)
+      //   {
+      //     std::cout << *i << " ";
+      //   }
+      // std::cout << "\n";
+      
       seq = *m_retxSeqs.begin ();
       NS_LOG_INFO ("Before: " << m_retxSeqs.size ());
       m_retxSeqs.erase (m_retxSeqs.begin ());
@@ -296,6 +253,8 @@
       
       seq = m_seq++;
     }
+
+  // std::cout << Simulator::Now ().ToDouble (Time::S) << "s -> " << seq << "\n";
   
   //
   Ptr<CcnxNameComponents> nameWithSequence = Create<CcnxNameComponents> (m_interestName);
@@ -324,15 +283,10 @@
 
   NS_LOG_DEBUG ("Trying to add " << seq << " with " << Simulator::Now () << ". already " << m_seqTimeouts.size () << " items");  
   
-  std::pair<SeqTimeoutsContainer::iterator, bool>
-    res = m_seqTimeouts.insert (SeqTimeout (seq, Simulator::Now ()));
-  
-  if (!res.second)
-    m_seqTimeouts.modify (res.first,
-                          ll::bind(&SeqTimeout::time, ll::_1) = Simulator::Now ());
-  
+  m_seqTimeouts.insert (SeqTimeout (seq, Simulator::Now ()));
   m_transmittedInterests (&interestHeader, this, m_face);
 
+  m_rtt->SentSeq (SequenceNumber32 (seq), 1);
   ScheduleNextPacket ();
 }
 
@@ -368,6 +322,8 @@
 
   m_seqTimeouts.erase (seq);
   m_retxSeqs.erase (seq);
+
+  m_rtt->AckSeq (SequenceNumber32 (seq));
 }
 
 void
@@ -385,6 +341,7 @@
   // NS_LOG_INFO ("Received NACK: " << boost::cref(*interest));
   uint32_t seq = boost::lexical_cast<uint32_t> (interest->GetName ().GetComponents ().back ());
   NS_LOG_INFO ("< NACK for " << seq);
+  // std::cout << Simulator::Now ().ToDouble (Time::S) << "s -> " << "NACK for " << seq << "\n"; 
 
   // put in the queue of interests to be retransmitted
   NS_LOG_INFO ("Before: " << m_retxSeqs.size ());
@@ -394,4 +351,13 @@
   ScheduleNextPacket ();
 }
 
+void
+CcnxConsumer::OnTimeout (uint32_t sequenceNumber)
+{
+  // std::cout << "TO: " << sequenceNumber << "\n";
+  // m_retxSeqs.insert (sequenceNumber);
+  // std::cout << "Current RTO: " << m_rtt->RetransmitTimeout ().ToDouble (Time::S) << "s\n";
+  ScheduleNextPacket (); 
+}
+
 } // namespace ns3
diff --git a/apps/ccnx-consumer.h b/apps/ccnx-consumer.h
index 9b28a2c..4bffbaf 100644
--- a/apps/ccnx-consumer.h
+++ b/apps/ccnx-consumer.h
@@ -27,6 +27,7 @@
 #include "ns3/ccnx-name-components.h"
 #include "ns3/nstime.h"
 #include "ns3/data-rate.h"
+#include "ns3/rtt-estimator.h"
 
 #include <set>
 
@@ -66,6 +67,13 @@
   OnContentObject (const Ptr<const CcnxContentObjectHeader> &contentObject,
                    const Ptr<const Packet> &payload);
 
+  virtual void
+  OnTimeout (uint32_t sequenceNumber);
+
+  // Simulator::Schedule doesn't work with protected members???
+  void
+  SendPacket ();
+  
 protected:
   // from CcnxApp
   virtual void
@@ -74,31 +82,12 @@
   virtual void
   StopApplication ();
   
-private:
   /**
    * \brief Constructs the Interest packet and sends it using a callback to the underlying CCNx protocol
    */
-  void
-  ScheduleNextPacket ();
-
-  void
-  UpdateMean ();
-
-  void
-  SetPayloadSize (uint32_t payload);
-
-  uint32_t
-  GetPayloadSize () const;
-
-  void
-  SetDesiredRate (DataRate rate);
-
-  DataRate
-  GetDesiredRate () const;
+  virtual void
+  ScheduleNextPacket () = 0;
   
-  void
-  SendPacket ();
-
   /**
    * \brief Checks if the packet need to be retransmitted becuase of retransmission timer expiration
    */
@@ -119,6 +108,12 @@
   Time
   GetRetxTimer () const;
   
+  virtual void
+  SetPayloadSize (uint32_t payload);
+
+  uint32_t
+  GetPayloadSize () const;
+
   double
   GetMaxSize () const;
 
@@ -127,20 +122,15 @@
   
 protected:
   UniformVariable m_rand; // nonce generator
-
-  ExponentialVariable m_randExp; // packet inter-arrival time generation (Poisson process)
-  DataRate            m_desiredRate;    // Desired data packet rate
   uint32_t            m_payloadSize; // expected payload size
-  
+
   uint32_t        m_seq;
   uint32_t        m_seqMax;    // maximum number of sequence number
   EventId         m_sendEvent; // Eventid of pending "send packet" event
   Time            m_retxTimer;
   EventId         m_retxEvent; // Event to check whether or not retransmission should be performed
 
-  Time            m_rto;        ///< \brief Retransmission timeout
-  Time            m_rttVar;     ///< \brief RTT variance
-  Time            m_sRtt;       ///< \brief smoothed RTT
+  Ptr<RttEstimator> m_rtt;
   
   Time               m_offTime;             ///< \brief Time interval between packets
   CcnxNameComponents m_interestName;        ///< \brief CcnxName of the Interest (use CcnxNameComponents)
diff --git a/examples/congestion-pop.cc b/examples/congestion-pop.cc
index 51a5fa0..aed4aa9 100644
--- a/examples/congestion-pop.cc
+++ b/examples/congestion-pop.cc
@@ -144,9 +144,9 @@
         Ptr<Node> node1 = Names::Find<Node> ("/sprint", lexical_cast<string> (node1_num));
         Ptr<Node> node2 = Names::Find<Node> ("/sprint", lexical_cast<string> (node2_num));
 
-        CcnxAppHelper consumerHelper ("ns3::CcnxConsumer");
+        CcnxAppHelper consumerHelper ("ns3::CcnxConsumerWindow");
         consumerHelper.SetPrefix ("/" + lexical_cast<string> (node2->GetId ()));
-        consumerHelper.SetAttribute ("MeanRate", StringValue ("2Mbps"));
+        // consumerHelper.SetAttribute ("MeanRate", StringValue ("2Mbps"));
         consumerHelper.SetAttribute ("Size", StringValue ("1.983642578125")); //to make sure max seq # is 2000
 
         CcnxAppHelper producerHelper ("ns3::CcnxProducer");
@@ -169,7 +169,7 @@
   {
     cout << "Run Simulation.\n";
     Simulator::Stop (finishTime);
-    // Simulator::Schedule (Seconds (1.0), PrintTime);
+    Simulator::Schedule (Seconds (1.0), PrintTime);
     Simulator::Run ();
     Simulator::Destroy ();
     cout << "Done.\n";
@@ -186,7 +186,7 @@
   cout << "Begin congestion-pop scenario\n";
   
   Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps"));
-  Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20"));
+  Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("60"));
 
   uint32_t maxRuns = 1;
   uint32_t startRun = 0;
@@ -212,6 +212,9 @@
       ofstream of_nodes ((prefix + "apps.log").c_str ());
       for (uint32_t i = 0; i < apps.GetN () / 2; i++) 
         {
+          apps.Get (i*2)->SetStartTime (Seconds (i));
+          apps.Get (i*2 + 1)->SetStartTime (Seconds (i));
+          
           of_nodes << "From " << apps.Get (i*2)->GetNode ()->GetId ()
                    << " to "  << apps.Get (i*2 + 1)->GetNode ()->GetId ();
           of_nodes << "\n";
@@ -220,7 +223,8 @@
 
       CcnxTraceHelper traceHelper;
       traceHelper.EnableRateL3All (prefix + "rate-trace.log");
-      traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumer", prefix + "consumers-seqs.log");
+      // traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumerCbr", prefix + "consumers-seqs.log");
+      traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumerWindow", prefix + "consumers-seqs.log");
 
       experiment.Run (Seconds (200.0));
     }
diff --git a/helper/ccnx-stack-helper.cc b/helper/ccnx-stack-helper.cc
index ff73cae..62c5f82 100644
--- a/helper/ccnx-stack-helper.cc
+++ b/helper/ccnx-stack-helper.cc
@@ -155,7 +155,10 @@
 }
 
 void
-CcnxStackHelper::EnableLimits (bool enable/* = true*/, Time avgRtt/*=Seconds(0.1)*/, uint32_t avgContentObject/*=1100*/, uint32_t avgInterest/*=40*/)
+CcnxStackHelper::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;
@@ -237,7 +240,7 @@
           
           NS_LOG_INFO("DataRate for this link is " << dataRate.Get());
 
-          double maxInterestPackets = 1.0  * dataRate.Get ().GetBitRate () / 8.0 / m_avgContentObjectSize;
+          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);