First steps in CCNx packet coding. ccnx_encode* routines rewritten in NS3 style (using NS3::Buffer)

diff --git a/helper/ccnx-coding-helper.cc b/helper/ccnx-coding-helper.cc
new file mode 100644
index 0000000..6899543
--- /dev/null
+++ b/helper/ccnx-coding-helper.cc
@@ -0,0 +1,223 @@
+/* -*- 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: 
+ */
+
+#include "ccnx-coding-helper.h"
+
+#include "ns3/name-components.h"
+#include "ns3/ccnx-interest-header.h"
+#include "ns3/ccnx-content-object-header.h"
+
+#include <sstream>
+
+namespace ns3 {
+
+#define CCN_TT_BITS 3
+#define CCN_TT_MASK ((1 << CCN_TT_BITS) - 1)
+#define CCN_MAX_TINY ((1 << (7-CCN_TT_BITS)) - 1)
+#define CCN_TT_HBIT ((unsigned char)(1 << 7))
+
+size_t
+CcnxCodingHelper::AppendBlockHeader (Buffer::Iterator start, size_t val, enum 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 & ~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) | CCN_CLOSE;
+    n++;
+    val >>= 7;
+  }
+  start.Write (p,n);
+  return n;
+}
+
+size_t
+CcnxCodingHelper::AppendNumber (Buffer::Iterator start, uint32_t number)
+{
+  std::ostringstream os;
+  os << number;
+
+  size_t written = 0;
+  written += AppendBlockHeader (start, os.str().size(), CCN_UDATA);
+  written += os.str().size();
+  start.Write (reinterpret_cast<const unsigned char*>(os.str().c_str()), os.str().size());
+
+  return written;
+}
+
+  
+size_t
+CcnxCodingHelper::CcnxCodingHelper::AppendCloser (Buffer::Iterator start)
+{
+  start.WriteU8 (CCN_CLOSE);
+  return 1;
+}
+
+size_t
+CcnxCodingHelper::AppendName (Buffer::Iterator start, const Name::Components &name)
+{
+  return 0;
+}
+
+size_t
+CcnxCodingHelper::AppendTimestampBlob (Buffer::Iterator start, Time time)
+{
+  // the original function implements Markers... thought not sure what are these markers for...
+
+  // Determine miminal number of bytes required to store the timestamp
+  int required_bytes = 2; // 12 bits for fractions of a second, 4 bits left for seconds. Sometimes it is enough
+  intmax_t ts = time.ToInteger (Time::S) >> 4;
+  for (;  required_bytes < 7 && ts != 0; ts >>= 8) // not more than 6 bytes?
+     required_bytes++;
+  
+  size_t len = AppendBlockHeader(start, required_bytes, CCN_BLOB);
+
+  // write part with seconds
+  ts = time.ToInteger (Time::S) >> 4;
+  for (int i = 0; i < required_bytes - 2; i++)
+    start.WriteU8 ( ts >> (8 * (required_bytes - 3 - i)) );
+
+  /* arithmetic contortions are to avoid overflowing 31 bits */
+  ts = ((time.ToInteger (Time::S) & 15) << 12) + ((time.ToInteger (Time::NS) / 5 * 8 + 195312) / 390625);
+  for (int i = required_bytes - 2; i < required_bytes; i++)
+    start.WriteU8 ( ts >> (8 * (required_bytes - 1 - i)) );
+  
+  return len + required_bytes;
+}
+
+size_t
+CcnxCodingHelper::AppendTaggedBlob (Buffer::Iterator start, ccn_dtag dtag,
+                  const uint8_t *data, size_t size)
+{
+  size_t written = AppendBlockHeader (start, dtag, CCN_DTAG);
+  if (size>0)
+    {
+      written += AppendBlockHeader (start, size, CCN_BLOB);
+      start.Write (data, size);
+      written += size;
+    }
+  written += AppendCloser (start);
+
+  return written;
+}
+
+
+size_t
+CcnxCodingHelper::Serialize (Buffer::Iterator start, const CcnxInterestHeader &interest)
+{
+  size_t written = 0;
+  written += AppendBlockHeader (start, CCN_DTAG_Interest, CCN_DTAG); // <Interest>
+  
+  written += AppendBlockHeader (start, CCN_DTAG_Name, CCN_DTAG); // <Name>
+  written += AppendName (start, interest.GetName());                // <Component>...</Component>...
+  written += AppendCloser (start);                               // </Name>
+
+  if (interest.GetMinSuffixComponents() >= 0)
+    {
+      written += AppendBlockHeader (start, CCN_DTAG_MinSuffixComponents, CCN_DTAG);
+      written += AppendNumber (start, interest.GetMinSuffixComponents ());
+      written += AppendCloser (start);
+    }
+  if (interest.GetMaxSuffixComponents() >= 0)
+    {
+      written += AppendBlockHeader (start, CCN_DTAG_MaxSuffixComponents, CCN_DTAG);
+      written += AppendNumber (start, interest.GetMaxSuffixComponents ());
+      written += AppendCloser (start);
+    }
+  if (interest.GetExclude().size() > 0)
+    {
+      written += AppendBlockHeader (start, CCN_DTAG_Exclude, CCN_DTAG); // <Exclude>
+      written += AppendName (start, interest.GetExclude());                // <Component>...</Component>...
+      written += AppendCloser (start);                                  // </Exclude>
+    }
+  if (interest.IsEnabledChildSelector())
+    {
+      written += AppendBlockHeader (start, CCN_DTAG_ChildSelector, CCN_DTAG);
+      written += AppendNumber (start, 1);
+      written += AppendCloser (start);
+    }
+  if (interest.IsEnabledAnswerOriginKind())
+    {
+      written += AppendBlockHeader (start, CCN_DTAG_AnswerOriginKind, CCN_DTAG);
+      written += AppendNumber (start, 1);
+      written += AppendCloser (start);
+    }
+  if (interest.GetScope() >= 0)
+    {
+      written += AppendBlockHeader (start, CCN_DTAG_Scope, CCN_DTAG);
+      written += AppendNumber (start, interest.GetScope ());
+      written += AppendCloser (start);
+    }
+  if (!interest.GetInterestLifetime().IsZero())
+    {
+      written += AppendBlockHeader (start, CCN_DTAG_InterestLifetime, CCN_DTAG);
+      written += AppendTimestampBlob (start, interest.GetInterestLifetime());
+      written += AppendCloser (start);
+    }
+  if (interest.GetNonce()>0)
+    {
+      uint32_t nonce = interest.GetNonce();
+      written += AppendTaggedBlob (start, CCN_DTAG_Nonce,
+                                   reinterpret_cast<const uint8_t*>(&nonce),
+                                   sizeof(nonce));
+    }
+  written += AppendCloser (start); // </Interest>
+
+  return written;
+}
+
+size_t
+CcnxCodingHelper::Serialize (Buffer::Iterator start, const CcnxContentObjectHeader &contentObject)
+{
+  size_t written = 0;
+  written += AppendBlockHeader (start, CCN_DTAG_ContentObject, CCN_DTAG); // <ContentObject>
+
+  // fake signature
+  written += AppendBlockHeader (start, CCN_DTAG_Signature, CCN_DTAG); // <Signature>
+  // Signature ::= DigestAlgorithm? 
+  //               Witness?         
+  //               SignatureBits   
+  written += AppendTaggedBlob (start, CCN_DTAG_SignatureBits, 0, 0);      // <SignatureBits />
+  written += AppendCloser (start);                                    // </Signature>  
+
+  written += AppendName (start, contentObject.GetName()); // <Name><Component>...</Component>...</Name>
+
+  // fake signature
+  written += AppendBlockHeader (start, CCN_DTAG_SignedInfo, CCN_DTAG); // <SignedInfo>
+  // SignedInfo ::= PublisherPublicKeyDigest
+  //                Timestamp
+  //                Type?
+  //                FreshnessSeconds?
+  //                FinalBlockID?
+  //                KeyLocator?
+  written += AppendTaggedBlob (start, CCN_DTAG_PublisherPublicKeyDigest, 0, 0); // <PublisherPublicKeyDigest />
+  written += AppendCloser (start);                                     // </SignedInfo>
+
+  written += AppendBlockHeader (start, CCN_DTAG_Content, CCN_DTAG); // <Content>
+
+  // there is no closing tag !!!
+  return written;
+}
+
+} // namespace ns3
diff --git a/helper/ccnx-coding-helper.h b/helper/ccnx-coding-helper.h
new file mode 100644
index 0000000..3cafcbc
--- /dev/null
+++ b/helper/ccnx-coding-helper.h
@@ -0,0 +1,245 @@
+/* -*- 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 _CCNX_CODING_HELPER_H_
+#define _CCNX_CODING_HELPER_H_
+
+#include <sys/types.h>
+#include "ns3/ptr.h"
+#include "ns3/nstime.h"
+#include "ns3/buffer.h"
+
+namespace ns3 {
+
+namespace Name{ class Components; }
+
+class CcnxInterestHeader;
+class CcnxContentObjectHeader;
+  
+/**
+ * Helper to encode/decode ccnb formatted CCNx message
+ *
+ */
+class CcnxCodingHelper
+{
+public:
+  static size_t
+  Serialize (Buffer::Iterator start, const CcnxInterestHeader &interest);
+
+  static size_t
+  Serialize (Buffer::Iterator start, const CcnxContentObjectHeader &contentObject);
+
+private:
+  /**
+   * 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
+  };
+
+
+private:
+  static size_t
+  AppendBlockHeader (Buffer::Iterator start, size_t value, ccn_tt block_type);
+
+  static size_t
+  AppendNumber (Buffer::Iterator start, uint32_t number);
+
+  static size_t
+  AppendCloser (Buffer::Iterator start);
+
+  static size_t
+  AppendName (Buffer::Iterator start, const Name::Components &name);
+
+  /**
+   * Append a binary timestamp as a BLOB using the ccn binary
+   * Timestamp representation (12-bit fraction).
+   *
+   * @param start start iterator of  the buffer to append to.
+   * @param time - Time object
+   *
+   * @returns written length
+   */
+  static size_t
+  AppendTimestampBlob (Buffer::Iterator start, Time time);
+
+  /**
+   * Append a tagged BLOB
+   *
+   * This is a ccnb-encoded element with containing the BLOB as content
+   *
+   * @param start start iterator of  the buffer to append to.
+   * @param dtag is the element's dtab
+   * @param data points to the binary data
+   * @param size is the size of the data, in bytes
+   *
+   * @returns written length
+   */
+  static size_t
+  AppendTaggedBlob (Buffer::Iterator start, ccn_dtag dtag,
+                    const uint8_t *data, size_t size);
+  
+};
+
+} // namespace ns3
+
+#endif // _CCNX_CODING_HELPER_H_
+
diff --git a/helper/ccnx-forwarding-helper.cc b/helper/ccnx-forwarding-helper.cc
index ed038cb..83f16d5 100644
--- a/helper/ccnx-forwarding-helper.cc
+++ b/helper/ccnx-forwarding-helper.cc
@@ -20,7 +20,7 @@
 #include "ns3/node.h"
 #include "ns3/node-list.h"
 #include "ns3/simulator.h"
