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_ |
| 22 | #define _NDN_LIMITS_H_ |
| 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 | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 33 | * \brief Abstract class to manage Interest limits |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 34 | */ |
| 35 | class Limits : |
| 36 | public Object |
| 37 | { |
| 38 | public: |
Alexander Afanasyev | 08ab572 | 2012-11-06 17:22:25 -0800 | [diff] [blame] | 39 | typedef Callback<void> CallbackHandler; |
| 40 | |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 41 | static TypeId |
| 42 | GetTypeId (); |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 43 | |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 44 | /** |
| 45 | * @brief Default constructor |
| 46 | */ |
Alexander Afanasyev | 08ab572 | 2012-11-06 17:22:25 -0800 | [diff] [blame] | 47 | Limits (); |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 48 | |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 49 | /** |
| 50 | * @brief Virtual destructor |
| 51 | */ |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 52 | virtual |
| 53 | ~Limits () {} |
| 54 | |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 55 | /** |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 56 | * @brief Set limit for the number of outstanding interests |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 57 | * @param rate Maximum rate that needs to be enforced |
| 58 | * @param delay Maximum delay for BDP product for window-based limits |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 59 | */ |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 60 | virtual void |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 61 | SetLimits (double rate, double delay) |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 62 | { |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 63 | m_maxRate = rate; |
| 64 | m_maxDelay = delay; |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 65 | } |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 66 | |
| 67 | /** |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 68 | * @brief Get maximum rate that needs to be enforced |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 69 | */ |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 70 | virtual double |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 71 | GetMaxRate () const |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 72 | { |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 73 | 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 Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 83 | } |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 84 | |
| 85 | /** |
Alexander Afanasyev | a8f5d88 | 2012-11-09 14:22:48 -0800 | [diff] [blame] | 86 | * @brief Get maximum limit (interpretation of the limit depends on realization) |
| 87 | */ |
| 88 | virtual |
| 89 | double |
| 90 | GetMaxLimit () const = 0; |
| 91 | |
| 92 | /** |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 93 | * @brief Check whether limits are enabled or not |
| 94 | */ |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 95 | virtual inline bool |
Alexander Afanasyev | a28ec56 | 2012-10-25 14:07:32 -0700 | [diff] [blame] | 96 | IsEnabled () const |
| 97 | { |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 98 | return m_maxRate > 0.0; |
Alexander Afanasyev | a28ec56 | 2012-10-25 14:07:32 -0700 | [diff] [blame] | 99 | } |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 100 | |
| 101 | /** |
Alexander Afanasyev | a28ec56 | 2012-10-25 14:07:32 -0700 | [diff] [blame] | 102 | * @brief Update a current value of the limit |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 103 | * @param limit Value of current limit. |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 104 | * |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 105 | * 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 Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 109 | */ |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 110 | virtual void |
| 111 | UpdateCurrentLimit (double limit) = 0; |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 112 | |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 113 | /** |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 114 | * @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 Afanasyev | a8f5d88 | 2012-11-09 14:22:48 -0800 | [diff] [blame] | 120 | |
| 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 Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 129 | |
| 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 |
| 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 |
| 146 | BorrowLimit () = 0; |
| 147 | |
| 148 | /** |
| 149 | * @brief "Return" limit |
| 150 | */ |
| 151 | virtual void |
| 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 |
| 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 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 |
| 182 | RegisterAvailableSlotCallback (CallbackHandler handler); |
| 183 | |
| 184 | protected: |
| 185 | void |
| 186 | FireAvailableSlotCallback (); |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 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 | |
| 197 | |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 198 | } // namespace ndn |
| 199 | } // namespace ns3 |
| 200 | |
| 201 | #endif // _NDN_LIMITS_H_ |