blob: 7fcb45918a47b0967f353180c267e978fe371732 [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{
38}
39
Alexander Afanasyevb989b122013-07-10 17:15:46 -070040ContentObject::ContentObject (const ContentObject &other)
41 : m_name (Create<Name> (other.GetName ()))
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -070042 , m_freshness (other.GetFreshness ())
43 , m_timestamp (other.GetTimestamp ())
44 , m_signature (other.GetSignature ())
45 , m_payload (other.GetPayload ()->Copy ())
Alexander Afanasyevb989b122013-07-10 17:15:46 -070046 , m_wire (0)
47{
48}
49
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070050void
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070051ContentObject::SetName (Ptr<Name> name)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070052{
53 m_name = name;
54}
55
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070056void
57ContentObject::SetName (const Name &name)
58{
59 m_name = Create<Name> (name);
60}
61
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070062const Name&
63ContentObject::GetName () const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070064{
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070065 if (m_name==0) throw ContentObjectException();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070066 return *m_name;
67}
68
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070069Ptr<const Name>
70ContentObject::GetNamePtr () const
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070071{
72 return m_name;
73}
74
Alexander Afanasyev11fdadd2012-11-19 15:43:17 -080075
76void
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070077ContentObject::SetTimestamp (const Time &timestamp)
Alexander Afanasyev11fdadd2012-11-19 15:43:17 -080078{
79 m_timestamp = timestamp;
80}
81
82Time
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070083ContentObject::GetTimestamp () const
Alexander Afanasyev11fdadd2012-11-19 15:43:17 -080084{
85 return m_timestamp;
86}
87
88void
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070089ContentObject::SetFreshness (const Time &freshness)
Alexander Afanasyev11fdadd2012-11-19 15:43:17 -080090{
91 m_freshness = freshness;
92}
93
94Time
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070095ContentObject::GetFreshness () const
Alexander Afanasyev11fdadd2012-11-19 15:43:17 -080096{
97 return m_freshness;
98}
99
Alexander Afanasyevd6e5c5f2013-03-30 19:09:56 -0700100void
101ContentObject::SetSignature (uint32_t signature)
102{
103 m_signature = signature;
104}
105
106uint32_t
107ContentObject::GetSignature () const
108{
109 return m_signature;
110}
Alexander Afanasyev11fdadd2012-11-19 15:43:17 -0800111
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700112void
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -0700113ContentObject::Print (std::ostream &os) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700114{
Alexander Afanasyev7f3e49e2012-04-30 00:17:07 -0700115 os << "D: " << GetName ();
116 // os << "<ContentObject><Name>" << GetName () << "</Name><Content>";
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700117}
118
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700119void
120ContentObject::SetPayload (Ptr<Packet> payload)
121{
122 m_payload = payload;
123}
124
125Ptr<const Packet>
126ContentObject::GetPayload () const
127{
128 return m_payload;
129}
130
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700131} // namespace ndn
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700132} // namespace ns3