blob: 5fdad53a8dbca03c80b08442003d98e77a7d86f0 [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/**
32 * \ingroup ndn
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 /**
86 * @brief Check whether limits are enabled or not
87 */
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070088 virtual inline bool
Alexander Afanasyeva28ec562012-10-25 14:07:32 -070089 IsEnabled () const
90 {
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070091 return m_maxRate > 0.0;
Alexander Afanasyeva28ec562012-10-25 14:07:32 -070092 }
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -070093
94 /**
Alexander Afanasyeva28ec562012-10-25 14:07:32 -070095 * @brief Update a current value of the limit
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070096 * @param limit Value of current limit.
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -070097 *
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070098 * Note that interpretation of this value may be different in different ndn::Limit realizations
99 *
100 * All realizations will try to guarantee that if limit is larger than previously set value of maximum limit,
101 * then the current limit will be limited to that maximum value
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700102 */
Alexander Afanasyev6f95e702012-10-31 16:27:31 -0700103 virtual void
104 UpdateCurrentLimit (double limit) = 0;
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700105
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700106 /**
Alexander Afanasyev6f95e702012-10-31 16:27:31 -0700107 * @brief Get value of the current limit
108 *
109 * Note that interpretation of this value may be different in different ndn::Limit realizations
110 */
111 virtual double
112 GetCurrentLimit () const = 0;
113
114 ////////////////////////////////////////////////////////////////////////////
115 ////////////////////////////////////////////////////////////////////////////
116 ////////////////////////////////////////////////////////////////////////////
117
118 /**
119 * @brief Realization-specific method called to check availability of the limit
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700120 */
Alexander Afanasyevf5c07742012-10-31 13:13:05 -0700121 virtual bool
122 IsBelowLimit () = 0;
Alexander Afanasyev6f95e702012-10-31 16:27:31 -0700123
124 /**
125 * @brief "Borrow" limit
126 *
127 * IsBelowLimit **must** be true, otherwise assert fail
128 */
129 virtual void
130 BorrowLimit () = 0;
131
132 /**
133 * @brief "Return" limit
134 */
135 virtual void
136 ReturnLimit () = 0;
Alexander Afanasyev08ab5722012-11-06 17:22:25 -0800137
138 ////////////////////////////////////////////////////////////////////////////
139 ////////////////////////////////////////////////////////////////////////////
140 ////////////////////////////////////////////////////////////////////////////
141
142 /**
143 * @brief Set callback which will be called when exhausted limit gets a new slot
144 */
145 void
146 RegisterAvailableSlotCallback (CallbackHandler handler);
147
148protected:
149 void
150 FireAvailableSlotCallback ();
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700151
Alexander Afanasyev6f95e702012-10-31 16:27:31 -0700152private:
153 double m_maxRate;
154 double m_maxDelay;
Alexander Afanasyev08ab5722012-11-06 17:22:25 -0800155
156 CallbackHandler m_handler;
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700157};
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -0700158
159
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700160} // namespace ndn
161} // namespace ns3
162
163#endif // _NDN_LIMITS_H_