blob: cf5c0399affcfbe8842d75c4314a6d2eaba00bb9 [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
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070033 * \brief Abstract class to manage Interest limits
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070034 */
35class Limits :
36 public Object
37{
38public:
39 static TypeId
40 GetTypeId ();
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070041
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070042 /**
43 * @brief Default constructor
44 */
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070045 Limits ()
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070046 : m_maxRate (-1)
47 , m_maxDelay (1.0)
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070048 { }
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070049
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070050 /**
51 * @brief Virtual destructor
52 */
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070053 virtual
54 ~Limits () {}
55
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070056 /**
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -070057 * @brief Set limit for the number of outstanding interests
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070058 * @param rate Maximum rate that needs to be enforced
59 * @param delay Maximum delay for BDP product for window-based limits
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070060 */
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070061 virtual void
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070062 SetLimits (double rate, double delay)
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070063 {
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070064 m_maxRate = rate;
65 m_maxDelay = delay;
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070066 }
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070067
68 /**
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070069 * @brief Get maximum rate that needs to be enforced
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -070070 */
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070071 virtual double
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070072 GetMaxRate () const
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070073 {
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070074 return m_maxRate;
75 }
76
77 /**
78 * @brief Get maximum delay for BDP product for window-based limits
79 */
80 virtual double
81 GetMaxDelay () const
82 {
83 return m_maxDelay;
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070084 }
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -070085
86 /**
87 * @brief Check whether limits are enabled or not
88 */
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070089 virtual inline bool
Alexander Afanasyeva28ec562012-10-25 14:07:32 -070090 IsEnabled () const
91 {
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070092 return m_maxRate > 0.0;
Alexander Afanasyeva28ec562012-10-25 14:07:32 -070093 }
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -070094
95 /**
Alexander Afanasyeva28ec562012-10-25 14:07:32 -070096 * @brief Update a current value of the limit
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070097 * @param limit Value of current limit.
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -070098 *
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070099 * Note that interpretation of this value may be different in different ndn::Limit realizations
100 *
101 * All realizations will try to guarantee that if limit is larger than previously set value of maximum limit,
102 * then the current limit will be limited to that maximum value
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700103 */
Alexander Afanasyev6f95e702012-10-31 16:27:31 -0700104 virtual void
105 UpdateCurrentLimit (double limit) = 0;
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700106
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700107 /**
Alexander Afanasyev6f95e702012-10-31 16:27:31 -0700108 * @brief Get value of the current limit
109 *
110 * Note that interpretation of this value may be different in different ndn::Limit realizations
111 */
112 virtual double
113 GetCurrentLimit () const = 0;
114
115 ////////////////////////////////////////////////////////////////////////////
116 ////////////////////////////////////////////////////////////////////////////
117 ////////////////////////////////////////////////////////////////////////////
118
119 /**
120 * @brief Realization-specific method called to check availability of the limit
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700121 */
Alexander Afanasyevf5c07742012-10-31 13:13:05 -0700122 virtual bool
123 IsBelowLimit () = 0;
Alexander Afanasyev6f95e702012-10-31 16:27:31 -0700124
125 /**
126 * @brief "Borrow" limit
127 *
128 * IsBelowLimit **must** be true, otherwise assert fail
129 */
130 virtual void
131 BorrowLimit () = 0;
132
133 /**
134 * @brief "Return" limit
135 */
136 virtual void
137 ReturnLimit () = 0;
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700138
Alexander Afanasyev6f95e702012-10-31 16:27:31 -0700139private:
140 double m_maxRate;
141 double m_maxDelay;
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700142};
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -0700143
144
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700145} // namespace ndn
146} // namespace ns3
147
148#endif // _NDN_LIMITS_H_