limits: Adding ability for GlobalRoutingController to set precise BDP prefix limits using knowledge of RTT for destination
diff --git a/helper/boost-graph-ndn-global-routing-helper.h b/helper/boost-graph-ndn-global-routing-helper.h
index df08c73..f406a3e 100644
--- a/helper/boost-graph-ndn-global-routing-helper.h
+++ b/helper/boost-graph-ndn-global-routing-helper.h
@@ -29,6 +29,7 @@
 #include <boost/ref.hpp>
 
 #include "ns3/ndn-face.h"
+#include "ns3/ndn-limits.h"
 #include "ns3/node-list.h"
 #include "ns3/channel-list.h"
 #include "../model/ndn-global-router.h"
@@ -205,14 +206,14 @@
 struct property_traits< EdgeWeights >
 {
   // Metric property map
-  typedef tuple< ns3::Ptr<ns3::ndn::Face>, uint16_t > value_type;
-  typedef tuple< ns3::Ptr<ns3::ndn::Face>, uint16_t > reference;
+  typedef tuple< ns3::Ptr<ns3::ndn::Face>, uint16_t, double > value_type;
+  typedef tuple< ns3::Ptr<ns3::ndn::Face>, uint16_t, double > reference;
   typedef ns3::ndn::GlobalRouter::Incidency key_type;
   typedef readable_property_map_tag category;
 };
 
-const property_traits< EdgeWeights >::value_type WeightZero (0, 0);
-const property_traits< EdgeWeights >::value_type WeightInf (0, std::numeric_limits<uint16_t>::max ());
+const property_traits< EdgeWeights >::value_type WeightZero (0, 0, 0.0);
+const property_traits< EdgeWeights >::value_type WeightInf (0, std::numeric_limits<uint16_t>::max (), 0.0);
 
 struct WeightCompare :
     public std::binary_function<property_traits< EdgeWeights >::reference,
@@ -253,14 +254,14 @@
     return a + b.get<1> ();
   }
 
-  tuple< ns3::Ptr<ns3::ndn::Face>, uint32_t >
-  operator () (tuple< ns3::Ptr<ns3::ndn::Face>, uint32_t > a,
+  tuple< ns3::Ptr<ns3::ndn::Face>, uint32_t, double >
+  operator () (tuple< ns3::Ptr<ns3::ndn::Face>, uint32_t, double > a,
                property_traits< EdgeWeights >::reference b) const
   {
     if (a.get<0> () == 0)
-      return make_tuple (b.get<0> (), a.get<1> () + b.get<1> ());
+      return make_tuple (b.get<0> (), a.get<1> () + b.get<1> (), a.get<2> () + b.get<2> ());
     else
-      return make_tuple (a.get<0> (), a.get<1> () + b.get<1> ());
+      return make_tuple (a.get<0> (), a.get<1> () + b.get<1> (), a.get<2> () + b.get<2> ());
   }
 };
   
@@ -311,9 +312,17 @@
 get(const boost::EdgeWeights&, ns3::ndn::GlobalRouter::Incidency &edge)
 {
   if (edge.get<1> () == 0)
-    return property_traits< EdgeWeights >::reference (0, 0);
+    return property_traits< EdgeWeights >::reference (0, 0, 0.0);
   else
-    return property_traits< EdgeWeights >::reference (edge.get<1> (), edge.get<1> ()->GetMetric ());
+    {
+      ns3::Ptr<ns3::ndn::Limits> limits = edge.get<1> ()->GetObject<ns3::ndn::Limits> ();
+      double delay = 0.0;
+      if (limits != 0) // valid limits object
+        {
+          delay = limits->GetLinkDelay ();
+        }
+      return property_traits< EdgeWeights >::reference (edge.get<1> (), edge.get<1> ()->GetMetric (), delay);
+    }
 }
 
 struct PredecessorsMap :
@@ -333,7 +342,7 @@
 
 
 struct DistancesMap :
-    public std::map< ns3::Ptr< ns3::ndn::GlobalRouter >, tuple< ns3::Ptr<ns3::ndn::Face>, uint32_t > >
+  public std::map< ns3::Ptr< ns3::ndn::GlobalRouter >, tuple< ns3::Ptr<ns3::ndn::Face>, uint32_t, double > >
 {
 };
 
@@ -341,18 +350,18 @@
 struct property_traits< reference_wrapper<DistancesMap> >
 {
   // Metric property map
-  typedef tuple< ns3::Ptr<ns3::ndn::Face>, uint32_t > value_type;
-  typedef tuple< ns3::Ptr<ns3::ndn::Face>, uint32_t > reference;
+  typedef tuple< ns3::Ptr<ns3::ndn::Face>, uint32_t, double > value_type;
+  typedef tuple< ns3::Ptr<ns3::ndn::Face>, uint32_t, double > reference;
   typedef ns3::Ptr< ns3::ndn::GlobalRouter > key_type;
   typedef read_write_property_map_tag category;
 };
 
