blob: a476247422366ccafec308360a7ee57fdfc483f1 [file] [log] [blame]
Alexander Afanasyev6f95e702012-10-31 16:27:31 -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_RATE_H_
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080022#define _NDN_LIMITS_RATE_H_
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070023
Alexander Afanasyev0c395372014-12-20 15:54:02 -080024#include "ndn-limits.hpp"
Alexander Afanasyevdc115ef2013-02-13 12:06:55 -080025#include <ns3/nstime.h>
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070026
27namespace ns3 {
28namespace ndn {
29
30/**
Alexander Afanasyev79206512013-07-27 16:49:12 -070031 * \ingroup ndn-fw
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070032 * \brief Structure to manage limits for outstanding interests
33 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080034class LimitsRate : public Limits {
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070035public:
36 typedef Limits super;
Alexander Afanasyevdc115ef2013-02-13 12:06:55 -080037
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070038 static TypeId
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080039 GetTypeId();
Alexander Afanasyevdc115ef2013-02-13 12:06:55 -080040
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070041 /**
42 * \brief Constructor
43 * \param prefix smart pointer to the prefix for the FIB entry
44 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080045 LimitsRate()
46 : m_isLeakScheduled(false)
47 , m_bucketMax(0)
48 , m_bucketLeak(1)
49 , m_bucket(0)
50 {
51 }
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070052
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080053 virtual ~LimitsRate()
54 {
55 }
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070056
57 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080058 SetLimits(double rate, double delay);
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070059
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080060 virtual double
61 GetMaxLimit() const
Alexander Afanasyeva8f5d882012-11-09 14:22:48 -080062 {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080063 return GetMaxRate();
Alexander Afanasyeva8f5d882012-11-09 14:22:48 -080064 }
65
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070066 /**
67 * @brief Check if Interest limit is reached (token bucket is not empty)
68 */
69 virtual bool
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080070 IsBelowLimit();
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070071
72 /**
73 * @brief Get token from the bucket
74 */
75 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080076 BorrowLimit();
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070077
78 /**
79 * @brief Does nothing (token bucket leakage is time-dependent only)
80 */
81 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080082 ReturnLimit();
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070083
84 /**
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080085 * @brief Update normalized amount that should be leaked every second (token bucket leak rate) and
86 * leak rate
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070087 */
88 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080089 UpdateCurrentLimit(double limit);
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070090
91 /**
Alexander Afanasyevccd5bb42012-10-31 17:27:49 -070092 * @brief Get normalized amount that should be leaked every second (token bucket leak rate)
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070093 */
94 virtual double
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080095 GetCurrentLimit() const
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070096 {
97 return m_bucketLeak;
98 }
99
Alexander Afanasyeva8f5d882012-11-09 14:22:48 -0800100 virtual double
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800101 GetCurrentLimitRate() const
Alexander Afanasyeva8f5d882012-11-09 14:22:48 -0800102 {
103 return m_bucketLeak;
104 }
Alexander Afanasyevdc115ef2013-02-13 12:06:55 -0800105
Alexander Afanasyev7e4235a2012-10-31 16:58:44 -0700106protected:
107 // from Node
108 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800109 NotifyNewAggregate();
Alexander Afanasyevdc115ef2013-02-13 12:06:55 -0800110
Alexander Afanasyev6f95e702012-10-31 16:27:31 -0700111private:
112 /**
113 * @brief Leak bucket, assuming `interval' seconds between leakages
114 *
115 * @param interval Time interval for leakage. Used to calculate size of the leak
116 */
117 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800118 LeakBucket(double interval);
Alexander Afanasyev6f95e702012-10-31 16:27:31 -0700119
120private:
Alexander Afanasyev7e4235a2012-10-31 16:58:44 -0700121 bool m_isLeakScheduled;
Alexander Afanasyevdc115ef2013-02-13 12:06:55 -0800122
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800123 double m_bucketMax; ///< \brief Maximum Interest allowance for this face (maximum tokens that can
124 /// be issued at the same time)
125 double m_bucketLeak; ///< \brief Normalized amount that should be leaked every second (token
126 /// bucket leak rate)
127 double m_bucket; ///< \brief Value representing current size of the Interest allowance for this
128 /// face (current size of token bucket)
Alexander Afanasyevdc115ef2013-02-13 12:06:55 -0800129
130 Time m_leakRandomizationInteral;
Alexander Afanasyev6f95e702012-10-31 16:27:31 -0700131};
Alexander Afanasyevdc115ef2013-02-13 12:06:55 -0800132
Alexander Afanasyev6f95e702012-10-31 16:27:31 -0700133} // namespace ndn
134} // namespace ns3
135
136#endif // _NDN_LIMITS_RATE_H_