blob: c6b977880e50b98decbf1065cd239d19accb3d8f [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 Afanasyev6eba36f2013-08-07 17:42:54 -070022#include "ndn-data.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 Afanasyev772f51b2013-08-01 18:53:25 -070028NS_LOG_COMPONENT_DEFINE ("ndn.Data");
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 Afanasyev772f51b2013-08-01 18:53:25 -070033Data::Data (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)
Alexander Afanasyev208c25d2013-08-08 21:44:45 -070037 , m_keyLocator (0)
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -070038 , m_wire (0)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070039{
Alexander Afanasyeve4795ae2013-07-11 20:01:31 -070040 if (m_payload == 0) // just in case
41 {
42 m_payload = Create<Packet> ();
43 }
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070044}
45
Alexander Afanasyev772f51b2013-08-01 18:53:25 -070046Data::Data (const Data &other)
Alexander Afanasyevb989b122013-07-10 17:15:46 -070047 : m_name (Create<Name> (other.GetName ()))
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -070048 , m_freshness (other.GetFreshness ())
49 , m_timestamp (other.GetTimestamp ())
50 , m_signature (other.GetSignature ())
51 , m_payload (other.GetPayload ()->Copy ())
Alexander Afanasyevb989b122013-07-10 17:15:46 -070052 , m_wire (0)
53{
Alexander Afanasyev208c25d2013-08-08 21:44:45 -070054 if (other.GetKeyLocator ())
55 {
56 m_keyLocator = Create<Name> (*other.GetKeyLocator ());
57 }
Alexander Afanasyevb989b122013-07-10 17:15:46 -070058}
59
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070060void
Alexander Afanasyev772f51b2013-08-01 18:53:25 -070061Data::SetName (Ptr<Name> name)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070062{
63 m_name = name;
Alexander Afanasyevee762552013-07-10 22:29:22 -070064 m_wire = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070065}
66
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070067void
Alexander Afanasyev772f51b2013-08-01 18:53:25 -070068Data::SetName (const Name &name)
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070069{
70 m_name = Create<Name> (name);
Alexander Afanasyevee762552013-07-10 22:29:22 -070071 m_wire = 0;
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070072}
73
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070074const Name&
Alexander Afanasyev772f51b2013-08-01 18:53:25 -070075Data::GetName () const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070076{
Alexander Afanasyev772f51b2013-08-01 18:53:25 -070077 if (m_name==0) throw DataException();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070078 return *m_name;
79}
80
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070081Ptr<const Name>
Alexander Afanasyev772f51b2013-08-01 18:53:25 -070082Data::GetNamePtr () const
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070083{
84 return m_name;
85}
86
Alexander Afanasyev11fdadd2012-11-19 15:43:17 -080087
88void
Alexander Afanasyev772f51b2013-08-01 18:53:25 -070089Data::SetTimestamp (const Time &timestamp)
Alexander Afanasyev11fdadd2012-11-19 15:43:17 -080090{
91 m_timestamp = timestamp;
Alexander Afanasyevee762552013-07-10 22:29:22 -070092 m_wire = 0;
Alexander Afanasyev11fdadd2012-11-19 15:43:17 -080093}
94
95Time
Alexander Afanasyev772f51b2013-08-01 18:53:25 -070096Data::GetTimestamp () const
Alexander Afanasyev11fdadd2012-11-19 15:43:17 -080097{
98 return m_timestamp;
99}
100
101void
Alexander Afanasyev772f51b2013-08-01 18:53:25 -0700102Data::SetFreshness (const Time &freshness)
Alexander Afanasyev11fdadd2012-11-19 15:43:17 -0800103{
104 m_freshness = freshness;
Alexander Afanasyevee762552013-07-10 22:29:22 -0700105 m_wire = 0;
Alexander Afanasyev11fdadd2012-11-19 15:43:17 -0800106}
107
Alexander Afanasyevee762552013-07-10 22:29:22 -0700108
Alexander Afanasyev11fdadd2012-11-19 15:43:17 -0800109Time
Alexander Afanasyev772f51b2013-08-01 18:53:25 -0700110Data::GetFreshness () const
Alexander Afanasyev11fdadd2012-11-19 15:43:17 -0800111{
112 return m_freshness;
113}
114
Alexander Afanasyevd6e5c5f2013-03-30 19:09:56 -0700115void
Alexander Afanasyev772f51b2013-08-01 18:53:25 -0700116Data::SetSignature (uint32_t signature)
Alexander Afanasyevd6e5c5f2013-03-30 19:09:56 -0700117{
118 m_signature = signature;
Alexander Afanasyevee762552013-07-10 22:29:22 -0700119 m_wire = 0;
Alexander Afanasyevd6e5c5f2013-03-30 19:09:56 -0700120}
121
122uint32_t
Alexander Afanasyev772f51b2013-08-01 18:53:25 -0700123Data::GetSignature () const
Alexander Afanasyevd6e5c5f2013-03-30 19:09:56 -0700124{
125 return m_signature;
126}
Alexander Afanasyev11fdadd2012-11-19 15:43:17 -0800127
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700128void
Alexander Afanasyev772f51b2013-08-01 18:53:25 -0700129Data::SetKeyLocator (Ptr<Name> keyLocator)
Alexander Afanasyev1043c702013-07-15 16:21:09 -0700130{
131 m_keyLocator = keyLocator;
132}
133
134Ptr<const Name>
Alexander Afanasyev772f51b2013-08-01 18:53:25 -0700135Data::GetKeyLocator () const
Alexander Afanasyev1043c702013-07-15 16:21:09 -0700136{
137 return m_keyLocator;
138}
139
140void
Alexander Afanasyev772f51b2013-08-01 18:53:25 -0700141Data::Print (std::ostream &os) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700142{
Alexander Afanasyev7f3e49e2012-04-30 00:17:07 -0700143 os << "D: " << GetName ();
Alexander Afanasyev772f51b2013-08-01 18:53:25 -0700144 // os << "<Data><Name>" << GetName () << "</Name><Content>";
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700145}
146
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700147void
Alexander Afanasyev772f51b2013-08-01 18:53:25 -0700148Data::SetPayload (Ptr<Packet> payload)
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700149{
150 m_payload = payload;
Alexander Afanasyevee762552013-07-10 22:29:22 -0700151 m_wire = 0;
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700152}
153
154Ptr<const Packet>
Alexander Afanasyev772f51b2013-08-01 18:53:25 -0700155Data::GetPayload () const
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700156{
157 return m_payload;
158}
159
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700160} // namespace ndn
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700161} // namespace ns3