blob: b21184a0fe07685c4f74a66a5576b5a65ec9d0f9 [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_
22#define _NDN_LIMITS_RATE_H_
23
24#include "ndn-limits.h"
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/**
31 * \ingroup ndn
32 * \brief Structure to manage limits for outstanding interests
33 */
34class LimitsRate :
35 public Limits
36{
37public:
38 typedef Limits super;
Alexander Afanasyevdc115ef2013-02-13 12:06:55 -080039
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070040 static TypeId
41 GetTypeId ();
Alexander Afanasyevdc115ef2013-02-13 12:06:55 -080042
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070043 /**
44 * \brief Constructor
45 * \param prefix smart pointer to the prefix for the FIB entry
46 */
47 LimitsRate ()
Alexander Afanasyev7e4235a2012-10-31 16:58:44 -070048 : m_isLeakScheduled (false)
49 , m_bucketMax (0)
50 , m_bucketLeak (1)
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070051 , m_bucket (0)
52 { }
53
54 virtual
55 ~LimitsRate () { }
56
57 virtual void
Alexander Afanasyevccd5bb42012-10-31 17:27:49 -070058 SetLimits (double rate, double delay);
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070059
Alexander Afanasyeva8f5d882012-11-09 14:22:48 -080060 virtual
61 double
62 GetMaxLimit () const
63 {
64 return GetMaxRate ();
65 }
66
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070067 /**
68 * @brief Check if Interest limit is reached (token bucket is not empty)
69 */
70 virtual bool
71 IsBelowLimit ();
72
73 /**
74 * @brief Get token from the bucket
75 */
76 virtual void
77 BorrowLimit ();
78
79 /**
80 * @brief Does nothing (token bucket leakage is time-dependent only)
81 */
82 virtual void
83 ReturnLimit ();
84
85 /**
Alexander Afanasyevccd5bb42012-10-31 17:27:49 -070086 * @brief Update normalized amount that should be leaked every second (token bucket leak rate) and leak rate
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070087 */
88 virtual void
89 UpdateCurrentLimit (double limit);
90
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
95 GetCurrentLimit () const
96 {
97 return m_bucketLeak;
98 }
99
Alexander Afanasyeva8f5d882012-11-09 14:22:48 -0800100 virtual double
101 GetCurrentLimitRate () const
102 {
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
109 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
118 LeakBucket (double interval);
119
120private:
Alexander Afanasyev7e4235a2012-10-31 16:58:44 -0700121 bool m_isLeakScheduled;
Alexander Afanasyevdc115ef2013-02-13 12:06:55 -0800122
Alexander Afanasyev6f95e702012-10-31 16:27:31 -0700123 double m_bucketMax; ///< \brief Maximum Interest allowance for this face (maximum tokens that can be issued at the same time)
124 double m_bucketLeak; ///< \brief Normalized amount that should be leaked every second (token bucket leak rate)
125 double m_bucket; ///< \brief Value representing current size of the Interest allowance for this face (current size of token bucket)
Alexander Afanasyevdc115ef2013-02-13 12:06:55 -0800126
127 Time m_leakRandomizationInteral;
Alexander Afanasyev6f95e702012-10-31 16:27:31 -0700128};
Alexander Afanasyevdc115ef2013-02-13 12:06:55 -0800129
Alexander Afanasyev6f95e702012-10-31 16:27:31 -0700130
131} // namespace ndn
132} // namespace ns3
133
134#endif // _NDN_LIMITS_RATE_H_