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: |
| 39 | static TypeId |
| 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 | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 45 | Limits () |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 46 | : m_maxRate (-1) |
| 47 | , m_maxDelay (1.0) |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 48 | { } |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 49 | |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 50 | /** |
| 51 | * @brief Virtual destructor |
| 52 | */ |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 53 | virtual |
| 54 | ~Limits () {} |
| 55 | |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 56 | /** |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 57 | * @brief Set limit for the number of outstanding interests |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 58 | * @param rate Maximum rate that needs to be enforced |
| 59 | * @param delay Maximum delay for BDP product for window-based limits |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 60 | */ |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 61 | virtual void |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 62 | SetLimits (double rate, double delay) |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 63 | { |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 64 | m_maxRate = rate; |
| 65 | m_maxDelay = delay; |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 66 | } |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 67 | |
| 68 | /** |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 69 | * @brief Get maximum rate that needs to be enforced |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 70 | */ |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 71 | virtual double |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 72 | GetMaxRate () const |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 73 | { |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 74 | return m_maxRate; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * @brief Get maximum delay for BDP product for window-based limits |
| 79 | */ |
| 80 | virtual double |
| 81 | GetMaxDelay () const |
| 82 | { |
| 83 | return m_maxDelay; |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 84 | } |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 85 | |
| 86 | /** |
| 87 | * @brief Check whether limits are enabled or not |
| 88 | */ |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 89 | virtual inline bool |
Alexander Afanasyev | a28ec56 | 2012-10-25 14:07:32 -0700 | [diff] [blame] | 90 | IsEnabled () const |
| 91 | { |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 92 | return m_maxRate > 0.0; |
Alexander Afanasyev | a28ec56 | 2012-10-25 14:07:32 -0700 | [diff] [blame] | 93 | } |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 94 | |
| 95 | /** |
Alexander Afanasyev | a28ec56 | 2012-10-25 14:07:32 -0700 | [diff] [blame] | 96 | * @brief Update a current value of the limit |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 97 | * @param limit Value of current limit. |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 98 | * |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 99 | * Note that interpretation of this value may be different in different ndn::Limit realizations |
| 100 | * |
| 101 | * All realizations will try to guarantee that if limit is larger than previously set value of maximum limit, |
| 102 | * then the current limit will be limited to that maximum value |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 103 | */ |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 104 | virtual void |
| 105 | UpdateCurrentLimit (double limit) = 0; |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 106 | |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 107 | /** |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 108 | * @brief Get value of the current limit |
| 109 | * |
| 110 | * Note that interpretation of this value may be different in different ndn::Limit realizations |
| 111 | */ |
| 112 | virtual double |
| 113 | GetCurrentLimit () const = 0; |
| 114 | |
| 115 | //////////////////////////////////////////////////////////////////////////// |
| 116 | //////////////////////////////////////////////////////////////////////////// |
| 117 | //////////////////////////////////////////////////////////////////////////// |
| 118 | |
| 119 | /** |
| 120 | * @brief Realization-specific method called to check availability of the limit |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 121 | */ |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 122 | virtual bool |
| 123 | IsBelowLimit () = 0; |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 124 | |
| 125 | /** |
| 126 | * @brief "Borrow" limit |
| 127 | * |
| 128 | * IsBelowLimit **must** be true, otherwise assert fail |
| 129 | */ |
| 130 | virtual void |
| 131 | BorrowLimit () = 0; |
| 132 | |
| 133 | /** |
| 134 | * @brief "Return" limit |
| 135 | */ |
| 136 | virtual void |
| 137 | ReturnLimit () = 0; |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 138 | |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 139 | private: |
| 140 | double m_maxRate; |
| 141 | double m_maxDelay; |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 142 | }; |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 143 | |
| 144 | |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 145 | } // namespace ndn |
| 146 | } // namespace ns3 |
| 147 | |
| 148 | #endif // _NDN_LIMITS_H_ |