blob: 75e9373ba909636c243e1881814fea61c5ac6b5f [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"
27#include "ns3/ndn-interest-header.h"
28#include "ns3/ndn-content-object-header.h"
Ilya Moiseenko1c570bc2011-08-17 19:18:02 -070029
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070030NS_LOG_COMPONENT_DEFINE ("NdnContentStore");
Ilya Moiseenko1c570bc2011-08-17 19:18:02 -070031
32namespace ns3
33{
Alexander Afanasyev070aa482011-08-20 00:38:25 -070034
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070035NS_OBJECT_ENSURE_REGISTERED (NdnContentStore);
Alexander Afanasyev070aa482011-08-20 00:38:25 -070036
Alexander Afanasyevcf133f02011-09-06 12:13:48 -070037TypeId
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070038NdnContentStore::GetTypeId (void)
Alexander Afanasyevcf133f02011-09-06 12:13:48 -070039{
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070040 static TypeId tid = TypeId ("ns3::NdnContentStore")
41 .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 Afanasyev4aac5572012-08-09 10:49:55 -070045 MakeTraceSourceAccessor (&NdnContentStore::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 Afanasyev4aac5572012-08-09 10:49:55 -070048 MakeTraceSourceAccessor (&NdnContentStore::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 Afanasyev4aac5572012-08-09 10:49:55 -070055NdnContentStore::~NdnContentStore ()
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 Afanasyev4aac5572012-08-09 10:49:55 -070061NdnContentStoreEntry::NdnContentStoreEntry (Ptr<const NdnContentObjectHeader> header, Ptr<const Packet> packet)
Alexander Afanasyev070aa482011-08-20 00:38:25 -070062 : 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>
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070068NdnContentStoreEntry::GetFullyFormedNdnPacket () const
Alexander Afanasyev070aa482011-08-20 00:38:25 -070069{
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070070 static NdnContentObjectTail tail; ///< \internal for optimization purposes
Alexander Afanasyev8accdf62011-09-20 11:33:59 -070071
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 Afanasyev4aac5572012-08-09 10:49:55 -070078const NdnNameComponents&
79NdnContentStoreEntry::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 Afanasyev4aac5572012-08-09 10:49:55 -070084Ptr<const NdnContentObjectHeader>
85NdnContentStoreEntry::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>
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070091NdnContentStoreEntry::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