NS-3 based Named Data Networking (NDN) simulator
ndnSIM: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
wire-ccnb.h
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2 /*
3  * Copyright (c) 2011-2013 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: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19  */
20 
21 #ifndef NDN_WIRE_CCNB_SYNTAX_H
22 #define NDN_WIRE_CCNB_SYNTAX_H
23 
24 #include "ns3/ptr.h"
25 #include "ns3/nstime.h"
26 #include "ns3/buffer.h"
27 
28 #include "ns3/ndn-common.h"
29 #include "ns3/ndn-name.h"
30 
31 NDN_NAMESPACE_BEGIN
32 
33 namespace wire {
34 
38 class Ccnb
39 {
40 public:
49  static size_t
50  AppendBlockHeader (Buffer::Iterator &start, size_t value, uint32_t block_type);
51 
57  static size_t
58  EstimateBlockHeader (size_t value);
59 
67  static size_t
68  AppendNumber (Buffer::Iterator &start, uint32_t number);
69 
75  static size_t
76  EstimateNumber (uint32_t number);
77 
84  static size_t
85  AppendCloser (Buffer::Iterator &start);
86 
96  static size_t
97  AppendTimestampBlob (Buffer::Iterator &start, const Time &time);
98 
104  static size_t
105  EstimateTimestampBlob (const Time &time);
106 
119  static size_t
120  AppendTaggedBlob (Buffer::Iterator &start, uint32_t dtag,
121  const uint8_t *data, size_t size);
122 
136  static size_t
137  AppendTaggedBlobWithPadding (Buffer::Iterator &start, uint32_t dtag,
138  uint32_t length,
139  const uint8_t *data, size_t size);
140 
147  static size_t
148  EstimateTaggedBlob (uint32_t dtag, size_t size);
149 
163  template<class T>
164  static inline size_t
165  AppendTaggedBlob (Buffer::Iterator &start, uint32_t dtag, const T &data);
166 
181  template<class T>
182  static inline size_t
183  AppendTaggedBlobWithPadding (Buffer::Iterator &start, uint32_t dtag, uint32_t length, const T &data);
184 
196  static size_t
197  AppendString (Buffer::Iterator &start, uint32_t dtag,
198  const std::string &string);
199 
206  static size_t
207  EstimateString (uint32_t dtag, const std::string &string);
208 
210  // General use wire formatters
212 
220  static size_t
221  SerializeName (Buffer::Iterator &start, const Name &name);
222 
228  static size_t
229  SerializedSizeName (const Name &name);
230 
236  static Ptr<Name>
237  DeserializeName (Buffer::Iterator &start);
238 }; // Ccnb
239 
240 
241 template<class T>
242 inline size_t
243 Ccnb::AppendTaggedBlob (Buffer::Iterator &start, uint32_t dtag, const T &data)
244 {
245  return AppendTaggedBlob (start, dtag, reinterpret_cast<const uint8_t*> (&data), sizeof (data));
246 }
247 
248 template<class T>
249 inline size_t
250 Ccnb::AppendTaggedBlobWithPadding (Buffer::Iterator &start, uint32_t dtag, uint32_t length, const T &data)
251 {
252  return AppendTaggedBlobWithPadding (start, dtag, length, reinterpret_cast<const uint8_t*> (&data), sizeof (data));
253 }
254 
255 } // wire
256 
257 NDN_NAMESPACE_END
258 
259 #endif // NDN_WIRE_CCNB_SYNTAX_H
Class for NDN Name.
Definition: name.h:29
Helper to encode CCNb blocks.
Definition: wire-ccnb.h:38