-inline tuple< ns3::Ptr<ns3::ndn::Face>, uint32_t >
+inline tuple< ns3::Ptr<ns3::ndn::Face>, uint32_t, double >
 get (DistancesMap &map, ns3::Ptr<ns3::ndn::GlobalRouter> key)
 {
   boost::DistancesMap::iterator i = map.find (key);
   if (i == map.end ())
-    return tuple< ns3::Ptr<ns3::ndn::Face>, uint32_t > (0, std::numeric_limits<uint32_t>::max ());
+    return tuple< ns3::Ptr<ns3::ndn::Face>, uint32_t, double > (0, std::numeric_limits<uint32_t>::max (), 0.0);
   else
     return i->second;
 }
diff --git a/helper/ndn-global-routing-helper.cc b/helper/ndn-global-routing-helper.cc
index 3d18042..68f7228 100644
--- a/helper/ndn-global-routing-helper.cc
+++ b/helper/ndn-global-routing-helper.cc
@@ -258,7 +258,7 @@
       fib->InvalidateAll ();
       NS_ASSERT (fib != 0);
       
-      // cout << "Reachability from Node: " << source->GetObject<Node> ()->GetId () << endl;
+      cout << "Reachability from Node: " << source->GetObject<Node> ()->GetId () << endl;
       for (DistancesMap::iterator i = distances.begin ();
 	   i != distances.end ();
 	   i++)
@@ -274,25 +274,26 @@
 		}
 	      else
 		{
-		// cout << " reachable via face " << *i->second.get<0> ()
-		//      << " with distance " << i->second.get<1> () << endl;
-
-		BOOST_FOREACH (const Ptr<const NameComponents> &prefix, i->first->GetLocalPrefixes ())
-		  {
-		    Ptr<fib::Entry> entry = fib->Add (prefix, i->second.get<0> (), i->second.get<1> ());
-                    Ptr<Limits> limits = i->second.get<0> ()->GetObject<Limits> ();
+                  BOOST_FOREACH (const Ptr<const NameComponents> &prefix, i->first->GetLocalPrefixes ())
+                    {
+                      cout << " prefix " << prefix << " reachable via face " << *i->second.get<0> ()
+                           << " with distance " << i->second.get<1> ()
+                           << " with delay " << i->second.get<2> () << endl;
                     
-                    if (limits != 0 && limits->IsEnabled ())
-                      {
-                        ObjectFactory limitsFactory;
-                        limitsFactory.SetTypeId (limits->GetInstanceTypeId ());
+                      Ptr<fib::Entry> entry = fib->Add (prefix, i->second.get<0> (), i->second.get<1> ());
+                      Ptr<Limits> limits = i->second.get<0> ()->GetObject<Limits> ();
+                    
+                      if (limits != 0 && limits->IsEnabled ())
+                        {
+                          ObjectFactory limitsFactory;
+                          limitsFactory.SetTypeId (limits->GetInstanceTypeId ());
 
-                        Ptr<Limits> entryLimits = limitsFactory.Create<Limits> ();
-                        entryLimits->SetLimits (limits->GetMaxRate (), limits->GetMaxDelay ());
+                          Ptr<Limits> entryLimits = limitsFactory.Create<Limits> ();
+                          entryLimits->SetLimits (limits->GetMaxRate (), 2*i->second.get<2> ());
 
-                        entry->AggregateObject (entryLimits);
-                      }
-		  }
+                          entry->AggregateObject (entryLimits);
+                        }
+                    }
 		}
 	    }
 	}
diff --git a/helper/ndn-stack-helper.cc b/helper/ndn-stack-helper.cc
index 5dade78..983c8cf 100644
--- a/helper/ndn-stack-helper.cc
+++ b/helper/ndn-stack-helper.cc
@@ -28,6 +28,7 @@
 #include "ns3/simulator.h"
 #include "ns3/string.h"
 #include "ns3/net-device.h"
+#include "ns3/channel.h"
 #include "ns3/callback.h"
 #include "ns3/node.h"
 #include "ns3/core-config.h"
@@ -270,6 +271,7 @@
               // Set maximum buckets (averaging over 1 second)
       
               DataRateValue dataRate; device->GetAttribute ("DataRate", dataRate);
+              TimeValue linkDelay;   device->GetChannel ()->GetAttribute ("Delay", linkDelay);
           
               NS_LOG_INFO("DataRate for this link is " << dataRate.Get());
 
@@ -280,6 +282,7 @@
 
               // Set max to BDP
               limits->SetLimits (maxInterestPackets, m_avgRtt.ToDouble (Time::S));
+              limits->SetLinkDelay (linkDelay.Get ().ToDouble (Time::S));
             }
         }