Content ns3 packet

diff --git a/model/ccn_buf_encoder.cc b/model/ccn_buf_encoder.cc
index 54b58aa..34bd95d 100644
--- a/model/ccn_buf_encoder.cc
+++ b/model/ccn_buf_encoder.cc
@@ -43,3 +43,104 @@
   }
   return(ccn_charbuf_append(c, p, n));
 }
+
+
+/**
+ * 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;
+    //struct ccn_sigc *sig_ctx;
+    //struct ccn_signature *signature;
+    //size_t signature_size;
+    struct ccn_charbuf *content_header;
+    size_t closer_start;
+    
+    content_header = ccn_charbuf_create();
+    res |= ccn_charbuf_append_tt(content_header, CCN_DTAG_Content, CCN_DTAG);
+    if (size != 0)
+        res |= ccn_charbuf_append_tt(content_header, size, CCN_BLOB);
+    closer_start = content_header->length;
+    res |= ccn_charbuf_append_closer(content_header);
+    if (res < 0)
+        return(-1);
+    //sig_ctx = ccn_sigc_create();
+    //if (sig_ctx == NULL)
+    //    return(-1);
+    //if (0 != ccn_sigc_init(sig_ctx, digest_algorithm))
+    //    return(-1);
+    //if (0 != ccn_sigc_update(sig_ctx, Name->buf, Name->length))
+    //    return(-1);
+    //if (0 != ccn_sigc_update(sig_ctx, SignedInfo->buf, SignedInfo->length))
+    //    return(-1);
+    //if (0 != ccn_sigc_update(sig_ctx, content_header->buf, closer_start))
+    //    return(-1);
+    //if (0 != ccn_sigc_update(sig_ctx, data, size))
+    //    return(-1);
+    //if (0 != ccn_sigc_update(sig_ctx, content_header->buf + closer_start,
+    //                         content_header->length - closer_start))
+    //    return(-1);
+    //signature = calloc(1, ccn_sigc_signature_max_size(sig_ctx, private_key));
+    //if (signature == NULL)
+    //    return(-1);
+    //res = ccn_sigc_final(sig_ctx, signature, &signature_size, private_key);
+    //if (0 != res) {
+    //    free(signature);
+    //    return(-1);
+    //}
+    //ccn_sigc_destroy(&sig_ctx);
+    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/model/ccn_ccn.h b/model/ccn_ccn.h
index f5b9d86..319e546 100644
--- a/model/ccn_ccn.h
+++ b/model/ccn_ccn.h
@@ -15,15 +15,91 @@
 #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_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 ***********/
 
@@ -303,4 +379,9 @@
   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/model/ndn_contentpacket.cc b/model/ndn_contentpacket.cc
index 6d64497..bb9ff8d 100644
--- a/model/ndn_contentpacket.cc
+++ b/model/ndn_contentpacket.cc
@@ -6,3 +6,21 @@
 //
 
 #include "ndn_contentpacket.h"
+
+namespace ns3
+{
+namespace NDNabstraction
+{
+    ContentPacket::ContentPacket(const struct ccn_charbuf *Name,const void *data,size_t size):Packet()
+    {
+        ccn_charbuf *output = ccn_charbuf_create();
+        int result = ccn_encode_ContentObject(output,Name,data,size);
+        
+        if(result>=0)
+        {
+            Ptr<Packet> p = Create<Packet> (output->buf, (uint32_t)output->length);
+            this->AddAtEnd (p);
+        }
+    }
+}
+}
\ No newline at end of file
diff --git a/model/ndn_contentpacket.h b/model/ndn_contentpacket.h
index 1d5fe73..efd04bd 100644
--- a/model/ndn_contentpacket.h
+++ b/model/ndn_contentpacket.h
@@ -10,13 +10,20 @@
 
 #include "ns3/header.h"
 #include <ns3/packet.h>
+#include "ccn_ccn.h"
 
 namespace ns3
 {
-    class InterestPacket : public Packet 
+namespace NDNabstraction
+{
+    class ContentPacket : public Packet 
     {
+    public: 
+        ContentPacket(const struct ccn_charbuf *Name,const void *data,size_t size);
+
         
     };
 }
+}
 
 #endif 
\ No newline at end of file