blob: 034c9791790cc1ecc5d6150dba7c8084f4a36a78 [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"
26#include "ns3/nstime.h"
27#include "ns3/traced-value.h"
28
29namespace ns3 {
30namespace ndn {
31
32/**
33 * \ingroup ndn
34 * \brief Structure to manage limits for outstanding interests
35 */
36class Limits :
37 public Object
38{
39public:
40 static TypeId
41 GetTypeId ();
42
43 /**
44 * \brief Constructor
45 * \param prefix smart pointer to the prefix for the FIB entry
46 */
47 Limits ()
48 : m_maxLimit (0)
49 , m_curMaxLimit (0)
50 , m_outstanding (0)
51 { }
52
53 /**
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -070054 * @brief Set limit for the number of outstanding interests
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070055 */
56 void
57 SetMaxLimit (uint32_t max);
58
59 /**
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -070060 * @brief Get limit for the number of outstanding interests
61 */
62 uint32_t
63 GetMaxLimit () const;
64
65 /**
66 * @brief Check whether limits are enabled or not
67 */
68 inline bool
69 IsEnabled () const;
70
71 /**
72 * @brief Decay current limit (exponential decaying)
73 *
74 * If needed, this method should be called externally periodically (doesn't matter how often, decaying amount will remain the same).
75 * Decaying is most likely needed for per-prefix limits, but definitely not needed for per-face limits.
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070076 */
77 void
78 DecayCurrentLimit ();
79
80 /**
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -070081 * @brief Increase current limit (additive increase)
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070082 */
83 void
84 IncreaseLimit ();
85
86 /**
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -070087 * @brief Decrease current limit (multiplicative decrease)
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070088 */
89 void
90 DecreaseLimit ();
91
92 ////////////////////////////////////////////////////////////////////////////
93 ////////////////////////////////////////////////////////////////////////////
94 ////////////////////////////////////////////////////////////////////////////
95
96 /**
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -070097 * @brief Check if new interest can be send out, if yes, number of outstanding will be increased
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070098 */
99 bool
100 IsBelowLimit ();
101
102 /**
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -0700103 * @brief Remove outstanding interests
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700104 */
105 void
106 RemoveOutstanding ();
107
108public:
109 uint32_t m_maxLimit;
110
111 TracedValue< double > m_curMaxLimit;
112 TracedValue< uint32_t > m_outstanding;
113
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -0700114 Time m_exponentialDecayTau;
115 Time m_nonDecreasePeriod;
116 double m_additiveIncrease;
117 double m_multiplicativeDecrease;
118
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700119 Time m_lastDecrease;
120 Time m_lastDecay;
121};
122
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -0700123inline bool
124Limits::IsEnabled () const
125{
126 return m_maxLimit != 0;
127}
128
129
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700130} // namespace ndn
131} // namespace ns3
132
133#endif // _NDN_LIMITS_H_