Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 2 | /* |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 3 | * Copyright (c) 2011-2013 University of California, Los Angeles |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 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 | |
Alexander Afanasyev | 6eba36f | 2013-08-07 17:42:54 -0700 | [diff] [blame] | 22 | #include "ndn-data.h" |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 23 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 24 | #include "ns3/log.h" |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 25 | |
| 26 | #include <boost/foreach.hpp> |
| 27 | |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 28 | NS_LOG_COMPONENT_DEFINE ("ndn.Data"); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 29 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 30 | namespace ns3 { |
| 31 | namespace ndn { |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 32 | |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 33 | Data::Data (Ptr<Packet> payload/* = Create<Packet> ()*/) |
Alexander Afanasyev | 0a15a2b | 2013-07-18 16:23:15 -0700 | [diff] [blame] | 34 | : m_name (Create<Name> ()) |
| 35 | , m_signature (0) |
Alexander Afanasyev | faa01f9 | 2013-07-10 18:34:31 -0700 | [diff] [blame] | 36 | , m_payload (payload) |
| 37 | , m_wire (0) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 38 | { |
Alexander Afanasyev | e4795ae | 2013-07-11 20:01:31 -0700 | [diff] [blame] | 39 | if (m_payload == 0) // just in case |
| 40 | { |
| 41 | m_payload = Create<Packet> (); |
| 42 | } |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 43 | } |
| 44 | |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 45 | Data::Data (const Data &other) |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 46 | : m_name (Create<Name> (other.GetName ())) |
Alexander Afanasyev | faa01f9 | 2013-07-10 18:34:31 -0700 | [diff] [blame] | 47 | , m_freshness (other.GetFreshness ()) |
| 48 | , m_timestamp (other.GetTimestamp ()) |
| 49 | , m_signature (other.GetSignature ()) |
| 50 | , m_payload (other.GetPayload ()->Copy ()) |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 51 | , m_wire (0) |
| 52 | { |
| 53 | } |
| 54 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 55 | void |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 56 | Data::SetName (Ptr<Name> name) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 57 | { |
| 58 | m_name = name; |
Alexander Afanasyev | ee76255 | 2013-07-10 22:29:22 -0700 | [diff] [blame] | 59 | m_wire = 0; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Alexander Afanasyev | cc50d98 | 2013-03-30 19:09:10 -0700 | [diff] [blame] | 62 | void |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 63 | Data::SetName (const Name &name) |
Alexander Afanasyev | cc50d98 | 2013-03-30 19:09:10 -0700 | [diff] [blame] | 64 | { |
| 65 | m_name = Create<Name> (name); |
Alexander Afanasyev | ee76255 | 2013-07-10 22:29:22 -0700 | [diff] [blame] | 66 | m_wire = 0; |
Alexander Afanasyev | cc50d98 | 2013-03-30 19:09:10 -0700 | [diff] [blame] | 67 | } |
| 68 | |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 69 | const Name& |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 70 | Data::GetName () const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 71 | { |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 72 | if (m_name==0) throw DataException(); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 73 | return *m_name; |
| 74 | } |
| 75 | |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 76 | Ptr<const Name> |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 77 | Data::GetNamePtr () const |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 78 | { |
| 79 | return m_name; |
| 80 | } |
| 81 | |
Alexander Afanasyev | 11fdadd | 2012-11-19 15:43:17 -0800 | [diff] [blame] | 82 | |
| 83 | void |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 84 | Data::SetTimestamp (const Time ×tamp) |
Alexander Afanasyev | 11fdadd | 2012-11-19 15:43:17 -0800 | [diff] [blame] | 85 | { |
| 86 | m_timestamp = timestamp; |
Alexander Afanasyev | ee76255 | 2013-07-10 22:29:22 -0700 | [diff] [blame] | 87 | m_wire = 0; |
Alexander Afanasyev | 11fdadd | 2012-11-19 15:43:17 -0800 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | Time |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 91 | Data::GetTimestamp () const |
Alexander Afanasyev | 11fdadd | 2012-11-19 15:43:17 -0800 | [diff] [blame] | 92 | { |
| 93 | return m_timestamp; |
| 94 | } |
| 95 | |
| 96 | void |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 97 | Data::SetFreshness (const Time &freshness) |
Alexander Afanasyev | 11fdadd | 2012-11-19 15:43:17 -0800 | [diff] [blame] | 98 | { |
| 99 | m_freshness = freshness; |
Alexander Afanasyev | ee76255 | 2013-07-10 22:29:22 -0700 | [diff] [blame] | 100 | m_wire = 0; |
Alexander Afanasyev | 11fdadd | 2012-11-19 15:43:17 -0800 | [diff] [blame] | 101 | } |
| 102 | |
Alexander Afanasyev | ee76255 | 2013-07-10 22:29:22 -0700 | [diff] [blame] | 103 | |
Alexander Afanasyev | 11fdadd | 2012-11-19 15:43:17 -0800 | [diff] [blame] | 104 | Time |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 105 | Data::GetFreshness () const |
Alexander Afanasyev | 11fdadd | 2012-11-19 15:43:17 -0800 | [diff] [blame] | 106 | { |
| 107 | return m_freshness; |
| 108 | } |
| 109 | |
Alexander Afanasyev | d6e5c5f | 2013-03-30 19:09:56 -0700 | [diff] [blame] | 110 | void |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 111 | Data::SetSignature (uint32_t signature) |
Alexander Afanasyev | d6e5c5f | 2013-03-30 19:09:56 -0700 | [diff] [blame] | 112 | { |
| 113 | m_signature = signature; |
Alexander Afanasyev | ee76255 | 2013-07-10 22:29:22 -0700 | [diff] [blame] | 114 | m_wire = 0; |
Alexander Afanasyev | d6e5c5f | 2013-03-30 19:09:56 -0700 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | uint32_t |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 118 | Data::GetSignature () const |
Alexander Afanasyev | d6e5c5f | 2013-03-30 19:09:56 -0700 | [diff] [blame] | 119 | { |
| 120 | return m_signature; |
| 121 | } |
Alexander Afanasyev | 11fdadd | 2012-11-19 15:43:17 -0800 | [diff] [blame] | 122 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 123 | void |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 124 | Data::SetKeyLocator (Ptr<Name> keyLocator) |
Alexander Afanasyev | 1043c70 | 2013-07-15 16:21:09 -0700 | [diff] [blame] | 125 | { |
| 126 | m_keyLocator = keyLocator; |
| 127 | } |
| 128 | |
| 129 | Ptr<const Name> |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 130 | Data::GetKeyLocator () const |
Alexander Afanasyev | 1043c70 | 2013-07-15 16:21:09 -0700 | [diff] [blame] | 131 | { |
| 132 | return m_keyLocator; |
| 133 | } |
| 134 | |
| 135 | void |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 136 | Data::Print (std::ostream &os) const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 137 | { |
Alexander Afanasyev | 7f3e49e | 2012-04-30 00:17:07 -0700 | [diff] [blame] | 138 | os << "D: " << GetName (); |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 139 | // os << "<Data><Name>" << GetName () << "</Name><Content>"; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 140 | } |
| 141 | |
Alexander Afanasyev | faa01f9 | 2013-07-10 18:34:31 -0700 | [diff] [blame] | 142 | void |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 143 | Data::SetPayload (Ptr<Packet> payload) |
Alexander Afanasyev | faa01f9 | 2013-07-10 18:34:31 -0700 | [diff] [blame] | 144 | { |
| 145 | m_payload = payload; |
Alexander Afanasyev | ee76255 | 2013-07-10 22:29:22 -0700 | [diff] [blame] | 146 | m_wire = 0; |
Alexander Afanasyev | faa01f9 | 2013-07-10 18:34:31 -0700 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | Ptr<const Packet> |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 150 | Data::GetPayload () const |
Alexander Afanasyev | faa01f9 | 2013-07-10 18:34:31 -0700 | [diff] [blame] | 151 | { |
| 152 | return m_payload; |
| 153 | } |
| 154 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 155 | } // namespace ndn |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 156 | } // namespace ns3 |