model: Initial attempt to optimize Interest/Data encoding/decoding via a custom packet format
diff --git a/disabled/ccnb-parser/common.h b/disabled/ccnb-parser/common.h
new file mode 100644
index 0000000..260ae74
--- /dev/null
+++ b/disabled/ccnb-parser/common.h
@@ -0,0 +1,181 @@
+/* -*- 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_COMMON_H_
+#define _CCNB_PARSER_COMMON_H_
+
+namespace ns3 {
+namespace ndn {
+
+/**
+ * \ingroup ndn
+ * \defgroup ndn-ccnb CCNB decoding routines
+ */
+/**
+ * \ingroup ndn-ccnb
+ * \brief Namespace for ccnb parer
+ */
+namespace CcnbParser {
+
+// forward declarations
+class Block;
+class Blob;
+class Udata;
+class Tag;
+class Attr;
+class Dtag;
+class Dattr;
+class Ext;
+
+
+/**
+ * \brief Exception thrown if there is a parsing error
+ *
+ * \todo inherit this class from some exception class and provide meaningful error messages
+ */
+class CcnbDecodingException {};
+
+/**
+ * \brief Type tag for a ccnb start marker.
+ *
+ * \see http://www.ccnx.org/releases/latest/doc/technical/DTAG.html
+ */
+enum ccn_tt {
+ CCN_EXT, /**< starts composite extension - numval is subtype */
+ CCN_TAG, /**< starts composite - numval is tagnamelen-1 */
+ CCN_DTAG, /**< starts composite - numval is tagdict index (enum ccn_dtag) */
+ CCN_ATTR, /**< attribute - numval is attrnamelen-1, value follows */
+ CCN_DATTR, /**< attribute numval is attrdict index */
+ CCN_BLOB, /**< opaque binary data - numval is byte count */
+ CCN_UDATA, /**< UTF-8 encoded character data - numval is byte count */
+ CCN_NO_TOKEN /**< should not occur in encoding */
+};
+
+/** \brief CCN_CLOSE terminates composites */
+enum {CCN_CLOSE = 0};
+
+/**
+ * \brief DTAG identifies ccnb-encoded elements.
+ *
+ * \see http://www.ccnx.org/releases/latest/doc/technical/DTAG.html
+ */
+enum ccn_dtag {
+ CCN_DTAG_Any = 13,
+ CCN_DTAG_Name = 14,
+ CCN_DTAG_Component = 15,
+ CCN_DTAG_Certificate = 16,
+ CCN_DTAG_Collection = 17,
+ CCN_DTAG_CompleteName = 18,
+ CCN_DTAG_Content = 19,
+ CCN_DTAG_SignedInfo = 20,
+ CCN_DTAG_ContentDigest = 21,
+ CCN_DTAG_ContentHash = 22,
+ CCN_DTAG_Count = 24,
+ CCN_DTAG_Header = 25,
+ CCN_DTAG_Interest = 26, /* 20090915 */
+ CCN_DTAG_Key = 27,
+ CCN_DTAG_KeyLocator = 28,
+ CCN_DTAG_KeyName = 29,
+ CCN_DTAG_Length = 30,
+ CCN_DTAG_Link = 31,
+ CCN_DTAG_LinkAuthenticator = 32,
+ CCN_DTAG_NameComponentCount = 33, /* DeprecatedInInterest */
+ CCN_DTAG_RootDigest = 36,
+ CCN_DTAG_Signature = 37,
+ CCN_DTAG_Start = 38,
+ CCN_DTAG_Timestamp = 39,
+ CCN_DTAG_Type = 40,
+ CCN_DTAG_Nonce = 41,
+ CCN_DTAG_Scope = 42,
+ CCN_DTAG_Exclude = 43,
+ CCN_DTAG_Bloom = 44,
+ CCN_DTAG_BloomSeed = 45,
+ CCN_DTAG_AnswerOriginKind = 47,
+ CCN_DTAG_InterestLifetime = 48,
+ CCN_DTAG_Witness = 53,
+ CCN_DTAG_SignatureBits = 54,
+ CCN_DTAG_DigestAlgorithm = 55,
+ CCN_DTAG_BlockSize = 56,
+ CCN_DTAG_FreshnessSeconds = 58,
+ CCN_DTAG_FinalBlockID = 59,
+ CCN_DTAG_PublisherPublicKeyDigest = 60,
+ CCN_DTAG_PublisherCertificateDigest = 61,
+ CCN_DTAG_PublisherIssuerKeyDigest = 62,
+ CCN_DTAG_PublisherIssuerCertificateDigest = 63,
+ CCN_DTAG_ContentObject = 64, /* 20090915 */
+ CCN_DTAG_WrappedKey = 65,
+ CCN_DTAG_WrappingKeyIdentifier = 66,
+ CCN_DTAG_WrapAlgorithm = 67,
+ CCN_DTAG_KeyAlgorithm = 68,
+ CCN_DTAG_Label = 69,
+ CCN_DTAG_EncryptedKey = 70,
+ CCN_DTAG_EncryptedNonceKey = 71,
+ CCN_DTAG_WrappingKeyName = 72,
+ CCN_DTAG_Action = 73,
+ CCN_DTAG_FaceID = 74,
+ CCN_DTAG_IPProto = 75,
+ CCN_DTAG_Host = 76,
+ CCN_DTAG_Port = 77,
+ CCN_DTAG_MulticastInterface = 78,
+ CCN_DTAG_ForwardingFlags = 79,
+ CCN_DTAG_FaceInstance = 80,
+ CCN_DTAG_ForwardingEntry = 81,
+ CCN_DTAG_MulticastTTL = 82,
+ CCN_DTAG_MinSuffixComponents = 83,
+ CCN_DTAG_MaxSuffixComponents = 84,
+ CCN_DTAG_ChildSelector = 85,
+ CCN_DTAG_RepositoryInfo = 86,
+ CCN_DTAG_Version = 87,
+ CCN_DTAG_RepositoryVersion = 88,
+ CCN_DTAG_GlobalPrefix = 89,
+ CCN_DTAG_LocalName = 90,
+ CCN_DTAG_Policy = 91,
+ CCN_DTAG_Namespace = 92,
+ CCN_DTAG_GlobalPrefixName = 93,
+ CCN_DTAG_PolicyVersion = 94,
+ CCN_DTAG_KeyValueSet = 95,
+ CCN_DTAG_KeyValuePair = 96,
+ CCN_DTAG_IntegerValue = 97,
+ CCN_DTAG_DecimalValue = 98,
+ CCN_DTAG_StringValue = 99,
+ CCN_DTAG_BinaryValue = 100,
+ CCN_DTAG_NameValue = 101,
+ CCN_DTAG_Entry = 102,
+ CCN_DTAG_ACL = 103,
+ CCN_DTAG_ParameterizedName = 104,
+ CCN_DTAG_Prefix = 105,
+ CCN_DTAG_Suffix = 106,
+ CCN_DTAG_Root = 107,
+ CCN_DTAG_ProfileName = 108,
+ CCN_DTAG_Parameters = 109,
+ CCN_DTAG_InfoString = 110,
+ CCN_DTAG_StatusResponse = 112,
+ CCN_DTAG_StatusCode = 113,
+ CCN_DTAG_StatusText = 114,
+ CCN_DTAG_Nack = 200,
+ CCN_DTAG_SequenceNumber = 256,
+ CCN_DTAG_CCNProtocolDataUnit = 17702112
+};
+
+} // namespace CcnxParser
+} // namespace ndn
+} // namespace ns3
+
+#endif // _CCNB_PARSER_COMMON_H_
diff --git a/disabled/ccnb-parser/syntax-tree/attr.cc b/disabled/ccnb-parser/syntax-tree/attr.cc
new file mode 100644
index 0000000..fda4c77
--- /dev/null
+++ b/disabled/ccnb-parser/syntax-tree/attr.cc
@@ -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>
+ */
+
+#include "attr.h"
+#include "../common.h"
+
+namespace ns3 {
+namespace ndn {
+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"
+}
+
+}
+}
+}
diff --git a/disabled/ccnb-parser/syntax-tree/attr.h b/disabled/ccnb-parser/syntax-tree/attr.h
new file mode 100644
index 0000000..6238aee
--- /dev/null
+++ b/disabled/ccnb-parser/syntax-tree/attr.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_ATTR_H_
+#define _CCNB_PARSER_ATTR_H_
+
+#include "base-attr.h"
+#include <string>
+
+namespace ns3 {
+namespace ndn {
+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
+};
+
+}
+}
+}
+
+#endif // _CCNB_PARSER_ATTR_H_
diff --git a/disabled/ccnb-parser/syntax-tree/base-attr.h b/disabled/ccnb-parser/syntax-tree/base-attr.h
new file mode 100644
index 0000000..d6890a1
--- /dev/null
+++ b/disabled/ccnb-parser/syntax-tree/base-attr.h
@@ -0,0 +1,47 @@
+/* -*- 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"
+
+namespace ns3 {
+namespace ndn {
+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/disabled/ccnb-parser/syntax-tree/base-tag.h b/disabled/ccnb-parser/syntax-tree/base-tag.h
new file mode 100644
index 0000000..403dcb4
--- /dev/null
+++ b/disabled/ccnb-parser/syntax-tree/base-tag.h
@@ -0,0 +1,56 @@
+/* -*- 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>
+
+namespace ns3 {
+namespace ndn {
+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/disabled/ccnb-parser/syntax-tree/blob.cc b/disabled/ccnb-parser/syntax-tree/blob.cc
new file mode 100644
index 0000000..6df6012
--- /dev/null
+++ b/disabled/ccnb-parser/syntax-tree/blob.cc
@@ -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>
+ */
+
+#include "blob.h"
+
+namespace ns3 {
+namespace ndn {
+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;
+}
+
+}
+}
+}
diff --git a/disabled/ccnb-parser/syntax-tree/blob.h b/disabled/ccnb-parser/syntax-tree/blob.h
new file mode 100644
index 0000000..1745b1d
--- /dev/null
+++ b/disabled/ccnb-parser/syntax-tree/blob.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_BLOB_H_
+#define _CCNB_PARSER_BLOB_H_
+
+#include "block.h"
+
+namespace ns3 {
+namespace ndn {
+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
+};
+
+}
+}
+}
+
+#endif // _CCNB_PARSER_BLOB_H_
diff --git a/disabled/ccnb-parser/syntax-tree/block.cc b/disabled/ccnb-parser/syntax-tree/block.cc
new file mode 100644
index 0000000..0d425dd
--- /dev/null
+++ b/disabled/ccnb-parser/syntax-tree/block.cc
@@ -0,0 +1,99 @@
+/* -*- 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");
+
+namespace ns3 {
+namespace ndn {
+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 ()
+{
+}
+
+}
+}
+}
diff --git a/disabled/ccnb-parser/syntax-tree/block.h b/disabled/ccnb-parser/syntax-tree/block.h
new file mode 100644
index 0000000..23604f5
--- /dev/null
+++ b/disabled/ccnb-parser/syntax-tree/block.h
@@ -0,0 +1,87 @@
+/* -*- 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"
+
+namespace ns3 {
+namespace ndn {
+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;
+}
+
+}
+}
+}
+
+#endif // _CCNB_PARSER_BLOCK_H_
diff --git a/disabled/ccnb-parser/syntax-tree/dattr.cc b/disabled/ccnb-parser/syntax-tree/dattr.cc
new file mode 100644
index 0000000..dde424c
--- /dev/null
+++ b/disabled/ccnb-parser/syntax-tree/dattr.cc
@@ -0,0 +1,38 @@
+/* -*- 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"
+
+namespace ns3 {
+namespace ndn {
+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"
+}
+
+}
+}
+}
diff --git a/disabled/ccnb-parser/syntax-tree/dattr.h b/disabled/ccnb-parser/syntax-tree/dattr.h
new file mode 100644
index 0000000..e4c622c
--- /dev/null
+++ b/disabled/ccnb-parser/syntax-tree/dattr.h
@@ -0,0 +1,61 @@
+/* -*- 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"
+
+namespace ns3 {
+namespace ndn {
+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
+};
+
+}
+}
+}
+
+#endif // _CCNB_PARSER_DATTR_H_
diff --git a/disabled/ccnb-parser/syntax-tree/dtag.cc b/disabled/ccnb-parser/syntax-tree/dtag.cc
new file mode 100644
index 0000000..129b363
--- /dev/null
+++ b/disabled/ccnb-parser/syntax-tree/dtag.cc
@@ -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>
+ */
+
+#include "dtag.h"
+
+#include "base-attr.h"
+#include "base-tag.h"
+
+namespace ns3 {
+namespace ndn {
+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 ++;
+}
+
+}
+}
+}
diff --git a/disabled/ccnb-parser/syntax-tree/dtag.h b/disabled/ccnb-parser/syntax-tree/dtag.h
new file mode 100644
index 0000000..cf9871e
--- /dev/null
+++ b/disabled/ccnb-parser/syntax-tree/dtag.h
@@ -0,0 +1,66 @@
+/* -*- 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"
+
+namespace ns3 {
+namespace ndn {
+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
+};
+
+}
+}
+}
+
+#endif // _CCNB_PARSER_DTAG_H_
diff --git a/disabled/ccnb-parser/syntax-tree/ext.cc b/disabled/ccnb-parser/syntax-tree/ext.cc
new file mode 100644
index 0000000..b80743c
--- /dev/null
+++ b/disabled/ccnb-parser/syntax-tree/ext.cc
@@ -0,0 +1,34 @@
+/* -*- 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"
+
+namespace ns3 {
+namespace ndn {
+namespace CcnbParser {
+
+Ext::Ext (Buffer::Iterator &start, uint32_t extSubtype)
+{
+ m_extSubtype = extSubtype;
+}
+
+}
+}
+}
diff --git a/disabled/ccnb-parser/syntax-tree/ext.h b/disabled/ccnb-parser/syntax-tree/ext.h
new file mode 100644
index 0000000..072405c
--- /dev/null
+++ b/disabled/ccnb-parser/syntax-tree/ext.h
@@ -0,0 +1,61 @@
+/* -*- 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"
+
+namespace ns3 {
+namespace ndn {
+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
+};
+
+}
+}
+}
+
+#endif // _CCNB_PARSER_EXT_H_
diff --git a/disabled/ccnb-parser/syntax-tree/tag.cc b/disabled/ccnb-parser/syntax-tree/tag.cc
new file mode 100644
index 0000000..5a0d96c
--- /dev/null
+++ b/disabled/ccnb-parser/syntax-tree/tag.cc
@@ -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>
+ */
+
+#include "tag.h"
+
+#include "base-attr.h"
+
+namespace ns3 {
+namespace ndn {
+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
+}
+
+}
+}
+}
diff --git a/disabled/ccnb-parser/syntax-tree/tag.h b/disabled/ccnb-parser/syntax-tree/tag.h
new file mode 100644
index 0000000..94f4d32
--- /dev/null
+++ b/disabled/ccnb-parser/syntax-tree/tag.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_TAG_H_
+#define _CCNB_PARSER_TAG_H_
+
+#include "base-tag.h"
+#include <string>
+
+namespace ns3 {
+namespace ndn {
+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
+};
+
+}
+}
+}
+
+#endif // _CCNB_PARSER_TAG_H_
diff --git a/disabled/ccnb-parser/syntax-tree/udata.cc b/disabled/ccnb-parser/syntax-tree/udata.cc
new file mode 100644
index 0000000..cd69aba
--- /dev/null
+++ b/disabled/ccnb-parser/syntax-tree/udata.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 "udata.h"
+
+namespace ns3 {
+namespace ndn {
+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 ();
+}
+
+}
+}
+}
diff --git a/disabled/ccnb-parser/syntax-tree/udata.h b/disabled/ccnb-parser/syntax-tree/udata.h
new file mode 100644
index 0000000..b589ea4
--- /dev/null
+++ b/disabled/ccnb-parser/syntax-tree/udata.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_UDATA_H_
+#define _CCNB_PARSER_UDATA_H_
+
+#include "block.h"
+#include <string>
+
+namespace ns3 {
+namespace ndn {
+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
+};
+
+}
+}
+}
+
+#endif // _CCNB_PARSER_UDATA_H_
diff --git a/disabled/ccnb-parser/visitors/content-type-visitor.cc b/disabled/ccnb-parser/visitors/content-type-visitor.cc
new file mode 100644
index 0000000..a89b99c
--- /dev/null
+++ b/disabled/ccnb-parser/visitors/content-type-visitor.cc
@@ -0,0 +1,52 @@
+/* -*- 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 "content-type-visitor.h"
+#include "../syntax-tree/blob.h"
+
+namespace ns3 {
+namespace ndn {
+namespace CcnbParser {
+
+boost::any
+ContentTypeVisitor::visit (Blob &n)
+{
+ // Buffer n.m_blob;
+ if (n.m_blobSize != 3)
+ throw CcnbDecodingException ();
+
+ uint32_t type =
+ (n.m_blob [0] << 16) |
+ (n.m_blob [1] << 8 ) |
+ (n.m_blob [2] );
+
+ return boost::any (type);
+}
+
+boost::any
+ContentTypeVisitor::visit (Udata &n)
+{
+ // std::string n.m_udata;
+ throw CcnbDecodingException ();
+}
+
+}
+}
+}
diff --git a/disabled/ccnb-parser/visitors/content-type-visitor.h b/disabled/ccnb-parser/visitors/content-type-visitor.h
new file mode 100644
index 0000000..2cbd883
--- /dev/null
+++ b/disabled/ccnb-parser/visitors/content-type-visitor.h
@@ -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>
+ */
+
+#ifndef _CCNB_PARSER_CONTENT_TYPE_VISITOR_H_
+#define _CCNB_PARSER_CONTENT_TYPE_VISITOR_H_
+
+#include "no-argu-depth-first-visitor.h"
+
+namespace ns3 {
+namespace ndn {
+namespace CcnbParser {
+
+/**
+ * \ingroup ccnx-ccnb
+ * \brief Visitor to obtain nonce value from BLOB block
+ *
+ * Note, only first 32 bits will be actually parsed into nonce. If
+ * original Nonce contains more, the rest will be ignored
+ *
+ * Will return empty boost::any() if called on anything except BLOB block
+ */
+class ContentTypeVisitor : public NoArguDepthFirstVisitor
+{
+public:
+ virtual boost::any visit (Blob &n);
+ virtual boost::any visit (Udata &n); ///< Throws parsing error if BLOB object is encountered
+};
+
+}
+}
+}
+
+#endif // _CCNB_PARSER_CONTENT_TYPE_VISITOR_H_
diff --git a/disabled/ccnb-parser/visitors/depth-first-visitor.cc b/disabled/ccnb-parser/visitors/depth-first-visitor.cc
new file mode 100644
index 0000000..305fff6
--- /dev/null
+++ b/disabled/ccnb-parser/visitors/depth-first-visitor.cc
@@ -0,0 +1,110 @@
+/* -*- 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 "depth-first-visitor.h"
+
+#include "../syntax-tree/blob.h"
+#include "../syntax-tree/udata.h"
+#include "../syntax-tree/tag.h"
+#include "../syntax-tree/dtag.h"
+#include "../syntax-tree/attr.h"
+#include "../syntax-tree/dattr.h"
+#include "../syntax-tree/ext.h"
+
+#include <boost/foreach.hpp>
+
+namespace ns3 {
+namespace ndn {
+namespace CcnbParser {
+
+boost::any
+DepthFirstVisitor::visit (Blob &n, boost::any param)
+{
+ // Buffer n.m_blob;
+ return n.m_blob;
+}
+
+boost::any
+DepthFirstVisitor::visit (Udata &n, boost::any param)
+{
+ // std::string n.m_udata;
+ return n.m_udata;
+}
+
+boost::any
+DepthFirstVisitor::visit (Tag &n, boost::any param)
+{
+ // std::string n.m_tag;
+ // std::list<Ptr<Block> > n.m_attrs;
+ // std::list<Ptr<Block> > n.m_nestedBlocks;
+ BOOST_FOREACH (Ptr<Block> block, n.m_attrs)
+ {
+ block->accept (*this, param);
+ }
+ BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags)
+ {
+ block->accept (*this, param);
+ }
+ return boost::any();
+}
+
+boost::any
+DepthFirstVisitor::visit (Dtag &n, boost::any param)
+{
+ // std::string n.m_tag;
+ // std::list<Ptr<Block> > n.m_attrs;
+ // std::list<Ptr<Block> > n.m_nestedBlocks;
+ BOOST_FOREACH (Ptr<Block> block, n.m_attrs)
+ {
+ block->accept (*this, param);
+ }
+ BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags)
+ {
+ block->accept (*this, param);
+ }
+ return boost::any ();
+}
+
+boost::any
+DepthFirstVisitor::visit (Attr &n, boost::any param)
+{
+ // std::string n.m_attr;
+ // Ptr<Udata> n.m_value;
+ return boost::any ();
+}
+
+boost::any
+DepthFirstVisitor::visit (Dattr &n, boost::any param)
+{
+ // uint32_t n.m_dattr;
+ // Ptr<Udata> n.m_value;
+ return boost::any ();
+}
+
+boost::any
+DepthFirstVisitor::visit (Ext &n, boost::any param)
+{
+ // uint64_t n.m_extSubtype;
+ return n.m_extSubtype;
+}
+
+}
+}
+}
diff --git a/disabled/ccnb-parser/visitors/depth-first-visitor.h b/disabled/ccnb-parser/visitors/depth-first-visitor.h
new file mode 100644
index 0000000..2257802
--- /dev/null
+++ b/disabled/ccnb-parser/visitors/depth-first-visitor.h
@@ -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>
+ */
+
+#ifndef _CCNB_PARSER_DEPTH_FIRST_VISITOR_H_
+#define _CCNB_PARSER_DEPTH_FIRST_VISITOR_H_
+
+#include "visitor.h"
+
+namespace ns3 {
+namespace ndn {
+namespace CcnbParser {
+
+/**
+ * \ingroup ccnx-ccnb
+ * \brief Depth-first visitor that takes boot::any as argument and returns boost::any value
+ */
+class DepthFirstVisitor : public Visitor
+{
+public:
+ virtual boost::any visit (Blob&, boost::any);
+ virtual boost::any visit (Udata&, boost::any);
+ virtual boost::any visit (Tag&, boost::any);
+ virtual boost::any visit (Attr&, boost::any);
+ virtual boost::any visit (Dtag&, boost::any);
+ virtual boost::any visit (Dattr&, boost::any);
+ virtual boost::any visit (Ext&, boost::any);
+};
+
+}
+}
+}
+
+#endif // _CCNB_PARSER_DEPTH_FIRST_VISITOR_H_
diff --git a/disabled/ccnb-parser/visitors/interest-visitor.cc b/disabled/ccnb-parser/visitors/interest-visitor.cc
new file mode 100644
index 0000000..175eaad
--- /dev/null
+++ b/disabled/ccnb-parser/visitors/interest-visitor.cc
@@ -0,0 +1,188 @@
+/* -*- 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 "interest-visitor.h"
+
+#include "../syntax-tree/block.h"
+#include "../syntax-tree/dtag.h"
+
+#include "ns3/ndn-name-components.h"
+#include "ns3/ndn-interest-header.h"
+
+#include "ns3/assert.h"
+#include "ns3/nstime.h"
+
+#include "name-components-visitor.h"
+#include "non-negative-integer-visitor.h"
+#include "timestamp-visitor.h"
+#include "uint32t-blob-visitor.h"
+
+#include <boost/foreach.hpp>
+
+#include "ns3/log.h"
+
+NS_LOG_COMPONENT_DEFINE ("ndn.CcnbParser.InterestVisitor");
+
+namespace ns3 {
+namespace ndn {
+namespace CcnbParser {
+
+// We don't care about any other fields
+void
+InterestVisitor::visit (Dtag &n, boost::any param/*should be InterestHeader* */)
+{
+ // uint32_t n.m_dtag;
+ // std::list<Ptr<Block> > n.m_nestedBlocks;
+
+ static NonNegativeIntegerVisitor nonNegativeIntegerVisitor;
+ static NameComponentsVisitor nameComponentsVisitor;
+ static TimestampVisitor timestampVisitor;
+ static Uint32tBlobVisitor nonceVisitor;
+
+ InterestHeader &interest = *(boost::any_cast<InterestHeader*> (param));
+
+ switch (n.m_dtag)
+ {
+ case CCN_DTAG_Interest:
+ NS_LOG_DEBUG ("Interest");
+
+ // process nested blocks
+ BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags)
+ {
+ block->accept (*this, param);
+ }
+ break;
+ case CCN_DTAG_Name:
+ {
+ NS_LOG_DEBUG ("Name");
+
+ // process name components
+ Ptr<NameComponents> name = Create<NameComponents> ();
+
+ BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags)
+ {
+ block->accept (nameComponentsVisitor, &(*name));
+ }
+ interest.SetName (name);
+ break;
+ }
+ case CCN_DTAG_MinSuffixComponents:
+ NS_LOG_DEBUG ("MinSuffixComponents");
+ if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag
+ throw CcnbDecodingException ();
+ interest.SetMinSuffixComponents (
+ boost::any_cast<uint32_t> (
+ (*n.m_nestedTags.begin())->accept(
+ nonNegativeIntegerVisitor
+ )));
+ break;
+ case CCN_DTAG_MaxSuffixComponents:
+ NS_LOG_DEBUG ("MaxSuffixComponents");
+ if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag
+ throw CcnbDecodingException ();
+ interest.SetMaxSuffixComponents (
+ boost::any_cast<uint32_t> (
+ (*n.m_nestedTags.begin())->accept(
+ nonNegativeIntegerVisitor
+ )));
+ break;
+ case CCN_DTAG_Exclude:
+ {
+ NS_LOG_DEBUG ("Exclude");
+ // process exclude components
+ Ptr<NameComponents> exclude = Create<NameComponents> ();
+
+ BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags)
+ {
+ block->accept (nameComponentsVisitor, &(*exclude));
+ }
+ interest.SetExclude (exclude);
+ break;
+ }
+ case CCN_DTAG_ChildSelector:
+ NS_LOG_DEBUG ("ChildSelector");
+ if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag
+ throw CcnbDecodingException ();
+
+ interest.SetChildSelector (
+ 1 == boost::any_cast<uint32_t> (
+ (*n.m_nestedTags.begin())->accept(
+ nonNegativeIntegerVisitor
+ )));
+ break;
+ case CCN_DTAG_AnswerOriginKind:
+ NS_LOG_DEBUG ("AnswerOriginKind");
+ if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag
+ throw CcnbDecodingException ();
+ interest.SetAnswerOriginKind (
+ 1 == boost::any_cast<uint32_t> (
+ (*n.m_nestedTags.begin())->accept(
+ nonNegativeIntegerVisitor
+ )));
+ break;
+ case CCN_DTAG_Scope:
+ NS_LOG_DEBUG ("Scope");
+ if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag
+ throw CcnbDecodingException ();
+ interest.SetScope (
+ boost::any_cast<uint32_t> (
+ (*n.m_nestedTags.begin())->accept(
+ nonNegativeIntegerVisitor
+ )));
+ break;
+ case CCN_DTAG_InterestLifetime:
+ NS_LOG_DEBUG ("InterestLifetime");
+ if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag
+ throw CcnbDecodingException ();
+
+ interest.SetInterestLifetime (
+ boost::any_cast<Time> (
+ (*n.m_nestedTags.begin())->accept(
+ timestampVisitor
+ )));
+ break;
+ case CCN_DTAG_Nonce:
+ NS_LOG_DEBUG ("Nonce");
+ if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag
+ throw CcnbDecodingException ();
+
+ interest.SetNonce (
+ boost::any_cast<uint32_t> (
+ (*n.m_nestedTags.begin())->accept(
+ nonceVisitor
+ )));
+ break;
+
+
+ case CCN_DTAG_Nack:
+ NS_LOG_DEBUG ("Nack");
+ if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag
+ throw CcnbDecodingException ();
+
+ interest.SetNack (
+ boost::any_cast<uint32_t> (
+ (*n.m_nestedTags.begin())->accept(nonNegativeIntegerVisitor)));
+ break;
+ }
+}
+
+} // namespace CcnbParser
+} // namespace ndn
+} // namespace ns3
diff --git a/disabled/ccnb-parser/visitors/interest-visitor.h b/disabled/ccnb-parser/visitors/interest-visitor.h
new file mode 100644
index 0000000..f78d07f
--- /dev/null
+++ b/disabled/ccnb-parser/visitors/interest-visitor.h
@@ -0,0 +1,52 @@
+/* -*- 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_INTEREST_VISITOR_H_
+#define _CCNB_PARSER_INTEREST_VISITOR_H_
+
+#include "void-depth-first-visitor.h"
+
+namespace ns3 {
+namespace ndn {
+namespace CcnbParser {
+
+/**
+ * \ingroup ccnx-ccnb
+ * \brief Visitor that fills fields in CcnxInterestHeader
+ *
+ * Usage example:
+ * \code
+ * Ptr<CcnxInterestHeader> header = Create<CcnxInterestHeader> ();
+ * Ptr<CcnbParser::Block> root = CcnbParser::Block::ParseBlock (i);
+ * InterestVisitor visitor;
+ * root->accept (visitor, *header);
+ * \endcode
+ */
+class InterestVisitor : public VoidDepthFirstVisitor
+{
+public:
+ virtual void visit (Dtag &n, boost::any param/*should be CcnxInterestHeader* */);
+};
+
+} // namespace CcnbParser
+} // namespace ndn
+} // namespace ns3
+
+#endif // _CCNB_PARSER_INTEREST_VISITOR_H_
diff --git a/disabled/ccnb-parser/visitors/name-components-visitor.cc b/disabled/ccnb-parser/visitors/name-components-visitor.cc
new file mode 100644
index 0000000..ef87281
--- /dev/null
+++ b/disabled/ccnb-parser/visitors/name-components-visitor.cc
@@ -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>
+ */
+
+#include "name-components-visitor.h"
+
+#include "string-visitor.h"
+#include "../syntax-tree/dtag.h"
+
+#include "ns3/ndn-name-components.h"
+
+namespace ns3 {
+namespace ndn {
+namespace CcnbParser {
+
+void
+NameComponentsVisitor::visit (Dtag &n, boost::any param/*should be NameComponents* */)
+{
+ // uint32_t n.m_dtag;
+ // std::list<Ptr<Block> > n.m_nestedBlocks;
+ static StringVisitor stringVisitor;
+
+ NameComponents &components = *(boost::any_cast<NameComponents*> (param));
+
+ switch (n.m_dtag)
+ {
+ case CCN_DTAG_Component:
+ if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag
+ throw CcnbDecodingException ();
+ components.Add (
+ boost::any_cast<std::string> ((*n.m_nestedTags.begin())->accept(
+ stringVisitor
+ )));
+ break;
+ default:
+ // ignore any other components
+ // when parsing Exclude, there could be <Any /> and <Bloom /> tags
+ break;
+ }
+}
+
+}
+}
+}
diff --git a/disabled/ccnb-parser/visitors/name-components-visitor.h b/disabled/ccnb-parser/visitors/name-components-visitor.h
new file mode 100644
index 0000000..823de35
--- /dev/null
+++ b/disabled/ccnb-parser/visitors/name-components-visitor.h
@@ -0,0 +1,45 @@
+/* -*- 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_NAME_COMPONENTS_VISITOR_H_
+#define _CCNB_PARSER_NAME_COMPONENTS_VISITOR_H_
+
+#include "void-depth-first-visitor.h"
+
+namespace ns3 {
+namespace ndn {
+namespace CcnbParser {
+
+/**
+ * \ingroup ccnx-ccnb
+ * \brief Visitor to obtain fill CcnxNameComponents object with name components
+ */
+class NameComponentsVisitor : public VoidDepthFirstVisitor
+{
+public:
+ virtual void visit (Dtag &n, boost::any param/*should be CcnxNameComponents* */);
+};
+
+}
+}
+}
+
+#endif // _CCNB_PARSER_NAME_COMPONENTS_VISITOR_H_
+
diff --git a/disabled/ccnb-parser/visitors/no-argu-depth-first-visitor.cc b/disabled/ccnb-parser/visitors/no-argu-depth-first-visitor.cc
new file mode 100644
index 0000000..53f1122
--- /dev/null
+++ b/disabled/ccnb-parser/visitors/no-argu-depth-first-visitor.cc
@@ -0,0 +1,110 @@
+/* -*- 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 "no-argu-depth-first-visitor.h"
+
+#include "../syntax-tree/blob.h"
+#include "../syntax-tree/udata.h"
+#include "../syntax-tree/tag.h"
+#include "../syntax-tree/dtag.h"
+#include "../syntax-tree/attr.h"
+#include "../syntax-tree/dattr.h"
+#include "../syntax-tree/ext.h"
+
+#include <boost/foreach.hpp>
+
+namespace ns3 {
+namespace ndn {
+namespace CcnbParser {
+
+boost::any
+NoArguDepthFirstVisitor::visit (Blob &n)
+{
+ // Buffer n.m_blob;
+ return n.m_blob;
+}
+
+boost::any
+NoArguDepthFirstVisitor::visit (Udata &n)
+{
+ // std::string n.m_udata;
+ return n.m_udata;
+}
+
+boost::any
+NoArguDepthFirstVisitor::visit (Tag &n)
+{
+ // uint32_t n.m_dtag;
+ // std::list<Ptr<Block> > n.m_attrs;
+ // std::list<Ptr<Block> > n.m_nestedBlocks;
+ BOOST_FOREACH (Ptr<Block> block, n.m_attrs)
+ {
+ block->accept (*this);
+ }
+ BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags)
+ {
+ block->accept (*this);
+ }
+ return boost::any ();
+}
+
+boost::any
+NoArguDepthFirstVisitor::visit (Dtag &n)
+{
+ // uint32_t n.m_dtag;
+ // std::list<Ptr<Block> > n.m_attrs;
+ // std::list<Ptr<Block> > n.m_nestedBlocks;
+ BOOST_FOREACH (Ptr<Block> block, n.m_attrs)
+ {
+ block->accept (*this);
+ }
+ BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags)
+ {
+ block->accept (*this);
+ }
+ return boost::any();
+}
+
+boost::any
+NoArguDepthFirstVisitor::visit (Attr &n)
+{
+ // std::string n.m_attr;
+ // Ptr<Udata> n.m_value;
+ return boost::any ();
+}
+
+boost::any
+NoArguDepthFirstVisitor::visit (Dattr &n)
+{
+ // uint32_t n.m_dattr;
+ // Ptr<Udata> n.m_value;
+ return boost::any ();
+}
+
+boost::any
+NoArguDepthFirstVisitor::visit (Ext &n)
+{
+ // uint64_t n.m_extSubtype;
+ return n.m_extSubtype;
+}
+
+}
+}
+}
diff --git a/disabled/ccnb-parser/visitors/no-argu-depth-first-visitor.h b/disabled/ccnb-parser/visitors/no-argu-depth-first-visitor.h
new file mode 100644
index 0000000..4b6c2e9
--- /dev/null
+++ b/disabled/ccnb-parser/visitors/no-argu-depth-first-visitor.h
@@ -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>
+ */
+
+#ifndef _CCNB_PARSER_NO_ARGU_DEPTH_FIRST_VISITOR_H_
+#define _CCNB_PARSER_NO_ARGU_DEPTH_FIRST_VISITOR_H_
+
+#include "no-argu-visitor.h"
+
+namespace ns3 {
+namespace ndn {
+namespace CcnbParser {
+
+/**
+ * \ingroup ccnx-ccnb
+ * \brief Depth-first visitor that takes no arguments and returns boost::any value
+ */
+class NoArguDepthFirstVisitor : public NoArguVisitor
+{
+public:
+ virtual boost::any visit (Blob& );
+ virtual boost::any visit (Udata&);
+ virtual boost::any visit (Tag& );
+ virtual boost::any visit (Attr& );
+ virtual boost::any visit (Dtag& );
+ virtual boost::any visit (Dattr&);
+ virtual boost::any visit (Ext& );
+};
+
+}
+}
+}
+
+#endif // _CCNB_PARSER_NO_ARGU_DEPTH_FIRST_VISITOR_H_
diff --git a/disabled/ccnb-parser/visitors/no-argu-visitor.h b/disabled/ccnb-parser/visitors/no-argu-visitor.h
new file mode 100644
index 0000000..abbf843
--- /dev/null
+++ b/disabled/ccnb-parser/visitors/no-argu-visitor.h
@@ -0,0 +1,56 @@
+/* -*- 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_NO_ARGU_VISITOR_H_
+#define _CCNB_PARSER_NO_ARGU_VISITOR_H_
+
+#include "../common.h"
+#include <boost/any.hpp>
+
+namespace ns3 {
+namespace ndn {
+namespace CcnbParser {
+
+/**
+ * \ingroup ccnx-ccnb
+ * \brief Visitor interface that takes no arguments and returns boost::any
+ *
+ * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
+ * for ccnb encoding format help
+ */
+class NoArguVisitor
+{
+public:
+ virtual boost::any visit (Blob& )=0; ///< \brief Method accepting BLOB block
+ virtual boost::any visit (Udata&)=0; ///< \brief Method accepting UDATA block
+ virtual boost::any visit (Tag& )=0; ///< \brief Method accepting TAG block
+ virtual boost::any visit (Attr& )=0; ///< \brief Method accepting ATTR block
+ virtual boost::any visit (Dtag& )=0; ///< \brief Method accepting DTAG block
+ virtual boost::any visit (Dattr&)=0; ///< \brief Method accepting DATTR block
+ virtual boost::any visit (Ext& )=0; ///< \brief Method accepting EXT block
+
+ virtual ~NoArguVisitor () { }
+};
+
+}
+}
+}
+
+#endif // _CCNB_PARSER_NO_ARGU_VISITOR_H_
diff --git a/disabled/ccnb-parser/visitors/non-negative-integer-visitor.cc b/disabled/ccnb-parser/visitors/non-negative-integer-visitor.cc
new file mode 100644
index 0000000..d5fc041
--- /dev/null
+++ b/disabled/ccnb-parser/visitors/non-negative-integer-visitor.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 "non-negative-integer-visitor.h"
+
+#include "../syntax-tree/blob.h"
+#include "../syntax-tree/udata.h"
+#include <sstream>
+
+namespace ns3 {
+namespace ndn {
+namespace CcnbParser {
+
+boost::any
+NonNegativeIntegerVisitor::visit (Blob &n) //to throw parsing error
+{
+ // Buffer n.m_blob;
+ throw CcnbDecodingException ();
+}
+
+boost::any
+NonNegativeIntegerVisitor::visit (Udata &n)
+{
+ // std::string n.m_udata;
+ std::istringstream is (n.m_udata);
+ int32_t value;
+ is >> value;
+ if (value<0) // value should be non-negative
+ throw CcnbDecodingException ();
+
+ return static_cast<uint32_t> (value);
+}
+
+}
+}
+}
diff --git a/disabled/ccnb-parser/visitors/non-negative-integer-visitor.h b/disabled/ccnb-parser/visitors/non-negative-integer-visitor.h
new file mode 100644
index 0000000..2bb9f91
--- /dev/null
+++ b/disabled/ccnb-parser/visitors/non-negative-integer-visitor.h
@@ -0,0 +1,47 @@
+/* -*- 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_NON_NEGATIVE_INTEGER_VISITOR_H_
+#define _CCNB_PARSER_NON_NEGATIVE_INTEGER_VISITOR_H_
+
+#include "no-argu-depth-first-visitor.h"
+
+namespace ns3 {
+namespace ndn {
+namespace CcnbParser {
+
+/**
+ * \ingroup ccnx-ccnb
+ * \brief Visitor to obtain non-negative integer value from UDATA block
+ *
+ * Will return empty boost::any() if called on anything except UDATA block
+ */
+class NonNegativeIntegerVisitor : public NoArguDepthFirstVisitor
+{
+public:
+ virtual boost::any visit (Blob &n); ///< Throws an exception if BLOB object is encountered
+ virtual boost::any visit (Udata &n);
+};
+
+}
+}
+}
+
+#endif // _CCNB_PARSER_NON_NEGATIVE_INTEGER_VISITOR_H_
diff --git a/disabled/ccnb-parser/visitors/string-visitor.cc b/disabled/ccnb-parser/visitors/string-visitor.cc
new file mode 100644
index 0000000..5f44bf3
--- /dev/null
+++ b/disabled/ccnb-parser/visitors/string-visitor.cc
@@ -0,0 +1,45 @@
+/* -*- 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 "string-visitor.h"
+#include "../syntax-tree/udata.h"
+#include "../syntax-tree/blob.h"
+
+namespace ns3 {
+namespace ndn {
+namespace CcnbParser {
+
+boost::any
+StringVisitor::visit (Blob &n)
+{
+ // Buffer n.m_blob;
+ return std::string (n.m_blob, n.m_blobSize);
+}
+
+boost::any
+StringVisitor::visit (Udata &n)
+{
+ // std::string n.m_udata;
+ return n.m_udata;
+}
+
+}
+}
+}
diff --git a/disabled/ccnb-parser/visitors/string-visitor.h b/disabled/ccnb-parser/visitors/string-visitor.h
new file mode 100644
index 0000000..ea285d1
--- /dev/null
+++ b/disabled/ccnb-parser/visitors/string-visitor.h
@@ -0,0 +1,47 @@
+/* -*- 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_STRING_VISITOR_H_
+#define _CCNB_PARSER_STRING_VISITOR_H_
+
+#include "no-argu-depth-first-visitor.h"
+
+namespace ns3 {
+namespace ndn {
+namespace CcnbParser {
+
+/**
+ * \ingroup ccnx-ccnb
+ * \brief Visitor to obtain string value from UDATA block
+ *
+ * Will return empty boost::any() if called on anything except UDATA block
+ */
+class StringVisitor : public NoArguDepthFirstVisitor
+{
+public:
+ virtual boost::any visit (Blob &n);
+ virtual boost::any visit (Udata &n);
+};
+
+}
+}
+}
+
+#endif // _CCNB_PARSER_STRING_VISITOR_H_
diff --git a/disabled/ccnb-parser/visitors/timestamp-visitor.cc b/disabled/ccnb-parser/visitors/timestamp-visitor.cc
new file mode 100644
index 0000000..5917711
--- /dev/null
+++ b/disabled/ccnb-parser/visitors/timestamp-visitor.cc
@@ -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>
+ */
+
+#include "timestamp-visitor.h"
+#include "../syntax-tree/blob.h"
+
+#include "ns3/nstime.h"
+
+namespace ns3 {
+namespace ndn {
+namespace CcnbParser {
+
+boost::any/*Time*/
+TimestampVisitor::visit (Blob &n)
+{
+ // Buffer n.m_blob;
+ if (n.m_blobSize < 2)
+ throw CcnbDecodingException ();
+
+ const char *start = n.m_blob;
+
+ intmax_t seconds = 0;
+ intmax_t nanoseconds = 0;
+
+ for (uint32_t i=0; i < n.m_blobSize-2; i++)
+ {
+ seconds = (seconds << 8) | (uint8_t)start[i];
+ }
+ uint8_t combo = start[n.m_blobSize-2]; // 4 most significant bits hold 4 least significant bits of number of seconds
+ seconds = (seconds << 4) | (combo >> 4);
+
+ nanoseconds = combo & 0x0F; /*00001111*/ // 4 least significant bits hold 4 most significant bits of number of
+ nanoseconds = (nanoseconds << 8) | start[n.m_blobSize-1];
+ nanoseconds = (intmax_t) ((nanoseconds / 4096.0/*2^12*/) * 1000000 /*up-convert useconds*/);
+
+ return boost::any (Time::FromInteger (seconds, Time::S) + Time::FromInteger (nanoseconds, Time::US));
+}
+
+boost::any
+TimestampVisitor::visit (Udata &n)
+{
+ // std::string n.m_udata;
+ throw CcnbDecodingException ();
+}
+
+}
+}
+}
diff --git a/disabled/ccnb-parser/visitors/timestamp-visitor.h b/disabled/ccnb-parser/visitors/timestamp-visitor.h
new file mode 100644
index 0000000..3884ff6
--- /dev/null
+++ b/disabled/ccnb-parser/visitors/timestamp-visitor.h
@@ -0,0 +1,47 @@
+/* -*- 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_TIMESTAMP_VISITOR_H_
+#define _CCNB_PARSER_TIMESTAMP_VISITOR_H_
+
+#include "no-argu-depth-first-visitor.h"
+
+namespace ns3 {
+namespace ndn {
+namespace CcnbParser {
+
+/**
+ * \ingroup ccnx-ccnb
+ * \brief Visitor to obtain timestamp value from BLOB block
+ *
+ * Will return empty boost::any() if called on anything except BLOB block
+ */
+class TimestampVisitor : public NoArguDepthFirstVisitor
+{
+public:
+ virtual boost::any visit (Blob &n);
+ virtual boost::any/*Time*/ visit (Udata &n); ///< Throws parsing error if UDATA object is encountered
+};
+
+}
+}
+}
+
+#endif // _CCNB_PARSER_TIMESTAMP_VISITOR_H_
diff --git a/disabled/ccnb-parser/visitors/uint32t-blob-visitor.cc b/disabled/ccnb-parser/visitors/uint32t-blob-visitor.cc
new file mode 100644
index 0000000..351cc36
--- /dev/null
+++ b/disabled/ccnb-parser/visitors/uint32t-blob-visitor.cc
@@ -0,0 +1,47 @@
+/* -*- 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 "uint32t-blob-visitor.h"
+#include "../syntax-tree/blob.h"
+
+namespace ns3 {
+namespace ndn {
+namespace CcnbParser {
+
+boost::any
+Uint32tBlobVisitor::visit (Blob &n)
+{
+ // Buffer n.m_blob;
+ if (n.m_blobSize < 4)
+ throw CcnbDecodingException ();
+
+ return boost::any (*(reinterpret_cast<uint32_t*> (n.m_blob)));
+}
+
+boost::any
+Uint32tBlobVisitor::visit (Udata &n)
+{
+ // std::string n.m_udata;
+ throw CcnbDecodingException ();
+}
+
+}
+}
+}
diff --git a/disabled/ccnb-parser/visitors/uint32t-blob-visitor.h b/disabled/ccnb-parser/visitors/uint32t-blob-visitor.h
new file mode 100644
index 0000000..de5f374
--- /dev/null
+++ b/disabled/ccnb-parser/visitors/uint32t-blob-visitor.h
@@ -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>
+ */
+
+#ifndef _CCNB_PARSER_UINT32T_BLOB_VISITOR_H_
+#define _CCNB_PARSER_UINT32T_BLOB_VISITOR_H_
+
+#include "no-argu-depth-first-visitor.h"
+
+namespace ns3 {
+namespace ndn {
+namespace CcnbParser {
+
+/**
+ * \ingroup ccnx-ccnb
+ * \brief Visitor to obtain nonce value from BLOB block
+ *
+ * Note, only first 32 bits will be actually parsed into nonce. If
+ * original Nonce contains more, the rest will be ignored
+ *
+ * Will return empty boost::any() if called on anything except BLOB block
+ */
+class Uint32tBlobVisitor : public NoArguDepthFirstVisitor
+{
+public:
+ virtual boost::any visit (Blob &n);
+ virtual boost::any visit (Udata &n); ///< Throws parsing error if BLOB object is encountered
+};
+
+}
+}
+}
+
+#endif // _CCNB_PARSER_UINT32T_BLOB_VISITOR_H_
diff --git a/disabled/ccnb-parser/visitors/visitor.h b/disabled/ccnb-parser/visitors/visitor.h
new file mode 100644
index 0000000..76744ee
--- /dev/null
+++ b/disabled/ccnb-parser/visitors/visitor.h
@@ -0,0 +1,56 @@
+/* -*- 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_VISITOR_H_
+#define _CCNB_PARSER_VISITOR_H_
+
+#include "../common.h"
+#include <boost/any.hpp>
+
+namespace ns3 {
+namespace ndn {
+namespace CcnbParser {
+
+/**
+ * \ingroup ccnx-ccnb
+ * \brief Visitor interface that takes one boost::any argument and returns boost::any
+ *
+ * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
+ * for ccnb encoding format help
+ */
+class Visitor
+{
+public:
+ virtual boost::any visit (Blob&, boost::any)=0; ///< \brief Method accepting BLOB block
+ virtual boost::any visit (Udata&, boost::any)=0; ///< \brief Method accepting UDATA block
+ virtual boost::any visit (Tag&, boost::any)=0; ///< \brief Method accepting TAG block
+ virtual boost::any visit (Attr&, boost::any)=0; ///< \brief Method accepting ATTR block
+ virtual boost::any visit (Dtag&, boost::any)=0; ///< \brief Method accepting DTAG block
+ virtual boost::any visit (Dattr&, boost::any)=0; ///< \brief Method accepting DATTR block
+ virtual boost::any visit (Ext&, boost::any)=0; ///< \brief Method accepting EXT block
+
+ virtual ~Visitor () { }
+};
+
+}
+}
+}
+
+#endif // _CCNB_PARSER_VISITOR_H_
diff --git a/disabled/ccnb-parser/visitors/void-depth-first-visitor.cc b/disabled/ccnb-parser/visitors/void-depth-first-visitor.cc
new file mode 100644
index 0000000..1a1770a
--- /dev/null
+++ b/disabled/ccnb-parser/visitors/void-depth-first-visitor.cc
@@ -0,0 +1,103 @@
+/* -*- 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 "void-depth-first-visitor.h"
+
+#include "../syntax-tree/blob.h"
+#include "../syntax-tree/udata.h"
+#include "../syntax-tree/tag.h"
+#include "../syntax-tree/dtag.h"
+#include "../syntax-tree/attr.h"
+#include "../syntax-tree/dattr.h"
+#include "../syntax-tree/ext.h"
+
+#include <boost/foreach.hpp>
+
+namespace ns3 {
+namespace ndn {
+namespace CcnbParser {
+
+void
+VoidDepthFirstVisitor::visit (Blob &n, boost::any param)
+{
+ // Buffer n.m_blob;
+}
+
+void
+VoidDepthFirstVisitor::visit (Udata &n, boost::any param)
+{
+ // std::string n.m_udata;
+}
+
+void
+VoidDepthFirstVisitor::visit (Tag &n, boost::any param)
+{
+ // std::string n.m_tag;
+ // std::list<Ptr<Block> > n.m_attrs;
+ // std::list<Ptr<Block> > n.m_nestedBlocks;
+ BOOST_FOREACH (Ptr<Block> block, n.m_attrs)
+ {
+ block->accept (*this, param);
+ }
+ BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags)
+ {
+ block->accept (*this, param);
+ }
+}
+
+void
+VoidDepthFirstVisitor::visit (Dtag &n, boost::any param)
+{
+ // std::string n.m_tag;
+ // std::list<Ptr<Block> > n.m_attrs;
+ // std::list<Ptr<Block> > n.m_nestedBlocks;
+ BOOST_FOREACH (Ptr<Block> block, n.m_attrs)
+ {
+ block->accept (*this, param);
+ }
+ BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags)
+ {
+ block->accept (*this, param);
+ }
+}
+
+void
+VoidDepthFirstVisitor::visit (Attr &n, boost::any param)
+{
+ // std::string n.m_attr;
+ // Ptr<Udata> n.m_value;
+}
+
+void
+VoidDepthFirstVisitor::visit (Dattr &n, boost::any param)
+{
+ // uint32_t n.m_dattr;
+ // Ptr<Udata> n.m_value;
+}
+
+void
+VoidDepthFirstVisitor::visit (Ext &n, boost::any param)
+{
+ // uint64_t n.m_extSubtype;
+}
+
+}
+}
+}
diff --git a/disabled/ccnb-parser/visitors/void-depth-first-visitor.h b/disabled/ccnb-parser/visitors/void-depth-first-visitor.h
new file mode 100644
index 0000000..2e1862e
--- /dev/null
+++ b/disabled/ccnb-parser/visitors/void-depth-first-visitor.h
@@ -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>
+ */
+
+#ifndef _CCNB_PARSER_VOID_DEPTH_FIRST_VISITOR_H_
+#define _CCNB_PARSER_VOID_DEPTH_FIRST_VISITOR_H_
+
+#include "void-visitor.h"
+
+namespace ns3 {
+namespace ndn {
+namespace CcnbParser {
+
+/**
+ * \ingroup ccnx-ccnb
+ * \brief Depth-first visitor that takes one argument and returns nothing
+ */
+class VoidDepthFirstVisitor : public VoidVisitor
+{
+public:
+ virtual void visit (Blob&, boost::any);
+ virtual void visit (Udata&, boost::any);
+ virtual void visit (Tag&, boost::any);
+ virtual void visit (Attr&, boost::any);
+ virtual void visit (Dtag&, boost::any);
+ virtual void visit (Dattr&, boost::any);
+ virtual void visit (Ext&, boost::any);
+};
+
+}
+}
+}
+
+#endif // _CCNB_PARSER_VOID_DEPTH_FIRST_VISITOR_H_
diff --git a/disabled/ccnb-parser/visitors/void-no-argu-depth-first-visitor.cc b/disabled/ccnb-parser/visitors/void-no-argu-depth-first-visitor.cc
new file mode 100644
index 0000000..439bf93
--- /dev/null
+++ b/disabled/ccnb-parser/visitors/void-no-argu-depth-first-visitor.cc
@@ -0,0 +1,103 @@
+/* -*- 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 "void-no-argu-depth-first-visitor.h"
+
+#include "../syntax-tree/blob.h"
+#include "../syntax-tree/udata.h"
+#include "../syntax-tree/tag.h"
+#include "../syntax-tree/dtag.h"
+#include "../syntax-tree/attr.h"
+#include "../syntax-tree/dattr.h"
+#include "../syntax-tree/ext.h"
+
+#include <boost/foreach.hpp>
+
+namespace ns3 {
+namespace ndn {
+namespace CcnbParser {
+
+void
+VoidNoArguDepthFirstVisitor::visit (Blob &n)
+{
+ // Buffer n.m_blob;
+}
+
+void
+VoidNoArguDepthFirstVisitor::visit (Udata &n)
+{
+ // std::string n.m_udata;
+}
+
+void
+VoidNoArguDepthFirstVisitor::visit (Tag &n)
+{
+ // std::string n.m_tag;
+ // std::list<Ptr<Block> > n.m_attrs;
+ // std::list<Ptr<Block> > n.m_nestedBlocks;
+ BOOST_FOREACH (Ptr<Block> block, n.m_attrs)
+ {
+ block->accept (*this);
+ }
+ BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags)
+ {
+ block->accept (*this);
+ }
+}
+
+void
+VoidNoArguDepthFirstVisitor::visit (Dtag &n)
+{
+ // uint32_t n.m_dtag;
+ // std::list<Ptr<Block> > n.m_attrs;
+ // std::list<Ptr<Block> > n.m_nestedBlocks;
+ BOOST_FOREACH (Ptr<Block> block, n.m_attrs)
+ {
+ block->accept (*this);
+ }
+ BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags)
+ {
+ block->accept (*this);
+ }
+}
+
+void
+VoidNoArguDepthFirstVisitor::visit (Attr &n)
+{
+ // std::string n.m_attr;
+ // Ptr<Udata> n.m_value;
+}
+
+void
+VoidNoArguDepthFirstVisitor::visit (Dattr &n)
+{
+ // uint32_t n.m_dattr;
+ // Ptr<Udata> n.m_value;
+}
+
+void
+VoidNoArguDepthFirstVisitor::visit (Ext &n)
+{
+ // uint64_t n.m_extSubtype;
+}
+
+}
+}
+}
diff --git a/disabled/ccnb-parser/visitors/void-no-argu-depth-first-visitor.h b/disabled/ccnb-parser/visitors/void-no-argu-depth-first-visitor.h
new file mode 100644
index 0000000..995f90a
--- /dev/null
+++ b/disabled/ccnb-parser/visitors/void-no-argu-depth-first-visitor.h
@@ -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>
+ */
+
+#ifndef _CCNB_PARSER_VOID_NO_ARGU_DEPTH_FIRST_VISITOR_H_
+#define _CCNB_PARSER_VOID_NO_ARGU_DEPTH_FIRST_VISITOR_H_
+
+#include "void-no-argu-visitor.h"
+
+namespace ns3 {
+namespace ndn {
+namespace CcnbParser {
+
+/**
+ * \ingroup ccnx-ccnb
+ * \brief Depth-first visitor that takes no arguments and returns nothing
+ */
+class VoidNoArguDepthFirstVisitor : public VoidNoArguVisitor
+{
+public:
+ virtual void visit (Blob& );
+ virtual void visit (Udata&);
+ virtual void visit (Tag& );
+ virtual void visit (Attr& );
+ virtual void visit (Dtag& );
+ virtual void visit (Dattr&);
+ virtual void visit (Ext& );
+};
+
+}
+}
+}
+
+#endif // _CCNB_PARSER_VOID_NO_ARGU_DEPTH_FIRST_VISITOR_H_
diff --git a/disabled/ccnb-parser/visitors/void-no-argu-visitor.h b/disabled/ccnb-parser/visitors/void-no-argu-visitor.h
new file mode 100644
index 0000000..6dccf4e
--- /dev/null
+++ b/disabled/ccnb-parser/visitors/void-no-argu-visitor.h
@@ -0,0 +1,55 @@
+/* -*- 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_VOID_NO_ARGU_VISITOR_H_
+#define _CCNB_PARSER_VOID_NO_ARGU_VISITOR_H_
+
+#include "../common.h"
+
+namespace ns3 {
+namespace ndn {
+namespace CcnbParser {
+
+/**
+ * \ingroup ndn-ccnb
+ * \brief Visitor interface that takes no arguments and returns nothing
+ *
+ * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
+ * for ccnb encoding format help
+ */
+class VoidNoArguVisitor
+{
+public:
+ virtual void visit (Blob& )=0; ///< \brief Method accepting BLOB block
+ virtual void visit (Udata&)=0; ///< \brief Method accepting UDATA block
+ virtual void visit (Tag& )=0; ///< \brief Method accepting TAG block
+ virtual void visit (Attr& )=0; ///< \brief Method accepting ATTR block
+ virtual void visit (Dtag& )=0; ///< \brief Method accepting DTAG block
+ virtual void visit (Dattr&)=0; ///< \brief Method accepting DATTR block
+ virtual void visit (Ext& )=0; ///< \brief Method accepting EXT block
+
+ virtual ~VoidNoArguVisitor () { }
+};
+
+}
+}
+}
+
+#endif // _CCNB_PARSER_VOID_NO_ARGU_VISITOR_H_
diff --git a/disabled/ccnb-parser/visitors/void-visitor.h b/disabled/ccnb-parser/visitors/void-visitor.h
new file mode 100644
index 0000000..6ad7eed
--- /dev/null
+++ b/disabled/ccnb-parser/visitors/void-visitor.h
@@ -0,0 +1,56 @@
+/* -*- 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_VOID_VISITOR_H_
+#define _CCNB_PARSER_VOID_VISITOR_H_
+
+#include "../common.h"
+#include <boost/any.hpp>
+
+namespace ns3 {
+namespace ndn {
+namespace CcnbParser {
+
+/**
+ * \ingroup ndn-ccnb
+ * \brief Visitor interface that takes one boost::any argument and returns nothing
+ *
+ * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
+ * for ccnb encoding format help
+ */
+class VoidVisitor
+{
+public:
+ virtual void visit (Blob&, boost::any)=0; ///< \brief Method accepting BLOB block
+ virtual void visit (Udata&, boost::any)=0; ///< \brief Method accepting UDATA block
+ virtual void visit (Tag&, boost::any)=0; ///< \brief Method accepting TAG block
+ virtual void visit (Attr&, boost::any)=0; ///< \brief Method accepting ATTR block
+ virtual void visit (Dtag&, boost::any)=0; ///< \brief Method accepting DTAG block
+ virtual void visit (Dattr&, boost::any)=0; ///< \brief Method accepting DATTR block
+ virtual void visit (Ext&, boost::any)=0; ///< \brief Method accepting EXT block
+
+ virtual ~VoidVisitor () { }
+};
+
+}
+}
+}
+
+#endif // _CCNB_PARSER_VOID_VISITOR_H_
diff --git a/disabled/ndn-content-object-header-ccnb.cc b/disabled/ndn-content-object-header-ccnb.cc
new file mode 100644
index 0000000..c2611d8
--- /dev/null
+++ b/disabled/ndn-content-object-header-ccnb.cc
@@ -0,0 +1,555 @@
+/* -*- 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: Ilya Moiseenko <iliamo@cs.ucla.edu>
+ * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "ndn-content-object-header-ccnb.h"
+
+#include "ns3/log.h"
+#include "../helper/ndn-encoding-helper.h"
+#include "../helper/ndn-decoding-helper.h"
+
+#include "../helper/ccnb-parser/common.h"
+#include "../helper/ccnb-parser/visitors/void-depth-first-visitor.h"
+#include "../helper/ccnb-parser/visitors/name-components-visitor.h"
+#include "../helper/ccnb-parser/visitors/non-negative-integer-visitor.h"
+#include "../helper/ccnb-parser/visitors/timestamp-visitor.h"
+#include "../helper/ccnb-parser/visitors/string-visitor.h"
+#include "../helper/ccnb-parser/visitors/uint32t-blob-visitor.h"
+#include "../helper/ccnb-parser/visitors/content-type-visitor.h"
+
+#include "../helper/ccnb-parser/syntax-tree/block.h"
+#include "../helper/ccnb-parser/syntax-tree/dtag.h"
+
+#include <boost/foreach.hpp>
+
+NS_LOG_COMPONENT_DEFINE ("ndn.ContentObjectHeader");
+
+namespace ns3 {
+namespace ndn {
+
+using namespace CcnbParser;
+
+const std::string ContentObjectHeader::Signature::DefaultDigestAlgorithm = "2.16.840.1.101.3.4.2.1";
+
+NS_OBJECT_ENSURE_REGISTERED (ContentObjectHeader);
+NS_OBJECT_ENSURE_REGISTERED (ContentObjectTail);
+
+TypeId
+ContentObjectHeader::GetTypeId (void)
+{
+ static TypeId tid = TypeId ("ns3::ndn::ContentObjectHeader")
+ .SetGroupName ("Ndn")
+ .SetParent<Header> ()
+ .AddConstructor<ContentObjectHeader> ()
+ ;
+ return tid;
+}
+
+ContentObjectHeader::ContentObjectHeader ()
+{
+}
+
+void
+ContentObjectHeader::SetName (const Ptr<NameComponents> &name)
+{
+ m_name = name;
+}
+
+const NameComponents&
+ContentObjectHeader::GetName () const
+{
+ if (m_name==0) throw ContentObjectHeaderException();
+ return *m_name;
+}
+
+Ptr<const NameComponents>
+ContentObjectHeader::GetNamePtr () const
+{
+ return m_name;
+}
+
+#define CCNB EncodingHelper // just to simplify writing
+
+void
+ContentObjectHeader::Serialize (Buffer::Iterator start) const
+{
+ size_t written = 0;
+ written += CCNB::AppendBlockHeader (start, CCN_DTAG_ContentObject, CCN_DTAG); // <ContentObject>
+
+ // fake signature
+ written += CCNB::AppendBlockHeader (start, CCN_DTAG_Signature, CCN_DTAG); // <Signature>
+ // Signature ::= √DigestAlgorithm?
+ // Witness?
+ // √SignatureBits
+ if (GetSignature ().GetDigestAlgorithm () != Signature::DefaultDigestAlgorithm)
+ {
+ written += CCNB::AppendString (start, CCN_DTAG_DigestAlgorithm, GetSignature ().GetDigestAlgorithm ());
+ }
+ written += CCNB::AppendTaggedBlob (start, CCN_DTAG_SignatureBits, GetSignature ().GetSignatureBits ()); // <SignatureBits />
+ written += CCNB::AppendCloser (start); // </Signature>
+
+ written += CCNB::AppendBlockHeader (start, CCN_DTAG_Name, CCN_DTAG); // <Name>
+ written += CCNB::AppendNameComponents (start, GetName()); // <Component>...</Component>...
+ written += CCNB::AppendCloser (start); // </Name>
+
+ // fake signature
+ written += CCNB::AppendBlockHeader (start, CCN_DTAG_SignedInfo, CCN_DTAG); // <SignedInfo>
+ // SignedInfo ::= √PublisherPublicKeyDigest
+ // √Timestamp
+ // √Type?
+ // √FreshnessSeconds?
+ // FinalBlockID?
+ // KeyLocator?
+ written += CCNB::AppendTaggedBlob (start, CCN_DTAG_PublisherPublicKeyDigest, // <PublisherPublicKeyDigest>...
+ GetSignedInfo ().GetPublisherPublicKeyDigest ());
+
+ written += CCNB::AppendBlockHeader (start, CCN_DTAG_Timestamp, CCN_DTAG); // <Timestamp>...
+ written += CCNB::AppendTimestampBlob (start, GetSignedInfo ().GetTimestamp ());
+ written += CCNB::AppendCloser (start);
+
+ if (GetSignedInfo ().GetContentType () != DATA)
+ {
+ uint8_t type[3];
+ type[0] = (GetSignedInfo ().GetContentType () >> 16) & 0xFF;
+ type[1] = (GetSignedInfo ().GetContentType () >> 8 ) & 0xFF;
+ type[2] = (GetSignedInfo ().GetContentType () ) & 0xFF;
+
+ written += CCNB::AppendTaggedBlob (start, CCN_DTAG_Type, type, 3);
+ }
+ if (GetSignedInfo ().GetFreshness () > Seconds(0))
+ {
+ written += CCNB::AppendBlockHeader (start, CCN_DTAG_FreshnessSeconds, CCN_DTAG);
+ written += CCNB::AppendNumber (start, GetSignedInfo ().GetFreshness ().ToInteger (Time::S));
+ written += CCNB::AppendCloser (start);
+ }
+ if (GetSignedInfo ().GetKeyLocator () != 0)
+ {
+ written += CCNB::AppendBlockHeader (start, CCN_DTAG_KeyLocator, CCN_DTAG); // <KeyLocator>
+ {
+ written += CCNB::AppendBlockHeader (start, CCN_DTAG_KeyName, CCN_DTAG); // <KeyName>
+ {
+ written += CCNB::AppendBlockHeader (start, CCN_DTAG_Name, CCN_DTAG); // <Name>
+ written += CCNB::AppendNameComponents (start, GetName()); // <Component>...</Component>...
+ written += CCNB::AppendCloser (start); // </Name>
+ }
+ written += CCNB::AppendCloser (start); // </KeyName>
+ }
+ written += CCNB::AppendCloser (start); // </KeyLocator>
+ }
+
+ written += CCNB::AppendCloser (start); // </SignedInfo>
+
+ written += CCNB::AppendBlockHeader (start, CCN_DTAG_Content, CCN_DTAG); // <Content>
+
+ // there are no closing tags !!!
+ // The closing tag is handled by ContentObjectTail
+}
+
+uint32_t
+ContentObjectHeader::GetSerializedSize () const
+{
+ size_t written = 0;
+ written += CCNB::EstimateBlockHeader (CCN_DTAG_ContentObject); // <ContentObject>
+
+ // fake signature
+ written += CCNB::EstimateBlockHeader (CCN_DTAG_Signature); // <Signature>
+ // Signature ::= DigestAlgorithm?
+ // Witness?
+ // SignatureBits
+ if (GetSignature ().GetDigestAlgorithm () != Signature::DefaultDigestAlgorithm)
+ {
+ written += CCNB::EstimateString (CCN_DTAG_DigestAlgorithm, GetSignature ().GetDigestAlgorithm ());
+ }
+ written += CCNB::EstimateTaggedBlob (CCN_DTAG_SignatureBits,
+ sizeof (GetSignature ().GetSignatureBits ())); // <SignatureBits />
+ written += 1; // </Signature>
+
+ written += CCNB::EstimateBlockHeader (CCN_DTAG_Name); // <Name>
+ written += CCNB::EstimateNameComponents (GetName()); // <Component>...</Component>...
+ written += 1; // </Name>
+
+ // fake signature
+ written += CCNB::EstimateBlockHeader (CCN_DTAG_SignedInfo); // <SignedInfo>
+ // SignedInfo ::= √PublisherPublicKeyDigest
+ // √Timestamp
+ // √Type?
+ // √FreshnessSeconds?
+ // FinalBlockID?
+ // KeyLocator?
+
+ written += CCNB::EstimateTaggedBlob (CCN_DTAG_PublisherPublicKeyDigest, // <PublisherPublicKeyDigest>...
+ sizeof (GetSignedInfo ().GetPublisherPublicKeyDigest ()));
+
+ written += CCNB::EstimateBlockHeader (CCN_DTAG_Timestamp); // <Timestamp>...
+ written += CCNB::EstimateTimestampBlob (GetSignedInfo ().GetTimestamp ());
+ written += 1;
+
+ if (GetSignedInfo ().GetContentType () != DATA)
+ {
+ written += CCNB::EstimateTaggedBlob (CCN_DTAG_Type, 3);
+ }
+ if (GetSignedInfo ().GetFreshness () > Seconds(0))
+ {
+ written += CCNB::EstimateBlockHeader (CCN_DTAG_FreshnessSeconds);
+ written += CCNB::EstimateNumber (GetSignedInfo ().GetFreshness ().ToInteger (Time::S));
+ written += 1;
+ }
+
+ if (GetSignedInfo ().GetKeyLocator () != 0)
+ {
+ written += CCNB::EstimateBlockHeader (CCN_DTAG_KeyLocator); // <KeyLocator>
+ {
+ written += CCNB::EstimateBlockHeader (CCN_DTAG_KeyName); // <KeyName>
+ {
+ written += CCNB::EstimateBlockHeader (CCN_DTAG_Name); // <Name>
+ written += CCNB::EstimateNameComponents (GetName()); // <Component>...</Component>...
+ written += 1; // </Name>
+ }
+ written += 1; // </KeyName>
+ }
+ written += 1; // </KeyLocator>
+ }
+
+ written += 1; // </SignedInfo>
+
+ written += CCNB::EstimateBlockHeader (CCN_DTAG_Content); // <Content>
+
+ // there are no closing tags !!!
+ // The closing tag is handled by ContentObjectTail
+ return written;
+}
+#undef CCNB
+
+class ContentObjectVisitor : public VoidDepthFirstVisitor
+{
+public:
+ virtual void visit (Dtag &n, boost::any param/*should be ContentObjectHeader* */)
+ {
+ // uint32_t n.m_dtag;
+ // std::list<Ptr<Block> > n.m_nestedBlocks;
+ static NameComponentsVisitor nameComponentsVisitor;
+ static NonNegativeIntegerVisitor nonNegativeIntegerVisitor;
+ static TimestampVisitor timestampVisitor;
+ static StringVisitor stringVisitor;
+ static Uint32tBlobVisitor uint32tBlobVisitor;
+ static ContentTypeVisitor contentTypeVisitor;
+
+ ContentObjectHeader &contentObject = *(boost::any_cast<ContentObjectHeader*> (param));
+
+ switch (n.m_dtag)
+ {
+ case CCN_DTAG_ContentObject:
+ // process nested blocks
+ BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags)
+ {
+ block->accept (*this, param);
+ }
+ break;
+ case CCN_DTAG_Name:
+ {
+ // process name components
+ Ptr<NameComponents> name = Create<NameComponents> ();
+
+ BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags)
+ {
+ block->accept (nameComponentsVisitor, &(*name));
+ }
+ contentObject.SetName (name);
+ break;
+ }
+
+ case CCN_DTAG_Signature:
+ // process nested blocks
+ BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags)
+ {
+ block->accept (*this, param);
+ }
+ break;
+
+ case CCN_DTAG_DigestAlgorithm:
+ NS_LOG_DEBUG ("DigestAlgorithm");
+ if (n.m_nestedTags.size ()!=1) // should be exactly one UDATA inside this tag
+ throw CcnbDecodingException ();
+
+ contentObject.GetSignature ().SetDigestAlgorithm
+ (boost::any_cast<std::string> ((*n.m_nestedTags.begin())->accept
+ (stringVisitor)));
+ break;
+
+ case CCN_DTAG_SignatureBits:
+ NS_LOG_DEBUG ("SignatureBits");
+ if (n.m_nestedTags.size ()!=1) // should be only one nested tag
+ throw CcnbDecodingException ();
+
+ contentObject.GetSignature ().SetSignatureBits
+ (boost::any_cast<uint32_t> ((*n.m_nestedTags.begin())->accept
+ (uint32tBlobVisitor)));
+ break;
+
+ case CCN_DTAG_SignedInfo:
+ // process nested blocks
+ BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags)
+ {
+ block->accept (*this, param);
+ }
+ break;
+
+ case CCN_DTAG_PublisherPublicKeyDigest:
+ NS_LOG_DEBUG ("PublisherPublicKeyDigest");
+ if (n.m_nestedTags.size ()!=1) // should be only one nested tag
+ throw CcnbDecodingException ();
+
+ contentObject.GetSignedInfo ().SetPublisherPublicKeyDigest
+ (boost::any_cast<uint32_t> ((*n.m_nestedTags.begin())->accept
+ (uint32tBlobVisitor)));
+ break;
+
+ case CCN_DTAG_Timestamp:
+ NS_LOG_DEBUG ("Timestamp");
+ if (n.m_nestedTags.size()!=1) // should be exactly one nested tag
+ throw CcnbDecodingException ();
+
+ contentObject.GetSignedInfo ().SetTimestamp
+ (boost::any_cast<Time> ((*n.m_nestedTags.begin())->accept
+ (timestampVisitor)));
+ break;
+
+ case CCN_DTAG_Type:
+ NS_LOG_DEBUG ("Type");
+ if (n.m_nestedTags.size ()!=1) // should be only one nested tag
+ throw CcnbDecodingException ();
+
+ contentObject.GetSignedInfo ().SetContentType
+ (static_cast<ContentObjectHeader::ContentType>
+ (boost::any_cast<uint32_t> ((*n.m_nestedTags.begin())->accept
+ (contentTypeVisitor))));
+ break;
+
+ case CCN_DTAG_FreshnessSeconds:
+ NS_LOG_DEBUG ("FreshnessSeconds");
+
+ if (n.m_nestedTags.size()!=1) // should be exactly one nested tag
+ throw CcnbDecodingException ();
+
+ contentObject.GetSignedInfo ().SetFreshness
+ (Seconds
+ (boost::any_cast<uint32_t> ((*n.m_nestedTags.begin())->accept
+ (nonNegativeIntegerVisitor))));
+ break;
+
+ case CCN_DTAG_KeyLocator:
+ // process nested blocks
+ BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags)
+ {
+ block->accept (*this, param);
+ }
+ break;
+
+ case CCN_DTAG_KeyName:
+ {
+ if (n.m_nestedTags.size ()!=1) // should be exactly one nested tag
+ throw CcnbDecodingException ();
+
+ Ptr<BaseTag> nameTag = DynamicCast<BaseTag>(n.m_nestedTags.front ());
+ if (nameTag == 0)
+ throw CcnbDecodingException ();
+
+ // process name components
+ Ptr<NameComponents> name = Create<NameComponents> ();
+
+ BOOST_FOREACH (Ptr<Block> block, nameTag->m_nestedTags)
+ {
+ block->accept (nameComponentsVisitor, &(*name));
+ }
+ contentObject.GetSignedInfo ().SetKeyLocator (name);
+ break;
+ }
+
+ case CCN_DTAG_Content: // !!! HACK
+ // This hack was necessary for memory optimizations (i.e., content is virtual payload)
+ NS_ASSERT_MSG (n.m_nestedTags.size() == 0, "Parser should have stopped just after processing <Content> tag");
+ break;
+
+ default: // ignore all other stuff
+ break;
+ }
+ }
+};
+
+uint32_t
+ContentObjectHeader::Deserialize (Buffer::Iterator start)
+{
+ static ContentObjectVisitor contentObjectVisitor;
+
+ Buffer::Iterator i = start;
+ Ptr<Block> root = Block::ParseBlock (i);
+ root->accept (contentObjectVisitor, this);
+
+ return i.GetDistanceFrom (start);
+}
+
+TypeId
+ContentObjectHeader::GetInstanceTypeId (void) const
+{
+ return GetTypeId ();
+}
+
+void
+ContentObjectHeader::Print (std::ostream &os) const
+{
+ os << "D: " << GetName ();
+ // os << "<ContentObject><Name>" << GetName () << "</Name><Content>";
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+
+ContentObjectTail::ContentObjectTail ()
+{
+}
+
+TypeId
+ContentObjectTail::GetTypeId (void)
+{
+ static TypeId tid = TypeId ("ns3::ndn::ContentObjectTail")
+ .SetParent<Trailer> ()
+ .AddConstructor<ContentObjectTail> ()
+ ;
+ return tid;
+}
+
+TypeId
+ContentObjectTail::GetInstanceTypeId (void) const
+{
+ return GetTypeId ();
+}
+
+void
+ContentObjectTail::Print (std::ostream &os) const
+{
+ os << "</Content></ContentObject>";
+}
+
+uint32_t
+ContentObjectTail::GetSerializedSize (void) const
+{
+ return 2;
+}
+
+void
+ContentObjectTail::Serialize (Buffer::Iterator start) const
+{
+ Buffer::Iterator i = start;
+ i.Prev (2); // Trailer interface requires us to go backwards
+
+ i.WriteU8 (0x00); // </Content>
+ i.WriteU8 (0x00); // </ContentObject>
+}
+
+uint32_t
+ContentObjectTail::Deserialize (Buffer::Iterator start)
+{
+ Buffer::Iterator i = start;
+ i.Prev (2); // Trailer interface requires us to go backwards
+
+ uint8_t closing_tag_content = i.ReadU8 ();
+ NS_ASSERT_MSG (closing_tag_content==0, "Should be a closing tag </Content> (0x00)");
+
+ uint8_t closing_tag_content_object = i.ReadU8 ();
+ NS_ASSERT_MSG (closing_tag_content_object==0, "Should be a closing tag </ContentObject> (0x00)");
+
+ return 2;
+}
+
+///////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////
+
+ContentObjectHeader::SignedInfo::SignedInfo ()
+ : m_publisherPublicKeyDigest (0)
+ // , m_timestamp
+ , m_type (DATA)
+ // , m_freshness
+ // , FinalBlockID
+ // , KeyLocator
+{
+}
+
+void
+ContentObjectHeader::SignedInfo::SetPublisherPublicKeyDigest (uint32_t digest)
+{
+ m_publisherPublicKeyDigest = digest;
+}
+
+uint32_t
+ContentObjectHeader::SignedInfo::GetPublisherPublicKeyDigest () const
+{
+ return m_publisherPublicKeyDigest;
+}
+
+void
+ContentObjectHeader::SignedInfo::SetTimestamp (const Time ×tamp)
+{
+ m_timestamp = timestamp;
+}
+
+Time
+ContentObjectHeader::SignedInfo::GetTimestamp () const
+{
+ return m_timestamp;
+}
+
+void
+ContentObjectHeader::SignedInfo::SetContentType (ContentObjectHeader::ContentType type)
+{
+ m_type = type;
+}
+
+ContentObjectHeader::ContentType
+ContentObjectHeader::SignedInfo::GetContentType () const
+{
+ return m_type;
+}
+
+void
+ContentObjectHeader::SignedInfo::SetFreshness (const Time &freshness)
+{
+ m_freshness = freshness;
+}
+
+Time
+ContentObjectHeader::SignedInfo::GetFreshness () const
+{
+ return m_freshness;
+}
+
+void
+ContentObjectHeader::SignedInfo::SetKeyLocator (Ptr<const NameComponents> keyLocator)
+{
+ m_keyLocator = keyLocator;
+}
+
+Ptr<const NameComponents>
+ContentObjectHeader::SignedInfo::GetKeyLocator () const
+{
+ return m_keyLocator;
+}
+
+} // namespace ndn
+} // namespace ns3
diff --git a/disabled/ndn-content-object-header-ccnb.h b/disabled/ndn-content-object-header-ccnb.h
new file mode 100644
index 0000000..f19dbbe
--- /dev/null
+++ b/disabled/ndn-content-object-header-ccnb.h
@@ -0,0 +1,373 @@
+/* -*- 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: Ilya Moiseenko <iliamo@cs.ucla.edu>
+ * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef _NDN_CONTENT_OBJECT_HEADER_CCNB_H_
+#define _NDN_CONTENT_OBJECT_HEADER_CCNB_H_
+
+#include "ns3/integer.h"
+#include "ns3/header.h"
+#include "ns3/simple-ref-count.h"
+#include "ns3/trailer.h"
+#include "ns3/nstime.h"
+
+#include <string>
+#include <vector>
+#include <list>
+
+#include "ndn-name-components.h"
+
+namespace ns3 {
+namespace ndn {
+
+/**
+ * Ndn XML definition of ContentObject
+ *
+ * Only few important fields are actually implemented in the simulation
+ *
+ *
+ * ContentObjectHeader serializes/deserializes header up-to and including <Content> tags
+ * Necessary closing tags should be added using ContentObjectTail
+ *
+ * This hacks are necessary to optimize memory use (i.e., virtual payload)
+ *
+ * "<ContentObject><Signature>..</Signature><Name>...</Name><SignedInfo>...</SignedInfo><Content>"
+ *
+ */
+class ContentObjectHeader : public SimpleRefCount<ContentObjectHeader,Header>
+{
+public:
+ ////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////
+ /**
+ * @brief Class representing Signature section of the content object
+ */
+ class Signature
+ {
+ public:
+ /**
+ * @brief Default constructor. Creates a fake-type signature
+ */
+ inline Signature ();
+
+ /**
+ * @brief Get digest algorithm
+ */
+ inline const std::string &
+ GetDigestAlgorithm () const;
+
+ /**
+ * @brief Set digest algorithm
+ */
+ inline void
+ SetDigestAlgorithm (const std::string &digestAlgorithm);
+
+ /**
+ * @brief Get signature bits
+ */
+ inline uint32_t
+ GetSignatureBits () const;
+
+ /**
+ * @brief Set signature bits
+ */
+ inline void
+ SetSignatureBits (uint32_t signatureBits);
+
+ /**
+ * @brief Default digest algorithm ("2.16.840.1.101.3.4.2.1")
+ */
+ static const std::string DefaultDigestAlgorithm; // = "2.16.840.1.101.3.4.2.1";
+
+ private:
+ std::string m_digestAlgorithm; // if value is `2.16.840.1.101.3.4.2.1`, then SHA-256 (not supported)
+ // in NS-3 value `99.0` represents a fake digest
+ // Witness // not used in NS-3
+ uint32_t m_signatureBits; // in NS-3 a fake signature is a just 32-bits
+ };
+
+ ////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////
+
+ /**
+ * @brief Options for the data packet Type
+ */
+ enum ContentType
+ {
+ DATA = 0x0C04C0, // default value. If ContentObject is type of DATA, then ContentType tag will be omitted
+ ENCR = 0x10D091,
+ GONE = 0x18E344,
+ KEY = 0x28463F,
+ LINK = 0x2C834A,
+ NACK = 0x34008A
+ };
+
+ ////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////
+
+ /**
+ * @brief Class representing SignedInfo section of the content object
+ */
+ class SignedInfo
+ {
+ public:
+ /**
+ * @brief Default constructor
+ */
+ SignedInfo ();
+
+ /**
+ * @brief Set PublisherPublicKey digest
+ * @param digest a fake 32-bit digest is supported
+ */
+ void
+ SetPublisherPublicKeyDigest (uint32_t digest);
+
+ /**
+ * @brief Get PublisherPublicKey digest
+ */
+ uint32_t
+ GetPublisherPublicKeyDigest () const;
+
+ /**
+ * @brief Set content object timestamp
+ * @param timestamp timestamp
+ */
+ void
+ SetTimestamp (const Time ×tamp);
+
+ /**
+ * @brief Get timestamp of the content object
+ */
+ Time
+ GetTimestamp () const;
+
+ /**
+ * @brief Set ContentObject type
+ * @param type type of the content object
+ */
+ void
+ SetContentType (ContentType type);
+
+ /**
+ * @brief Get ContentObject type
+ */
+ ContentType
+ GetContentType () const;
+
+ /**
+ * @brief Set freshness of the content object
+ * @param freshness Freshness, 0s means infinity
+ */
+ void
+ SetFreshness (const Time &freshness);
+
+ /**
+ * @brief Get freshness of the content object
+ */
+ Time
+ GetFreshness () const;
+
+ /**
+ * @brief Set key locator
+ * @param keyLocator name of the key
+ *
+ * Note that only <KeyName> option for the key locator is supported
+ */
+ void
+ SetKeyLocator (Ptr<const NameComponents> keyLocator);
+
+ /**
+ * @brief Get key locator
+ *
+ * Note that only <KeyName> option for the key locator is supported
+ */
+ Ptr<const NameComponents>
+ GetKeyLocator () const;
+
+ private:
+ uint32_t m_publisherPublicKeyDigest; // fake publisher key digest
+ Time m_timestamp;
+ ContentType m_type;
+ Time m_freshness;
+ // FinalBlockID
+ Ptr<const NameComponents> m_keyLocator; // support only <KeyName> option for KeyLocator
+ };
+
+ ////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////
+
+ /**
+ * Constructor
+ *
+ * Creates a null header
+ **/
+ ContentObjectHeader ();
+
+ /**
+ * \brief Set content object name
+ *
+ * Sets name of the content object. For example, SetName( NameComponents("prefix")("postfix") );
+ **/
+ void
+ SetName (const Ptr<NameComponents> &name);
+
+ /**
+ * @brief Get name of the content object
+ */
+ const NameComponents&
+ GetName () const;
+
+ /**
+ * @brief Get smart pointer to the interest name (to avoid extra memory usage)
+ */
+ Ptr<const NameComponents>
+ GetNamePtr () const;
+
+ /**
+ * @brief Get editable reference to content object's Signature
+ */
+ inline Signature &
+ GetSignature ();
+
+ /**
+ * @brief Get read-only reference to content object's Signature
+ */
+ inline const Signature &
+ GetSignature () const;
+
+ /**
+ * @brief Get editable reference to content object's SignedInfo
+ */
+ inline SignedInfo &
+ GetSignedInfo ();
+
+ /**
+ * @brief Get read-only reference to content object's SignedInfo
+ */
+ inline const SignedInfo &
+ GetSignedInfo () const;
+
+ //////////////////////////////////////////////////////////////////
+
+ static TypeId GetTypeId (void); ///< @brief Get TypeId
+ virtual TypeId GetInstanceTypeId (void) const; ///< @brief Get TypeId of the instance
+ virtual void Print (std::ostream &os) const; ///< @brief Print out information about the Header into the stream
+ virtual uint32_t GetSerializedSize (void) const; ///< @brief Get size necessary to serialize the Header
+ virtual void Serialize (Buffer::Iterator start) const; ///< @brief Serialize the Header
+ virtual uint32_t Deserialize (Buffer::Iterator start); ///< @brief Deserialize the Header
+
+private:
+ Signature m_signature;
+ Ptr<NameComponents> m_name;
+ SignedInfo m_signedInfo;
+};
+
+/**
+ * ContentObjectTail should always be 2 bytes, representing two closing tags:
+ * "</Content><ContentObject>"
+ */
+class ContentObjectTail : public Trailer
+{
+public:
+ ContentObjectTail ();
+ //////////////////////////////////////////////////////////////////
+
+ static TypeId GetTypeId (void); ///< @brief Get TypeId
+ virtual TypeId GetInstanceTypeId (void) const; ///< @brief Get TypeId of the instance
+ virtual void Print (std::ostream &os) const; ///< @brief Print out information about Tail into the stream
+ virtual uint32_t GetSerializedSize (void) const; ///< @brief Get size necessary to serialize the Tail
+ virtual void Serialize (Buffer::Iterator start) const; ///< @brief Serialize the Tail
+ virtual uint32_t Deserialize (Buffer::Iterator start); ///< @brief Deserialize the Tail
+};
+
+
+ContentObjectHeader::Signature::Signature ()
+ : m_digestAlgorithm ("99.0")
+ , m_signatureBits (0)
+{
+}
+
+const std::string &
+ContentObjectHeader::Signature::GetDigestAlgorithm () const
+{
+ return m_digestAlgorithm;
+}
+
+void
+ContentObjectHeader::Signature::SetDigestAlgorithm (const std::string &digestAlgorithm)
+{
+ m_digestAlgorithm = digestAlgorithm;
+}
+
+uint32_t
+ContentObjectHeader::Signature::GetSignatureBits () const
+{
+ return m_signatureBits;
+}
+
+inline void
+ContentObjectHeader::Signature::SetSignatureBits (uint32_t signature)
+{
+ m_signatureBits = signature;
+}
+
+
+ContentObjectHeader::Signature &
+ContentObjectHeader::GetSignature ()
+{
+ return m_signature;
+}
+
+const ContentObjectHeader::Signature &
+ContentObjectHeader::GetSignature () const
+{
+ return m_signature;
+}
+
+ContentObjectHeader::SignedInfo &
+ContentObjectHeader::GetSignedInfo ()
+{
+ return m_signedInfo;
+}
+
+const ContentObjectHeader::SignedInfo &
+ContentObjectHeader::GetSignedInfo () const
+{
+ return m_signedInfo;
+}
+
+/**
+ * @ingroup ndn-exceptions
+ * @brief Class for ContentObject parsing exception
+ */
+class ContentObjectHeaderException {};
+
+} // namespace ndn
+} // namespace ns3
+
+#endif // _NDN_CONTENT_OBJECT_HEADER_CCNB_H_
diff --git a/disabled/ndn-decoding-helper.cc b/disabled/ndn-decoding-helper.cc
new file mode 100644
index 0000000..89936c1
--- /dev/null
+++ b/disabled/ndn-decoding-helper.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 "ndn-decoding-helper.h"
+
+#include "ns3/ndn-interest-header.h"
+
+#include "ccnb-parser/visitors/interest-visitor.h"
+
+#include "ccnb-parser/syntax-tree/block.h"
+#include "ccnb-parser/syntax-tree/dtag.h"
+
+#include "ns3/log.h"
+
+NS_LOG_COMPONENT_DEFINE ("ndn.DecodingHelper");
+
+namespace ns3 {
+namespace ndn {
+
+size_t
+DecodingHelper::Deserialize (Buffer::Iterator start, InterestHeader &interest)
+{
+ static CcnbParser::InterestVisitor interestVisitor;
+
+ Buffer::Iterator i = start;
+ Ptr<CcnbParser::Block> root = CcnbParser::Block::ParseBlock (i);
+ root->accept (interestVisitor, &interest);
+
+ return i.GetDistanceFrom (start);
+}
+
+// size_t
+// NdnDecodingHelper::Deserialize (Buffer::Iterator start, NdnContentObjectHeader &contentObject)
+// {
+// static CcnbParser::ContentObjectVisitor contentObjectVisitor;
+
+// Buffer::Iterator i = start;
+// Ptr<CcnbParser::Block> root = CcnbParser::Block::ParseBlock (i);
+// root->accept (contentObjectVisitor, &contentObject);
+
+// return i.GetDistanceFrom (start);
+// }
+
+} // namespace ndn
+} // namespace ns3
diff --git a/disabled/ndn-decoding-helper.h b/disabled/ndn-decoding-helper.h
new file mode 100644
index 0000000..9e1f5ef
--- /dev/null
+++ b/disabled/ndn-decoding-helper.h
@@ -0,0 +1,61 @@
+/* -*- 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 _NDN_DECODING_HELPER_H_
+#define _NDN_DECODING_HELPER_H_
+
+#include <cstring>
+#include "ns3/buffer.h"
+
+namespace ns3 {
+namespace ndn {
+
+class InterestHeader;
+class ContentObjectHeader;
+
+/**
+ * \brief Helper class to decode ccnb formatted Ndn message
+ */
+class DecodingHelper
+{
+public:
+ /**
+ * \brief Deserialize Buffer::Iterator to NdnInterestHeader
+ * @param start Buffer containing serialized Ndn message
+ * @param interest Pointer to the NdnInterestHeader to hold deserialized value
+ * @return Number of bytes used for deserialization
+ */
+ static size_t
+ Deserialize (Buffer::Iterator start, InterestHeader &interest);
+
+ /**
+ * \brief Deserialize Buffer::Iterator to NdnContentObjectHeader
+ * @param start Buffer containing serialized Ndn message
+ * @param contentObject Pointer to the NdnContentObjectHeader to hold deserialized value
+ * @return Number of bytes used for deserialization
+ */
+ // static size_t
+ // Deserialize (Buffer::Iterator start, ContentObjectHeader &contentObject);
+};
+
+} // namespace ndn
+} // namespace ns3
+
+#endif // _NDN_DECODING_HELPER_H_
diff --git a/disabled/ndn-encoding-helper.cc b/disabled/ndn-encoding-helper.cc
new file mode 100644
index 0000000..c9292ab
--- /dev/null
+++ b/disabled/ndn-encoding-helper.cc
@@ -0,0 +1,352 @@
+/* -*- 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 "ndn-encoding-helper.h"
+
+#include "ns3/ndn-name-components.h"
+#include "ns3/ndn-interest-header.h"
+#include "ns3/ndn-content-object-header.h"
+
+#include <sstream>
+#include <boost/foreach.hpp>
+
+namespace ns3 {
+namespace ndn {
+
+size_t
+EncodingHelper::Serialize (Buffer::Iterator start, const InterestHeader &interest)
+{
+ size_t written = 0;
+ written += AppendBlockHeader (start, CcnbParser::CCN_DTAG_Interest, CcnbParser::CCN_DTAG); // <Interest>
+
+ written += AppendBlockHeader (start, CcnbParser::CCN_DTAG_Name, CcnbParser::CCN_DTAG); // <Name>
+ written += AppendNameComponents (start, interest.GetName()); // <Component>...</Component>...
+ written += AppendCloser (start); // </Name>
+
+ if (interest.GetMinSuffixComponents() >= 0)
+ {
+ written += AppendBlockHeader (start, CcnbParser::CCN_DTAG_MinSuffixComponents, CcnbParser::CCN_DTAG);
+ written += AppendNumber (start, interest.GetMinSuffixComponents ());
+ written += AppendCloser (start);
+ }
+ if (interest.GetMaxSuffixComponents() >= 0)
+ {
+ written += AppendBlockHeader (start, CcnbParser::CCN_DTAG_MaxSuffixComponents, CcnbParser::CCN_DTAG);
+ written += AppendNumber (start, interest.GetMaxSuffixComponents ());
+ written += AppendCloser (start);
+ }
+ if (interest.IsEnabledExclude() && interest.GetExclude().size() > 0)
+ {
+ written += AppendBlockHeader (start, CcnbParser::CCN_DTAG_Exclude, CcnbParser::CCN_DTAG); // <Exclude>
+ written += AppendNameComponents (start, interest.GetExclude()); // <Component>...</Component>...
+ written += AppendCloser (start); // </Exclude>
+ }
+ if (interest.IsEnabledChildSelector())
+ {
+ written += AppendBlockHeader (start, CcnbParser::CCN_DTAG_ChildSelector, CcnbParser::CCN_DTAG);
+ written += AppendNumber (start, 1);
+ written += AppendCloser (start);
+ }
+ if (interest.IsEnabledAnswerOriginKind())
+ {
+ written += AppendBlockHeader (start, CcnbParser::CCN_DTAG_AnswerOriginKind, CcnbParser::CCN_DTAG);
+ written += AppendNumber (start, 1);
+ written += AppendCloser (start);
+ }
+ if (interest.GetScope() >= 0)
+ {
+ written += AppendBlockHeader (start, CcnbParser::CCN_DTAG_Scope, CcnbParser::CCN_DTAG);
+ written += AppendNumber (start, interest.GetScope ());
+ written += AppendCloser (start);
+ }
+ if (!interest.GetInterestLifetime().IsZero())
+ {
+ written += AppendBlockHeader (start, CcnbParser::CCN_DTAG_InterestLifetime, CcnbParser::CCN_DTAG);
+ written += AppendTimestampBlob (start, interest.GetInterestLifetime ());
+ written += AppendCloser (start);
+ }
+ if (interest.GetNonce()>0)
+ {
+ uint32_t nonce = interest.GetNonce();
+ written += AppendTaggedBlob (start, CcnbParser::CCN_DTAG_Nonce, nonce);
+ }
+
+ if (interest.GetNack ()>0)
+ {
+ written += AppendBlockHeader (start, CcnbParser::CCN_DTAG_Nack, CcnbParser::CCN_DTAG);
+ written += AppendNumber (start, interest.GetNack ());
+ written += AppendCloser (start);
+ }
+ written += AppendCloser (start); // </Interest>
+
+ return written;
+}
+
+size_t
+EncodingHelper::GetSerializedSize (const InterestHeader &interest)
+{
+ size_t written = 0;
+ written += EstimateBlockHeader (CcnbParser::CCN_DTAG_Interest); // <Interest>
+
+ written += EstimateBlockHeader (CcnbParser::CCN_DTAG_Name); // <Name>
+ written += EstimateNameComponents (interest.GetName()); // <Component>...</Component>...
+ written += 1; // </Name>
+
+ if (interest.GetMinSuffixComponents() >= 0)
+ {
+ written += EstimateBlockHeader (CcnbParser::CCN_DTAG_MinSuffixComponents);
+ written += EstimateNumber (interest.GetMinSuffixComponents ());
+ written += 1;
+ }
+ if (interest.GetMaxSuffixComponents() >= 0)
+ {
+ written += EstimateBlockHeader (CcnbParser::CCN_DTAG_MaxSuffixComponents);
+ written += EstimateNumber (interest.GetMaxSuffixComponents ());
+ written += 1;
+ }
+ if (interest.IsEnabledExclude() && interest.GetExclude().size() > 0)
+ {
+ written += EstimateBlockHeader (CcnbParser::CCN_DTAG_Exclude);
+ written += EstimateNameComponents (interest.GetExclude()); // <Component>...</Component>...
+ written += 1; // </Exclude>
+ }
+ if (interest.IsEnabledChildSelector())
+ {
+ written += EstimateBlockHeader (CcnbParser::CCN_DTAG_ChildSelector);
+ written += EstimateNumber (1);
+ written += 1;
+ }
+ if (interest.IsEnabledAnswerOriginKind())
+ {
+ written += EstimateBlockHeader (CcnbParser::CCN_DTAG_AnswerOriginKind);
+ written += EstimateNumber (1);
+ written += 1;
+ }
+ if (interest.GetScope() >= 0)
+ {
+ written += EstimateBlockHeader (CcnbParser::CCN_DTAG_Scope);
+ written += EstimateNumber (interest.GetScope ());
+ written += 1;
+ }
+ if (!interest.GetInterestLifetime().IsZero())
+ {
+ written += EstimateBlockHeader (CcnbParser::CCN_DTAG_InterestLifetime);
+ written += EstimateTimestampBlob (interest.GetInterestLifetime());
+ written += 1;
+ }
+ if (interest.GetNonce()>0)
+ {
+ written += EstimateTaggedBlob (CcnbParser::CCN_DTAG_Nonce, sizeof(uint32_t));
+ }
+ if (interest.GetNack ()>0)
+ {
+ written += EstimateBlockHeader (CcnbParser::CCN_DTAG_Nack);
+ written += EstimateNumber (interest.GetNack ());
+ written += 1;
+ }
+
+ written += 1; // </Interest>
+
+ return written;
+}
+
+//////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////
+
+#define CCN_TT_BITS 3
+#define CCN_TT_MASK ((1 << CCN_TT_BITS) - 1)
+#define CCN_MAX_TINY ((1 << (7-CCN_TT_BITS)) - 1)
+#define CCN_TT_HBIT ((unsigned char)(1 << 7))
+
+size_t
+EncodingHelper::AppendBlockHeader (Buffer::Iterator &start, size_t val, CcnbParser::ccn_tt tt)
+{
+ unsigned char buf[1+8*((sizeof(val)+6)/7)];
+ unsigned char *p = &(buf[sizeof(buf)-1]);
+ size_t n = 1;
+ p[0] = (CCN_TT_HBIT & ~CcnbParser::CCN_CLOSE) |
+ ((val & CCN_MAX_TINY) << CCN_TT_BITS) |
+ (CCN_TT_MASK & tt);
+ val >>= (7-CCN_TT_BITS);
+ while (val != 0) {
+ (--p)[0] = (((unsigned char)val) & ~CCN_TT_HBIT) | CcnbParser::CCN_CLOSE;
+ n++;
+ val >>= 7;
+ }
+ start.Write (p,n);
+ return n;
+}
+
+size_t
+EncodingHelper::EstimateBlockHeader (size_t value)
+{
+ value >>= (7-CCN_TT_BITS);
+ size_t n = 1;
+ while (value>0)
+ {
+ value >>= 7;
+ n++;
+ }
+ return n;
+}
+
+size_t
+EncodingHelper::AppendNumber (Buffer::Iterator &start, uint32_t number)
+{
+ std::ostringstream os;
+ os << number;
+
+ size_t written = 0;
+ written += AppendBlockHeader (start, os.str().size(), CcnbParser::CCN_UDATA);
+ written += os.str().size();
+ start.Write (reinterpret_cast<const unsigned char*>(os.str().c_str()), os.str().size());
+
+ return written;
+}
+
+size_t
+EncodingHelper::EstimateNumber (uint32_t number)
+{
+ std::ostringstream os;
+ os << number;
+ return EstimateBlockHeader (os.str ().size ()) + os.str ().size ();
+}
+
+size_t
+EncodingHelper::AppendCloser (Buffer::Iterator &start)
+{
+ start.WriteU8 (CcnbParser::CCN_CLOSE);
+ return 1;
+}
+
+size_t
+EncodingHelper::AppendNameComponents (Buffer::Iterator &start, const NameComponents &name)
+{
+ size_t written = 0;
+ BOOST_FOREACH (const std::string &component, name.GetComponents())
+ {
+ written += AppendTaggedBlob (start, CcnbParser::CCN_DTAG_Component,
+ reinterpret_cast<const uint8_t*>(component.c_str()), component.size());
+ }
+ return written;
+}
+
+size_t
+EncodingHelper::EstimateNameComponents (const NameComponents &name)
+{
+ size_t written = 0;
+ BOOST_FOREACH (const std::string &component, name.GetComponents())
+ {
+ written += EstimateTaggedBlob (CcnbParser::CCN_DTAG_Component, component.size());
+ }
+ return written;
+}
+
+size_t
+EncodingHelper::AppendTimestampBlob (Buffer::Iterator &start, const Time &time)
+{
+ // the original function implements Markers... thought not sure what are these markers for...
+
+ // Determine miminal number of bytes required to store the timestamp
+ int required_bytes = 2; // 12 bits for fractions of a second, 4 bits left for seconds. Sometimes it is enough
+ intmax_t ts = time.ToInteger (Time::S) >> 4;
+ for (; required_bytes < 7 && ts != 0; ts >>= 8) // not more than 6 bytes?
+ required_bytes++;
+
+ size_t len = AppendBlockHeader(start, required_bytes, CcnbParser::CCN_BLOB);
+
+ // write part with seconds
+ ts = time.ToInteger (Time::S) >> 4;
+ for (int i = 0; i < required_bytes - 2; i++)
+ start.WriteU8 ( ts >> (8 * (required_bytes - 3 - i)) );
+
+ /* arithmetic contortions are to avoid overflowing 31 bits */
+ ts = ((time.ToInteger (Time::S) & 15) << 12) +
+ (((time.ToInteger (Time::NS) % 1000000000) / 5 * 8 + 195312) / 390625);
+ for (int i = required_bytes - 2; i < required_bytes; i++)
+ start.WriteU8 ( ts >> (8 * (required_bytes - 1 - i)) );
+
+ return len + required_bytes;
+}
+
+size_t
+EncodingHelper::EstimateTimestampBlob (const Time &time)
+{
+ int required_bytes = 2; // 12 bits for fractions of a second, 4 bits left for seconds. Sometimes it is enough
+ intmax_t ts = time.ToInteger (Time::S) >> 4;
+ for (; required_bytes < 7 && ts != 0; ts >>= 8) // not more than 6 bytes?
+ required_bytes++;
+
+ return EstimateBlockHeader (required_bytes) + required_bytes;
+}
+
+size_t
+EncodingHelper::AppendTaggedBlob (Buffer::Iterator &start, CcnbParser::ccn_dtag dtag,
+ const uint8_t *data, size_t size)
+{
+ size_t written = AppendBlockHeader (start, dtag, CcnbParser::CCN_DTAG);
+ /* 2 */
+ if (size>0)
+ {
+ written += AppendBlockHeader (start, size, CcnbParser::CCN_BLOB);
+ start.Write (data, size);
+ written += size;
+ /* size */
+ }
+ written += AppendCloser (start);
+ /* 1 */
+
+ return written;
+}
+
+size_t
+EncodingHelper::EstimateTaggedBlob (CcnbParser::ccn_dtag dtag, size_t size)
+{
+ if (size>0)
+ return EstimateBlockHeader (dtag) + EstimateBlockHeader (size) + size + 1;
+ else
+ return EstimateBlockHeader (dtag) + 1;
+}
+
+size_t
+EncodingHelper::AppendString (Buffer::Iterator &start, CcnbParser::ccn_dtag dtag,
+ const std::string &string)
+{
+ size_t written = AppendBlockHeader (start, dtag, CcnbParser::CCN_DTAG);
+ {
+ written += AppendBlockHeader (start, string.size (), CcnbParser::CCN_UDATA);
+ start.Write (reinterpret_cast<const uint8_t*> (string.c_str ()), string.size ());
+ written += string.size ();
+ }
+ written += AppendCloser (start);
+
+ return written;
+}
+
+size_t
+EncodingHelper::EstimateString (CcnbParser::ccn_dtag dtag, const std::string &string)
+{
+ return EstimateBlockHeader (dtag) + EstimateBlockHeader (string.size ()) + string.size () + 1;
+}
+
+
+} // namespace ndn
+} // namespace ns3
diff --git a/disabled/ndn-encoding-helper.h b/disabled/ndn-encoding-helper.h
new file mode 100644
index 0000000..66796c3
--- /dev/null
+++ b/disabled/ndn-encoding-helper.h
@@ -0,0 +1,226 @@
+/* -*- 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 _NDN_ENCODING_HELPER_H_
+#define _NDN_ENCODING_HELPER_H_
+
+#include <sys/types.h>
+
+#include "ccnb-parser/common.h"
+#include "ns3/ptr.h"
+#include "ns3/nstime.h"
+#include "ns3/buffer.h"
+
+namespace ns3 {
+namespace ndn {
+
+class NameComponents;
+
+class InterestHeader;
+class ContentObjectHeader;
+
+/**
+ * \brief Helper to encode/decode ccnb formatted Ndn message
+ */
+class EncodingHelper
+{
+public:
+ /**
+ * \brief Serialize NdnInterestHeader to Buffer::Iterator
+ * @param start Buffer to store serialized NdnInterestHeader
+ * @param interest Pointer to NdnInterestHeader to be serialized
+ * @return length of serialized NdnInterestHeader
+ */
+ static size_t
+ Serialize (Buffer::Iterator start, const InterestHeader &interest);
+
+ /**
+ * \brief Compute the size of serialized NdnInterestHeader
+ * @param interest Pointer to NdnInterestHeader
+ * @return length
+ */
+ static size_t
+ GetSerializedSize (const InterestHeader &interest);
+
+public:
+ /**
+ * @brief Append CCNB block header
+ * @param start Buffer to store serialized NdnInterestHeader
+ * @param value dictionary id of the block header
+ * @param block_type Type of CCNB block
+ *
+ * @returns written length
+ */
+ static size_t
+ AppendBlockHeader (Buffer::Iterator &start, size_t value, CcnbParser::ccn_tt block_type);
+
+ /**
+ * @brief Estimate size of the CCNB block header
+ * @param value dictionary id of the block header
+ * @returns estimated length
+ */
+ static size_t
+ EstimateBlockHeader (size_t value);
+
+ /**
+ * @brief Add number in CCNB encoding
+ * @param start Buffer to store serialized NdnInterestHeader
+ * @param number Number to be written
+ *
+ * @returns written length
+ */
+ static size_t
+ AppendNumber (Buffer::Iterator &start, uint32_t number);
+
+ /**
+ * @brief Estimate size of the number in CCNB encoding
+ * @param number Number to be written
+ * @returns estimated length
+ */
+ static size_t
+ EstimateNumber (uint32_t number);
+
+ /**
+ * @brief Append CCNB closer tag (estimated size is 1)
+ * @param start Buffer to store serialized InterestHeader
+ *
+ * @returns written length
+ */
+ static size_t
+ AppendCloser (Buffer::Iterator &start);
+
+ /**
+ * @brief Append NameComponents in CCNB encoding
+ * @param start Buffer to store serialized InterestHeader
+ * @param name constant reference to NameComponents object
+ *
+ * @returns written length
+ */
+ static size_t
+ AppendNameComponents (Buffer::Iterator &start, const NameComponents &name);
+
+ /**
+ * @brief Estimate size of NameComponents in CCNB encoding
+ * @param name constant reference to NameComponents object
+ * @returns estimated length
+ */
+ static size_t
+ EstimateNameComponents (const NameComponents &name);
+
+ /**
+ * Append a binary timestamp as a BLOB using the ccn binary
+ * Timestamp representation (12-bit fraction).
+ *
+ * @param start start iterator of the buffer to append to.
+ * @param time - Time object
+ *
+ * @returns written length
+ */
+ static size_t
+ AppendTimestampBlob (Buffer::Iterator &start, const Time &time);
+
+ /**
+ * @brief Estimate size of a binary timestamp as a BLOB using CCNB enconding
+ * @param time - Time object
+ * @returns estimated length
+ */
+ static size_t
+ EstimateTimestampBlob (const Time &time);
+
+ /**
+ * Append a tagged BLOB
+ *
+ * This is a ccnb-encoded element with containing the BLOB as content
+ *
+ * @param start start iterator of the buffer to append to.
+ * @param dtag is the element's dtab
+ * @param data points to the binary data
+ * @param size is the size of the data, in bytes
+ *
+ * @returns written length
+ */
+ static size_t
+ AppendTaggedBlob (Buffer::Iterator &start, CcnbParser::ccn_dtag dtag,
+ const uint8_t *data, size_t size);
+
+ /**
+ * @brief Estimate size of a tagged BLOB in CCNB enconding
+ * @param dtag is the element's dtab
+ * @param size is the size of the data, in bytes
+ * @returns estimated length
+ */
+ static size_t
+ EstimateTaggedBlob (CcnbParser::ccn_dtag dtag, size_t size);
+
+ /**
+ * Append value as a tagged BLOB (templated version)
+ *
+ * This is a ccnb-encoded element with containing the BLOB as content
+ *
+ * Data will be reinterpret_cast<const uint8_t*> and size will be obtained using sizeof
+ *
+ * @param start start iterator of the buffer to append to.
+ * @param dtag is the element's dtab
+ * @param data a value to add
+ *
+ * @returns written length
+ */
+ template<class T>
+ static inline size_t
+ AppendTaggedBlob (Buffer::Iterator &start, CcnbParser::ccn_dtag dtag, const T &data);
+
+ /**
+ * Append a tagged string (should be a valid UTF-8 coded string)
+ *
+ * This is a ccnb-encoded element with containing UDATA as content
+ *
+ * @param start start iterator of the buffer to append to.
+ * @param dtag is the element's dtab
+ * @param string UTF-8 string to be written
+ *
+ * @returns written length
+ */
+ static size_t
+ AppendString (Buffer::Iterator &start, CcnbParser::ccn_dtag dtag,
+ const std::string &string);
+
+ /**
+ * @brief Estimate size of the string in CCNB encoding
+ * @param dtag is the element's dtab
+ * @param string UTF-8 string to be written
+ * @returns estimated length
+ */
+ static size_t
+ EstimateString (CcnbParser::ccn_dtag dtag, const std::string &string);
+};
+
+
+template<class T>
+size_t
+EncodingHelper::AppendTaggedBlob (Buffer::Iterator &start, CcnbParser::ccn_dtag dtag, const T &data)
+{
+ return AppendTaggedBlob (start, dtag, reinterpret_cast<const uint8_t*> (&data), sizeof (data));
+}
+
+} // namespace ndn
+} // namespace ns3
+
+#endif // _NDN_ENCODING_HELPER_H_
+
diff --git a/disabled/ndn-interest-header-ccnb.cc b/disabled/ndn-interest-header-ccnb.cc
new file mode 100644
index 0000000..beebda8
--- /dev/null
+++ b/disabled/ndn-interest-header-ccnb.cc
@@ -0,0 +1,296 @@
+/* -*- 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: Ilya Moiseenko <iliamo@cs.ucla.edu>
+ * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+///< #CCN_PR_SCOPE0 (0x20) local scope,
+///< #CCN_PR_SCOPE1 (0x40) this host,
+///< #CCN_PR_SCOPE2 (0x80) immediate neighborhood
+
+#include "ndn-interest-header-ccnb.h"
+
+#include "ns3/log.h"
+#include "ns3/unused.h"
+#include "ns3/packet.h"
+#include "../helper/ndn-encoding-helper.h"
+#include "../helper/ndn-decoding-helper.h"
+
+NS_LOG_COMPONENT_DEFINE ("ndn.InterestHeader");
+
+namespace ns3 {
+namespace ndn {
+
+NS_OBJECT_ENSURE_REGISTERED (InterestHeader);
+
+TypeId
+InterestHeader::GetTypeId (void)
+{
+ static TypeId tid = TypeId ("ns3::ndn::InterestHeader")
+ .SetGroupName ("Ndn")
+ .SetParent<Header> ()
+ .AddConstructor<InterestHeader> ()
+ ;
+ return tid;
+}
+
+
+InterestHeader::InterestHeader ()
+ : m_name ()
+ , m_minSuffixComponents (-1)
+ , m_maxSuffixComponents (-1)
+ , m_exclude ()
+ , m_childSelector (false)
+ , m_answerOriginKind (false)
+ , m_scope (-1)
+ , m_interestLifetime (Seconds (0))
+ , m_nonce (0)
+ , m_nackType (NORMAL_INTEREST)
+{
+}
+
+InterestHeader::InterestHeader (const InterestHeader &interest)
+ : m_name (Create<NameComponents> (interest.GetName ()))
+ , m_minSuffixComponents (interest.m_minSuffixComponents)
+ , m_maxSuffixComponents (interest.m_maxSuffixComponents)
+ , m_exclude (interest.IsEnabledExclude () ? Create<NameComponents> (interest.GetExclude ()) : 0)
+ , m_childSelector (interest.m_childSelector)
+ , m_answerOriginKind (interest.m_answerOriginKind)
+ , m_scope (interest.m_scope)
+ , m_interestLifetime (interest.m_interestLifetime)
+ , m_nonce (interest.m_nonce)
+ , m_nackType (interest.m_nackType)
+{
+}
+
+Ptr<InterestHeader>
+InterestHeader::GetInterest (Ptr<Packet> packet)
+{
+ Ptr<InterestHeader> interest = Create<InterestHeader> ();
+ packet->RemoveHeader (*interest);
+
+ return interest;
+}
+
+void
+InterestHeader::SetName (Ptr<NameComponents> name)
+{
+ m_name = name;
+}
+
+const NameComponents&
+InterestHeader::GetName () const
+{
+ if (m_name==0) throw InterestHeaderException();
+ return *m_name;
+}
+
+Ptr<const NameComponents>
+InterestHeader::GetNamePtr () const
+{
+ return m_name;
+}
+
+void
+InterestHeader::SetMinSuffixComponents (int32_t value)
+{
+ m_minSuffixComponents = value;
+}
+
+int32_t
+InterestHeader::GetMinSuffixComponents () const
+{
+ return m_minSuffixComponents;
+}
+
+void
+InterestHeader::SetMaxSuffixComponents (int32_t value)
+{
+ m_maxSuffixComponents = value;
+}
+
+int32_t
+InterestHeader::GetMaxSuffixComponents () const
+{
+ return m_maxSuffixComponents;
+}
+
+void
+InterestHeader::SetExclude (Ptr<NameComponents> exclude)
+{
+ m_exclude = exclude;
+}
+
+bool
+InterestHeader::IsEnabledExclude () const
+{
+ return m_exclude!=0;
+}
+
+const NameComponents&
+InterestHeader::GetExclude () const
+{
+ if (m_exclude==0) throw InterestHeaderException();
+ return *m_exclude;
+}
+
+void
+InterestHeader::SetChildSelector (bool value)
+{
+ m_childSelector = value;
+}
+
+bool
+InterestHeader::IsEnabledChildSelector () const
+{
+ return m_childSelector;
+}
+
+void
+InterestHeader::SetAnswerOriginKind (bool value)
+{
+ m_answerOriginKind = value;
+}
+
+bool
+InterestHeader::IsEnabledAnswerOriginKind () const
+{
+ return m_answerOriginKind;
+}
+
+void
+InterestHeader::SetScope (int8_t scope)
+{
+ m_scope = scope;
+}
+
+int8_t
+InterestHeader::GetScope () const
+{
+ return m_scope;
+}
+
+void
+InterestHeader::SetInterestLifetime (Time lifetime)
+{
+ m_interestLifetime = lifetime;
+}
+
+Time
+InterestHeader::GetInterestLifetime () const
+{
+ return m_interestLifetime;
+}
+
+void
+InterestHeader::SetNonce (uint32_t nonce)
+{
+ m_nonce = nonce;
+}
+
+uint32_t
+InterestHeader::GetNonce () const
+{
+ return m_nonce;
+}
+
+void
+InterestHeader::SetNack (uint32_t nackType)
+{
+ m_nackType = nackType;
+}
+
+uint32_t
+InterestHeader::GetNack () const
+{
+ return m_nackType;
+}
+
+uint32_t
+InterestHeader::GetSerializedSize (void) const
+{
+ // unfortunately, we don't know exact header size in advance
+ return EncodingHelper::GetSerializedSize (*this);
+}
+
+void
+InterestHeader::Serialize (Buffer::Iterator start) const
+{
+ size_t size = EncodingHelper::Serialize (start, *this);
+ NS_UNUSED (size);
+ NS_LOG_INFO ("Serialize size = " << size);
+}
+
+uint32_t
+InterestHeader::Deserialize (Buffer::Iterator start)
+{
+ return DecodingHelper::Deserialize (start, *this); // \todo Debugging is necessary
+}
+
+TypeId
+InterestHeader::GetInstanceTypeId (void) const
+{
+ return GetTypeId ();
+}
+
+void
+InterestHeader::Print (std::ostream &os) const
+{
+ os << "I: " << GetName ();
+
+ return;
+ os << "<Interest>\n <Name>" << GetName () << "</Name>\n";
+ if (GetNack ()>0)
+ {
+ os << " <NACK>";
+ switch (GetNack ())
+ {
+ case NACK_LOOP:
+ os << "loop";
+ break;
+ case NACK_CONGESTION:
+ os << "congestion";
+ break;
+ default:
+ os << "unknown";
+ break;
+ }
+ os << "</NACK>\n";
+ }
+ if (GetMinSuffixComponents () >= 0)
+ os << " <MinSuffixComponents>" << GetMinSuffixComponents () << "</MinSuffixComponents>\n";
+ if (GetMaxSuffixComponents () >= 0)
+ os << " <MaxSuffixComponents>" << m_maxSuffixComponents << "</MaxSuffixComponents>\n";
+ if (IsEnabledExclude () && GetExclude ().size()>0)
+ os << " <Exclude>" << GetExclude () << "</Exclude>\n";
+ if (IsEnabledChildSelector ())
+ os << " <ChildSelector />\n";
+ if (IsEnabledAnswerOriginKind ())
+ os << " <AnswerOriginKind />\n";
+ if (GetScope () >= 0)
+ os << " <Scope>" << GetScope () << "</Scope>\n";
+ if ( !GetInterestLifetime ().IsZero() )
+ os << " <InterestLifetime>" << GetInterestLifetime () << "</InterestLifetime>\n";
+ if (GetNonce ()>0)
+ os << " <Nonce>" << GetNonce () << "</Nonce>\n";
+ os << "</Interest>";
+}
+
+} // namespace ndn
+} // namespace ns3
+
diff --git a/disabled/ndn-interest-header-ccnb.h b/disabled/ndn-interest-header-ccnb.h
new file mode 100644
index 0000000..7b643f1
--- /dev/null
+++ b/disabled/ndn-interest-header-ccnb.h
@@ -0,0 +1,419 @@
+/* -*- 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: Ilya Moiseenko <iliamo@cs.ucla.edu>
+ * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef _NDN_INTEREST_HEADER_CCNB_H_
+#define _NDN_INTEREST_HEADER_CCNB_H_
+
+#include "ns3/integer.h"
+#include "ns3/header.h"
+#include "ns3/simple-ref-count.h"
+#include "ns3/nstime.h"
+
+#include <string>
+#include <vector>
+#include <list>
+
+#include "ndn-name-components.h"
+
+namespace ns3 {
+
+class Packet;
+
+namespace ndn {
+
+/**
+ * Ndn XML definition of Interest
+ *
+ * Only few important fields are actually implemented in the simulation
+ *
+ * <xs:element name="Interest" type="InterestType"/>
+ * <xs:complexType name="InterestType">
+ * <xs:sequence>
+ * <xs:element name="Name" type="NameType"/>
+ * <xs:element name="MinSuffixComponents" type="xs:nonNegativeInteger"
+ * minOccurs="0" maxOccurs="1"/>
+ * <xs:element name="MaxSuffixComponents" type="xs:nonNegativeInteger"
+ * minOccurs="0" maxOccurs="1"/>
+ * <xs:choice minOccurs="0" maxOccurs="1">
+ * <xs:element name="PublisherPublicKeyDigest" type="DigestType"/>
+ * <xs:element name="PublisherCertificateDigest" type="DigestType"/>
+ * <xs:element name="PublisherIssuerKeyDigest" type="DigestType"/>
+ * <xs:element name="PublisherIssuerCertificateDigest" type="DigestType"/>
+ * </xs:choice>
+ * <xs:element name="Exclude" type="ExcludeType"
+ * minOccurs="0" maxOccurs="1"/>
+ * <xs:element name="ChildSelector" type="xs:nonNegativeInteger"
+ * minOccurs="0" maxOccurs="1"/>
+ * <xs:element name="AnswerOriginKind" type="xs:nonNegativeInteger"
+ * minOccurs="0" maxOccurs="1"/>
+ * <xs:element name="Scope" type="xs:nonNegativeInteger"
+ * minOccurs="0" maxOccurs="1"/>
+ * <xs:element name="InterestLifetime" type="FinegrainLifetimeType"
+ * minOccurs="0" maxOccurs="1"/>
+ * <xs:element name="Nonce" type="Base64BinaryType"
+ * minOccurs="0" maxOccurs="1"/>
+ * </xs:sequence>
+ * </xs:complexType>
+ *
+ * <xs:complexType name="NameType">
+ * <xs:sequence>
+ * <xs:element name="Component" type="Base64BinaryType"
+ * minOccurs="0" maxOccurs="unbounded"/>
+ * </xs:sequence>
+ * </xs:complexType>
+ *
+ * <xs:complexType name="ExcludeType">
+ * <xs:sequence>
+ * <xs:choice minOccurs="0" maxOccurs="1">
+ * <xs:element name="Any" type="EmptyType"/>
+ * <xs:element name="Bloom" type="Base64BinaryType"/> <!-- Bloom is deprecated --!>
+ * </xs:choice>
+ * <xs:sequence minOccurs="0" maxOccurs="unbounded">
+ * <xs:element name="Component" type="Base64BinaryType"/>
+ * <xs:choice minOccurs="0" maxOccurs="1">
+ * <xs:element name="Any" type="EmptyType"/>
+ * <xs:element name="Bloom" type="Base64BinaryType"/> <!-- Bloom is deprecated --!>
+ * </xs:choice>
+ * </xs:sequence>
+ * </xs:sequence>
+ * </xs:complexType>
+ *
+ * <!-- Binary representation of time, Unix time epoch, units 2**-12 sec (0.000244140625 sec) -->
+ * <!-- The length limit limit of 6 bytes is not actually to be enforced, but
+ * it will be a loooooooong time before anyone cares. -->
+ *
+ * <!-- Binary representation of relative time, relative to "now" -->
+ * <xs:complexType name="FinegrainLifetimeType">
+ * <xs:simpleContent>
+ * <xs:extension base="BinaryTime12">
+ * <xs:attribute name="ccnbencoding" type="xs:string" fixed="base64Binary"/>
+ * </xs:extension>
+ * </xs:simpleContent>
+ * </xs:complexType>
+ *
+ * <xs:simpleType name="BinaryTime12">
+ * <xs:restriction base="xs:base64Binary">
+ * <xs:length value="6" fixed="true"/>
+ * </xs:restriction>
+ * </xs:simpleType>
+ *
+ **/
+
+/**
+ * @brief NDN InterestHeader and routines to serialize/deserialize
+ *
+ * Simplifications:
+ * - Name: binary name components are not supported
+ * - MinSuffixComponents and MasSuffixComponents: if value is negative (default), will not be serialized
+ * - ChildSelector, AnswerOriginKind: 0 - false, 1 - true, -1 not set
+ * - Publisher* elements are not supported
+ * - Exclude: only simple name matching is supported (Bloom support has been deprecated in Ndn)
+ * - InterestLifetime: ?
+ * - Nonce: 32 bit random integer. If value is 0, will not be serialized
+ **/
+class InterestHeader : public SimpleRefCount<InterestHeader, Header>
+{
+public:
+ /**
+ * \brief Constructor
+ *
+ * Creates a null header
+ **/
+ InterestHeader ();
+
+ /**
+ * @brief Copy constructor
+ */
+ InterestHeader (const InterestHeader &interest);
+
+ /**
+ * \brief Set interest name
+ *
+ * Sets name of the interest. For example, SetName( ndnNameComponents("prefix")("postfix") );
+ * @param[in] name const pointer to ndnNameComponents object that contains an interest name
+ **/
+ void
+ SetName (Ptr<NameComponents> name);
+
+
+ /**
+ * \brief Get interest name
+ *
+ * Gets name of the interest.
+ **/
+ const NameComponents&
+ GetName () const;
+
+ /**
+ * @brief Get smart pointer to the interest name (to avoid extra memory usage)
+ */
+ Ptr<const NameComponents>
+ GetNamePtr () const;
+
+ /**
+ * \brief Set interest MinSuffixComponents
+ *
+ * MinSuffixComponents refer to the number of name components beyond those in the prefix,
+ * and counting the implicit digest, that may occur in the matching ContentObject.
+ * \see http://www.ndn.org/releases/latest/doc/technical/InterestMessage.html for more information.
+ * @param[in] value minimum length of suffix components
+ **/
+ void
+ SetMinSuffixComponents (int32_t value);
+
+ /**
+ * \brief Get interest MinSuffixComponents
+ *
+ * MinSuffixComponents refer to the number of name components beyond those in the prefix,
+ * and counting the implicit digest, that may occur in the matching ContentObject.
+ * For more information, see http://www.ndn.org/releases/latest/doc/technical/InterestMessage.html
+ **/
+ int32_t
+ GetMinSuffixComponents () const;
+
+
+ /**
+ * \brief Set interest MaxSuffixComponents
+ *
+ * MaxSuffixComponents refer to the number of name components beyond those in the prefix,
+ * and counting the implicit digest, that may occur in the matching ContentObject.
+ * \see http://www.ndn.org/releases/latest/doc/technical/InterestMessage.html for more information.
+ * @param[in] value maximum length of suffix components
+ **/
+ void
+ SetMaxSuffixComponents (int32_t value);
+
+ /**
+ * \brief Get interest MaxSuffixComponents
+ *
+ * MaxSuffixComponents refer to the number of name components beyond those in the prefix,
+ * and counting the implicit digest, that may occur in the matching ContentObject.
+ * For more information, see http://www.ndn.org/releases/latest/doc/technical/InterestMessage.html
+ **/
+ int32_t
+ GetMaxSuffixComponents () const;
+
+ /**
+ * \brief Set exclude filer
+ *
+ * For example, SetExclude (ndnNameComponents("exclude1")("exclude2")("exclude3"))
+ * @param[in] exclude const pointer to ndnNameComponents to be excluded
+ **/
+ void
+ SetExclude (Ptr<NameComponents> exclude);
+
+ /**
+ * \brief Check if interest conatins exclude filter
+ *
+ */
+ bool
+ IsEnabledExclude () const;
+
+ /**
+ * \brief Get exclude filter
+ */
+ const NameComponents&
+ GetExclude () const;
+
+ /**
+ * \brief Set ChildSelector
+ * Often a given interest will match more than one ContentObject within a given content store.
+ * The ChildSelector provides a way of expressing a preference for which of these should be returned.
+ * If the value is false, the leftmost child is preferred. If true, the rightmost child is preferred.
+ * \see http://www.ndn.org/releases/latest/doc/technical/InterestMessage.html for more information.
+ * @param[in] value boolean ChildSelector value
+ */
+ void
+ SetChildSelector (bool value);
+
+ /**
+ * \brief Return ChildSelector value
+ * \see http://www.ndn.org/releases/latest/doc/technical/InterestMessage.html for more information.
+ *
+ */
+ bool
+ IsEnabledChildSelector () const;
+
+ /**
+ * \brief Set AnswerOriginKind
+ * Default value for AnswerOriginKind is false.
+ * @param[in] value boolean AnswerOriginKind value
+ */
+ void
+ SetAnswerOriginKind (bool value);
+
+ /**
+ * \brief Check the value of AnswerOriginKind
+ *
+ */
+ bool
+ IsEnabledAnswerOriginKind () const;
+
+ /**
+ * \brief Set Scope
+ * Scope limits where the Interest may propagate.
+ * Scope 0 prevents propagation beyond the local ccnd (even to other applications on the same host).
+ * Scope 1 limits propagation to the applications on the originating host.
+ * Scope 2 limits propagation to no further than the next host.
+ * Other values are not defined, and will cause the Interest message to be dropped.
+ * Note that this is not a hop count - the value is not decremented as the interest is forwarded.
+ * @param[in] scope interest scope
+ */
+ void
+ SetScope (int8_t scope);
+
+ /**
+ * \brief Get Scope value
+ * Scope limits where the Interest may propagate.
+ * Scope 0 prevents propagation beyond the local ccnd (even to other applications on the same host).
+ * Scope 1 limits propagation to the applications on the originating host.
+ * Scope 2 limits propagation to no further than the next host.
+ * Other values are not defined, and will cause the Interest message to be dropped.
+ * Note that this is not a hop count - the value is not decremented as the interest is forwarded.
+ */
+ int8_t
+ GetScope () const;
+
+ /**
+ * \brief Set InterestLifetime
+ * InterestLifetime indicates the (approximate) time remaining before the interest times out.
+ * The timeout is relative to the arrival time of the interest at the current node.
+ * \see http://www.ndn.org/releases/latest/doc/technical/InterestMessage.html for more information.
+ * @param[in] time interest lifetime
+ */
+ void
+ SetInterestLifetime (Time time);
+
+ /**
+ * \brief Get InterestLifetime value
+ * InterestLifetime indicates the (approximate) time remaining before the interest times out.
+ * The timeout is relative to the arrival time of the interest at the current node.
+ * \see http://www.ndn.org/releases/latest/doc/technical/InterestMessage.html for more information.
+ */
+ Time
+ GetInterestLifetime () const;
+
+ /**
+ * \brief Set Nonce
+ * Nonce carries a randomly-genenerated bytestring that is used to detect and discard duplicate Interest messages.
+ * @param[in] nonce Unique packet identification number
+ */
+ void
+ SetNonce (uint32_t nonce);
+
+ /**
+ * \brief Get Nonce value
+ * Nonce carries a randomly-genenerated bytestring that is used to detect and discard duplicate Interest messages.
+ *
+ */
+ uint32_t
+ GetNonce () const;
+
+ /**
+ * @brief NACK Type
+ * Specifies the type of Interest packet
+ */
+ enum
+ {
+ NORMAL_INTEREST = 0,
+ NACK_LOOP = 10,
+ NACK_CONGESTION = 11,
+ NACK_GIVEUP_PIT = 12,
+ };
+
+ /**
+ * \brief Mark the Interest as a Negative Acknowledgement
+ * Three types of NACKs are supported
+ * 1. NACK_LOOP
+ * 2. NACK_CONGESTION
+ * 3. NACK_GIVEUP_PIT
+ * @param[in] nackType NACK_LOOP or NACK_CONGESTION or NACK_GIVEUP_PIT or NORMAL_INTEREST
+ */
+ void
+ SetNack (uint32_t nackType);
+
+ /**
+ * \brief Get NACK type
+ * Returns NACK_LOOP, NACK_CONGESTION or NACK_GIVEUP_PIT.
+ * Otherwise, in case of normal interest packet, returns NORMAL_INTEREST (equals 0).
+ */
+ uint32_t
+ GetNack () const;
+
+ //////////////////////////////////////////////////////////////////
+
+ static TypeId GetTypeId (void); ///< @brief Get TypeId of the class
+ virtual TypeId GetInstanceTypeId (void) const; ///< @brief Get TypeId of the instance
+
+ /**
+ * \brief Print Interest packet
+ */
+ virtual void Print (std::ostream &os) const;
+
+ /**
+ * \brief Get the size of Interest packet
+ * Returns the Interest packet size after serialization
+ */
+ virtual uint32_t GetSerializedSize (void) const;
+
+ /**
+ * \brief Serialize Interest packet
+ * Serializes Interest packet into Buffer::Iterator
+ * @param[in] start buffer to contain serialized Interest packet
+ */
+ virtual void Serialize (Buffer::Iterator start) const;
+
+ /**
+ * \brief Deserialize Interest packet
+ * Deserializes Buffer::Iterator into Interest packet
+ * @param[in] start buffer that contains serialized Interest packet
+ */
+ virtual uint32_t Deserialize (Buffer::Iterator start);
+
+ /**
+ * @brief Cheat for python bindings
+ */
+ static Ptr<InterestHeader>
+ GetInterest (Ptr<Packet> packet);
+
+private:
+ Ptr<NameComponents> m_name; ///< Interest name
+ int32_t m_minSuffixComponents; ///< Minimum suffix components. not used if negative
+ int32_t m_maxSuffixComponents; ///< Maximum suffix components. not used if negative
+ Ptr<NameComponents> m_exclude; ///< Exclude filter
+ bool m_childSelector; ///< Default value for ChildSelector is false
+ bool m_answerOriginKind; ///< Default value for AnswerOriginKind is false
+ int8_t m_scope; ///< -1 not set, 0 local scope, 1 this host, 2 immediate neighborhood
+ Time m_interestLifetime; ///< InterestLifetime
+ uint32_t m_nonce; ///< Nonce. not used if zero
+ uint32_t m_nackType; ///< Negative Acknowledgement type
+};
+
+/**
+ * @ingroup ndn-exceptions
+ * @brief Class for Interest parsing exception
+ */
+class InterestHeaderException {};
+
+} // namespace ndn
+} // namespace ns3
+
+#endif // _NDN_INTEREST_HEADER_CCNB_H_