blob: e567207b2f3d57b56402f127ea251d0cb859b234 [file] [log] [blame]
Alexander Afanasyevc74a6022011-08-15 20:01:35 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -07002/*
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 Afanasyev45b92d42011-08-14 23:11:38 -070024#include "ns3/log.h"
Alexander Afanasyev834f35c2011-08-16 17:13:50 -070025#include "ns3/ccnx-encoding-helper.h"
26#include "ns3/ccnx-decoding-helper.h"
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070027
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070028NS_LOG_COMPONENT_DEFINE ("CcnxContentObjectHeader");
29
30namespace ns3
31{
32
33NS_OBJECT_ENSURE_REGISTERED (CcnxContentObjectHeader);
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070034NS_OBJECT_ENSURE_REGISTERED (CcnxContentObjectTail);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070035
36TypeId
37CcnxContentObjectHeader::GetTypeId (void)
38{
39 static TypeId tid = TypeId ("ns3::CcnxContentObjectHeader")
40 .SetParent<Header> ()
41 .AddConstructor<CcnxContentObjectHeader> ()
42 ;
43 return tid;
44}
45
46CcnxContentObjectHeader::CcnxContentObjectHeader ()
47{
48}
49
50void
51CcnxContentObjectHeader::SetName (const Ptr<Name::Components> &name)
52{
53 m_name = name;
54}
55
56const Name::Components&
57CcnxContentObjectHeader::GetName () const
58{
59 return *m_name;
60}
61
62uint32_t
63CcnxContentObjectHeader::GetSerializedSize (void) const
64{
Alexander Afanasyev2a5df202011-08-15 22:39:05 -070065 // Unfortunately, two serializations are required, unless we can pre-calculate header length... which is not trivial
66 Buffer tmp;
67
Alexander Afanasyev834f35c2011-08-16 17:13:50 -070068 return CcnxEncodingHelper::Serialize (tmp.Begin(), *this);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070069}
70
71void
72CcnxContentObjectHeader::Serialize (Buffer::Iterator start) const
73{
Alexander Afanasyev834f35c2011-08-16 17:13:50 -070074 CcnxEncodingHelper::Serialize (start, *this);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070075}
76
77uint32_t
78CcnxContentObjectHeader::Deserialize (Buffer::Iterator start)
79{
Alexander Afanasyev834f35c2011-08-16 17:13:50 -070080 return CcnxDecodingHelper::Deserialize (start, *this); // \todo Debugging is necessary
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070081}
82
83TypeId
84CcnxContentObjectHeader::GetInstanceTypeId (void) const
85{
86 return GetTypeId ();
87}
88
89void
90CcnxContentObjectHeader::Print (std::ostream &os) const
91{
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070092 os << "<ContentObject><Name>" << *m_name << "</Name><Content>";
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070093}
94
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070095
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070096////////////////////////////////////////////////////////////////////////////////////////////////////
97
98CcnxContentObjectTail::CcnxContentObjectTail ()
99{
100}
101
102TypeId
103CcnxContentObjectTail::GetTypeId (void)
104{
Alexander Afanasyev834f35c2011-08-16 17:13:50 -0700105 static TypeId tid = TypeId ("ns3::CcnxContentObjectTail")
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700106 .SetParent<Header> ()
107 .AddConstructor<CcnxContentObjectHeader> ()
108 ;
109 return tid;
110}
111
112TypeId
113CcnxContentObjectTail::GetInstanceTypeId (void) const
114{
115 return GetTypeId ();
116}
117
118void
119CcnxContentObjectTail::Print (std::ostream &os) const
120{
121 os << "</Content></ContentObject>";
122}
123
124uint32_t
125CcnxContentObjectTail::GetSerializedSize (void) const
126{
127 return 2;
128}
129
130void
131CcnxContentObjectTail::Serialize (Buffer::Iterator start) const
132{
133 Buffer::Iterator i = start;
134 i.WriteU8 (0x00); // </Content>
135 i.WriteU8 (0x00); // </ContentObject>
136}
137
138uint32_t
139CcnxContentObjectTail::Deserialize (Buffer::Iterator start)
140{
141 Buffer::Iterator i = start;
142 uint8_t __attribute__ ((unused)) closing_tag_content = i.ReadU8 ();
Alexander Afanasyev834f35c2011-08-16 17:13:50 -0700143 NS_ASSERT_MSG (closing_tag_content==0, "Should be a closing tag </Content> (0x00)");
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700144
145 uint8_t __attribute__ ((unused)) closing_tag_content_object = i.ReadU8 ();
Alexander Afanasyev834f35c2011-08-16 17:13:50 -0700146 NS_ASSERT_MSG (closing_tag_content_object==0, "Should be a closing tag </ContentObject> (0x00)");
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700147
148 return 2;
149}
150
151} // namespace ns3