NS-3 based Named Data Networking (NDN) simulator
ndnSIM: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
ndn-data.cc
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2 /*
3  * Copyright (c) 2011-2013 University of California, Los Angeles
4  *
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 
22 #include "ndn-data.h"
23 
24 #include "ns3/log.h"
25 
26 #include <boost/foreach.hpp>
27 
28 NS_LOG_COMPONENT_DEFINE ("ndn.Data");
29 
30 namespace ns3 {
31 namespace ndn {
32 
33 Data::Data (Ptr<Packet> payload/* = Create<Packet> ()*/)
34  : m_name (Create<Name> ())
35  , m_signature (0)
36  , m_payload (payload)
37  , m_keyLocator (0)
38  , m_wire (0)
39 {
40  if (m_payload == 0) // just in case
41  {
42  m_payload = Create<Packet> ();
43  }
44 }
45 
46 Data::Data (const Data &other)
47  : m_name (Create<Name> (other.GetName ()))
48  , m_freshness (other.GetFreshness ())
49  , m_timestamp (other.GetTimestamp ())
50  , m_signature (other.GetSignature ())
51  , m_payload (other.GetPayload ()->Copy ())
52  , m_wire (0)
53 {
54  if (other.GetKeyLocator ())
55  {
56  m_keyLocator = Create<Name> (*other.GetKeyLocator ());
57  }
58 }
59 
60 void
61 Data::SetName (Ptr<Name> name)
62 {
63  m_name = name;
64  m_wire = 0;
65 }
66 
67 void
68 Data::SetName (const Name &name)
69 {
70  m_name = Create<Name> (name);
71  m_wire = 0;
72 }
73 
74 const Name&
75 Data::GetName () const
76 {
77  if (m_name==0) throw DataException();
78  return *m_name;
79 }
80 
81 Ptr<const Name>
83 {
84  return m_name;
85 }
86 
87 
88 void
89 Data::SetTimestamp (const Time &timestamp)
90 {
91  m_timestamp = timestamp;
92  m_wire = 0;
93 }
94 
95 Time
97 {
98  return m_timestamp;
99 }
100 
101 void
102 Data::SetFreshness (const Time &freshness)
103 {
104  m_freshness = freshness;
105  m_wire = 0;
106 }
107 
108 
109 Time
111 {
112  return m_freshness;
113 }
114 
115 void
116 Data::SetSignature (uint32_t signature)
117 {
118  m_signature = signature;
119  m_wire = 0;
120 }
121 
122 uint32_t
124 {
125  return m_signature;
126 }
127 
128 void
129 Data::SetKeyLocator (Ptr<Name> keyLocator)
130 {
131  m_keyLocator = keyLocator;
132 }
133 
134 Ptr<const Name>
136 {
137  return m_keyLocator;
138 }
139 
140 void
141 Data::Print (std::ostream &os) const
142 {
143  os << "D: " << GetName ();
144  // os << "<Data><Name>" << GetName () << "</Name><Content>";
145 }
146 
147 void
148 Data::SetPayload (Ptr<Packet> payload)
149 {
150  m_payload = payload;
151  m_wire = 0;
152 }
153 
154 Ptr<const Packet>
156 {
157  return m_payload;
158 }
159 
160 } // namespace ndn
161 } // namespace ns3
Data(Ptr< Packet > payload=Create< Packet >())
Constructor.
Definition: ndn-data.cc:33
void Print(std::ostream &os) const
Print Interest in plain-text to the specified output stream.
Definition: ndn-data.cc:141
Class for NDN Name.
Definition: name.h:29
Ptr< const Name > GetNamePtr() const
Get smart pointer to the interest name (to avoid extra memory usage)
Definition: ndn-data.cc:82
Ptr< const Name > GetKeyLocator() const
Get key locator.
Definition: ndn-data.cc:135
void SetTimestamp(const Time &timestamp)
Set content object timestamp.
Definition: ndn-data.cc:89
Data header.
Definition: ndn-data.h:39
const Name & GetName() const
Get name of the content object.
Definition: ndn-data.cc:75
void SetKeyLocator(Ptr< Name > keyLocator)
Set key locator.
Definition: ndn-data.cc:129
void SetFreshness(const Time &freshness)
Set freshness of the content object.
Definition: ndn-data.cc:102
Time GetTimestamp() const
Get timestamp of the content object.
Definition: ndn-data.cc:96
Class for Data parsing exception.
Definition: ndn-data.h:203
void SetPayload(Ptr< Packet > payload)
Get payload of data packet.
Definition: ndn-data.cc:148
void SetName(Ptr< Name > name)
Set content object name.
Definition: ndn-data.cc:61
uint32_t GetSignature() const
Get "fake" signature of the content object.
Definition: ndn-data.cc:123
Time GetFreshness() const
Get freshness of the content object.
Definition: ndn-data.cc:110
void SetSignature(uint32_t signature)
Set "fake" signature on the content object.
Definition: ndn-data.cc:116
Ptr< const Packet > GetPayload() const
Set payload of data packet.
Definition: ndn-data.cc:155