-#include "ns3/ccnx-forwarding-protocol.h"
+#include "ns3/ccnx-forwarding-strategy.h"
 #include "ccnx-forwarding-helper.h"
 
 namespace ns3 {
@@ -65,7 +65,7 @@
 CcnxForwardingHelper::Print (Ptr<Node> node, Ptr<OutputStreamWrapper> stream) const
 {
   Ptr<Ccnx> ccnx = node->GetObject<Ccnx> ();
-  Ptr<CcnxForwardingProtocol> rp = ccnx->GetForwardingProtocol ();
+  Ptr<CcnxForwardingStrategy> rp = ccnx->GetForwardingStrategy ();
   NS_ASSERT (rp);
   rp->PrintForwardingTable (stream);
 }
@@ -74,7 +74,7 @@
 CcnxForwardingHelper::PrintEvery (Time printInterval, Ptr<Node> node, Ptr<OutputStreamWrapper> stream) const
 {
   Ptr<Ccnx> ccnx = node->GetObject<Ccnx> ();
-  Ptr<CcnxForwardingProtocol> rp = ccnx->GetForwardingProtocol ();
+  Ptr<CcnxForwardingStrategy> rp = ccnx->GetForwardingStrategy ();
   NS_ASSERT (rp);
   rp->PrintForwardingTable (stream);
   Simulator::Schedule (printInterval, &CcnxForwardingHelper::PrintEvery, this, printInterval, node, stream);
diff --git a/helper/ccnx-forwarding-helper.h b/helper/ccnx-forwarding-helper.h
index d66584f..a7d0bf8 100644
--- a/helper/ccnx-forwarding-helper.h
+++ b/helper/ccnx-forwarding-helper.h
@@ -26,14 +26,14 @@
 
 namespace ns3 {
 
-class CcnxForwardingProtocol;
+class CcnxForwardingStrategy;
 class Node;
 
 /**
- * \brief a factory to create ns3::CcnxForwardingProtocol objects
+ * \brief a factory to create ns3::CcnxForwardingStrategy objects
  *
  * For each new forwarding protocol created as a subclass of 
- * ns3::CcnxForwardingProtocol, you need to create 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.
@@ -59,7 +59,7 @@
    * \param node the node within which the new forwarding protocol will run
    * \returns a newly-created forwarding protocol
    */
-  virtual Ptr<CcnxForwardingProtocol> Create (Ptr<Node> node) const = 0;
+  virtual Ptr<CcnxForwardingStrategy> Create (Ptr<Node> node) const = 0;
 
   /**
    * \brief prints the forwarding tables of all nodes at a particular time.
@@ -67,7 +67,7 @@
    * \param stream The output stream object to use 
    *
    * This method calls the PrintForwardingTable() method of the 
-   * CcnxForwardingProtocol stored in the Ccnx object, for all nodes at the
+   * CcnxForwardingStrategy stored in the Ccnx object, for all nodes at the
    * specified time; the output format is forwarding protocol-specific.
    */
   void PrintForwardingTableAllAt (Time printTime, Ptr<OutputStreamWrapper> stream) const;
@@ -78,7 +78,7 @@
    * \param stream The output stream object to use
    *
    * This method calls the PrintForwardingTable() method of the 
-   * CcnxForwardingProtocol stored in the Ccnx object, for all nodes at the
+   * CcnxForwardingStrategy stored in the Ccnx object, for all nodes at the
    * specified time interval; the output format is forwarding protocol-specific.
    */
   void PrintForwardingTableAllEvery (Time printInterval, Ptr<OutputStreamWrapper> stream) const;
@@ -90,7 +90,7 @@
    * \param stream The output stream object to use
    *
    * This method calls the PrintForwardingTable() method of the 
-   * CcnxForwardingProtocol stored in the Ccnx object, for the selected node 
+   * CcnxForwardingStrategy stored in the Ccnx object, for the selected node 
    * at the specified time; the output format is forwarding protocol-specific.
    */
   void PrintForwardingTableAt (Time printTime, Ptr<Node> node, Ptr<OutputStreamWrapper> stream) const;
@@ -102,7 +102,7 @@
    * \param stream The output stream object to use
    *
    * This method calls the PrintForwardingTable() method of the 
-   * CcnxForwardingProtocol stored in the Ccnx object, for the selected node 
+   * CcnxForwardingStrategy stored in the Ccnx object, for the selected node 
    * at the specified interval; the output format is forwarding protocol-specific.
    */
   void PrintForwardingTableEvery (Time printInterval, Ptr<Node> node, Ptr<OutputStreamWrapper> stream) const;
diff --git a/helper/ccnx-header-helper.cc b/helper/ccnx-header-helper.cc
new file mode 100644
index 0000000..fdc986a
--- /dev/null
+++ b/helper/ccnx-header-helper.cc
@@ -0,0 +1,61 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "ccnx-header-helper.h"
+
+#include "ns3/log.h"
+#include "ns3/packet.h"
+#include "ns3/header.h"
+#include "ns3/object.h"
+
+#include "ns3/ccnx-interest-header.h"
+#include "ns3/ccnx-content-object-header.h"
+
+NS_LOG_COMPONENT_DEFINE ("CcnxHeaderHelper");
+
+#define INTEREST_BYTE0 0x01
+#define INTEREST_BYTE1 0xD2
+
+#define CONTENT_OBJECT_BYTE0 0x04
+#define CONTENT_OBJECT_BYTE1 0x82
+
+namespace ns3
+{
+
+Ptr<Header>
+CcnxHeaderHelper::CreateCorrectCcnxHeader (Ptr<const Packet> packet)
+{
+  uint8_t type[2];
+  uint32_t read=packet->CopyData (type,2);
+  if (read!=2) throw CcnxUnknownHeaderException();
+  
+  if (type[0] == INTEREST_BYTE0 && type[1] == INTEREST_BYTE1)
+    {
+      return Create<CcnxInterestHeader> ();
+    }
+  else if (type[0] == CONTENT_OBJECT_BYTE0 && type[1] == CONTENT_OBJECT_BYTE1)
+    {
+      return Create<CcnxContentObjectHeader> ();
+    }
+
+  throw CcnxUnknownHeaderException();
+}
+
+} // namespace ns3
diff --git a/helper/ccnx-header-helper.h b/helper/ccnx-header-helper.h
new file mode 100644
index 0000000..35aeab8
--- /dev/null
+++ b/helper/ccnx-header-helper.h
@@ -0,0 +1,75 @@
+/* -*- 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_HEADER_HELPER_H_
+#define _CCNX_HEADER_HELPER_H_
+
+#include "ns3/ptr.h"
+
+namespace ns3
+{
+
+class Header;
+class Packet;
+
+/**
+ * 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
+ * determine type of CCNx packet and return corresponent header class,
+ * CcnxInterestHeader or CcnxContentObjectHeader
+ *
+ * Throws CcnxUnknownHeaderException if header type couldn't be determined
+ */
+class CcnxHeaderHelper
+{
+public:
+
+  /**
+   * Static function to create an appropriate CCNx header
+   *
+   * It peeks first 2 bytes of a packet.
+   *
+   *  All interests start with 
+   *   +-----------------+  +---+---------+-------+
+   *   | 0 0 0 0 0 0 0 1 |  | 1 | 1 0 1 0 | 0 1 0 |   (0x01 0xD2)
+   *   +-----------------+  +---+---------+-------+
+   *
+   *  All content objects start with 
+   *   +-----------------+  +---+---------+-------+
+   *   | 0 0 0 0 0 1 0 0 |  | 1 | 0 0 0 0 | 0 1 0 |   (0x04 0x82)
+   *   +-----------------+  +---+---------+-------+
+   *                          ^             ^^^^^
+   *                          |               |
+   *                      terminator      DTAG (Dictionary TAG)
+   *
+   * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
+   */
+  
+  static Ptr<Header>
+  CreateCorrectCcnxHeader (Ptr<const Packet> packet);
+};
+
+class CcnxUnknownHeaderException {};
+
+} // namespace ns3
+
+#endif // _CCNX_HEADER_HELPER_H_
diff --git a/helper/ccnx-stack-helper.cc b/helper/ccnx-stack-helper.cc
index 836c379..50839a3 100644
--- a/helper/ccnx-stack-helper.cc
+++ b/helper/ccnx-stack-helper.cc
@@ -66,7 +66,7 @@
 #include "ns3/callback.h"
 #include "ns3/node.h"
 #include "ns3/core-config.h"
-#include "ns3/ccnx-forwarding-protocol.h"
+#include "ns3/ccnx-forwarding-strategy.h"
 
 #include "ccnx-stack-helper.h"
 #include "ccnx-forwarding-helper.h"
@@ -216,8 +216,8 @@
       CreateAndAggregateObjectFromTypeId (node, "ns3::CcnxL3Protocol");
       // Set forwarding
       Ptr<Ccnx> ccnx = node->GetObject<Ccnx> ();
-      Ptr<CcnxForwardingProtocol> ccnxForwarding = m_forwarding->Create (node);
-      ccnx->SetForwardingProtocol (ccnxForwarding);
+      Ptr<CcnxForwardingStrategy> ccnxForwarding = m_forwarding->Create (node);
+      ccnx->SetForwardingStrategy (ccnxForwarding);
     }
 }
 
