blob: ebb8d151774fc4719df5165ca2dee2f4608ffd10 [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_
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080022#define _NDN_LIMITS_H_
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070023
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 Afanasyevbe55cf62014-12-20 17:51:09 -080033 * \brief Abstract class to manage Interest limits
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070034 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080035class Limits : public Object {
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070036public:
Alexander Afanasyev08ab5722012-11-06 17:22:25 -080037 typedef Callback<void> CallbackHandler;
38
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070039 static TypeId
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080040 GetTypeId();
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070041
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070042 /**
43 * @brief Default constructor
44 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080045 Limits();
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070046
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070047 /**
48 * @brief Virtual destructor
49 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080050 virtual ~Limits()
51 {
52 }
53
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070054 /**
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -070055 * @brief Set limit for the number of outstanding interests
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070056 * @param rate Maximum rate that needs to be enforced
57 * @param delay Maximum delay for BDP product for window-based limits
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070058 */
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070059 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080060 SetLimits(double rate, double delay)
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070061 {
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070062 m_maxRate = rate;
63 m_maxDelay = delay;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080064 }
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070065
66 /**
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070067 * @brief Get maximum rate that needs to be enforced
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -070068 */
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070069 virtual double
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080070 GetMaxRate() const
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070071 {
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070072 return m_maxRate;
73 }
74
75 /**
76 * @brief Get maximum delay for BDP product for window-based limits
77 */
78 virtual double
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080079 GetMaxDelay() const
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070080 {
81 return m_maxDelay;
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070082 }
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -070083
84 /**
Alexander Afanasyeva8f5d882012-11-09 14:22:48 -080085 * @brief Get maximum limit (interpretation of the limit depends on realization)
86 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080087 virtual double
88 GetMaxLimit() const = 0;
Alexander Afanasyeva8f5d882012-11-09 14:22:48 -080089
90 /**
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -070091 * @brief Check whether limits are enabled or not
92 */
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070093 virtual inline bool
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080094 IsEnabled() const
Alexander Afanasyeva28ec562012-10-25 14:07:32 -070095 {
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070096 return m_maxRate > 0.0;
Alexander Afanasyeva28ec562012-10-25 14:07:32 -070097 }
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -070098
99 /**
Alexander Afanasyeva28ec562012-10-25 14:07:32 -0700100 * @brief Update a current value of the limit
Alexander Afanasyev6f95e702012-10-31 16:27:31 -0700101 * @param limit Value of current limit.
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -0700102 *
Alexander Afanasyev6f95e702012-10-31 16:27:31 -0700103 * Note that interpretation of this value may be different in different ndn::Limit realizations
104 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800105 * All realizations will try to guarantee that if limit is larger than previously set value of
106 *maximum limit,
Alexander Afanasyev6f95e702012-10-31 16:27:31 -0700107 * then the current limit will be limited to that maximum value
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700108 */
Alexander Afanasyev6f95e702012-10-31 16:27:31 -0700109 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800110 UpdateCurrentLimit(double limit) = 0;
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700111
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700112 /**
Alexander Afanasyev6f95e702012-10-31 16:27:31 -0700113 * @brief Get value of the current limit
114 *
115 * Note that interpretation of this value may be different in different ndn::Limit realizations
116 */
117 virtual double
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800118 GetCurrentLimit() const = 0;
Alexander Afanasyeva8f5d882012-11-09 14:22:48 -0800119
120 /**
121 * @brief Get value of the current limit in terms of maximum rate that needs to be enforced
122 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800123 * Compared to GetCurrentLimit, this method guarantees that the returned value is maximum number
124 *of packets
Alexander Afanasyeva8f5d882012-11-09 14:22:48 -0800125 * that can be send out within one second (max "rate")
126 */
127 virtual double
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800128 GetCurrentLimitRate() const = 0;
129
Alexander Afanasyev6f95e702012-10-31 16:27:31 -0700130 ////////////////////////////////////////////////////////////////////////////
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
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800138 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
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800146 BorrowLimit() = 0;
Alexander Afanasyev6f95e702012-10-31 16:27:31 -0700147
148 /**
149 * @brief "Return" limit
150 */
151 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800152 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
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800160 SetLinkDelay(double delay)
Alexander Afanasyeva8f5d882012-11-09 14:22:48 -0800161 {
162 m_linkDelay = delay;
163 }
164
165 /**
166 * @brief Get link delay (in seconds)
167 */
168 virtual double
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800169 GetLinkDelay() const
Alexander Afanasyeva8f5d882012-11-09 14:22:48 -0800170 {
171 return m_linkDelay;
172 }
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800173
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
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800182 RegisterAvailableSlotCallback(CallbackHandler handler);
Alexander Afanasyev08ab5722012-11-06 17:22:25 -0800183
184protected:
185 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800186 FireAvailableSlotCallback();
187
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
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700197} // namespace ndn
198} // namespace ns3
199
200#endif // _NDN_LIMITS_H_