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 |
| 33 | * \brief Structure to manage limits for outstanding interests |
| 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 | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 42 | Limits () |
Alexander Afanasyev | a28ec56 | 2012-10-25 14:07:32 -0700 | [diff] [blame] | 43 | : m_maxLimit (-1) |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 44 | , m_curMaxLimit (0) |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 45 | { } |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame^] | 46 | |
| 47 | virtual |
| 48 | ~Limits () {} |
| 49 | |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 50 | /** |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 51 | * @brief Set limit for the number of outstanding interests |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 52 | */ |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame^] | 53 | virtual void |
| 54 | SetMaxLimit (double max) |
| 55 | { |
| 56 | m_maxLimit = max; |
| 57 | m_curMaxLimit = max; |
| 58 | } |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 59 | |
| 60 | /** |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 61 | * @brief Get limit for the number of outstanding interests |
| 62 | */ |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame^] | 63 | virtual double |
| 64 | GetMaxLimit () const |
| 65 | { |
| 66 | return m_maxLimit; |
| 67 | } |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 68 | |
| 69 | /** |
| 70 | * @brief Check whether limits are enabled or not |
| 71 | */ |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame^] | 72 | virtual inline bool |
Alexander Afanasyev | a28ec56 | 2012-10-25 14:07:32 -0700 | [diff] [blame] | 73 | IsEnabled () const |
| 74 | { |
| 75 | return m_maxLimit > 0.0; |
| 76 | } |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 77 | |
| 78 | /** |
Alexander Afanasyev | a28ec56 | 2012-10-25 14:07:32 -0700 | [diff] [blame] | 79 | * @brief Update a current value of the limit |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 80 | * |
Alexander Afanasyev | a28ec56 | 2012-10-25 14:07:32 -0700 | [diff] [blame] | 81 | * If limit is larger than previously set value of maximum limit (SetMaxLimit), then the current limit will |
| 82 | * be limited to that maximum value |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 83 | */ |
| 84 | void |
Alexander Afanasyev | a28ec56 | 2012-10-25 14:07:32 -0700 | [diff] [blame] | 85 | UpdateCurrentLimit (double limit); |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 86 | |
Alexander Afanasyev | ef94e91 | 2012-10-29 10:15:26 -0700 | [diff] [blame] | 87 | double |
| 88 | GetCurrentLimit () const |
| 89 | { |
| 90 | return m_curMaxLimit; |
| 91 | } |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame^] | 92 | |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 93 | //////////////////////////////////////////////////////////////////////////// |
| 94 | //////////////////////////////////////////////////////////////////////////// |
| 95 | //////////////////////////////////////////////////////////////////////////// |
| 96 | |
| 97 | /** |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 98 | * @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] | 99 | */ |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame^] | 100 | virtual bool |
| 101 | IsBelowLimit () = 0; |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 102 | |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame^] | 103 | protected: |
Alexander Afanasyev | a28ec56 | 2012-10-25 14:07:32 -0700 | [diff] [blame] | 104 | double m_maxLimit; |
Alexander Afanasyev | a28ec56 | 2012-10-25 14:07:32 -0700 | [diff] [blame] | 105 | TracedValue< double > m_curMaxLimit; |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 106 | }; |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 107 | |
| 108 | |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 109 | } // namespace ndn |
| 110 | } // namespace ns3 |
| 111 | |
| 112 | #endif // _NDN_LIMITS_H_ |