blob: c5a66c91b7f5c481b6c9930d4add770b400c5ca3 [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
23#include "ccnx-content-store.h"
24#include "ns3/log.h"
Alexander Afanasyev070aa482011-08-20 00:38:25 -070025#include "ns3/packet.h"
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070026#include "ns3/ccnx-name-components.h"
Alexander Afanasyev070aa482011-08-20 00:38:25 -070027#include "ns3/ccnx-interest-header.h"
28#include "ns3/ccnx-content-object-header.h"
Ilya Moiseenko1c570bc2011-08-17 19:18:02 -070029
30NS_LOG_COMPONENT_DEFINE ("CcnxContentStore");
31
32namespace ns3
33{
Alexander Afanasyev070aa482011-08-20 00:38:25 -070034
Alexander Afanasyeva514d632012-02-14 18:54:14 -080035NS_OBJECT_ENSURE_REGISTERED (CcnxContentStore);
Alexander Afanasyev070aa482011-08-20 00:38:25 -070036
Alexander Afanasyevcf133f02011-09-06 12:13:48 -070037TypeId
38CcnxContentStore::GetTypeId (void)
39{
40 static TypeId tid = TypeId ("ns3::CcnxContentStore")
41 .SetGroupName ("Ccnx")
42 .SetParent<Object> ()
Alexander Afanasyev39485d82012-06-08 17:51:47 -070043
44 .AddTraceSource ("CacheHits", "Trace called every time there is a cache hit",
45 MakeTraceSourceAccessor (&CcnxContentStore::m_cacheHitsTrace))
46 .AddTraceSource ("CacheMisses", "Trace called every time there is a cache miss",
47 MakeTraceSourceAccessor (&CcnxContentStore::m_cacheMissesTrace))
Alexander Afanasyevcf133f02011-09-06 12:13:48 -070048 ;
Alexander Afanasyev070aa482011-08-20 00:38:25 -070049
Alexander Afanasyevcf133f02011-09-06 12:13:48 -070050 return tid;
51}
Alexander Afanasyev070aa482011-08-20 00:38:25 -070052
Alexander Afanasyevfccdb9e2011-08-22 19:27:14 -070053
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070054CcnxContentStore::~CcnxContentStore ()
Alexander Afanasyevfccdb9e2011-08-22 19:27:14 -070055{
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070056}
Alexander Afanasyevfccdb9e2011-08-22 19:27:14 -070057
58//////////////////////////////////////////////////////////////////////
59
Alexander Afanasyev070aa482011-08-20 00:38:25 -070060CcnxContentStoreEntry::CcnxContentStoreEntry (Ptr<CcnxContentObjectHeader> header, Ptr<const Packet> packet)
61 : m_header (header)
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070062 , m_packet (packet->Copy ())
Alexander Afanasyev070aa482011-08-20 00:38:25 -070063{
Alexander Afanasyev070aa482011-08-20 00:38:25 -070064}
65
66Ptr<Packet>
67CcnxContentStoreEntry::GetFullyFormedCcnxPacket () const
68{
Alexander Afanasyev8accdf62011-09-20 11:33:59 -070069 static CcnxContentObjectTail tail; ///< \internal for optimization purposes
70
Alexander Afanasyev070aa482011-08-20 00:38:25 -070071 Ptr<Packet> packet = m_packet->Copy ();
72 packet->AddHeader (*m_header);
Alexander Afanasyev8accdf62011-09-20 11:33:59 -070073 packet->AddTrailer (tail);
Alexander Afanasyev070aa482011-08-20 00:38:25 -070074 return packet;
75}
76
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070077const CcnxNameComponents&
78CcnxContentStoreEntry::GetName () const
Ilya Moiseenko1c570bc2011-08-17 19:18:02 -070079{
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070080 return m_header->GetName ();
Alexander Afanasyev070aa482011-08-20 00:38:25 -070081}
82
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070083Ptr<const CcnxContentObjectHeader>
84CcnxContentStoreEntry::GetHeader () const
Alexander Afanasyev070aa482011-08-20 00:38:25 -070085{
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070086 return m_header;
Alexander Afanasyev070aa482011-08-20 00:38:25 -070087}
88
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070089Ptr<const Packet>
90CcnxContentStoreEntry::GetPacket () const
Alexander Afanasyev070aa482011-08-20 00:38:25 -070091{
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070092 return m_packet;
Alexander Afanasyev070aa482011-08-20 00:38:25 -070093}
94
95} // namespace ns3