blob: a3852a27f53a07560df21b4d2be2e30c8f5f9563 [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 Afanasyev2a5df202011-08-15 22:39:05 -070025#include "ns3/ccnx-coding-helper.h"
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070026
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070027NS_LOG_COMPONENT_DEFINE ("CcnxContentObjectHeader");
28
29namespace ns3
30{
31
32NS_OBJECT_ENSURE_REGISTERED (CcnxContentObjectHeader);
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070033NS_OBJECT_ENSURE_REGISTERED (CcnxContentObjectTail);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070034
35TypeId
36CcnxContentObjectHeader::GetTypeId (void)
37{
38 static TypeId tid = TypeId ("ns3::CcnxContentObjectHeader")
39 .SetParent<Header> ()
40 .AddConstructor<CcnxContentObjectHeader> ()
41 ;
42 return tid;
43}
44
45CcnxContentObjectHeader::CcnxContentObjectHeader ()
46{
47}
48
49void
50CcnxContentObjectHeader::SetName (const Ptr<Name::Components> &name)
51{
52 m_name = name;
53}
54
55const Name::Components&
56CcnxContentObjectHeader::GetName () const
57{
58 return *m_name;
59}
60
61uint32_t
62CcnxContentObjectHeader::GetSerializedSize (void) const
63{
Alexander Afanasyev2a5df202011-08-15 22:39:05 -070064 // 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 Afanasyev08d984e2011-08-13 19:20:22 -070068}
69
70void
71CcnxContentObjectHeader::Serialize (Buffer::Iterator start) const
72{
Alexander Afanasyev2a5df202011-08-15 22:39:05 -070073 CcnxCodingHelper::Serialize (start, *this);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070074}
75
76uint32_t
77CcnxContentObjectHeader::Deserialize (Buffer::Iterator start)
78{
Alexander Afanasyev2a5df202011-08-15 22:39:05 -070079 return 0; // the most complicated part is here
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070080}
81
82TypeId
83CcnxContentObjectHeader::GetInstanceTypeId (void) const
84{
85 return GetTypeId ();
86}
87
88void
89CcnxContentObjectHeader::Print (std::ostream &os) const
90{
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070091 os << "<ContentObject><Name>" << *m_name << "</Name><Content>";
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070092}
93
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070094
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070095////////////////////////////////////////////////////////////////////////////////////////////////////
96
97CcnxContentObjectTail::CcnxContentObjectTail ()
98{
99}
100
101TypeId
102CcnxContentObjectTail::GetTypeId (void)
103{
104 static TypeId tid = TypeId ("ns3::CcnxContentObjectHeader")
105 .SetParent<Header> ()
106 .AddConstructor<CcnxContentObjectHeader> ()
107 ;
108 return tid;
109}
110
111TypeId
112CcnxContentObjectTail::GetInstanceTypeId (void) const
113{
114 return GetTypeId ();
115}
116
117void
118CcnxContentObjectTail::Print (std::ostream &os) const
119{
120 os << "</Content></ContentObject>";
121}
122
123uint32_t
124CcnxContentObjectTail::GetSerializedSize (void) const
125{
126 return 2;
127}
128
129void
130CcnxContentObjectTail::Serialize (Buffer::Iterator start) const
131{
132 Buffer::Iterator i = start;
133 i.WriteU8 (0x00); // </Content>
134 i.WriteU8 (0x00); // </ContentObject>
135}
136
137uint32_t
138CcnxContentObjectTail::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