model: Returning back support for CCNb wire format
Refs #1008 (http://redmine.named-data.net/)
diff --git a/model/wire/ccnb/ccnb-parser/syntax-tree/attr.cc b/model/wire/ccnb/ccnb-parser/syntax-tree/attr.cc
new file mode 100644
index 0000000..f661186
--- /dev/null
+++ b/model/wire/ccnb/ccnb-parser/syntax-tree/attr.cc
@@ -0,0 +1,48 @@
+/* -*- 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 "attr.h"
+#include "../common.h"
+
+NDN_NAMESPACE_BEGIN
+
+namespace wire {
+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
+ uint32_t i = 0;
+ for (; !start.IsEnd () && i < (length+1); i++)
+ {
+ m_attr.push_back (start.ReadU8 ());
+ }
+ if (i < (length+1) && start.IsEnd ())
+ throw CcnbDecodingException ();
+ m_value = DynamicCast<Udata> (Block::ParseBlock (start));
+ if (m_value == 0)
+ throw CcnbDecodingException (); // "ATTR must be followed by UDATA field"
+}
+
+} // namespace CcnbParser
+} // namespace wire
+
+NDN_NAMESPACE_END
diff --git a/model/wire/ccnb/ccnb-parser/syntax-tree/attr.h b/model/wire/ccnb/ccnb-parser/syntax-tree/attr.h
new file mode 100644
index 0000000..37882ad
--- /dev/null
+++ b/model/wire/ccnb/ccnb-parser/syntax-tree/attr.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_ATTR_H_
+#define _CCNB_PARSER_ATTR_H_
+
+#include "base-attr.h"
+#include <string>
+
+NDN_NAMESPACE_BEGIN
+
+namespace wire {
+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( VoidNoArguVisitor &v ) { v.visit( *this ); }
+ virtual void accept( VoidVisitor &v, boost::any param ) { v.visit( *this, param ); }
+ virtual boost::any accept( NoArguVisitor &v ) { return v.visit( *this ); }
+ virtual boost::any accept( Visitor &v, boost::any param ) { return v.visit( *this, param ); }
+
+ std::string m_attr; ///< field holding name of the attribute
+};
+
+} // namespace CcnbParser
+} // namespace wire
+
+NDN_NAMESPACE_END
+
+#endif // _CCNB_PARSER_ATTR_H_
diff --git a/model/wire/ccnb/ccnb-parser/syntax-tree/base-attr.h b/model/wire/ccnb/ccnb-parser/syntax-tree/base-attr.h
new file mode 100644
index 0000000..c2b2627
--- /dev/null
+++ b/model/wire/ccnb/ccnb-parser/syntax-tree/base-attr.h
@@ -0,0 +1,49 @@
+/* -*- 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 "udata.h"
+
+NDN_NAMESPACE_BEGIN
+
+namespace wire {
+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
+};
+
+} // namespace CcnbParser
+} // namespace wire
+
+NDN_NAMESPACE_END
+
+#endif // _CCNB_PARSER_BASE_ATTR_H_
diff --git a/model/wire/ccnb/ccnb-parser/syntax-tree/base-tag.h b/model/wire/ccnb/ccnb-parser/syntax-tree/base-tag.h
new file mode 100644
index 0000000..1449d9f
--- /dev/null
+++ b/model/wire/ccnb/ccnb-parser/syntax-tree/base-tag.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_BASE_TAG_H_
+#define _CCNB_PARSER_BASE_TAG_H_
+
+#include "block.h"
+#include <list>
+
+NDN_NAMESPACE_BEGIN
+
+namespace wire {
+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() { }
+};
+
+} // namespace CcnbParser
+} // namespace wire
+
+NDN_NAMESPACE_END
+
+#endif // _CCNB_PARSER_BASE_TAG_H_
+
diff --git a/model/wire/ccnb/ccnb-parser/syntax-tree/blob.cc b/model/wire/ccnb/ccnb-parser/syntax-tree/blob.cc
new file mode 100644
index 0000000..6c2ab2e
--- /dev/null
+++ b/model/wire/ccnb/ccnb-parser/syntax-tree/blob.cc
@@ -0,0 +1,53 @@
+/* -*- 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 "blob.h"
+
+NDN_NAMESPACE_BEGIN
+
+namespace wire {
+namespace CcnbParser {
+
+Blob::Blob (Buffer::Iterator &start, uint32_t length)
+{
+ m_blobSize = length;
+ m_blob = new char[length];
+ if (m_blob == 0 )
+ throw CcnbDecodingException (); // memory problem
+
+ uint32_t i = 0;
+ for (; !start.IsEnd () && i < length; i++)
+ {
+ m_blob[i] = start.ReadU8 ();
+ }
+ if (i < length && start.IsEnd ())
+ throw CcnbDecodingException ();
+ // Block::counter += length;
+}
+
+Blob::~Blob ()
+{
+ delete [] m_blob;
+}
+
+} // namespace CcnbParser
+} // namespace wire
+
+NDN_NAMESPACE_END
diff --git a/model/wire/ccnb/ccnb-parser/syntax-tree/blob.h b/model/wire/ccnb/ccnb-parser/syntax-tree/blob.h
new file mode 100644
index 0000000..2b480ca
--- /dev/null
+++ b/model/wire/ccnb/ccnb-parser/syntax-tree/blob.h
@@ -0,0 +1,65 @@
+/* -*- 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_BLOB_H_
+#define _CCNB_PARSER_BLOB_H_
+
+#include "block.h"
+
+NDN_NAMESPACE_BEGIN
+
+namespace wire {
+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);
+ ~Blob ();
+
+ virtual void accept( VoidNoArguVisitor &v ) { v.visit( *this ); }
+ virtual void accept( VoidVisitor &v, boost::any param ) { v.visit( *this, param ); }
+ virtual boost::any accept( NoArguVisitor &v ) { return v.visit( *this ); }
+ virtual boost::any accept( Visitor &v, boost::any param ) { return v.visit( *this, param ); }
+
+ char* m_blob; ///< \brief field holding a parsed BLOB value of the block
+ uint32_t m_blobSize; ///< @brief field representing size of the BLOB field stored
+};
+
+} // namespace CcnbParser
+} // namespace wire
+
+NDN_NAMESPACE_END
+
+#endif // _CCNB_PARSER_BLOB_H_
diff --git a/model/wire/ccnb/ccnb-parser/syntax-tree/block.cc b/model/wire/ccnb/ccnb-parser/syntax-tree/block.cc
new file mode 100644
index 0000000..06c8e2c
--- /dev/null
+++ b/model/wire/ccnb/ccnb-parser/syntax-tree/block.cc
@@ -0,0 +1,101 @@
+/* -*- 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 "block.h"
+
+#include "blob.h"
+#include "udata.h"
+#include "tag.h"
+#include "dtag.h"
+#include "attr.h"
+#include "dattr.h"
+#include "ext.h"
+
+#include "ns3/log.h"
+
+NS_LOG_COMPONENT_DEFINE ("ndn.CcnbParser.Block");
+
+NDN_NAMESPACE_BEGIN
+
+namespace wire {
+namespace CcnbParser {
+
+/// @cond include_hidden
+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));
+/// @endcond
+
+// int Block::counter = 0;
+
+Ptr<Block> Block::ParseBlock (Buffer::Iterator &start)
+{
+ // std::cout << "<< pos: " << counter << "\n";
+ 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 (!start.IsEnd() && !(byte & CCN_TT_HBIT))
+ {
+ value <<= 8;
+ value += byte;
+ byte = start.ReadU8 ();
+ // Block::counter ++;
+ }
+ if (start.IsEnd())
+ CcnbDecodingException ();
+
+ value <<= 4;
+ value += ( (byte&(~CCN_TT_HBIT)) >> 3);
+
+ /**
+ * Huh. After fighting with NS-3, it became apparent that Create<T>(...) construct
+ * doesn't work with references. Just simply doesn't work. wtf?
+ */
+ switch (byte & CCN_TT_MASK)
+ {
+ case CCN_BLOB:
+ return Ptr<Blob> (new Blob(start, value), false);
+ case CCN_UDATA:
+ return Ptr<Udata> (new Udata(start, value), false);
+ case CCN_TAG:
+ return Ptr<Tag> (new Tag(start, value), false);
+ case CCN_ATTR:
+ return Ptr<Attr> (new Attr(start, value), false);
+ case CCN_DTAG:
+ return Ptr<Dtag> (new Dtag(start, value), false);
+ case CCN_DATTR:
+ return Ptr<Dattr> (new Dattr(start, value), false);
+ case CCN_EXT:
+ return Ptr<Ext> (new Ext(start, value), false);
+ default:
+ throw CcnbDecodingException ();
+ }
+}
+
+Block::~Block ()
+{
+}
+
+} // namespace CcnbParser
+} // namespace wire
+
+NDN_NAMESPACE_END
diff --git a/model/wire/ccnb/ccnb-parser/syntax-tree/block.h b/model/wire/ccnb/ccnb-parser/syntax-tree/block.h
new file mode 100644
index 0000000..caf227f
--- /dev/null
+++ b/model/wire/ccnb/ccnb-parser/syntax-tree/block.h
@@ -0,0 +1,89 @@
+/* -*- 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 "../visitors/void-no-argu-visitor.h"
+#include "../visitors/void-visitor.h"
+#include "../visitors/no-argu-visitor.h"
+#include "../visitors/visitor.h"
+
+NDN_NAMESPACE_BEGIN
+
+namespace wire {
+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:
+ // static int counter;
+ /**
+ * \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 ~Block ();
+
+ virtual void accept( VoidNoArguVisitor &v ) = 0; ///< @brief Accept visitor void(*)()
+ virtual void accept( VoidVisitor &v, boost::any param ) = 0; ///< @brief Accept visitor void(*)(boost::any)
+ virtual boost::any accept( NoArguVisitor &v ) = 0; ///< @brief Accept visitor boost::any(*)()
+ virtual boost::any accept( Visitor &v, boost::any param ) = 0; ///< @brief Accept visitor boost::any(*)(boost::any)
+};
+
+/**
+ * @brief Necessary until Buffer::Iterator gets PeekU8 call
+ * @param i buffer iterator
+ * @return peeked uint8_t value
+ */
+inline
+uint8_t
+BufferIteratorPeekU8 (Buffer::Iterator &i)
+{
+ uint8_t ret = i.ReadU8 ();
+ i.Prev ();
+ return ret;
+}
+
+} // namespace CcnbParser
+} // namespace wire
+
+NDN_NAMESPACE_END
+
+#endif // _CCNB_PARSER_BLOCK_H_
diff --git a/model/wire/ccnb/ccnb-parser/syntax-tree/dattr.cc b/model/wire/ccnb/ccnb-parser/syntax-tree/dattr.cc
new file mode 100644
index 0000000..a37db84
--- /dev/null
+++ b/model/wire/ccnb/ccnb-parser/syntax-tree/dattr.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 "dattr.h"
+
+NDN_NAMESPACE_BEGIN
+
+namespace wire {
+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 CcnbDecodingException (); // "ATTR must be followed by UDATA field"
+}
+
+} // namespace CcnbParser
+} // namespace wire
+
+NDN_NAMESPACE_END
diff --git a/model/wire/ccnb/ccnb-parser/syntax-tree/dattr.h b/model/wire/ccnb/ccnb-parser/syntax-tree/dattr.h
new file mode 100644
index 0000000..3728d6e
--- /dev/null
+++ b/model/wire/ccnb/ccnb-parser/syntax-tree/dattr.h
@@ -0,0 +1,63 @@
+/* -*- 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 "base-attr.h"
+
+NDN_NAMESPACE_BEGIN
+
+namespace wire {
+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( VoidNoArguVisitor &v ) { v.visit( *this ); }
+ virtual void accept( VoidVisitor &v, boost::any param ) { v.visit( *this, param ); }
+ virtual boost::any accept( NoArguVisitor &v ) { return v.visit( *this ); }
+ virtual boost::any accept( Visitor &v, boost::any param ) { return v.visit( *this, param ); }
+
+ uint32_t m_dattr; ///< \brief Dictionary code of DATTR
+};
+
+} // namespace CcnbParser
+} // namespace wire
+
+NDN_NAMESPACE_END
+
+#endif // _CCNB_PARSER_DATTR_H_
diff --git a/model/wire/ccnb/ccnb-parser/syntax-tree/dtag.cc b/model/wire/ccnb/ccnb-parser/syntax-tree/dtag.cc
new file mode 100644
index 0000000..b7af79b
--- /dev/null
+++ b/model/wire/ccnb/ccnb-parser/syntax-tree/dtag.cc
@@ -0,0 +1,91 @@
+/* -*- 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 "dtag.h"
+
+#include "base-attr.h"
+#include "base-tag.h"
+
+NDN_NAMESPACE_BEGIN
+
+namespace wire {
+namespace CcnbParser {
+
+Dtag::Dtag (Buffer::Iterator &start, uint32_t dtag)
+{
+ m_dtag = dtag;
+ // std::cout << m_dtag << ", position: " << Block::counter << "\n";
+ /**
+ * Hack
+ *
+ * Stop processing after encountering "Content" dtag. Actual
+ * content (including virtual payload) will be stored in Packet
+ * buffer
+ */
+ if (dtag == CCN_DTAG_Content)
+ return; // hack #1. Do not process nesting block for <Content>
+
+ // parse attributes until first nested block reached
+ while (!start.IsEnd () && BufferIteratorPeekU8 (start)!=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 () && BufferIteratorPeekU8 (start)!=CCN_CLOSE)
+ {
+ // hack #2. Stop processing nested blocks if last block was <Content>
+ if (m_dtag == CCN_DTAG_ContentObject && // we are in <ContentObject>
+ DynamicCast<Dtag> (m_nestedTags.back())!=0 && // last block is DTAG
+ DynamicCast<Dtag> (m_nestedTags.back())->m_dtag == CCN_DTAG_Content)
+ {
+ return;
+ }
+
+ m_nestedTags.push_back (Block::ParseBlock (start));
+ }
+
+ // hack #3. Stop processing when last tag was <ContentObject>
+ if (m_dtag == CCN_DTAG_ContentObject && // we are in <ContentObject>
+ DynamicCast<Dtag> (m_nestedTags.back())!=0 && // last block is DTAG
+ DynamicCast<Dtag> (m_nestedTags.back())->m_dtag == CCN_DTAG_Content)
+ {
+ return;
+ }
+
+ if (start.IsEnd ())
+ throw CcnbDecodingException ();
+
+ start.ReadU8 (); // read CCN_CLOSE
+ // std::cout << "closer, position = " << Block::counter << "\n";
+ // Block::counter ++;
+}
+
+} // namespace CcnbParser
+} // namespace wire
+
+NDN_NAMESPACE_END
diff --git a/model/wire/ccnb/ccnb-parser/syntax-tree/dtag.h b/model/wire/ccnb/ccnb-parser/syntax-tree/dtag.h
new file mode 100644
index 0000000..0d00f50
--- /dev/null
+++ b/model/wire/ccnb/ccnb-parser/syntax-tree/dtag.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_DTAG_H_
+#define _CCNB_PARSER_DTAG_H_
+
+#include "base-tag.h"
+
+NDN_NAMESPACE_BEGIN
+
+namespace wire {
+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( VoidNoArguVisitor &v ) { v.visit( *this ); }
+ virtual void accept( VoidVisitor &v, boost::any param ) { v.visit( *this, param ); }
+ virtual boost::any accept( NoArguVisitor &v ) { return v.visit( *this ); }
+ virtual boost::any accept( Visitor &v, boost::any param ) { return v.visit( *this, param ); }
+
+ uint32_t m_dtag; ///< \brief Dictionary code for DTAG
+};
+
+} // namespace CcnbParser
+} // namespace wire
+
+NDN_NAMESPACE_END
+
+#endif // _CCNB_PARSER_DTAG_H_
diff --git a/model/wire/ccnb/ccnb-parser/syntax-tree/ext.cc b/model/wire/ccnb/ccnb-parser/syntax-tree/ext.cc
new file mode 100644
index 0000000..79ac738
--- /dev/null
+++ b/model/wire/ccnb/ccnb-parser/syntax-tree/ext.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 "ext.h"
+
+NDN_NAMESPACE_BEGIN
+
+namespace wire {
+namespace CcnbParser {
+
+Ext::Ext (Buffer::Iterator &start, uint32_t extSubtype)
+{
+ m_extSubtype = extSubtype;
+}
+
+} // namespace CcnbParser
+} // namespace wire
+
+NDN_NAMESPACE_END
diff --git a/model/wire/ccnb/ccnb-parser/syntax-tree/ext.h b/model/wire/ccnb/ccnb-parser/syntax-tree/ext.h
new file mode 100644
index 0000000..532eb87
--- /dev/null
+++ b/model/wire/ccnb/ccnb-parser/syntax-tree/ext.h
@@ -0,0 +1,63 @@
+/* -*- 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 "block.h"
+
+NDN_NAMESPACE_BEGIN
+
+namespace wire {
+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( VoidNoArguVisitor &v ) { v.visit( *this ); }
+ virtual void accept( VoidVisitor &v, boost::any param ) { v.visit( *this, param ); }
+ virtual boost::any accept( NoArguVisitor &v ) { return v.visit( *this ); }
+ virtual boost::any accept( Visitor &v, boost::any param ) { return v.visit( *this, param ); }
+
+ uint64_t m_extSubtype; ///< \brief Extension type
+};
+
+} // namespace CcnbParser
+} // namespace wire
+
+NDN_NAMESPACE_END
+
+#endif // _CCNB_PARSER_EXT_H_
diff --git a/model/wire/ccnb/ccnb-parser/syntax-tree/tag.cc b/model/wire/ccnb/ccnb-parser/syntax-tree/tag.cc
new file mode 100644
index 0000000..8cd7fd1
--- /dev/null
+++ b/model/wire/ccnb/ccnb-parser/syntax-tree/tag.cc
@@ -0,0 +1,70 @@
+/* -*- 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 "tag.h"
+
+#include "base-attr.h"
+
+NDN_NAMESPACE_BEGIN
+
+namespace wire {
+namespace CcnbParser {
+
+Tag::Tag (Buffer::Iterator &start, uint32_t length)
+{
+ m_tag.reserve (length+2); // extra byte for potential \0 at the end
+ uint32_t i = 0;
+ for (; !start.IsEnd () && i < (length+1); i++)
+ {
+ m_tag.push_back (start.ReadU8 ());
+ }
+ if (i < (length+1) && start.IsEnd ())
+ throw CcnbDecodingException ();
+
+ // parse attributes until first nested block reached
+ while (!start.IsEnd () && BufferIteratorPeekU8 (start)!=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 () && BufferIteratorPeekU8 (start)!=CCN_CLOSE)
+ {
+ Ptr<Block> block = Block::ParseBlock (start);
+ m_nestedTags.push_back (block);
+ }
+
+ if (start.IsEnd ()) //should not be the end
+ throw CcnbDecodingException ();
+
+ start.ReadU8 (); // read CCN_CLOSE
+}
+
+} // namespace CcnbParser
+} // namespace wire
+
+NDN_NAMESPACE_END
diff --git a/model/wire/ccnb/ccnb-parser/syntax-tree/tag.h b/model/wire/ccnb/ccnb-parser/syntax-tree/tag.h
new file mode 100644
index 0000000..8949119
--- /dev/null
+++ b/model/wire/ccnb/ccnb-parser/syntax-tree/tag.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_TAG_H_
+#define _CCNB_PARSER_TAG_H_
+
+#include "base-tag.h"
+#include <string>
+
+NDN_NAMESPACE_BEGIN
+
+namespace wire {
+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( VoidNoArguVisitor &v ) { v.visit( *this ); }
+ virtual void accept( VoidVisitor &v, boost::any param ) { v.visit( *this, param ); }
+ virtual boost::any accept( NoArguVisitor &v ) { return v.visit( *this ); }
+ virtual boost::any accept( Visitor &v, boost::any param ) { return v.visit( *this, param ); }
+
+ std::string m_tag; ///< \brief Name of TAG block
+};
+
+} // namespace CcnbParser
+} // namespace wire
+
+NDN_NAMESPACE_END
+
+#endif // _CCNB_PARSER_TAG_H_
diff --git a/model/wire/ccnb/ccnb-parser/syntax-tree/udata.cc b/model/wire/ccnb/ccnb-parser/syntax-tree/udata.cc
new file mode 100644
index 0000000..9d3c8df
--- /dev/null
+++ b/model/wire/ccnb/ccnb-parser/syntax-tree/udata.cc
@@ -0,0 +1,50 @@
+/* -*- 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 "udata.h"
+
+NDN_NAMESPACE_BEGIN
+
+namespace wire {
+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
+ uint32_t i = 0;
+ for (; !start.IsEnd () && i < length; i++)
+ {
+ m_udata.push_back (start.ReadU8 ());
+ }
+
+ if (i < length && start.IsEnd ())
+ throw CcnbDecodingException ();
+}
+
+} // namespace CcnbParser
+} // namespace wire
+
+NDN_NAMESPACE_END
diff --git a/model/wire/ccnb/ccnb-parser/syntax-tree/udata.h b/model/wire/ccnb/ccnb-parser/syntax-tree/udata.h
new file mode 100644
index 0000000..463898f
--- /dev/null
+++ b/model/wire/ccnb/ccnb-parser/syntax-tree/udata.h
@@ -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>
+ */
+
+#ifndef _CCNB_PARSER_UDATA_H_
+#define _CCNB_PARSER_UDATA_H_
+
+#include "block.h"
+#include <string>
+
+NDN_NAMESPACE_BEGIN
+
+namespace wire {
+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( VoidNoArguVisitor &v ) { v.visit( *this ); }
+ virtual void accept( VoidVisitor &v, boost::any param ) { v.visit( *this, param ); }
+ virtual boost::any accept( NoArguVisitor &v ) { return v.visit( *this ); }
+ virtual boost::any accept( Visitor &v, boost::any param ) { return v.visit( *this, param ); }
+
+ std::string m_udata; ///< \brief field holding a parsed UDATA value of the block
+};
+
+} // namespace CcnbParser
+} // namespace wire
+
+NDN_NAMESPACE_END
+
+#endif // _CCNB_PARSER_UDATA_H_