blob: 5b93b6e53bfb9a8bab83b794404622436d5e51b6 [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_
22#define _NDN_LIMITS_WINDOW_H_
23
24#include "ndn-limits.h"
25
26namespace ns3 {
27namespace ndn {
28
29/**
30 * \ingroup ndn
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 */
33class LimitsWindow :
34 public Limits
35{
36public:
37 typedef Limits super;
38
39 static TypeId
40 GetTypeId ();
41
42 /**
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070043 * @brief Default Constructor
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070044 */
45 LimitsWindow ()
46 : m_outstanding (0)
47 { }
48
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070049 /**
50 * @brief Virtual destructor
51 */
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070052 virtual
53 ~LimitsWindow () { }
54
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
58 SetLimits (double rate, double delay)
59 {
60 super::SetLimits (rate, delay);
61
62 m_curMaxLimit = GetMaxRate () * GetMaxDelay ();
63 }
64
65 virtual void
66 UpdateCurrentLimit (double limit);
67
68 virtual double
69 GetCurrentLimit () const
70 {
71 return m_curMaxLimit;
72 }
73
74 /**
75 * @brief Check if current interest window (number of pending interests) if less than maximum
76 */
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070077 virtual bool
78 IsBelowLimit ();
79
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070080 /**
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070081 * @brief Increase current window of outstanding interests
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070082 */
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070083 virtual void
84 BorrowLimit ();
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070085
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070086 /**
87 * @brief Decrease current window of outstanding interests
88 */
89 virtual void
90 ReturnLimit ();
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070091
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070092private:
93 TracedValue< double > m_curMaxLimit;
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070094 TracedValue< double > m_outstanding;
95};
96
97
98} // namespace ndn
99} // namespace ns3
100
101#endif // _NDN_LIMITS_WINDOW_H_