blob: 14aec50352aa26cbe4cf05004a413ab8fabf67b8 [file] [log] [blame]
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -07001/* -*- 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 Afanasyevea9b3e62012-08-13 19:02:54 -070026#include "ns3/traced-value.h"
27
28namespace ns3 {
29namespace ndn {
30
31/**
32 * \ingroup ndn
33 * \brief Structure to manage limits for outstanding interests
34 */
35class Limits :
36 public Object
37{
38public:
39 static TypeId
40 GetTypeId ();
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070041
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070042 Limits ()
Alexander Afanasyeva28ec562012-10-25 14:07:32 -070043 : m_maxLimit (-1)
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070044 , m_curMaxLimit (0)
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070045 { }
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070046
47 virtual
48 ~Limits () {}
49
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070050 /**
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -070051 * @brief Set limit for the number of outstanding interests
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070052 */
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070053 virtual void
54 SetMaxLimit (double max)
55 {
56 m_maxLimit = max;
57 m_curMaxLimit = max;
58 }
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070059
60 /**
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -070061 * @brief Get limit for the number of outstanding interests
62 */
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070063 virtual double
64 GetMaxLimit () const
65 {
66 return m_maxLimit;
67 }
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -070068
69 /**
70 * @brief Check whether limits are enabled or not
71 */
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070072 virtual inline bool
Alexander Afanasyeva28ec562012-10-25 14:07:32 -070073 IsEnabled () const
74 {
75 return m_maxLimit > 0.0;
76 }
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -070077
78 /**
Alexander Afanasyeva28ec562012-10-25 14:07:32 -070079 * @brief Update a current value of the limit
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -070080 *
Alexander Afanasyeva28ec562012-10-25 14:07:32 -070081 * 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 Afanasyevea9b3e62012-08-13 19:02:54 -070083 */
84 void
Alexander Afanasyeva28ec562012-10-25 14:07:32 -070085 UpdateCurrentLimit (double limit);
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070086
Alexander Afanasyevef94e912012-10-29 10:15:26 -070087 double
88 GetCurrentLimit () const
89 {
90 return m_curMaxLimit;
91 }
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070092
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070093 ////////////////////////////////////////////////////////////////////////////
94 ////////////////////////////////////////////////////////////////////////////
95 ////////////////////////////////////////////////////////////////////////////
96
97 /**
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -070098 * @brief Check if new interest can be send out, if yes, number of outstanding will be increased
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070099 */
Alexander Afanasyevf5c07742012-10-31 13:13:05 -0700100 virtual bool
101 IsBelowLimit () = 0;
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700102
Alexander Afanasyevf5c07742012-10-31 13:13:05 -0700103protected:
Alexander Afanasyeva28ec562012-10-25 14:07:32 -0700104 double m_maxLimit;
Alexander Afanasyeva28ec562012-10-25 14:07:32 -0700105 TracedValue< double > m_curMaxLimit;
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700106};
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -0700107
108
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700109} // namespace ndn
110} // namespace ns3
111
112#endif // _NDN_LIMITS_H_