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 | /** |
| 32 | * \ingroup ndn |
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 | /** |
| 86 | * @brief Check whether limits are enabled or not |
| 87 | */ |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 88 | virtual inline bool |
Alexander Afanasyev | a28ec56 | 2012-10-25 14:07:32 -0700 | [diff] [blame] | 89 | IsEnabled () const |
| 90 | { |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 91 | return m_maxRate > 0.0; |
Alexander Afanasyev | a28ec56 | 2012-10-25 14:07:32 -0700 | [diff] [blame] | 92 | } |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 93 | |
| 94 | /** |
Alexander Afanasyev | a28ec56 | 2012-10-25 14:07:32 -0700 | [diff] [blame] | 95 | * @brief Update a current value of the limit |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 96 | * @param limit Value of current limit. |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 97 | * |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 98 | * 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 Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 102 | */ |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 103 | virtual void |
| 104 | UpdateCurrentLimit (double limit) = 0; |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 105 | |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 106 | /** |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 107 | * @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 Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 120 | */ |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 121 | virtual bool |
| 122 | IsBelowLimit () = 0; |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 123 | |
| 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 Afanasyev | 08ab572 | 2012-11-06 17:22:25 -0800 | [diff] [blame^] | 137 | |
| 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 | |
| 148 | protected: |
| 149 | void |
| 150 | FireAvailableSlotCallback (); |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 151 | |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 152 | private: |
| 153 | double m_maxRate; |
| 154 | double m_maxDelay; |
Alexander Afanasyev | 08ab572 | 2012-11-06 17:22:25 -0800 | [diff] [blame^] | 155 | |
| 156 | CallbackHandler m_handler; |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 157 | }; |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 158 | |
| 159 | |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 160 | } // namespace ndn |
| 161 | } // namespace ns3 |
| 162 | |
| 163 | #endif // _NDN_LIMITS_H_ |