diff --git a/helper/ccnx-stack-helper.h b/helper/ccnx-stack-helper.h
index d692b05..3d0b3a4 100644
--- a/helper/ccnx-stack-helper.h
+++ b/helper/ccnx-stack-helper.h
@@ -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
  *
diff --git a/helper/ccnx-trace-helper.h b/helper/ccnx-trace-helper.h
index 6c4fa7b..a0390e7 100644
--- a/helper/ccnx-trace-helper.h
+++ b/helper/ccnx-trace-helper.h
@@ -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) 2010 University of Washington
  *
diff --git a/helper/ndn_stupidinterestgenerator_helper.cc b/helper/ndn_stupidinterestgenerator_helper.cc
index 1699f40..8fde311 100644
--- a/helper/ndn_stupidinterestgenerator_helper.cc
+++ b/helper/ndn_stupidinterestgenerator_helper.cc
@@ -1,11 +1,11 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; c-set-offset 'innamespace 0; -*- */
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
 //
 //  ndn_stupidinterestgenerator_helper.cpp
 //  Abstraction
 //
 //  Created by Ilya Moiseenko on 05.08.11.
 //  Copyright 2011 UCLA. All rights reserved.
-//
+//w
 
 #include "ndn_stupidinterestgenerator_helper.h"
 #include "ns3/inet-socket-address.h"