Checkpoint. Reorganizing ccnb parsing into many small files.
diff --git a/helper/ccnb-parser/syntax-tree/ccnb-parser-attr.cc b/helper/ccnb-parser/syntax-tree/ccnb-parser-attr.cc
new file mode 100644
index 0000000..3fe986e
--- /dev/null
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-attr.cc
@@ -0,0 +1,40 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "ccnb-parser-attr.h"
+
+namespace ns3 {
+namespace CcnbParser {
+
+// length length in octets of UTF-8 encoding of tag name - 1 (minimum tag name length is 1) 
+Attr::Attr (Buffer::Iterator &start, uint32_t length)
+{
+  m_attr.reserve (length+2); // extra byte for potential \0 at the end
+  for (uint32_t i = 0; i < (length+1); i++)
+    {
+      m_attr.push_back (start.ReadU8 ());
+    }
+  m_value = DynamicCast<Udata> (Block::ParseBlock (start));
+  if (m_value == 0)
+    throw CcnxDecodingException (); // "ATTR must be followed by UDATA field"
+}
+
+}
+}
diff --git a/helper/ccnb-parser/syntax-tree/ccnb-parser-attr.h b/helper/ccnb-parser/syntax-tree/ccnb-parser-attr.h
new file mode 100644
index 0000000..7864459
--- /dev/null
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-attr.h
@@ -0,0 +1,60 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef _CCNB_PARSER_ATTR_H_
+#define _CCNB_PARSER_ATTR_H_
+
+#include "ccnb-parser-base-attr.h"
+#include <string>
+
+namespace ns3 {
+namespace CcnbParser {
+
+/**
+ * \ingroup ccnx-ccnb
+ * \brief Class to represent ATTR ccnb-encoded node
+ *
+ * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
+ */
+class Attr : public BaseAttr
+{
+public:
+  /**
+   * \brief Constructor that actually parsed ccnb-encoded ATTR block
+   *
+   * \param start  buffer iterator pointing to the first byte of ATTR block name
+   * \param length length of ATTR name (extracted from the value field)
+   *
+   * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
+   */
+  Attr (Buffer::Iterator &start, uint32_t length);
+  
+  virtual void accept( Visitor &v )                           { v.visit( *this ); }
+  virtual void accept( GJVoidVisitor &v, boost::any param )   { v.visit( *this, param ); }
+  virtual boost::any accept( GJNoArguVisitor &v )             { return v.visit( *this ); }
+  virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); }
+
+  std::string m_attr; ///< field holding name of the attribute
+};
+
+}
+}
+
+#endif // _CCNB_PARSER_ATTR_H_
diff --git a/helper/ccnb-parser/syntax-tree/ccnb-parser-base-attr.h b/helper/ccnb-parser/syntax-tree/ccnb-parser-base-attr.h
new file mode 100644
index 0000000..f83f77e
--- /dev/null
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-base-attr.h
@@ -0,0 +1,46 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef _CCNB_PARSER_BASE_ATTR_H_
+#define _CCNB_PARSER_BASE_ATTR_H_
+
+#include "ccnb-parser-block.h"
+#include "ccnb-parser-udata.h"
+
+namespace ns3 {
+namespace CcnbParser {
+
+/**
+ * \ingroup ccnx-ccnb
+ * \brief Virtual base class providing a common storage for ATTR
+ * and DATTR ccnb-encoded blocks
+ *
+ * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
+ */
+class BaseAttr : public Block
+{
+public:
+  Ptr<Udata> m_value; ///< \brief Value of the attribute
+};
+
+}
+}
+
+#endif // _CCNB_PARSER_BASE_ATTR_H_
diff --git a/helper/ccnb-parser/syntax-tree/ccnb-parser-base-tag.h b/helper/ccnb-parser/syntax-tree/ccnb-parser-base-tag.h
new file mode 100644
index 0000000..bfd1f5b
--- /dev/null
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-base-tag.h
@@ -0,0 +1,51 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef _CCNB_PARSER_BASE_TAG_H_
+#define _CCNB_PARSER_BASE_TAG_H_
+
+#include "ccnb-parser-block.h"
+#include <list>
+
+namespace ns3 {
+namespace CcnbParser {
+
+/**
+ * \ingroup ccnx-ccnb
+ * \brief Virtual base class providing a common storage for TAG
+ * and DTAG ccnb-encoded blocks
+ *
+ * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
+ */
+class BaseTag : public Block
+{
+public:
+  std::list<Ptr<Block> > m_attrs;      ///< \brief List of attributes, associated with this tag
+  std::list<Ptr<Block> > m_nestedTags; ///< \brief List of nested tags
+
+protected:
+  /**
+   * \brief Default constructor
+   */
+  BaseTag() { }
+};
+
+#endif // _CCNB_PARSER_BASE_TAG_H_
+
diff --git a/helper/ccnb-parser/syntax-tree/ccnb-parser-blob.cc b/helper/ccnb-parser/syntax-tree/ccnb-parser-blob.cc
new file mode 100644
index 0000000..0928eb8
--- /dev/null
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-blob.cc
@@ -0,0 +1,32 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "ccnb-parser-blob.h"
+
+namespace ns3 {
+namespace CcnbParser {
+
+Blob::Blob (Buffer::Iterator &start, uint32_t length)
+{
+  start.Read (m_blob.Begin (), length);
+}
+
+}
+}
diff --git a/helper/ccnb-parser/syntax-tree/ccnb-parser-blob.h b/helper/ccnb-parser/syntax-tree/ccnb-parser-blob.h
new file mode 100644
index 0000000..1693fbe
--- /dev/null
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-blob.h
@@ -0,0 +1,59 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef _CCNB_PARSER_BLOCK_H_
+#define _CCNB_PARSER_BLOCK_H_
+
+#include "ccnb-parser-block.h"
+
+namespace ns3 {
+namespace CcnbParser {
+
+/**
+ * \ingroup ccnx-ccnb
+ * \brief Class to represent BLOB ccnb-encoded node
+ *
+ * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
+ */
+class Blob : public Block
+{
+public:
+  /**
+   * \brief Constructor that actually parsed ccnb-encoded BLOB block
+   *
+   * \param start  buffer iterator pointing to the first byte of BLOB data in ccnb-encoded block 
+   * \param length length of data in BLOB block (extracted from the value field)
+   *
+   * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
+   */
+  Blob (Buffer::Iterator &start, uint32_t length);
+  
+  virtual void accept( Visitor &v )                           { v.visit( *this ); }
+  virtual void accept( GJVoidVisitor &v, boost::any param )   { v.visit( *this, param ); }
+  virtual boost::any accept( GJNoArguVisitor &v )             { return v.visit( *this ); }
+  virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); }
+
+  Buffer m_blob; ///< \brief field holding a parsed BLOB value of the block
+};
+
+}
+}
+
+#endif // _CCNB_PARSER_BLOCK_H_
diff --git a/helper/ccnb-parser/syntax-tree/ccnb-parser-block.cc b/helper/ccnb-parser/syntax-tree/ccnb-parser-block.cc
new file mode 100644
index 0000000..81d137f
--- /dev/null
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-block.cc
@@ -0,0 +1,69 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "ccnb-parser-block.h"
+#include "ns3/ccnb-parser-common.h"
+
+namespace ns3 {
+namespace CcnbParser {
+
+const uint8_t CCN_TT_BITS = 3;
+const uint8_t CCN_TT_MASK = ((1 << CCN_TT_BITS) - 1);
+const uint8_t CCN_MAX_TINY= ((1 << (7-CCN_TT_BITS)) - 1);
+const uint8_t CCN_TT_HBIT = ((uint8_t)(1 << 7));
+
+Ptr<Block> Block::ParseBlock (Buffer::Iterator &start)
+{
+  uint32_t value = 0;
+
+  // We will have problems if length field is more than 32 bits. Though it's really impossible
+  uint8_t byte = 0;
+  while (!(byte & CCN_TT_HBIT))
+    {
+      value <<= 8;
+      value += byte;
+      byte = start.ReadU8 ();
+    }
+  value <<= 4;
+  value += ( (byte&(~CCN_TT_HBIT)) >> 3);
+
+  switch (byte & CCN_TT_MASK)
+    {
+    case CCN_BLOB:
+      return Create<Blob> (start, value);
+    case CCN_UDATA:
+      return Create<Udata> (start, value);
+    case CCN_TAG:
+      return Create<Tag> (start, value);
+    case CCN_ATTR:
+      return Create<Attr> (start, value);
+    case CCN_DTAG:
+      return Create<Dtag> (start, value);
+    case CCN_DATTR:
+      return Create<Dattr> (start, value);
+    case CCN_EXT:
+      return Create<Ext> (start, value);
+    default:
+      throw CcnxDecodingException ();
+    }
+}
+
+}
+}
diff --git a/helper/ccnb-parser/syntax-tree/ccnb-parser-block.h b/helper/ccnb-parser/syntax-tree/ccnb-parser-block.h
new file mode 100644
index 0000000..6cbb6b3
--- /dev/null
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-block.h
@@ -0,0 +1,68 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef _CCNB_PARSER_BLOCK_H_
+#define _CCNB_PARSER_BLOCK_H_
+
+#include "ns3/simple-ref-count.h"
+#include "ns3/buffer.h"
+#include "ns3/ptr.h"
+
+// visitors
+#include "ns3/ccnb-parser-void-no-argu-visitor.h"
+#include "ns3/ccnb-parser-void-visitor.h"
+#include "ns3/ccnb-parser-no-argu-visitor.h"
+#include "ns3/ccnb-parser-visitor.h"
+
+namespace ns3 {
+namespace CcnbParser {
+
+/**
+ * \ingroup ccnx-ccnb
+ * \brief Base class for ccnb-encoded node
+ *
+ * This class provides a static method to create a new block
+ * (recursively) from the stream
+ *
+ * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
+ */
+class Block : public SimpleRefCount<Block>
+{
+public:
+  /**
+   * \brief Parsing stream (recursively) and creating a parsed BLOCK
+   * object
+   *
+   * \param start buffer iterator pointing to the start position for parsing 
+   * \returns parsed ccnb-encoded block, that could contain more block inside
+   */
+  static Ptr<Block>
+  ParseBlock (Buffer::Iterator &start);
+  
+  virtual void accept (VoidNoArguVisitor &v )               =0; ///< \brief Method to dispatch VoidNoArguVisitor
+  virtual void accept (VoidVisitor &v, boost::any param)    =0; ///< \brief Method to dispatch VoidVisitor
+  virtual boost::any accept (NoArguVisitor &v )             =0; ///< \brief Method to dispatch NoArguVisitor 
+  virtual boost::any accept (Visitor &v, boost::any param ) =0; ///< \brief Method to dispatch Visitor
+};
+
+}
+}
+
+#endif // _CCNB_PARSER_BLOCK_H_
diff --git a/helper/ccnb-parser/syntax-tree/ccnb-parser-dattr.cc b/helper/ccnb-parser/syntax-tree/ccnb-parser-dattr.cc
new file mode 100644
index 0000000..b8ef685
--- /dev/null
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-dattr.cc
@@ -0,0 +1,36 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "ccnb-parser-dattr.h"
+
+namespace ns3 {
+namespace CcnbParser {
+
+// dictionary attributes are not used (yet?) in CCNx 
+Dattr::Dattr (Buffer::Iterator &start, uint32_t dattr)
+{
+  m_dattr = dattr;
+  m_value = DynamicCast<Udata> (Block::ParseBlock (start));
+  if (m_value == 0)
+    throw CcnxDecodingException (); // "ATTR must be followed by UDATA field"
+}
+
+}
+}
diff --git a/helper/ccnb-parser/syntax-tree/ccnb-parser-dattr.h b/helper/ccnb-parser/syntax-tree/ccnb-parser-dattr.h
new file mode 100644
index 0000000..42de5f6
--- /dev/null
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-dattr.h
@@ -0,0 +1,59 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef _CCNB_PARSER_DATTR_H_
+#define _CCNB_PARSER_DATTR_H_
+
+#include "ccnb-parser-base-attr.h"
+
+namespace ns3 {
+namespace CcnbParser {
+
+/**
+ * \ingroup ccnx-ccnb
+ * \brief Class to represent DATTR ccnb-encoded node
+ *
+ * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
+ */
+class Dattr : public BaseAttr
+{
+public:
+  /**
+   * \brief Constructor that actually parsed ccnb-encoded DATTR block
+   *
+   * \param start buffer iterator pointing to the first byte of attribute value (UDATA block)
+   * \param dattr dictionary code of DATTR (extracted from the value field)
+   *
+   * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
+   */
+  Dattr (Buffer::Iterator &start, uint32_t dattr);
+
+  virtual void accept( Visitor &v )                           { v.visit( *this ); }
+  virtual void accept( GJVoidVisitor &v, boost::any param )   { v.visit( *this, param ); }
+  virtual boost::any accept( GJNoArguVisitor &v )             { return v.visit( *this ); }
+  virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); }
+
+  uint32_t m_dattr; ///< \brief Dictionary code of DATTR
+};
+
+}
+}
+
+#endif // _CCNB_PARSER_DATTR_H_
diff --git a/helper/ccnb-parser/syntax-tree/ccnb-parser-dtag.cc b/helper/ccnb-parser/syntax-tree/ccnb-parser-dtag.cc
new file mode 100644
index 0000000..0cfe4bd
--- /dev/null
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-dtag.cc
@@ -0,0 +1,74 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "ccnb-parser-dtag.h"
+#include "ns3/ccnb-parser-common.h"
+
+namespace ns3 {
+namespace CcnbParser {
+
+Dtag::Dtag (Buffer::Iterator &start, uint32_t dtag)
+{
+  m_dtag = dtag;
+
+  /**
+   * Hack
+   *
+   * Stop processing after encountering <Content> dtag.  Actual
+   * content (including virtual payload) will be stored in Packet
+   * buffer
+   */
+  if (dtag == Ccnx::CCN_DTAG_Content)
+    return; // hack #1. Do not process nesting block for <Content>
+  
+  // parse attributes until first nested block reached
+  while (!start.IsEnd () && start.PeekU8 ()!=CCN_CLOSE)
+    {
+      Ptr<Block> block = Block::ParseBlock (start);
+      if (DynamicCast<BaseAttr> (block)!=0)
+		m_attrs.push_back (block);
+	  else
+		{
+		  m_nestedTags.push_back (block);
+		  break;
+		}
+	}
+
+  // parse the rest of nested blocks
+  while (!start.IsEnd () && start.PeekU8 ()!=CCN_CLOSE)
+    {
+      // hack #2. Stop processing nested blocks if last block was <Content>
+      if (m_dtag == Ccnx::CCN_DTAG_ContentObject && // we are in <ContentObject>
+          DynamicCast<Dtag> (m_nestedBlocks.back())!=0 && // last block is DTAG
+          DynamicCast<Dtag> (m_nestedBlocks.back())->m_dtag == CCN_DTAG_Content) 
+        {
+          return; 
+        }
+
+      m_nestedBlocks.push_back (Block::ParseBlock (start));
+    }
+  if (start.IsEnd ())
+      throw CcnxDecodingException ();
+
+  start.ReadU8 (); // read CCN_CLOSE
+}
+
+}
+}
diff --git a/helper/ccnb-parser/syntax-tree/ccnb-parser-dtag.h b/helper/ccnb-parser/syntax-tree/ccnb-parser-dtag.h
new file mode 100644
index 0000000..65a84f5
--- /dev/null
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-dtag.h
@@ -0,0 +1,64 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef _CCNB_PARSER_DTAG_H_
+#define _CCNB_PARSER_DTAG_H_
+
+#include "ccnb-parser-base-tag.h"
+
+namespace ns3 {
+namespace CcnbParser {
+
+/**
+ * \ingroup ccnx-ccnb
+ * \brief Class to represent DTAG ccnb-encoded node
+ *
+ * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
+ */
+class Dtag : public BaseTag
+{
+public:
+  /**
+   * \brief Constructor that actually parsed ccnb-encoded DTAG block
+   *
+   * \param start buffer iterator pointing to the first nesting block or closing tag
+   * \param dtag  dictionary code of DTAG (extracted from the value field)
+   *
+   * DTAG parsing is slightly hacked to provide memory optimization
+   * for NS-3 simulations.  Parsing will be stopped after encountering
+   * <Content> dtag.  Actual content (including virtual payload) will
+   * be stored in Packet buffer
+   *
+   * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
+   */
+  Dtag (Buffer::Iterator &start, uint32_t dtag);
+
+  virtual void accept( Visitor &v )                           { v.visit( *this ); }
+  virtual void accept( GJVoidVisitor &v, boost::any param )   { v.visit( *this, param ); }
+  virtual boost::any accept( GJNoArguVisitor &v )             { return v.visit( *this ); }
+  virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); }
+
+  uint32_t m_dtag; ///< \brief Dictionary code for DTAG
+};
+
+}
+}
+
+#endif // _CCNB_PARSER_DTAG_H_
diff --git a/helper/ccnb-parser/syntax-tree/ccnb-parser-ext.cc b/helper/ccnb-parser/syntax-tree/ccnb-parser-ext.cc
new file mode 100644
index 0000000..7d90019
--- /dev/null
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-ext.cc
@@ -0,0 +1,32 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "ccnb-parser-ext.h"
+
+namespace ns3 {
+namespace CcnbParser {
+
+Ext::Ext (Buffer::Iterator &start, uint32_t extSubtype)
+{
+  m_extSubtype = extSubtype;
+}
+
+}
+}
diff --git a/helper/ccnb-parser/syntax-tree/ccnb-parser-ext.h b/helper/ccnb-parser/syntax-tree/ccnb-parser-ext.h
new file mode 100644
index 0000000..9a2f2c8
--- /dev/null
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-ext.h
@@ -0,0 +1,59 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef _CCNB_PARSER_EXT_H_
+#define _CCNB_PARSER_EXT_H_
+
+#include "ccnb-parser-ext.h"
+
+namespace ns3 {
+namespace CcnbParser {
+
+/**
+ * \ingroup ccnx-ccnb
+ * \brief Class to represent EXT ccnb-encoded node
+ *
+ * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
+ */
+class Ext : public Block
+{
+public:
+  /**
+   * \brief Constructor that actually parsed ccnb-encoded DTAG block
+   *
+   * \param start buffer iterator pointing to the next byte past EXT block
+   * \param extSubtype extension type (extracted from the value field)
+   *
+   * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
+   */
+  Ext (Buffer::Iterator &start, uint32_t extSubtype);
+
+  virtual void accept( Visitor &v )                           { v.visit( *this ); }
+  virtual void accept( GJVoidVisitor &v, boost::any param )   { v.visit( *this, param ); }
+  virtual boost::any accept( GJNoArguVisitor &v )             { return v.visit( *this ); }
+  virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); }
+
+  uint64_t m_extSubtype; ///< \brief Extension type
+};
+
+}
+}
+
+#endif // _CCNB_PARSER_EXT_H_
diff --git a/helper/ccnb-parser/syntax-tree/ccnb-parser-tag.cc b/helper/ccnb-parser/syntax-tree/ccnb-parser-tag.cc
new file mode 100644
index 0000000..f045d55
--- /dev/null
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-tag.cc
@@ -0,0 +1,62 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "ccnb-parser-tag.h"
+#include "ns3/ccnb-parser-common.h"
+
+namespace ns3 {
+namespace CcnbParser {
+
+Tag::Tag (Buffer::Iterator &start, uint32_t length)
+{
+  m_tag.reserve (length+2); // extra byte for potential \0 at the end
+  for (uint32_t i = 0; i < (length+1); i++)
+    {
+      m_tag.push_back (start.ReadU8 ());
+    }
+  
+  // parse attributes until first nested block reached
+  while (!start.IsEnd () && start.PeekU8 ()!=CCN_CLOSE)
+    {
+      Ptr<Block> block = Block::ParseBlock (start);
+      if (DynamicCast<BaseAttr> (block)!=0)
+		m_attrs.push_back (block);
+	  else
+		{
+		  m_nestedTags.push_back (block);
+		  break;
+		}
+	}
+
+  // parse the rest of nested blocks
+  while (!start.IsEnd () && start.PeekU8 ()!=CCN_CLOSE)
+    {
+      Ptr<Block> block = Block::ParseBlock (start);
+	  m_nestedTags.push_back (block);
+    }
+  
+  if (start.IsEnd ()) //should not be the end
+      throw CcnxDecodingException ();
+
+  start.ReadU8 (); // read CCN_CLOSE
+}
+
+}
+}
diff --git a/helper/ccnb-parser/syntax-tree/ccnb-parser-tag.h b/helper/ccnb-parser/syntax-tree/ccnb-parser-tag.h
new file mode 100644
index 0000000..aea0bcc
--- /dev/null
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-tag.h
@@ -0,0 +1,60 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef _CCNB_PARSER_TAG_H_
+#define _CCNB_PARSER_TAG_H_
+
+#include "ccnb-parser-base-tag.h"
+#include <string>
+
+namespace ns3 {
+namespace CcnbParser {
+
+/**
+ * \ingroup ccnx-ccnb
+ * \brief Class to represent TAG ccnb-encoded node
+ *
+ * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
+ */
+class Tag : public BaseTag
+{
+public:
+  /**
+   * \brief Constructor that actually parsed ccnb-encoded TAG block
+   *
+   * \param start  buffer iterator pointing to the first byte of TAG block name
+   * \param length length of TAG name - 1 byte (i.e., minimum tag name is 1 byte)
+   *
+   * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
+   */
+  Tag (Buffer::Iterator &start, uint32_t length);
+
+  virtual void accept( Visitor &v )                           { v.visit( *this ); }
+  virtual void accept( GJVoidVisitor &v, boost::any param )   { v.visit( *this, param ); }
+  virtual boost::any accept( GJNoArguVisitor &v )             { return v.visit( *this ); }
+  virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); }
+
+  std::string m_tag; ///< \brief Name of TAG block
+};
+
+}
+}
+
+#endif // _CCNB_PARSER_TAG_H_
diff --git a/helper/ccnb-parser/syntax-tree/ccnb-parser-udata.cc b/helper/ccnb-parser/syntax-tree/ccnb-parser-udata.cc
new file mode 100644
index 0000000..39217fd
--- /dev/null
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-udata.cc
@@ -0,0 +1,42 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "ccnb-parser-udata.h"
+
+namespace ns3 {
+namespace CcnbParser {
+
+Udata::Udata (Buffer::Iterator &start, uint32_t length)
+{
+  // Ideally, the code should look like this. Unfortunately, we don't have normal compatible iterators
+  // Buffer::Iterator realStart = start;
+  // start.Next (length); // advancing forward
+  // m_udata.assign (realStart, start/*actually, it is the end*/);
+
+  m_udata.reserve (length+1); //just in case we will need \0 at the end later
+  // this is actually the way Read method is implemented in network/src/buffer.cc
+  for (uint32_t i = 0; i < length; i++)
+    {
+      m_udata.push_back (start.ReadU8 ());
+    }
+}
+
+}
+}
diff --git a/helper/ccnb-parser/syntax-tree/ccnb-parser-udata.h b/helper/ccnb-parser/syntax-tree/ccnb-parser-udata.h
new file mode 100644
index 0000000..c75fc9d
--- /dev/null
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-udata.h
@@ -0,0 +1,58 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef _CCNB_PARSER_UDATA_H_
+#define _CCNB_PARSER_UDATA_H_
+
+#include "ccnb-parser-block.h"
+#include <string>
+
+namespace ns3 {
+namespace CcnbParser {
+
+/**
+ * \ingroup ccnx-ccnb
+ * \brief Class to represent UDATA ccnb-encoded node
+ */
+class Udata : public Block
+{
+public:
+  /**
+   * \brief Constructor that actually parsed ccnb-encoded UDATA block
+   *
+   * \param start  buffer iterator pointing to the first byte of string in ccnb-encoded block 
+   * \param length length of data in UDATA block (extracted from the value field)
+   *
+   * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
+   */
+  Udata (Buffer::Iterator &start, uint32_t length);
+  
+  virtual void accept( Visitor &v )                           { v.visit( *this ); }
+  virtual void accept( GJVoidVisitor &v, boost::any param )   { v.visit( *this, param ); }
+  virtual boost::any accept( GJNoArguVisitor &v )             { return v.visit( *this ); }
+  virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); }
+
+  std::string m_udata; ///< \brief field holding a parsed UDATA value of the block
+};
+
+}
+}
+
+#endif // _CCNB_PARSER_UDATA_H_