Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame^] | 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 | #include "ns3/simulator.h" |
| 25 | #include "ns3/random-variable.h" |
| 26 | |
| 27 | NS_LOG_COMPONENT_DEFINE ("ndn.Limits.Window"); |
| 28 | |
| 29 | namespace ns3 { |
| 30 | namespace ndn { |
| 31 | |
| 32 | NS_OBJECT_ENSURE_REGISTERED (Limits); |
| 33 | |
| 34 | TypeId |
| 35 | LimitsWindow::GetTypeId () |
| 36 | { |
| 37 | static TypeId tid = TypeId ("ns3::ndn::Limits::Window") |
| 38 | .SetGroupName ("Ndn") |
| 39 | .SetParent <Limits> () |
| 40 | .AddConstructor <LimitsWindow> () |
| 41 | |
| 42 | .AddTraceSource ("Outstanding", |
| 43 | "Number of outstanding interests", |
| 44 | MakeTraceSourceAccessor (&LimitsWindow::m_outstanding)) |
| 45 | ; |
| 46 | return tid; |
| 47 | } |
| 48 | |
| 49 | bool |
| 50 | LimitsWindow::IsBelowLimit () |
| 51 | { |
| 52 | if (!IsEnabled ()) return true; |
| 53 | |
| 54 | if (m_curMaxLimit - m_outstanding >= 1.0) |
| 55 | { |
| 56 | // static UniformVariable acceptanceProbability (0, m_curMaxLimit); |
| 57 | // double value = acceptanceProbability.GetValue (); |
| 58 | double value = m_outstanding + 1; |
| 59 | |
| 60 | if (m_outstanding < value) |
| 61 | { |
| 62 | m_outstanding += 1.0; |
| 63 | return true; |
| 64 | } |
| 65 | else |
| 66 | return false; |
| 67 | } |
| 68 | else |
| 69 | return false; |
| 70 | } |
| 71 | |
| 72 | void |
| 73 | LimitsWindow::RemoveOutstanding () |
| 74 | { |
| 75 | if (!IsEnabled ()) return; |
| 76 | |
| 77 | NS_LOG_DEBUG (m_outstanding); |
| 78 | NS_ASSERT_MSG (m_outstanding >= (uint32_t)1, "Should not be possible, unless we decreasing this number twice somewhere"); |
| 79 | m_outstanding -= 1; |
| 80 | } |
| 81 | |
| 82 | } // namespace ndn |
| 83 | } // namespace ns3 |