Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -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 | /* |
| 3 | * Copyright (c) 2011 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 "ccnx-content-object-header.h" |
| 23 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 24 | #include "ns3/log.h" |
Alexander Afanasyev | f9f4eb0 | 2011-12-16 01:51:14 -0800 | [diff] [blame] | 25 | #include "../helper/ccnx-encoding-helper.h" |
| 26 | #include "../helper/ccnx-decoding-helper.h" |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 27 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 28 | NS_LOG_COMPONENT_DEFINE ("CcnxContentObjectHeader"); |
| 29 | |
| 30 | namespace ns3 |
| 31 | { |
| 32 | |
| 33 | NS_OBJECT_ENSURE_REGISTERED (CcnxContentObjectHeader); |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 34 | NS_OBJECT_ENSURE_REGISTERED (CcnxContentObjectTail); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 35 | |
| 36 | TypeId |
| 37 | CcnxContentObjectHeader::GetTypeId (void) |
| 38 | { |
| 39 | static TypeId tid = TypeId ("ns3::CcnxContentObjectHeader") |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 40 | .SetGroupName ("Ccnx") |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 41 | .SetParent<Header> () |
| 42 | .AddConstructor<CcnxContentObjectHeader> () |
| 43 | ; |
| 44 | return tid; |
| 45 | } |
| 46 | |
| 47 | CcnxContentObjectHeader::CcnxContentObjectHeader () |
| 48 | { |
| 49 | } |
| 50 | |
| 51 | void |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame] | 52 | CcnxContentObjectHeader::SetName (const Ptr<CcnxNameComponents> &name) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 53 | { |
| 54 | m_name = name; |
| 55 | } |
| 56 | |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame] | 57 | const CcnxNameComponents& |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 58 | CcnxContentObjectHeader::GetName () const |
| 59 | { |
Alexander Afanasyev | e91ab75 | 2011-08-31 19:13:40 -0700 | [diff] [blame] | 60 | if (m_name==0) throw CcnxContentObjectHeaderException(); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 61 | return *m_name; |
| 62 | } |
| 63 | |
Alexander Afanasyev | 9568f95 | 2012-04-05 16:09:14 -0700 | [diff] [blame] | 64 | void |
| 65 | CcnxContentObjectHeader::SetTimestamp (const Time ×tamp) |
| 66 | { |
| 67 | m_signedInfo.m_timestamp = timestamp; |
| 68 | } |
| 69 | |
| 70 | Time |
| 71 | CcnxContentObjectHeader::GetTimestamp () const |
| 72 | { |
| 73 | return m_signedInfo.m_timestamp; |
| 74 | } |
| 75 | |
| 76 | void |
| 77 | CcnxContentObjectHeader::SetFreshness (const Time &freshness) |
| 78 | { |
| 79 | m_signedInfo.m_freshness = freshness; |
| 80 | } |
| 81 | |
| 82 | Time |
| 83 | CcnxContentObjectHeader::GetFreshness () const |
| 84 | { |
| 85 | return m_signedInfo.m_freshness; |
| 86 | } |
| 87 | |
| 88 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 89 | uint32_t |
| 90 | CcnxContentObjectHeader::GetSerializedSize (void) const |
| 91 | { |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 92 | // unfortunately, we don't know exact header size in advance |
| 93 | return CcnxEncodingHelper::GetSerializedSize (*this); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | void |
| 97 | CcnxContentObjectHeader::Serialize (Buffer::Iterator start) const |
| 98 | { |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 99 | CcnxEncodingHelper::Serialize (start, *this); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | uint32_t |
| 103 | CcnxContentObjectHeader::Deserialize (Buffer::Iterator start) |
| 104 | { |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 105 | return CcnxDecodingHelper::Deserialize (start, *this); // \todo Debugging is necessary |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | TypeId |
| 109 | CcnxContentObjectHeader::GetInstanceTypeId (void) const |
| 110 | { |
| 111 | return GetTypeId (); |
| 112 | } |
| 113 | |
| 114 | void |
| 115 | CcnxContentObjectHeader::Print (std::ostream &os) const |
| 116 | { |
Alexander Afanasyev | e91ab75 | 2011-08-31 19:13:40 -0700 | [diff] [blame] | 117 | os << "<ContentObject><Name>" << GetName () << "</Name><Content>"; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 120 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 121 | |
| 122 | CcnxContentObjectTail::CcnxContentObjectTail () |
| 123 | { |
| 124 | } |
| 125 | |
| 126 | TypeId |
| 127 | CcnxContentObjectTail::GetTypeId (void) |
| 128 | { |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 129 | static TypeId tid = TypeId ("ns3::CcnxContentObjectTail") |
Alexander Afanasyev | e91ab75 | 2011-08-31 19:13:40 -0700 | [diff] [blame] | 130 | .SetParent<Trailer> () |
| 131 | .AddConstructor<CcnxContentObjectTail> () |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 132 | ; |
| 133 | return tid; |
| 134 | } |
| 135 | |
| 136 | TypeId |
| 137 | CcnxContentObjectTail::GetInstanceTypeId (void) const |
| 138 | { |
| 139 | return GetTypeId (); |
| 140 | } |
| 141 | |
| 142 | void |
| 143 | CcnxContentObjectTail::Print (std::ostream &os) const |
| 144 | { |
| 145 | os << "</Content></ContentObject>"; |
| 146 | } |
| 147 | |
| 148 | uint32_t |
| 149 | CcnxContentObjectTail::GetSerializedSize (void) const |
| 150 | { |
| 151 | return 2; |
| 152 | } |
| 153 | |
| 154 | void |
| 155 | CcnxContentObjectTail::Serialize (Buffer::Iterator start) const |
| 156 | { |
| 157 | Buffer::Iterator i = start; |
Alexander Afanasyev | e91ab75 | 2011-08-31 19:13:40 -0700 | [diff] [blame] | 158 | i.Prev (2); // Trailer interface requires us to go backwards |
| 159 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 160 | i.WriteU8 (0x00); // </Content> |
| 161 | i.WriteU8 (0x00); // </ContentObject> |
| 162 | } |
| 163 | |
| 164 | uint32_t |
| 165 | CcnxContentObjectTail::Deserialize (Buffer::Iterator start) |
| 166 | { |
| 167 | Buffer::Iterator i = start; |
Alexander Afanasyev | e91ab75 | 2011-08-31 19:13:40 -0700 | [diff] [blame] | 168 | i.Prev (2); // Trailer interface requires us to go backwards |
| 169 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 170 | uint8_t __attribute__ ((unused)) closing_tag_content = i.ReadU8 (); |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 171 | NS_ASSERT_MSG (closing_tag_content==0, "Should be a closing tag </Content> (0x00)"); |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 172 | |
| 173 | uint8_t __attribute__ ((unused)) closing_tag_content_object = i.ReadU8 (); |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 174 | NS_ASSERT_MSG (closing_tag_content_object==0, "Should be a closing tag </ContentObject> (0x00)"); |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 175 | |
| 176 | return 2; |
| 177 | } |
| 178 | |
| 179 | } // namespace ns3 |