Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 1 | /* -*- 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 Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 22 | #define _NDN_LIMITS_H_ |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 23 | |
| 24 | #include "ns3/ptr.h" |
| 25 | #include "ns3/object.h" |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 26 | #include "ns3/traced-value.h" |
| 27 | |
| 28 | namespace ns3 { |
| 29 | namespace ndn { |
| 30 | |
| 31 | /** |
Alexander Afanasyev | 7920651 | 2013-07-27 16:49:12 -0700 | [diff] [blame] | 32 | * \ingroup ndn-fw |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 33 | * \brief Abstract class to manage Interest limits |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 34 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 35 | class Limits : public Object { |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 36 | public: |
Alexander Afanasyev | 08ab572 | 2012-11-06 17:22:25 -0800 | [diff] [blame] | 37 | typedef Callback<void> CallbackHandler; |
| 38 | |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 39 | static TypeId |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 40 | GetTypeId(); |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 41 | |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 42 | /** |
| 43 | * @brief Default constructor |
| 44 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 45 | Limits(); |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 46 | |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 47 | /** |
| 48 | * @brief Virtual destructor |
| 49 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 50 | virtual ~Limits() |
| 51 | { |
| 52 | } |
| 53 | |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 54 | /** |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 55 | * @brief Set limit for the number of outstanding interests |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 56 | * @param rate Maximum rate that needs to be enforced |
| 57 | * @param delay Maximum delay for BDP product for window-based limits |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 58 | */ |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 59 | virtual void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 60 | SetLimits(double rate, double delay) |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 61 | { |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 62 | m_maxRate = rate; |
| 63 | m_maxDelay = delay; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 64 | } |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 65 | |
| 66 | /** |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 67 | * @brief Get maximum rate that needs to be enforced |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 68 | */ |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 69 | virtual double |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 70 | GetMaxRate() const |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 71 | { |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 72 | return m_maxRate; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * @brief Get maximum delay for BDP product for window-based limits |
| 77 | */ |
| 78 | virtual double |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 79 | GetMaxDelay() const |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 80 | { |
| 81 | return m_maxDelay; |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 82 | } |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 83 | |
| 84 | /** |
Alexander Afanasyev | a8f5d88 | 2012-11-09 14:22:48 -0800 | [diff] [blame] | 85 | * @brief Get maximum limit (interpretation of the limit depends on realization) |
| 86 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 87 | virtual double |
| 88 | GetMaxLimit() const = 0; |
Alexander Afanasyev | a8f5d88 | 2012-11-09 14:22:48 -0800 | [diff] [blame] | 89 | |
| 90 | /** |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 91 | * @brief Check whether limits are enabled or not |
| 92 | */ |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 93 | virtual inline bool |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 94 | IsEnabled() const |
Alexander Afanasyev | a28ec56 | 2012-10-25 14:07:32 -0700 | [diff] [blame] | 95 | { |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 96 | return m_maxRate > 0.0; |
Alexander Afanasyev | a28ec56 | 2012-10-25 14:07:32 -0700 | [diff] [blame] | 97 | } |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 98 | |
| 99 | /** |
Alexander Afanasyev | a28ec56 | 2012-10-25 14:07:32 -0700 | [diff] [blame] | 100 | * @brief Update a current value of the limit |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 101 | * @param limit Value of current limit. |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 102 | * |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 103 | * Note that interpretation of this value may be different in different ndn::Limit realizations |
| 104 | * |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 105 | * All realizations will try to guarantee that if limit is larger than previously set value of |
| 106 | *maximum limit, |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 107 | * then the current limit will be limited to that maximum value |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 108 | */ |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 109 | virtual void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 110 | UpdateCurrentLimit(double limit) = 0; |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 111 | |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 112 | /** |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 113 | * @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 Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 118 | GetCurrentLimit() const = 0; |
Alexander Afanasyev | a8f5d88 | 2012-11-09 14:22:48 -0800 | [diff] [blame] | 119 | |
| 120 | /** |
| 121 | * @brief Get value of the current limit in terms of maximum rate that needs to be enforced |
| 122 | * |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 123 | * Compared to GetCurrentLimit, this method guarantees that the returned value is maximum number |
| 124 | *of packets |
Alexander Afanasyev | a8f5d88 | 2012-11-09 14:22:48 -0800 | [diff] [blame] | 125 | * that can be send out within one second (max "rate") |
| 126 | */ |
| 127 | virtual double |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 128 | GetCurrentLimitRate() const = 0; |
| 129 | |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 130 | //////////////////////////////////////////////////////////////////////////// |
| 131 | //////////////////////////////////////////////////////////////////////////// |
| 132 | //////////////////////////////////////////////////////////////////////////// |
| 133 | |
| 134 | /** |
| 135 | * @brief Realization-specific method called to check availability of the limit |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 136 | */ |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 137 | virtual bool |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 138 | IsBelowLimit() = 0; |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 139 | |
| 140 | /** |
| 141 | * @brief "Borrow" limit |
| 142 | * |
| 143 | * IsBelowLimit **must** be true, otherwise assert fail |
| 144 | */ |
| 145 | virtual void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 146 | BorrowLimit() = 0; |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 147 | |
| 148 | /** |
| 149 | * @brief "Return" limit |
| 150 | */ |
| 151 | virtual void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 152 | ReturnLimit() = 0; |
Alexander Afanasyev | 08ab572 | 2012-11-06 17:22:25 -0800 | [diff] [blame] | 153 | |
Alexander Afanasyev | a8f5d88 | 2012-11-09 14:22:48 -0800 | [diff] [blame] | 154 | /** |
| 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 Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 160 | SetLinkDelay(double delay) |
Alexander Afanasyev | a8f5d88 | 2012-11-09 14:22:48 -0800 | [diff] [blame] | 161 | { |
| 162 | m_linkDelay = delay; |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * @brief Get link delay (in seconds) |
| 167 | */ |
| 168 | virtual double |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 169 | GetLinkDelay() const |
Alexander Afanasyev | a8f5d88 | 2012-11-09 14:22:48 -0800 | [diff] [blame] | 170 | { |
| 171 | return m_linkDelay; |
| 172 | } |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 173 | |
Alexander Afanasyev | 08ab572 | 2012-11-06 17:22:25 -0800 | [diff] [blame] | 174 | //////////////////////////////////////////////////////////////////////////// |
| 175 | //////////////////////////////////////////////////////////////////////////// |
| 176 | //////////////////////////////////////////////////////////////////////////// |
| 177 | |
| 178 | /** |
| 179 | * @brief Set callback which will be called when exhausted limit gets a new slot |
| 180 | */ |
| 181 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 182 | RegisterAvailableSlotCallback(CallbackHandler handler); |
Alexander Afanasyev | 08ab572 | 2012-11-06 17:22:25 -0800 | [diff] [blame] | 183 | |
| 184 | protected: |
| 185 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 186 | FireAvailableSlotCallback(); |
| 187 | |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 188 | private: |
| 189 | double m_maxRate; |
| 190 | double m_maxDelay; |
Alexander Afanasyev | 08ab572 | 2012-11-06 17:22:25 -0800 | [diff] [blame] | 191 | |
| 192 | CallbackHandler m_handler; |
Alexander Afanasyev | a8f5d88 | 2012-11-09 14:22:48 -0800 | [diff] [blame] | 193 | |
| 194 | double m_linkDelay; |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 195 | }; |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 196 | |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 197 | } // namespace ndn |
| 198 | } // namespace ns3 |
| 199 | |
| 200 | #endif // _NDN_LIMITS_H_ |