blob: ccbf200a4ab536ad052010702b9e543dd9def54e [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))
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",
48 MakeTraceSourceAccessor (&CcnxContentStore::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 Afanasyevd9fecdd2012-06-08 16:22:24 -070055CcnxContentStore::~CcnxContentStore ()
Alexander Afanasyevfccdb9e2011-08-22 19:27:14 -070056{
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070057}
Alexander Afanasyevfccdb9e2011-08-22 19:27:14 -070058
59//////////////////////////////////////////////////////////////////////
60
Alexander Afanasyev070aa482011-08-20 00:38:25 -070061CcnxContentStoreEntry::CcnxContentStoreEntry (Ptr<CcnxContentObjectHeader> header, Ptr<const Packet> packet)
62 : m_header (header)
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070063 , m_packet (packet->Copy ())
Alexander Afanasyev070aa482011-08-20 00:38:25 -070064{
Alexander Afanasyev070aa482011-08-20 00:38:25 -070065}
66
67Ptr<Packet>
68CcnxContentStoreEntry::GetFullyFormedCcnxPacket () const
69{
Alexander Afanasyev8accdf62011-09-20 11:33:59 -070070 static CcnxContentObjectTail tail; ///< \internal for optimization purposes
71
Alexander Afanasyev070aa482011-08-20 00:38:25 -070072 Ptr<Packet> packet = m_packet->Copy ();
73 packet->AddHeader (*m_header);
Alexander Afanasyev8accdf62011-09-20 11:33:59 -070074 packet->AddTrailer (tail);
Alexander Afanasyev070aa482011-08-20 00:38:25 -070075 return packet;
76}
77
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070078const CcnxNameComponents&
79CcnxContentStoreEntry::GetName () const
Ilya Moiseenko1c570bc2011-08-17 19:18:02 -070080{
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070081 return m_header->GetName ();
Alexander Afanasyev070aa482011-08-20 00:38:25 -070082}
83
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070084Ptr<const CcnxContentObjectHeader>
85CcnxContentStoreEntry::GetHeader () const
Alexander Afanasyev070aa482011-08-20 00:38:25 -070086{
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070087 return m_header;
Alexander Afanasyev070aa482011-08-20 00:38:25 -070088}
89
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070090Ptr<const Packet>
91CcnxContentStoreEntry::GetPacket () const
Alexander Afanasyev070aa482011-08-20 00:38:25 -070092{
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070093 return m_packet;
Alexander Afanasyev070aa482011-08-20 00:38:25 -070094}
95
96} // namespace ns3