Merge remote-tracking branch 'git.irl/master'
diff --git a/examples/ccnx-test.cc b/examples/ccnx-test.cc
index 626a2f5..0d32793 100644
--- a/examples/ccnx-test.cc
+++ b/examples/ccnx-test.cc
@@ -2,9 +2,7 @@
#include "ns3/core-module.h"
#include "ns3/network-module.h"
-#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
-#include "ns3/applications-module.h"
#include "ns3/NDNabstraction-module.h"
using namespace ns3;
@@ -15,18 +13,23 @@
main (int argc, char *argv[])
{
LogComponentEnable ("CcnxTest", LOG_ALL);
+ LogComponentEnable ("CcnxStackHelper", LOG_ALL);
- Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210));
- Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("448kb/s"));
+ // Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210));
+ // Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("448kb/s"));
+
+ Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("10Mbps"));
+ Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("1ms"));
CommandLine cmd;
cmd.Parse (argc, argv);
// Here, we will explicitly create seven nodes.
NodeContainer c;
- c.Create (2);
+ c.Create (3);
- NodeContainer n = NodeContainer (c.Get (0), c.Get (2));
+ NodeContainer n1 = NodeContainer (c.Get (0), c.Get (1));
+ NodeContainer n2 = NodeContainer (c.Get (1), c.Get (2));
// Ipv4StaticRoutingHelper staticRouting;
@@ -35,16 +38,16 @@
NS_LOG_INFO ("Create channels.");
PointToPointHelper p2p;
- p2p.SetDeviceAttribute ("DataRate", StringValue ("10Mbps"));
- p2p.SetChannelAttribute ("Delay", StringValue ("1ms"));
- NetDeviceContainer nd = p2p.Install (n);
+ // NetDeviceContainer nd =
+ p2p.Install (n1);
+ p2p.Install (n2);
NS_LOG_INFO ("Installing NDN stack");
CcnxStackHelper ccnx;
+ Ptr<CcnxFaceContainer> cf = ccnx.Install (c);
// ? set up forwarding
- // ccnx.Install (c);
//Add static routing
// InternetStackHelper internet;
diff --git a/helper/ccnb-parser/ccnb-parser-common.h b/helper/ccnb-parser/ccnb-parser-common.h
new file mode 100644
index 0000000..4e4eb12
--- /dev/null
+++ b/helper/ccnb-parser/ccnb-parser-common.h
@@ -0,0 +1,178 @@
+/* -*- 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 {
+
+/**
+ * \ingroup ccnx
+ * \defgroup ccnx-ccnb CCNB decoding routines
+ */
+/**
+ * \ingroup ccnx-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_SequenceNumber = 256,
+ CCN_DTAG_CCNProtocolDataUnit = 17702112
+};
+
+} // namespace CcnxParser
+} // namespace ns3
+
+#endif // _CCNB_PARSER_COMMON_H_
diff --git a/helper/ccnb-parser/ccnx-decoding-helper.h b/helper/ccnb-parser/ccnx-decoding-helper.h
new file mode 100644
index 0000000..375a57a
--- /dev/null
+++ b/helper/ccnb-parser/ccnx-decoding-helper.h
@@ -0,0 +1,46 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef _CCNX_DECODING_HELPER_H_
+#define _CCNX_DECODING_HELPER_H_
+
+namespace ns3 {
+
+class CcnxInterestHeader;
+class CcnxContentObjectHeader;
+
+/**
+ * \brief Helper class to decode ccnb formatted CCNx message
+ */
+class CcnxDecodingHelper
+{
+public:
+ static size_t
+ Deserialize (Buffer::Iterator start, const CcnxInterestHeader &interest);
+
+ static size_t
+ Deserialize (Buffer::Iterator start, const CcnxContentObjectHeader &contentObject);
+
+private:
+};
+
+} // namespace ns3
+
+#endif // _CCNX_DECODING_HELPER_H_
diff --git a/helper/ccnb-parser/syntax-tree/ccnb-parser-attr.cc b/helper/ccnb-parser/syntax-tree/ccnb-parser-attr.cc
new file mode 100644
index 0000000..397e940
--- /dev/null
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-attr.cc
@@ -0,0 +1,41 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "ccnb-parser-attr.h"
+#include "ns3/ccnb-parser-common.h"
+
+namespace ns3 {
+namespace CcnbParser {
+
+// length length in octets of UTF-8 encoding of tag name - 1 (minimum tag name length is 1)
+Attr::Attr (Buffer::Iterator &start, uint32_t length)
+{
+ m_attr.reserve (length+2); // extra byte for potential \0 at the end
+ for (uint32_t i = 0; i < (length+1); i++)
+ {
+ m_attr.push_back (start.ReadU8 ());
+ }
+ m_value = DynamicCast<Udata> (Block::ParseBlock (start));
+ if (m_value == 0)
+ throw CcnbDecodingException (); // "ATTR must be followed by UDATA field"
+}
+
+}
+}
diff --git a/helper/ccnb-parser/syntax-tree/ccnb-parser-attr.h b/helper/ccnb-parser/syntax-tree/ccnb-parser-attr.h
new file mode 100644
index 0000000..1b7d5e8
--- /dev/null
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-attr.h
@@ -0,0 +1,60 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef _CCNB_PARSER_ATTR_H_
+#define _CCNB_PARSER_ATTR_H_
+
+#include "ccnb-parser-base-attr.h"
+#include <string>
+
+namespace ns3 {
+namespace CcnbParser {
+
+/**
+ * \ingroup ccnx-ccnb
+ * \brief Class to represent ATTR ccnb-encoded node
+ *
+ * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
+ */
+class Attr : public BaseAttr
+{
+public:
+ /**
+ * \brief Constructor that actually parsed ccnb-encoded ATTR block
+ *
+ * \param start buffer iterator pointing to the first byte of ATTR block name
+ * \param length length of ATTR name (extracted from the value field)
+ *
+ * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
+ */
+ Attr (Buffer::Iterator &start, uint32_t length);
+
+ virtual void accept( 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/helper/ccnb-parser/syntax-tree/ccnb-parser-base-attr.h b/helper/ccnb-parser/syntax-tree/ccnb-parser-base-attr.h
new file mode 100644
index 0000000..9b20073
--- /dev/null
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-base-attr.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_BASE_ATTR_H_
+#define _CCNB_PARSER_BASE_ATTR_H_
+
+#include "ccnb-parser-udata.h"
+
+namespace ns3 {
+namespace CcnbParser {
+
+/**
+ * \ingroup ccnx-ccnb
+ * \brief Virtual base class providing a common storage for ATTR
+ * and DATTR ccnb-encoded blocks
+ *
+ * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
+ */
+class BaseAttr : public Block
+{
+public:
+ Ptr<Udata> m_value; ///< \brief Value of the attribute
+};
+
+}
+}
+
+#endif // _CCNB_PARSER_BASE_ATTR_H_
diff --git a/helper/ccnb-parser/syntax-tree/ccnb-parser-base-tag.h b/helper/ccnb-parser/syntax-tree/ccnb-parser-base-tag.h
new file mode 100644
index 0000000..6b7fe76
--- /dev/null
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-base-tag.h
@@ -0,0 +1,54 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef _CCNB_PARSER_BASE_TAG_H_
+#define _CCNB_PARSER_BASE_TAG_H_
+
+#include "ccnb-parser-block.h"
+#include <list>
+
+namespace ns3 {
+namespace CcnbParser {
+
+/**
+ * \ingroup ccnx-ccnb
+ * \brief Virtual base class providing a common storage for TAG
+ * and DTAG ccnb-encoded blocks
+ *
+ * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
+ */
+class BaseTag : public Block
+{
+public:
+ std::list<Ptr<Block> > m_attrs; ///< \brief List of attributes, associated with this tag
+ std::list<Ptr<Block> > m_nestedTags; ///< \brief List of nested tags
+
+protected:
+ /**
+ * \brief Default constructor
+ */
+ BaseTag() { }
+};
+
+}
+}
+
+#endif // _CCNB_PARSER_BASE_TAG_H_
+
diff --git a/in-progress/ccn/ccn_name_util.h b/helper/ccnb-parser/syntax-tree/ccnb-parser-blob.cc
similarity index 76%
copy from in-progress/ccn/ccn_name_util.h
copy to helper/ccnb-parser/syntax-tree/ccnb-parser-blob.cc
index 6e5fda7..0928eb8 100644
--- a/in-progress/ccn/ccn_name_util.h
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-blob.cc
@@ -15,5 +15,18 @@
* 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>
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
*/
+
+#include "ccnb-parser-blob.h"
+
+namespace ns3 {
+namespace CcnbParser {
+
+Blob::Blob (Buffer::Iterator &start, uint32_t length)
+{
+ start.Read (m_blob.Begin (), length);
+}
+
+}
+}
diff --git a/helper/ccnb-parser/syntax-tree/ccnb-parser-blob.h b/helper/ccnb-parser/syntax-tree/ccnb-parser-blob.h
new file mode 100644
index 0000000..4b22d62
--- /dev/null
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-blob.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_BLOB_H_
+#define _CCNB_PARSER_BLOB_H_
+
+#include "ccnb-parser-block.h"
+#include "ns3/buffer.h"
+
+namespace ns3 {
+namespace CcnbParser {
+
+/**
+ * \ingroup ccnx-ccnb
+ * \brief Class to represent BLOB ccnb-encoded node
+ *
+ * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
+ */
+class Blob : public Block
+{
+public:
+ /**
+ * \brief Constructor that actually parsed ccnb-encoded BLOB block
+ *
+ * \param start buffer iterator pointing to the first byte of BLOB data in ccnb-encoded block
+ * \param length length of data in BLOB block (extracted from the value field)
+ *
+ * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
+ */
+ Blob (Buffer::Iterator &start, uint32_t length);
+
+ virtual void accept( 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 ); }
+
+ Buffer m_blob; ///< \brief field holding a parsed BLOB value of the block
+};
+
+}
+}
+
+#endif // _CCNB_PARSER_BLOB_H_
diff --git a/helper/ccnb-parser/syntax-tree/ccnb-parser-block.cc b/helper/ccnb-parser/syntax-tree/ccnb-parser-block.cc
new file mode 100644
index 0000000..e1e09fd
--- /dev/null
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-block.cc
@@ -0,0 +1,76 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "ccnb-parser-block.h"
+
+#include "ccnb-parser-blob.h"
+#include "ccnb-parser-udata.h"
+#include "ccnb-parser-tag.h"
+#include "ccnb-parser-dtag.h"
+#include "ccnb-parser-attr.h"
+#include "ccnb-parser-dattr.h"
+#include "ccnb-parser-ext.h"
+
+namespace ns3 {
+namespace CcnbParser {
+
+const uint8_t CCN_TT_BITS = 3;
+const uint8_t CCN_TT_MASK = ((1 << CCN_TT_BITS) - 1);
+const uint8_t CCN_MAX_TINY= ((1 << (7-CCN_TT_BITS)) - 1);
+const uint8_t CCN_TT_HBIT = ((uint8_t)(1 << 7));
+
+Ptr<Block> Block::ParseBlock (Buffer::Iterator &start)
+{
+ uint32_t value = 0;
+
+ // We will have problems if length field is more than 32 bits. Though it's really impossible
+ uint8_t byte = 0;
+ while (!(byte & CCN_TT_HBIT))
+ {
+ value <<= 8;
+ value += byte;
+ byte = start.ReadU8 ();
+ }
+ value <<= 4;
+ value += ( (byte&(~CCN_TT_HBIT)) >> 3);
+
+ switch (byte & CCN_TT_MASK)
+ {
+ case CCN_BLOB:
+ return Create<Blob> (start, value);
+ case CCN_UDATA:
+ return Create<Udata> (start, value);
+ case CCN_TAG:
+ return Create<Tag> (start, value);
+ case CCN_ATTR:
+ return Create<Attr> (start, value);
+ case CCN_DTAG:
+ return Create<Dtag> (start, value);
+ case CCN_DATTR:
+ return Create<Dattr> (start, value);
+ case CCN_EXT:
+ return Create<Ext> (start, value);
+ default:
+ throw CcnbDecodingException ();
+ }
+}
+
+}
+}
diff --git a/helper/ccnb-parser/syntax-tree/ccnb-parser-block.h b/helper/ccnb-parser/syntax-tree/ccnb-parser-block.h
new file mode 100644
index 0000000..1ff614b
--- /dev/null
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-block.h
@@ -0,0 +1,68 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef _CCNB_PARSER_BLOCK_H_
+#define _CCNB_PARSER_BLOCK_H_
+
+#include "ns3/simple-ref-count.h"
+#include "ns3/buffer.h"
+#include "ns3/ptr.h"
+
+// visitors
+#include "ns3/ccnb-parser-void-no-argu-visitor.h"
+#include "ns3/ccnb-parser-void-visitor.h"
+#include "ns3/ccnb-parser-no-argu-visitor.h"
+#include "ns3/ccnb-parser-visitor.h"
+
+namespace ns3 {
+namespace CcnbParser {
+
+/**
+ * \ingroup ccnx-ccnb
+ * \brief Base class for ccnb-encoded node
+ *
+ * This class provides a static method to create a new block
+ * (recursively) from the stream
+ *
+ * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
+ */
+class Block : public SimpleRefCount<Block>
+{
+public:
+ /**
+ * \brief Parsing stream (recursively) and creating a parsed BLOCK
+ * object
+ *
+ * \param start buffer iterator pointing to the start position for parsing
+ * \returns parsed ccnb-encoded block, that could contain more block inside
+ */
+ static Ptr<Block>
+ ParseBlock (Buffer::Iterator &start);
+
+ virtual void accept( VoidNoArguVisitor &v ) = 0;
+ virtual void accept( VoidVisitor &v, boost::any param ) = 0;
+ virtual boost::any accept( NoArguVisitor &v ) = 0;
+ virtual boost::any accept( Visitor &v, boost::any param ) = 0;
+};
+
+}
+}
+
+#endif // _CCNB_PARSER_BLOCK_H_
diff --git a/in-progress/ccn/ccn_name_util.h b/helper/ccnb-parser/syntax-tree/ccnb-parser-dattr.cc
similarity index 64%
copy from in-progress/ccn/ccn_name_util.h
copy to helper/ccnb-parser/syntax-tree/ccnb-parser-dattr.cc
index 6e5fda7..bb6be82 100644
--- a/in-progress/ccn/ccn_name_util.h
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-dattr.cc
@@ -15,5 +15,22 @@
* 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>
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
*/
+
+#include "ccnb-parser-dattr.h"
+
+namespace ns3 {
+namespace CcnbParser {
+
+// dictionary attributes are not used (yet?) in CCNx
+Dattr::Dattr (Buffer::Iterator &start, uint32_t dattr)
+{
+ m_dattr = dattr;
+ m_value = DynamicCast<Udata> (Block::ParseBlock (start));
+ if (m_value == 0)
+ throw CcnbDecodingException (); // "ATTR must be followed by UDATA field"
+}
+
+}
+}
diff --git a/helper/ccnb-parser/syntax-tree/ccnb-parser-dattr.h b/helper/ccnb-parser/syntax-tree/ccnb-parser-dattr.h
new file mode 100644
index 0000000..6775017
--- /dev/null
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-dattr.h
@@ -0,0 +1,59 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef _CCNB_PARSER_DATTR_H_
+#define _CCNB_PARSER_DATTR_H_
+
+#include "ccnb-parser-base-attr.h"
+
+namespace ns3 {
+namespace CcnbParser {
+
+/**
+ * \ingroup ccnx-ccnb
+ * \brief Class to represent DATTR ccnb-encoded node
+ *
+ * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
+ */
+class Dattr : public BaseAttr
+{
+public:
+ /**
+ * \brief Constructor that actually parsed ccnb-encoded DATTR block
+ *
+ * \param start buffer iterator pointing to the first byte of attribute value (UDATA block)
+ * \param dattr dictionary code of DATTR (extracted from the value field)
+ *
+ * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
+ */
+ Dattr (Buffer::Iterator &start, uint32_t dattr);
+
+ virtual void accept( 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/helper/ccnb-parser/syntax-tree/ccnb-parser-dtag.cc b/helper/ccnb-parser/syntax-tree/ccnb-parser-dtag.cc
new file mode 100644
index 0000000..8d9ecf7
--- /dev/null
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-dtag.cc
@@ -0,0 +1,76 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "ccnb-parser-dtag.h"
+
+#include "ccnb-parser-base-attr.h"
+#include "ccnb-parser-base-tag.h"
+
+namespace ns3 {
+namespace CcnbParser {
+
+Dtag::Dtag (Buffer::Iterator &start, uint32_t dtag)
+{
+ m_dtag = dtag;
+
+ /**
+ * Hack
+ *
+ * Stop processing after encountering <Content> dtag. Actual
+ * content (including virtual payload) will be stored in Packet
+ * buffer
+ */
+ if (dtag == CCN_DTAG_Content)
+ return; // hack #1. Do not process nesting block for <Content>
+
+ // parse attributes until first nested block reached
+ while (!start.IsEnd () && start.PeekU8 ()!=CCN_CLOSE)
+ {
+ Ptr<Block> block = Block::ParseBlock (start);
+ if (DynamicCast<BaseAttr> (block)!=0)
+ m_attrs.push_back (block);
+ else
+ {
+ m_nestedTags.push_back (block);
+ break;
+ }
+ }
+
+ // parse the rest of nested blocks
+ while (!start.IsEnd () && start.PeekU8 ()!=CCN_CLOSE)
+ {
+ // hack #2. Stop processing nested blocks if last block was <Content>
+ if (m_dtag == 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));
+ }
+ if (start.IsEnd ())
+ throw CcnbDecodingException ();
+
+ start.ReadU8 (); // read CCN_CLOSE
+}
+
+}
+}
diff --git a/helper/ccnb-parser/syntax-tree/ccnb-parser-dtag.h b/helper/ccnb-parser/syntax-tree/ccnb-parser-dtag.h
new file mode 100644
index 0000000..1ff75e3
--- /dev/null
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-dtag.h
@@ -0,0 +1,64 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef _CCNB_PARSER_DTAG_H_
+#define _CCNB_PARSER_DTAG_H_
+
+#include "ccnb-parser-base-tag.h"
+
+namespace ns3 {
+namespace CcnbParser {
+
+/**
+ * \ingroup ccnx-ccnb
+ * \brief Class to represent DTAG ccnb-encoded node
+ *
+ * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
+ */
+class Dtag : public BaseTag
+{
+public:
+ /**
+ * \brief Constructor that actually parsed ccnb-encoded DTAG block
+ *
+ * \param start buffer iterator pointing to the first nesting block or closing tag
+ * \param dtag dictionary code of DTAG (extracted from the value field)
+ *
+ * DTAG parsing is slightly hacked to provide memory optimization
+ * for NS-3 simulations. Parsing will be stopped after encountering
+ * <Content> dtag. Actual content (including virtual payload) will
+ * be stored in Packet buffer
+ *
+ * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
+ */
+ Dtag (Buffer::Iterator &start, uint32_t dtag);
+
+ virtual void accept( 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/in-progress/ccn/ccn_name_util.h b/helper/ccnb-parser/syntax-tree/ccnb-parser-ext.cc
similarity index 76%
rename from in-progress/ccn/ccn_name_util.h
rename to helper/ccnb-parser/syntax-tree/ccnb-parser-ext.cc
index 6e5fda7..7d90019 100644
--- a/in-progress/ccn/ccn_name_util.h
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-ext.cc
@@ -15,5 +15,18 @@
* 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>
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
*/
+
+#include "ccnb-parser-ext.h"
+
+namespace ns3 {
+namespace CcnbParser {
+
+Ext::Ext (Buffer::Iterator &start, uint32_t extSubtype)
+{
+ m_extSubtype = extSubtype;
+}
+
+}
+}
diff --git a/helper/ccnb-parser/syntax-tree/ccnb-parser-ext.h b/helper/ccnb-parser/syntax-tree/ccnb-parser-ext.h
new file mode 100644
index 0000000..568706b
--- /dev/null
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-ext.h
@@ -0,0 +1,59 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef _CCNB_PARSER_EXT_H_
+#define _CCNB_PARSER_EXT_H_
+
+#include "ccnb-parser-block.h"
+
+namespace ns3 {
+namespace CcnbParser {
+
+/**
+ * \ingroup ccnx-ccnb
+ * \brief Class to represent EXT ccnb-encoded node
+ *
+ * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
+ */
+class Ext : public Block
+{
+public:
+ /**
+ * \brief Constructor that actually parsed ccnb-encoded DTAG block
+ *
+ * \param start buffer iterator pointing to the next byte past EXT block
+ * \param extSubtype extension type (extracted from the value field)
+ *
+ * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
+ */
+ Ext (Buffer::Iterator &start, uint32_t extSubtype);
+
+ virtual void accept( 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/helper/ccnb-parser/syntax-tree/ccnb-parser-tag.cc b/helper/ccnb-parser/syntax-tree/ccnb-parser-tag.cc
new file mode 100644
index 0000000..c288be9
--- /dev/null
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-tag.cc
@@ -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>
+ */
+
+#include "ccnb-parser-tag.h"
+
+#include "ccnb-parser-base-attr.h"
+
+namespace ns3 {
+namespace CcnbParser {
+
+Tag::Tag (Buffer::Iterator &start, uint32_t length)
+{
+ m_tag.reserve (length+2); // extra byte for potential \0 at the end
+ for (uint32_t i = 0; i < (length+1); i++)
+ {
+ m_tag.push_back (start.ReadU8 ());
+ }
+
+ // parse attributes until first nested block reached
+ while (!start.IsEnd () && start.PeekU8 ()!=CCN_CLOSE)
+ {
+ Ptr<Block> block = Block::ParseBlock (start);
+ if (DynamicCast<BaseAttr> (block)!=0)
+ m_attrs.push_back (block);
+ else
+ {
+ m_nestedTags.push_back (block);
+ break;
+ }
+ }
+
+ // parse the rest of nested blocks
+ while (!start.IsEnd () && start.PeekU8 ()!=CCN_CLOSE)
+ {
+ Ptr<Block> block = Block::ParseBlock (start);
+ m_nestedTags.push_back (block);
+ }
+
+ if (start.IsEnd ()) //should not be the end
+ throw CcnbDecodingException ();
+
+ start.ReadU8 (); // read CCN_CLOSE
+}
+
+}
+}
diff --git a/helper/ccnb-parser/syntax-tree/ccnb-parser-tag.h b/helper/ccnb-parser/syntax-tree/ccnb-parser-tag.h
new file mode 100644
index 0000000..c80581d
--- /dev/null
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-tag.h
@@ -0,0 +1,60 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef _CCNB_PARSER_TAG_H_
+#define _CCNB_PARSER_TAG_H_
+
+#include "ccnb-parser-base-tag.h"
+#include <string>
+
+namespace ns3 {
+namespace CcnbParser {
+
+/**
+ * \ingroup ccnx-ccnb
+ * \brief Class to represent TAG ccnb-encoded node
+ *
+ * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
+ */
+class Tag : public BaseTag
+{
+public:
+ /**
+ * \brief Constructor that actually parsed ccnb-encoded TAG block
+ *
+ * \param start buffer iterator pointing to the first byte of TAG block name
+ * \param length length of TAG name - 1 byte (i.e., minimum tag name is 1 byte)
+ *
+ * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
+ */
+ Tag (Buffer::Iterator &start, uint32_t length);
+
+ virtual void accept( 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/helper/ccnb-parser/syntax-tree/ccnb-parser-udata.cc b/helper/ccnb-parser/syntax-tree/ccnb-parser-udata.cc
new file mode 100644
index 0000000..39217fd
--- /dev/null
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-udata.cc
@@ -0,0 +1,42 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "ccnb-parser-udata.h"
+
+namespace ns3 {
+namespace CcnbParser {
+
+Udata::Udata (Buffer::Iterator &start, uint32_t length)
+{
+ // Ideally, the code should look like this. Unfortunately, we don't have normal compatible iterators
+ // Buffer::Iterator realStart = start;
+ // start.Next (length); // advancing forward
+ // m_udata.assign (realStart, start/*actually, it is the end*/);
+
+ m_udata.reserve (length+1); //just in case we will need \0 at the end later
+ // this is actually the way Read method is implemented in network/src/buffer.cc
+ for (uint32_t i = 0; i < length; i++)
+ {
+ m_udata.push_back (start.ReadU8 ());
+ }
+}
+
+}
+}
diff --git a/helper/ccnb-parser/syntax-tree/ccnb-parser-udata.h b/helper/ccnb-parser/syntax-tree/ccnb-parser-udata.h
new file mode 100644
index 0000000..b6ef2c2
--- /dev/null
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-udata.h
@@ -0,0 +1,58 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef _CCNB_PARSER_UDATA_H_
+#define _CCNB_PARSER_UDATA_H_
+
+#include "ccnb-parser-block.h"
+#include <string>
+
+namespace ns3 {
+namespace CcnbParser {
+
+/**
+ * \ingroup ccnx-ccnb
+ * \brief Class to represent UDATA ccnb-encoded node
+ */
+class Udata : public Block
+{
+public:
+ /**
+ * \brief Constructor that actually parsed ccnb-encoded UDATA block
+ *
+ * \param start buffer iterator pointing to the first byte of string in ccnb-encoded block
+ * \param length length of data in UDATA block (extracted from the value field)
+ *
+ * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
+ */
+ Udata (Buffer::Iterator &start, uint32_t length);
+
+ virtual void accept( 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/helper/ccnb-parser/visitors/ccnb-parser-content-object-visitor.cc b/helper/ccnb-parser/visitors/ccnb-parser-content-object-visitor.cc
new file mode 100644
index 0000000..d694f11
--- /dev/null
+++ b/helper/ccnb-parser/visitors/ccnb-parser-content-object-visitor.cc
@@ -0,0 +1,79 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "ccnb-parser-content-object-visitor.h"
+#include "ccnb-parser-name-components-visitor.h"
+
+#include "ns3/ccnb-parser-block.h"
+#include "ns3/ccnb-parser-dtag.h"
+#include "ns3/name-components.h"
+#include "ns3/assert.h"
+
+#include "ns3/ccnx-content-object-header.h"
+
+#include <boost/foreach.hpp>
+
+namespace ns3 {
+namespace CcnbParser {
+
+// We don't really care about any other fields
+void
+ContentObjectVisitor::visit (Dtag &n, boost::any param/*should be CcnxContentObjectHeader&*/)
+{
+ // uint32_t n.m_dtag;
+ // std::list<Ptr<Block> > n.m_nestedBlocks;
+ static NameComponentsVisitor nameComponentsVisitor;
+
+ CcnxContentObjectHeader &contentObject = boost::any_cast<CcnxContentObjectHeader&> (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<Name::Components> name = Create<Name::Components> ();
+
+ BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags)
+ {
+ block->accept (nameComponentsVisitor, *name);
+ }
+ contentObject.SetName (name);
+ break;
+ }
+ case CCN_DTAG_Signature: // ignoring
+ break;
+ case CCN_DTAG_SignedInfo: // ignoring
+ 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;
+ }
+}
+
+} // namespace CcnbParser
+} // namespace ns3
diff --git a/helper/ccnb-parser/visitors/ccnb-parser-content-object-visitor.h b/helper/ccnb-parser/visitors/ccnb-parser-content-object-visitor.h
new file mode 100644
index 0000000..e15e290
--- /dev/null
+++ b/helper/ccnb-parser/visitors/ccnb-parser-content-object-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_OBJECT_VISITOR_H_
+#define _CCNB_PARSER_CONTENT_OBJECT_VISITOR_H_
+
+#include "ccnb-parser-void-depth-first-visitor.h"
+
+namespace ns3 {
+namespace CcnbParser {
+
+/**
+ * \ingroup ccnx-ccnb
+ * \brief Visitor that fills fields in CcnxContentObjectHeader
+ *
+ * Usage example:
+ * \code
+ * Ptr<CcnxContentObjectHeader> header = Create<CcnxContentObjectHeader> ();
+ * Ptr<CcnbParser::Block> root = CcnbParser::Block::ParseBlock (i);
+ * ContentObjectVisitor visitor;
+ * root->accept (visitor, *header);
+ * \endcode
+ */
+class ContentObjectVisitor : public VoidDepthFirstVisitor
+{
+public:
+ virtual void visit (Dtag &n, boost::any param/*should be CcnxContentObjectHeader&*/);
+};
+
+}
+}
+
+#endif // _CCNB_PARSER_CONTENT_OBJECT_VISITOR_H_
diff --git a/helper/ccnb-parser/visitors/ccnb-parser-depth-first-visitor.cc b/helper/ccnb-parser/visitors/ccnb-parser-depth-first-visitor.cc
new file mode 100644
index 0000000..514f444
--- /dev/null
+++ b/helper/ccnb-parser/visitors/ccnb-parser-depth-first-visitor.cc
@@ -0,0 +1,108 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "ccnb-parser-depth-first-visitor.h"
+
+#include "ns3/ccnb-parser-blob.h"
+#include "ns3/ccnb-parser-udata.h"
+#include "ns3/ccnb-parser-tag.h"
+#include "ns3/ccnb-parser-dtag.h"
+#include "ns3/ccnb-parser-attr.h"
+#include "ns3/ccnb-parser-dattr.h"
+#include "ns3/ccnb-parser-ext.h"
+
+#include <boost/foreach.hpp>
+
+namespace ns3 {
+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/helper/ccnb-parser/visitors/ccnb-parser-depth-first-visitor.h b/helper/ccnb-parser/visitors/ccnb-parser-depth-first-visitor.h
new file mode 100644
index 0000000..d68b4ad
--- /dev/null
+++ b/helper/ccnb-parser/visitors/ccnb-parser-depth-first-visitor.h
@@ -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>
+ */
+
+#ifndef _CCNB_PARSER_DEPTH_FIRST_VISITOR_H_
+#define _CCNB_PARSER_DEPTH_FIRST_VISITOR_H_
+
+#include "ccnb-parser-visitor.h"
+
+namespace ns3 {
+namespace CcnbParser {
+
+/**
+ * \ingrou 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/helper/ccnb-parser/visitors/ccnb-parser-interest-visitor.cc b/helper/ccnb-parser/visitors/ccnb-parser-interest-visitor.cc
new file mode 100644
index 0000000..70578e7
--- /dev/null
+++ b/helper/ccnb-parser/visitors/ccnb-parser-interest-visitor.cc
@@ -0,0 +1,157 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "ccnb-parser-interest-visitor.h"
+
+#include "ns3/ccnb-parser-block.h"
+#include "ns3/ccnb-parser-dtag.h"
+#include "ns3/name-components.h"
+#include "ns3/assert.h"
+#include "ns3/nstime.h"
+
+#include "ns3/ccnx-interest-header.h"
+#include "ccnb-parser-name-components-visitor.h"
+#include "ccnb-parser-non-negative-integer-visitor.h"
+#include "ccnb-parser-timestamp-visitor.h"
+#include "ccnb-parser-nonce-visitor.h"
+
+#include <boost/foreach.hpp>
+
+namespace ns3 {
+namespace CcnbParser {
+
+// We don't care about any other fields
+void
+InterestVisitor::visit (Dtag &n, boost::any param/*should be CcnxInterestHeader&*/)
+{
+ // uint32_t n.m_dtag;
+ // std::list<Ptr<Block> > n.m_nestedBlocks;
+
+ static NonNegativeIntegerVisitor nonNegativeIntegerVisitor;
+ static NameComponentsVisitor nameComponentsVisitor;
+ static TimestampVisitor timestampVisitor;
+ static NonceVisitor nonceVisitor;
+
+ CcnxInterestHeader &interest = boost::any_cast<CcnxInterestHeader&> (param);
+
+ switch (n.m_dtag)
+ {
+ case CCN_DTAG_Interest:
+ // process nested blocks
+ BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags)
+ {
+ block->accept (*this, param);
+ }
+ break;
+ case CCN_DTAG_Name:
+ {
+ // process name components
+ Ptr<Name::Components> name = Create<Name::Components> ();
+
+ BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags)
+ {
+ block->accept (nameComponentsVisitor, *name);
+ }
+ interest.SetName (name);
+ break;
+ }
+ case CCN_DTAG_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:
+ 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:
+ {
+ // process exclude components
+ Ptr<Name::Components> exclude = Create<Name::Components> ();
+
+ BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags)
+ {
+ block->accept (nameComponentsVisitor, *exclude);
+ }
+ interest.SetExclude (exclude);
+ break;
+ }
+ case CCN_DTAG_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:
+ 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:
+ 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:
+ 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:
+ 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;
+ }
+}
+
+} // namespace CcnbParser
+} // namespace ns3
diff --git a/helper/ccnb-parser/visitors/ccnb-parser-interest-visitor.h b/helper/ccnb-parser/visitors/ccnb-parser-interest-visitor.h
new file mode 100644
index 0000000..136b173
--- /dev/null
+++ b/helper/ccnb-parser/visitors/ccnb-parser-interest-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_INTEREST_VISITOR_H_
+#define _CCNB_PARSER_INTEREST_VISITOR_H_
+
+#include "ccnb-parser-void-depth-first-visitor.h"
+
+namespace ns3 {
+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&*/);
+};
+
+}
+}
+
+#endif // _CCNB_PARSER_INTEREST_VISITOR_H_
diff --git a/helper/ccnb-parser/visitors/ccnb-parser-name-components-visitor.cc b/helper/ccnb-parser/visitors/ccnb-parser-name-components-visitor.cc
new file mode 100644
index 0000000..3138be1
--- /dev/null
+++ b/helper/ccnb-parser/visitors/ccnb-parser-name-components-visitor.cc
@@ -0,0 +1,57 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "ccnb-parser-name-components-visitor.h"
+
+#include "ccnb-parser-string-visitor.h"
+#include "ns3/ccnb-parser-dtag.h"
+#include "ns3/name-components.h"
+
+namespace ns3 {
+namespace CcnbParser {
+
+void
+NameComponentsVisitor::visit (Dtag &n, boost::any param/*should be Name::Components&*/)
+{
+ // uint32_t n.m_dtag;
+ // std::list<Ptr<Block> > n.m_nestedBlocks;
+ static StringVisitor stringVisitor;
+
+ Name::Components &components = boost::any_cast<Name::Components&> (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/helper/ccnb-parser/visitors/ccnb-parser-name-components-visitor.h b/helper/ccnb-parser/visitors/ccnb-parser-name-components-visitor.h
new file mode 100644
index 0000000..c68eb56
--- /dev/null
+++ b/helper/ccnb-parser/visitors/ccnb-parser-name-components-visitor.h
@@ -0,0 +1,43 @@
+/* -*- 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 "ccnb-parser-void-depth-first-visitor.h"
+
+namespace ns3 {
+namespace CcnbParser {
+
+/**
+ * \ingroup ccnx-ccnb
+ * \brief Visitor to obtain fill Name::Components object with name components
+ */
+class NameComponentsVisitor : public VoidDepthFirstVisitor
+{
+public:
+ virtual void visit (Dtag &n, boost::any param/*should be Name::Components&*/);
+};
+
+}
+}
+
+#endif // _CCNB_PARSER_NAME_COMPONENTS_VISITOR_H_
+
diff --git a/helper/ccnb-parser/visitors/ccnb-parser-no-argu-depth-first-visitor.cc b/helper/ccnb-parser/visitors/ccnb-parser-no-argu-depth-first-visitor.cc
new file mode 100644
index 0000000..f81a350
--- /dev/null
+++ b/helper/ccnb-parser/visitors/ccnb-parser-no-argu-depth-first-visitor.cc
@@ -0,0 +1,108 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "ccnb-parser-no-argu-depth-first-visitor.h"
+
+#include "ns3/ccnb-parser-blob.h"
+#include "ns3/ccnb-parser-udata.h"
+#include "ns3/ccnb-parser-tag.h"
+#include "ns3/ccnb-parser-dtag.h"
+#include "ns3/ccnb-parser-attr.h"
+#include "ns3/ccnb-parser-dattr.h"
+#include "ns3/ccnb-parser-ext.h"
+
+#include <boost/foreach.hpp>
+
+namespace ns3 {
+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/helper/ccnb-parser/visitors/ccnb-parser-no-argu-depth-first-visitor.h b/helper/ccnb-parser/visitors/ccnb-parser-no-argu-depth-first-visitor.h
new file mode 100644
index 0000000..1990d87
--- /dev/null
+++ b/helper/ccnb-parser/visitors/ccnb-parser-no-argu-depth-first-visitor.h
@@ -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>
+ */
+
+#ifndef _CCNB_PARSER_NO_ARGU_DEPTH_FIRST_VISITOR_H_
+#define _CCNB_PARSER_NO_ARGU_DEPTH_FIRST_VISITOR_H_
+
+#include "ccnb-parser-no-argu-visitor.h"
+
+namespace ns3 {
+namespace CcnbParser {
+
+/**
+ * \ingrou 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/helper/ccnb-parser/visitors/ccnb-parser-no-argu-visitor.h b/helper/ccnb-parser/visitors/ccnb-parser-no-argu-visitor.h
new file mode 100644
index 0000000..3e1750f
--- /dev/null
+++ b/helper/ccnb-parser/visitors/ccnb-parser-no-argu-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_NO_ARGU_VISITOR_H_
+#define _CCNB_PARSER_NO_ARGU_VISITOR_H_
+
+#include "ns3/ccnb-parser-commoh.h"
+#include <boost/any.hpp>
+
+namespace ns3 {
+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
+};
+
+}
+}
+
+#endif // _CCNB_PARSER_NO_ARGU_VISITOR_H_
diff --git a/helper/ccnb-parser/visitors/ccnb-parser-non-negative-integer-visitor.cc b/helper/ccnb-parser/visitors/ccnb-parser-non-negative-integer-visitor.cc
new file mode 100644
index 0000000..e393770
--- /dev/null
+++ b/helper/ccnb-parser/visitors/ccnb-parser-non-negative-integer-visitor.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 "ccnb-parser-non-negative-integer-visitor.h"
+
+#include "ns3/ccnb-parser-blob.h"
+#include "ns3/ccnb-parser-udata.h"
+#include <sstream>
+
+namespace ns3 {
+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/helper/ccnb-parser/visitors/ccnb-parser-non-negative-integer-visitor.h b/helper/ccnb-parser/visitors/ccnb-parser-non-negative-integer-visitor.h
new file mode 100644
index 0000000..7ecc3a9
--- /dev/null
+++ b/helper/ccnb-parser/visitors/ccnb-parser-non-negative-integer-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_NON_NEGATIVE_INTEGER_VISITOR_H_
+#define _CCNB_PARSER_NON_NEGATIVE_INTEGER_VISITOR_H_
+
+#include "ccnb-parser-no-argu-depth-first-visitor.h"
+
+namespace ns3 {
+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/in-progress/ccn/ccn_name_util.h b/helper/ccnb-parser/visitors/ccnb-parser-nonce-visitor.cc
similarity index 61%
copy from in-progress/ccn/ccn_name_util.h
copy to helper/ccnb-parser/visitors/ccnb-parser-nonce-visitor.cc
index 6e5fda7..7492adf 100644
--- a/in-progress/ccn/ccn_name_util.h
+++ b/helper/ccnb-parser/visitors/ccnb-parser-nonce-visitor.cc
@@ -15,5 +15,31 @@
* 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>
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
*/
+
+#include "ccnb-parser-nonce-visitor.h"
+#include "ns3/ccnb-parser-blob.h"
+
+namespace ns3 {
+namespace CcnbParser {
+
+boost::any
+NonceVisitor::visit (Blob &n)
+{
+ // Buffer n.m_blob;
+ if (n.m_blob.GetSize ()<4)
+ throw CcnbDecodingException ();
+
+ return boost::any (n.m_blob.Begin ().ReadU32 ());
+}
+
+boost::any
+NonceVisitor::visit (Udata &n)
+{
+ // std::string n.m_udata;
+ throw CcnbDecodingException ();
+}
+
+}
+}
diff --git a/helper/ccnb-parser/visitors/ccnb-parser-nonce-visitor.h b/helper/ccnb-parser/visitors/ccnb-parser-nonce-visitor.h
new file mode 100644
index 0000000..c4912aa
--- /dev/null
+++ b/helper/ccnb-parser/visitors/ccnb-parser-nonce-visitor.h
@@ -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>
+ */
+
+#ifndef _CCNB_PARSER_NONCE_VISITOR_H_
+#define _CCNB_PARSER_NONCE_VISITOR_H_
+
+#include "ccnb-parser-no-argu-depth-first-visitor.h"
+
+namespace ns3 {
+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 NonceVisitor : 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_NONCE_VISITOR_H_
diff --git a/in-progress/ccn/ccn_name_util.h b/helper/ccnb-parser/visitors/ccnb-parser-string-visitor.cc
similarity index 66%
copy from in-progress/ccn/ccn_name_util.h
copy to helper/ccnb-parser/visitors/ccnb-parser-string-visitor.cc
index 6e5fda7..33c9465 100644
--- a/in-progress/ccn/ccn_name_util.h
+++ b/helper/ccnb-parser/visitors/ccnb-parser-string-visitor.cc
@@ -15,5 +15,28 @@
* 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>
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
*/
+
+#include "ccnb-parser-string-visitor.h"
+#include "ns3/ccnb-parser-udata.h"
+
+namespace ns3 {
+namespace CcnbParser {
+
+boost::any
+StringVisitor::visit (Blob &n)
+{
+ // Buffer n.m_blob;
+ throw CcnbDecodingException ();
+}
+
+boost::any
+StringVisitor::visit (Udata &n)
+{
+ // std::string n.m_udata;
+ return n.m_udata;
+}
+
+}
+}
diff --git a/helper/ccnb-parser/visitors/ccnb-parser-string-visitor.h b/helper/ccnb-parser/visitors/ccnb-parser-string-visitor.h
new file mode 100644
index 0000000..b2a2a29
--- /dev/null
+++ b/helper/ccnb-parser/visitors/ccnb-parser-string-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_STRING_VISITOR_H_
+#define _CCNB_PARSER_STRING_VISITOR_H_
+
+#include "ccnb-parser-no-argu-depth-first-visitor.h"
+
+namespace ns3 {
+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); ///< Throws parsing error if BLOB object is encountered
+ virtual boost::any visit (Udata &n);
+};
+
+}
+}
+
+#endif // _CCNB_PARSER_STRING_VISITOR_H_
diff --git a/helper/ccnb-parser/visitors/ccnb-parser-timestamp-visitor.cc b/helper/ccnb-parser/visitors/ccnb-parser-timestamp-visitor.cc
new file mode 100644
index 0000000..4724bb4
--- /dev/null
+++ b/helper/ccnb-parser/visitors/ccnb-parser-timestamp-visitor.cc
@@ -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>
+ */
+
+#include "ccnb-parser-timestamp-visitor.h"
+#include "ns3/ccnb-parser-blob.h"
+
+#include "ns3/nstime.h"
+
+namespace ns3 {
+namespace CcnbParser {
+
+boost::any/*Time*/
+TimestampVisitor::visit (Blob &n)
+{
+ // Buffer n.m_blob;
+ if (n.m_blob.GetSize ()<2)
+ throw CcnbDecodingException ();
+
+ Buffer::Iterator start = n.m_blob.Begin ();
+
+ intmax_t seconds = 0;
+ intmax_t nanoseconds = 0;
+
+ for (uint32_t i=0; i < n.m_blob.GetSize ()-2; i++)
+ {
+ seconds = (seconds << 8) | start.ReadU8 ();
+ }
+ uint8_t combo = start.ReadU8 (); // 4 most significant bits hold 4 least significant bits of number of seconds
+ seconds = (seconds << 8) | (combo >> 4);
+
+ nanoseconds = combo & 0x0F; /*00001111*/ // 4 least significant bits hold 4 most significant bits of number of
+ nanoseconds = (nanoseconds << 8) | start.ReadU8 ();
+ nanoseconds = (intmax_t) ((nanoseconds / 4096.0/*2^12*/) * 1000000000 /*up-convert nanoseconds*/);
+
+ return boost::any (Time::FromInteger (seconds, Time::S) + Time::FromInteger (nanoseconds, Time::NS));
+}
+
+boost::any
+TimestampVisitor::visit (Udata &n)
+{
+ // std::string n.m_udata;
+ throw CcnbDecodingException ();
+}
+
+}
+}
diff --git a/helper/ccnb-parser/visitors/ccnb-parser-timestamp-visitor.h b/helper/ccnb-parser/visitors/ccnb-parser-timestamp-visitor.h
new file mode 100644
index 0000000..ff7e8c8
--- /dev/null
+++ b/helper/ccnb-parser/visitors/ccnb-parser-timestamp-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_TIMESTAMP_VISITOR_H_
+#define _CCNB_PARSER_TIMESTAMP_VISITOR_H_
+
+#include "ccnb-parser-no-argu-depth-first-visitor.h"
+
+namespace ns3 {
+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/helper/ccnb-parser/visitors/ccnb-parser-visitor.h b/helper/ccnb-parser/visitors/ccnb-parser-visitor.h
new file mode 100644
index 0000000..aa6911b
--- /dev/null
+++ b/helper/ccnb-parser/visitors/ccnb-parser-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_VISITOR_H_
+#define _CCNB_PARSER_VISITOR_H_
+
+#include "ns3/ccnb-parser-commoh.h"
+#include <boost/any.hpp>
+
+namespace ns3 {
+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
+};
+
+}
+}
+
+#endif // _CCNB_PARSER_VISITOR_H_
diff --git a/helper/ccnb-parser/visitors/ccnb-parser-void-depth-first-visitor.cc b/helper/ccnb-parser/visitors/ccnb-parser-void-depth-first-visitor.cc
new file mode 100644
index 0000000..1c9a28a
--- /dev/null
+++ b/helper/ccnb-parser/visitors/ccnb-parser-void-depth-first-visitor.cc
@@ -0,0 +1,101 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "ccnb-parser-void-depth-first-visitor.h"
+
+#include "ns3/ccnb-parser-blob.h"
+#include "ns3/ccnb-parser-udata.h"
+#include "ns3/ccnb-parser-tag.h"
+#include "ns3/ccnb-parser-dtag.h"
+#include "ns3/ccnb-parser-attr.h"
+#include "ns3/ccnb-parser-dattr.h"
+#include "ns3/ccnb-parser-ext.h"
+
+#include <boost/foreach.hpp>
+
+namespace ns3 {
+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/helper/ccnb-parser/visitors/ccnb-parser-void-depth-first-visitor.h b/helper/ccnb-parser/visitors/ccnb-parser-void-depth-first-visitor.h
new file mode 100644
index 0000000..f2b78e3
--- /dev/null
+++ b/helper/ccnb-parser/visitors/ccnb-parser-void-depth-first-visitor.h
@@ -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>
+ */
+
+#ifndef _CCNB_PARSER_VOID_DEPTH_FIRST_VISITOR_H_
+#define _CCNB_PARSER_VOID_DEPTH_FIRST_VISITOR_H_
+
+#include "ccnb-parser-void-visitor.h"
+
+namespace ns3 {
+namespace CcnbParser {
+
+/**
+ * \ingrou 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/helper/ccnb-parser/visitors/ccnb-parser-void-no-argu-depth-first-visitor.cc b/helper/ccnb-parser/visitors/ccnb-parser-void-no-argu-depth-first-visitor.cc
new file mode 100644
index 0000000..1944b2a
--- /dev/null
+++ b/helper/ccnb-parser/visitors/ccnb-parser-void-no-argu-depth-first-visitor.cc
@@ -0,0 +1,101 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "ccnb-parser-void-no-argu-depth-first-visitor.h"
+
+#include "ns3/ccnb-parser-blob.h"
+#include "ns3/ccnb-parser-udata.h"
+#include "ns3/ccnb-parser-tag.h"
+#include "ns3/ccnb-parser-dtag.h"
+#include "ns3/ccnb-parser-attr.h"
+#include "ns3/ccnb-parser-dattr.h"
+#include "ns3/ccnb-parser-ext.h"
+
+#include <boost/foreach.hpp>
+
+namespace ns3 {
+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/helper/ccnb-parser/visitors/ccnb-parser-void-no-argu-depth-first-visitor.h b/helper/ccnb-parser/visitors/ccnb-parser-void-no-argu-depth-first-visitor.h
new file mode 100644
index 0000000..9237c2c
--- /dev/null
+++ b/helper/ccnb-parser/visitors/ccnb-parser-void-no-argu-depth-first-visitor.h
@@ -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>
+ */
+
+#ifndef _CCNB_PARSER_VOID_NO_ARGU_DEPTH_FIRST_VISITOR_H_
+#define _CCNB_PARSER_VOID_NO_ARGU_DEPTH_FIRST_VISITOR_H_
+
+#include "ccnb-parser-void-no-argu-visitor.h"
+
+namespace ns3 {
+namespace CcnbParser {
+
+/**
+ * \ingrou 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/helper/ccnb-parser/visitors/ccnb-parser-void-no-argu-visitor.h b/helper/ccnb-parser/visitors/ccnb-parser-void-no-argu-visitor.h
new file mode 100644
index 0000000..5941350
--- /dev/null
+++ b/helper/ccnb-parser/visitors/ccnb-parser-void-no-argu-visitor.h
@@ -0,0 +1,51 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef _CCNB_PARSER_VOID_NO_ARGU_VISITOR_H_
+#define _CCNB_PARSER_VOID_NO_ARGU_VISITOR_H_
+
+#include "ns3/ccnb-parser-commoh.h"
+
+namespace ns3 {
+namespace CcnbParser {
+
+/**
+ * \ingroup ccnx-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
+};
+
+}
+}
+
+#endif // _CCNB_PARSER_VOID_NO_ARGU_VISITOR_H_
diff --git a/helper/ccnb-parser/visitors/ccnb-parser-void-visitor.h b/helper/ccnb-parser/visitors/ccnb-parser-void-visitor.h
new file mode 100644
index 0000000..9ef1e3c
--- /dev/null
+++ b/helper/ccnb-parser/visitors/ccnb-parser-void-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_VOID_VISITOR_H_
+#define _CCNB_PARSER_VOID_VISITOR_H_
+
+#include "ns3/ccnb-parser-commoh.h"
+#include <boost/any.hpp>
+
+namespace ns3 {
+namespace CcnbParser {
+
+/**
+ * \ingroup ccnx-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
+};
+
+}
+}
+
+#endif // _CCNB_PARSER_VOID_VISITOR_H_
diff --git a/helper/ccnx-decoding-helper.cc b/helper/ccnx-decoding-helper.cc
index 0dabb66..1ebb0e8 100644
--- a/helper/ccnx-decoding-helper.cc
+++ b/helper/ccnx-decoding-helper.cc
@@ -20,25 +20,23 @@
#include "ccnx-decoding-helper.h"
-#include "ns3/ccnx.h"
-#include "ns3/name-components.h"
#include "ns3/ccnx-interest-header.h"
#include "ns3/ccnx-content-object-header.h"
-#include <sstream>
-#include <boost/foreach.hpp>
+#include "ns3/ccnb-parser-interest-visitor.h"
+#include "ns3/ccnb-parser-content-object-visitor.h"
+#include "ns3/ccnb-parser-block.h"
namespace ns3 {
-CcnxParser::InterestVisitor CcnxDecodingHelper::m_interestVisitor;
-CcnxParser::ContentObjectVisitor CcnxDecodingHelper::m_contentObjectVisitor;
-
size_t
CcnxDecodingHelper::Deserialize (Buffer::Iterator start, const CcnxInterestHeader &interest)
{
+ static CcnbParser::InterestVisitor interestVisitor;
+
Buffer::Iterator i = start;
- Ptr<CcnxParser::Block> root = CcnxParser::Block::ParseBlock (i);
- root->accept (m_interestVisitor, interest);
+ Ptr<CcnbParser::Block> root = CcnbParser::Block::ParseBlock (i);
+ root->accept (interestVisitor, interest);
return i.GetDistanceFrom (start);
}
@@ -46,622 +44,13 @@
size_t
CcnxDecodingHelper::Deserialize (Buffer::Iterator start, const CcnxContentObjectHeader &contentObject)
{
+ static CcnbParser::ContentObjectVisitor contentObjectVisitor;
+
Buffer::Iterator i = start;
- Ptr<CcnxParser::Block> root = CcnxParser::Block::ParseBlock (i);
- root->accept (m_contentObjectVisitor, contentObject);
+ Ptr<CcnbParser::Block> root = CcnbParser::Block::ParseBlock (i);
+ root->accept (contentObjectVisitor, contentObject);
return i.GetDistanceFrom (start);
}
-
-//////////////////////////////////////////////////////////////////////
-
-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));
-
-namespace CcnxParser {
-
-Ptr<Block> Block::ParseBlock (Buffer::Iterator &start)
-{
- uint32_t value = 0;
-
- // We will have problems if length field is more than 32 bits. Though it's really impossible
- uint8_t byte = 0;
- while (!(byte & CCN_TT_HBIT))
- {
- value <<= 8;
- value += byte;
- byte = start.ReadU8 ();
- }
- value <<= 4;
- value += ( (byte&(~CCN_TT_HBIT)) >> 3);
-
- switch (byte & CCN_TT_MASK)
- {
- case Ccnx::CCN_BLOB:
- return Create<Blob> (start, value);
- case Ccnx::CCN_UDATA:
- return Create<Udata> (start, value);
- case Ccnx::CCN_TAG:
- return Create<Tag> (start, value);
- case Ccnx::CCN_ATTR:
- return Create<Attr> (start, value);
- case Ccnx::CCN_DTAG:
- return Create<Dtag> (start, value);
- case Ccnx::CCN_DATTR:
- return Create<Dattr> (start, value);
- case Ccnx::CCN_EXT:
- return Create<Ext> (start, value);
- default:
- throw CcnxDecodingException ();
- }
-}
-
-Blob::Blob (Buffer::Iterator &start, uint32_t length)
-{
- start.Read (m_blob.Begin (), length);
-}
-
-Udata::Udata (Buffer::Iterator &start, uint32_t length)
-{
- // Ideally, the code should look like this. Unfortunately, we don't have normal compatible iterators
- // Buffer::Iterator realStart = start;
- // start.Next (length); // advancing forward
- // m_udata.assign (realStart, start/*actually, it is the end*/);
-
- m_udata.reserve (length+1); //just in case we will need \0 at the end later
- // this is actually the way Read method is implemented in network/src/buffer.cc
- for (uint32_t i = 0; i < length; i++)
- {
- m_udata.push_back (start.ReadU8 ());
- }
-}
-
-// length length in octets of UTF-8 encoding of tag name - 1 (minimum tag name length is 1)
-Tag::Tag (Buffer::Iterator &start, uint32_t length)
-{
- m_tag.reserve (length+2); // extra byte for potential \0 at the end
- for (uint32_t i = 0; i < (length+1); i++)
- {
- m_tag.push_back (start.ReadU8 ());
- }
-
- while (!start.IsEnd () && start.PeekU8 ()!=Ccnx::CCN_CLOSE)
- {
- m_nestedBlocks.push_back (Block::ParseBlock (start));
- }
- if (start.IsEnd ())
- throw CcnxDecodingException ();
-
- start.ReadU8 (); // read CCN_CLOSE
-}
-
-// length length in octets of UTF-8 encoding of tag name - 1 (minimum tag name length is 1)
-Attr::Attr (Buffer::Iterator &start, uint32_t length)
-{
- m_attr.reserve (length+2); // extra byte for potential \0 at the end
- for (uint32_t i = 0; i < (length+1); i++)
- {
- m_attr.push_back (start.ReadU8 ());
- }
- m_value = DynamicCast<Udata> (Block::ParseBlock (start));
- if (m_value == 0)
- throw CcnxDecodingException (); // "ATTR must be followed by UDATA field"
-}
-
-Dtag::Dtag (Buffer::Iterator &start, uint32_t dtag)
-{
- m_dtag = dtag;
-
- /**
- * Hack
- *
- * Stop processing after encountering <Content> dtag. Actual
- * content (including virtual payload) will be stored in Packet
- * buffer
- */
- if (dtag == Ccnx::CCN_DTAG_Content)
- return; // hack #1. Do not process nesting block for <Content>
-
- while (!start.IsEnd () && start.PeekU8 ()!=Ccnx::CCN_CLOSE)
- {
- m_nestedBlocks.push_back (Block::ParseBlock (start));
-
- // hack #2. Stop processing nested blocks if last block was <Content>
- if (m_dtag == Ccnx::CCN_DTAG_ContentObject && // we are in <ContentObject>
- DynamicCast<Dtag> (m_nestedBlocks.back())!=0 && // last block is DTAG
- DynamicCast<Dtag> (m_nestedBlocks.back())->m_dtag == Ccnx::CCN_DTAG_Content)
- {
- return;
- }
- }
- if (start.IsEnd ())
- throw CcnxDecodingException ();
-
- start.ReadU8 (); // read CCN_CLOSE
-}
-
-// dictionary attributes are not used (yet?) in CCNx
-Dattr::Dattr (Buffer::Iterator &start, uint32_t dattr)
-{
- m_dattr = dattr;
- m_value = DynamicCast<Udata> (Block::ParseBlock (start));
- if (m_value == 0)
- throw CcnxDecodingException (); // "ATTR must be followed by UDATA field"
-}
-
-Ext::Ext (Buffer::Iterator &start, uint32_t extSubtype)
-{
- m_extSubtype = extSubtype;
-}
-
-void
-DepthFirstVisitor::visit (Blob &n)
-{
- // Buffer n.m_blob;
-}
-
-void
-DepthFirstVisitor::visit (Udata &n)
-{
- // std::string n.m_udata;
-}
-
-void
-DepthFirstVisitor::visit (Tag &n)
-{
- // std::string n.m_tag;
- // std::list<Ptr<Block> > n.m_nestedBlocks;
- BOOST_FOREACH (Ptr<Block> block, n.m_nestedBlocks)
- {
- block->accept (*this);
- }
-}
-
-void
-DepthFirstVisitor::visit (Attr &n)
-{
- // std::string n.m_attr;
- // Ptr<Udata> n.m_value;
-}
-
-void
-DepthFirstVisitor::visit (Dtag &n)
-{
- // uint32_t n.m_dtag;
- // std::list<Ptr<Block> > n.m_nestedBlocks;
- BOOST_FOREACH (Ptr<Block> block, n.m_nestedBlocks)
- {
- block->accept (*this);
- }
-}
-
-void
-DepthFirstVisitor::visit (Dattr &n)
-{
- // uint32_t n.m_dattr;
- // Ptr<Udata> n.m_value;
-}
-
-void
-DepthFirstVisitor::visit (Ext &n)
-{
- // uint64_t n.m_extSubtype;
-}
-
-//////////////////////////////////////////////////////////////////////
-
-boost::any
-GJNoArguDepthFirstVisitor::visit (Blob &n)
-{
- // Buffer n.m_blob;
- return n.m_blob;
-}
-
-boost::any
-GJNoArguDepthFirstVisitor::visit (Udata &n)
-{
- // std::string n.m_udata;
- return n.m_udata;
-}
-
-boost::any
-GJNoArguDepthFirstVisitor::visit (Tag &n)
-{
- // std::string n.m_tag;
- // std::list<Ptr<Block> > n.m_nestedBlocks;
- BOOST_FOREACH (Ptr<Block> block, n.m_nestedBlocks)
- {
- block->accept (*this);
- }
- return boost::any();
-}
-
-boost::any
-GJNoArguDepthFirstVisitor::visit (Attr &n)
-{
- // std::string n.m_attr;
- // Ptr<Udata> n.m_value;
- return boost::any(
- std::pair<std::string,std::string> (
- n.m_attr,
- boost::any_cast<std::string> (n.m_value->accept (*this))
- ));
-}
-
-boost::any
-GJNoArguDepthFirstVisitor::visit (Dtag &n)
-{
- // uint32_t n.m_dtag;
- // std::list<Ptr<Block> > n.m_nestedBlocks;
- BOOST_FOREACH (Ptr<Block> block, n.m_nestedBlocks)
- {
- block->accept (*this);
- }
- return boost::any();
-}
-
-boost::any
-GJNoArguDepthFirstVisitor::visit (Dattr &n)
-{
- // uint32_t n.m_dattr;
- // Ptr<Udata> n.m_value;
- return boost::any(
- std::pair<uint32_t,std::string> (
- n.m_dattr,
- boost::any_cast<std::string> (n.m_value->accept (*this))
- ));
-}
-
-boost::any
-GJNoArguDepthFirstVisitor::visit (Ext &n)
-{
- // uint64_t n.m_extSubtype;
- return n.m_extSubtype;
-}
-
-//////////////////////////////////////////////////////////////////////
-
-void
-GJVoidDepthFirstVisitor::visit (Blob &n, boost::any param)
-{
- // Buffer n.m_blob;
-}
-
-void
-GJVoidDepthFirstVisitor::visit (Udata &n, boost::any param)
-{
- // std::string n.m_udata;
-}
-
-void
-GJVoidDepthFirstVisitor::visit (Tag &n, boost::any param)
-{
- // std::string n.m_tag;
- // std::list<Ptr<Block> > n.m_nestedBlocks;
- BOOST_FOREACH (Ptr<Block> block, n.m_nestedBlocks)
- {
- block->accept (*this, param);
- }
-}
-
-void
-GJVoidDepthFirstVisitor::visit (Attr &n, boost::any param)
-{
- // std::string n.m_attr;
- // Ptr<Udata> n.m_value;
-}
-
-void
-GJVoidDepthFirstVisitor::visit (Dtag &n, boost::any param)
-{
- // uint32_t n.m_dtag;
- // std::list<Ptr<Block> > n.m_nestedBlocks;
- BOOST_FOREACH (Ptr<Block> block, n.m_nestedBlocks)
- {
- block->accept (*this, param);
- }
-}
-
-void
-GJVoidDepthFirstVisitor::visit (Dattr &n, boost::any param)
-{
- // uint32_t n.m_dattr;
- // Ptr<Udata> n.m_value;
-}
-
-void
-GJVoidDepthFirstVisitor::visit (Ext &n, boost::any param)
-{
- // uint64_t n.m_extSubtype;
-}
-
-//////////////////////////////////////////////////////////////////////
-
-boost::any
-GJDepthFirstVisitor::visit (Blob &n, boost::any param)
-{
- // Buffer n.m_blob;
- return n.m_blob;
-}
-
-boost::any
-GJDepthFirstVisitor::visit (Udata &n, boost::any param)
-{
- // std::string n.m_udata;
- return n.m_udata;
-}
-
-boost::any
-GJDepthFirstVisitor::visit (Tag &n, boost::any param)
-{
- // std::string n.m_tag;
- // std::list<Ptr<Block> > n.m_nestedBlocks;
- BOOST_FOREACH (Ptr<Block> block, n.m_nestedBlocks)
- {
- block->accept (*this, param);
- }
- return boost::any();
-}
-
-boost::any
-GJDepthFirstVisitor::visit (Attr &n, boost::any param)
-{
- // std::string n.m_attr;
- // Ptr<Udata> n.m_value;
- return boost::any(
- std::pair<std::string,std::string> (
- n.m_attr,
- boost::any_cast<std::string> (n.m_value->accept (*this,param))
- ));
-}
-
-boost::any
-GJDepthFirstVisitor::visit (Dtag &n, boost::any param)
-{
- // uint32_t n.m_dtag;
- // std::list<Ptr<Block> > n.m_nestedBlocks;
- BOOST_FOREACH (Ptr<Block> block, n.m_nestedBlocks)
- {
- block->accept (*this, param);
- }
- return boost::any();
-}
-
-boost::any
-GJDepthFirstVisitor::visit (Dattr &n, boost::any param)
-{
- // uint32_t n.m_dattr;
- // Ptr<Udata> n.m_value;
- return boost::any(
- std::pair<uint32_t,std::string> (
- n.m_dattr,
- boost::any_cast<std::string> (n.m_value->accept (*this,param))
- ));
-}
-
-boost::any
-GJDepthFirstVisitor::visit (Ext &n, boost::any param)
-{
- // uint64_t n.m_extSubtype;
- return n.m_extSubtype;
-}
-
-//////////////////////////////////////////////////////////////////////
-
-boost::any
-NonNegativeIntegerVisitor::visit (Blob &n) //to throw parsing error
-{
- // Buffer n.m_blob;
- throw CcnxDecodingException ();
-}
-
-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 CcnxDecodingException ();
-
- return static_cast<uint32_t> (value);
-}
-
-
-//////////////////////////////////////////////////////////////////////
-
-boost::any
-StringVisitor::visit (Blob &n) //to throw parsing error
-{
- // Buffer n.m_blob;
- throw CcnxDecodingException ();
-}
-
-boost::any
-StringVisitor::visit (Udata &n)
-{
- // std::string n.m_udata;
- return n.m_udata;
-}
-
-//////////////////////////////////////////////////////////////////////
-
-StringVisitor NameComponentsVisitor::m_stringVisitor;
-
-void
-NameComponentsVisitor::visit (Dtag &n, boost::any param/*should be Name::Components&*/)
-{
- // uint32_t n.m_dtag;
- // std::list<Ptr<Block> > n.m_nestedBlocks;
- Name::Components &components = boost::any_cast<Name::Components&> (param);
-
- switch (n.m_dtag)
- {
- case Ccnx::CCN_DTAG_Component:
- if (n.m_nestedBlocks.size()!=1) // should be exactly one UDATA inside this tag
- throw CcnxDecodingException ();
- components.Add (
- boost::any_cast<std::string> ((*n.m_nestedBlocks.begin())->accept(
- m_stringVisitor
- )));
- break;
- default:
- // ignore any other components
- // when parsing Exclude, there could be <Any /> and <Bloom /> tags
- break;
- }
-}
-
-//////////////////////////////////////////////////////////////////////
-
-NonNegativeIntegerVisitor InterestVisitor::m_nonNegativeIntegerVisitor;
-NameComponentsVisitor InterestVisitor::m_nameComponentsVisitor;
-
-// We don't really care about any other fields
-void
-InterestVisitor::visit (Dtag &n, boost::any param/*should be CcnxInterestHeader&*/)
-{
- // uint32_t n.m_dtag;
- // std::list<Ptr<Block> > n.m_nestedBlocks;
- CcnxInterestHeader &interest = boost::any_cast<CcnxInterestHeader&> (param);
-
- switch (n.m_dtag)
- {
- case Ccnx::CCN_DTAG_Interest:
- // process nested blocks
- BOOST_FOREACH (Ptr<Block> block, n.m_nestedBlocks)
- {
- block->accept (*this, param);
- }
- break;
- case Ccnx::CCN_DTAG_Name:
- {
- // process name components
- Ptr<Name::Components> name = Create<Name::Components> ();
-
- BOOST_FOREACH (Ptr<Block> block, n.m_nestedBlocks)
- {
- block->accept (m_nameComponentsVisitor, *name);
- }
- interest.SetName (name);
- break;
- }
- case Ccnx::CCN_DTAG_MinSuffixComponents:
- if (n.m_nestedBlocks.size()!=1) // should be exactly one UDATA inside this tag
- throw CcnxDecodingException ();
- interest.SetMinSuffixComponents (
- boost::any_cast<uint32_t> (
- (*n.m_nestedBlocks.begin())->accept(
- m_nonNegativeIntegerVisitor
- )));
- break;
- case Ccnx::CCN_DTAG_MaxSuffixComponents:
- if (n.m_nestedBlocks.size()!=1) // should be exactly one UDATA inside this tag
- throw CcnxDecodingException ();
- interest.SetMaxSuffixComponents (
- boost::any_cast<uint32_t> (
- (*n.m_nestedBlocks.begin())->accept(
- m_nonNegativeIntegerVisitor
- )));
- break;
- case Ccnx::CCN_DTAG_Exclude:
- {
- // process exclude components
- Ptr<Name::Components> exclude = Create<Name::Components> ();
-
- BOOST_FOREACH (Ptr<Block> block, n.m_nestedBlocks)
- {
- block->accept (m_nameComponentsVisitor, *exclude);
- }
- interest.SetExclude (exclude);
- break;
- }
- case Ccnx::CCN_DTAG_ChildSelector:
- if (n.m_nestedBlocks.size()!=1) // should be exactly one UDATA inside this tag
- throw CcnxDecodingException ();
-
- interest.SetChildSelector (
- 1 == boost::any_cast<uint32_t> (
- (*n.m_nestedBlocks.begin())->accept(
- m_nonNegativeIntegerVisitor
- )));
- break;
- case Ccnx::CCN_DTAG_AnswerOriginKind:
- if (n.m_nestedBlocks.size()!=1) // should be exactly one UDATA inside this tag
- throw CcnxDecodingException ();
- interest.SetAnswerOriginKind (
- 1 == boost::any_cast<uint32_t> (
- (*n.m_nestedBlocks.begin())->accept(
- m_nonNegativeIntegerVisitor
- )));
- break;
- case Ccnx::CCN_DTAG_Scope:
- if (n.m_nestedBlocks.size()!=1) // should be exactly one UDATA inside this tag
- throw CcnxDecodingException ();
- interest.SetScope (
- boost::any_cast<uint32_t> (
- (*n.m_nestedBlocks.begin())->accept(
- m_nonNegativeIntegerVisitor
- )));
- break;
- case Ccnx::CCN_DTAG_InterestLifetime:
- if (n.m_nestedBlocks.size()!=1) // should be exactly one UDATA inside this tag
- throw CcnxDecodingException ();
- break;
- case Ccnx::CCN_DTAG_Nonce:
- if (n.m_nestedBlocks.size()!=1) // should be exactly one UDATA inside this tag
- throw CcnxDecodingException ();
- break;
- }
-}
-
-//////////////////////////////////////////////////////////////////////
-
-NameComponentsVisitor ContentObjectVisitor::m_nameComponentsVisitor;
-
-// We don't really care about any other fields
-void
-ContentObjectVisitor::visit (Dtag &n, boost::any param/*should be CcnxContentObjectHeader&*/)
-{
- // uint32_t n.m_dtag;
- // std::list<Ptr<Block> > n.m_nestedBlocks;
- CcnxContentObjectHeader &contentObject = boost::any_cast<CcnxContentObjectHeader&> (param);
-
- switch (n.m_dtag)
- {
- case Ccnx::CCN_DTAG_ContentObject:
- // process nested blocks
- BOOST_FOREACH (Ptr<Block> block, n.m_nestedBlocks)
- {
- block->accept (*this, param);
- }
- break;
- case Ccnx::CCN_DTAG_Name:
- {
- // process name components
- Ptr<Name::Components> name = Create<Name::Components> ();
-
- BOOST_FOREACH (Ptr<Block> block, n.m_nestedBlocks)
- {
- block->accept (m_nameComponentsVisitor, *name);
- }
- contentObject.SetName (name);
- break;
- }
- case Ccnx::CCN_DTAG_Signature: // ignoring
- break;
- case Ccnx::CCN_DTAG_SignedInfo: // ignoring
- break;
- case Ccnx::CCN_DTAG_Content: // !!! HACK
- // This hack was necessary for memory optimizations (i.e., content is virtual payload)
- NS_ASSERT_MSG (n.m_nestedBlocks.size() == 0, "Parser should have stopped just after processing <Content> tag");
- break;
- }
-}
-
-} // namespace CcnxParser
} // namespace ns3
diff --git a/helper/ccnx-decoding-helper.h b/helper/ccnx-decoding-helper.h
index e89766c..2e41769 100644
--- a/helper/ccnx-decoding-helper.h
+++ b/helper/ccnx-decoding-helper.h
@@ -15,37 +15,22 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Author:
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
*/
#ifndef _CCNX_DECODING_HELPER_H_
#define _CCNX_DECODING_HELPER_H_
-#include <sys/types.h>
-#include <boost/any.hpp>
-#include <list>
-
-#include "ns3/ptr.h"
-#include "ns3/nstime.h"
+#include <cstring>
#include "ns3/buffer.h"
-#include "ns3/simple-ref-count.h"
-
namespace ns3 {
-namespace Name{ class Components; }
-
class CcnxInterestHeader;
class CcnxContentObjectHeader;
-namespace CcnxParser {
-class InterestVisitor;
-class ContentObjectVisitor;
-}
-
/**
- * Helper to encode/decode ccnb formatted CCNx message
- *
+ * \brief Helper class to decode ccnb formatted CCNx message
*/
class CcnxDecodingHelper
{
@@ -57,276 +42,8 @@
Deserialize (Buffer::Iterator start, const CcnxContentObjectHeader &contentObject);
private:
- static CcnxParser::InterestVisitor m_interestVisitor;
- static CcnxParser::ContentObjectVisitor m_contentObjectVisitor;
};
-namespace CcnxParser {
-
-class Block;
-class Blob;
-class Udata;
-class Tag;
-class Attr;
-class Dtag;
-class Dattr;
-class Ext;
-
-class Visitor
-{
-public:
- virtual void visit (Blob& )=0;
- virtual void visit (Udata&)=0;
- virtual void visit (Tag& )=0;
- virtual void visit (Attr& )=0;
- virtual void visit (Dtag& )=0;
- virtual void visit (Dattr&)=0;
- virtual void visit (Ext& )=0;
-};
-
-class GJVisitor
-{
-public:
- virtual boost::any visit (Blob&, boost::any)=0;
- virtual boost::any visit (Udata&, boost::any)=0;
- virtual boost::any visit (Tag&, boost::any)=0;
- virtual boost::any visit (Attr&, boost::any)=0;
- virtual boost::any visit (Dtag&, boost::any)=0;
- virtual boost::any visit (Dattr&, boost::any)=0;
- virtual boost::any visit (Ext&, boost::any)=0;
-};
-
-class GJNoArguVisitor
-{
-public:
- virtual boost::any visit (Blob& )=0;
- virtual boost::any visit (Udata&)=0;
- virtual boost::any visit (Tag& )=0;
- virtual boost::any visit (Attr& )=0;
- virtual boost::any visit (Dtag& )=0;
- virtual boost::any visit (Dattr&)=0;
- virtual boost::any visit (Ext& )=0;
-};
-
-class GJVoidVisitor
-{
-public:
- virtual void visit (Blob&, boost::any)=0;
- virtual void visit (Udata&, boost::any)=0;
- virtual void visit (Tag&, boost::any)=0;
- virtual void visit (Attr&, boost::any)=0;
- virtual void visit (Dtag&, boost::any)=0;
- virtual void visit (Dattr&, boost::any)=0;
- virtual void visit (Ext&, boost::any)=0;
-};
-
-class Block : public SimpleRefCount<Block>
-{
-public:
- /**
- * Parsing block header and creating an appropriate object
- */
- static Ptr<Block>
- ParseBlock (Buffer::Iterator &start);
-
- virtual void accept( Visitor &v ) =0;
- virtual void accept (GJVoidVisitor &v, boost::any param) =0;
- virtual boost::any accept( GJNoArguVisitor &v ) =0;
- virtual boost::any accept( GJVisitor &v, boost::any param ) =0;
-};
-
-class Blob : public Block
-{
-public:
- Blob (Buffer::Iterator &start, uint32_t length);
-
- virtual void accept( Visitor &v ) { v.visit( *this ); }
- virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); }
- virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); }
- virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); }
-
- Buffer m_blob;
-};
-
-class Udata : public Block
-{
-public:
- Udata (Buffer::Iterator &start, uint32_t length);
-
- virtual void accept( Visitor &v ) { v.visit( *this ); }
- virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); }
- virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); }
- virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); }
-
- std::string m_udata;
-};
-
-class Tag : public Block
-{
-public:
- Tag (Buffer::Iterator &start, uint32_t length);
-
- virtual void accept( Visitor &v ) { v.visit( *this ); }
- virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); }
- virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); }
- virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); }
-
- std::string m_tag;
- std::list<Ptr<Block> > m_nestedBlocks;
-};
-
-class Attr : public Block
-{
-public:
- Attr (Buffer::Iterator &start, uint32_t length);
-
- virtual void accept( Visitor &v ) { v.visit( *this ); }
- virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); }
- virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); }
- virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); }
-
- std::string m_attr;
- Ptr<Udata> m_value;
-};
-
-class Dtag : public Block
-{
-public:
- Dtag (Buffer::Iterator &start, uint32_t dtag);
-
- virtual void accept( Visitor &v ) { v.visit( *this ); }
- virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); }
- virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); }
- virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); }
-
- uint32_t m_dtag;
- std::list<Ptr<Block> > m_nestedBlocks;
-};
-
-class Dattr : public Block
-{
-public:
- Dattr (Buffer::Iterator &start, uint32_t dattr);
-
- virtual void accept( Visitor &v ) { v.visit( *this ); }
- virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); }
- virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); }
- virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); }
-
- uint32_t m_dattr;
- Ptr<Udata> m_value;
-};
-
-class Ext : public Block
-{
-public:
- Ext (Buffer::Iterator &start, uint32_t extSubtype);
-
- virtual void accept( Visitor &v ) { v.visit( *this ); }
- virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); }
- virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); }
- virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); }
-
- uint64_t m_extSubtype;
-};
-
-class DepthFirstVisitor : public Visitor
-{
-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& );
-};
-
-class GJDepthFirstVisitor : public GJVisitor
-{
-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);
-};
-
-class GJNoArguDepthFirstVisitor : public GJNoArguVisitor
-{
-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& );
-};
-
-class GJVoidDepthFirstVisitor : public GJVoidVisitor
-{
-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);
-};
-
-// class NameComponentsVisitor : public
-
-class NonNegativeIntegerVisitor : public GJNoArguDepthFirstVisitor
-{
-public:
- virtual boost::any visit (Blob &n); //to throw parsing error
- virtual boost::any visit (Udata &n);
-};
-
-class StringVisitor : public GJNoArguDepthFirstVisitor
-{
-public:
- virtual boost::any visit (Blob &n); //to throw parsing error
- virtual boost::any visit (Udata &n);
-};
-
-class NameComponentsVisitor : public GJVoidDepthFirstVisitor
-{
-public:
- virtual void visit (Dtag &n, boost::any param/*should be Name::Components*/);
-private:
- static StringVisitor m_stringVisitor;
-};
-
-class InterestVisitor : public GJVoidDepthFirstVisitor
-{
-public:
- virtual void visit (Dtag &n, boost::any param/*should be CcnxInterestHeader&*/);
-
-private:
- static NonNegativeIntegerVisitor m_nonNegativeIntegerVisitor;
- static NameComponentsVisitor m_nameComponentsVisitor;
-};
-
-class ContentObjectVisitor : public GJVoidDepthFirstVisitor
-{
-public:
- virtual void visit (Dtag &n, boost::any param/*should be CcnxContentObjectHeader&*/);
-
-private:
- static NameComponentsVisitor m_nameComponentsVisitor;
-};
-
-
-class CcnxDecodingException {};
-
-} // namespace CcnxParser
-
} // namespace ns3
#endif // _CCNX_DECODING_HELPER_H_
-
diff --git a/helper/ccnx-encoding-helper.cc b/helper/ccnx-encoding-helper.cc
index 21ca9ae..7783d7a 100644
--- a/helper/ccnx-encoding-helper.cc
+++ b/helper/ccnx-encoding-helper.cc
@@ -35,17 +35,17 @@
#define CCN_TT_HBIT ((unsigned char)(1 << 7))
size_t
-CcnxEncodingHelper::AppendBlockHeader (Buffer::Iterator start, size_t val, Ccnx::ccn_tt tt)
+CcnxEncodingHelper::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 & ~Ccnx::CCN_CLOSE) |
+ 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) | Ccnx::CCN_CLOSE;
+ (--p)[0] = (((unsigned char)val) & ~CCN_TT_HBIT) | CcnbParser::CCN_CLOSE;
n++;
val >>= 7;
}
@@ -60,7 +60,7 @@
os << number;
size_t written = 0;
- written += AppendBlockHeader (start, os.str().size(), Ccnx::CCN_UDATA);
+ 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());
@@ -71,7 +71,7 @@
size_t
CcnxEncodingHelper::CcnxEncodingHelper::AppendCloser (Buffer::Iterator start)
{
- start.WriteU8 (Ccnx::CCN_CLOSE);
+ start.WriteU8 (CcnbParser::CCN_CLOSE);
return 1;
}
@@ -81,7 +81,7 @@
size_t written = 0;
BOOST_FOREACH (const std::string &component, name.GetComponents())
{
- written += AppendTaggedBlob (start, Ccnx::CCN_DTAG_Component,
+ written += AppendTaggedBlob (start, CcnbParser::CCN_DTAG_Component,
reinterpret_cast<const uint8_t*>(component.c_str()), component.size());
}
return written;
@@ -98,7 +98,7 @@
for (; required_bytes < 7 && ts != 0; ts >>= 8) // not more than 6 bytes?
required_bytes++;
- size_t len = AppendBlockHeader(start, required_bytes, Ccnx::CCN_BLOB);
+ size_t len = AppendBlockHeader(start, required_bytes, CcnbParser::CCN_BLOB);
// write part with seconds
ts = time.ToInteger (Time::S) >> 4;
@@ -114,13 +114,13 @@
}
size_t
-CcnxEncodingHelper::AppendTaggedBlob (Buffer::Iterator start, Ccnx::ccn_dtag dtag,
+CcnxEncodingHelper::AppendTaggedBlob (Buffer::Iterator start, CcnbParser::ccn_dtag dtag,
const uint8_t *data, size_t size)
{
- size_t written = AppendBlockHeader (start, dtag, Ccnx::CCN_DTAG);
+ size_t written = AppendBlockHeader (start, dtag, CcnbParser::CCN_DTAG);
if (size>0)
{
- written += AppendBlockHeader (start, size, Ccnx::CCN_BLOB);
+ written += AppendBlockHeader (start, size, CcnbParser::CCN_BLOB);
start.Write (data, size);
written += size;
}
@@ -134,58 +134,58 @@
CcnxEncodingHelper::Serialize (Buffer::Iterator start, const CcnxInterestHeader &interest)
{
size_t written = 0;
- written += AppendBlockHeader (start, Ccnx::CCN_DTAG_Interest, Ccnx::CCN_DTAG); // <Interest>
+ written += AppendBlockHeader (start, CcnbParser::CCN_DTAG_Interest, CcnbParser::CCN_DTAG); // <Interest>
- written += AppendBlockHeader (start, Ccnx::CCN_DTAG_Name, Ccnx::CCN_DTAG); // <Name>
+ 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, Ccnx::CCN_DTAG_MinSuffixComponents, Ccnx::CCN_DTAG);
+ 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, Ccnx::CCN_DTAG_MaxSuffixComponents, Ccnx::CCN_DTAG);
+ written += AppendBlockHeader (start, CcnbParser::CCN_DTAG_MaxSuffixComponents, CcnbParser::CCN_DTAG);
written += AppendNumber (start, interest.GetMaxSuffixComponents ());
written += AppendCloser (start);
}
if (interest.GetExclude().size() > 0)
{
- written += AppendBlockHeader (start, Ccnx::CCN_DTAG_Exclude, Ccnx::CCN_DTAG); // <Exclude>
+ 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, Ccnx::CCN_DTAG_ChildSelector, Ccnx::CCN_DTAG);
+ written += AppendBlockHeader (start, CcnbParser::CCN_DTAG_ChildSelector, CcnbParser::CCN_DTAG);
written += AppendNumber (start, 1);
written += AppendCloser (start);
}
if (interest.IsEnabledAnswerOriginKind())
{
- written += AppendBlockHeader (start, Ccnx::CCN_DTAG_AnswerOriginKind, Ccnx::CCN_DTAG);
+ written += AppendBlockHeader (start, CcnbParser::CCN_DTAG_AnswerOriginKind, CcnbParser::CCN_DTAG);
written += AppendNumber (start, 1);
written += AppendCloser (start);
}
if (interest.GetScope() >= 0)
{
- written += AppendBlockHeader (start, Ccnx::CCN_DTAG_Scope, Ccnx::CCN_DTAG);
+ 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, Ccnx::CCN_DTAG_InterestLifetime, Ccnx::CCN_DTAG);
+ 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, Ccnx::CCN_DTAG_Nonce,
+ written += AppendTaggedBlob (start, CcnbParser::CCN_DTAG_Nonce,
reinterpret_cast<const uint8_t*>(&nonce),
sizeof(nonce));
}
@@ -198,32 +198,32 @@
CcnxEncodingHelper::Serialize (Buffer::Iterator start, const CcnxContentObjectHeader &contentObject)
{
size_t written = 0;
- written += AppendBlockHeader (start, Ccnx::CCN_DTAG_ContentObject, Ccnx::CCN_DTAG); // <ContentObject>
+ written += AppendBlockHeader (start, CcnbParser::CCN_DTAG_ContentObject, CcnbParser::CCN_DTAG); // <ContentObject>
// fake signature
- written += AppendBlockHeader (start, Ccnx::CCN_DTAG_Signature, Ccnx::CCN_DTAG); // <Signature>
+ written += AppendBlockHeader (start, CcnbParser::CCN_DTAG_Signature, CcnbParser::CCN_DTAG); // <Signature>
// Signature ::= DigestAlgorithm?
// Witness?
// SignatureBits
- written += AppendTaggedBlob (start, Ccnx::CCN_DTAG_SignatureBits, 0, 0); // <SignatureBits />
+ written += AppendTaggedBlob (start, CcnbParser::CCN_DTAG_SignatureBits, 0, 0); // <SignatureBits />
written += AppendCloser (start); // </Signature>
- written += AppendBlockHeader (start, Ccnx::CCN_DTAG_Name, Ccnx::CCN_DTAG); // <Name>
+ written += AppendBlockHeader (start, CcnbParser::CCN_DTAG_Name, CcnbParser::CCN_DTAG); // <Name>
written += AppendNameComponents (start, contentObject.GetName()); // <Component>...</Component>...
written += AppendCloser (start); // </Name>
// fake signature
- written += AppendBlockHeader (start, Ccnx::CCN_DTAG_SignedInfo, Ccnx::CCN_DTAG); // <SignedInfo>
+ written += AppendBlockHeader (start, CcnbParser::CCN_DTAG_SignedInfo, CcnbParser::CCN_DTAG); // <SignedInfo>
// SignedInfo ::= PublisherPublicKeyDigest
// Timestamp
// Type?
// FreshnessSeconds?
// FinalBlockID?
// KeyLocator?
- written += AppendTaggedBlob (start, Ccnx::CCN_DTAG_PublisherPublicKeyDigest, 0, 0); // <PublisherPublicKeyDigest />
+ written += AppendTaggedBlob (start, CcnbParser::CCN_DTAG_PublisherPublicKeyDigest, 0, 0); // <PublisherPublicKeyDigest />
written += AppendCloser (start); // </SignedInfo>
- written += AppendBlockHeader (start, Ccnx::CCN_DTAG_Content, Ccnx::CCN_DTAG); // <Content>
+ written += AppendBlockHeader (start, CcnbParser::CCN_DTAG_Content, CcnbParser::CCN_DTAG); // <Content>
// there is no closing tag !!!
return written;
diff --git a/helper/ccnx-encoding-helper.h b/helper/ccnx-encoding-helper.h
index 90fad22..da5066a 100644
--- a/helper/ccnx-encoding-helper.h
+++ b/helper/ccnx-encoding-helper.h
@@ -23,7 +23,7 @@
#include <sys/types.h>
-#include "ns3/ccnx.h"
+#include "ns3/ccnb-parser-common.h"
#include "ns3/ptr.h"
#include "ns3/nstime.h"
#include "ns3/buffer.h"
@@ -50,7 +50,7 @@
private:
static size_t
- AppendBlockHeader (Buffer::Iterator start, size_t value, Ccnx::ccn_tt block_type);
+ AppendBlockHeader (Buffer::Iterator start, size_t value, CcnbParser::ccn_tt block_type);
static size_t
AppendNumber (Buffer::Iterator start, uint32_t number);
@@ -86,7 +86,7 @@
* @returns written length
*/
static size_t
- AppendTaggedBlob (Buffer::Iterator start, Ccnx::ccn_dtag dtag,
+ AppendTaggedBlob (Buffer::Iterator start, CcnbParser::ccn_dtag dtag,
const uint8_t *data, size_t size);
};
diff --git a/helper/ccnx-face-container.cc b/helper/ccnx-face-container.cc
index 956614d..ce595bb 100644
--- a/helper/ccnx-face-container.cc
+++ b/helper/ccnx-face-container.cc
@@ -19,8 +19,7 @@
*/
#include "ccnx-face-container.h"
-// #include "ns3/node-list.h"
-// #include "ns3/names.h"
+
#include <algorithm>
#include "ns3/ccnx-face.h"
@@ -47,6 +46,12 @@
void
+CcnxFaceContainer::AddAll (Ptr<CcnxFaceContainer> other)
+{
+ AddAll (*other);
+}
+
+void
CcnxFaceContainer::AddAll (const CcnxFaceContainer &other)
{
m_faces.insert (m_faces.end (),
diff --git a/helper/ccnx-face-container.h b/helper/ccnx-face-container.h
index 4426449..ecb29d9 100644
--- a/helper/ccnx-face-container.h
+++ b/helper/ccnx-face-container.h
@@ -23,20 +23,24 @@
#include <stdint.h>
#include <vector>
-#include "ns3/ccnx.h"
+
+#include "ns3/ptr.h"
+#include "ns3/simple-ref-count.h"
namespace ns3 {
+class CcnxFace;
+
/**
- * \ingroup ccnx
+ * \ingroup ccnx-helpers
* \brief A pool for CCNx faces
*
* Provides tools to perform basic manipulation on faces, such as
* setting metrics and states on faces
*
- * \see Ccnx
+ * \see CcnxStackHelper
*/
-class CcnxFaceContainer
+class CcnxFaceContainer : public SimpleRefCount<CcnxFaceContainer>
{
private:
typedef std::vector<Ptr<CcnxFace> > FaceContainer;
@@ -67,6 +71,13 @@
/**
* \brief Add all entries from other container
*
+ * \param other smart pointer to a container
+ */
+ void AddAll (Ptr<CcnxFaceContainer> other);
+
+ /**
+ * \brief Add all entries from other container
+ *
* \param other container
*/
void AddAll (const CcnxFaceContainer &other);
diff --git a/helper/ccnx-forwarding-helper.h b/helper/ccnx-forwarding-helper.h
index a7d0bf8..8ac041e 100644
--- a/helper/ccnx-forwarding-helper.h
+++ b/helper/ccnx-forwarding-helper.h
@@ -30,13 +30,11 @@
class Node;
/**
+ * \ingroup ccnx-helpers
+ *
* \brief a factory to create ns3::CcnxForwardingStrategy objects
*
- * For each new forwarding protocol created as a subclass of
- * ns3::CcnxForwardingStrategy, you need to create a subclass of
- * ns3::CcnxForwardingHelper which can be used by
- * ns3::InternetStackHelper::SetForwardingHelper and
- * ns3::InternetStackHelper::Install.
+ * \todo Document this class
*/
class CcnxForwardingHelper
{
@@ -53,7 +51,7 @@
* This method is mainly for internal use by the other helpers;
* clients are expected to free the dynamic memory allocated by this method
*/
- virtual CcnxForwardingHelper* Copy (void) const = 0;
+ virtual CcnxForwardingHelper* Copy () const = 0;
/**
* \param node the node within which the new forwarding protocol will run
diff --git a/helper/ccnx-header-helper.h b/helper/ccnx-header-helper.h
index 35aeab8..72d030c 100644
--- a/helper/ccnx-header-helper.h
+++ b/helper/ccnx-header-helper.h
@@ -30,7 +30,9 @@
class Packet;
/**
- * Class implementing functionality to detect CCNx packet type and
+ * \ingroup ccnx-helpers
+ *
+ * \brief Class implementing functionality to detect CCNx packet type and
* create the corresponding object
*
* CCNx doesn't really have a header, so we need this class to
@@ -68,6 +70,15 @@
CreateCorrectCcnxHeader (Ptr<const Packet> packet);
};
+ /**
+ * \ingroup ccnx
+ * \defgroup ccnx-exceptions Exceptions
+ */
+ /**
+ * \ingroup ccnx-exceptions
+ * \brief Exception thrown if CCNx stack receives unrecognized
+ * message type
+ */
class CcnxUnknownHeaderException {};
} // namespace ns3
diff --git a/helper/ccnx-stack-helper.cc b/helper/ccnx-stack-helper.cc
index 50839a3..d59827e 100644
--- a/helper/ccnx-stack-helper.cc
+++ b/helper/ccnx-stack-helper.cc
@@ -1,4 +1,4 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2011 UCLA
*
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Author:
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
*/
/**
@@ -67,7 +67,10 @@
#include "ns3/node.h"
#include "ns3/core-config.h"
#include "ns3/ccnx-forwarding-strategy.h"
+#include "ns3/ccnx-net-device-face.h"
+#include "ns3/ccnx-l3-protocol.h"
+#include "ccnx-face-container.h"
#include "ccnx-stack-helper.h"
#include "ccnx-forwarding-helper.h"
@@ -175,19 +178,21 @@
m_ccnxEnabled = enable;
}
-void
+Ptr<CcnxFaceContainer>
CcnxStackHelper::Install (NodeContainer c) const
{
+ Ptr<CcnxFaceContainer> faces = Create<CcnxFaceContainer> ();
for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
{
- Install (*i);
+ faces->AddAll (Install (*i));
}
+ return faces;
}
-void
+Ptr<CcnxFaceContainer>
CcnxStackHelper::InstallAll (void) const
{
- Install (NodeContainer::GetGlobal ());
+ return Install (NodeContainer::GetGlobal ());
}
void
@@ -199,10 +204,11 @@
node->AggregateObject (protocol);
}
-void
+Ptr<CcnxFaceContainer>
CcnxStackHelper::Install (Ptr<Node> node) const
{
- NS_ASSERT_MSG (m_forwarding, "CcnxForwarding should be set prior calling Install() method");
+ // NS_ASSERT_MSG (m_forwarding, "SetForwardingHelper() should be set prior calling Install() method");
+ Ptr<CcnxFaceContainer> faces = Create<CcnxFaceContainer> ();
if (m_ccnxEnabled)
{
@@ -210,22 +216,32 @@
{
NS_FATAL_ERROR ("CcnxStackHelper::Install (): Installing "
"a CcnxStack to a node with an existing Ccnx object");
- return;
+ return 0;
}
CreateAndAggregateObjectFromTypeId (node, "ns3::CcnxL3Protocol");
// Set forwarding
Ptr<Ccnx> ccnx = node->GetObject<Ccnx> ();
- Ptr<CcnxForwardingStrategy> ccnxForwarding = m_forwarding->Create (node);
- ccnx->SetForwardingStrategy (ccnxForwarding);
+ for (uint32_t index=0; index < node->GetNDevices (); index++)
+ {
+ Ptr<CcnxNetDeviceFace> face = Create<CcnxNetDeviceFace> (node->GetDevice (index));
+ uint32_t __attribute__ ((unused)) face_id = ccnx->AddFace (face);
+ NS_LOG_LOGIC ("Node " << node->GetId () << ": added CcxnNetDeviceFace as face #" << face_id);
+
+ faces->Add (face);
+ }
+ // Ptr<CcnxForwardingStrategy> ccnxForwarding = m_forwarding->Create (node);
+ // ccnx->SetForwardingStrategy (ccnxForwarding);
}
+
+ return faces;
}
-void
+Ptr<CcnxFaceContainer>
CcnxStackHelper::Install (std::string nodeName) const
{
Ptr<Node> node = Names::Find<Node> (nodeName);
- Install (node);
+ return Install (node);
}
static void
diff --git a/helper/ccnx-stack-helper.h b/helper/ccnx-stack-helper.h
index 3d0b3a4..7308241 100644
--- a/helper/ccnx-stack-helper.h
+++ b/helper/ccnx-stack-helper.h
@@ -21,12 +21,9 @@
#ifndef CCNX_STACK_HELPER_H
#define CCNX_STACK_HELPER_H
-#include "ns3/node-container.h"
-#include "ns3/net-device-container.h"
#include "ns3/packet.h"
#include "ns3/ptr.h"
#include "ns3/object-factory.h"
-#include "ns3/ccnx-l3-protocol.h"
#include "ccnx-trace-helper.h"
@@ -34,8 +31,14 @@
class Node;
class CcnxForwardingHelper;
+class CcnxFaceContainer;
/**
+ * \ingroup ccnx
+ * \defgroup ccnx-helpers Helpers
+ */
+/**
+ * \ingroup ccnx-helpers
* \brief Adding CCNx functionality to existing Nodes.
*
* This helper enables pcap and ascii tracing of events in the ccnx stack
@@ -55,25 +58,27 @@
{
public:
/**
- * Create a new CcnxStackHelper which <empty> forwarding by default.
+ * \brief Create a new CcnxStackHelper which <empty> forwarding by default.
*
* \todo set non-empty default forwarding
*/
CcnxStackHelper ();
/**
- * Destroy the CcnxStackHelper
+ * \brief Destroy the CcnxStackHelper
*/
virtual ~CcnxStackHelper ();
CcnxStackHelper (const CcnxStackHelper &);
CcnxStackHelper &operator = (const CcnxStackHelper &o);
/**
- * Return helper internal state to that of a newly constructed one
+ * \brief Return helper internal state to that of a newly constructed one
*/
void Reset ();
/**
+ * Set forwarding strategy helper
+ *
* \param forwarding a new forwarding helper
*
* Set the forwarding helper to use during Install. The forwarding helper is
@@ -81,50 +86,68 @@
* ns3::CcnxFrProtocol per node. This forwarding object is then associated to
* a single ns3::Ccnx object through its ns3::Ccnx::SetforwardingProtocol.
*/
- void SetForwardingHelper (const CcnxForwardingHelper &forwarding);
+ void
+ SetForwardingHelper (const CcnxForwardingHelper &forwarding);
/**
- * Install CCNx stack on the node
+ * \brief Install CCNx stack on the node
*
* This method will assert if called on a node that already has Ccnx object
* installed on it
*
* \param nodeName The name of the node on which to install the stack.
+ *
+ * \returns list of installed faces in the form of a smart pointer
+ * to CcnxFaceContainer object
*/
- void Install (std::string nodeName) const;
+ Ptr<CcnxFaceContainer>
+ Install (std::string nodeName) const;
/**
- * Install CCNx stack on the node
+ * \brief Install CCNx stack on the node
*
* This method will assert if called on a node that already has Ccnx object
* installed on it
*
* \param node The node on which to install the stack.
+ *
+ * \returns list of installed faces in the form of a smart pointer
+ * to CcnxFaceContainer object
*/
- void Install (Ptr<Node> node) const;
+ Ptr<CcnxFaceContainer>
+ Install (Ptr<Node> node) const;
/**
- * Install CCNx stack on each node in the input container
+ * \brief Install CCNx stack on each node in the input container
*
* The program will assert if this method is called on a container with a node
* that already has an ccnx object aggregated to it.
*
* \param c NodeContainer that holds the set of nodes on which to install the
* new stacks.
+ *
+ * \returns list of installed faces in the form of a smart pointer
+ * to CcnxFaceContainer object
*/
- void Install (NodeContainer c) const;
+ Ptr<CcnxFaceContainer>
+ Install (NodeContainer c) const;
/**
- * Install CCNx stack on all nodes in the simulation
+ * \brief Install CCNx stack on all nodes in the simulation
+ *
+ * \returns list of installed faces in the form of a smart pointer
+ * to CcnxFaceContainer object
*/
- void
+ Ptr<CcnxFaceContainer>
InstallAll () const;
/**
* \brief Enable/disable ccnx stack install.
+ *
* \param enable enable state
*/
- void SetCcnxStackInstall (bool enable);
+ void
+ SetCcnxStackInstall (bool enable);
private:
/**
diff --git a/helper/ccnx-trace-helper.h b/helper/ccnx-trace-helper.h
index a0390e7..49ad8e0 100644
--- a/helper/ccnx-trace-helper.h
+++ b/helper/ccnx-trace-helper.h
@@ -14,6 +14,8 @@
* 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
+ *
+ * Authors: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
*/
#ifndef CCNX_TRACE_HELPER_H
@@ -27,6 +29,8 @@
namespace ns3 {
/**
+ * \ingroup ccnx-helpers
+ *
* @brief Base class providing common user-level pcap operations for helpers
* representing Ccnx protocols .
*/
@@ -119,6 +123,8 @@
};
/**
+ * \ingroup ccnx-helpers
+ *
* @brief Base class providing common user-level ascii trace operations for
* helpers representing Ccnx protocols .
*/
diff --git a/in-progress/ccn/README b/in-progress/ccn/README
deleted file mode 100644
index 6b9ef69..0000000
--- a/in-progress/ccn/README
+++ /dev/null
@@ -1,2 +0,0 @@
-This directory contains files borrowed and adapted from CCNx implementation
-
diff --git a/in-progress/ccn/ccn.h b/in-progress/ccn/ccn.h
deleted file mode 100644
index af9dcae..0000000
--- a/in-progress/ccn/ccn.h
+++ /dev/null
@@ -1,407 +0,0 @@
-/* -*- 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>
- */
-
-/*
- * ccn_ccn.h
- * Abstraction
- *
- * Created by Ilya on 7/29/11.
- * Copyright 2011 __MyCompanyName__. All rights reserved.
- *
- */
-
-#ifndef CCN_CCN_DEFINED
-#define CCN_CCN_DEFINED
-
-#include <stdint.h>
-#include "ccn_coding.h"
-#include "ccn_charbuf.h"
-#include "ccn_indexbuf.h"
-
-/***********************************
- * Writing Names
- * Names for interests are constructed in charbufs using
- * the following routines.
- */
-
-/*
- * ccn_name_init: reset charbuf to represent an empty Name in binary format
- * Return value is 0, or -1 for error.
- */
-int ccn_name_init(struct ccn_charbuf *c);
-
-/*
- * ccn_name_append: add a Component to a Name
- * The component is an arbitrary string of n octets, no escaping required.
- * Return value is 0, or -1 for error.
- */
-int ccn_name_append(struct ccn_charbuf *c, const void *component, size_t n);
-
-/*
- * ccn_name_append_str: add a Component that is a \0 terminated string.
- * The component added is the bytes of the string without the \0.
- * This function is convenient for those applications that construct
- * component names from simple strings.
- * Return value is 0, or -1 for error
- */
-int ccn_name_append_str(struct ccn_charbuf *c, const char *s);
-
-/*
- * ccn_name_append_components: add sequence of ccnb-encoded Components
- * to a ccnb-encoded Name
- * start and stop are offsets from ccnb
- * Return value is 0, or -1 for obvious error
- */
-int ccn_name_append_components(struct ccn_charbuf *c,
- const unsigned char *ccnb,
- size_t start, size_t stop);
-
-enum ccn_marker {
- CCN_MARKER_NONE = -1,
- CCN_MARKER_SEQNUM = 0x00, /**< consecutive block sequence numbers */
- CCN_MARKER_CONTROL = 0xC1, /**< commands, etc. */
- CCN_MARKER_OSEQNUM = 0xF8, /**< deprecated */
- CCN_MARKER_BLKID = 0xFB, /**< nonconsecutive block ids */
- CCN_MARKER_VERSION = 0xFD /**< timestamp-based versioning */
-};
-
-/*
- * ccn_name_append_numeric: add binary Component to ccnb-encoded Name
- * These are special components used for marking versions, fragments, etc.
- * Return value is 0, or -1 for error
- * see doc/technical/NameConventions.html
- */
-int ccn_name_append_numeric(struct ccn_charbuf *c,
- enum ccn_marker tag, uintmax_t value);
-
-/*
- * ccn_name_append_nonce: add nonce Component to ccnb-encoded Name
- * Uses %C1.N.n marker.
- * see doc/technical/NameConventions.html
- */
-int ccn_name_append_nonce(struct ccn_charbuf *c);
-
-/*
- * ccn_name_split: find Component boundaries in a ccnb-encoded Name
- * Thin veneer over ccn_parse_Name().
- * returns -1 for error, otherwise the number of Components
- * components arg may be NULL to just do a validity check
- */
-int ccn_name_split(const struct ccn_charbuf *c,
- struct ccn_indexbuf* components);
-
-/*
- * ccn_name_chop: Chop the name down to n components.
- * returns -1 for error, otherwise the new number of Components
- * components arg may be NULL; if provided it must be consistent with
- * some prefix of the name, and is updated accordingly.
- * n may be negative to say how many components to remove instead of how
- * many to leave, e.g. -1 will remove just the last component.
- */
-int ccn_name_chop(struct ccn_charbuf *c,
- struct ccn_indexbuf* components, int n);
-
-
-
-
-/*********** Interest parsing ***********/
-
-/*
- * The parse of an interest results in an array of offsets into the
- * wire representation, with the start and end of each major element and
- * a few of the inportant sub-elements. The following enum allows those
- * array items to be referred to symbolically. The *_B_* indices correspond
- * to beginning offsets and the *_E_* indices correspond to ending offsets.
- * An omitted element has its beginning and ending offset equal to each other.
- * Normally these offsets will end up in non-decreasing order.
- * Some aliasing tricks may be played here, e.g. since
- * offset[CCN_PI_E_ComponentLast] is always equal to
- * offset[CCN_PI_E_LastPrefixComponent],
- * we may define CCN_PI_E_ComponentLast = CCN_PI_E_LastPrefixComponent.
- * However, code should not rely on that,
- * since it may change from time to time as the
- * interest schema evolves.
- */
-enum ccn_parsed_interest_offsetid {
- CCN_PI_B_Name,
- CCN_PI_B_Component0,
- CCN_PI_B_LastPrefixComponent,
- CCN_PI_E_LastPrefixComponent,
- CCN_PI_E_ComponentLast = CCN_PI_E_LastPrefixComponent,
- CCN_PI_E_Name,
- CCN_PI_B_MinSuffixComponents,
- CCN_PI_E_MinSuffixComponents,
- CCN_PI_B_MaxSuffixComponents,
- CCN_PI_E_MaxSuffixComponents,
- CCN_PI_B_PublisherID, // XXX - rename
- CCN_PI_B_PublisherIDKeyDigest,
- CCN_PI_E_PublisherIDKeyDigest,
- CCN_PI_E_PublisherID,
- CCN_PI_B_Exclude,
- CCN_PI_E_Exclude,
- CCN_PI_B_ChildSelector,
- CCN_PI_E_ChildSelector,
- CCN_PI_B_AnswerOriginKind,
- CCN_PI_E_AnswerOriginKind,
- CCN_PI_B_Scope,
- CCN_PI_E_Scope,
- CCN_PI_B_InterestLifetime,
- CCN_PI_E_InterestLifetime,
- CCN_PI_B_Nonce,
- CCN_PI_E_Nonce,
- CCN_PI_B_OTHER,
- CCN_PI_E_OTHER,
- CCN_PI_E
-};
-
-
-struct ccn_parsed_interest {
- int magic;
- int prefix_comps;
- int min_suffix_comps;
- int max_suffix_comps;
- int orderpref;
- int answerfrom;
- int scope;
- unsigned short offset[CCN_PI_E+1];
-};
-
-/*
- * Bitmasks for AnswerOriginKind
- */
-#define CCN_AOK_CS 0x1 /* Answer from content store */
-#define CCN_AOK_NEW 0x2 /* OK to produce new content */
-#define CCN_AOK_DEFAULT (CCN_AOK_CS | CCN_AOK_NEW)
-#define CCN_AOK_STALE 0x4 /* OK to answer with stale data */
-#define CCN_AOK_EXPIRE 0x10 /* Mark as stale (must have Scope 0) */
-
-/***********************************
- * Low-level binary formatting
- */
-
-/*
- * Append a ccnb start marker
- *
- * This forms the basic building block of ccnb-encoded data.
- * c is the buffer to append to.
- * Return value is 0, or -1 for error.
- */
-int ccn_charbuf_append_tt(struct ccn_charbuf *c, size_t val, enum ccn_tt tt);
-
-/**
- * Append a CCN_CLOSE
- *
- * Use this to close off an element in ccnb-encoded data.
- * @param c is the buffer to append to.
- * @returns 0 for success or -1 for error.
- */
-int ccn_charbuf_append_closer(struct ccn_charbuf *c);
-
-/***********************************
- * Slightly higher level binary formatting
- */
-
-/*
- * Append a non-negative integer as a UDATA.
- */
-int ccnb_append_number(struct ccn_charbuf *c, int nni);
-
-/*
- * Append a binary timestamp
- * as a BLOB using the ccn binary Timestamp representation (12-bit fraction).
- */
-int ccnb_append_timestamp_blob(struct ccn_charbuf *c,
- enum ccn_marker marker,
- long long secs, int nsecs);
-
-/*
- * Append a binary timestamp, using the current time.
- */
-int ccnb_append_now_blob(struct ccn_charbuf *c, enum ccn_marker marker);
-
-/*
- * Append a start-of-element marker.
- */
-int ccnb_element_begin(struct ccn_charbuf *c, enum ccn_dtag dtag);
-
-/*
- * Append an end-of-element marker.
- * This is the same as ccn_charbuf_append_closer()
- */
-int ccnb_element_end(struct ccn_charbuf *c);
-
-/*
- * Append a tagged BLOB
- */
-int ccnb_append_tagged_blob(struct ccn_charbuf *c, enum ccn_dtag dtag,
- const void *data, size_t size);
-
-/*
- * Append a tagged UDATA string, with printf-style formatting
- */
-int ccnb_tagged_putf(struct ccn_charbuf *c, enum ccn_dtag dtag,
- const char *fmt, ...);
-
-
-
-/***********************************
- * Binary decoding
- * These routines require that the whole binary object be buffered.
- */
-
-struct ccn_buf_decoder {
- struct ccn_skeleton_decoder decoder;
- const unsigned char *buf;
- size_t size;
-};
-
-struct ccn_buf_decoder *ccn_buf_decoder_start(struct ccn_buf_decoder *d,
- const unsigned char *buf, size_t size);
-
-void ccn_buf_advance(struct ccn_buf_decoder *d);
-int ccn_buf_advance_past_element(struct ccn_buf_decoder *d);
-
-/* The match routines return a boolean - true for match */
-int ccn_buf_match_dtag(struct ccn_buf_decoder *d, enum ccn_dtag dtag);
-
-int ccn_buf_match_some_dtag(struct ccn_buf_decoder *d);
-
-int ccn_buf_match_some_blob(struct ccn_buf_decoder *d);
-int ccn_buf_match_blob(struct ccn_buf_decoder *d,
- const unsigned char **bufp, size_t *sizep);
-
-int ccn_buf_match_udata(struct ccn_buf_decoder *d, const char *s);
-
-int ccn_buf_match_attr(struct ccn_buf_decoder *d, const char *s);
-
-/* On error, the parse routines enter an error state and return a negative value. */
-/*int ccn_parse_required_tagged_BLOB(struct ccn_buf_decoder *d,
- enum ccn_dtag dtag,
- int minlen, int maxlen);
-int ccn_parse_optional_tagged_BLOB(struct ccn_buf_decoder *d,
- enum ccn_dtag dtag,
- int minlen, int maxlen);
-int ccn_parse_nonNegativeInteger(struct ccn_buf_decoder *d);
-int ccn_parse_optional_tagged_nonNegativeInteger(struct ccn_buf_decoder *d,
- enum ccn_dtag dtag);
-int ccn_parse_uintmax(struct ccn_buf_decoder *d, uintmax_t *result);
-int ccn_parse_tagged_string(struct ccn_buf_decoder *d,
- enum ccn_dtag dtag, struct ccn_charbuf *store);*/
-/* check the decoder error state for these two - result can't be negative */
-/*uintmax_t ccn_parse_required_tagged_binary_number(struct ccn_buf_decoder *d,
- enum ccn_dtag dtag,
- int minlen, int maxlen);
-uintmax_t ccn_parse_optional_tagged_binary_number(struct ccn_buf_decoder *d,
- enum ccn_dtag dtag,
- int minlen, int maxlen,
- uintmax_t default_value);*/
-
-/**
- * Enter an error state if element closer not found.
- */
-void ccn_buf_check_close(struct ccn_buf_decoder *d);
-
-/*
- * ccn_ref_tagged_BLOB: Get address & size associated with blob-valued element
- * Returns 0 for success, negative value for error.
- */
-int ccn_ref_tagged_BLOB(enum ccn_dtag tt,
- const unsigned char *buf,
- size_t start, size_t stop,
- const unsigned char **presult, size_t *psize);
-
-/*
- * ccn_parse_Name: Parses a ccnb-encoded name
- * components may be NULL, otherwise is filled in with Component boundary offsets
- * Returns the number of Components in the Name, or -1 if there is an error.
- */
-int ccn_parse_Name(struct ccn_buf_decoder *d, struct ccn_indexbuf *components);
-
-/***********************************
- * Authenticators and signatures for content are constructed in charbufs
- * using the following routines.
- */
-
-enum ccn_content_type {
- CCN_CONTENT_DATA = 0x0C04C0,
- CCN_CONTENT_ENCR = 0x10D091,
- CCN_CONTENT_GONE = 0x18E344,
- CCN_CONTENT_KEY = 0x28463F,
- CCN_CONTENT_LINK = 0x2C834A,
- CCN_CONTENT_NACK = 0x34008A
-};
-
-
-/*********** ContentObject parsing ***********/
-/* Analogous to enum ccn_parsed_interest_offsetid, but for content */
-enum ccn_parsed_content_object_offsetid {
- CCN_PCO_B_Signature,
- CCN_PCO_B_DigestAlgorithm,
- CCN_PCO_E_DigestAlgorithm,
- CCN_PCO_B_Witness,
- CCN_PCO_E_Witness,
- CCN_PCO_B_SignatureBits,
- CCN_PCO_E_SignatureBits,
- CCN_PCO_E_Signature,
- CCN_PCO_B_Name,
- CCN_PCO_B_Component0,
- CCN_PCO_E_ComponentN,
- CCN_PCO_E_ComponentLast = CCN_PCO_E_ComponentN,
- CCN_PCO_E_Name,
- CCN_PCO_B_SignedInfo,
- CCN_PCO_B_PublisherPublicKeyDigest,
- CCN_PCO_E_PublisherPublicKeyDigest,
- CCN_PCO_B_Timestamp,
- CCN_PCO_E_Timestamp,
- CCN_PCO_B_Type,
- CCN_PCO_E_Type,
- CCN_PCO_B_FreshnessSeconds,
- CCN_PCO_E_FreshnessSeconds,
- CCN_PCO_B_FinalBlockID,
- CCN_PCO_E_FinalBlockID,
- CCN_PCO_B_KeyLocator,
- /* Exactly one of Key, Certificate, or KeyName will be present */
- CCN_PCO_B_Key_Certificate_KeyName,
- CCN_PCO_B_KeyName_Name,
- CCN_PCO_E_KeyName_Name,
- CCN_PCO_B_KeyName_Pub,
- CCN_PCO_E_KeyName_Pub,
- CCN_PCO_E_Key_Certificate_KeyName,
- CCN_PCO_E_KeyLocator,
- CCN_PCO_E_SignedInfo,
- CCN_PCO_B_Content,
- CCN_PCO_E_Content,
- CCN_PCO_E
-};
-
-struct ccn_parsed_ContentObject {
- int magic;
- enum ccn_content_type type;
- int name_ncomps;
- unsigned short offset[CCN_PCO_E+1];
- unsigned char digest[32]; /* Computed only when needed */
- int digest_bytes;
-};
-
-int ccn_encode_ContentObject(struct ccn_charbuf *buf,
- const struct ccn_charbuf *Name,
- const void *data,
- size_t size);
-#endif
diff --git a/in-progress/ccn/ccn_buf_decoder.cc b/in-progress/ccn/ccn_buf_decoder.cc
deleted file mode 100644
index eeb51fa..0000000
--- a/in-progress/ccn/ccn_buf_decoder.cc
+++ /dev/null
@@ -1,930 +0,0 @@
-/* -*- 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>
- */
-
-#include <string.h>
-#include <stdlib.h>
-#include "ccn.h"
-#include "ccn_charbuf.h"
-#include "ccn_coding.h"
-#include "ccn_indexbuf.h"
-
-
-struct ccn_buf_decoder *
-ccn_buf_decoder_start(struct ccn_buf_decoder *d,
- const unsigned char *buf, size_t size)
-{
- memset(&d->decoder, 0, sizeof(d->decoder));
- d->decoder.state |= CCN_DSTATE_PAUSE;
- d->buf = buf;
- d->size = size;
- ccn_skeleton_decode(&d->decoder, buf, size);
- return(d);
-}
-
-void
-ccn_buf_advance(struct ccn_buf_decoder *d)
-{
- ccn_skeleton_decode(&d->decoder,
- d->buf + d->decoder.index,
- d->size - d->decoder.index);
-}
-
-int
-ccn_buf_match_dtag(struct ccn_buf_decoder *d, enum ccn_dtag dtag)
-{
- return (d->decoder.state >= 0 &&
- CCN_GET_TT_FROM_DSTATE(d->decoder.state) == CCN_DTAG &&
- (int)d->decoder.numval == dtag);
-}
-
-int
-ccn_buf_match_some_dtag(struct ccn_buf_decoder *d)
-{
- return(d->decoder.state >= 0 &&
- CCN_GET_TT_FROM_DSTATE(d->decoder.state) == CCN_DTAG);
-}
-
-int
-ccn_buf_match_some_blob(struct ccn_buf_decoder *d)
-{
- return(d->decoder.state >= 0 &&
- CCN_GET_TT_FROM_DSTATE(d->decoder.state) == CCN_BLOB);
-}
-
-int
-ccn_buf_match_blob(struct ccn_buf_decoder *d,
- const unsigned char **bufp, size_t *sizep)
-{
- if (ccn_buf_match_some_blob(d)) {
- if (bufp != NULL)
- *bufp = d->buf + d->decoder.index;
- if (sizep != NULL)
- *sizep = d->decoder.numval;
- return (1);
- }
- if (bufp != NULL)
- *bufp = d->buf + d->decoder.token_index;
- if (sizep != NULL)
- *sizep = 0;
- return(0);
-}
-
-int
-ccn_buf_match_udata(struct ccn_buf_decoder *d, const char *s)
-{
- size_t len = strlen(s);
- return (d->decoder.state >= 0 &&
- CCN_GET_TT_FROM_DSTATE(d->decoder.state) == CCN_UDATA &&
- d->decoder.numval == len &&
- 0 == memcmp(d->buf + d->decoder.index, s, len));
-}
-
-int
-ccn_buf_match_attr(struct ccn_buf_decoder *d, const char *s)
-{
- size_t len = strlen(s);
- return (d->decoder.state >= 0 &&
- CCN_GET_TT_FROM_DSTATE(d->decoder.state) == CCN_ATTR &&
- d->decoder.numval == len &&
- 0 == memcmp(d->buf + d->decoder.index, s, len));
-}
-
-void
-ccn_buf_check_close(struct ccn_buf_decoder *d)
-{
- if (d->decoder.state >= 0) {
- if (CCN_GET_TT_FROM_DSTATE(d->decoder.state) != CCN_NO_TOKEN)
- d->decoder.state = CCN_DSTATE_ERR_NEST;
- else
- ccn_buf_advance(d);
- }
-}
-
-int
-ccn_buf_advance_past_element(struct ccn_buf_decoder *d)
-{
- enum ccn_tt tt;
- int nest;
- if (d->decoder.state < 0)
- return(d->decoder.state);
- tt = (ccn_tt)CCN_GET_TT_FROM_DSTATE(d->decoder.state);
- if (tt == CCN_DTAG || tt == CCN_TAG) {
- nest = d->decoder.nest;
- ccn_buf_advance(d);
- while (d->decoder.state >= 0 && d->decoder.nest >= nest)
- ccn_buf_advance(d);
- /* The nest decrements before the closer is consumed */
- ccn_buf_check_close(d);
- }
- else
- return(-1);
- if (d->decoder.state < 0)
- return(d->decoder.state);
- return (0);
-}
-
-int
-ccn_parse_required_tagged_BLOB(struct ccn_buf_decoder *d, enum ccn_dtag dtag,
- int minlen, int maxlen)
-{
- int res = -1;
- size_t len = 0;
- if (ccn_buf_match_dtag(d, dtag)) {
- res = d->decoder.element_index;
- ccn_buf_advance(d);
- if (ccn_buf_match_some_blob(d)) {
- len = d->decoder.numval;
- ccn_buf_advance(d);
- }
- ccn_buf_check_close(d);
- if ((int)len < minlen || (maxlen >= 0 && (int)len > maxlen)) {
- d->decoder.state = -__LINE__;
- }
- }
- else
- d->decoder.state = -__LINE__;
- if (d->decoder.state < 0)
- return (d->decoder.state);
- return(res);
-}
-
-int
-ccn_parse_optional_tagged_BLOB(struct ccn_buf_decoder *d, enum ccn_dtag dtag,
- int minlen, int maxlen)
-{
- if (ccn_buf_match_dtag(d, dtag))
- return(ccn_parse_required_tagged_BLOB(d, dtag, minlen, maxlen));
- return(-1);
-}
-
-uintmax_t
-ccn_parse_required_tagged_binary_number(struct ccn_buf_decoder *d,
- enum ccn_dtag dtag,
- int minlen, int maxlen)
-{
- uintmax_t value = 0;
- const unsigned char *p = NULL;
- size_t len = 0;
- int i;
- if (0 <= minlen && minlen <= maxlen && maxlen <= (int)sizeof(value) &&
- ccn_buf_match_dtag(d, dtag)) {
- ccn_buf_advance(d);
- if (ccn_buf_match_blob(d, &p, &len))
- ccn_buf_advance(d);
- ccn_buf_check_close(d);
- if (d->decoder.state < 0)
- return(value);
- if (minlen <= (int)len && (int)len <= maxlen)
- for (i = 0; i < (int)len; i++)
- value = (value << 8) + p[i];
- else
- d->decoder.state = -__LINE__;
- }
- else
- d->decoder.state = -__LINE__;
- return(value);
-}
-
-uintmax_t
-ccn_parse_optional_tagged_binary_number(struct ccn_buf_decoder *d, enum ccn_dtag dtag,
- int minlen, int maxlen, uintmax_t default_value)
-{
- if (ccn_buf_match_dtag(d, dtag))
- return(ccn_parse_required_tagged_binary_number(d, dtag, minlen, maxlen));
- return(default_value);
-}
-
-int
-ccn_parse_required_tagged_UDATA(struct ccn_buf_decoder *d, enum ccn_dtag dtag)
-{
- int res = -1;
- if (ccn_buf_match_dtag(d, dtag)) {
- res = d->decoder.element_index;
- ccn_buf_advance(d);
- if (d->decoder.state >= 0 &&
- CCN_GET_TT_FROM_DSTATE(d->decoder.state) == CCN_UDATA)
- ccn_buf_advance(d);
- else
- d->decoder.state = -__LINE__;
- ccn_buf_check_close(d);
- }
- else
- d->decoder.state = -__LINE__;
- if (d->decoder.state < 0)
- return (-1);
- return(res);
-}
-
-int
-ccn_parse_optional_tagged_UDATA(struct ccn_buf_decoder *d, enum ccn_dtag dtag)
-{
- if (ccn_buf_match_dtag(d, dtag))
- return(ccn_parse_required_tagged_UDATA(d, dtag));
- return(-1);
-}
-
-/**
- * Parses a ccnb-encoded element expected to contain a UDATA string.
- * @param d is the decoder
- * @param dtag is the expected dtag value
- * @param store - on success, the string value is appended to store,
- * with null termination.
- * @returns the offset into the store buffer of the copied value, or -1 for error.
- * If a parse error occurs, d->decoder.state is set to a negative value.
- * If the element is not present, -1 is returned but no parse error
- * is indicated.
- */
-int
-ccn_parse_tagged_string(struct ccn_buf_decoder *d, enum ccn_dtag dtag, struct ccn_charbuf *store)
-{
- const unsigned char *p = NULL;
- size_t size = 0;
- int res;
-
- if (ccn_buf_match_dtag(d, dtag)) {
- ccn_buf_advance(d);
- if (d->decoder.state >= 0 &&
- CCN_GET_TT_FROM_DSTATE(d->decoder.state) == CCN_UDATA) {
- res = store->length;
- p = d->buf + d->decoder.index;
- size = d->decoder.numval;
- ccn_buf_advance(d);
- }
- ccn_buf_check_close(d);
- if (d->decoder.state >= 0) {
- // XXX - should check for valid utf-8 data.
- res = store->length;
- if (size > 0)
- ccn_charbuf_append(store, p, size);
- ccn_charbuf_append_value(store, 0, 1);
- return(res);
- }
- }
- return(-1);
-}
-
-/**
- * Parses a ccnb-encoded name
- * @param d is the decoder
- * @param components may be NULL, otherwise is filled in with the
- * Component boundary offsets
- * @returns the number of Components in the Name, or -1 if there is an error.
- */
-int
-ccn_parse_Name(struct ccn_buf_decoder *d, struct ccn_indexbuf *components)
-{
- int ncomp = 0;
- if (ccn_buf_match_dtag(d, CCN_DTAG_Name)) {
- if (components != NULL) components->n = 0;
- ccn_buf_advance(d);
- while (ccn_buf_match_dtag(d, CCN_DTAG_Component)) {
- if (components != NULL)
- ccn_indexbuf_append_element(components, d->decoder.token_index);
- ncomp += 1;
- ccn_buf_advance(d);
- if (ccn_buf_match_blob(d, NULL, NULL))
- ccn_buf_advance(d);
- ccn_buf_check_close(d);
- }
- if (components != NULL)
- ccn_indexbuf_append_element(components, d->decoder.token_index);
- ccn_buf_check_close(d);
- }
- else
- d->decoder.state = -__LINE__;
- if (d->decoder.state < 0)
- return(-1);
- else
- return(ncomp);
-}
-
-int
-ccn_parse_PublisherID(struct ccn_buf_decoder *d, struct ccn_parsed_interest *pi)
-{
- int res = -1;
- int iskey = 0;
- unsigned pubstart = d->decoder.token_index;
- unsigned keystart = pubstart;
- unsigned keyend = pubstart;
- unsigned pubend = pubstart;
- iskey = ccn_buf_match_dtag(d, CCN_DTAG_PublisherPublicKeyDigest);
- if (iskey ||
- ccn_buf_match_dtag(d, CCN_DTAG_PublisherCertificateDigest) ||
- ccn_buf_match_dtag(d, CCN_DTAG_PublisherIssuerKeyDigest) ||
- ccn_buf_match_dtag(d, CCN_DTAG_PublisherIssuerCertificateDigest)) {
- res = d->decoder.element_index;
- ccn_buf_advance(d);
- keystart = d->decoder.token_index;
- if (!ccn_buf_match_some_blob(d))
- return (d->decoder.state = -__LINE__);
- ccn_buf_advance(d);
- keyend = d->decoder.token_index;
- ccn_buf_check_close(d);
- pubend = d->decoder.token_index;
- }
- if (d->decoder.state < 0)
- return (d->decoder.state);
- if (pi != NULL) {
- pi->offset[CCN_PI_B_PublisherID] = pubstart;
- pi->offset[CCN_PI_B_PublisherIDKeyDigest] = keystart;
- pi->offset[CCN_PI_E_PublisherIDKeyDigest] = iskey ? keyend : keystart;
- pi->offset[CCN_PI_E_PublisherID] = pubend;
- }
- return(res);
-}
-
-static int
-ccn_parse_optional_Any_or_Bloom(struct ccn_buf_decoder *d)
-{
- int res;
- res = ccn_parse_optional_tagged_BLOB(d, CCN_DTAG_Bloom, 1, 1024+8);
- if (res >= 0)
- return(res);
- if (ccn_buf_match_dtag(d, CCN_DTAG_Any)) {
- ccn_buf_advance(d);
- ccn_buf_check_close(d);
- res = 0;
- }
- if (d->decoder.state < 0)
- return (d->decoder.state);
- return(res);
-}
-
-int
-ccn_parse_Exclude(struct ccn_buf_decoder *d)
-{
- int res = -1;
- if (ccn_buf_match_dtag(d, CCN_DTAG_Exclude)) {
- res = d->decoder.element_index;
- ccn_buf_advance(d);
- ccn_parse_optional_Any_or_Bloom(d);
- while (ccn_buf_match_dtag(d, CCN_DTAG_Component)) {
- ccn_parse_required_tagged_BLOB(d, CCN_DTAG_Component, 0, -1);
- ccn_parse_optional_Any_or_Bloom(d);
- }
- ccn_buf_check_close(d);
- }
- if (d->decoder.state < 0)
- return (d->decoder.state);
- return(res);
-}
-
-
-
-int
-ccn_parse_nonNegativeInteger(struct ccn_buf_decoder *d)
-{
- const unsigned char *p;
- int i;
- int n;
- int val;
- int newval;
- unsigned char c;
- if (d->decoder.state < 0)
- return(d->decoder.state);
- if (CCN_GET_TT_FROM_DSTATE(d->decoder.state) == CCN_UDATA) {
- p = d->buf + d->decoder.index;
- n = d->decoder.numval;
- if (n < 1)
- return(d->decoder.state = -__LINE__);
- val = 0;
- for (i = 0; i < n; i++) {
- c = p[i];
- if ('0' <= c && c <= '9') {
- newval = val * 10 + (c - '0');
- if (newval < val)
- return(d->decoder.state = -__LINE__);
- val = newval;
- }
- else
- return(d->decoder.state = -__LINE__);
- }
- ccn_buf_advance(d);
- return(val);
- }
- return(d->decoder.state = -__LINE__);
-}
-
-/**
- * Parse a potentially large non-negative integer.
- *
- * @returns 0 for success, and the value is place in *result; for an error
- * a negative value is returned and *result is unchanged.
- */
-int
-ccn_parse_uintmax(struct ccn_buf_decoder *d, uintmax_t *result)
-{
- const unsigned char *p;
- int i;
- int n;
- uintmax_t val;
- uintmax_t newval;
- unsigned char c;
- if (d->decoder.state < 0)
- return(d->decoder.state);
- if (CCN_GET_TT_FROM_DSTATE(d->decoder.state) == CCN_UDATA) {
- p = d->buf + d->decoder.index;
- n = d->decoder.numval;
- if (n < 1)
- return(d->decoder.state = -__LINE__);
- val = 0;
- for (i = 0; i < n; i++) {
- c = p[i];
- if ('0' <= c && c <= '9') {
- newval = val * 10 + (c - '0');
- if (newval < val)
- return(d->decoder.state = -__LINE__);
- val = newval;
- }
- else
- return(d->decoder.state = -__LINE__);
- }
- ccn_buf_advance(d);
- *result = val;
- return(0);
- }
- return(d->decoder.state = -__LINE__);
-}
-
-int
-ccn_parse_timestamp(struct ccn_buf_decoder *d)
-{
- const unsigned char dlm[] = "--T::.Z";
- const unsigned char *p;
- int i;
- int k;
- int n;
- if (d->decoder.state < 0)
- return(d->decoder.state);
- if (CCN_GET_TT_FROM_DSTATE(d->decoder.state) == CCN_BLOB) {
- /* New-style binary timestamp, 12-bit fraction */
- n = d->decoder.numval;
- if (n < 3 || n > 7)
- return(d->decoder.state = -__LINE__);
- ccn_buf_advance(d);
- return(0);
- }
- if (CCN_GET_TT_FROM_DSTATE(d->decoder.state) == CCN_UDATA) {
- /* This is for some temporary back-compatibility */
- p = d->buf + d->decoder.index;
- n = d->decoder.numval;
- if (n < 8 || n > 40)
- return(d->decoder.state = -__LINE__);
- if (p[n - 1] != 'Z')
- return(d->decoder.state = -__LINE__);
- for (i = 0, k = 0; i < n && '0' <= p[i] && p[i] <= '9';) {
- i++;
- if (i < n && p[i] == dlm[k]) {
- if (dlm[k++] == 0)
- return(d->decoder.state = -__LINE__);
- i++;
- }
- }
- if (k < 5)
- return(d->decoder.state = -__LINE__);
- if (!(i == n || i == n - 1))
- return(d->decoder.state = -__LINE__);
- ccn_buf_advance(d);
- return(0);
- }
- return(d->decoder.state = -__LINE__);
-}
-
-int
-ccn_parse_required_tagged_timestamp(struct ccn_buf_decoder *d, enum ccn_dtag dtag)
-{
- int res = -1;
- if (ccn_buf_match_dtag(d, dtag)) {
- res = d->decoder.element_index;
- ccn_buf_advance(d);
- ccn_parse_timestamp(d);
- ccn_buf_check_close(d);
- }
- else
- d->decoder.state = -__LINE__;
- if (d->decoder.state < 0)
- return (-1);
- return(res);
-}
-
-int
-ccn_parse_optional_tagged_nonNegativeInteger(struct ccn_buf_decoder *d, enum ccn_dtag dtag)
-{
- int res = -1;
- if (ccn_buf_match_dtag(d, dtag)) {
- ccn_buf_advance(d);
- res = ccn_parse_nonNegativeInteger(d);
- ccn_buf_check_close(d);
- }
- if (d->decoder.state < 0)
- return (d->decoder.state);
- return(res);
-}
-
-int
-ccn_fetch_tagged_nonNegativeInteger(enum ccn_dtag tt,
- const unsigned char *buf,
- size_t start, size_t stop)
-{
- struct ccn_buf_decoder decoder;
- struct ccn_buf_decoder *d;
- int result = -1;
- if (stop < start) return(-1);
- d = ccn_buf_decoder_start(&decoder, buf + start, stop - start);
- if (ccn_buf_match_dtag(d, tt)) {
- ccn_buf_advance(d);
- result = ccn_parse_nonNegativeInteger(d);
- ccn_buf_check_close(d);
- }
- if (result < 0)
- return(-1);
- return(result);
-}
-
-
-int
-ccn_parse_interest(const unsigned char *msg, size_t size,
- struct ccn_parsed_interest *interest,
- struct ccn_indexbuf *components)
-{
- struct ccn_buf_decoder decoder;
- struct ccn_buf_decoder *d = ccn_buf_decoder_start(&decoder, msg, size);
- int magic = 0;
- int ncomp = 0;
- int res;
- if (ccn_buf_match_dtag(d, CCN_DTAG_Interest)) {
- if (components == NULL) {
- /* We need to have the component offsets. */
- components = ccn_indexbuf_create();
- if (components == NULL) return(-1);
- res = ccn_parse_interest(msg, size, interest, components);
- ccn_indexbuf_destroy(&components);
- return(res);
- }
- ccn_buf_advance(d);
- interest->offset[CCN_PI_B_Name] = d->decoder.element_index;
- interest->offset[CCN_PI_B_Component0] = d->decoder.index;
- ncomp = ccn_parse_Name(d, components);
- if (d->decoder.state < 0) {
- memset(interest->offset, 0, sizeof(interest->offset));
- return(d->decoder.state);
- }
- interest->offset[CCN_PI_E_ComponentLast] = d->decoder.token_index - 1;
- interest->offset[CCN_PI_E_Name] = d->decoder.token_index;
- interest->prefix_comps = ncomp;
- interest->offset[CCN_PI_B_LastPrefixComponent] = components->buf[(ncomp > 0) ? (ncomp - 1) : 0];
- interest->offset[CCN_PI_E_LastPrefixComponent] = components->buf[ncomp];
- /* optional MinSuffixComponents, MaxSuffixComponents */
- interest->min_suffix_comps = 0;
- interest->max_suffix_comps = 32767;
- interest->offset[CCN_PI_B_MinSuffixComponents] = d->decoder.token_index;
- res = ccn_parse_optional_tagged_nonNegativeInteger(d,
- CCN_DTAG_MinSuffixComponents);
- interest->offset[CCN_PI_E_MinSuffixComponents] = d->decoder.token_index;
- if (res >= 0)
- interest->min_suffix_comps = res;
- interest->offset[CCN_PI_B_MaxSuffixComponents] = d->decoder.token_index;
- res = ccn_parse_optional_tagged_nonNegativeInteger(d,
- CCN_DTAG_MaxSuffixComponents);
- interest->offset[CCN_PI_E_MaxSuffixComponents] = d->decoder.token_index;
- if (res >= 0)
- interest->max_suffix_comps = res;
- if (interest->max_suffix_comps < interest->min_suffix_comps)
- return (d->decoder.state = -__LINE__);
- /* optional PublisherID */
- res = ccn_parse_PublisherID(d, interest);
- /* optional Exclude element */
- interest->offset[CCN_PI_B_Exclude] = d->decoder.token_index;
- res = ccn_parse_Exclude(d);
- interest->offset[CCN_PI_E_Exclude] = d->decoder.token_index;
- /* optional ChildSelector */
- interest->offset[CCN_PI_B_ChildSelector] = d->decoder.token_index;
- res = ccn_parse_optional_tagged_nonNegativeInteger(d,
- CCN_DTAG_ChildSelector);
- if (res < 0)
- res = 0;
- interest->orderpref = res;
- interest->offset[CCN_PI_E_ChildSelector] = d->decoder.token_index;
- if (interest->orderpref > 5)
- return (d->decoder.state = -__LINE__);
- /* optional AnswerOriginKind */
- interest->offset[CCN_PI_B_AnswerOriginKind] = d->decoder.token_index;
- interest->answerfrom = ccn_parse_optional_tagged_nonNegativeInteger(d,
- CCN_DTAG_AnswerOriginKind);
- interest->offset[CCN_PI_E_AnswerOriginKind] = d->decoder.token_index;
- if (interest->answerfrom == -1)
- interest->answerfrom = CCN_AOK_DEFAULT;
- else if ((interest->answerfrom & CCN_AOK_NEW) != 0 &&
- (interest->answerfrom & CCN_AOK_CS) == 0)
- return (d->decoder.state = -__LINE__);
- /* optional Scope */
- interest->offset[CCN_PI_B_Scope] = d->decoder.token_index;
- interest->scope = ccn_parse_optional_tagged_nonNegativeInteger(d,
- CCN_DTAG_Scope);
- interest->offset[CCN_PI_E_Scope] = d->decoder.token_index;
- if (interest->scope > 9)
- return (d->decoder.state = -__LINE__);
- if ((interest->answerfrom & CCN_AOK_EXPIRE) != 0 &&
- interest->scope != 0)
- return (d->decoder.state = -__LINE__);
- /* optional InterestLifetime */
- interest->offset[CCN_PI_B_InterestLifetime] = d->decoder.token_index;
- res = ccn_parse_optional_tagged_BLOB(d, CCN_DTAG_InterestLifetime, 1, 8);
- if (res >= 0)
- magic |= 20100401;
- interest->offset[CCN_PI_E_InterestLifetime] = d->decoder.token_index;
- /* optional Nonce */
- interest->offset[CCN_PI_B_Nonce] = d->decoder.token_index;
- res = ccn_parse_optional_tagged_BLOB(d, CCN_DTAG_Nonce, 4, 64);
- interest->offset[CCN_PI_E_Nonce] = d->decoder.token_index;
- /* Allow for no experimental stuff */
- interest->offset[CCN_PI_B_OTHER] = d->decoder.token_index;
- interest->offset[CCN_PI_E_OTHER] = d->decoder.token_index;
- ccn_buf_check_close(d);
- interest->offset[CCN_PI_E] = d->decoder.index;
- }
- else
- return (d->decoder.state = -__LINE__);
- if (d->decoder.state < 0)
- return (d->decoder.state);
- if (d->decoder.index != (int)size || !CCN_FINAL_DSTATE(d->decoder.state))
- return (CCN_DSTATE_ERR_CODING);
- if (magic == 0)
- magic = 20090701;
- if (!(magic == 20090701 || magic == 20100401))
- return (d->decoder.state = -__LINE__);
- interest->magic = magic;
- return (ncomp);
-}
-
-struct parsed_KeyName {
- int Name;
- int endName;
- int PublisherID;
- int endPublisherID;
-};
-
-static int
-ccn_parse_KeyName(struct ccn_buf_decoder *d, struct parsed_KeyName *x)
-{
- int res = -1;
- if (ccn_buf_match_dtag(d, CCN_DTAG_KeyName)) {
- res = d->decoder.element_index;
- ccn_buf_advance(d);
- x->Name = d->decoder.token_index;
- ccn_parse_Name(d, NULL);
- x->endName = d->decoder.token_index;
- x->PublisherID = ccn_parse_PublisherID(d, NULL);
- x->endPublisherID = d->decoder.token_index;
- ccn_buf_check_close(d);
- }
- else
- d->decoder.state = -__LINE__;
- if (d->decoder.state < 0)
- return (d->decoder.state);
- return(res);
-}
-
-static int
-ccn_parse_Signature(struct ccn_buf_decoder *d, struct ccn_parsed_ContentObject *x)
-{
- int res = -1;
- int i;
- struct ccn_parsed_ContentObject dummy;
- if (x == NULL)
- x = &dummy;
- for (i = CCN_PCO_B_Signature; i <= CCN_PCO_E_Signature; i++) {
- x->offset[i] = d->decoder.token_index;
- }
- if (ccn_buf_match_dtag(d, CCN_DTAG_Signature)) {
- res = d->decoder.element_index;
- ccn_buf_advance(d);
- x->offset[CCN_PCO_B_DigestAlgorithm] = d->decoder.token_index;
- ccn_parse_optional_tagged_UDATA(d, CCN_DTAG_DigestAlgorithm);
- x->offset[CCN_PCO_E_DigestAlgorithm] = d->decoder.token_index;
- x->offset[CCN_PCO_B_Witness] = d->decoder.token_index;
- ccn_parse_optional_tagged_BLOB(d, CCN_DTAG_Witness, 8, -1);
- x->offset[CCN_PCO_E_Witness] = d->decoder.token_index;
- x->offset[CCN_PCO_B_SignatureBits] = d->decoder.token_index;
- ccn_parse_required_tagged_BLOB(d, CCN_DTAG_SignatureBits, 16, -1);
- x->offset[CCN_PCO_E_SignatureBits] = d->decoder.token_index;
- ccn_buf_check_close(d);
- x->offset[CCN_PCO_E_Signature] = d->decoder.token_index;
- }
- if (d->decoder.state < 0)
- return (d->decoder.state);
- return(res);
-}
-
-static int
-ccn_parse_SignedInfo(struct ccn_buf_decoder *d, struct ccn_parsed_ContentObject *x)
-{
- x->offset[CCN_PCO_B_SignedInfo] = d->decoder.token_index;
- if (ccn_buf_match_dtag(d, CCN_DTAG_SignedInfo)) {
- ccn_buf_advance(d);
- x->offset[CCN_PCO_B_PublisherPublicKeyDigest] = d->decoder.token_index;
- ccn_parse_required_tagged_BLOB(d, CCN_DTAG_PublisherPublicKeyDigest, 16, 64);
- x->offset[CCN_PCO_E_PublisherPublicKeyDigest] = d->decoder.token_index;
-
- x->offset[CCN_PCO_B_Timestamp] = d->decoder.token_index;
- ccn_parse_required_tagged_timestamp(d, CCN_DTAG_Timestamp);
- x->offset[CCN_PCO_E_Timestamp] = d->decoder.token_index;
-
- x->offset[CCN_PCO_B_Type] = d->decoder.token_index;
- x->type = CCN_CONTENT_DATA;
- x->type = (ccn_content_type)ccn_parse_optional_tagged_binary_number(d, CCN_DTAG_Type, 3, 3, CCN_CONTENT_DATA);
- x->offset[CCN_PCO_E_Type] = d->decoder.token_index;
-
- x->offset[CCN_PCO_B_FreshnessSeconds] = d->decoder.token_index;
- ccn_parse_optional_tagged_nonNegativeInteger(d, CCN_DTAG_FreshnessSeconds);
- x->offset[CCN_PCO_E_FreshnessSeconds] = d->decoder.token_index;
-
- x->offset[CCN_PCO_B_FinalBlockID] = d->decoder.token_index;
- ccn_parse_optional_tagged_BLOB(d, CCN_DTAG_FinalBlockID, 1, -1);
- x->offset[CCN_PCO_E_FinalBlockID] = d->decoder.token_index;
-
- x->offset[CCN_PCO_B_KeyLocator] = d->decoder.token_index;
- x->offset[CCN_PCO_B_Key_Certificate_KeyName] = d->decoder.token_index;
- x->offset[CCN_PCO_E_Key_Certificate_KeyName] = d->decoder.token_index;
- x->offset[CCN_PCO_B_KeyName_Name] = d->decoder.token_index;
- x->offset[CCN_PCO_E_KeyName_Name] = d->decoder.token_index;
- x->offset[CCN_PCO_B_KeyName_Pub] = d->decoder.token_index;
- x->offset[CCN_PCO_E_KeyName_Pub] = d->decoder.token_index;
- if (ccn_buf_match_dtag(d, CCN_DTAG_KeyLocator)) {
- ccn_buf_advance(d);
- x->offset[CCN_PCO_B_Key_Certificate_KeyName] = d->decoder.token_index;
- if (ccn_buf_match_dtag(d, CCN_DTAG_Key)) {
- (void)ccn_parse_required_tagged_BLOB(d, CCN_DTAG_Key, 0, -1);
- }
- else if (ccn_buf_match_dtag(d, CCN_DTAG_Certificate)) {
- (void)ccn_parse_required_tagged_BLOB(d, CCN_DTAG_Certificate, 0, -1);
- }
- else {
- struct parsed_KeyName keyname = {-1, -1, -1, -1};
- if (ccn_parse_KeyName(d, &keyname) >= 0) {
- if (keyname.Name >= 0) {
- x->offset[CCN_PCO_B_KeyName_Name] = keyname.Name;
- x->offset[CCN_PCO_E_KeyName_Name] = keyname.endName;
- }
- if (keyname.PublisherID >= 0) {
- x->offset[CCN_PCO_B_KeyName_Pub] = keyname.PublisherID;
- x->offset[CCN_PCO_E_KeyName_Pub] = keyname.endPublisherID;
- }
- }
- }
- x->offset[CCN_PCO_E_Key_Certificate_KeyName] = d->decoder.token_index;
- ccn_buf_check_close(d);
- }
- x->offset[CCN_PCO_E_KeyLocator] = d->decoder.token_index;
- ccn_buf_check_close(d);
- }
- else
- d->decoder.state = -__LINE__;
- x->offset[CCN_PCO_E_SignedInfo] = d->decoder.token_index;
- if (d->decoder.state < 0)
- return (d->decoder.state);
- return(0);
-}
-
-int
-ccn_parse_ContentObject(const unsigned char *msg, size_t size,
- struct ccn_parsed_ContentObject *x,
- struct ccn_indexbuf *components)
-{
- struct ccn_buf_decoder decoder;
- struct ccn_buf_decoder *d = ccn_buf_decoder_start(&decoder, msg, size);
- int res;
- x->magic = 20090415;
- x->digest_bytes = 0;
- if (ccn_buf_match_dtag(d, CCN_DTAG_ContentObject)) {
- ccn_buf_advance(d);
- res = ccn_parse_Signature(d, x);
- x->offset[CCN_PCO_B_Name] = d->decoder.token_index;
- x->offset[CCN_PCO_B_Component0] = d->decoder.index;
- res = ccn_parse_Name(d, components);
- if (res < 0)
- d->decoder.state = -__LINE__;
- x->name_ncomps = res;
- x->offset[CCN_PCO_E_ComponentLast] = d->decoder.token_index - 1;
- x->offset[CCN_PCO_E_Name] = d->decoder.token_index;
- ccn_parse_SignedInfo(d, x);
- x->offset[CCN_PCO_B_Content] = d->decoder.token_index;
- ccn_parse_required_tagged_BLOB(d, CCN_DTAG_Content, 0, -1);
- x->offset[CCN_PCO_E_Content] = d->decoder.token_index;
- ccn_buf_check_close(d);
- x->offset[CCN_PCO_E] = d->decoder.index;
- }
- else
- d->decoder.state = -__LINE__;
- if (d->decoder.index != (int)size || !CCN_FINAL_DSTATE(d->decoder.state))
- return (CCN_DSTATE_ERR_CODING);
- return(0);
-}
-
-int
-ccn_ref_tagged_BLOB(enum ccn_dtag tt,
- const unsigned char *buf, size_t start, size_t stop,
- const unsigned char **presult, size_t *psize)
-{
- struct ccn_buf_decoder decoder;
- struct ccn_buf_decoder *d;
- if (stop < start) return(-1);
- d = ccn_buf_decoder_start(&decoder, buf + start, stop - start);
- if (ccn_buf_match_dtag(d, tt)) {
- ccn_buf_advance(d);
- if (ccn_buf_match_blob(d, presult, psize))
- ccn_buf_advance(d);
- ccn_buf_check_close(d);
- }
- else
- return(-1);
- if (d->decoder.index != (int)d->size || !CCN_FINAL_DSTATE(d->decoder.state))
- return (CCN_DSTATE_ERR_CODING);
- return(0);
-}
-
-static struct ccn_buf_decoder *
-ccn_buf_decoder_start_at_components(struct ccn_buf_decoder *d,
- const unsigned char *buf, size_t buflen)
-{
- ccn_buf_decoder_start(d, buf, buflen);
- while (ccn_buf_match_dtag(d, CCN_DTAG_Name) ||
- ccn_buf_match_dtag(d, CCN_DTAG_Interest) ||
- ccn_buf_match_dtag(d, CCN_DTAG_ContentObject)
- ) {
- ccn_buf_advance(d);
- ccn_parse_Signature(d, NULL);
- }
- return(d);
-}
-
-int
-ccn_content_get_value(const unsigned char *data, size_t data_size,
- const struct ccn_parsed_ContentObject *content,
- const unsigned char **value, size_t *value_size)
-{
- int res;
- res = ccn_ref_tagged_BLOB(CCN_DTAG_Content, data,
- content->offset[CCN_PCO_B_Content],
- content->offset[CCN_PCO_E_Content],
- value, value_size);
- return(res);
-}
-
-int
-ccn_compare_names(const unsigned char *a, size_t asize,
- const unsigned char *b, size_t bsize)
-{
- struct ccn_buf_decoder a_decoder;
- struct ccn_buf_decoder b_decoder;
- struct ccn_buf_decoder *aa =
- ccn_buf_decoder_start_at_components(&a_decoder, a, asize);
- struct ccn_buf_decoder *bb =
- ccn_buf_decoder_start_at_components(&b_decoder, b, bsize);
- const unsigned char *acp = NULL;
- const unsigned char *bcp = NULL;
- size_t acsize;
- size_t bcsize;
- int cmp = 0;
- int more_a;
- for (;;) {
- more_a = ccn_buf_match_dtag(aa, CCN_DTAG_Component);
- cmp = more_a - ccn_buf_match_dtag(bb, CCN_DTAG_Component);
- if (more_a == 0 || cmp != 0)
- break;
- ccn_buf_advance(aa);
- ccn_buf_advance(bb);
- acsize = bcsize = 0;
- if (ccn_buf_match_blob(aa, &acp, &acsize))
- ccn_buf_advance(aa);
- if (ccn_buf_match_blob(bb, &bcp, &bcsize))
- ccn_buf_advance(bb);
- cmp = acsize - bcsize;
- if (cmp != 0)
- break;
- cmp = memcmp(acp, bcp, acsize);
- if (cmp != 0)
- break;
- ccn_buf_check_close(aa);
- ccn_buf_check_close(bb);
- }
- return (cmp);
-}
-
diff --git a/in-progress/ccn/ccn_buf_encoder.cc b/in-progress/ccn/ccn_buf_encoder.cc
deleted file mode 100644
index d0d157b..0000000
--- a/in-progress/ccn/ccn_buf_encoder.cc
+++ /dev/null
@@ -1,91 +0,0 @@
-/* -*- 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>
- */
-
-#include <string.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/time.h>
-#include "ccn.h"
-#include "ccn_charbuf.h"
-#include "ccn_coding.h"
-#include "ccn_indexbuf.h"
-
-/**
- * Encode and sign a ContentObject.
- * @param buf is the output buffer where encoded object is written.
- * @param Name is the ccnb-encoded name from ccn_name_init and friends.
- * @param SignedInfo is the ccnb-encoded info from ccn_signed_info_create.
- * @param data pintes to the raw data to be encoded.
- * @param size is the size, in bytes, of the raw data to be encoded.
- * @param digest_algorithm may be NULL for default.
- * @param private_key is the private key to use for signing.
- * @returns 0 for success or -1 for error.
- */
-int
-ccn_encode_ContentObject(struct ccn_charbuf *buf,
- const struct ccn_charbuf *Name,
- /*const struct ccn_charbuf *SignedInfo,*/
- const void *data,
- size_t size
- /*const char *digest_algorithm,
- const struct ccn_pkey *private_key*/
- )
-{
- int res = 0;
-
- res |= ccn_charbuf_append_tt(buf, CCN_DTAG_ContentObject, CCN_DTAG);
- //res |= ccn_encode_Signature(buf, digest_algorithm,
- // NULL, 0, signature, signature_size);
- res |= ccn_charbuf_append_charbuf(buf, Name);
- //res |= ccn_charbuf_append_charbuf(buf, SignedInfo);
- res |= ccnb_append_tagged_blob(buf, CCN_DTAG_Content, data, size);
- res |= ccn_charbuf_append_closer(buf);
- //free(signature);
- ccn_charbuf_destroy(&content_header);
- return(res == 0 ? 0 : -1);
-}
-
-/**
- * Append a tagged BLOB
- *
- * This is a ccnb-encoded element with containing the BLOB as content
- * @param c is 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 0 for success or -1 for error.
- */
-int
-ccnb_append_tagged_blob(struct ccn_charbuf *c,
- enum ccn_dtag dtag,
- const void *data,
- size_t size)
-{
- int res;
-
- res = ccn_charbuf_append_tt(c, dtag, CCN_DTAG);
- if (size != 0) {
- res |= ccn_charbuf_append_tt(c, size, CCN_BLOB);
- res |= ccn_charbuf_append(c, data, size);
- }
- res |= ccn_charbuf_append_closer(c);
- return(res == 0 ? 0 : -1);
-}
diff --git a/in-progress/ccn/ccn_charbuf.cc b/in-progress/ccn/ccn_charbuf.cc
deleted file mode 100644
index 06c6544..0000000
--- a/in-progress/ccn/ccn_charbuf.cc
+++ /dev/null
@@ -1,215 +0,0 @@
-/* -*- 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>
- */
-
-#include "ccn_charbuf.h"
-
-/**
- * @file ccn_charbuf.c
- * @brief Support expandable buffer for counted sequences of arbitrary bytes.
- *
- * Part of the CCNx C Library.
- *
- * Copyright (C) 2008, 2009 Palo Alto Research Center, Inc.
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License version 2.1
- * as published by the Free Software Foundation.
- * This library 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
- * Lesser General Public License for more details. You should have received
- * a copy of the GNU Lesser General Public License along with this library;
- * if not, write to the Free Software Foundation, Inc., 51 Franklin Street,
- * Fifth Floor, Boston, MA 02110-1301 USA.
- */
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/time.h>
-#include "ccn_coding.h"
-
-struct ccn_charbuf *
-ccn_charbuf_create(void)
-{
- struct ccn_charbuf *c;
- c = (ccn_charbuf*)calloc(1, sizeof(*c));
- return(c);
-}
-
-void
-ccn_charbuf_destroy(struct ccn_charbuf **cbp)
-{
- struct ccn_charbuf *c = *cbp;
- if (c != NULL) {
- if (c->buf != NULL)
- free(c->buf);
- free(c);
- *cbp = NULL;
- }
-}
-
-/*
- * ccn_charbuf_reserve: expand buffer as necessary to hold n more chars
- */
-unsigned char *
-ccn_charbuf_reserve(struct ccn_charbuf *c, size_t n)
-{
- size_t newsz = n + c->length;
- unsigned char *buf = c->buf;
- if (newsz < n)
- return(NULL);
- if (newsz > c->limit) {
- if (2 * c->limit > newsz)
- newsz = 2 * c->limit;
- buf = (unsigned char*)realloc(c->buf, newsz);
- if (buf == NULL)
- return(NULL);
- memset(buf + c->limit, 0, newsz - c->limit);
- c->buf = buf;
- c->limit = newsz;
- }
- buf += c->length;
- return(buf);
-}
-
-void ccn_charbuf_reset(struct ccn_charbuf *c)
-{
- if (c == NULL) {
- return;
- }
- c->length = 0;
-}
-
-int
-ccn_charbuf_append(struct ccn_charbuf *c, const void *p, size_t n)
-{
- unsigned char *dst = ccn_charbuf_reserve(c, n);
- if (dst == NULL)
- return(-1);
- memcpy(dst, p, n);
- c->length += n;
- return(0);
-}
-
-int
-ccn_charbuf_append_value(struct ccn_charbuf *c, unsigned val, unsigned n)
-{
- unsigned char *dst;
- unsigned i;
- if (n > sizeof(val))
- return(-1);
- dst = ccn_charbuf_reserve(c, n);
- if (dst == NULL)
- return(-1);
- for (i = 0; i < n; i++)
- dst[i] = (unsigned char)(val >> (8 * (n-1-i)));
- c->length += n;
- return(0);
-}
-
-int
-ccn_charbuf_append_charbuf(struct ccn_charbuf *c, const struct ccn_charbuf *in)
-{
- return(ccn_charbuf_append(c, in->buf, in->length));
-}
-
-int
-ccn_charbuf_append_string(struct ccn_charbuf *c, const char *s)
-{
- return(ccn_charbuf_append(c, s, strlen(s)));
-}
-
-int
-ccn_charbuf_putf(struct ccn_charbuf *c, const char *fmt, ...)
-{
- int sz;
- va_list ap;
- char *buf;
- buf = (char *)ccn_charbuf_reserve(c, strlen(fmt) + 10); /* estimate */
- if (buf == NULL) return(-1);
- va_start(ap, fmt);
- sz = vsnprintf(buf, c->limit - c->length, fmt, ap);
- va_end(ap);
- if (sz < 0)
- return(sz);
- if (c->length + sz < c->limit) {
- c->length += sz;
- return(sz);
- }
- va_end(ap);
- buf = (char *)ccn_charbuf_reserve(c, sz + 1); /* accurate */
- if (buf == NULL) return(-1);
- va_start(ap, fmt);
- sz = vsnprintf(buf, c->limit - c->length, fmt, ap);
- va_end(ap);
- if (c->length + sz < c->limit) {
- c->length += sz;
- return(sz);
- }
- return(-1);
-}
-
-/* This formats time into xs:dateTime format */
-int
-ccn_charbuf_append_datetime(struct ccn_charbuf *c, time_t secs, int nsecs)
-{
- char timestring[32];
- int timelen;
- struct tm time_tm;
- int res;
-
- timelen = strftime(timestring, sizeof(timestring),
- "%FT%T", gmtime_r(&secs, &time_tm));
- if (timelen >= (int)sizeof(timestring))
- return(-1);
- if (nsecs != 0) {
- if (nsecs < 0 || nsecs >= 1000000000)
- return(-1);
- timelen += snprintf(×tring[timelen], sizeof(timestring) - timelen,
- ".%09d", nsecs);
- if (timelen >= (int)sizeof(timestring))
- return(-1);
- while (timestring[timelen - 1] == '0') timelen--;
- }
- timestring[timelen++] = 'Z';
- res = ccn_charbuf_append(c, timestring, timelen);
- return (res);
-}
-
-char *
-ccn_charbuf_as_string(struct ccn_charbuf *c)
-{
- unsigned char *r;
- r = ccn_charbuf_reserve(c, 1);
- if (r == NULL)
- return(NULL);
- r[0] = 0;
- return((char *)c->buf);
-}
-
-int
-ccn_charbuf_append_closer(struct ccn_charbuf *c)
-{
- int res;
- const unsigned char closer = CCN_CLOSE;
- res = ccn_charbuf_append(c, &closer, 1);
- return(res);
-}
diff --git a/in-progress/ccn/ccn_charbuf.h b/in-progress/ccn/ccn_charbuf.h
deleted file mode 100644
index 066eda2..0000000
--- a/in-progress/ccn/ccn_charbuf.h
+++ /dev/null
@@ -1,137 +0,0 @@
-/* -*- 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>
- */
-
-/**
- * @file ccn/charbuf.h
- *
- * Expandable character buffer for counted sequences of arbitrary octets.
- *
- * Part of the CCNx C Library.
- *
- * Copyright (C) 2008, 2009 Palo Alto Research Center, Inc.
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License version 2.1
- * as published by the Free Software Foundation.
- * This library 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
- * Lesser General Public License for more details. You should have received
- * a copy of the GNU Lesser General Public License along with this library;
- * if not, write to the Free Software Foundation, Inc., 51 Franklin Street,
- * Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#ifndef CCN_CHARBUF_DEFINED
-#define CCN_CHARBUF_DEFINED
-
-#include <stddef.h>
-#include <time.h>
-
-struct ccn_charbuf {
- size_t length;
- size_t limit;
- unsigned char *buf;
-};
-
-/*
- * ccn_charbuf_create: allocate a new charbuf
- * ccn_charbuf_destroy: destroy a charbuf
- */
-struct ccn_charbuf *ccn_charbuf_create(void);
-void ccn_charbuf_destroy(struct ccn_charbuf **cbp);
-
-/*
- * ccn_charbuf_reserve: reserve some space in the buffer
- * Grows c->buf if needed and returns a pointer to the new region.
- * Does not modify c->length
- */
-unsigned char *ccn_charbuf_reserve(struct ccn_charbuf *c, size_t n);
-
-/*
- * ccn_charbuf_reset: reset to empty for reuse
- * Sets c->length to 0
- */
-void ccn_charbuf_reset(struct ccn_charbuf *c);
-
-/*
- * ccn_charbuf_append: append character content
- */
-int ccn_charbuf_append(struct ccn_charbuf *c, const void *p, size_t n);
-
-/*
- * ccn_charbuf_append: append n bytes of val
- * The n low-order bytes are appended in network byte order (big-endian)
- */
-int ccn_charbuf_append_value(struct ccn_charbuf *c, unsigned val, unsigned n);
-
-
-/*
- * ccn_charbuf_append_charbuf: append content from another charbuf
- */
-int ccn_charbuf_append_charbuf(struct ccn_charbuf *c, const struct ccn_charbuf *i);
-
-/*
- * ccn_charbuf_append: append a string
- * Sometimes you have a null-terminated string in hand...
- */
-int ccn_charbuf_append_string(struct ccn_charbuf *c, const char *s);
-
-/*
- * ccn_charbuf_putf: formatting output
- * Use this in preference to snprintf to simplify bookkeeping.
- */
-int ccn_charbuf_putf(struct ccn_charbuf *c, const char *fmt, ...);
-
-/*
- * ccn_charbuf_append_datetime: append a date/time string
- * Appends a dateTime string in canonical form according to
- * http://www.w3.org/TR/xmlschema-2/
- * Return value is 0, or -1 for error.
- * example: 2008-07-22T17:33:14.109Z
- */
-int ccn_charbuf_append_datetime(struct ccn_charbuf *c, time_t secs, int nsecs);
-
-/*
- * ccn_charbuf_append_datetime_now: append a date/time string
- * Appends a dateTime string representing the current date and time
- * in canonical form according to
- * http://www.w3.org/TR/xmlschema-2/
- * precision, a non-negative number, indicates the maximum number
- * of fractional digits in the seconds. Only values 0..6 have
- * any effect, at this times, since the gettimeofday() function
- * is defined to return microsecond resolution.
- * Return value is 0, or -1 for error.
- * example: 2008-07-22T17:33:14.109Z
- */
-#define CCN_DATETIME_PRECISION_USEC 6
-#define CCN_DATETIME_PRECISION_MAX 6
-int ccn_charbuf_append_datetime_now(struct ccn_charbuf *c, int precision);
-
-/*
- * ccn_charbuf_as_string: view charbuf contents as a string
- * This assures that c->buf has a null termination, and simply
- * returns the pointer into the buffer. If the result needs to
- * persist beyond the next operation on c, the caller is
- * responsible for copying it.
- */
-char *ccn_charbuf_as_string(struct ccn_charbuf *c);
-
-#endif
diff --git a/in-progress/ccn/ccn_indexbuf.cc b/in-progress/ccn/ccn_indexbuf.cc
deleted file mode 100644
index 034c5db..0000000
--- a/in-progress/ccn/ccn_indexbuf.cc
+++ /dev/null
@@ -1,247 +0,0 @@
-/* -*- 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>
- */
-
-#include "ccn_indexbuf.h"
-
-/**
- * @file ccn_indexbuf.c
- * @brief Support for expandable buffer of non-negative values.
- *
- * Part of the CCNx C Library.
- *
- * Copyright (C) 2008, 2009 Palo Alto Research Center, Inc.
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License version 2.1
- * as published by the Free Software Foundation.
- * This library 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
- * Lesser General Public License for more details. You should have received
- * a copy of the GNU Lesser General Public License along with this library;
- * if not, write to the Free Software Foundation, Inc., 51 Franklin Street,
- * Fifth Floor, Boston, MA 02110-1301 USA.
- */
-#include <stddef.h>
-#include <stdlib.h>
-#include <string.h>
-
-#define ELEMENT size_t
-
-/**
- * Create a new indexbuf.
- */
-struct ccn_indexbuf *
-ccn_indexbuf_create(void)
-{
- struct ccn_indexbuf *c;
- c = (ccn_indexbuf*)calloc(1, sizeof(*c));
- return(c);
-}
-
-/**
- * Deallocate indexbuf.
- */
-void
-ccn_indexbuf_destroy(struct ccn_indexbuf **cbp)
-{
- struct ccn_indexbuf *c = *cbp;
- if (c != NULL) {
- if (c->buf != NULL) {
- free(c->buf);
- }
- free(c);
- *cbp = NULL;
- }
-}
-
-/**
- * Expand buffer as necessary to hold at least n more values.
- * @returns pointer to reserved space
- */
-ELEMENT *
-ccn_indexbuf_reserve(struct ccn_indexbuf *c, size_t n)
-{
- size_t newlim = n + c->n;
- size_t oldlim = c->limit;
- ELEMENT *buf = c->buf;
- if (newlim < n)
- return(NULL);
- if (newlim > oldlim) {
- if (2 * oldlim > newlim)
- newlim = 2 * oldlim;
- buf = (size_t*)realloc(c->buf, newlim * sizeof(ELEMENT));
- if (buf == NULL)
- return(NULL);
- memset(buf + oldlim, 0, (newlim - oldlim) * sizeof(ELEMENT));
- c->buf = buf;
- c->limit = newlim;
- }
- buf += c->n;
- return(buf);
-}
-
-/**
- * Append multiple elements to the indexbuf.
- * @returns 0 for success, -1 for failure.
- */
-int
-ccn_indexbuf_append(struct ccn_indexbuf *c, const ELEMENT *p, size_t n)
-{
- ELEMENT *dst = ccn_indexbuf_reserve(c, n);
- if (dst == NULL)
- return(-1);
- memcpy(dst, p, n * sizeof(ELEMENT));
- c->n += n;
- return(0);
-}
-
-/**
- * Append v to the indexbuf
- * @returns 0 for success, -1 for failure.
- */
-int
-ccn_indexbuf_append_element(struct ccn_indexbuf *c, ELEMENT v)
-{
- ELEMENT *dst = ccn_indexbuf_reserve(c, 1);
- if (dst == NULL)
- return(-1);
- *dst = v;
- c->n += 1;
- return(0);
-}
-
-/**
- * @returns index at which the element was found or appended, or -1 if not found.
- */
-int
-ccn_indexbuf_member(struct ccn_indexbuf *x, ELEMENT val)
-{
- int i;
- if (x == NULL)
- return (-1);
- for (i = x->n - 1; i >= 0; i--)
- if (x->buf[i] == val)
- return(i);
- return(-1);
-}
-
-/**
- * Removes up to one instance of val from the indexbuf.
- * Order of elements not preserved.
- */
-void
-ccn_indexbuf_remove_element(struct ccn_indexbuf *x, ELEMENT val)
-{
- int i;
- if (x == NULL) return;
- for (i = x->n - 1; i >= 0; i--)
- if (x->buf[i] == val) {
- x->buf[i] = x->buf[--x->n]; /* move last element into vacant spot */
- return;
- }
-}
-
-/**
- * @returns index at which the element was found or appended,
- * or -1 in case of error.
- */
-int
-ccn_indexbuf_set_insert(struct ccn_indexbuf *x, ELEMENT val)
-{
- int i;
- if (x == NULL)
- return (-1);
- for (i = 0; i < (int)x->n; i++)
- if (x->buf[i] == val)
- return(i);
- if (ccn_indexbuf_append_element(x, val) < 0)
- return(-1);
- return(i);
-}
-
-/**
- * Removes first occurrence of val, preserving order
- * @returns index at which the element was found,
- * or -1 if the element was not found.
- */
-int
-ccn_indexbuf_remove_first_match(struct ccn_indexbuf *x, ELEMENT val)
-{
- int i;
- int n;
- if (x == NULL)
- return (-1);
- for (i = 0, n = x->n; i < n; i++) {
- if (x->buf[i] == val) {
- if (i + 1 < n)
- memmove(&(x->buf[i]),
- &(x->buf[i + 1]),
- sizeof(x->buf[i]) * (n - i - 1));
- x->n--;
- return(i);
- }
- }
- return(-1);
-}
-
-/**
- * If val is present in the indexbuf, move it to the final place.
- */
-void
-ccn_indexbuf_move_to_end(struct ccn_indexbuf *x, ELEMENT val)
-{
- int i;
- int n;
- if (x == NULL)
- return;
- for (i = 0, n = x->n; i + 1 < n; i++) {
- if (x->buf[i] == val) {
- memmove(&(x->buf[i]),
- &(x->buf[i + 1]),
- sizeof(x->buf[i]) * (n - i - 1));
- x->buf[n - 1] = val;
- return;
- }
- }
-}
-
-/**
- * If val is present in the indexbuf, move it to the first place.
- */
-void
-ccn_indexbuf_move_to_front(struct ccn_indexbuf *x, ELEMENT val)
-{
- int i;
- int n;
- if (x == NULL)
- return;
- for (i = 0, n = x->n; i < n; i++) {
- if (x->buf[i] == val) {
- memmove(&(x->buf[1]),
- &(x->buf[0]),
- sizeof(x->buf[i]) * i);
- x->buf[0] = val;
- return;
- }
- }
-
-}
-
diff --git a/in-progress/ccn/ccn_indexbuf.h b/in-progress/ccn/ccn_indexbuf.h
deleted file mode 100644
index 3e133c3..0000000
--- a/in-progress/ccn/ccn_indexbuf.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/* -*- 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>
- */
-
-/**
- * @file ccn/indexbuf.h
- *
- * Expandable buffer of non-negative values.
- *
- * Part of the CCNx C Library.
- *
- * Copyright (C) 2008, 2009 Palo Alto Research Center, Inc.
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License version 2.1
- * as published by the Free Software Foundation.
- * This library 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
- * Lesser General Public License for more details. You should have received
- * a copy of the GNU Lesser General Public License along with this library;
- * if not, write to the Free Software Foundation, Inc., 51 Franklin Street,
- * Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#ifndef CCN_INDEXBUF_DEFINED
-#define CCN_INDEXBUF_DEFINED
-
-#include <stddef.h>
-
-struct ccn_indexbuf {
- size_t n;
- size_t limit;
- size_t *buf;
-};
-
-struct ccn_indexbuf *ccn_indexbuf_create(void);
-void ccn_indexbuf_destroy(struct ccn_indexbuf **cbp);
-size_t *ccn_indexbuf_reserve(struct ccn_indexbuf *c, size_t n);
-int ccn_indexbuf_append(struct ccn_indexbuf *c, const size_t *p, size_t n);
-int ccn_indexbuf_append_element(struct ccn_indexbuf *c, size_t v);
-int ccn_indexbuf_member(struct ccn_indexbuf *x, size_t val);
-void ccn_indexbuf_remove_element(struct ccn_indexbuf *x, size_t val);
-int ccn_indexbuf_set_insert(struct ccn_indexbuf *x, size_t val);
-int ccn_indexbuf_remove_first_match(struct ccn_indexbuf *x, size_t val);
-void ccn_indexbuf_move_to_end(struct ccn_indexbuf *x, size_t val);
-void ccn_indexbuf_move_to_front(struct ccn_indexbuf *x, size_t val);
-
-#endif
diff --git a/in-progress/ccn/ccn_name_util.cc b/in-progress/ccn/ccn_name_util.cc
deleted file mode 100644
index 64405ce..0000000
--- a/in-progress/ccn/ccn_name_util.cc
+++ /dev/null
@@ -1,326 +0,0 @@
-/* -*- 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>
- */
-
-#include "ccn_name_util.h"
-#include "ccn_coding.h"
-#include "ccn_charbuf.h"
-#include "ccn_indexbuf.h"
-#include <string.h>
-#include <stdlib.h>
-#include "ccn_random.h"
-#include "ccn.h"
-
-/**
- * @file ccn_name_util.c
- * @brief Support for manipulating ccnb-encoded Names.
- *
- * Part of the CCNx C Library.
- *
- * Copyright (C) 2008-2010 Palo Alto Research Center, Inc.
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License version 2.1
- * as published by the Free Software Foundation.
- * This library 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
- * Lesser General Public License for more details. You should have received
- * a copy of the GNU Lesser General Public License along with this library;
- * if not, write to the Free Software Foundation, Inc., 51 Franklin Street,
- * Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-//#include <ccn/ccn.h>
-
-/**
- * Reset charbuf to represent an empty Name in binary format.
- * @returns 0, or -1 for error.
- */
-int
-ccn_name_init(struct ccn_charbuf *c)
-{
- int res;
- c->length = 0;
- res = ccn_charbuf_append_tt(c, CCN_DTAG_Name, CCN_DTAG);
- if (res == -1) return(res);
- res = ccn_charbuf_append_closer(c);
- return(res);
-}
-
-/**
- * Add a Component to a Name.
- *
- * The component is an arbitrary string of n octets, no escaping required.
- * @returns 0, or -1 for error.
- */
-int
-ccn_name_append(struct ccn_charbuf *c, const void *component, size_t n)
-{
- int res;
- const unsigned char closer[2] = {CCN_CLOSE, CCN_CLOSE};
- if (c->length < 2 || c->buf[c->length-1] != closer[1])
- return(-1);
- c->length -= 1;
- ccn_charbuf_reserve(c, n + 8);
- res = ccn_charbuf_append_tt(c, CCN_DTAG_Component, CCN_DTAG);
- if (res == -1) return(res);
- res = ccn_charbuf_append_tt(c, n, CCN_BLOB);
- if (res == -1) return(res);
- res = ccn_charbuf_append(c, component, n);
- if (res == -1) return(res);
- res = ccn_charbuf_append(c, closer, sizeof(closer));
- return(res);
-}
-
-/**
- * Add a Component that is a NUL-terminated string.
- *
- * The component added consists of the bytes of the string without the NUL.
- * This function is convenient for those applications that construct
- * component names from simple strings.
- * @returns 0, or -1 for error.
- */
-int
-ccn_name_append_str(struct ccn_charbuf *c, const char *s)
-{
- return(ccn_name_append(c, s, strlen(s)));
-}
-
-/**
- * Add a binary Component to a ccnb-encoded Name
- *
- * These are special components used for marking versions, fragments, etc.
- * @returns 0, or -1 for error
- * see doc/technical/NameConventions.html
- */
-int
-ccn_name_append_numeric(struct ccn_charbuf *c,
- enum ccn_marker marker, unsigned long long value)
-{
- //uintmax_t v;
- unsigned long long v;
- int i;
- char b[32];
-
- for (v = value, i = sizeof(b); v != 0 && i > 0; i--, v >>= 8)
- b[i-1] = v & 0xff;
- if (i < 1)
- return(-1);
- if (marker >= 0)
- b[--i] = marker;
- return(ccn_name_append(c, b + i, sizeof(b) - i));
-}
-
-/**
- * Add nonce Component to ccnb-encoded Name
- *
- * Uses %C1.N namespace.
- * @returns 0, or -1 for error
- * see doc/technical/NameConventions.html
- */
-int
-ccn_name_append_nonce(struct ccn_charbuf *c)
-{
- const unsigned char pre[4] = { CCN_MARKER_CONTROL, '.', 'N', 0 };
- unsigned char b[15];
-
- memcpy(b, pre, sizeof(pre));
- ccn_random_bytes(b + sizeof(pre), sizeof(b) - sizeof(pre));
- return(ccn_name_append(c, b, sizeof(b)));
-}
-
-/**
- * Add sequence of ccnb-encoded Components to a ccnb-encoded Name.
- *
- * start and stop are offsets from ccnb
- * @returns 0, or -1 for obvious error
- */
-int
-ccn_name_append_components(struct ccn_charbuf *c,
- const unsigned char *ccnb,
- size_t start, size_t stop)
-{
- int res;
- if (c->length < 2 || start > stop)
- return(-1);
- c->length -= 1;
- ccn_charbuf_reserve(c, stop - start + 1);
- res = ccn_charbuf_append(c, ccnb + start, stop - start);
- if (res == -1) return(res);
- res = ccn_charbuf_append_closer(c);
- return(res);
-}
-
-/**
- * Extract a pointer to and size of component at
- * given index i. The first component is index 0.
- * @returns 0, or -1 for error.
- */
-int
-ccn_name_comp_get(const unsigned char *data,
- const struct ccn_indexbuf *indexbuf,
- unsigned int i,
- const unsigned char **comp, size_t *size)
-{
- int len;
- struct ccn_buf_decoder decoder;
- struct ccn_buf_decoder *d;
- /* indexbuf should have an extra value marking end of last component,
- so we need to use last 2 values */
- if (indexbuf->n < 2 || i > indexbuf->n - 2) {
- /* There isn't a component at this index */
- return(-1);
- }
- len = indexbuf->buf[i + 1]-indexbuf->buf[i];
- d = ccn_buf_decoder_start(&decoder, data + indexbuf->buf[i], len);
- if (ccn_buf_match_dtag(d, CCN_DTAG_Component)) {
- ccn_buf_advance(d);
- if (ccn_buf_match_blob(d, comp, size))
- return(0);
- *comp = d->buf + d->decoder.index;
- *size = 0;
- ccn_buf_check_close(d);
- if (d->decoder.state >= 0)
- return(0);
- }
- return(-1);
-}
-
-int
-ccn_name_comp_strcmp(const unsigned char *data,
- const struct ccn_indexbuf *indexbuf,
- unsigned int i, const char *val)
-{
- const unsigned char *comp_ptr;
- size_t comp_size;
-
- // XXX - We probably want somewhat different semantics in the API -
- // comparing a string against a longer string with a 0 byte should
- // not claim equality.
- if (ccn_name_comp_get(data, indexbuf, i, &comp_ptr, &comp_size) == 0)
- return(strncmp(val, (const char *)comp_ptr, comp_size));
- /* Probably no such component, say query is greater-than */
- return(1);
-}
-
-/**
- * Find Component boundaries in a ccnb-encoded Name.
- *
- * Thin veneer over ccn_parse_Name().
- * components arg may be NULL to just do a validity check
- *
- * @returns -1 for error, otherwise the number of Components.
- */
-int
-ccn_name_split(const struct ccn_charbuf *c, struct ccn_indexbuf *components)
-{
- struct ccn_buf_decoder decoder;
- struct ccn_buf_decoder *d;
- d = ccn_buf_decoder_start(&decoder, c->buf, c->length);
- return(ccn_parse_Name(d, components));
-}
-
-/**
- * Chop the name down to n components.
- * @param c contains a ccnb-encoded Name
- * @param components may be NULL; if provided it must be consistent with
- * some prefix of the name, and is updated accordingly.
- * @param n is the number or components to leave, or, if negative, specifies
- * how many components to remove,
- e.g. -1 will remove just the last component.
- * @returns -1 for error, otherwise the new number of Components
- */
-int
-ccn_name_chop(struct ccn_charbuf *c, struct ccn_indexbuf *components, int n)
-{
- if (components == NULL) {
- int res;
- components = ccn_indexbuf_create();
- if (components == NULL)
- return(-1);
- res = ccn_name_split(c, components);
- if (res >= 0)
- res = ccn_name_chop(c, components, n);
- ccn_indexbuf_destroy(&components);
- return(res);
- }
- /* Fix up components if needed. We could be a little smarter about this. */
- if (components->n == 0 || components->buf[components->n-1] + 1 != c->length)
- if (ccn_name_split(c, components) < 0)
- return(-1);
- if (n < 0)
- n += (components->n - 1); /* APL-style indexing */
- if (n < 0)
- return(-1);
- if (n < (int)(components->n)) {
- c->length = components->buf[n];
- ccn_charbuf_append_value(c, CCN_CLOSE, 1);
- components->n = n + 1;
- return(n);
- }
- return(-1);
-}
-
-/**
- * Advance the last Component of a Name to the next possible value.
- * @param c contains a ccnb-encoded Name to be updated.
- * @returns -1 for error, otherwise the number of Components
- */
-int
-ccn_name_next_sibling(struct ccn_charbuf *c)
-{
- int res = -1;
- struct ccn_indexbuf *ndx;
- unsigned char *lastcomp = NULL;
- size_t lastcompsize = 0;
- size_t i;
- int carry;
- struct ccn_charbuf *newcomp;
-
- ndx = ccn_indexbuf_create();
- if (ndx == NULL) goto Finish;
- res = ccn_name_split(c, ndx);
- if (res <= 0) {
- res = -1;
- goto Finish;
- }
- res = ccn_ref_tagged_BLOB(CCN_DTAG_Component, c->buf,
- ndx->buf[res-1], ndx->buf[res],
- (const unsigned char **)&lastcomp,
- &lastcompsize);
- if (res < 0) goto Finish;
- for (carry = 1, i = lastcompsize; carry && i > 0; i--) {
- carry = (((++lastcomp[i-1]) & 0xFF) == 0x00);
- }
- if (carry) {
- newcomp = ccn_charbuf_create();
- res |= ccn_charbuf_append_value(newcomp, 0, 1);
- res |= ccn_charbuf_append(newcomp, lastcomp, lastcompsize);
- res |= ccn_name_chop(c, ndx, ndx->n - 2);
- res |= ccn_name_append(c, newcomp->buf, newcomp->length);
- ccn_charbuf_destroy(&newcomp);
- if (res < 0) goto Finish;
- }
- res = ndx->n - 1;
-Finish:
- ccn_indexbuf_destroy(&ndx);
- return(res);
-}
-
diff --git a/in-progress/ccn/ccn_random.cc b/in-progress/ccn/ccn_random.cc
deleted file mode 100644
index 6176c79..0000000
--- a/in-progress/ccn/ccn_random.cc
+++ /dev/null
@@ -1,59 +0,0 @@
-/* -*- 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>
- */
-
-#include "ccn_random.h"
-#include <openssl/rand.h>
-//#include <openssl/rand.c>
-
-/**
- * Generate pseudo-random bytes.
- *
- * @param buf is the destination buffer
- * @param size is in bytes
- */
-void
-ccn_random_bytes(unsigned char *buf, size_t size)
-{
- int num = size;
-
- if (num < 0 || num != (int)size)
- abort();
- RAND_bytes(buf, num);
-}
-
-/**
- * Feed some entropy to the random number generator.
- *
- * @param buf is the source buffer
- * @param size is in bytes
- * @param bits_of_entropy is an estimate; use 0 to make me guess
- */
-void
-ccn_add_entropy(const void *buf, size_t size, int bits_of_entropy)
-{
- int num = size;
-
- if (num < 0 || num != (int)size)
- abort();
- /* Supply a hopefully conservative estimate of entropy. */
- if (bits_of_entropy <= 0)
- bits_of_entropy = (num < 32) ? 1 : num / 32;
- RAND_add((unsigned char *)buf, num, bits_of_entropy * 0.125);
-}
diff --git a/in-progress/ccn/ccn_random.h b/in-progress/ccn/ccn_random.h
deleted file mode 100644
index ddd0a38..0000000
--- a/in-progress/ccn/ccn_random.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/* -*- 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>
- */
-
-/**
- * @file random.h
- * @brief Pseudo-random number generation
- *
- * Part of the CCNx C Library.
- *
- * Copyright (C) 2010 Palo Alto Research Center, Inc.
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License version 2.1
- * as published by the Free Software Foundation.
- * This library 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
- * Lesser General Public License for more details. You should have received
- * a copy of the GNU Lesser General Public License along with this library;
- * if not, write to the Free Software Foundation, Inc., 51 Franklin Street,
- * Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#ifndef CCN_RANDOM_DEFINED
-#define CCN_RANDOM_DEFINED
-
-#include <stddef.h>
-#include <openssl/rand.h>
-
-void ccn_random_bytes(unsigned char *buf, size_t size);
-void ccn_add_entropy(const void *buf, size_t size, int bits_of_entropy);
-
-#endif
diff --git a/in-progress/ccnx-contentstore.cc b/in-progress/ccnx-contentstore.cc
deleted file mode 100644
index 61d6452..0000000
--- a/in-progress/ccnx-contentstore.cc
+++ /dev/null
@@ -1,123 +0,0 @@
-/* -*- 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>
- */
-
-#include "ndn_contentstore.h"
-
-namespace ns3
-{
-namespace NDNabstraction
-{
-
-ContentStore::ContentStore( int maxSize )
-: m_maxSize(maxSize) { }
-
-
-ContentStore::~ContentStore( )
-{ }
-
-//Find corresponding CS entry for the given content name
-CsEntry*
-ContentStore::Lookup(const char *prefix )
-{
- CriticalSection section(m_csMutex);
-
- struct CsEntry *result = NULL;
-
- HASH_FIND_STR (m_contentStore, prefix, result);
-
- if(result != NULL)
- Promote (*result);
-
- return result;
-}
-
-
-
-//Add entry to content store, if content store is full, use LRU replacement
-void
-ContentStore::Add( const char *contentName, int contentSize )
-{
- CriticalSection section(m_csMutex);
-
- // removing the old record
- struct CsEntry *tmp = NULL;
- HASH_FIND_STR (m_contentStore, contentName, tmp);
- HASH_DELETE (hh, m_contentStore,tmp);
- //free(tmp);
-
- int size = (int)HASH_COUNT(m_contentStore);
-
- if(size == m_maxSize )
- {
- CsEntry *entry = m_LRU.back();
- HASH_DELETE (hh, m_contentStore,entry);//_cs.erase( entry->contentName );
- m_LRU.pop_back( );
- }
-
- struct CsEntry *ce = (struct CsEntry*)malloc(sizeof(struct CsEntry));
- ce->contentName = (char*)contentName;
- ce->contentSize = contentSize;
-
- //_cs[ contentName ] = ce;
- HASH_ADD_KEYPTR (hh, m_contentStore, ce->contentName, strlen(ce->contentName), ce);
-
- //CsEntry *ce_in_hash = &(_cs[ contentName ]);
- struct CsEntry *ce_in_hash = NULL;
- HASH_FIND_STR (m_contentStore, contentName, ce_in_hash);
- m_LRU.push_front( ce_in_hash );
- ce_in_hash->lruPosition = m_LRU.begin( );
-}
-
-
-//move the given CS entry to the head of the list
-void
-ContentStore::Promote(CsEntry &ce )
-{
- // should not lock mutex. Otherwise deadlocks will be welcome
- if( m_LRU.front() == &ce ) return;
-
- //assert( *(ce.lruPosition)==&ce ); // should point to the same object
-
- // swaping positions in _lru
- m_LRU.erase( ce.lruPosition );
- m_LRU.push_front( &ce );
- ce.lruPosition = m_LRU.begin( );
-
- //assert( *(ce.lruPosition)==&ce ); // should point to the same object
-}
-
-void
-ContentStore::Dump()
-{
- CriticalSection section(m_csMutex);
-
- struct CsEntry *s, *tmp;
-
- HASH_ITER(hh, m_contentStore, s, tmp)
- {
- printf("-%s-", s->contentName);
- /* ... it is safe to delete and free s here */
- }
-
- printf("\n");
-
-}
-}
-}
diff --git a/in-progress/ccnx-contentstore.h b/in-progress/ccnx-contentstore.h
deleted file mode 100644
index 7e49fb6..0000000
--- a/in-progress/ccnx-contentstore.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/* -*- 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>
- */
-
-#ifndef ndn_contentstore_h
-#define ndn_contentstore_h
-
-#include <ns3/system-mutex.h>
-#include <list>
-#include <string>
-#include "uthash.h"
-
-using namespace std;
-
-//size of content store
-#define NDN_CONTENT_STORE_SIZE 100
-
-namespace ns3
-{
-namespace NDNabstraction
-{
-
-class CsEntry;
-typedef list<CsEntry*>::iterator CsLruIterator;
-
-//structure for CS entry
-struct CsEntry
-{
- char *contentName;
- int contentSize;
-
- CsLruIterator lruPosition;
- UT_hash_handle hh; /* makes this structure hashable */
-};
-
-
-class ContentStore
-{
-public:
- ContentStore( int max_size=NDN_CONTENT_STORE_SIZE );
- virtual ~ContentStore( );
-
- // Find corresponding CS entry for the given content name
- CsEntry* Lookup( const char *prefix );
- //bool isValid( const CsIterator &it ) { return it!=_cs.end(); }
-
- // Add new content to the content store. Old content will be replaced
- void Add( const char *contentName, int contentSize );
-
- // Dump content store entries
- void Dump( );
-
-protected:
- //move the given CS entry to the head of the list
- void Promote( CsEntry &entry );
-
-private:
- int m_maxSize; // maximum number of entries in cache
-
- struct CsEntry *m_contentStore; // actual content store
- list<CsEntry*> m_LRU; // LRU index of the content store
- SystemMutex m_csMutex; // just to make sure we are not
-};
-
-}
-}
-#endif
diff --git a/in-progress/ccnx-cs.cpp b/in-progress/ccnx-cs.cpp
deleted file mode 100644
index c102cd5..0000000
--- a/in-progress/ccnx-cs.cpp
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * File: ndn_cs.cpp
- * Author: cawka
- *
- * Created on December 15, 2010, 2:17 PM
- */
-
-#include "ndn_cs.h"
-
-NdnCs::NdnCs( int maxSize )
-: _maxSize(maxSize) { }
-
-//NdnCs::NdnCs( constNdnCs& orig ) { }
-
-NdnCs::~NdnCs( ) { }
-
-//Find corresponding CS entry for the given content name
-CsIterator NdnCs::lookup( const string &prefix )
-{
- QNThreadLock lock( &_csMutex );
-
- CsIterator entry=_cs.find( prefix );
- if( entry!=_cs.end() ) promote( entry->second );
- return entry;
-}
-
-
-
-//Add entry to content store, if content store is full, use LRU replacement
-void NdnCs::add( const string &contentName, int contentSize )
-{
- QNThreadLock lock( &_csMutex );
-
- _cs.erase( contentName ); // removing the old record
-
- if( _cs.size()==_maxSize )
- {
- CsEntry *entry=_lru.back();
- _cs.erase( entry->contentName );
- _lru.pop_back( );
- }
-
- CsEntry ce;
- ce.contentName = contentName;
- ce.contentSize = contentSize;
-
- _cs[ contentName ] = ce;
-
- CsEntry *ce_in_hash = &(_cs[ contentName ]);
- _lru.push_front( ce_in_hash );
- ce_in_hash->lruPosition = _lru.begin( );
-}
-
-
-//move the given CS entry to the head of the list
-void NdnCs::promote( CsEntry &ce )
-{
- // should not lock mutex. Otherwise deadlocks will be welcome
- if( _lru.front() == &ce ) return;
-
- assert( *(ce.lruPosition)==&ce ); // should point to the same object
-
- // swaping positions in _lru
- _lru.erase( ce.lruPosition );
- _lru.push_front( &ce );
- ce.lruPosition = _lru.begin( );
-
- assert( *(ce.lruPosition)==&ce ); // should point to the same object
-}
-
-void NdnCs::dump()
-{
- QNThreadLock lock( &_csMutex );
-
- for( CsRangeIterator it=_cs.begin(); it!=_cs.end(); ++it )
- {
- printf("-%s-", it->second.contentName.c_str() );
- }
-
- printf("\n");
-// list<CsEntry *>::reverse_iterator rit;
-//
-// for (rit = contentList->rbegin(); rit != contentList->rend(); rit ++)
-// {
-// temp = *rit;
-// printf("=%s=", temp->contentName);
-// }
-//
-// printf("\n");
-}
diff --git a/in-progress/ccnx-cs.h b/in-progress/ccnx-cs.h
deleted file mode 100644
index 096b0c0..0000000
--- a/in-progress/ccnx-cs.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * File: ndn_cs.h
- * Author: cawka
- *
- * Created on December 15, 2010, 2:17 PM
- */
-
-#ifndef NDN_CS_H
-#define NDN_CS_H
-
-#include "ndn_common.h"
-#include "hash_helper.h"
-#include <qualnet_mutex.h>
-#include <list>
-#include <string>
-
-using namespace std;
-
-class CsEntry;
-typedef list<CsEntry*>::iterator CsLruIterator;
-
-//structure for CS entry
-struct CsEntry
-{
- string contentName;
- int contentSize;
-
- CsLruIterator lruPosition;
-};
-
-typedef string_key_hash_t<CsEntry>::point_iterator CsIterator;
-typedef string_key_hash_t<CsEntry>::iterator CsRangeIterator;
-
-// class implementing NDN content store
-class NdnCs
-{
-public:
- NdnCs( int max_size=NDN_CONTENT_STORE_SIZE );
- virtual ~NdnCs( );
-
- // Find corresponding CS entry for the given content name
- CsIterator lookup( const string &prefix );
- bool isValid( const CsIterator &it ) { return it!=_cs.end(); }
-
- // Add new content to the content store. Old content will be replaced
- void add( const string &contentName, int contentSize );
-
- // Dump content store entries
- void dump( );
-
-protected:
- //move the given CS entry to the head of the list
- void promote( CsEntry &entry );
-
-private:
- int _maxSize; // maximum number of entries in cache
-
- string_key_hash_t<CsEntry> _cs; // actual content store
-
- list<CsEntry*> _lru; // LRU index of the content store
- QNThreadMutex _csMutex; // just to make sure we are not
- // getting problems with multiple threads
-};
-
-#endif /* NDN_CS_H */
diff --git a/in-progress/ccnx-fib.cpp b/in-progress/ccnx-fib.cpp
deleted file mode 100644
index a8adbd0..0000000
--- a/in-progress/ccnx-fib.cpp
+++ /dev/null
@@ -1,300 +0,0 @@
-/*
- * File: ndn_fib.cpp
- * Author: cawka
- *
- * Created on December 15, 2010, 1:54 PM
- */
-
-#include "ndn.h"
-#include "ndn_fib.h"
-
-#include <node.h>
-#include <buffer.h>
-#include <network_ip.h>
-#include <partition.h>
-#include <routing_ospfv2.h>
-#include <routing_bgp.h>
-
-//#define NDN_DEBUG_OSPF 0
-//#define NDN_DEBUG_OSPF_NODES 0
-
-//#define NDN_DUMP_FIB 0
-
-
-NdnFib::NdnFib( Ndn &node ) : _node(node) { }
-
-NdnFib::~NdnFib( ) { }
-
-
-//Find corresponding FIB entry for the given content name
-//Longest match is performed
-FibIterator NdnFib::lookup( const string &name )
-{
- string prefix=name;
-
- FibIterator entry;
- do
- {
- entry=_fib.find( prefix );
-
- prefix = GetLongestNamePrefix( prefix );
- } while( !isValid(entry) && prefix.size()>0 );
-
- return entry;
-}
-
-bool NdnFibNexthopSorter::operator()( const FibNexthop &first, const FibNexthop &second )
-{
- // Right now is a very simple logic.
- // Probably this logic should be changed later
- if( first. cost==NETWORK_UNREACHABLE && second.cost>=0 ) return false;
- if( second.cost==NETWORK_UNREACHABLE && first. cost>=0 ) return true;
- return first.cost < second.cost;
-}
-
-/**
- * Update FIB entry
- * If the entry exists, metric will be updated. Otherwise, new entry will be created
- *
- * @param name Prefix
- * @param interfaceIndex Forwarding interface
- * @param metric Routing metric
- * @param nextHop Nexthop node address (IPv4)
- * @return true if a new entry created, false otherwise
- */
-bool NdnFib::update( const string &name, int interfaceIndex, int metric, NodeAddress nextHop )
-{
- FibIterator entry = _fib.find( name );
- if( isValid(entry) )
- {
- FibNexthopIterator nh = VALUE(entry).findNexthop( interfaceIndex );
-
- if( !VALUE(entry).isValid(nh) )
- {
- nh = VALUE(entry).forwardingList.insert( VALUE(entry).forwardingList.begin(),
- FibNexthop(interfaceIndex,nextHop,metric) );
- }
- else
- {
- nh->cost = metric;
- nh->nextHop = nextHop;
- }
-
- VALUE(entry).forwardingList.sort( NdnFibNexthopSorter() );
-
- return false;
- }
-
- FibEntry &new_entry = _fib[name];
- new_entry.forwardingList.push_back( FibNexthop(interfaceIndex,nextHop,metric) );
-
- for( int interface=0; interface < _node.getNode()->numberInterfaces; interface++ )
- {
- NodeAddress src = NetworkIpGetInterfaceAddress( _node.getNode(), interface );
-
- if( isValidLink(src) && interface!=interfaceIndex )
- {
- new_entry.forwardingList.push_back( FibNexthop(interface,0,NETWORK_UNREACHABLE) );
- }
- }
-
- return true;
-}
-
-// helper for update call
-bool NdnFib::update( NodeAddress nodeId, int metric, NodeAddress nextHop )
-{
- ostringstream os;
- os << (int)nodeId;
-
- int interface = NetworkIpGetInterfaceIndexForNextHop( _node.getNode(), nextHop );
-
- return update( os.str(), interface, metric, nextHop );
-}
-
-// helper for update call
-bool NdnFib::update( NodeAddress nodeId, int interfaceIndex, int metric, NodeAddress nextHop )
-{
- ostringstream os;
- os << (int)nodeId;
-
- int interface = NetworkIpGetInterfaceIndexForNextHop( _node.getNode(), nextHop );
-
- return update( os.str(), interface, metric, nextHop ); //unknown metric
-}
-
-/**
- * Invalidate entries in FIB
- */
-void NdnFib::invalidate( )
-{
- for( FibRangeIterator fib=_fib.begin(); fib!=_fib.end(); fib++ )
- {
- for( FibNexthopIterator nh=VALUE(fib).forwardingList.begin(); nh!=VALUE(fib).forwardingList.end(); nh++ )
- {
- nh->cost = NETWORK_UNREACHABLE;
- }
- }
-}
-
-//compute and update STO value for Fib Entry (similar to RFC 2988)
-//for now we pick the maximum rto of all forwardings
-void FibEntry::updateSto( )
-{
- assert( forwardingList.size() > 0 );
-
- clocktype max = 0;
-
- for( FibNexthopIterator it = forwardingList.begin();
- it != forwardingList.end();
- it++ )
- {
- clocktype sto = it->srtt + NDN_RTO_K * it->rttvar;
-
- if( sto > max )
- max = sto;
- }
-
- this->sto = max;
-}
-
-
-/**
- * Updating FIB using data from OSPF
- * @param node
- * @param interface -2 Invalid OSPF (to purge FIB)
- * -1 Normal OSPF
- * 0-N SPF was calcylated using only interface `interface'
- *
- * @bug All local networks will always appear in routing table with cost == 1
- */
-void NdnFib::updateFibFromOSPFv2( int interface )
-{
- Ospfv2Data* ospf = (Ospfv2Data*)NetworkIpGetRoutingProtocol(_node.getNode(), ROUTING_PROTOCOL_OSPFv2);
-
- if( interface==-2 ) invalidate( );
-
-#ifdef NDN_DEBUG_OSPF
- if( interface==-1 ) printf( "Routing/interface costs\n" );
-#endif // NDN_DEBUG_OSPF
-
-#ifdef NDN_DEBUG_OSPF_NODES
- printf( "-- Node %d (interface %d) --\n", _node.getNode()->nodeId, interface );
-#endif // NDN_DEBUG_OSPF_NODES
-
- Ospfv2RoutingTableRow* rowPtr = (Ospfv2RoutingTableRow*)
- BUFFER_GetData(&ospf->routingTable.buffer);
-
- for (int i = 0; i < ospf->routingTable.numRows; i++)
- {
- NodeAddress destNodeId = Ipv4ToNodeId( rowPtr[i].destAddr );
-
- if( destNodeId!=-1 ) update( destNodeId, rowPtr[i].metric, rowPtr[i].nextHop );
- }
-
-#ifdef NDN_DUMP_FIB
- if( interface==-1 ) dump( );
-#endif
-}
-
-void NdnFib::updateFibFromBGP( )
-{
- BgpData* bgp=(BgpData*)_node.getNode()->appData.exteriorGatewayVar;
-
- assert( bgp->ip_version == NETWORK_IPV4 );
-
- invalidate( );
-
- int i=0;
- int numEntriesInAdjRibIn=BUFFER_GetCurrentSize( &( bgp->adjRibIn ) )
- / sizeof(BgpRoutingInformationBase );
-
- BgpRoutingInformationBase* adjRibInPtr=(BgpRoutingInformationBase*)
- BUFFER_GetData( &( bgp->adjRibIn ) );
-
- for( i=0; i < numEntriesInAdjRibIn; i++ )
- {
- assert( adjRibInPtr[i].nextHop.networkType == NETWORK_IPV4 );
-
- NodeAddress destNodeId = Ipv4ToNodeId( GetIPv4Address(adjRibInPtr[i].destAddress.prefix) );
-
- if( destNodeId!=-1 && adjRibInPtr[i].isValid != FALSE )
- {
- char destNodeStr[NDN_MAX_NAME_LENGTH];
- memset(destNodeStr, 0, NDN_MAX_NAME_LENGTH);
- sprintf(destNodeStr, "%d", destNodeId);
-
- update( destNodeId,
- adjRibInPtr[i].asPathList->pathSegmentLength / 2,
- GetIPv4Address(adjRibInPtr[i].nextHop) );
- }
- }
-
-#ifdef NDN_DUMP_FIB
- dump( );
-#endif
-}
-
-void NdnFib::updateFibFromIpRouting( )
-{
- invalidate( );
-
- for (int i = 0; i < _node.getNode()->partitionData->numNodes; i ++)
- {
- if( !_node.getNode()->networkData.networkVar->ndnEnabled ) continue;
-
- NodeAddress destNode = _node.getNode()->partitionData->nodeData[i]->nodeId;
- NodeAddress ipv4subnet = NodeIdToIpv4( destNode );
-
- int interfaceIndex;
- NodeAddress nextHopAddr;
- NetworkGetInterfaceAndNextHopFromForwardingTable(
- _node.getNode(), ipv4subnet, &interfaceIndex, &nextHopAddr );
-
- if( interfaceIndex != NETWORK_UNREACHABLE )
- {
- update( destNode, interfaceIndex, 1, nextHopAddr );
- }
- }
-}
-
-
-
-void NdnFib::dump( )
-{
- if( _node.getNode()->numberInterfaces==1 ) return; // do not dump FIB for `virtual' nodes
-
- printf( "Node %s: FIB\n", _node.getPrefix().c_str() );
- printf( " Dest prefix Interfaces(Costs) \n" );
- printf( "+-------------+--------------------------------------+\n" );
-
- for( FibRangeIterator fib=_fib.begin(); fib!=_fib.end(); fib++ )
- {
- dump( fib );
- }
-}
-
-void NdnFib::dump( const FibIterator &fib )
-{
- printf( " %8s ", fib->first.c_str() );
- for( FibNexthopIterator nh=VALUE(fib).forwardingList.begin(); nh!=VALUE(fib).forwardingList.end(); nh++ )
- {
- if( nh!=VALUE(fib).forwardingList.begin() ) printf( "," );
- printf( "i%d(%d)", nh->interfaceIndex, nh->cost );
- }
- printf( "\n" );
-}
-
-void NdnFib::resetProbing()
-{
- for(FibRangeIterator fib = _fib.begin(); fib != _fib.end(); fib++)
- VALUE(fib).needsProbing = true;
-}
-
-void NdnFib::updateInterfaceStatus( int interface, int status )
-{
- for( FibRangeIterator fib = _fib.begin(); fib!=_fib.end(); fib++ )
- {
- VALUE(fib).updateStatus( interface, status );
- }
-}
\ No newline at end of file
diff --git a/in-progress/ccnx-fib.h b/in-progress/ccnx-fib.h
deleted file mode 100644
index 9a1c3d6..0000000
--- a/in-progress/ccnx-fib.h
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * File: ndn_fib.h
- * Author: cawka
- *
- * Created on December 15, 2010, 1:54 PM
- */
-
-#ifndef NDN_FIB_H
-#define NDN_FIB_H
-
-#include "hash_helper.h"
-#include <clock.h>
-#include <main.h>
-
-class Ndn;
-
-const int NDN_FIB_GREEN = 1;
-const int NDN_FIB_YELLOW = 2;
-const int NDN_FIB_RED = 3;
-
-//structure for Fib outgoing interface
-struct FibNexthop
-{
- int interfaceIndex; //interface index of the node
- NodeAddress nextHop; //next-hop
- int cost; //routing protocol cost to route an interest via this interface
- int packetCount; //record the number of packets forwarded using this interface
-
- clocktype srtt; //smoothed round-trip time
- clocktype rttvar; //round-trip time variation
-
- int status; // Status of the next hop:
- // - #NDN_FIB_GREEN
- // - #NDN_FIB_YELLOW
- // - #NDN_FIB_RED
-
- bool operator==( int interface ) const { return interfaceIndex==interface; }
- FibNexthop( ) {}
- FibNexthop( int _interface, int _nextHop, int _cost )
- : interfaceIndex(_interface), nextHop(_nextHop), cost(_cost)
- , packetCount(1), srtt(0), rttvar(0), status(NDN_FIB_YELLOW) { }
-};
-
-typedef list<FibNexthop>::iterator FibNexthopIterator;
-typedef list<FibNexthop>::const_iterator FibNexthopConstIterator;
-
-//structure for FIB table entry
-struct FibEntry
-{
- list<FibNexthop> forwardingList;
- clocktype sto; //retransmission time out
-
- bool needsProbing; //set to true when probing timer goes out
-
- FibEntry( ) : sto(0), needsProbing(false) { }
-
- // Find nexthop record
- inline FibNexthopIterator findNexthop( int interfaceIndex );
- bool isValid( const FibNexthopIterator &nh )
- { return nh!=forwardingList.end(); }
-
- // Compute and update RTO value for Fib Entry (RFC 2988)
- // (for now we pick the maximum RTO of all forwardings)
- void updateSto( );
-
- // Update status of FIB next hop
- inline void updateStatus( int interface, int status );
-};
-
-typedef string_key_hash_t<FibEntry>::point_iterator FibIterator;
-typedef string_key_hash_t<FibEntry>::iterator FibRangeIterator;
-
-///////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////
-
-// Class implementing FIB functionality
-class NdnFib
-{
-public:
- NdnFib( Ndn &node );
- virtual ~NdnFib( );
-
- // Invalidate entries in FIB
- // Will leave FIB records in hash, but assign metric=NETWORK_UNREACHABLE
- void invalidate( );
-
- //Find corresponding FIB entry for the given content name
- //Longest match is performed
- FibIterator lookup( const string &name );
- bool isValid( const FibIterator &it ) { return it!=_fib.end(); }
-
- /**
- * Update FIB entry
- * If the entry exists, metric will be updated. Otherwise, new entry will be created
- *
- * Entries in FIB never deleted. They can be invalidated with metric==NETWORK_UNREACHABLE
- *
- * @param name Prefix
- * @param interfaceIndex Forwarding interface
- * @param metric Routing metric
- * @param nextHop Nexthop node address (IPv4)
- * @return true if a new entry created, false otherwise
- */
- bool update( const string &name, int interfaceIndex, int metric, NodeAddress nextHop );
- bool update( NodeAddress nodeId, int interfaceIndex, int metric, NodeAddress nextHop );
- bool update( NodeAddress nodeId, int metric, NodeAddress nextHop );
-
- // Update Fib from OSPF routing table (through a hack in OSPF algorithm)
- void updateFibFromOSPFv2( int interface );
-
- // Update Fib from BGP routing table (using info from RibIn)
- void updateFibFromBGP( );
-
- // Update Fib from IP routing table
- void updateFibFromIpRouting( );
-
- // Update the status for all FIB records for the specified interface
- void updateInterfaceStatus( int interface, int status );
-
- void dump( );
- void dump( const FibIterator &fib );
-
- void resetProbing(); //reset needsProbing field for every FibEntry
-private:
-
-private:
- Ndn &_node;
-
- string_key_hash_t<FibEntry> _fib;
-};
-
-///////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////
-
-class NdnFibNexthopSorter
-{
-public:
- bool operator()( const FibNexthop &first, const FibNexthop &second );
-};
-
-FibNexthopIterator FibEntry::findNexthop( int interfaceIndex )
-{
- return find( forwardingList.begin( ),
- forwardingList.end( ),
- interfaceIndex );
-}
-
-//inline FibNexthopIterator FibEntry::findBestNexthop( int bestNum, int excludeInterface )
-//{
-// // First adjust number of available interfaces (to make sure we have correct ranking function)
-// int num_valid_interfaces = forwardingList.size();
-// FibNexthopIterator nh;
-// for( nh=forwardingList.begin(); nh!=forwardingList.end(); nh++ )
-// {
-// if( nh->interfaceIndex==excludeInterface ) num_valid_interfaces--;
-// }
-//
-// if( num_valid_interfaces==0 ) return forwardingList.end();
-//
-// bestNum = bestNum % num_valid_interfaces;
-// int i=0;
-// for( nh=forwardingList.begin(); nh!=forwardingList.end(); nh++ ) // skip bestNum % size() FIB records
-// {
-// if( nh->interfaceIndex==excludeInterface ) continue;
-// if( i==bestNum ) break;
-//
-// i++;
-// }
-//
-// if( nh!=forwardingList.end() )
-// {
-// assert( nh->interfaceIndex!=excludeInterface );
-//// printf( "%d best => i%d\n", bestNum, nh->interfaceIndex );
-// }
-//// else
-//// {
-//// printf( "No other hops available\n" );
-//// }
-//
-//
-// return nh;
-//}
-
-void FibEntry::updateStatus( int interface, int status )
-{
- FibNexthopIterator nh = findNexthop( interface );
- if( isValid(nh) )
- {
- nh->status = status;
- }
-}
-
-#endif /* NDN_FIB_H */
diff --git a/in-progress/ccnx-pit.cpp b/in-progress/ccnx-pit.cpp
deleted file mode 100644
index 5d10b90..0000000
--- a/in-progress/ccnx-pit.cpp
+++ /dev/null
@@ -1,243 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-//
-// Copyright (c) 2010,2011 UCLA
-//
-// 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:
-//
-
-#include "ccnx-pit.h"
-#include <algorithm>
-
-CcnxPit::CcnxPit( Ccnx &node )
-: _node(node)
-{
-};
-
-CcnxPit::~CcnxPit( ) { }
-
-//Find corresponding CS entry for the given content name
-PitIterator CcnxPit::lookup( const string &prefix )
-{
- QNThreadLock lock( &_pitMutex );
-
- PitIterator entry=_pit.find( prefix );
- return entry;
-}
-
-// add new PIT entry
-bool CcnxPit::add( const string &name, const PitIncomingInterest &interest )
-{
- QNThreadLock lock( &_pitMutex );
-
- PitEntry *entry=NULL;
-
- PitIterator existent_entry = _pit.find( name );
- if( isValid(existent_entry) )
- {
- if( VALUE(existent_entry).timerExpired )
- {
- _node.fillAvailableInterfacesInPitEntry( VALUE(existent_entry) );
- }
-
- add( VALUE(existent_entry), interest );
- }
- else
- {
- PitEntry &entry = _pit[ name ];
- entry.contentName = name;
-
- _node.fillAvailableInterfacesInPitEntry( entry );
-
- add( entry, interest );
- }
-}
-
-// Remove expired records from PIT
-void CcnxPit::cleanExpired( clocktype time )
-{
- QNThreadLock lock( &_pitMutex );
-
- while( !_pitExpirationList.empty() )
- {
- PitExpirationIterator entry = _pitExpirationList.begin( );
-
- if( VALUE(entry)->expireTime <= time )
- {
- deleteIncomingInterest( *(KEY(entry)), VALUE(entry)->interfaceIndex );
-
- // delete entry if all incoming interests expired
- if( KEY(entry)->incomingInterests.size()==0 )
- {
- _pit.erase( KEY(entry)->contentName );
- }
- }
- else
- break;
- }
-}
-
-//delete PIT entry
-void CcnxPit::erase( const string &name )
-{
- // should not call `lookup' method !!!
-
- QNThreadLock lock( &_pitMutex );
-
- PitIterator pe = _pit.find( name );
-
- if( !isValid(pe) ) return;
-
- if( VALUE(pe).timerMsg ) MESSAGE_CancelSelfMsg( _node.getNode(), VALUE(pe).timerMsg );
-
- PitIncomingIterator it = VALUE(pe).incomingInterests.begin();
- while( it!=VALUE(pe).incomingInterests.end() )
- {
- deleteIncomingInterest( VALUE(pe), it );
-
- it = VALUE(pe).incomingInterests.begin();
- }
-
- resetPendingState( VALUE(pe) );
-
- _pit.erase( name );
-}
-
-//delete incoming interest from PIT entry
-//return 0 if interest does not exist, 1 otherwise
-bool CcnxPit::deleteIncomingInterest( PitEntry &pe, int interfaceIndex )
-{
- // should not lock thread !!! Otherwise there will be a deadlock
- if( pe.incomingInterests.size()==0 ) return false; //nothing to delete. Can happen when duplicate data arrives to the node
-
- PitIncomingIterator it = findIncoming( pe, interfaceIndex );
-
- if( !isValid(pe, it) ) return false;
-
- deleteIncomingInterest( pe, it );
-
- return true;
-}
-
-void CcnxPit::deleteAllIncomingInterests( PitEntry &pe )
-{
- PitIncomingIterator it = pe.incomingInterests.begin();
- while( it!=pe.incomingInterests.end() )
- {
- deleteIncomingInterest( pe, it );
-
- it = pe.incomingInterests.begin();
- }
-}
-
-void CcnxPit::deleteIncomingInterest( PitEntry &pe, PitIncomingIterator it )
-{
- assert( KEY(it->expirationPosition)==&pe );
- assert( VALUE(it->expirationPosition)->interfaceIndex==it->interfaceIndex );
-
- _pitExpirationList.erase( it->expirationPosition );
- pe.incomingInterests.erase( it );
-}
-
-//add new incoming interest to PIT entry
-//returns false if interface already exists, true otherwise
-bool CcnxPit::add( PitEntry &pe, const PitIncomingInterest &interest )
-{
- pe.availableInterfaces.remove( interest.interfaceIndex );
-
- PitIncomingIterator it=findIncoming( pe, interest.interfaceIndex );
-
- if( isValid(pe, it) )
- {
- //update expiration time
- it->expireTime = interest.expireTime;
- it->nonce = interest.nonce;
-
- //move Interest to the end of the node's Interest list
- _pitExpirationList.erase( it->expirationPosition );
- _pitExpirationList.push_back( PitExpirationEntry(&pe,&(*it)) );
-
- it->expirationPosition = --_pitExpirationList.end();
- return false;
- }
-
- pe.incomingInterests.push_back( interest );
- PitIncomingInterest *incoming = &pe.incomingInterests.back();
-
- //Add to the end of the node's Interest list
- _pitExpirationList.push_back( PitExpirationEntry(&pe,incoming) );
- incoming->expirationPosition = -- _pitExpirationList.end();
-
- return true;
-}
-
-//add new outgoing interest to PIT entry
-//returns false interface limit reached or interest exists and is still marked as outstanding (nonce will not be changed)
-// true otherwise
-int CcnxPit::add( PitEntry &pe, const PitOutgoingInterest &interest )
-{
- if( _node.isRateLimit && _bucketsPerInterface[interest.interfaceIndex]+1.0 >= maxBucketsPerInterface[interest.interfaceIndex] )
- {
-// printf( "DEBUG: bucket overflow. Should not forward anything to interface %d\n", interest.interfaceIndex );
- return false;
- }
-
- _bucketsPerInterface[interest.interfaceIndex] = _bucketsPerInterface[interest.interfaceIndex] + 1.0;
- pe.availableInterfaces.remove( interest.interfaceIndex );
-
- PitOutgoingIterator it = findOutgoing(pe, interest.interfaceIndex);
- if( isValid(pe, it) )
- {
- if( it->outstanding ) return false;
-
- it->retxNum ++;
- it->nonce = interest.nonce;
- it->outstanding = true;
- it->waitingInVain = false;
- }
- else
- {
- //add to the head of the list
- pe.outgoingInterests.push_front( interest );
- }
-
- return true;
-}
-
-void CcnxPit::resetPendingState( PitEntry &pe )
-{
- for( PitOutgoingIterator it = pe.outgoingInterests.begin();
- it != pe.outgoingInterests.end();
- it++ )
- {
- it->outstanding = false;
- }
-}
-
-void CcnxPit::leakBuckets( )
-{
- for( PitBucketIterator it=_bucketsPerInterface.begin();
- it != _bucketsPerInterface.end();
- it++ )
- {
- it->second = max( 0.0, it->second - leakSize[it->first] );
- }
-}
-
-void CcnxPit::leakBucket( int interface, int amount )
-{
- _bucketsPerInterface[interface] =
- max( 0.0, _bucketsPerInterface[interface] - amount );
-}
diff --git a/in-progress/ccnx-pit.h b/in-progress/ccnx-pit.h
deleted file mode 100644
index 83fad09..0000000
--- a/in-progress/ccnx-pit.h
+++ /dev/null
@@ -1,276 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-//
-// Copyright (c) 2010,2011 UCLA
-//
-// 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:
-//
-
-#ifndef CCNX_PIT_H
-#define CCNX_PIT_H
-
-#include "ns3/nstime.h"
-#include "hash-helper.h"
-#include <list>
-
-namespace ns3 {
-
-class Ccnx;
-class PitEntry;
-class PitIncomingInterest;
-typedef pair<PitEntry*,PitIncomingInterest*> PitExpirationEntry;
-typedef list<PitExpirationEntry>::iterator PitExpirationIterator;
-
-struct PitIncomingInterest
-{
- int interfaceIndex; // interface index of the incoming Interest
- Time expireTime; // life time of the incoming Interest
- int nonce; // nonce of the last received incoming Interest on this interface
-
- PitExpirationIterator expirationPosition;
-
-public:
-PitIncomingInterest( int _interface, clocktype _expire, int _nonce )
-: interfaceIndex(_interface)
-, expireTime(_expire)
- , nonce(_nonce)
- { };
-
- bool operator==( const PitIncomingInterest &dst ) { return interfaceIndex==dst.interfaceIndex; }
- bool operator==( int interface ) { return interfaceIndex==interface; }
-};
-
-struct PitOutgoingInterest
-{
- int interfaceIndex;
- clocktype sendTime; //time when the first outgoing interest is sent
- int retxNum; //number of retransmission
- int nonce; //nonce of the outgoing Interest
- bool outstanding; //flag to indicate that this interest is currently pending
- bool waitingInVain; //when flag is set, we do not expect data for this interest, only a small hope that it will happen
-
-public:
-PitOutgoingInterest( int interface, clocktype time, int nonce )
-: interfaceIndex(interface)
-, sendTime( time )
- , retxNum( 0 )
- , nonce( nonce )
- , outstanding( true )
- , waitingInVain( false )
- { };
-
- bool operator==( const PitIncomingInterest &dst ) { return interfaceIndex==dst.interfaceIndex; }
- bool operator==( int interface ) { return interfaceIndex==interface; }
-};
-
-
-//structure for PIT entry
-struct PitEntry
-{
- string contentName;
- list<PitIncomingInterest> incomingInterests;
- list<PitOutgoingInterest> outgoingInterests;
-
- bool timerExpired;
- int counterExpirations; //whether timer is expired (+ number of times timer expired)
-
- /**
- * This variable provides a list of interfaces that will be tried to propagate interest
- *
- * It should be initialized with all available interfaces upon reception of first or
- * any retransmitted (i.e., after STO expired), but not duplicate interests
- *
- * Reaction to duplicate interests depends on strategy.
- *
- * In case of flooding, this variable should always be empty (it is filled initially with
- * all avaialble interfaces and then immediately emptied by interest flooding)
- *
- * In case of routing strategies, this list will guide (and limit) the local recovery process
- */
- list<int> availableInterfaces;
-
- Message *timerMsg; //the timer message, used to cancel message if data is received
-
- // Changing PIT removal policy. From now on it will be deleted only when all outgoing
- // interests are satisfied
- //
- // bool dontDeleteOnFirstData; //don't delete when first data packet comes
- // //(PIT will be deleted only upon timeout or reception data
- // //packets or prunes for all outgoing interests)
-
-public:
-PitEntry()
-: timerExpired( false )
-, counterExpirations( 0 )
- , timerMsg( NULL )
- { }
-
- inline void fillAvailableInterfacesFromFIB( const FibEntry &fe );
-
- // Find best candidate, skipping `skip' first candidates (modulo availableInterfaces.size())
- // !!! assert( availableInterfaces.size()>0 ) !!!
- inline int findBestCandidate( int skip = 0 );
-
- // Get number of outgoing interests that we're expecting data from
- inline size_t numberOfPromisingInterests( ) const;
-};
-
-typedef string_key_hash_t<PitEntry>::point_iterator PitIterator;
-typedef string_key_hash_t<PitEntry>::iterator PitRangeIterator;
-
-typedef list<PitIncomingInterest>::iterator PitIncomingIterator;
-typedef list<PitOutgoingInterest>::iterator PitOutgoingIterator;
-typedef list<PitOutgoingInterest>::const_iterator PitOutgoingConstIterator;
-
-typedef map<int,int> PitCounter;
-typedef map<int,int>::iterator PitCounterIterator;
-
-typedef map<int,double> PitBucket;
-typedef map<int,double>::iterator PitBucketIterator;
-
-
-////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////
-
-// class implementing Pending Interests Table
-class CcnxPit
-{
- public:
- /**
- * PIT constructor
- */
- CcnxPit( Ccnx &node );
- virtual ~CcnxPit( );
-
- //Find corresponding PIT entry for the given content name
- PitIterator lookup( const string &prefix );
- bool isValid( const PitIterator &it ) { return it!=_pit.end(); }
-
- inline PitIncomingIterator findIncoming( PitEntry &pe, int interfaceIndex );
- inline bool isValid( PitEntry &pe, PitIncomingIterator it );
- inline PitOutgoingIterator findOutgoing( PitEntry &pe, int interfaceIndex );
- inline bool isValid( PitEntry &pe, PitOutgoingIterator it );
-
- // Add a new PIT entry and a correspondent new incoming interest
- bool add( const string &contentName, const PitIncomingInterest &interest );
-
- // Add a new outgoing interest
- int add( PitEntry &pe, const PitOutgoingInterest &interest );
-
- // remove a PIT entry
- void erase( const string &contentName );
-
- // inline bool InterestAlreadyForwarded( PitEntry &pe, int interfaceIndex );
-
- // Remove expired records from PIT
- void cleanExpired( clocktype time );
-
- // Dump content store entries
- void dump( );
-
- // Reset pending state in outgoing interests
- void resetPendingState( PitEntry &pe );
-
- // // Check if there are any interfaces that we haven't sent data to yet
- // bool areFreeInterfaces( PitEntry &pe, int interface );
-
- // Periodically generate pre-calculated number of tokens (leak buckets)
- void leakBuckets( );
-
- // Selectively leak a bucket
- void leakBucket( int interface, int amount );
-
- // Delete incoming interest for the interface
- bool deleteIncomingInterest( PitEntry &pe, int interfaceIndex );
-
- // Remove all incoming interests
- void deleteAllIncomingInterests( PitEntry &pe );
-
- public:
- PitBucket maxBucketsPerInterface; // maximum number of buckets. Automatically computed based on link capacity
- // averaging over 1 second (bandwidth * 1second)
- PitBucket leakSize; // size of a periodic bucket leak
-
- private:
- bool add( PitEntry &pe, const PitIncomingInterest &interest );
- void deleteIncomingInterest( PitEntry &pe, PitIncomingIterator it );
-
- private:
- Ccnx &_node;
-
- string_key_hash_t<PitEntry> _pit;
-
- list<PitExpirationEntry> _pitExpirationList; //list of incoming Interests sorted by expiration time
-
- PitBucket _bucketsPerInterface; // pending interface counter per interface
-
- QNThreadMutex _pitMutex; // just to make sure
-};
-
-////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////
-
-PitIncomingIterator CcnxPit::findIncoming( PitEntry &pe, int interfaceIndex )
-{
- return find( pe.incomingInterests.begin( ),
- pe.incomingInterests.end( ),
- interfaceIndex );
-}
-
-PitOutgoingIterator CcnxPit::findOutgoing( PitEntry &pe, int interfaceIndex )
-{
- return find( pe.outgoingInterests.begin( ),
- pe.outgoingInterests.end( ),
- interfaceIndex );
-}
-
-bool CcnxPit::isValid( PitEntry &pe, PitIncomingIterator it )
-{
- return it!=pe.incomingInterests.end( );
-}
-
-bool CcnxPit::isValid( PitEntry &pe, PitOutgoingIterator it )
-{
- return it!=pe.outgoingInterests.end( );
-}
-
-int PitEntry::findBestCandidate( int skip/* = 0*/ )
-{
- assert( availableInterfaces.size()>0 );
-
- skip = skip % availableInterfaces.size();
- list<int>::iterator candidate = availableInterfaces.begin( );
- while( skip>0 /* && candidate!=availableInterfaces.end() */ ) { skip--; candidate++; }
-
- return *candidate;
-}
-
-size_t PitEntry::numberOfPromisingInterests( ) const
-{
- size_t count = 0;
-
- for( PitOutgoingConstIterator i = outgoingInterests.begin();
- i!=outgoingInterests.end();
- i++ )
- {
- if( !i->waitingInVain ) count++;
- }
-
- return count;
-}
-
-} // namespace ns3
-
-#endif /* CCNX_PIT_H */
diff --git a/in-progress/ccnx-rit.cpp b/in-progress/ccnx-rit.cpp
deleted file mode 100644
index b84f9d0..0000000
--- a/in-progress/ccnx-rit.cpp
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * File: ndn_rit.cpp
- * Author: cawka
- *
- * Created on December 15, 2010, 2:02 PM
- */
-
-#include "ndn_rit.h"
-
-NdnRit::NdnRit( ) { }
-
-NdnRit::~NdnRit( ) { }
-
-
-//find corresponding RIT entry for the given nonce
-RitIterator NdnRit::lookup( int nonce )
-{
- QNThreadLock lock( &_ritMutex );
-
- RitIterator entry=_rit.find( nonce );
- return entry;
-}
-
-
-// add new RIT entry
-// returns false if entry already exists, otherwise returns true
-bool NdnRit::add( int nonce, clocktype expire )
-{
- QNThreadLock lock( &_ritMutex );
-
- RitIterator entry=_rit.find( nonce );
- if( isValid(entry) ) return false;
-
- RitEntry re;
- re.nonce = nonce;
- re.expireTime = expire;
-
- _rit[ nonce ] = re;
-
- _ritExpirationList.push_back( &(_rit[nonce]) );
-}
-
-
-void NdnRit::cleanExpired( clocktype time )
-{
- QNThreadLock lock( &_ritMutex );
-
- while( !_ritExpirationList.empty() )
- {
- RitEntry *head = _ritExpirationList.front( );
-
- if( head->expireTime <= time )
- {
- //delete the head RIT entry
- _rit.erase( head->nonce );
- _ritExpirationList.pop_front( );
- }
- else
- break;
- }
- //printf("Node %d: RIT entries\n", node->nodeId);
- //PrintRitEntries(ndn->riList);
-}
-
diff --git a/in-progress/ccnx-rit.h b/in-progress/ccnx-rit.h
deleted file mode 100644
index 4a03bda..0000000
--- a/in-progress/ccnx-rit.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * File: ndn_rit.h
- * Author: cawka
- *
- * Created on December 15, 2010, 2:02 PM
- */
-
-#ifndef NDN_RIT_H
-#define NDN_RIT_H
-
-#include "hash_helper.h"
-#include <qualnet_mutex.h>
-#include <clock.h>
-#include <list>
-using namespace std;
-
-//recent interest
-struct RitEntry
-{
- int nonce;
- clocktype expireTime; //RIT entries will stay in the table for a while before being cleaned out
-};
-
-typedef int_key_hash_t<RitEntry>::point_iterator RitIterator;
-typedef int_key_hash_t<RitEntry>::iterator RitRangeIterator;
-
-class NdnRit
-{
-public:
- NdnRit( );
- virtual ~NdnRit( );
-
- //Find corresponding RIT entry for the given content name
- RitIterator lookup( int nonce );
- bool isValid( const RitIterator &it ) { return it!=_rit.end(); }
-
- //add new RIT entry
- bool add( int nonce, clocktype expireTime );
-
- // Delete expired records
- void cleanExpired( clocktype time );
-
-private:
- int_key_hash_t<RitEntry> _rit;
-
- list<RitEntry*> _ritExpirationList;
-
- QNThreadMutex _ritMutex;
-};
-
-#endif /* NdnRit_H */
-
diff --git a/model/ccnx-content-object-header.cc b/model/ccnx-content-object-header.cc
index e567207..d1ad0cf 100644
--- a/model/ccnx-content-object-header.cc
+++ b/model/ccnx-content-object-header.cc
@@ -37,6 +37,7 @@
CcnxContentObjectHeader::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::CcnxContentObjectHeader")
+ .SetGroupName ("Ccnx")
.SetParent<Header> ()
.AddConstructor<CcnxContentObjectHeader> ()
;
diff --git a/model/ccnx-content-object-header.h b/model/ccnx-content-object-header.h
index c26052b..97a8d3d 100644
--- a/model/ccnx-content-object-header.h
+++ b/model/ccnx-content-object-header.h
@@ -24,6 +24,7 @@
#include "ns3/integer.h"
#include "ns3/header.h"
+#include "ns3/trailer.h"
#include <string>
#include <vector>
@@ -101,7 +102,7 @@
* ContentObjectTail should always be 2 bytes, representing two closing tags:
* "</Content><ContentObject>"
*/
-class CcnxContentObjectTail : public Header
+class CcnxContentObjectTail : public Trailer
{
public:
CcnxContentObjectTail ();
diff --git a/model/ccnx-content-store.cc b/model/ccnx-content-store.cc
index 31a9fb3..b526308 100644
--- a/model/ccnx-content-store.cc
+++ b/model/ccnx-content-store.cc
@@ -16,88 +16,137 @@
* 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 "ccnx-content-store.h"
#include "ns3/log.h"
-
+#include "ns3/packet.h"
+#include "ns3/ccnx-interest-header.h"
+#include "ns3/ccnx-content-object-header.h"
+#include "ns3/uinteger.h"
NS_LOG_COMPONENT_DEFINE ("CcnxContentStore");
namespace ns3
{
-
-CcnxContentStore::CcnxContentStore( int maxSize )
- : m_maxSize(maxSize) { }
+
+NS_OBJECT_ENSURE_REGISTERED (CcnxContentStore);
+
+using namespace __ccnx_private;
+
+TypeId
+CcnxContentStore::GetTypeId (void)
+{
+ static TypeId tid = TypeId ("ns3::CcnxContentStore")
+ .SetGroupName ("Ccnx")
+ .SetParent<Object> ()
+ .AddConstructor<CcnxContentStore> ()
+ .AddAttribute ("Size",
+ "Maximum number of packets that content storage can hold",
+ UintegerValue (100),
+ MakeUintegerAccessor (&CcnxContentStore::SetMaxSize,
+ &CcnxContentStore::GetMaxSize),
+ MakeUintegerChecker<uint32_t> ())
+ ;
+
+ return tid;
+}
+
+CcnxContentObjectTail CcnxContentStoreEntry::m_tail;
+
+CcnxContentStoreEntry::CcnxContentStoreEntry (Ptr<CcnxContentObjectHeader> header, Ptr<const Packet> packet)
+ : m_header (header)
+{
+ m_packet = packet->Copy ();
+ m_packet->RemoveHeader (*header);
+ m_packet->RemoveTrailer (m_tail);
+}
+
+Ptr<Packet>
+CcnxContentStoreEntry::GetFullyFormedCcnxPacket () const
+{
+ Ptr<Packet> packet = m_packet->Copy ();
+ packet->AddHeader (*m_header);
+ packet->AddTrailer (m_tail);
+ return packet;
+}
+
+// /// Disabled copy constructor
+// CcnxContentStoreEntry::CcnxContentStoreEntry (const CcnxContentStoreEntry &o)
+// {
+// }
+
+// /// Disables copy operator
+// CcnxContentStoreEntry& CcnxContentStoreEntry::operator= (const CcnxContentStoreEntry &o)
+// {
+// return *this;
+// }
+
+
+
+CcnxContentStore::CcnxContentStore( )
+ : m_maxSize(100) { } // this value shouldn't matter, NS-3 should call SetSize with default value specified in AddAttribute earlier
CcnxContentStore::~CcnxContentStore( )
- { }
+{ }
-//Find corresponding CS entry for the given content name
-CsEntry*
-CcnxContentStore::Lookup(const string prefix )
+/// Disabled copy constructor
+CcnxContentStore::CcnxContentStore (const CcnxContentStore &o)
{
- CriticalSection section(m_csMutex);
-
- CsEntry *result = &(m_contentStore.at(prefix));
-
- if(result != NULL)
- Promote (*result);
-
- return result;
+}
+
+/// Disables copy operator
+CcnxContentStore& CcnxContentStore::operator= (const CcnxContentStore &o)
+{
+ return *this;
+}
+
+
+Ptr<Packet>
+CcnxContentStore::Lookup (Ptr<const CcnxInterestHeader> interest)
+{
+ CcnxContentStoreContainer::type::iterator it = m_contentStore.get<hash> ().find (interest->GetName ());
+ if (it != m_contentStore.end ())
+ {
+ // promote entry to the top
+ m_contentStore.get<mru> ().relocate (m_contentStore.get<mru> ().begin (),
+ m_contentStore.project<mru> (it));
+
+ // return fully formed CCNx packet
+ return it->GetFullyFormedCcnxPacket ();
+ }
+ return 0;
}
-//move the given CS entry to the head of the list
void
-CcnxContentStore::Promote(CsEntry &ce )
+CcnxContentStore::Add (Ptr<CcnxContentObjectHeader> header, Ptr<const Packet> packet)
{
- // should not lock mutex. Otherwise deadlocks will be welcome
- if( m_LRU.front() == &ce ) return;
-
- //assert( *(ce.lruPosition)==&ce ); // should point to the same object
-
- // swaping positions in _lru
- m_LRU.erase( ce.lruPosition );
- m_LRU.push_front( &ce );
- ce.lruPosition = m_LRU.begin( );
-
- //assert( *(ce.lruPosition)==&ce ); // should point to the same object
-}
-
-//Add entry to content store, if content store is full, use LRU replacement
-void
-CcnxContentStore::Add( const string contentName, int contentSize )
-{
- CriticalSection section(m_csMutex);
-
- m_contentStore.erase(m_contentStore.find(contentName));
-
- if((int)m_contentStore.size() == m_maxSize )
- {
- CsEntry *entry = m_LRU.back();
- m_contentStore.erase(m_contentStore.find(entry->contentName));
- m_LRU.pop_back( );
+ CcnxContentStoreContainer::type::iterator it = m_contentStore.get<hash> ().find (header->GetName ());
+ if (it == m_contentStore.end ())
+ { // add entry to the top
+ m_contentStore.get<mru> ().push_front (CcnxContentStoreEntry (header, packet));
+ if (m_contentStore.size () > m_maxSize)
+ m_contentStore.get<mru> ().pop_back ();
}
-
- CsEntry ce;
- ce.contentName = contentName;
- ce.contentSize = contentSize;
-
- m_contentStore[contentName] = ce;
-
- CsEntry *ce_in_hash = &(m_contentStore.at(contentName));
- m_LRU.push_front( ce_in_hash );
- ce_in_hash->lruPosition = m_LRU.begin( );
-}
-
-void
-CcnxContentStore::Dump()
-{
- CriticalSection section(m_csMutex);
-
- BOOST_FOREACH(string_key_hash_t<CsEntry>::value_type i, m_contentStore)
+ else
{
- NS_LOG_INFO ("Key = " << i.first << " Value = " << i.second.contentName);
+ // promote entry to the top
+ m_contentStore.get<mru> ().relocate (m_contentStore.get<mru> ().begin (),
+ m_contentStore.project<mru> (it));
}
}
-}
\ No newline at end of file
+
+void
+CcnxContentStore::Print() const
+{
+ for( DUMP_INDEX::type::iterator it=m_contentStore.get<DUMP_INDEX_TAG> ().begin ();
+ it != m_contentStore.get<DUMP_INDEX_TAG> ().end ();
+ it++
+ )
+ {
+ NS_LOG_INFO (it->GetName ());
+ }
+}
+
+} // namespace ns3
diff --git a/model/ccnx-content-store.h b/model/ccnx-content-store.h
index 58e060e..29b838a 100644
--- a/model/ccnx-content-store.h
+++ b/model/ccnx-content-store.h
@@ -18,60 +18,327 @@
* Author: Ilya Moiseenko <iliamo@cs.ucla.edu>
*/
-#ifndef ccnx_content_store_h
-#define ccnx_content_store_h
+#ifndef CCNX_CONTENT_STORE_H
+#define CCNX_CONTENT_STORE_H
-#include <ns3/system-mutex.h>
+#include "ns3/object.h"
+#include "ns3/ptr.h"
+
#include <list>
#include <string>
-#include "hash-helper.h"
+#include <iostream>
-using namespace std;
+#include <boost/multi_index_container.hpp>
+#include <boost/multi_index/tag.hpp>
+#include <boost/multi_index/ordered_index.hpp>
+#include <boost/multi_index/sequenced_index.hpp>
+#include <boost/multi_index/hashed_index.hpp>
+#include <boost/multi_index/mem_fun.hpp>
+
+#include "hash-helper.h"
+#include "ccnx-content-object-header.h"
+#include "ccnx-interest-header.h"
+#include "name-components.h"
namespace ns3
{
-
-class CsEntry;
-typedef list<CsEntry*>::iterator CsLruIterator;
-
-//structure for CS entry
-struct CsEntry
-{
- string contentName;
- int contentSize;
-
- CsLruIterator lruPosition;
-};
-
-typedef string_key_hash_t<CsEntry>::iterator CsIterator;
-typedef string_key_hash_t<CsEntry>::iterator CsRangeIterator;
-
-class CcnxContentStore
+class Packet;
+
+/**
+ * \ingroup ccnx
+ * \brief NDN content store entry
+ *
+ * Content store entry stores separately pseudo header and content of
+ * ContentObject packet. It is responsibility of the caller to
+ * construct a fully formed CcnxPacket by calling Copy(), AddHeader(),
+ * AddTail() on the packet received by GetPacket() method.
+ *
+ * GetFullyFormedCcnxPacket method provided as a convenience
+ */
+class CcnxContentStoreEntry
{
public:
- CcnxContentStore( int max_size=NDN_CONTENT_STORE_SIZE );
- virtual ~CcnxContentStore( );
+ /**
+ * \brief Construct content store entry
+ *
+ * \param header Parsed CcnxContentObject header
+ * \param packet Original CCNx packet
+ *
+ * The constructor will make a copy of the supplied packet and calls
+ * RemoveHeader and RemoveTail on the copy.
+ */
+ CcnxContentStoreEntry (Ptr<CcnxContentObjectHeader> header, Ptr<const Packet> packet);
+
+ /**
+ * \brief Get prefix of the stored entry
+ * \returns prefix of the stored entry
+ */
+ inline const Name::Components&
+ GetName () const;
+
+ /**
+ * \brief Get CcnxContentObjectHeader of the stored entry
+ * \returns CcnxContentObjectHeader of the stored entry
+ */
+ inline Ptr<const CcnxContentObjectHeader>
+ GetHeader () const;
+
+ /**
+ * \brief Get content of the stored entry
+ * \returns content of the stored entry
+ */
+ inline Ptr<const Packet>
+ GetPacket () const;
+
+ /**
+ * \brief Convenience method to create a fully formed CCNx packet from stored header and content
+ * \returns A read-write copy of the packet with CcnxContentObjectHeader and CcxnContentObjectTail
+ */
+ Ptr<Packet>
+ GetFullyFormedCcnxPacket () const;
+
+// Copy constructor is required by the container. Though, we're
+// storing only two pointers, so shouldn't be a problem
+// private:
+// CcnxContentStoreEntry (const CcnxContentStoreEntry &); ///< disabled copy constructor
+// CcnxContentStoreEntry& operator= (const CcnxContentStoreEntry&); ///< disabled copy operator
+
+private:
+ Ptr<CcnxContentObjectHeader> m_header; ///< \brief non-modifiable CcnxContentObjectHeader
+ Ptr<Packet> m_packet; ///< \brief non-modifiable content of the ContentObject packet
+
+ static CcnxContentObjectTail m_tail; ///< \internal for optimization purposes
+};
+
+/// \brief Private namespace for CCNx implementation
+namespace __ccnx_private
+{
+class hash {}; ///< tag for Boost.Multiindex container (hashed prefix)
+class mru {}; ///< tag for Boost.Multiindex container (most recent used index)
+#ifdef _DEBUG
+class ordered {}; ///< tag for Boost.MultiIndex container (ordered by prefix)
+#endif
+};
+
+/**
+ * \ingroup ccnx
+ * \brief Typedef for content store container implemented as a Boost.MultiIndex container
+ *
+ * - First index (tag<prefix>) is a unique hash index based on NDN prefix of the stored content.
+ * - Second index (tag<mru>) is a sequential index used to maintain up to m_maxSize most recent used (MRU) entries in the content store
+ * - Third index (tag<ordered>) is just a helper to provide stored prefixes in ordered way. Should be disabled in production build
+ *
+ * \see http://www.boost.org/doc/libs/1_46_1/libs/multi_index/doc/ for more information on Boost.MultiIndex library
+ */
+struct CcnxContentStoreContainer
+{
+ typedef
+ boost::multi_index::multi_index_container<
+ CcnxContentStoreEntry,
+ boost::multi_index::indexed_by<
+ boost::multi_index::hashed_unique<
+ boost::multi_index::tag<__ccnx_private::hash>,
+ boost::multi_index::const_mem_fun<CcnxContentStoreEntry,
+ const Name::Components&,
+ &CcnxContentStoreEntry::GetName>,
+ CcnxPrefixHash>,
+ boost::multi_index::sequenced<boost::multi_index::tag<__ccnx_private::mru> >
+#ifdef _DEBUG
+ ,
+ boost::multi_index::ordered_unique<
+ boost::multi_index::tag<__ccnx_private::ordered>,
+ boost::multi_index::const_mem_fun<CcnxContentStoreEntry,
+ const Name::Components&,
+ &CcnxContentStoreEntry::GetName>
+ >
+#endif
+ >
+ > type;
+};
+
+/**
+ * \ingroup ccnx
+ * \brief Typedef for hash index of content store container
+ */
+struct CcnxContentStoreByPrefix
+{
+ typedef
+ CcnxContentStoreContainer::type::index<__ccnx_private::hash>::type
+ type;
+};
+
+/**
+ * \ingroup ccnx
+ * \brief Typedef for MRU index of content store container
+ */
+struct CcnxContentStoreByMru
+{
+ typedef
+ CcnxContentStoreContainer::type::index<__ccnx_private::mru>::type
+ type;
+};
+
+#ifdef _DEBUG
+#define DUMP_INDEX_TAG ordered
+#define DUMP_INDEX CcnxContentStoreOrderedPrefix
+/**
+ * \ingroup ccnx
+ * \brief Typedef for ordered index of content store container
+ */
+struct CcnxContentStoreOrderedPrefix
+{
+ typedef
+ CcnxContentStoreContainer::type::index<__ccnx_private::ordered>::type
+ type;
+};
+#else
+#define DUMP_INDEX_TAG mru
+#define DUMP_INDEX CcnxContentStoreByMru
+#endif
+
+/**
+ * \ingroup ccnx
+ * \brief NDN content store entry
+ */
+class CcnxContentStore : public Object
+{
+public:
+ /**
+ * \brief Interface ID
+ *
+ * \return interface ID
+ */
+ static TypeId GetTypeId ();
+
+ // typedef string_key_hash_t<CsEntry>::iterator CsIterator;
+ // typedef string_key_hash_t<CsEntry>::iterator CsRangeIterator;
+
+ /**
+ * Default constructor
+ */
+ CcnxContentStore( );
+ virtual ~CcnxContentStore( );
- // Find corresponding CS entry for the given content name
- CsEntry* Lookup( const string prefix );
- //bool isValid( const CsIterator &it ) { return it!=_cs.end(); }
+ /**
+ * \brief Find corresponding CS entry for the given interest
+ *
+ * \param interest Interest for which matching content store entry
+ * will be searched
+ *
+ * If an entry is found, it is promoted to the top of most recent
+ * used entries index, \see m_contentStore
+ */
+ Ptr<Packet>
+ Lookup (Ptr<const CcnxInterestHeader> interest);
- // Add new content to the content store. Old content will be replaced
- void Add( const string contentName, int contentSize );
-
- // Dump content store entries
- void Dump( );
+ /**
+ * \brief Add a new content to the content store.
+ *
+ * \param header Fully parsed CcnxContentObjectHeader
+ * \param packet Fully formed CCNx packet to add to content store
+ * (will be copied and stripped down of headers)
+ *
+ * If entry with the same prefix exists, the old entry will be
+ * promoted to the top of the MRU hash
+ */
+ void
+ Add (Ptr<CcnxContentObjectHeader> header, Ptr<const Packet> packet);
+
+ /**
+ * \brief Set maximum size of content store
+ *
+ * \param size size in packets
+ */
+ inline void
+ SetMaxSize (uint32_t maxSize);
+
+ /**
+ * \brief Get maximum size of content store
+ *
+ * \returns size in packets
+ */
+ inline uint32_t
+ GetMaxSize () const;
+
+ /**
+ * \brief Print out content store entries
+ *
+ * Debug build provides dumping of content store entries in
+ * lexicographical order of corresponding prefixes
+ *
+ * Release build dumps everything in MRU order
+ */
+ void Print () const;
protected:
- //move the given CS entry to the head of the list
- void Promote( CsEntry &entry );
-
+ // /**
+ // * \brief Move the given CS entry to the head of the list
+ // *
+ // * \param entry Content Store entry
+ // */
+ // void Promote( CsEntry &entry );
+
+ /**
+ * \todo Alex: DoDispose and NotifyNewAggregate are seem to be very
+ * important, but I'm not yet sure what exactly they are supposed to
+ * do
+ */
+ // virtual void DoDispose ();
+ // virtual void NotifyNewAggregate ();
+
private:
- int m_maxSize; // maximum number of entries in cache
-
- string_key_hash_t<CsEntry> m_contentStore; // actual content store
- list<CsEntry*> m_LRU; // LRU index of the content store
- SystemMutex m_csMutex; // just to make sure we are not
+ CcnxContentStore (const CcnxContentStore &o); ///< Disabled copy constructor
+ CcnxContentStore& operator= (const CcnxContentStore &o); ///< Disabled copy operator
+
+private:
+ size_t m_maxSize; ///< \brief maximum number of entries in cache \internal
+ // string_key_hash_t<CsEntry> m_contentStore; ///< \brief actual content store \internal
+
+ /**
+ * \brief Content store implemented as a Boost.MultiIndex container
+ * \internal
+ */
+ CcnxContentStoreContainer::type m_contentStore;
};
+
+inline std::ostream&
+operator<< (std::ostream &os, const CcnxContentStore &cs)
+{
+ cs.Print ();
+ return os;
}
-#endif
+
+const Name::Components&
+CcnxContentStoreEntry::GetName () const
+{
+ return m_header->GetName ();
+}
+
+Ptr<const CcnxContentObjectHeader>
+CcnxContentStoreEntry::GetHeader () const
+{
+ return m_header;
+}
+
+Ptr<const Packet>
+CcnxContentStoreEntry::GetPacket () const
+{
+ return m_packet;
+}
+
+
+inline void
+CcnxContentStore::SetMaxSize (uint32_t maxSize)
+{
+ m_maxSize = maxSize;
+}
+
+inline uint32_t
+CcnxContentStore::GetMaxSize () const
+{
+ return m_maxSize;
+}
+
+} //namespace ns3
+
+#endif // CCNX_CONTENT_STORE_H
diff --git a/model/ccnx-face.cc b/model/ccnx-face.cc
index e19dc57..3250355 100644
--- a/model/ccnx-face.cc
+++ b/model/ccnx-face.cc
@@ -34,6 +34,7 @@
CcnxFace::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::CcnxFace")
+ .SetGroupName ("Ccnx")
.SetParent<Object> ()
;
return tid;
diff --git a/model/ccnx-face.h b/model/ccnx-face.h
index 787bfa0..4370ab9 100644
--- a/model/ccnx-face.h
+++ b/model/ccnx-face.h
@@ -31,9 +31,10 @@
class Packet;
class Node;
+
/**
* \ingroup ccnx
- * \defgroup ccnx-face
+ * \defgroup ccnx-face Faces
*/
/**
* \ingroup ccnx-face
@@ -54,7 +55,7 @@
* \param face Face from which packet has been received
* \param packet Received packet
*/
- typedef Callback<void,const Ptr<CcnxFace>&,const Ptr<Packet>& > ProtocolHandler;
+ typedef Callback<void,const Ptr<CcnxFace>&,const Ptr<const Packet>& > ProtocolHandler;
/**
* \brief Interface ID
diff --git a/model/ccnx-forwarding-strategy.cc b/model/ccnx-forwarding-strategy.cc
index 6d4b045..7159109 100644
--- a/model/ccnx-forwarding-strategy.cc
+++ b/model/ccnx-forwarding-strategy.cc
@@ -28,6 +28,7 @@
TypeId CcnxForwardingStrategy::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::CcnxForwardingStrategy")
+ .SetGroupName ("Ccnx")
.SetParent<Object> ()
;
return tid;
diff --git a/model/ccnx-interest-header.cc b/model/ccnx-interest-header.cc
index 02ad9af..330e2f4 100644
--- a/model/ccnx-interest-header.cc
+++ b/model/ccnx-interest-header.cc
@@ -40,6 +40,7 @@
CcnxInterestHeader::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::CcnxInterestHeader")
+ .SetGroupName ("Ccnx")
.SetParent<Header> ()
.AddConstructor<CcnxInterestHeader> ()
;
diff --git a/model/ccnx-l3-protocol.cc b/model/ccnx-l3-protocol.cc
index 07bf848..8b7cccd 100644
--- a/model/ccnx-l3-protocol.cc
+++ b/model/ccnx-l3-protocol.cc
@@ -37,6 +37,7 @@
#include "ccnx-forwarding-strategy.h"
#include "ccnx-interest-header.h"
#include "ccnx-content-object-header.h"
+#include "ccnx-content-store.h"
#include <boost/foreach.hpp>
@@ -53,6 +54,7 @@
{
static TypeId tid = TypeId ("ns3::CcnxL3Protocol")
.SetParent<Ccnx> ()
+ .SetGroupName ("Ccnx")
.AddConstructor<CcnxL3Protocol> ()
// .AddTraceSource ("Tx", "Send ccnx packet to outgoing interface.",
// MakeTraceSourceAccessor (&CcnxL3Protocol::m_txTrace))
@@ -155,7 +157,7 @@
m_faces.push_back (face);
m_faceCounter ++;
- return m_faceCounter;
+ return face->GetId ();
}
Ptr<CcnxFace>
@@ -177,8 +179,14 @@
// Callback from lower layer
void
-CcnxL3Protocol::Receive (const Ptr<CcnxFace> &face, const Ptr<Packet> &p)
+CcnxL3Protocol::Receive (const Ptr<CcnxFace> &face, const Ptr<const Packet> &p)
{
+ if (face->IsUp ())
+ {
+ NS_LOG_LOGIC ("Dropping received packet -- interface is down");
+ // m_dropTrace (packet, DROP_INTERFACE_DOWN, m_node->GetObject<Ccnx> (), incomingFace);
+ return;
+ }
NS_LOG_LOGIC ("Packet from face " << &face << " received on node " << m_node->GetId ());
Ptr<Packet> packet = p->Copy (); // give upper layers a rw copy of the packet
@@ -198,16 +206,11 @@
const Ptr<CcnxInterestHeader> &header,
const Ptr<Packet> &packet)
{
- if (incomingFace->IsUp ())
- {
- NS_LOG_LOGIC ("Dropping received packet -- interface is down");
- // m_dropTrace (packet, DROP_INTERFACE_DOWN, m_node->GetObject<Ccnx> (), incomingFace);
- return;
- }
-
- NS_LOG_LOGIC ("Receiving interest from " << incomingFace);
+ NS_LOG_LOGIC ("Receiving interest from " << &incomingFace);
// m_rxTrace (packet, m_node->GetObject<Ccnx> (), incomingFace);
+ /// \todo Processing of Interest packets
+
// NS_ASSERT_MSG (m_forwardingStrategy != 0, "Need a forwarding protocol object to process packets");
// if (!m_forwardingStrategy->RouteInput (packet, incomingFace,
// MakeCallback (&CcnxL3Protocol::Send, this),
@@ -224,14 +227,9 @@
const Ptr<CcnxContentObjectHeader> &header,
const Ptr<Packet> &packet)
{
- if (incomingFace->IsUp ())
- {
- NS_LOG_LOGIC ("Dropping received packet -- interface is down");
- // m_dropTrace (packet, DROP_INTERFACE_DOWN, m_node->GetObject<Ccnx> (), incomingFace);
- return;
- }
+ NS_LOG_LOGIC ("Receiving contentObject from " << &incomingFace);
- NS_LOG_LOGIC ("Receiving contentObject from " << incomingFace);
+ /// \todo Processing of ContentObject packets
}
// fake method
@@ -245,27 +243,21 @@
void
CcnxL3Protocol::Send (const Ptr<CcnxFace> &face, const Ptr<Packet> &packet)
{
- // NS_LOG_FUNCTION (this << "packet: " << packet << ", route: "<< route);
-
- // if (route == 0)
- // {
- // NS_LOG_WARN ("No route to host. Drop.");
- // // m_dropTrace (packet, DROP_NO_ROUTE, m_node->GetObject<Ccnx> (), 0);
- // return;
- // }
- // Ptr<CcnxFace> outFace = route->GetOutputFace ();
+ NS_LOG_FUNCTION (this << "packet: " << &packet << ", face: "<< &face); //
- // if (outFace->IsUp ())
- // {
- // NS_LOG_LOGIC ("Sending via face " << *outFace);
- // // m_txTrace (packet, m_node->GetObject<Ccnx> (), outFace);
- // outFace->Send (packet);
- // }
- // else
- // {
- // NS_LOG_LOGIC ("Dropping -- outgoing interface is down: " << *outFace);
- // // m_dropTrace (packet, DROP_INTERFACE_DOWN, m_node->GetObject<Ccnx> (), outFace);
- // }
+ NS_ASSERT_MSG (face != 0, "Face should never be NULL");
+
+ if (face->IsUp ())
+ {
+ NS_LOG_LOGIC ("Sending via face " << &face); //
+ m_txTrace (packet, m_node->GetObject<Ccnx> (), face);
+ face->Send (packet);
+ }
+ else
+ {
+ NS_LOG_LOGIC ("Dropping -- outgoing interface is down: " << &face);
+ m_dropTrace (packet, DROP_INTERFACE_DOWN, m_node->GetObject<Ccnx> (), face);
+ }
}
diff --git a/model/ccnx-l3-protocol.h b/model/ccnx-l3-protocol.h
index 4743bdd..6167fd0 100644
--- a/model/ccnx-l3-protocol.h
+++ b/model/ccnx-l3-protocol.h
@@ -41,7 +41,8 @@
class Header;
class CcnxInterestHeader;
class CcnxContentObjectHeader;
-
+class CcnxContentStore;
+
/**
* \ingroup ccnx
* \brief Actual implementation of the Ccnx network layer
@@ -105,7 +106,7 @@
Ptr<CcnxForwardingStrategy> GetForwardingStrategy () const;
virtual void Send (const Ptr<CcnxFace> &face, const Ptr<Packet> &packet);
- virtual void Receive (const Ptr<CcnxFace> &device, const Ptr<Packet> &p);
+ virtual void Receive (const Ptr<CcnxFace> &face, const Ptr<const Packet> &p);
virtual uint32_t AddFace (const Ptr<CcnxFace> &face);
virtual uint32_t GetNFaces () const;
@@ -113,7 +114,7 @@
protected:
/**
- * Actual processing of incoming CCNx packets. Also processing packets coming from local apps
+ * \brief Actual processing of incoming CCNx interests
*
* Processing Interest packets
*/
@@ -124,7 +125,7 @@
/**
- * Actual processing of incoming CCNx packets. Also processing packets coming from local apps
+ * \brief Actual processing of incoming CCNx content objects
*
* Processing ContentObject packets
*/
@@ -153,22 +154,32 @@
ReceiveAndProcess (Ptr<CcnxFace> face, Ptr<Header> header, Ptr<Packet> p);
private:
- uint32_t m_faceCounter; ///< counter of faces. Increased every time a new face is added to the stack
+ uint32_t m_faceCounter; ///< \brief counter of faces. Increased every time a new face is added to the stack
typedef std::vector<Ptr<CcnxFace> > CcnxFaceList;
- CcnxFaceList m_faces;
+ CcnxFaceList m_faces; ///< \brief list of faces that belongs to ccnx stack on this node
- Ptr<Node> m_node;
- Ptr<CcnxForwardingStrategy> m_forwardingStrategy;
+ Ptr<Node> m_node; ///< \brief node on which ccnx stack is installed
+ Ptr<CcnxForwardingStrategy> m_forwardingStrategy; ///< \brief smart pointer to the selected forwarding strategy
- // TracedCallback<Ptr<const Packet>, Ptr<const CcnxFace> > m_sendOutgoingTrace;
- // TracedCallback<Ptr<const Packet>, Ptr<const CcnxFace> > m_unicastForwardTrace;
- // TracedCallback<Ptr<const Packet>, Ptr<const CcnxFace> > m_localDeliverTrace;
+ Ptr<CcnxContentStore> m_contentStore;
+
+ /**
+ * \brief Trace of transmitted packets, including all headers
+ * \internal
+ */
+ TracedCallback<Ptr<const Packet>, Ptr<Ccnx>, Ptr<const CcnxFace> > m_txTrace;
- // // The following two traces pass a packet with an IP header
- // TracedCallback<Ptr<const Packet>, Ptr<Ccnx>, Ptr<const CcnxFace> > m_txTrace;
- // TracedCallback<Ptr<const Packet>, Ptr<Ccnx>, Ptr<const CcnxFace> > m_rxTrace;
- // // <ip-header, payload, reason, ifindex> (ifindex not valid if reason is DROP_NO_ROUTE)
- // TracedCallback<Ptr<const Packet>, DropReason, Ptr<const Ccnx>, Ptr<const CcnxFace> > m_dropTrace;
+ /**
+ * \brief Trace of received packets, including all headers
+ * \internal
+ */
+ TracedCallback<Ptr<const Packet>, Ptr<Ccnx>, Ptr<const CcnxFace> > m_rxTrace;
+
+ /**
+ * \brief Trace of dropped packets, including reason and all headers
+ * \internal
+ */
+ TracedCallback<Ptr<const Packet>, DropReason, Ptr<const Ccnx>, Ptr<const CcnxFace> > m_dropTrace;
};
} // Namespace ns3
diff --git a/model/ccnx-local-face.cc b/model/ccnx-local-face.cc
index ea2a84b..80b0b52 100644
--- a/model/ccnx-local-face.cc
+++ b/model/ccnx-local-face.cc
@@ -37,6 +37,7 @@
CcnxLocalFace::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::CcnxLocalFace")
+ .SetGroupName ("Ccnx")
.SetParent<CcnxFace> ()
;
return tid;
diff --git a/model/ccnx-net-device-face.cc b/model/ccnx-net-device-face.cc
index 37a3555..9bdcd43 100644
--- a/model/ccnx-net-device-face.cc
+++ b/model/ccnx-net-device-face.cc
@@ -38,20 +38,21 @@
CcnxNetDeviceFace::GetTypeId ()
{
static TypeId tid = TypeId ("ns3::CcnxNetDeviceFace")
+ .SetGroupName ("Ccnx")
.SetParent<CcnxFace> ()
;
return tid;
}
/**
- * By default, Ccnx face are created in the "down" state
- * with no IP addresses. Before becoming useable, the user must
- * invoke SetUp on them once an Ccnx address and mask have been set.
+ * By default, Ccnx face are created in the "down" state. Before
+ * becoming useable, the user must invoke SetUp on the face
*/
-CcnxNetDeviceFace::CcnxNetDeviceFace ()
- : m_netDevice (0)
+CcnxNetDeviceFace::CcnxNetDeviceFace (const Ptr<NetDevice> &netDevice)
{
NS_LOG_FUNCTION (this);
+
+ m_netDevice = netDevice;
}
CcnxNetDeviceFace::~CcnxNetDeviceFace ()
@@ -77,12 +78,6 @@
Object::DoDispose ();
}
-void
-CcnxNetDeviceFace::SetNetDevice (Ptr<NetDevice> netDevice)
-{
- m_netDevice = netDevice;
-}
-
Ptr<NetDevice>
CcnxNetDeviceFace::GetNetDevice () const
{
@@ -127,7 +122,7 @@
const Address &to,
NetDevice::PacketType packetType)
{
- // bla bla bla
+ m_protocolHandler (Ptr<CcnxFace>(this), p);
}
diff --git a/model/ccnx-net-device-face.h b/model/ccnx-net-device-face.h
index 397d6c1..baf6a48 100644
--- a/model/ccnx-net-device-face.h
+++ b/model/ccnx-net-device-face.h
@@ -36,6 +36,10 @@
* component responsible for actual delivery of data packet to and
* from CCNx stack
*
+ * CcnxNetDevice face is permanently associated with one NetDevice
+ * object and this object cannot be changed for the lifetime of the
+ * face
+ *
* \see CcnxLocalFace, CcnxNetDeviceFace, CcnxIpv4Face, CcnxUdpFace
*/
class CcnxNetDeviceFace : public CcnxFace
@@ -49,9 +53,12 @@
static TypeId GetTypeId (void);
/**
- * \brief Default constructor
+ * \brief Constructor
+ *
+ * \param netDevice a smart pointer to NetDevice object to which
+ * this face will be associate
*/
- CcnxNetDeviceFace ();
+ CcnxNetDeviceFace (const Ptr<NetDevice> &netDevice);
virtual ~CcnxNetDeviceFace();
////////////////////////////////////////////////////////////////////
@@ -64,13 +71,6 @@
////////////////////////////////////////////////////////////////////
/**
- * \brief Associate NetDevice object with face
- *
- * \param node smart pointer to a NetDevice object
- */
- void SetNetDevice (Ptr<NetDevice> node);
-
- /**
* \brief Get NetDevice associated with the face
*
* \returns smart pointer to NetDevice associated with the face
@@ -84,7 +84,7 @@
CcnxNetDeviceFace (const CcnxNetDeviceFace &); ///< \brief Disabled copy constructor
CcnxNetDeviceFace& operator= (const CcnxNetDeviceFace &); ///< \brief Disabled copy operator
- // callback
+ /// \brief callback from lower layers
void ReceiveFromNetDevice (Ptr<NetDevice> device,
Ptr<const Packet> p,
uint16_t protocol,
diff --git a/model/ccnx.cc b/model/ccnx.cc
index a940c36..0fe4b31 100644
--- a/model/ccnx.cc
+++ b/model/ccnx.cc
@@ -32,6 +32,7 @@
Ccnx::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::Ccnx")
+ .SetGroupName ("Ccnx")
.SetParent<Object> ()
;
return tid;
diff --git a/model/ccnx.h b/model/ccnx.h
index 1cbe428..666158f 100644
--- a/model/ccnx.h
+++ b/model/ccnx.h
@@ -90,7 +90,7 @@
* \param p the packet
*/
virtual void
- Receive (const Ptr<CcnxFace> &device, const Ptr<Packet> &p) = 0;
+ Receive (const Ptr<CcnxFace> &face, const Ptr<const Packet> &p) = 0;
/**
* \brief Register a new forwarding strategy to be used by this Ccnx
@@ -140,128 +140,6 @@
*/
virtual Ptr<CcnxFace>
GetFace (uint32_t face) const = 0;
-
-public:
- /**
- * \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_SequenceNumber = 256,
- CCN_DTAG_CCNProtocolDataUnit = 17702112
- };
};
} // namespace ns3
diff --git a/model/hash-helper.h b/model/hash-helper.h
index 880a217..36a9ee8 100644
--- a/model/hash-helper.h
+++ b/model/hash-helper.h
@@ -18,48 +18,50 @@
* Author: Ilya Moiseenko <iliamo@cs.ucla.edu>
*/
-#ifndef ccnx_hash_helper_h
-#define ccnx_hash_helper_h
+#ifndef CCNX_HASH_HELPER_H
+#define CCNX_HASH_HELPER_H
#include <string>
-#include <boost/unordered_map.hpp>
-#include <boost/functional/hash.hpp>
#include <boost/foreach.hpp>
+#include "name-components.h"
-//size of content store
-#define NDN_CONTENT_STORE_SIZE 100
-//maximum length of content name
-#define NDN_MAX_NAME_LENGTH 30
-
-//using namespace std;
-
-#define KEY(x) x->first
-#define VALUE(x) x->second
-
-
-/*template<typename T>
-struct hash : public std::unary_function<T, std::size_t> {
- std::size_t operator()(T const&) const;
-};*/
-
-struct string_hash : public std::unary_function<std::string, std::size_t>
+namespace ns3
{
- inline std::size_t operator( )( std::string str ) const
- {
- std::size_t hash = str.size() + 23;
- for( std::string::const_iterator it = str.begin( ); it!=str.end(); it++ )
- {
- hash = ((hash << 6) ^ (hash >> 27)) + static_cast<std::size_t>( *it );
- }
-
- return boost::hash_value(hash); //hash;
- }
-};
-// A collision-chaining hash table mapping strings to ints.
-template<typename Value>
-class string_key_hash_t : public boost::unordered_map<std::string,Value, string_hash, std::equal_to<std::string>,std::allocator<std::string> >
+/**
+ * \ingroup ccnx-helpers
+ * \brief Helper providing hash value for the name prefix
+ *
+ * The whole prefix is considered as a long string with '/' delimiters
+ *
+ * \todo Testing is required to determine if this hash function
+ * actually provides good hash results
+ */
+struct CcnxPrefixHash : public std::unary_function<Name::Components, std::size_t>
{
+ std::size_t
+ operator() (const Name::Components &prefix) const
+ {
+ std::size_t hash = 23;
+ BOOST_FOREACH (const std::string &str, prefix.GetComponents ())
+ {
+ hash += str.size ();
+ hash = ((hash << 6) ^ (hash >> 27)) + '/';
+ BOOST_FOREACH (char c, str)
+ {
+ hash = ((hash << 6) ^ (hash >> 27)) + c;
+ }
+ }
+ return hash;
+ }
};
+
+// // A collision-chaining hash table mapping strings to ints.
+// template<typename Value>
+// class string_key_hash_t : public boost::unordered_map<std::string,Value, string_hash, std::equal_to<std::string>,std::allocator<std::string> >
+// {
+// };
-#endif
\ No newline at end of file
+} // namespace ns3
+
+#endif // CCNX_HASH_HELPER_H
diff --git a/model/name-components.h b/model/name-components.h
index 0ea4821..95d2347 100644
--- a/model/name-components.h
+++ b/model/name-components.h
@@ -24,6 +24,7 @@
#include "ns3/simple-ref-count.h"
#include <string>
+#include <algorithm>
#include <list>
namespace ns3 {
@@ -58,6 +59,12 @@
inline size_t
size () const;
+
+ inline bool
+ operator== (const Components &prefix) const;
+
+ inline bool
+ operator< (const Components &prefix) const;
private:
std::list<std::string> m_prefix;
@@ -79,8 +86,20 @@
{
(*this) (s);
}
-
-
+
+bool
+Components::operator== (const Components &prefix) const
+{
+ return std::equal (m_prefix.begin (), m_prefix.end (), prefix.m_prefix.begin ());
+}
+
+bool
+Components::operator< (const Components &prefix) const
+{
+ return std::lexicographical_compare (m_prefix.begin (), m_prefix.end (),
+ prefix.m_prefix.begin (), prefix.m_prefix.end ());
+}
+
} // Namespace Name
} // namespace ns3
diff --git a/wscript b/wscript
index 0142dc2..0eb185e 100644
--- a/wscript
+++ b/wscript
@@ -10,7 +10,7 @@
def configure(conf):
conf.check_tool('boost')
- conf.env['BOOST'] = conf.check_boost(lib = '', # need only base
+ conf.env['BOOST'] = conf.check_boost(lib = 'iostreams',
min_version='1.40.0' )
if not conf.env['BOOST']:
conf.report_optional_feature("ndn-abstract", "NDN abstraction", False,
@@ -22,42 +22,46 @@
def build(bld):
- module = bld.create_ns3_module ('NDNabstraction', ['applications', 'core', 'network', 'point-to-point','topology-read','visualizer'])
+ module = bld.create_ns3_module ('NDNabstraction', ['core', 'network', 'point-to-point',
+ 'topology-read'])
+ module.uselib = 'BOOST BOOST_IOSTREAMS'
tests = bld.create_ns3_module_test_library('NDNabstraction')
headers = bld.new_task_gen('ns3header')
headers.module = 'NDNabstraction'
if not bld.env['ENABLE_NDN_ABSTRACT']:
+ conf.env['MODULES_NOT_BUILT'].append('NDNabstraction')
return
- module.find_sources_in_dirs (['model', 'apps', 'helper'],[],['.cc']);
+ module.find_sources_in_dirs (['model', 'apps', 'helper',
+ 'helper/ccnb-parser',
+ 'helper/ccnb-parser/visitors',
+ 'helper/ccnb-parser/syntax-tree'],[],['.cc']);
tests.find_sources_in_dirs( ['test'], [], ['.cc'] );
- headers.find_sources_in_dirs( ['model', 'apps', 'helper'], [], ['.h'] );
+ headers.find_sources_in_dirs( ['model', 'apps', 'helper',
+ 'helper/ccnb-parser',
+ 'helper/ccnb-parser/visitors',
+ 'helper/ccnb-parser/syntax-tree'], [], ['.h'] );
-
- for path in ["examples"]:
- anode = bld.path.find_dir (path)
- if not anode or not anode.is_child_of(bld.srcnode):
- raise Utils.WscriptError("Unable to use '%s' - either because \
- it's not a relative path"", or it's not child of \
- '%s'."%(name,bld.srcnode))
- bld.rescan(anode)
- for filename in bld.cache_dir_contents[anode.id]:
- if filename.startswith('.') or not filename.endswith(".cc"):
- continue
- name = filename[:-len(".cc")]
- obj = bld.create_ns3_program(name, ['NDNabstraction'])
- obj.path = obj.path.find_dir (path)
- obj.source = filename
- obj.target = name
- obj.name = obj.target
-
- if bld.env['ENABLE_OPENSSL']:
- module.uselib = 'OPENSSL'
-
- if bld.env['ENABLE_EXAMPLES']:
- bld.add_subdirs('examples')
+ if True or bld.env['ENABLE_EXAMPLES']:
+ for path in ["examples"]:
+ anode = bld.path.find_dir (path)
+ if not anode or not anode.is_child_of(bld.srcnode):
+ raise Utils.WscriptError("Unable to use '%s' - either because \
+ it's not a relative path"", or it's not child of \
+ '%s'."%(name,bld.srcnode))
+ bld.rescan(anode)
+ for filename in bld.cache_dir_contents[anode.id]:
+ if filename.startswith('.') or not filename.endswith(".cc"):
+ continue
+ name = filename[:-len(".cc")]
+ obj = bld.create_ns3_program(name, ['NDNabstraction'])
+ obj.path = obj.path.find_dir (path)
+ obj.source = filename
+ obj.target = name
+ obj.name = obj.target
+ obj.uselib = 'BOOST BOOST_IOSTREAMS'
bld.ns3_python_bindings()