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 () |
Alexander Afanasyev | a28ec56 | 2012-10-25 14:07:32 -0700 | [diff] [blame] | 48 | : m_maxLimit (-1) |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 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 |
Alexander Afanasyev | a28ec56 | 2012-10-25 14:07:32 -0700 | [diff] [blame] | 57 | SetMaxLimit (double max); |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 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 | */ |
Alexander Afanasyev | a28ec56 | 2012-10-25 14:07:32 -0700 | [diff] [blame] | 62 | double |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 63 | GetMaxLimit () const; |
| 64 | |
| 65 | /** |
| 66 | * @brief Check whether limits are enabled or not |
| 67 | */ |
| 68 | inline bool |
Alexander Afanasyev | a28ec56 | 2012-10-25 14:07:32 -0700 | [diff] [blame] | 69 | IsEnabled () const |
| 70 | { |
| 71 | return m_maxLimit > 0.0; |
| 72 | } |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 73 | |
| 74 | /** |
Alexander Afanasyev | a28ec56 | 2012-10-25 14:07:32 -0700 | [diff] [blame] | 75 | * @brief Update a current value of the limit |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 76 | * |
Alexander Afanasyev | a28ec56 | 2012-10-25 14:07:32 -0700 | [diff] [blame] | 77 | * If limit is larger than previously set value of maximum limit (SetMaxLimit), then the current limit will |
| 78 | * be limited to that maximum value |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 79 | */ |
| 80 | void |
Alexander Afanasyev | a28ec56 | 2012-10-25 14:07:32 -0700 | [diff] [blame] | 81 | UpdateCurrentLimit (double limit); |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 82 | |
Alexander Afanasyev | ef94e91 | 2012-10-29 10:15:26 -0700 | [diff] [blame] | 83 | double |
| 84 | GetCurrentLimit () const |
| 85 | { |
| 86 | return m_curMaxLimit; |
| 87 | } |
| 88 | |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 89 | //////////////////////////////////////////////////////////////////////////// |
| 90 | //////////////////////////////////////////////////////////////////////////// |
| 91 | //////////////////////////////////////////////////////////////////////////// |
| 92 | |
| 93 | /** |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 94 | * @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] | 95 | */ |
| 96 | bool |
| 97 | IsBelowLimit (); |
| 98 | |
| 99 | /** |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 100 | * @brief Remove outstanding interests |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 101 | */ |
| 102 | void |
| 103 | RemoveOutstanding (); |
| 104 | |
| 105 | public: |
Alexander Afanasyev | a28ec56 | 2012-10-25 14:07:32 -0700 | [diff] [blame] | 106 | double m_maxLimit; |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 107 | |
Alexander Afanasyev | a28ec56 | 2012-10-25 14:07:32 -0700 | [diff] [blame] | 108 | TracedValue< double > m_curMaxLimit; |
| 109 | TracedValue< double > m_outstanding; |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 110 | }; |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 111 | |
| 112 | |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 113 | } // namespace ndn |
| 114 | } // namespace ns3 |
| 115 | |
| 116 | #endif // _NDN_LIMITS_H_ |