blob: a6328fd635abd50cb57e878fda11477e945d57bc [file] [log] [blame]
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -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#include "ccnx-pit.h"
22#include "ns3/log.h"
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080023#include "ns3/string.h"
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -070024#include "ns3/uinteger.h"
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070025#include "ns3/simulator.h"
26#include "ccnx-interest-header.h"
27#include "ccnx-content-object-header.h"
28
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -070029#include <boost/lambda/bind.hpp>
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080030#include <boost/lambda/lambda.hpp>
31
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070032NS_LOG_COMPONENT_DEFINE ("CcnxPit");
33
34namespace ns3 {
35
Alexander Afanasyevd02a5d62011-11-21 11:01:51 -080036NS_OBJECT_ENSURE_REGISTERED (CcnxPit);
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070037
38using namespace __ccnx_private;
39
Alexander Afanasyeva46844b2011-11-21 19:13:26 -080040TypeId
Alexander Afanasyevcf133f02011-09-06 12:13:48 -070041CcnxPit::GetTypeId ()
42{
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070043 static TypeId tid = TypeId ("ns3::private::CcnxPit")
Alexander Afanasyevcf133f02011-09-06 12:13:48 -070044 .SetGroupName ("Ccnx")
45 .SetParent<Object> ()
Alexander Afanasyevcf133f02011-09-06 12:13:48 -070046 .AddAttribute ("CleanupTimeout",
47 "Timeout defining how frequent RIT should be cleaned up",
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080048 StringValue ("1s"),
Alexander Afanasyevcf133f02011-09-06 12:13:48 -070049 MakeTimeAccessor (&CcnxPit::GetCleanupTimeout, &CcnxPit::SetCleanupTimeout),
50 MakeTimeChecker ())
Alexander Afanasyevf9f4eb02011-12-16 01:51:14 -080051
Alexander Afanasyeva46844b2011-11-21 19:13:26 -080052 .AddAttribute ("PitEntryPruningTimout",
53 "Timeout for PIT entry to live after being satisfied. To make sure recently satisfied interest will not be satisfied again",
54 StringValue ("100ms"),
55 MakeTimeAccessor (&CcnxPit::m_PitEntryPruningTimout),
56 MakeTimeChecker ())
Alexander Afanasyevcf133f02011-09-06 12:13:48 -070057 ;
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070058
Alexander Afanasyevcf133f02011-09-06 12:13:48 -070059 return tid;
60}
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070061
62CcnxPit::CcnxPit ()
63{
64}
65
Alexander Afanasyevd02a5d62011-11-21 11:01:51 -080066CcnxPit::~CcnxPit ()
67{
Alexander Afanasyevd02a5d62011-11-21 11:01:51 -080068}
69
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070070void CcnxPit::CleanExpired ()
Alexander Afanasyev18252852011-11-21 13:35:31 -080071{
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070072 DoCleanExpired ();
73
74 // schedule next event
75 m_cleanupEvent = Simulator::Schedule (m_cleanupTimeout,
76 &CcnxPit::CleanExpired, this);
Alexander Afanasyev18252852011-11-21 13:35:31 -080077}
78
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070079void
80CcnxPit::SetCleanupTimeout (const Time &timeout)
81{
82 m_cleanupTimeout = timeout;
83 if (m_cleanupEvent.IsRunning ())
84 m_cleanupEvent.Cancel (); // cancel any scheduled cleanup events
85
86 // schedule even with new timeout
Alexander Afanasyeva46844b2011-11-21 19:13:26 -080087 m_cleanupEvent = Simulator::Schedule (m_cleanupTimeout,
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070088 &CcnxPit::CleanExpired, this);
89}
90
91Time
92CcnxPit::GetCleanupTimeout () const
93{
94 return m_cleanupTimeout;
95}
96
Alexander Afanasyeva95b7392012-03-09 10:54:10 -080097
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070098} // namespace ns3