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_ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 22 | #define _NDN_LIMITS_RATE_H_ |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 23 | |
Alexander Afanasyev | 0c39537 | 2014-12-20 15:54:02 -0800 | [diff] [blame] | 24 | #include "ndn-limits.hpp" |
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 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 34 | class LimitsRate : public Limits { |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 35 | public: |
| 36 | typedef Limits super; |
Alexander Afanasyev | dc115ef | 2013-02-13 12:06:55 -0800 | [diff] [blame] | 37 | |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 38 | static TypeId |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 39 | GetTypeId(); |
Alexander Afanasyev | dc115ef | 2013-02-13 12:06:55 -0800 | [diff] [blame] | 40 | |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 41 | /** |
| 42 | * \brief Constructor |
| 43 | * \param prefix smart pointer to the prefix for the FIB entry |
| 44 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 45 | LimitsRate() |
| 46 | : m_isLeakScheduled(false) |
| 47 | , m_bucketMax(0) |
| 48 | , m_bucketLeak(1) |
| 49 | , m_bucket(0) |
| 50 | { |
| 51 | } |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 52 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 53 | virtual ~LimitsRate() |
| 54 | { |
| 55 | } |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 56 | |
| 57 | virtual void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 58 | SetLimits(double rate, double delay); |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 59 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 60 | virtual double |
| 61 | GetMaxLimit() const |
Alexander Afanasyev | a8f5d88 | 2012-11-09 14:22:48 -0800 | [diff] [blame] | 62 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 63 | return GetMaxRate(); |
Alexander Afanasyev | a8f5d88 | 2012-11-09 14:22:48 -0800 | [diff] [blame] | 64 | } |
| 65 | |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 66 | /** |
| 67 | * @brief Check if Interest limit is reached (token bucket is not empty) |
| 68 | */ |
| 69 | virtual bool |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 70 | IsBelowLimit(); |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 71 | |
| 72 | /** |
| 73 | * @brief Get token from the bucket |
| 74 | */ |
| 75 | virtual void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 76 | BorrowLimit(); |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 77 | |
| 78 | /** |
| 79 | * @brief Does nothing (token bucket leakage is time-dependent only) |
| 80 | */ |
| 81 | virtual void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 82 | ReturnLimit(); |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 83 | |
| 84 | /** |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 85 | * @brief Update normalized amount that should be leaked every second (token bucket leak rate) and |
| 86 | * leak rate |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 87 | */ |
| 88 | virtual void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 89 | UpdateCurrentLimit(double limit); |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 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 |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 95 | GetCurrentLimit() const |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 96 | { |
| 97 | return m_bucketLeak; |
| 98 | } |
| 99 | |
Alexander Afanasyev | a8f5d88 | 2012-11-09 14:22:48 -0800 | [diff] [blame] | 100 | virtual double |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 101 | GetCurrentLimitRate() const |
Alexander Afanasyev | a8f5d88 | 2012-11-09 14:22:48 -0800 | [diff] [blame] | 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 |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 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 |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 118 | LeakBucket(double interval); |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 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 | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 123 | double m_bucketMax; ///< \brief Maximum Interest allowance for this face (maximum tokens that can |
| 124 | /// be issued at the same time) |
| 125 | double m_bucketLeak; ///< \brief Normalized amount that should be leaked every second (token |
| 126 | /// bucket leak rate) |
| 127 | double m_bucket; ///< \brief Value representing current size of the Interest allowance for this |
| 128 | /// face (current size of token bucket) |
Alexander Afanasyev | dc115ef | 2013-02-13 12:06:55 -0800 | [diff] [blame] | 129 | |
| 130 | Time m_leakRandomizationInteral; |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 131 | }; |
Alexander Afanasyev | dc115ef | 2013-02-13 12:06:55 -0800 | [diff] [blame] | 132 | |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 133 | } // namespace ndn |
| 134 | } // namespace ns3 |
| 135 | |
| 136 | #endif // _NDN_LIMITS_RATE_H_ |