blob: ecf31971ac81ac6033b9a44e8cbe67a91b4d98b6 [file] [log] [blame]
Alexander Afanasyev4aac5572012-08-09 10:49:55 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -07002/*
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -07003 * Copyright (c) 2011-2013 University of California, Los Angeles
Alexander Afanasyev08d984e2011-08-13 19:20:22 -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 *
18 * Author: Ilya Moiseenko <iliamo@cs.ucla.edu>
19 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
20 */
21
Alexander Afanasyevbd9c18e2012-11-19 15:23:41 -080022#include "ndn-content-object.h"
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070023
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070024#include "ns3/log.h"
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -070025
26#include <boost/foreach.hpp>
27
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070028NS_LOG_COMPONENT_DEFINE ("ndn.ContentObject");
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070029
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070030namespace ns3 {
31namespace ndn {
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -070032
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -070033ContentObject::ContentObject (Ptr<Packet> payload/* = Create<Packet> ()*/)
Alexander Afanasyevd6e5c5f2013-03-30 19:09:56 -070034 : m_signature (0)
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -070035 , m_payload (payload)
36 , m_wire (0)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070037{
Alexander Afanasyeve4795ae2013-07-11 20:01:31 -070038 if (m_payload == 0) // just in case
39 {
40 m_payload = Create<Packet> ();
41 }
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070042}
43
Alexander Afanasyevb989b122013-07-10 17:15:46 -070044ContentObject::ContentObject (const ContentObject &other)
45 : m_name (Create<Name> (other.GetName ()))
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -070046 , m_freshness (other.GetFreshness ())
47 , m_timestamp (other.GetTimestamp ())
48 , m_signature (other.GetSignature ())
49 , m_payload (other.GetPayload ()->Copy ())
Alexander Afanasyevb989b122013-07-10 17:15:46 -070050 , m_wire (0)
51{
52}
53
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070054void
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070055ContentObject::SetName (Ptr<Name> name)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070056{
57 m_name = name;
Alexander Afanasyevee762552013-07-10 22:29:22 -070058 m_wire = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070059}
60
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070061void
62ContentObject::SetName (const Name &name)
63{
64 m_name = Create<Name> (name);
Alexander Afanasyevee762552013-07-10 22:29:22 -070065 m_wire = 0;
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070066}
67
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070068const Name&
69ContentObject::GetName () const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070070{
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070071 if (m_name==0) throw ContentObjectException();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070072 return *m_name;
73}
74
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070075Ptr<const Name>
76ContentObject::GetNamePtr () const
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070077{
78 return m_name;
79}
80
Alexander Afanasyev11fdadd2012-11-19 15:43:17 -080081
82void
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070083ContentObject::SetTimestamp (const Time &timestamp)
Alexander Afanasyev11fdadd2012-11-19 15:43:17 -080084{
85 m_timestamp = timestamp;
Alexander Afanasyevee762552013-07-10 22:29:22 -070086 m_wire = 0;
Alexander Afanasyev11fdadd2012-11-19 15:43:17 -080087}
88
89Time
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070090ContentObject::GetTimestamp () const
Alexander Afanasyev11fdadd2012-11-19 15:43:17 -080091{
92 return m_timestamp;
93}
94
95void
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070096ContentObject::SetFreshness (const Time &freshness)
Alexander Afanasyev11fdadd2012-11-19 15:43:17 -080097{
98 m_freshness = freshness;
Alexander Afanasyevee762552013-07-10 22:29:22 -070099 m_wire = 0;
Alexander Afanasyev11fdadd2012-11-19 15:43:17 -0800100}
101
Alexander Afanasyevee762552013-07-10 22:29:22 -0700102
Alexander Afanasyev11fdadd2012-11-19 15:43:17 -0800103Time
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -0700104ContentObject::GetFreshness () const
Alexander Afanasyev11fdadd2012-11-19 15:43:17 -0800105{
106 return m_freshness;
107}
108
Alexander Afanasyevd6e5c5f2013-03-30 19:09:56 -0700109void
110ContentObject::SetSignature (uint32_t signature)
111{
112 m_signature = signature;
Alexander Afanasyevee762552013-07-10 22:29:22 -0700113 m_wire = 0;
Alexander Afanasyevd6e5c5f2013-03-30 19:09:56 -0700114}
115
116uint32_t
117ContentObject::GetSignature () const
118{
119 return m_signature;
120}
Alexander Afanasyev11fdadd2012-11-19 15:43:17 -0800121
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700122void
Alexander Afanasyev1043c702013-07-15 16:21:09 -0700123ContentObject::SetKeyLocator (Ptr<Name> keyLocator)
124{
125 m_keyLocator = keyLocator;
126}
127
128Ptr<const Name>
129ContentObject::GetKeyLocator () const
130{
131 return m_keyLocator;
132}
133
134void
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -0700135ContentObject::Print (std::ostream &os) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700136{
Alexander Afanasyev7f3e49e2012-04-30 00:17:07 -0700137 os << "D: " << GetName ();
138 // os << "<ContentObject><Name>" << GetName () << "</Name><Content>";
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700139}
140
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700141void
142ContentObject::SetPayload (Ptr<Packet> payload)
143{
144 m_payload = payload;
Alexander Afanasyevee762552013-07-10 22:29:22 -0700145 m_wire = 0;
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700146}
147
148Ptr<const Packet>
149ContentObject::GetPayload () const
150{
151 return m_payload;
152}
153
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700154} // namespace ndn
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700155} // namespace ns3