blob: 3733880f5899a018ca3f29f0e3649e6ec2b335cf [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 Afanasyevf9f4eb02011-12-16 01:51:14 -080057
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080058 .AddAttribute ("PitEntryDefaultLifetime",
59 "Default lifetime of PIT entry (aka default Interest lifetime)",
60 StringValue("4s"),
61 MakeTimeAccessor (&CcnxPit::m_PitEntryDefaultLifetime),
62 MakeTimeChecker ())
Alexander Afanasyevcf133f02011-09-06 12:13:48 -070063 ;
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070064
Alexander Afanasyevcf133f02011-09-06 12:13:48 -070065 return tid;
66}
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070067
68CcnxPit::CcnxPit ()
69{
70}
71
Alexander Afanasyevd02a5d62011-11-21 11:01:51 -080072CcnxPit::~CcnxPit ()
73{
Alexander Afanasyevd02a5d62011-11-21 11:01:51 -080074}
75
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070076void CcnxPit::CleanExpired ()
Alexander Afanasyev18252852011-11-21 13:35:31 -080077{
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070078 DoCleanExpired ();
79
80 // schedule next event
81 m_cleanupEvent = Simulator::Schedule (m_cleanupTimeout,
82 &CcnxPit::CleanExpired, this);
Alexander Afanasyev18252852011-11-21 13:35:31 -080083}
84
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070085void
86CcnxPit::SetCleanupTimeout (const Time &timeout)
87{
88 m_cleanupTimeout = timeout;
89 if (m_cleanupEvent.IsRunning ())
90 m_cleanupEvent.Cancel (); // cancel any scheduled cleanup events
91
92 // schedule even with new timeout
Alexander Afanasyeva46844b2011-11-21 19:13:26 -080093 m_cleanupEvent = Simulator::Schedule (m_cleanupTimeout,
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070094 &CcnxPit::CleanExpired, this);
95}
96
97Time
98CcnxPit::GetCleanupTimeout () const
99{
100 return m_cleanupTimeout;
101}
102
Alexander Afanasyeva95b7392012-03-09 10:54:10 -0800103
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700104} // namespace ns3