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
block.cc
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2 /*
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: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19  */
20 
21 #include "block.h"
22 
23 #include "blob.h"
24 #include "udata.h"
25 #include "tag.h"
26 #include "dtag.h"
27 #include "attr.h"
28 #include "dattr.h"
29 #include "ext.h"
30 
31 #include "ns3/log.h"
32 
33 NS_LOG_COMPONENT_DEFINE ("ndn.CcnbParser.Block");
34 
35 NDN_NAMESPACE_BEGIN
36 
37 namespace wire {
38 namespace CcnbParser {
39 
41 const uint8_t CCN_TT_BITS = 3;
42 const uint8_t CCN_TT_MASK = ((1 << CCN_TT_BITS) - 1);
43 const uint8_t CCN_MAX_TINY= ((1 << (7-CCN_TT_BITS)) - 1);
44 const uint8_t CCN_TT_HBIT = ((uint8_t)(1 << 7));
46 
47 // int Block::counter = 0;
48 
49 Ptr<Block> Block::ParseBlock (Buffer::Iterator &start, bool dontParseBlock)
50 {
51  // std::cout << "<< pos: " << counter << "\n";
52  uint32_t value = 0;
53 
54  // We will have problems if length field is more than 32 bits. Though it's really impossible
55  uint8_t byte = 0;
56  while (!start.IsEnd() && !(byte & CCN_TT_HBIT))
57  {
58  value <<= 7;
59  value += byte;
60  byte = start.ReadU8 ();
61  // Block::counter ++;
62  }
63  if (start.IsEnd())
65 
66  if (dontParseBlock)
67  {
68  return 0;
69  }
70 
71  value <<= 4;
72  value += ( (byte&(~CCN_TT_HBIT)) >> 3);
73 
78  switch (byte & CCN_TT_MASK)
79  {
80  case CCN_BLOB:
81  return Ptr<Blob> (new Blob(start, value), false);
82  case CCN_UDATA:
83  return Ptr<Udata> (new Udata(start, value), false);
84  case CCN_TAG:
85  return Ptr<Tag> (new Tag(start, value), false);
86  case CCN_ATTR:
87  return Ptr<Attr> (new Attr(start, value), false);
88  case CCN_DTAG:
89  return Ptr<Dtag> (new Dtag(start, value), false);
90  case CCN_DATTR:
91  return Ptr<Dattr> (new Dattr(start, value), false);
92  case CCN_EXT:
93  return Ptr<Ext> (new Ext(start, value), false);
94  default:
95  throw CcnbDecodingException ();
96  }
97 }
98 
99 Block::~Block ()
100 {
101 }
102 
103 } // namespace CcnbParser
104 } // namespace wire
105 
106 NDN_NAMESPACE_END
Class to represent DATTR ccnb-encoded node.
Definition: dattr.h:37
Exception thrown if there is a parsing error.
Definition: common.h:50
Class to represent DTAG ccnb-encoded node.
Definition: dtag.h:37
Class to represent BLOB ccnb-encoded node.
Definition: blob.h:37
Class to represent ATTR ccnb-encoded node.
Definition: attr.h:38
Class to represent TAG ccnb-encoded node.
Definition: tag.h:38
Class to represent EXT ccnb-encoded node.
Definition: ext.h:37
Class to represent UDATA ccnb-encoded node.
Definition: udata.h:36