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" |
| 26 | #include "ns3/nstime.h" |
| 27 | #include "ns3/traced-value.h" |
| 28 | |
| 29 | namespace ns3 { |
| 30 | namespace ndn { |
| 31 | |
| 32 | /** |
| 33 | * \ingroup ndn |
| 34 | * \brief Structure to manage limits for outstanding interests |
| 35 | */ |
| 36 | class Limits : |
| 37 | public Object |
| 38 | { |
| 39 | public: |
| 40 | static TypeId |
| 41 | GetTypeId (); |
| 42 | |
| 43 | /** |
| 44 | * \brief Constructor |
| 45 | * \param prefix smart pointer to the prefix for the FIB entry |
| 46 | */ |
| 47 | Limits () |
| 48 | : m_maxLimit (0) |
| 49 | , m_curMaxLimit (0) |
| 50 | , m_outstanding (0) |
| 51 | { } |
| 52 | |
| 53 | /** |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 54 | * @brief Set limit for the number of outstanding interests |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 55 | */ |
| 56 | void |
| 57 | SetMaxLimit (uint32_t max); |
| 58 | |
| 59 | /** |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 60 | * @brief Get limit for the number of outstanding interests |
| 61 | */ |
| 62 | uint32_t |
| 63 | GetMaxLimit () const; |
| 64 | |
| 65 | /** |
| 66 | * @brief Check whether limits are enabled or not |
| 67 | */ |
| 68 | inline bool |
| 69 | IsEnabled () const; |
| 70 | |
| 71 | /** |
| 72 | * @brief Decay current limit (exponential decaying) |
| 73 | * |
| 74 | * If needed, this method should be called externally periodically (doesn't matter how often, decaying amount will remain the same). |
| 75 | * Decaying is most likely needed for per-prefix limits, but definitely not needed for per-face limits. |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 76 | */ |
| 77 | void |
| 78 | DecayCurrentLimit (); |
| 79 | |
| 80 | /** |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 81 | * @brief Increase current limit (additive increase) |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 82 | */ |
| 83 | void |
| 84 | IncreaseLimit (); |
| 85 | |
| 86 | /** |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 87 | * @brief Decrease current limit (multiplicative decrease) |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 88 | */ |
| 89 | void |
| 90 | DecreaseLimit (); |
| 91 | |
| 92 | //////////////////////////////////////////////////////////////////////////// |
| 93 | //////////////////////////////////////////////////////////////////////////// |
| 94 | //////////////////////////////////////////////////////////////////////////// |
| 95 | |
| 96 | /** |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 97 | * @brief Check if new interest can be send out, if yes, number of outstanding will be increased |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 98 | */ |
| 99 | bool |
| 100 | IsBelowLimit (); |
| 101 | |
| 102 | /** |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 103 | * @brief Remove outstanding interests |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 104 | */ |
| 105 | void |
| 106 | RemoveOutstanding (); |
| 107 | |
| 108 | public: |
| 109 | uint32_t m_maxLimit; |
| 110 | |
| 111 | TracedValue< double > m_curMaxLimit; |
| 112 | TracedValue< uint32_t > m_outstanding; |
| 113 | |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 114 | Time m_exponentialDecayTau; |
| 115 | Time m_nonDecreasePeriod; |
| 116 | double m_additiveIncrease; |
| 117 | double m_multiplicativeDecrease; |
| 118 | |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 119 | Time m_lastDecrease; |
| 120 | Time m_lastDecay; |
| 121 | }; |
| 122 | |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 123 | inline bool |
| 124 | Limits::IsEnabled () const |
| 125 | { |
| 126 | return m_maxLimit != 0; |
| 127 | } |
| 128 | |
| 129 | |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 130 | } // namespace ndn |
| 131 | } // namespace ns3 |
| 132 | |
| 133 | #endif // _NDN_LIMITS_H_ |