blob: 15e4824dafca1800174ed83b71ed509fdbae3dce [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"
23#include "ns3/simulator.h"
24#include "ccnx-interest-header.h"
25#include "ccnx-content-object-header.h"
26
27NS_LOG_COMPONENT_DEFINE ("CcnxPit");
28
29namespace ns3 {
30
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -070031// NS_OBJECT_ENSURE_REGISTERED (CcnxPit);
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070032
33using namespace __ccnx_private;
34
35// size_t
36// PitEntry::numberOfPromisingInterests(e_pi ) const
37// {
38// size_t count = 0;
39
40// BOOST_FOREACH (const CcnxPitOutgoingInterest &interest, m_outgoingInterests)
41// {
42// }
43// for( PitOutgoingConstIterator i = outgoingInterests.begin();
44// i!=outgoingInterests.end();
45// i++ )
46// {
47// if( !i->waitingInVain ) count++;
48// }
49
50// return count;
51// }
52
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -070053// TypeId
54// CcnxPit::GetTypeId ()
55// {
56// static TypeId tid = TypeId ("ns3::CcnxPit")
57// .SetGroupName ("Ccnx")
58// .SetParent<Object> ()
59// .AddConstructor<CcnxPit> ()
60// .AddAttribute ("CleanupTimeout",
61// "Timeout defining how frequent RIT should be cleaned up",
62// TimeValue (Seconds (1)),
63// MakeTimeAccessor (&CcnxPit::GetCleanupTimeout, &CcnxPit::SetCleanupTimeout),
64// MakeTimeChecker ())
65// ;
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070066
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -070067// return tid;
68// }
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070069
70CcnxPit::CcnxPit ()
71{
72}
73
74void
75CcnxPit::SetCleanupTimeout (const Time &timeout)
76{
77 m_cleanupTimeout = timeout;
78 if (m_cleanupEvent.IsRunning ())
79 m_cleanupEvent.Cancel (); // cancel any scheduled cleanup events
80
81 // schedule even with new timeout
82 m_cleanupEvent = Simulator::Schedule (Simulator::Now () + m_cleanupTimeout,
83 &CcnxPit::CleanExpired, this);
84}
85
86Time
87CcnxPit::GetCleanupTimeout () const
88{
89 return m_cleanupTimeout;
90}
91
92void CcnxPit::CleanExpired ()
93{
94 NS_LOG_LOGIC ("Cleaning PIT");
95 Time now = Simulator::Now ();
96
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -070097 while( !empty() )
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070098 {
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -070099 if( get<i_timestamp> ().front ().GetExpireTime () <= now ) // is the record stale?
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700100 {
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700101 get<i_timestamp> ().pop_front( );
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700102 }
103 else
104 break; // nothing else to do. All later records will not be stale
105 }
106
107 // schedule next even
108 m_cleanupEvent = Simulator::Schedule (Simulator::Now () + m_cleanupTimeout,
109 &CcnxPit::CleanExpired, this);
110}
111
112const CcnxPitEntry&
113CcnxPit::Lookup (const CcnxContentObjectHeader &header) const
114{
115 CcnxPitEntryContainer::type::iterator entry =
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700116 get<i_prefix> ().find (header.GetName ());
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700117
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700118 if (entry != end ())
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700119 throw CcnxPitEntryNotFound();
120
121 return *entry;
122}
123
124const CcnxPitEntry&
125CcnxPit::Lookup (const CcnxInterestHeader &header) const
126{
127 CcnxPitEntryContainer::type::iterator entry =
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700128 get<i_prefix> ().find (header.GetName ());
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700129
130 // if (entry != m_pit.end ())
131 // entry = m_pit.insert (m_pit.end (), CcnxPitEntry (Create<CcnxNameComponents> (header.GetName ())));
132
133 return *entry;
134}
135
136
137} // namespace ns3