blob: 9df1d275ec727e14abd1eba0d9c449f848e8ac89 [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 Afanasyev0a15a2b2013-07-18 16:23:15 -070034 : m_name (Create<Name> ())
35 , m_signature (0)
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -070036 , m_payload (payload)
37 , m_wire (0)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070038{
Alexander Afanasyeve4795ae2013-07-11 20:01:31 -070039 if (m_payload == 0) // just in case
40 {
41 m_payload = Create<Packet> ();
42 }
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070043}
44
Alexander Afanasyevb989b122013-07-10 17:15:46 -070045ContentObject::ContentObject (const ContentObject &other)
46 : m_name (Create<Name> (other.GetName ()))
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -070047 , m_freshness (other.GetFreshness ())
48 , m_timestamp (other.GetTimestamp ())
49 , m_signature (other.GetSignature ())
50 , m_payload (other.GetPayload ()->Copy ())
Alexander Afanasyevb989b122013-07-10 17:15:46 -070051 , m_wire (0)
52{
53}
54
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070055void
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070056ContentObject::SetName (Ptr<Name> name)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070057{
58 m_name = name;
Alexander Afanasyevee762552013-07-10 22:29:22 -070059 m_wire = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070060}
61
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070062void
63ContentObject::SetName (const Name &name)
64{
65 m_name = Create<Name> (name);
Alexander Afanasyevee762552013-07-10 22:29:22 -070066 m_wire = 0;
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070067}
68
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070069const Name&
70ContentObject::GetName () const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070071{
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070072 if (m_name==0) throw ContentObjectException();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070073 return *m_name;
74}
75
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070076Ptr<const Name>
77ContentObject::GetNamePtr () const
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070078{
79 return m_name;
80}
81
Alexander Afanasyev11fdadd2012-11-19 15:43:17 -080082
83void
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070084ContentObject::SetTimestamp (const Time &timestamp)
Alexander Afanasyev11fdadd2012-11-19 15:43:17 -080085{
86 m_timestamp = timestamp;
Alexander Afanasyevee762552013-07-10 22:29:22 -070087 m_wire = 0;
Alexander Afanasyev11fdadd2012-11-19 15:43:17 -080088}
89
90Time
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070091ContentObject::GetTimestamp () const
Alexander Afanasyev11fdadd2012-11-19 15:43:17 -080092{
93 return m_timestamp;
94}
95
96void
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070097ContentObject::SetFreshness (const Time &freshness)
Alexander Afanasyev11fdadd2012-11-19 15:43:17 -080098{
99 m_freshness = freshness;
Alexander Afanasyevee762552013-07-10 22:29:22 -0700100 m_wire = 0;
Alexander Afanasyev11fdadd2012-11-19 15:43:17 -0800101}
102
Alexander Afanasyevee762552013-07-10 22:29:22 -0700103
Alexander Afanasyev11fdadd2012-11-19 15:43:17 -0800104Time
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -0700105ContentObject::GetFreshness () const
Alexander Afanasyev11fdadd2012-11-19 15:43:17 -0800106{
107 return m_freshness;
108}
109
Alexander Afanasyevd6e5c5f2013-03-30 19:09:56 -0700110void
111ContentObject::SetSignature (uint32_t signature)
112{
113 m_signature = signature;
Alexander Afanasyevee762552013-07-10 22:29:22 -0700114 m_wire = 0;
Alexander Afanasyevd6e5c5f2013-03-30 19:09:56 -0700115}
116
117uint32_t
118ContentObject::GetSignature () const
119{
120 return m_signature;
121}
Alexander Afanasyev11fdadd2012-11-19 15:43:17 -0800122
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700123void
Alexander Afanasyev1043c702013-07-15 16:21:09 -0700124ContentObject::SetKeyLocator (Ptr<Name> keyLocator)
125{
126 m_keyLocator = keyLocator;
127}
128
129Ptr<const Name>
130ContentObject::GetKeyLocator () const
131{
132 return m_keyLocator;
133}
134
135void
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -0700136ContentObject::Print (std::ostream &os) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700137{
Alexander Afanasyev7f3e49e2012-04-30 00:17:07 -0700138 os << "D: " << GetName ();
139 // os << "<ContentObject><Name>" << GetName () << "</Name><Content>";
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700140}
141
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700142void
143ContentObject::SetPayload (Ptr<Packet> payload)
144{
145 m_payload = payload;
Alexander Afanasyevee762552013-07-10 22:29:22 -0700146 m_wire = 0;
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700147}
148
149Ptr<const Packet>
150ContentObject::GetPayload () const
151{
152 return m_payload;
153}
154
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700155} // namespace ndn
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700156} // namespace ns3