blob: 2f47aec96776c064b2f0c2831c2b8c19244e80a4 [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)
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 Afanasyev772f51b2013-08-01 18:53:25 -070045Data::Data (const Data &other)
Alexander Afanasyevb989b122013-07-10 17:15:46 -070046 : 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 Afanasyev772f51b2013-08-01 18:53:25 -070056Data::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
Alexander Afanasyev772f51b2013-08-01 18:53:25 -070063Data::SetName (const Name &name)
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070064{
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&
Alexander Afanasyev772f51b2013-08-01 18:53:25 -070070Data::GetName () const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070071{
Alexander Afanasyev772f51b2013-08-01 18:53:25 -070072 if (m_name==0) throw DataException();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070073 return *m_name;
74}
75
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070076Ptr<const Name>
Alexander Afanasyev772f51b2013-08-01 18:53:25 -070077Data::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 Afanasyev772f51b2013-08-01 18:53:25 -070084Data::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 Afanasyev772f51b2013-08-01 18:53:25 -070091Data::GetTimestamp () const
Alexander Afanasyev11fdadd2012-11-19 15:43:17 -080092{
93 return m_timestamp;
94}
95
96void
Alexander Afanasyev772f51b2013-08-01 18:53:25 -070097Data::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 Afanasyev772f51b2013-08-01 18:53:25 -0700105Data::GetFreshness () const
Alexander Afanasyev11fdadd2012-11-19 15:43:17 -0800106{
107 return m_freshness;
108}
109
Alexander Afanasyevd6e5c5f2013-03-30 19:09:56 -0700110void
Alexander Afanasyev772f51b2013-08-01 18:53:25 -0700111Data::SetSignature (uint32_t signature)
Alexander Afanasyevd6e5c5f2013-03-30 19:09:56 -0700112{
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
Alexander Afanasyev772f51b2013-08-01 18:53:25 -0700118Data::GetSignature () const
Alexander Afanasyevd6e5c5f2013-03-30 19:09:56 -0700119{
120 return m_signature;
121}
Alexander Afanasyev11fdadd2012-11-19 15:43:17 -0800122
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700123void
Alexander Afanasyev772f51b2013-08-01 18:53:25 -0700124Data::SetKeyLocator (Ptr<Name> keyLocator)
Alexander Afanasyev1043c702013-07-15 16:21:09 -0700125{
126 m_keyLocator = keyLocator;
127}
128
129Ptr<const Name>
Alexander Afanasyev772f51b2013-08-01 18:53:25 -0700130Data::GetKeyLocator () const
Alexander Afanasyev1043c702013-07-15 16:21:09 -0700131{
132 return m_keyLocator;
133}
134
135void
Alexander Afanasyev772f51b2013-08-01 18:53:25 -0700136Data::Print (std::ostream &os) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700137{
Alexander Afanasyev7f3e49e2012-04-30 00:17:07 -0700138 os << "D: " << GetName ();
Alexander Afanasyev772f51b2013-08-01 18:53:25 -0700139 // os << "<Data><Name>" << GetName () << "</Name><Content>";
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700140}
141
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700142void
Alexander Afanasyev772f51b2013-08-01 18:53:25 -0700143Data::SetPayload (Ptr<Packet> payload)
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700144{
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>
Alexander Afanasyev772f51b2013-08-01 18:53:25 -0700150Data::GetPayload () const
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700151{
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