limits: Introducing modularity for Interest limits
Now ndn::Limits object can be aggregated on a face/FIB entry. A
forwarding strategy module is responsible in creating an appropriate
implementation of the Interest limits module.
diff --git a/utils/ndn-limits-window.cc b/utils/ndn-limits-window.cc
new file mode 100644
index 0000000..6f371b4
--- /dev/null
+++ b/utils/ndn-limits-window.cc
@@ -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: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "ndn-limits-window.h"
+
+#include "ns3/log.h"
+#include "ns3/simulator.h"
+#include "ns3/random-variable.h"
+
+NS_LOG_COMPONENT_DEFINE ("ndn.Limits.Window");
+
+namespace ns3 {
+namespace ndn {
+
+NS_OBJECT_ENSURE_REGISTERED (Limits);
+
+TypeId
+LimitsWindow::GetTypeId ()
+{
+ static TypeId tid = TypeId ("ns3::ndn::Limits::Window")
+ .SetGroupName ("Ndn")
+ .SetParent <Limits> ()
+ .AddConstructor <LimitsWindow> ()
+
+ .AddTraceSource ("Outstanding",
+ "Number of outstanding interests",
+ MakeTraceSourceAccessor (&LimitsWindow::m_outstanding))
+ ;
+ return tid;
+}
+
+bool
+LimitsWindow::IsBelowLimit ()
+{
+ if (!IsEnabled ()) return true;
+
+ if (m_curMaxLimit - m_outstanding >= 1.0)
+ {
+ // static UniformVariable acceptanceProbability (0, m_curMaxLimit);
+ // double value = acceptanceProbability.GetValue ();
+ double value = m_outstanding + 1;
+
+ if (m_outstanding < value)
+ {
+ m_outstanding += 1.0;
+ return true;
+ }
+ else
+ return false;
+ }
+ else
+ return false;
+}
+
+void
+LimitsWindow::RemoveOutstanding ()
+{
+ if (!IsEnabled ()) return;
+
+ NS_LOG_DEBUG (m_outstanding);
+ NS_ASSERT_MSG (m_outstanding >= (uint32_t)1, "Should not be possible, unless we decreasing this number twice somewhere");
+ m_outstanding -= 1;
+}
+
+} // namespace ndn
+} // namespace ns3
diff --git a/utils/ndn-limits-window.h b/utils/ndn-limits-window.h
new file mode 100644
index 0000000..b1f2208
--- /dev/null
+++ b/utils/ndn-limits-window.h
@@ -0,0 +1,84 @@
+/* -*- 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>
+ */
+
+#ifndef _NDN_LIMITS_WINDOW_H_
+#define _NDN_LIMITS_WINDOW_H_
+
+#include "ndn-limits.h"
+
+namespace ns3 {
+namespace ndn {
+
+/**
+ * \ingroup ndn
+ * \brief Structure to manage limits for outstanding interests
+ */
+class LimitsWindow :
+ public Limits
+{
+public:
+ typedef Limits super;
+
+ static TypeId
+ GetTypeId ();
+
+ /**
+ * \brief Constructor
+ * \param prefix smart pointer to the prefix for the FIB entry
+ */
+ LimitsWindow ()
+ : m_outstanding (0)
+ { }
+
+ virtual
+ ~LimitsWindow () { }
+
+
+ // from limits
+ virtual bool
+ IsBelowLimit ();
+
+ ////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////
+
+ // specific to window-based limits
+
+ /**
+ * @brief Remove outstanding interests
+ */
+ void
+ RemoveOutstanding ();
+
+ double
+ GetOutstanding () const
+ {
+ return m_outstanding;
+ }
+
+protected:
+ TracedValue< double > m_outstanding;
+};
+
+
+} // namespace ndn
+} // namespace ns3
+
+#endif // _NDN_LIMITS_WINDOW_H_
diff --git a/utils/ndn-limits.cc b/utils/ndn-limits.cc
index 2e4a9ec..4e5f48f 100644
--- a/utils/ndn-limits.cc
+++ b/utils/ndn-limits.cc
@@ -29,41 +29,22 @@
namespace ns3 {
namespace ndn {
-NS_OBJECT_ENSURE_REGISTERED (Limits);
-
TypeId
Limits::GetTypeId ()
{
static TypeId tid = TypeId ("ns3::ndn::Limits")
.SetGroupName ("Ndn")
.SetParent <Object> ()
- .AddConstructor <Limits> ()
.AddTraceSource ("CurMaxLimit",
"Current maximum limit",
MakeTraceSourceAccessor (&Limits::m_curMaxLimit))
- .AddTraceSource ("Outstanding",
- "Number of outstanding interests",
- MakeTraceSourceAccessor (&Limits::m_outstanding))
;
return tid;
}
void
-Limits::SetMaxLimit (double max)
-{
- m_maxLimit = max;
- m_curMaxLimit = max;
-}
-
-double
-Limits::GetMaxLimit () const
-{
- return m_maxLimit;
-}
-
-void
Limits::UpdateCurrentLimit (double limit)
{
NS_ASSERT_MSG (limit >= 0.0, "Limit should be greater or equal to zero");
@@ -71,38 +52,5 @@
m_curMaxLimit = std::min (limit, m_maxLimit);
}
-bool
-Limits::IsBelowLimit ()
-{
- if (!IsEnabled ()) return true;
-
- if (m_curMaxLimit - m_outstanding >= 1.0)
- {
- // static UniformVariable acceptanceProbability (0, m_curMaxLimit);
- // double value = acceptanceProbability.GetValue ();
- double value = m_outstanding + 1;
-
- if (m_outstanding < value)
- {
- m_outstanding += 1.0;
- return true;
- }
- else
- return false;
- }
- else
- return false;
-}
-
-void
-Limits::RemoveOutstanding ()
-{
- if (!IsEnabled ()) return;
-
- NS_LOG_DEBUG (m_outstanding);
- NS_ASSERT_MSG (m_outstanding >= (uint32_t)1, "Should not be possible, unless we decreasing this number twice somewhere");
- m_outstanding -= 1;
-}
-
} // namespace ndn
} // namespace ns3
diff --git a/utils/ndn-limits.h b/utils/ndn-limits.h
index 181059a..14aec50 100644
--- a/utils/ndn-limits.h
+++ b/utils/ndn-limits.h
@@ -23,7 +23,6 @@
#include "ns3/ptr.h"
#include "ns3/object.h"
-#include "ns3/nstime.h"
#include "ns3/traced-value.h"
namespace ns3 {
@@ -39,33 +38,38 @@
public:
static TypeId
GetTypeId ();
-
- /**
- * \brief Constructor
- * \param prefix smart pointer to the prefix for the FIB entry
- */
+
Limits ()
: m_maxLimit (-1)
, m_curMaxLimit (0)
- , m_outstanding (0)
{ }
-
+
+ virtual
+ ~Limits () {}
+
/**
* @brief Set limit for the number of outstanding interests
*/
- void
- SetMaxLimit (double max);
+ virtual void
+ SetMaxLimit (double max)
+ {
+ m_maxLimit = max;
+ m_curMaxLimit = max;
+ }
/**
* @brief Get limit for the number of outstanding interests
*/
- double
- GetMaxLimit () const;
+ virtual double
+ GetMaxLimit () const
+ {
+ return m_maxLimit;
+ }
/**
* @brief Check whether limits are enabled or not
*/
- inline bool
+ virtual inline bool
IsEnabled () const
{
return m_maxLimit > 0.0;
@@ -85,7 +89,7 @@
{
return m_curMaxLimit;
}
-
+
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
@@ -93,20 +97,12 @@
/**
* @brief Check if new interest can be send out, if yes, number of outstanding will be increased
*/
- bool
- IsBelowLimit ();
-
- /**
- * @brief Remove outstanding interests
- */
- void
- RemoveOutstanding ();
+ virtual bool
+ IsBelowLimit () = 0;
-public:
+protected:
double m_maxLimit;
-
TracedValue< double > m_curMaxLimit;
- TracedValue< double > m_outstanding;
};