blob: d8f848b4393748b711ea418057e795f41c420f11 [file] [log] [blame]
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2011 University of California, Los Angeles
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19 */
20
21#ifndef _NDN_LIMITS_H_
22#define _NDN_LIMITS_H_
23
24#include "ns3/ptr.h"
25#include "ns3/object.h"
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070026#include "ns3/traced-value.h"
27
28namespace ns3 {
29namespace ndn {
30
31/**
Alexander Afanasyev79206512013-07-27 16:49:12 -070032 * \ingroup ndn-fw
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070033 * \brief Abstract class to manage Interest limits
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070034 */
35class Limits :
36 public Object
37{
38public:
Alexander Afanasyev08ab5722012-11-06 17:22:25 -080039 typedef Callback<void> CallbackHandler;
40
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070041 static TypeId
42 GetTypeId ();
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070043
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070044 /**
45 * @brief Default constructor
46 */
Alexander Afanasyev08ab5722012-11-06 17:22:25 -080047 Limits ();
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070048
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070049 /**
50 * @brief Virtual destructor
51 */
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070052 virtual
53 ~Limits () {}
54
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070055 /**
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -070056 * @brief Set limit for the number of outstanding interests
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070057 * @param rate Maximum rate that needs to be enforced
58 * @param delay Maximum delay for BDP product for window-based limits
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070059 */
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070060 virtual void
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070061 SetLimits (double rate, double delay)
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070062 {
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070063 m_maxRate = rate;
64 m_maxDelay = delay;
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070065 }
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070066
67 /**
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070068 * @brief Get maximum rate that needs to be enforced
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -070069 */
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070070 virtual double
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070071 GetMaxRate () const
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070072 {
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070073 return m_maxRate;
74 }
75
76 /**
77 * @brief Get maximum delay for BDP product for window-based limits
78 */
79 virtual double
80 GetMaxDelay () const
81 {
82 return m_maxDelay;
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070083 }
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -070084
85 /**
Alexander Afanasyeva8f5d882012-11-09 14:22:48 -080086 * @brief Get maximum limit (interpretation of the limit depends on realization)
87 */
88 virtual
89 double
90 GetMaxLimit () const = 0;
91
92 /**
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -070093 * @brief Check whether limits are enabled or not
94 */
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070095 virtual inline bool
Alexander Afanasyeva28ec562012-10-25 14:07:32 -070096 IsEnabled () const
97 {
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070098 return m_maxRate > 0.0;
Alexander Afanasyeva28ec562012-10-25 14:07:32 -070099 }
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -0700100
101 /**
Alexander Afanasyeva28ec562012-10-25 14:07:32 -0700102 * @brief Update a current value of the limit
Alexander Afanasyev6f95e702012-10-31 16:27:31 -0700103 * @param limit Value of current limit.
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -0700104 *
Alexander Afanasyev6f95e702012-10-31 16:27:31 -0700105 * Note that interpretation of this value may be different in different ndn::Limit realizations
106 *
107 * All realizations will try to guarantee that if limit is larger than previously set value of maximum limit,
108 * then the current limit will be limited to that maximum value
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700109 */
Alexander Afanasyev6f95e702012-10-31 16:27:31 -0700110 virtual void
111 UpdateCurrentLimit (double limit) = 0;
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700112
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700113 /**
Alexander Afanasyev6f95e702012-10-31 16:27:31 -0700114 * @brief Get value of the current limit
115 *
116 * Note that interpretation of this value may be different in different ndn::Limit realizations
117 */
118 virtual double
119 GetCurrentLimit () const = 0;
Alexander Afanasyeva8f5d882012-11-09 14:22:48 -0800120
121 /**
122 * @brief Get value of the current limit in terms of maximum rate that needs to be enforced
123 *
124 * Compared to GetCurrentLimit, this method guarantees that the returned value is maximum number of packets
125 * that can be send out within one second (max "rate")
126 */
127 virtual double
128 GetCurrentLimitRate () const = 0;
Alexander Afanasyev6f95e702012-10-31 16:27:31 -0700129
130 ////////////////////////////////////////////////////////////////////////////
131 ////////////////////////////////////////////////////////////////////////////
132 ////////////////////////////////////////////////////////////////////////////
133
134 /**
135 * @brief Realization-specific method called to check availability of the limit
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700136 */
Alexander Afanasyevf5c07742012-10-31 13:13:05 -0700137 virtual bool
138 IsBelowLimit () = 0;
Alexander Afanasyev6f95e702012-10-31 16:27:31 -0700139
140 /**
141 * @brief "Borrow" limit
142 *
143 * IsBelowLimit **must** be true, otherwise assert fail
144 */
145 virtual void
146 BorrowLimit () = 0;
147
148 /**
149 * @brief "Return" limit
150 */
151 virtual void
152 ReturnLimit () = 0;
Alexander Afanasyev08ab5722012-11-06 17:22:25 -0800153
Alexander Afanasyeva8f5d882012-11-09 14:22:48 -0800154 /**
155 * @brief Set link delay (in seconds)
156 *
157 * This is a supplementary information that may or may not be useful for limits
158 */
159 virtual void
160 SetLinkDelay (double delay)
161 {
162 m_linkDelay = delay;
163 }
164
165 /**
166 * @brief Get link delay (in seconds)
167 */
168 virtual double
169 GetLinkDelay () const
170 {
171 return m_linkDelay;
172 }
173
Alexander Afanasyev08ab5722012-11-06 17:22:25 -0800174 ////////////////////////////////////////////////////////////////////////////
175 ////////////////////////////////////////////////////////////////////////////
176 ////////////////////////////////////////////////////////////////////////////
177
178 /**
179 * @brief Set callback which will be called when exhausted limit gets a new slot
180 */
181 void
182 RegisterAvailableSlotCallback (CallbackHandler handler);
183
184protected:
185 void
186 FireAvailableSlotCallback ();
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700187
Alexander Afanasyev6f95e702012-10-31 16:27:31 -0700188private:
189 double m_maxRate;
190 double m_maxDelay;
Alexander Afanasyev08ab5722012-11-06 17:22:25 -0800191
192 CallbackHandler m_handler;
Alexander Afanasyeva8f5d882012-11-09 14:22:48 -0800193
194 double m_linkDelay;
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700195};
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -0700196
197
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700198} // namespace ndn
199} // namespace ns3
200
201#endif // _NDN_LIMITS_H_