blob: d858e04a4fdaff7fc1dc5f4ba9b9b3d484031ff9 [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 Afanasyevf9f4eb02011-12-16 01:51:14 -080025#include "../helper/ccnx-encoding-helper.h"
26#include "../helper/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{
Alexander Afanasyeve91ab752011-08-31 19:13:40 -070060 if (m_name==0) throw CcnxContentObjectHeaderException();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070061 return *m_name;
62}
63
Alexander Afanasyev9568f952012-04-05 16:09:14 -070064void
65CcnxContentObjectHeader::SetTimestamp (const Time &timestamp)
66{
67 m_signedInfo.m_timestamp = timestamp;
68}
69
70Time
71CcnxContentObjectHeader::GetTimestamp () const
72{
73 return m_signedInfo.m_timestamp;
74}
75
76void
77CcnxContentObjectHeader::SetFreshness (const Time &freshness)
78{
79 m_signedInfo.m_freshness = freshness;
80}
81
82Time
83CcnxContentObjectHeader::GetFreshness () const
84{
85 return m_signedInfo.m_freshness;
86}
87
88
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070089uint32_t
90CcnxContentObjectHeader::GetSerializedSize (void) const
91{
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070092 // unfortunately, we don't know exact header size in advance
93 return CcnxEncodingHelper::GetSerializedSize (*this);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070094}
95
96void
97CcnxContentObjectHeader::Serialize (Buffer::Iterator start) const
98{
Alexander Afanasyev834f35c2011-08-16 17:13:50 -070099 CcnxEncodingHelper::Serialize (start, *this);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700100}
101
102uint32_t
103CcnxContentObjectHeader::Deserialize (Buffer::Iterator start)
104{
Alexander Afanasyev834f35c2011-08-16 17:13:50 -0700105 return CcnxDecodingHelper::Deserialize (start, *this); // \todo Debugging is necessary
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700106}
107
108TypeId
109CcnxContentObjectHeader::GetInstanceTypeId (void) const
110{
111 return GetTypeId ();
112}
113
114void
115CcnxContentObjectHeader::Print (std::ostream &os) const
116{
Alexander Afanasyev7f3e49e2012-04-30 00:17:07 -0700117 os << "D: " << GetName ();
118 // os << "<ContentObject><Name>" << GetName () << "</Name><Content>";
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700119}
120
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700121////////////////////////////////////////////////////////////////////////////////////////////////////
122
123CcnxContentObjectTail::CcnxContentObjectTail ()
124{
125}
126
127TypeId
128CcnxContentObjectTail::GetTypeId (void)
129{
Alexander Afanasyev834f35c2011-08-16 17:13:50 -0700130 static TypeId tid = TypeId ("ns3::CcnxContentObjectTail")
Alexander Afanasyeve91ab752011-08-31 19:13:40 -0700131 .SetParent<Trailer> ()
132 .AddConstructor<CcnxContentObjectTail> ()
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700133 ;
134 return tid;
135}
136
137TypeId
138CcnxContentObjectTail::GetInstanceTypeId (void) const
139{
140 return GetTypeId ();
141}
142
143void
144CcnxContentObjectTail::Print (std::ostream &os) const
145{
146 os << "</Content></ContentObject>";
147}
148
149uint32_t
150CcnxContentObjectTail::GetSerializedSize (void) const
151{
152 return 2;
153}
154
155void
156CcnxContentObjectTail::Serialize (Buffer::Iterator start) const
157{
158 Buffer::Iterator i = start;
Alexander Afanasyeve91ab752011-08-31 19:13:40 -0700159 i.Prev (2); // Trailer interface requires us to go backwards
160
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700161 i.WriteU8 (0x00); // </Content>
162 i.WriteU8 (0x00); // </ContentObject>
163}
164
165uint32_t
166CcnxContentObjectTail::Deserialize (Buffer::Iterator start)
167{
168 Buffer::Iterator i = start;
Alexander Afanasyeve91ab752011-08-31 19:13:40 -0700169 i.Prev (2); // Trailer interface requires us to go backwards
170
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700171 uint8_t __attribute__ ((unused)) closing_tag_content = i.ReadU8 ();
Alexander Afanasyev834f35c2011-08-16 17:13:50 -0700172 NS_ASSERT_MSG (closing_tag_content==0, "Should be a closing tag </Content> (0x00)");
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700173
174 uint8_t __attribute__ ((unused)) closing_tag_content_object = i.ReadU8 ();
Alexander Afanasyev834f35c2011-08-16 17:13:50 -0700175 NS_ASSERT_MSG (closing_tag_content_object==0, "Should be a closing tag </ContentObject> (0x00)");
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700176
177 return 2;
178}
179
180} // namespace ns3