blob: 986405f78a9c94b3233d623883326eb3dd8fb384 [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 Afanasyevcf133f02011-09-06 12:13:48 -070043 ;
Alexander Afanasyev070aa482011-08-20 00:38:25 -070044
Alexander Afanasyevcf133f02011-09-06 12:13:48 -070045 return tid;
46}
Alexander Afanasyev070aa482011-08-20 00:38:25 -070047
Alexander Afanasyevfccdb9e2011-08-22 19:27:14 -070048
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070049CcnxContentStore::~CcnxContentStore ()
Alexander Afanasyevfccdb9e2011-08-22 19:27:14 -070050{
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070051}
Alexander Afanasyevfccdb9e2011-08-22 19:27:14 -070052
53//////////////////////////////////////////////////////////////////////
54
Alexander Afanasyev070aa482011-08-20 00:38:25 -070055CcnxContentStoreEntry::CcnxContentStoreEntry (Ptr<CcnxContentObjectHeader> header, Ptr<const Packet> packet)
56 : m_header (header)
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070057 , m_packet (packet->Copy ())
Alexander Afanasyev070aa482011-08-20 00:38:25 -070058{
Alexander Afanasyev070aa482011-08-20 00:38:25 -070059}
60
61Ptr<Packet>
62CcnxContentStoreEntry::GetFullyFormedCcnxPacket () const
63{
Alexander Afanasyev8accdf62011-09-20 11:33:59 -070064 static CcnxContentObjectTail tail; ///< \internal for optimization purposes
65
Alexander Afanasyev070aa482011-08-20 00:38:25 -070066 Ptr<Packet> packet = m_packet->Copy ();
67 packet->AddHeader (*m_header);
Alexander Afanasyev8accdf62011-09-20 11:33:59 -070068 packet->AddTrailer (tail);
Alexander Afanasyev070aa482011-08-20 00:38:25 -070069 return packet;
70}
71
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070072const CcnxNameComponents&
73CcnxContentStoreEntry::GetName () const
Ilya Moiseenko1c570bc2011-08-17 19:18:02 -070074{
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070075 return m_header->GetName ();
Alexander Afanasyev070aa482011-08-20 00:38:25 -070076}
77
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070078Ptr<const CcnxContentObjectHeader>
79CcnxContentStoreEntry::GetHeader () const
Alexander Afanasyev070aa482011-08-20 00:38:25 -070080{
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070081 return m_header;
Alexander Afanasyev070aa482011-08-20 00:38:25 -070082}
83
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070084Ptr<const Packet>
85CcnxContentStoreEntry::GetPacket () const
Alexander Afanasyev070aa482011-08-20 00:38:25 -070086{
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070087 return m_packet;
Alexander Afanasyev070aa482011-08-20 00:38:25 -070088}
89
90} // namespace ns3