blob: cfe362e9b6127f74600777ba6b75542d2ca475d0 [file] [log] [blame]
Ilya Moiseenko1c570bc2011-08-17 19:18:02 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -07003 * Copyright (c) 2011,2012 University of California, Los Angeles
Ilya Moiseenko1c570bc2011-08-17 19:18:02 -07004 *
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 *
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070018 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19 * Ilya Moiseenko <iliamo@cs.ucla.edu>
20 *
Ilya Moiseenko1c570bc2011-08-17 19:18:02 -070021 */
22
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070023#include "ndn-content-store.h"
Ilya Moiseenko1c570bc2011-08-17 19:18:02 -070024#include "ns3/log.h"
Alexander Afanasyev070aa482011-08-20 00:38:25 -070025#include "ns3/packet.h"
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070026#include "ns3/ndn-name.h"
Alexander Afanasyevbd9c18e2012-11-19 15:23:41 -080027#include "ns3/ndn-interest.h"
28#include "ns3/ndn-content-object.h"
Ilya Moiseenko1c570bc2011-08-17 19:18:02 -070029
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070030NS_LOG_COMPONENT_DEFINE ("ndn.cs.ContentStore");
Ilya Moiseenko1c570bc2011-08-17 19:18:02 -070031
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070032namespace ns3 {
33namespace ndn {
Alexander Afanasyev070aa482011-08-20 00:38:25 -070034
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070035NS_OBJECT_ENSURE_REGISTERED (ContentStore);
Alexander Afanasyev070aa482011-08-20 00:38:25 -070036
Alexander Afanasyevb989b122013-07-10 17:15:46 -070037TypeId
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070038ContentStore::GetTypeId (void)
Alexander Afanasyevcf133f02011-09-06 12:13:48 -070039{
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070040 static TypeId tid = TypeId ("ns3::ndn::ContentStore")
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070041 .SetGroupName ("Ndn")
Alexander Afanasyevcf133f02011-09-06 12:13:48 -070042 .SetParent<Object> ()
Alexander Afanasyev39485d82012-06-08 17:51:47 -070043
44 .AddTraceSource ("CacheHits", "Trace called every time there is a cache hit",
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070045 MakeTraceSourceAccessor (&ContentStore::m_cacheHitsTrace))
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -070046
Alexander Afanasyev39485d82012-06-08 17:51:47 -070047 .AddTraceSource ("CacheMisses", "Trace called every time there is a cache miss",
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070048 MakeTraceSourceAccessor (&ContentStore::m_cacheMissesTrace))
Alexander Afanasyevcf133f02011-09-06 12:13:48 -070049 ;
Alexander Afanasyev070aa482011-08-20 00:38:25 -070050
Alexander Afanasyevcf133f02011-09-06 12:13:48 -070051 return tid;
52}
Alexander Afanasyev070aa482011-08-20 00:38:25 -070053
Alexander Afanasyevfccdb9e2011-08-22 19:27:14 -070054
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070055ContentStore::~ContentStore ()
Alexander Afanasyevfccdb9e2011-08-22 19:27:14 -070056{
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070057}
Alexander Afanasyevfccdb9e2011-08-22 19:27:14 -070058
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070059namespace cs {
60
Alexander Afanasyevfccdb9e2011-08-22 19:27:14 -070061//////////////////////////////////////////////////////////////////////
62
Alexander Afanasyevb989b122013-07-10 17:15:46 -070063Entry::Entry (Ptr<ContentStore> cs, Ptr<const ContentObject> data)
Alexander Afanasyev0e4ae8e2013-03-12 15:59:18 -070064 : m_cs (cs)
Alexander Afanasyevb989b122013-07-10 17:15:46 -070065 , m_data (data)
Alexander Afanasyev070aa482011-08-20 00:38:25 -070066{
Alexander Afanasyev070aa482011-08-20 00:38:25 -070067}
68
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070069const Name&
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070070Entry::GetName () const
Ilya Moiseenko1c570bc2011-08-17 19:18:02 -070071{
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070072 return m_header->GetName ();
Alexander Afanasyev070aa482011-08-20 00:38:25 -070073}
74
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070075Ptr<const ContentObject>
Alexander Afanasyevb989b122013-07-10 17:15:46 -070076Entry::GetData () const
Alexander Afanasyev070aa482011-08-20 00:38:25 -070077{
Alexander Afanasyevb989b122013-07-10 17:15:46 -070078 return m_data;
Alexander Afanasyev070aa482011-08-20 00:38:25 -070079}
80
Alexander Afanasyev0e4ae8e2013-03-12 15:59:18 -070081Ptr<ContentStore>
82Entry::GetContentStore ()
83{
84 return m_cs;
85}
86
87
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070088} // namespace cs
89} // namespace ndn
Alexander Afanasyev070aa482011-08-20 00:38:25 -070090} // namespace ns3