Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -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_WINDOW_H_ |
| 22 | #define _NDN_LIMITS_WINDOW_H_ |
| 23 | |
| 24 | #include "ndn-limits.h" |
| 25 | |
| 26 | namespace ns3 { |
| 27 | namespace ndn { |
| 28 | |
| 29 | /** |
| 30 | * \ingroup ndn |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 31 | * \brief Structure to manage limits for outstanding interests (window-based limiting) |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 32 | */ |
| 33 | class LimitsWindow : |
| 34 | public Limits |
| 35 | { |
| 36 | public: |
| 37 | typedef Limits super; |
| 38 | |
| 39 | static TypeId |
| 40 | GetTypeId (); |
| 41 | |
| 42 | /** |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 43 | * @brief Default Constructor |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 44 | */ |
| 45 | LimitsWindow () |
| 46 | : m_outstanding (0) |
| 47 | { } |
| 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 | ~LimitsWindow () { } |
| 54 | |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 55 | // from ndn::Limits |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 56 | |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 57 | virtual void |
| 58 | SetLimits (double rate, double delay) |
| 59 | { |
| 60 | super::SetLimits (rate, delay); |
| 61 | |
| 62 | m_curMaxLimit = GetMaxRate () * GetMaxDelay (); |
| 63 | } |
| 64 | |
Alexander Afanasyev | a8f5d88 | 2012-11-09 14:22:48 -0800 | [diff] [blame] | 65 | virtual |
| 66 | double |
| 67 | GetMaxLimit () const |
| 68 | { |
| 69 | return GetMaxRate () * GetMaxDelay (); |
| 70 | } |
| 71 | |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 72 | virtual void |
| 73 | UpdateCurrentLimit (double limit); |
| 74 | |
| 75 | virtual double |
| 76 | GetCurrentLimit () const |
| 77 | { |
| 78 | return m_curMaxLimit; |
| 79 | } |
| 80 | |
Alexander Afanasyev | a8f5d88 | 2012-11-09 14:22:48 -0800 | [diff] [blame] | 81 | virtual double |
| 82 | GetCurrentLimitRate () const |
| 83 | { |
| 84 | return m_curMaxLimit / GetMaxDelay (); |
| 85 | } |
| 86 | |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 87 | /** |
| 88 | * @brief Check if current interest window (number of pending interests) if less than maximum |
| 89 | */ |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 90 | virtual bool |
| 91 | IsBelowLimit (); |
| 92 | |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 93 | /** |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 94 | * @brief Increase current window of outstanding interests |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 95 | */ |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 96 | virtual void |
| 97 | BorrowLimit (); |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 98 | |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 99 | /** |
| 100 | * @brief Decrease current window of outstanding interests |
| 101 | */ |
| 102 | virtual void |
| 103 | ReturnLimit (); |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 104 | |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 105 | private: |
| 106 | TracedValue< double > m_curMaxLimit; |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 107 | TracedValue< double > m_outstanding; |
| 108 | }; |
| 109 | |
| 110 | |
| 111 | } // namespace ndn |
| 112 | } // namespace ns3 |
| 113 | |
| 114 | #endif // _NDN_LIMITS_WINDOW_H_ |