blob: 581c6c40eca0d5d4a4481e37d3c693c6ec50d169 [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")
Alexander Afanasyev070aa482011-08-20 00:38:25 -070040 .SetGroupName ("Ccnx")
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070041 .SetParent<Header> ()
42 .AddConstructor<CcnxContentObjectHeader> ()
43 ;
44 return tid;
45}
46
47CcnxContentObjectHeader::CcnxContentObjectHeader ()
48{
49}
50
51void
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -070052CcnxContentObjectHeader::SetName (const Ptr<CcnxNameComponents> &name)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070053{
54 m_name = name;
55}
56
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -070057const CcnxNameComponents&
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070058CcnxContentObjectHeader::GetName () const
59{
60 return *m_name;
61}
62
63uint32_t
64CcnxContentObjectHeader::GetSerializedSize (void) const
65{
Alexander Afanasyev2a5df202011-08-15 22:39:05 -070066 // Unfortunately, two serializations are required, unless we can pre-calculate header length... which is not trivial
Alexander Afanasyevae0d6522011-08-30 13:29:55 -070067 /// \todo This is totally wrong. Need to do some simple packet buffer estimation
68 Buffer tmp(2048);
Alexander Afanasyev2a5df202011-08-15 22:39:05 -070069
Alexander Afanasyev834f35c2011-08-16 17:13:50 -070070 return CcnxEncodingHelper::Serialize (tmp.Begin(), *this);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070071}
72
73void
74CcnxContentObjectHeader::Serialize (Buffer::Iterator start) const
75{
Alexander Afanasyev834f35c2011-08-16 17:13:50 -070076 CcnxEncodingHelper::Serialize (start, *this);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070077}
78
79uint32_t
80CcnxContentObjectHeader::Deserialize (Buffer::Iterator start)
81{
Alexander Afanasyev834f35c2011-08-16 17:13:50 -070082 return CcnxDecodingHelper::Deserialize (start, *this); // \todo Debugging is necessary
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070083}
84
85TypeId
86CcnxContentObjectHeader::GetInstanceTypeId (void) const
87{
88 return GetTypeId ();
89}
90
91void
92CcnxContentObjectHeader::Print (std::ostream &os) const
93{
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070094 os << "<ContentObject><Name>" << *m_name << "</Name><Content>";
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070095}
96
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070097
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070098////////////////////////////////////////////////////////////////////////////////////////////////////
99
100CcnxContentObjectTail::CcnxContentObjectTail ()
101{
102}
103
104TypeId
105CcnxContentObjectTail::GetTypeId (void)
106{
Alexander Afanasyev834f35c2011-08-16 17:13:50 -0700107 static TypeId tid = TypeId ("ns3::CcnxContentObjectTail")
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700108 .SetParent<Header> ()
109 .AddConstructor<CcnxContentObjectHeader> ()
110 ;
111 return tid;
112}
113
114TypeId
115CcnxContentObjectTail::GetInstanceTypeId (void) const
116{
117 return GetTypeId ();
118}
119
120void
121CcnxContentObjectTail::Print (std::ostream &os) const
122{
123 os << "</Content></ContentObject>";
124}
125
126uint32_t
127CcnxContentObjectTail::GetSerializedSize (void) const
128{
129 return 2;
130}
131
132void
133CcnxContentObjectTail::Serialize (Buffer::Iterator start) const
134{
135 Buffer::Iterator i = start;
136 i.WriteU8 (0x00); // </Content>
137 i.WriteU8 (0x00); // </ContentObject>
138}
139
140uint32_t
141CcnxContentObjectTail::Deserialize (Buffer::Iterator start)
142{
143 Buffer::Iterator i = start;
144 uint8_t __attribute__ ((unused)) closing_tag_content = i.ReadU8 ();
Alexander Afanasyev834f35c2011-08-16 17:13:50 -0700145 NS_ASSERT_MSG (closing_tag_content==0, "Should be a closing tag </Content> (0x00)");
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700146
147 uint8_t __attribute__ ((unused)) closing_tag_content_object = i.ReadU8 ();
Alexander Afanasyev834f35c2011-08-16 17:13:50 -0700148 NS_ASSERT_MSG (closing_tag_content_object==0, "Should be a closing tag </ContentObject> (0x00)");
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700149
150 return 2;
151}
152
153} // namespace ns3