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 | 2a5df20 | 2011-08-15 22:39:05 -0700 | [diff] [blame^] | 25 | #include "ns3/ccnx-coding-helper.h" |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 26 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 27 | NS_LOG_COMPONENT_DEFINE ("CcnxContentObjectHeader"); |
| 28 | |
| 29 | namespace ns3 |
| 30 | { |
| 31 | |
| 32 | NS_OBJECT_ENSURE_REGISTERED (CcnxContentObjectHeader); |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 33 | NS_OBJECT_ENSURE_REGISTERED (CcnxContentObjectTail); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 34 | |
| 35 | TypeId |
| 36 | CcnxContentObjectHeader::GetTypeId (void) |
| 37 | { |
| 38 | static TypeId tid = TypeId ("ns3::CcnxContentObjectHeader") |
| 39 | .SetParent<Header> () |
| 40 | .AddConstructor<CcnxContentObjectHeader> () |
| 41 | ; |
| 42 | return tid; |
| 43 | } |
| 44 | |
| 45 | CcnxContentObjectHeader::CcnxContentObjectHeader () |
| 46 | { |
| 47 | } |
| 48 | |
| 49 | void |
| 50 | CcnxContentObjectHeader::SetName (const Ptr<Name::Components> &name) |
| 51 | { |
| 52 | m_name = name; |
| 53 | } |
| 54 | |
| 55 | const Name::Components& |
| 56 | CcnxContentObjectHeader::GetName () const |
| 57 | { |
| 58 | return *m_name; |
| 59 | } |
| 60 | |
| 61 | uint32_t |
| 62 | CcnxContentObjectHeader::GetSerializedSize (void) const |
| 63 | { |
Alexander Afanasyev | 2a5df20 | 2011-08-15 22:39:05 -0700 | [diff] [blame^] | 64 | // Unfortunately, two serializations are required, unless we can pre-calculate header length... which is not trivial |
| 65 | Buffer tmp; |
| 66 | |
| 67 | return CcnxCodingHelper::Serialize (tmp.Begin(), *this); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | void |
| 71 | CcnxContentObjectHeader::Serialize (Buffer::Iterator start) const |
| 72 | { |
Alexander Afanasyev | 2a5df20 | 2011-08-15 22:39:05 -0700 | [diff] [blame^] | 73 | CcnxCodingHelper::Serialize (start, *this); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | uint32_t |
| 77 | CcnxContentObjectHeader::Deserialize (Buffer::Iterator start) |
| 78 | { |
Alexander Afanasyev | 2a5df20 | 2011-08-15 22:39:05 -0700 | [diff] [blame^] | 79 | return 0; // the most complicated part is here |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | TypeId |
| 83 | CcnxContentObjectHeader::GetInstanceTypeId (void) const |
| 84 | { |
| 85 | return GetTypeId (); |
| 86 | } |
| 87 | |
| 88 | void |
| 89 | CcnxContentObjectHeader::Print (std::ostream &os) const |
| 90 | { |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 91 | os << "<ContentObject><Name>" << *m_name << "</Name><Content>"; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 94 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 95 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 96 | |
| 97 | CcnxContentObjectTail::CcnxContentObjectTail () |
| 98 | { |
| 99 | } |
| 100 | |
| 101 | TypeId |
| 102 | CcnxContentObjectTail::GetTypeId (void) |
| 103 | { |
| 104 | static TypeId tid = TypeId ("ns3::CcnxContentObjectHeader") |
| 105 | .SetParent<Header> () |
| 106 | .AddConstructor<CcnxContentObjectHeader> () |
| 107 | ; |
| 108 | return tid; |
| 109 | } |
| 110 | |
| 111 | TypeId |
| 112 | CcnxContentObjectTail::GetInstanceTypeId (void) const |
| 113 | { |
| 114 | return GetTypeId (); |
| 115 | } |
| 116 | |
| 117 | void |
| 118 | CcnxContentObjectTail::Print (std::ostream &os) const |
| 119 | { |
| 120 | os << "</Content></ContentObject>"; |
| 121 | } |
| 122 | |
| 123 | uint32_t |
| 124 | CcnxContentObjectTail::GetSerializedSize (void) const |
| 125 | { |
| 126 | return 2; |
| 127 | } |
| 128 | |
| 129 | void |
| 130 | CcnxContentObjectTail::Serialize (Buffer::Iterator start) const |
| 131 | { |
| 132 | Buffer::Iterator i = start; |
| 133 | i.WriteU8 (0x00); // </Content> |
| 134 | i.WriteU8 (0x00); // </ContentObject> |
| 135 | } |
| 136 | |
| 137 | uint32_t |
| 138 | CcnxContentObjectTail::Deserialize (Buffer::Iterator start) |
| 139 | { |
| 140 | Buffer::Iterator i = start; |
| 141 | uint8_t __attribute__ ((unused)) closing_tag_content = i.ReadU8 (); |
| 142 | NS_ASSERT_MSG (closing_tag_content==0, "Should be closing tag </Content> (0x00)"); |
| 143 | |
| 144 | uint8_t __attribute__ ((unused)) closing_tag_content_object = i.ReadU8 (); |
| 145 | NS_ASSERT_MSG (closing_tag_content_object==0, "Should be closing tag </ContentObject> (0x00)"); |
| 146 | |
| 147 | return 2; |
| 148 | } |
| 149 | |
| 150 | } // namespace ns3 |