blob: 181059a41fc70430a587442106122e5438ef10dd [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 ()
Alexander Afanasyeva28ec562012-10-25 14:07:32 -070048 : m_maxLimit (-1)
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070049 , 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
Alexander Afanasyeva28ec562012-10-25 14:07:32 -070057 SetMaxLimit (double max);
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070058
59 /**
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -070060 * @brief Get limit for the number of outstanding interests
61 */
Alexander Afanasyeva28ec562012-10-25 14:07:32 -070062 double
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -070063 GetMaxLimit () const;
64
65 /**
66 * @brief Check whether limits are enabled or not
67 */
68 inline bool
Alexander Afanasyeva28ec562012-10-25 14:07:32 -070069 IsEnabled () const
70 {
71 return m_maxLimit > 0.0;
72 }
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -070073
74 /**
Alexander Afanasyeva28ec562012-10-25 14:07:32 -070075 * @brief Update a current value of the limit
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -070076 *
Alexander Afanasyeva28ec562012-10-25 14:07:32 -070077 * If limit is larger than previously set value of maximum limit (SetMaxLimit), then the current limit will
78 * be limited to that maximum value
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070079 */
80 void
Alexander Afanasyeva28ec562012-10-25 14:07:32 -070081 UpdateCurrentLimit (double limit);
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070082
Alexander Afanasyevef94e912012-10-29 10:15:26 -070083 double
84 GetCurrentLimit () const
85 {
86 return m_curMaxLimit;
87 }
88
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070089 ////////////////////////////////////////////////////////////////////////////
90 ////////////////////////////////////////////////////////////////////////////
91 ////////////////////////////////////////////////////////////////////////////
92
93 /**
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -070094 * @brief Check if new interest can be send out, if yes, number of outstanding will be increased
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070095 */
96 bool
97 IsBelowLimit ();
98
99 /**
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -0700100 * @brief Remove outstanding interests
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700101 */
102 void
103 RemoveOutstanding ();
104
105public:
Alexander Afanasyeva28ec562012-10-25 14:07:32 -0700106 double m_maxLimit;
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700107
Alexander Afanasyeva28ec562012-10-25 14:07:32 -0700108 TracedValue< double > m_curMaxLimit;
109 TracedValue< double > m_outstanding;
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700110};
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -0700111
112
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700113} // namespace ndn
114} // namespace ns3
115
116#endif // _NDN_LIMITS_H_