blob: fbe85cee0efd0fd1186f15e2b6523d5ebc90db50 [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 Afanasyev4aac5572012-08-09 10:49:55 -070026#include "ns3/ndn-name-components.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 Afanasyevcf133f02011-09-06 12:13:48 -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 Afanasyev0e4ae8e2013-03-12 15:59:18 -070063Entry::Entry (Ptr<ContentStore> cs, Ptr<const ContentObjectHeader> header, Ptr<const Packet> packet)
64 : m_cs (cs)
65 , m_header (header)
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070066 , m_packet (packet->Copy ())
Alexander Afanasyev070aa482011-08-20 00:38:25 -070067{
Alexander Afanasyev070aa482011-08-20 00:38:25 -070068}
69
70Ptr<Packet>
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070071Entry::GetFullyFormedNdnPacket () const
Alexander Afanasyev070aa482011-08-20 00:38:25 -070072{
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070073 static ContentObjectTail tail; ///< \internal for optimization purposes
Alexander Afanasyev8accdf62011-09-20 11:33:59 -070074
Alexander Afanasyev070aa482011-08-20 00:38:25 -070075 Ptr<Packet> packet = m_packet->Copy ();
76 packet->AddHeader (*m_header);
Alexander Afanasyev8accdf62011-09-20 11:33:59 -070077 packet->AddTrailer (tail);
Alexander Afanasyev070aa482011-08-20 00:38:25 -070078 return packet;
79}
80
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070081const NameComponents&
82Entry::GetName () const
Ilya Moiseenko1c570bc2011-08-17 19:18:02 -070083{
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070084 return m_header->GetName ();
Alexander Afanasyev070aa482011-08-20 00:38:25 -070085}
86
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070087Ptr<const ContentObjectHeader>
88Entry::GetHeader () const
Alexander Afanasyev070aa482011-08-20 00:38:25 -070089{
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070090 return m_header;
Alexander Afanasyev070aa482011-08-20 00:38:25 -070091}
92
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070093Ptr<const Packet>
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070094Entry::GetPacket () const
Alexander Afanasyev070aa482011-08-20 00:38:25 -070095{
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070096 return m_packet;
Alexander Afanasyev070aa482011-08-20 00:38:25 -070097}
98
Alexander Afanasyev0e4ae8e2013-03-12 15:59:18 -070099Ptr<ContentStore>
100Entry::GetContentStore ()
101{
102 return m_cs;
103}
104
105
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700106} // namespace cs
107} // namespace ndn
Alexander Afanasyev070aa482011-08-20 00:38:25 -0700108} // namespace ns3