blob: b407e020d15b3629669f4d709f96d87a489faab9 [file] [log] [blame]
Alexander Afanasyevf5c07742012-10-31 13:13:05 -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_WINDOW_H_
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080022#define _NDN_LIMITS_WINDOW_H_
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070023
Alexander Afanasyev0c395372014-12-20 15:54:02 -080024#include "ndn-limits.hpp"
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070025
26namespace ns3 {
27namespace ndn {
28
29/**
Alexander Afanasyev79206512013-07-27 16:49:12 -070030 * \ingroup ndn-fw
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070031 * \brief Structure to manage limits for outstanding interests (window-based limiting)
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070032 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080033class LimitsWindow : public Limits {
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070034public:
35 typedef Limits super;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080036
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070037 static TypeId
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080038 GetTypeId();
39
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070040 /**
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070041 * @brief Default Constructor
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070042 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080043 LimitsWindow()
44 : m_outstanding(0)
45 {
46 }
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070047
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070048 /**
49 * @brief Virtual destructor
50 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080051 virtual ~LimitsWindow()
52 {
53 }
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070054
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070055 // from ndn::Limits
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070056
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070057 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 super::SetLimits(rate, delay);
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070061
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080062 m_curMaxLimit = GetMaxRate() * GetMaxDelay();
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070063 }
64
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070065 virtual double
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080066 GetMaxLimit() const
67 {
68 return GetMaxRate() * GetMaxDelay();
69 }
70
71 virtual void
72 UpdateCurrentLimit(double limit);
73
74 virtual double
75 GetCurrentLimit() const
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070076 {
77 return m_curMaxLimit;
78 }
79
Alexander Afanasyeva8f5d882012-11-09 14:22:48 -080080 virtual double
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080081 GetCurrentLimitRate() const
Alexander Afanasyeva8f5d882012-11-09 14:22:48 -080082 {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080083 return m_curMaxLimit / GetMaxDelay();
Alexander Afanasyeva8f5d882012-11-09 14:22:48 -080084 }
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080085
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070086 /**
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080087 * @brief Check if current interest window (number of pending interests) if less than maximum
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070088 */
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070089 virtual bool
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080090 IsBelowLimit();
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070091
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070092 /**
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070093 * @brief Increase current window of outstanding interests
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070094 */
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070095 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080096 BorrowLimit();
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070097
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070098 /**
99 * @brief Decrease current window of outstanding interests
100 */
101 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800102 ReturnLimit();
103
Alexander Afanasyev6f95e702012-10-31 16:27:31 -0700104private:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800105 TracedValue<double> m_curMaxLimit;
106 TracedValue<double> m_outstanding;
Alexander Afanasyevf5c07742012-10-31 13:13:05 -0700107};
Alexander Afanasyevf5c07742012-10-31 13:13:05 -0700108
109} // namespace ndn
110} // namespace ns3
111
112#endif // _NDN_LIMITS_WINDOW_H_