Ilya Moiseenko | 1c570bc | 2011-08-17 19:18:02 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 3 | * Copyright (c) 2011,2012 University of California, Los Angeles |
Ilya Moiseenko | 1c570bc | 2011-08-17 19:18:02 -0700 | [diff] [blame] | 4 | * |
| 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 Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 18 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | * Ilya Moiseenko <iliamo@cs.ucla.edu> |
| 20 | * |
Ilya Moiseenko | 1c570bc | 2011-08-17 19:18:02 -0700 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | #include "ccnx-content-store.h" |
| 24 | #include "ns3/log.h" |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 25 | #include "ns3/packet.h" |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 26 | #include "ns3/ccnx-name-components.h" |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 27 | #include "ns3/ccnx-interest-header.h" |
| 28 | #include "ns3/ccnx-content-object-header.h" |
Ilya Moiseenko | 1c570bc | 2011-08-17 19:18:02 -0700 | [diff] [blame] | 29 | |
| 30 | NS_LOG_COMPONENT_DEFINE ("CcnxContentStore"); |
| 31 | |
| 32 | namespace ns3 |
| 33 | { |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 34 | |
Alexander Afanasyev | a514d63 | 2012-02-14 18:54:14 -0800 | [diff] [blame] | 35 | NS_OBJECT_ENSURE_REGISTERED (CcnxContentStore); |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 36 | |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 37 | TypeId |
| 38 | CcnxContentStore::GetTypeId (void) |
| 39 | { |
| 40 | static TypeId tid = TypeId ("ns3::CcnxContentStore") |
| 41 | .SetGroupName ("Ccnx") |
| 42 | .SetParent<Object> () |
Alexander Afanasyev | 39485d8 | 2012-06-08 17:51:47 -0700 | [diff] [blame] | 43 | |
| 44 | .AddTraceSource ("CacheHits", "Trace called every time there is a cache hit", |
| 45 | MakeTraceSourceAccessor (&CcnxContentStore::m_cacheHitsTrace)) |
Alexander Afanasyev | f034cbd | 2012-06-29 14:28:31 -0700 | [diff] [blame^] | 46 | |
Alexander Afanasyev | 39485d8 | 2012-06-08 17:51:47 -0700 | [diff] [blame] | 47 | .AddTraceSource ("CacheMisses", "Trace called every time there is a cache miss", |
| 48 | MakeTraceSourceAccessor (&CcnxContentStore::m_cacheMissesTrace)) |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 49 | ; |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 50 | |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 51 | return tid; |
| 52 | } |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 53 | |
Alexander Afanasyev | fccdb9e | 2011-08-22 19:27:14 -0700 | [diff] [blame] | 54 | |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 55 | CcnxContentStore::~CcnxContentStore () |
Alexander Afanasyev | fccdb9e | 2011-08-22 19:27:14 -0700 | [diff] [blame] | 56 | { |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 57 | } |
Alexander Afanasyev | fccdb9e | 2011-08-22 19:27:14 -0700 | [diff] [blame] | 58 | |
| 59 | ////////////////////////////////////////////////////////////////////// |
| 60 | |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 61 | CcnxContentStoreEntry::CcnxContentStoreEntry (Ptr<CcnxContentObjectHeader> header, Ptr<const Packet> packet) |
| 62 | : m_header (header) |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 63 | , m_packet (packet->Copy ()) |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 64 | { |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | Ptr<Packet> |
| 68 | CcnxContentStoreEntry::GetFullyFormedCcnxPacket () const |
| 69 | { |
Alexander Afanasyev | 8accdf6 | 2011-09-20 11:33:59 -0700 | [diff] [blame] | 70 | static CcnxContentObjectTail tail; ///< \internal for optimization purposes |
| 71 | |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 72 | Ptr<Packet> packet = m_packet->Copy (); |
| 73 | packet->AddHeader (*m_header); |
Alexander Afanasyev | 8accdf6 | 2011-09-20 11:33:59 -0700 | [diff] [blame] | 74 | packet->AddTrailer (tail); |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 75 | return packet; |
| 76 | } |
| 77 | |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 78 | const CcnxNameComponents& |
| 79 | CcnxContentStoreEntry::GetName () const |
Ilya Moiseenko | 1c570bc | 2011-08-17 19:18:02 -0700 | [diff] [blame] | 80 | { |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 81 | return m_header->GetName (); |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 84 | Ptr<const CcnxContentObjectHeader> |
| 85 | CcnxContentStoreEntry::GetHeader () const |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 86 | { |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 87 | return m_header; |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 90 | Ptr<const Packet> |
| 91 | CcnxContentStoreEntry::GetPacket () const |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 92 | { |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 93 | return m_packet; |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | } // namespace ns3 |