NS-3 based Named Data Networking (NDN) simulator
ndnSIM: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
ndn-limits-window.cc
1 /* -*- 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 #include "ndn-limits-window.h"
22 
23 #include "ns3/log.h"
24 
25 NS_LOG_COMPONENT_DEFINE ("ndn.Limits.Window");
26 
27 namespace ns3 {
28 namespace ndn {
29 
30 NS_OBJECT_ENSURE_REGISTERED (LimitsWindow);
31 
32 TypeId
33 LimitsWindow::GetTypeId ()
34 {
35  static TypeId tid = TypeId ("ns3::ndn::Limits::Window")
36  .SetGroupName ("Ndn")
37  .SetParent <Limits> ()
38  .AddConstructor <LimitsWindow> ()
39 
40  .AddTraceSource ("CurMaxLimit",
41  "Current maximum limit",
42  MakeTraceSourceAccessor (&LimitsWindow::m_curMaxLimit))
43 
44  .AddTraceSource ("Outstanding",
45  "Number of outstanding interests",
46  MakeTraceSourceAccessor (&LimitsWindow::m_outstanding))
47  ;
48  return tid;
49 }
50 
51 void
53 {
54  NS_ASSERT_MSG (limit >= 0.0, "Limit should be greater or equal to zero");
55 
56  m_curMaxLimit = std::min (limit, GetMaxRate () * GetMaxDelay ());
57 }
58 
59 bool
61 {
62  if (!IsEnabled ()) return true;
63 
64  return (m_curMaxLimit - m_outstanding >= 1.0);
65 }
66 
67 void
69 {
70  if (!IsEnabled ()) return;
71 
72  NS_ASSERT_MSG (m_curMaxLimit - m_outstanding >= 1.0, "Should not be possible, unless we IsBelowLimit was not checked correctly");
73  m_outstanding += 1;
74 }
75 
76 void
78 {
79  if (!IsEnabled ()) return;
80 
81  NS_ASSERT_MSG (m_outstanding >= (uint32_t)1, "Should not be possible, unless we decreasing this number twice somewhere");
82  m_outstanding -= 1;
83 
84  FireAvailableSlotCallback ();
85 }
86 
87 } // namespace ndn
88 } // namespace ns3
virtual void ReturnLimit()
Decrease current window of outstanding interests.
virtual bool IsEnabled() const
Check whether limits are enabled or not.
Definition: ndn-limits.h:96
Limits()
Default constructor.
Definition: ndn-limits.cc:43
virtual double GetMaxDelay() const
Get maximum delay for BDP product for window-based limits.
Definition: ndn-limits.h:80
virtual bool IsBelowLimit()
Check if current interest window (number of pending interests) if less than maximum.
virtual double GetMaxRate() const
Get maximum rate that needs to be enforced.
Definition: ndn-limits.h:71
virtual void BorrowLimit()
Increase current window of outstanding interests.
virtual void UpdateCurrentLimit(double limit)
Update a current value of the limit.