Implementing visitor pattern for CCNx message parsing. Needs debugging.

Altering src/network/model/buffer* to support more Iterator features
diff --git a/model/ccnx-content-object-header.cc b/model/ccnx-content-object-header.cc
index a3852a2..e567207 100644
--- a/model/ccnx-content-object-header.cc
+++ b/model/ccnx-content-object-header.cc
@@ -22,7 +22,8 @@
 #include "ccnx-content-object-header.h"
 
 #include "ns3/log.h"
-#include "ns3/ccnx-coding-helper.h"
+#include "ns3/ccnx-encoding-helper.h"
+#include "ns3/ccnx-decoding-helper.h"
 
 NS_LOG_COMPONENT_DEFINE ("CcnxContentObjectHeader");
 
@@ -64,19 +65,19 @@
   // Unfortunately, two serializations are required, unless we can pre-calculate header length... which is not trivial
   Buffer tmp;
   
-  return CcnxCodingHelper::Serialize (tmp.Begin(), *this);
+  return CcnxEncodingHelper::Serialize (tmp.Begin(), *this);
 }
     
 void
 CcnxContentObjectHeader::Serialize (Buffer::Iterator start) const
 {
-  CcnxCodingHelper::Serialize (start, *this);
+  CcnxEncodingHelper::Serialize (start, *this);
 }
 
 uint32_t
 CcnxContentObjectHeader::Deserialize (Buffer::Iterator start)
 {
-  return 0; // the most complicated part is here
+  return CcnxDecodingHelper::Deserialize (start, *this); // \todo Debugging is necessary
 }
   
 TypeId
@@ -101,7 +102,7 @@
 TypeId
 CcnxContentObjectTail::GetTypeId (void)
 {
-  static TypeId tid = TypeId ("ns3::CcnxContentObjectHeader")
+  static TypeId tid = TypeId ("ns3::CcnxContentObjectTail")
     .SetParent<Header> ()
     .AddConstructor<CcnxContentObjectHeader> ()
     ;
@@ -139,10 +140,10 @@
 {
   Buffer::Iterator i = start;
   uint8_t __attribute__ ((unused)) closing_tag_content = i.ReadU8 ();
-  NS_ASSERT_MSG (closing_tag_content==0, "Should be closing tag </Content> (0x00)");
+  NS_ASSERT_MSG (closing_tag_content==0, "Should be a closing tag </Content> (0x00)");
 
   uint8_t __attribute__ ((unused)) closing_tag_content_object = i.ReadU8 ();
-  NS_ASSERT_MSG (closing_tag_content_object==0, "Should be closing tag </ContentObject> (0x00)");
+  NS_ASSERT_MSG (closing_tag_content_object==0, "Should be a closing tag </ContentObject> (0x00)");
 
   return 2;
 }
diff --git a/model/ccnx-interest-header.cc b/model/ccnx-interest-header.cc
index cab33ea..02ad9af 100644
--- a/model/ccnx-interest-header.cc
+++ b/model/ccnx-interest-header.cc
@@ -26,7 +26,8 @@
 #include "ccnx-interest-header.h"
 
 #include "ns3/log.h"
-#include "ns3/ccnx-coding-helper.h"
+#include "ns3/ccnx-encoding-helper.h"
+#include "ns3/ccnx-decoding-helper.h"
 
 NS_LOG_COMPONENT_DEFINE ("CcnxInterestHeader");
 
@@ -171,19 +172,19 @@
   // unfortunately, 2 serialization required...
   Buffer tmp;
   
-  return CcnxCodingHelper::Serialize (tmp.Begin(), *this);
+  return CcnxEncodingHelper::Serialize (tmp.Begin(), *this);
 }
     
 void
 CcnxInterestHeader::Serialize (Buffer::Iterator start) const
 {
-  CcnxCodingHelper::Serialize (start, *this);
+  CcnxEncodingHelper::Serialize (start, *this);
 }
 
 uint32_t
 CcnxInterestHeader::Deserialize (Buffer::Iterator start)
 {
-  return 0; // the most complicated part is here
+  return CcnxDecodingHelper::Deserialize (start, *this); // \todo Debugging is necessary
 }
 
 TypeId
diff --git a/model/ccnx.h b/model/ccnx.h
index 12c45d2..1e1aa0b 100644
--- a/model/ccnx.h
+++ b/model/ccnx.h
@@ -161,6 +161,155 @@
    * ignored during Ccnx forwarding.
    */
   virtual void SetDown (uint32_t face) = 0;
+
+public:
+    /**
+   * 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 */
+  };
+
+  /** CCN_CLOSE terminates composites */
+  enum {CCN_CLOSE = 0};
+
+  // enum ccn_ext_subtype {
+  //   /* skip smallest values for now */
+  //   CCN_PROCESSING_INSTRUCTIONS = 16 /* <?name:U value:U?> */
+  // };
+
+  /**
+   * 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
+  };
+
+  /**
+   * The decoder state is one of these, possibly with some
+   * additional bits set for internal use.  A complete parse
+   * ends up in state 0 or an error state.  Not all possible
+   * error states are listed here.
+   */
+  enum ccn_decoder_state {
+    CCN_DSTATE_INITIAL = 0,
+    CCN_DSTATE_NEWTOKEN,
+    CCN_DSTATE_NUMVAL,
+    CCN_DSTATE_UDATA,
+    CCN_DSTATE_TAGNAME,
+    CCN_DSTATE_ATTRNAME,
+    CCN_DSTATE_BLOB,
+    /* All error states are negative */
+    CCN_DSTATE_ERR_OVERFLOW = -1,
+    CCN_DSTATE_ERR_ATTR     = -2,       
+    CCN_DSTATE_ERR_CODING   = -3,
+    CCN_DSTATE_ERR_NEST     = -4, 
+    CCN_DSTATE_ERR_BUG      = -5
+  };
 };
 
 } // namespace ns3 
diff --git a/model/name-components.h b/model/name-components.h
index d9b3f0a..0ea4821 100644
--- a/model/name-components.h
+++ b/model/name-components.h
@@ -36,7 +36,11 @@
   Components (const std::string &s);
   ~Components ();
   
-  Components& operator () (const std::string &s);
+  inline void
+  Add (const std::string &s);
+       
+  Components&
+  operator () (const std::string &s);
 
   const std::list<std::string> &
   GetComponents () const;
@@ -70,6 +74,12 @@
   return m_prefix.size ();
 }
   
+void
+Components::Add (const std::string &s)
+{
+  (*this) (s);
+}
+  
   
 } // Namespace Name
 } // namespace ns3