Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -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_RATE_H_ |
| 22 | #define _NDN_LIMITS_RATE_H_ |
| 23 | |
| 24 | #include "ndn-limits.h" |
Alexander Afanasyev | dc115ef | 2013-02-13 12:06:55 -0800 | [diff] [blame] | 25 | #include <ns3/nstime.h> |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 26 | |
| 27 | namespace ns3 { |
| 28 | namespace ndn { |
| 29 | |
| 30 | /** |
Alexander Afanasyev | 7920651 | 2013-07-27 16:49:12 -0700 | [diff] [blame] | 31 | * \ingroup ndn-fw |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 32 | * \brief Structure to manage limits for outstanding interests |
| 33 | */ |
| 34 | class LimitsRate : |
| 35 | public Limits |
| 36 | { |
| 37 | public: |
| 38 | typedef Limits super; |
Alexander Afanasyev | dc115ef | 2013-02-13 12:06:55 -0800 | [diff] [blame] | 39 | |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 40 | static TypeId |
| 41 | GetTypeId (); |
Alexander Afanasyev | dc115ef | 2013-02-13 12:06:55 -0800 | [diff] [blame] | 42 | |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 43 | /** |
| 44 | * \brief Constructor |
| 45 | * \param prefix smart pointer to the prefix for the FIB entry |
| 46 | */ |
| 47 | LimitsRate () |
Alexander Afanasyev | 7e4235a | 2012-10-31 16:58:44 -0700 | [diff] [blame] | 48 | : m_isLeakScheduled (false) |
| 49 | , m_bucketMax (0) |
| 50 | , m_bucketLeak (1) |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 51 | , m_bucket (0) |
| 52 | { } |
| 53 | |
| 54 | virtual |
| 55 | ~LimitsRate () { } |
| 56 | |
| 57 | virtual void |
Alexander Afanasyev | ccd5bb4 | 2012-10-31 17:27:49 -0700 | [diff] [blame] | 58 | SetLimits (double rate, double delay); |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 59 | |
Alexander Afanasyev | a8f5d88 | 2012-11-09 14:22:48 -0800 | [diff] [blame] | 60 | virtual |
| 61 | double |
| 62 | GetMaxLimit () const |
| 63 | { |
| 64 | return GetMaxRate (); |
| 65 | } |
| 66 | |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 67 | /** |
| 68 | * @brief Check if Interest limit is reached (token bucket is not empty) |
| 69 | */ |
| 70 | virtual bool |
| 71 | IsBelowLimit (); |
| 72 | |
| 73 | /** |
| 74 | * @brief Get token from the bucket |
| 75 | */ |
| 76 | virtual void |
| 77 | BorrowLimit (); |
| 78 | |
| 79 | /** |
| 80 | * @brief Does nothing (token bucket leakage is time-dependent only) |
| 81 | */ |
| 82 | virtual void |
| 83 | ReturnLimit (); |
| 84 | |
| 85 | /** |
Alexander Afanasyev | ccd5bb4 | 2012-10-31 17:27:49 -0700 | [diff] [blame] | 86 | * @brief Update normalized amount that should be leaked every second (token bucket leak rate) and leak rate |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 87 | */ |
| 88 | virtual void |
| 89 | UpdateCurrentLimit (double limit); |
| 90 | |
| 91 | /** |
Alexander Afanasyev | ccd5bb4 | 2012-10-31 17:27:49 -0700 | [diff] [blame] | 92 | * @brief Get normalized amount that should be leaked every second (token bucket leak rate) |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 93 | */ |
| 94 | virtual double |
| 95 | GetCurrentLimit () const |
| 96 | { |
| 97 | return m_bucketLeak; |
| 98 | } |
| 99 | |
Alexander Afanasyev | a8f5d88 | 2012-11-09 14:22:48 -0800 | [diff] [blame] | 100 | virtual double |
| 101 | GetCurrentLimitRate () const |
| 102 | { |
| 103 | return m_bucketLeak; |
| 104 | } |
Alexander Afanasyev | dc115ef | 2013-02-13 12:06:55 -0800 | [diff] [blame] | 105 | |
Alexander Afanasyev | 7e4235a | 2012-10-31 16:58:44 -0700 | [diff] [blame] | 106 | protected: |
| 107 | // from Node |
| 108 | void |
| 109 | NotifyNewAggregate (); |
Alexander Afanasyev | dc115ef | 2013-02-13 12:06:55 -0800 | [diff] [blame] | 110 | |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 111 | private: |
| 112 | /** |
| 113 | * @brief Leak bucket, assuming `interval' seconds between leakages |
| 114 | * |
| 115 | * @param interval Time interval for leakage. Used to calculate size of the leak |
| 116 | */ |
| 117 | void |
| 118 | LeakBucket (double interval); |
| 119 | |
| 120 | private: |
Alexander Afanasyev | 7e4235a | 2012-10-31 16:58:44 -0700 | [diff] [blame] | 121 | bool m_isLeakScheduled; |
Alexander Afanasyev | dc115ef | 2013-02-13 12:06:55 -0800 | [diff] [blame] | 122 | |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 123 | double m_bucketMax; ///< \brief Maximum Interest allowance for this face (maximum tokens that can be issued at the same time) |
| 124 | double m_bucketLeak; ///< \brief Normalized amount that should be leaked every second (token bucket leak rate) |
| 125 | double m_bucket; ///< \brief Value representing current size of the Interest allowance for this face (current size of token bucket) |
Alexander Afanasyev | dc115ef | 2013-02-13 12:06:55 -0800 | [diff] [blame] | 126 | |
| 127 | Time m_leakRandomizationInteral; |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 128 | }; |
Alexander Afanasyev | dc115ef | 2013-02-13 12:06:55 -0800 | [diff] [blame] | 129 | |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 130 | |
| 131 | } // namespace ndn |
| 132 | } // namespace ns3 |
| 133 | |
| 134 | #endif // _NDN_LIMITS_RATE_H_ |