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 | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 25 | #include "ns3/ccnx-encoding-helper.h" |
| 26 | #include "ns3/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 |
| 52 | CcnxContentObjectHeader::SetName (const Ptr<Name::Components> &name) |
| 53 | { |
| 54 | m_name = name; |
| 55 | } |
| 56 | |
| 57 | const Name::Components& |
| 58 | CcnxContentObjectHeader::GetName () const |
| 59 | { |
| 60 | return *m_name; |
| 61 | } |
| 62 | |
| 63 | uint32_t |
| 64 | CcnxContentObjectHeader::GetSerializedSize (void) const |
| 65 | { |
Alexander Afanasyev | 2a5df20 | 2011-08-15 22:39:05 -0700 | [diff] [blame] | 66 | // Unfortunately, two serializations are required, unless we can pre-calculate header length... which is not trivial |
| 67 | Buffer tmp; |
| 68 | |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 69 | return CcnxEncodingHelper::Serialize (tmp.Begin(), *this); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | void |
| 73 | CcnxContentObjectHeader::Serialize (Buffer::Iterator start) const |
| 74 | { |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 75 | CcnxEncodingHelper::Serialize (start, *this); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | uint32_t |
| 79 | CcnxContentObjectHeader::Deserialize (Buffer::Iterator start) |
| 80 | { |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 81 | return CcnxDecodingHelper::Deserialize (start, *this); // \todo Debugging is necessary |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | TypeId |
| 85 | CcnxContentObjectHeader::GetInstanceTypeId (void) const |
| 86 | { |
| 87 | return GetTypeId (); |
| 88 | } |
| 89 | |
| 90 | void |
| 91 | CcnxContentObjectHeader::Print (std::ostream &os) const |
| 92 | { |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 93 | os << "<ContentObject><Name>" << *m_name << "</Name><Content>"; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 96 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 97 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 98 | |
| 99 | CcnxContentObjectTail::CcnxContentObjectTail () |
| 100 | { |
| 101 | } |
| 102 | |
| 103 | TypeId |
| 104 | CcnxContentObjectTail::GetTypeId (void) |
| 105 | { |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 106 | static TypeId tid = TypeId ("ns3::CcnxContentObjectTail") |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 107 | .SetParent<Header> () |
| 108 | .AddConstructor<CcnxContentObjectHeader> () |
| 109 | ; |
| 110 | return tid; |
| 111 | } |
| 112 | |
| 113 | TypeId |
| 114 | CcnxContentObjectTail::GetInstanceTypeId (void) const |
| 115 | { |
| 116 | return GetTypeId (); |
| 117 | } |
| 118 | |
| 119 | void |
| 120 | CcnxContentObjectTail::Print (std::ostream &os) const |
| 121 | { |
| 122 | os << "</Content></ContentObject>"; |
| 123 | } |
| 124 | |
| 125 | uint32_t |
| 126 | CcnxContentObjectTail::GetSerializedSize (void) const |
| 127 | { |
| 128 | return 2; |
| 129 | } |
| 130 | |
| 131 | void |
| 132 | CcnxContentObjectTail::Serialize (Buffer::Iterator start) const |
| 133 | { |
| 134 | Buffer::Iterator i = start; |
| 135 | i.WriteU8 (0x00); // </Content> |
| 136 | i.WriteU8 (0x00); // </ContentObject> |
| 137 | } |
| 138 | |
| 139 | uint32_t |
| 140 | CcnxContentObjectTail::Deserialize (Buffer::Iterator start) |
| 141 | { |
| 142 | Buffer::Iterator i = start; |
| 143 | uint8_t __attribute__ ((unused)) closing_tag_content = i.ReadU8 (); |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 144 | 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] | 145 | |
| 146 | uint8_t __attribute__ ((unused)) closing_tag_content_object = i.ReadU8 (); |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 147 | 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] | 148 | |
| 149 | return 2; |
| 150 | } |
| 151 | |
| 152 | } // namespace ns3 |