blob: 11c91e939d1d3ec8e97e2493b2c7ada20ebed8cb [file] [log] [blame]
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -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-impl.h"
22#include "ns3/log.h"
23#include "ns3/string.h"
24#include "ns3/uinteger.h"
25#include "ns3/simulator.h"
26#include "ccnx-interest-header.h"
27#include "ccnx-content-object-header.h"
28
29#include <boost/lambda/bind.hpp>
30#include <boost/lambda/lambda.hpp>
31
32NS_LOG_COMPONENT_DEFINE ("CcnxPitImpl");
33
34using namespace boost::tuples;
35using namespace boost;
36namespace ll = boost::lambda;
37
38namespace ns3 {
39
40NS_OBJECT_ENSURE_REGISTERED (CcnxPitImpl);
41
42TypeId
43CcnxPitImpl::GetTypeId ()
44{
45 static TypeId tid = TypeId ("ns3::CcnxPit")
46 .SetGroupName ("Ccnx")
47 .SetParent<CcnxPit> ()
48 .AddConstructor<CcnxPitImpl> ()
49 .AddAttribute ("MaxSize",
50 "Set maximum number of entries in PIT. If 0, limit is not enforced",
51 StringValue ("0"),
52 MakeUintegerAccessor (&CcnxPitImpl::GetMaxSize, &CcnxPitImpl::SetMaxSize),
53 MakeUintegerChecker<uint32_t> ())
54 ;
55
56 return tid;
57}
58
59CcnxPitImpl::CcnxPitImpl ()
60{
61}
62
63CcnxPitImpl::~CcnxPitImpl ()
64{
65}
66
67uint32_t
68CcnxPitImpl::GetMaxSize () const
69{
70 return 0;
71}
72
73void
74CcnxPitImpl::SetMaxSize (uint32_t maxSize)
75{
76}
77
78void
79CcnxPitImpl::NotifyNewAggregate ()
80{
81 if (m_fib == 0)
82 {
83 m_fib = GetObject<CcnxFib> ();
84 }
85}
86
87void
88CcnxPitImpl::DoDispose ()
89{
90 // clear ();
91}
92
93void
94CcnxPitImpl::DoCleanExpired ()
95{
96 // NS_LOG_LOGIC ("Cleaning PIT. Total: " << size ());
97 Time now = Simulator::Now ();
98
99 // // uint32_t count = 0;
100 // while (!empty ())
101 // {
102 // CcnxPit::index<i_timestamp>::type::iterator entry = get<i_timestamp> ().begin ();
103 // if (entry->GetExpireTime () <= now) // is the record stale?
104 // {
105 // get<i_timestamp> ().erase (entry);
106 // // count ++;
107 // }
108 // else
109 // break; // nothing else to do. All later records will not be stale
110 // }
111}
112
113Ptr<CcnxPitEntry>
114CcnxPitImpl::Lookup (const CcnxContentObjectHeader &header) const
115{
116 return 0;
117 // iterator entry = end ();
118
119 // // do the longest prefix match
120 // const CcnxNameComponents &name = header.GetName ();
121 // for (size_t componentsCount = name.GetComponents ().size ()+1;
122 // componentsCount > 0;
123 // componentsCount--)
124 // {
125 // CcnxNameComponents subPrefix (name.GetSubComponents (componentsCount-1));
126
127 // entry = get<i_prefix> ().find (subPrefix);
128 // if (entry != end())
129 // return entry;
130 // }
131
132 // return end ();
133}
134
135Ptr<CcnxPitEntry>
136CcnxPitImpl::Lookup (const CcnxInterestHeader &header)
137{
138 return 0;
139 // NS_LOG_FUNCTION (header.GetName ());
140 // NS_ASSERT_MSG (m_fib != 0, "FIB should be set");
141
142 // iterator entry = get<i_prefix> ().find (header.GetName ());
143 // if (entry == end ())
144 // return end ();
145
146 // return entry;
147}
148
149bool
150CcnxPitImpl::CheckIfDuplicate (Ptr<CcnxPitEntry> entry, const CcnxInterestHeader &header)
151{
152 // if (!entry->IsNonceSeen (header.GetNonce ()))
153 // {
154 // modify (entry,
155 // boost::bind(&CcnxPitEntry::AddSeenNonce, ll::_1, header.GetNonce ()));
156 // return false;
157 // }
158 // else
159 // return true;
160 return false;
161}
162
163Ptr<CcnxPitEntry>
164CcnxPitImpl::Create (const CcnxInterestHeader &header)
165{
166 // NS_ASSERT_MSG (get<i_prefix> ().find (header.GetName ()) == end (),
167 // "Entry already exists, Create must not be called!!!");
168
169 // if (m_maxSize > 0 &&
170 // size () >= m_maxSize)
171 // {
172 // // remove old record
173 // get<i_timestamp> ().erase (get<i_timestamp> ().begin ());
174 // }
175
176 // Ptr<CcnxFibEntry> fibEntry = m_fib->LongestPrefixMatch (header);
177 // // NS_ASSERT_MSG (fibEntry != m_fib->m_fib.end (),
178 // // "There should be at least default route set" << " Prefix = "<<header.GetName() << "NodeID == " << m_fib->GetObject<Node>()->GetId() << "\n" << *m_fib);
179
180 // return insert (end (),
181 // CcnxPitEntry (ns3::Create<CcnxNameComponents> (header.GetName ()),
182 // header.GetInterestLifetime ().IsZero ()?m_PitEntryDefaultLifetime
183 // : header.GetInterestLifetime (),
184 // fibEntry));
185 return 0;
186}
187
188
189void
190CcnxPitImpl::MarkErased (Ptr<CcnxPitEntry> entry)
191{
192 // modify (entry,
193 // ll::bind (&CcnxPitEntry::SetExpireTime, ll::_1,
194 // Simulator::Now () + m_PitEntryPruningTimout));
195}
196
197
198void
199CcnxPitImpl::Print (std::ostream& os) const
200{
201 os << "Should be implemented soon\n";
202 // BOOST_FOREACH (const CcnxPitEntry &entry, pit)
203 // {
204 // if (entry.m_incoming.size () == 0 && entry.m_outgoing.size () == 0)
205 // continue; // these are stale to-be-removed records, so there is no need to print them out
206
207 // os << entry << std::endl;
208 // }
209}
210
211} // namespace ns3