New InterestHeader implementation (with a fake serialization for now)

diff --git a/model/interest-packet.cc b/model/interest-packet.cc
index 350095a..eecb753 100644
--- a/model/interest-packet.cc
+++ b/model/interest-packet.cc
@@ -18,70 +18,175 @@
  * Author: Ilya Moiseenko <iliamo@cs.ucla.edu>
  */
 
+///< #CCN_PR_SCOPE0 (0x20) local scope,
+///< #CCN_PR_SCOPE1 (0x40) this host,
+///< #CCN_PR_SCOPE2 (0x80) immediate neighborhood
+
+
 #include "interest-packet.h"
 
 namespace ns3
 {
 namespace NDNabstraction
 {
-  InterestPacket::InterestPacket ()
+
+  InterestHeader::InterestHeader ()
+    : m_minSuffixComponents (-1)
+    , m_maxSuffixComponents (-1)
+    , m_childSelector (false)
+    , m_answerOriginKind (false)
+    , m_scope (-1)
+    , m_interestLifetime (-1)
+    , m_nonce (0)
   {
   }
-  // InterestPacket::InterestPacket(const unsigned char *name, uint32_t size)
-  //   :Packet(name,size)
-  // {
-  //   maxNameLength = 10240;
-  // }
+
+  void
+  InterestHeader::SetName (const Ptr<Name::Components> &name)
+  {
+    m_name = name;
+  }
+
+  const Name::Components&
+  InterestHeader::GetName () const
+  {
+    return *m_name;
+  }
+
+  void
+  InterestHeader::SetMinSuffixComponents (int32_t value)
+  {
+    m_minSuffixComponents = value;
+  }
+
+  int32_t
+  InterestHeader::GetMinSuffixComponents () const
+  {
+    return m_minSuffixComponents;
+  }
+
+  void
+  InterestHeader::SetMaxSuffixComponents (int32_t value)
+  {
+    m_maxSuffixComponents = value;
+  }
+
+  int32_t
+  InterestHeader::GetMaxSuffixComponents () const
+  {
+    return m_maxSuffixComponents;
+  }
+
+  void
+  InterestHeader::SetExclude (const Ptr<Name::Components> &exclude)
+  {
+    m_exclude = exclude;
+  }
+
+  const Name::Components&
+  InterestHeader::GetExclude () const
+  {
+    return *m_exclude;
+  }
+
+  void
+  InterestHeader::EnableChildSelector ()
+  {
+    m_childSelector = true;
+  }
+
+  bool
+  InterestHeader::IsEnabledChildSelector () const
+  {
+    return m_childSelector;
+  }
+
+  void
+  InterestHeader::EnableAnswerOriginKind ()
+  {
+    m_answerOriginKind = true;
+  }
+
+  bool
+  InterestHeader::IsEnabledAnswerOriginKind () const
+  {
+    return m_answerOriginKind;
+  }
+
+  void
+  InterestHeader::SetScope (int8_t scope)
+  {
+    m_scope = scope;
+  }
+
+  int8_t
+  InterestHeader::GetScope () const
+  {
+    return m_scope;
+  }
+
+  void
+  InterestHeader::SetInterestLifetime (intmax_t lifetime)
+  {
+    m_interestLifetime = lifetime;
+  }
+
+  intmax_t
+  InterestHeader::GetInterestLifetime () const
+  {
+    return m_interestLifetime;
+  }
+
+  void
+  InterestHeader::SetNonce (uint32_t nonce)
+  {
+    m_nonce = nonce;
+  }
+
+  uint32_t
+  InterestHeader::GetNonce () const
+  {
+    return m_nonce;
+  }
+  
+  uint32_t
+  InterestHeader::GetSerializedSize (void) const
+  {
+    return 0;
+  }
     
-  // uint32_t 
-  // InterestPacket::GetName(unsigned char *name)
-  // {
-  //   //uint32_t Packet::CopyData (uint8_t *buffer, uint32_t size) const
-  //   return CopyData((uint8_t*) name, maxNameLength); 
-  // }
-    
-  // void 
-  // InterestPacket::AddTimeout(uint32_t milliseconds)
-  // {
-  //   TimeoutHeader tHeader (milliseconds);
-  //   AddHeader (tHeader);    
-  // }
-    
-  // uint32_t
-  // InterestPacket::GetTimeout(void)
-  // {
-  //   TimeoutHeader tHeader;
-  //   PeekHeader(tHeader);
-  //   return tHeader.GetValue();
-  // }
-    
-  // void
-  // InterestPacket::RemoveTimeout(void)
-  // {
-  //   TimeoutHeader tHeader;
-  //   RemoveHeader(tHeader);
-  // }
-    
-  // void 
-  // InterestPacket::AddNonce(uint32_t nonce)
-  // {
-  //   NonceHeader tHeader (nonce);
-  //   AddHeader (tHeader);
-  // }
-    
-  // uint32_t
-  // InterestPacket::GetNonce(void)
-  // {
-  //   NonceHeader tHeader;
-  //   PeekHeader(tHeader);
-  //   return tHeader.GetValue();
-  // }
-    
-  // void
-  // InterestPacket::RemoveNonce(void)
-  // {
-  //   NonceHeader tHeader;
-  //   RemoveHeader(tHeader);
-  // }
+  void
+  InterestHeader::Serialize (Buffer::Iterator start) const
+  {
+    return;
+  }
+
+  uint32_t
+  InterestHeader::Deserialize (Buffer::Iterator start)
+  {
+    return 0;
+  }
+
+  TypeId
+  InterestHeader::GetTypeId (void)
+  {
+    static TypeId tid = TypeId ("ns3::NDNabstraction::InterestHeader")
+      .SetParent<Header> ()
+      .AddConstructor<InterestHeader> ()
+      ;
+    return tid;
+  }
+  
+  TypeId
+  InterestHeader::GetInstanceTypeId (void) const
+  {
+    return GetTypeId ();
+  }
+  
+  void
+  InterestHeader::Print (std::ostream &os) const
+  {
+    os << "Interest: " << *m_name;
+  }
 }
 }
diff --git a/model/interest-packet.h b/model/interest-packet.h
index df04403..d4b2f9f 100644
--- a/model/interest-packet.h
+++ b/model/interest-packet.h
@@ -24,19 +24,213 @@
 //#define CCN_INTEREST_LIFETIME_SEC 4
 //#define CCN_INTEREST_LIFETIME_MICROSEC (CCN_INTEREST_LIFETIME_SEC * 1000000)
 
+#include <ns3/integer.h>
 #include <ns3/header.h>
 #include <ns3/packet.h>
+
 #include <string>
+#include <vector>
+#include <list>
+
+#include "name-components.h"
 
 namespace ns3
 {
 namespace NDNabstraction
 {
-  
-class InterestPacket : public Packet 
-{
-public:
-  InterestPacket( );
+
+/**
+ * CCNx XML definition of Interest
+ * 
+ * Only few important fields are actually implemented in the simulation
+ *
+ * <xs:element name="Interest" type="InterestType"/>
+ * <xs:complexType name="InterestType">
+ *   <xs:sequence>
+ *     <xs:element name="Name" type="NameType"/>
+ *     <xs:element name="MinSuffixComponents" type="xs:nonNegativeInteger"
+ *                         minOccurs="0" maxOccurs="1"/>
+ *     <xs:element name="MaxSuffixComponents" type="xs:nonNegativeInteger"
+ *                         minOccurs="0" maxOccurs="1"/>
+ *     <xs:choice minOccurs="0" maxOccurs="1">
+ *         <xs:element name="PublisherPublicKeyDigest" type="DigestType"/>
+ *         <xs:element name="PublisherCertificateDigest" type="DigestType"/>
+ *         <xs:element name="PublisherIssuerKeyDigest" type="DigestType"/>
+ *         <xs:element name="PublisherIssuerCertificateDigest" type="DigestType"/>
+ *     </xs:choice>
+ *     <xs:element name="Exclude" type="ExcludeType"
+ *                         minOccurs="0" maxOccurs="1"/>
+ *     <xs:element name="ChildSelector" type="xs:nonNegativeInteger"
+ *                         minOccurs="0" maxOccurs="1"/>
+ *     <xs:element name="AnswerOriginKind" type="xs:nonNegativeInteger"
+ *                         minOccurs="0" maxOccurs="1"/>
+ *     <xs:element name="Scope" type="xs:nonNegativeInteger"
+ * 			minOccurs="0" maxOccurs="1"/>
+ *     <xs:element name="InterestLifetime" type="FinegrainLifetimeType"
+ * 			minOccurs="0" maxOccurs="1"/>
+ *     <xs:element name="Nonce" type="Base64BinaryType"
+ * 			minOccurs="0" maxOccurs="1"/>
+ *   </xs:sequence>
+ * </xs:complexType>
+ *
+ * <xs:complexType name="NameType">
+ *   <xs:sequence>
+ *     <xs:element name="Component" type="Base64BinaryType"
+ *                 minOccurs="0" maxOccurs="unbounded"/>
+ *   </xs:sequence>
+ * </xs:complexType>
+ * 
+ * <xs:complexType name="ExcludeType">
+ *   <xs:sequence>
+ *     <xs:choice minOccurs="0" maxOccurs="1">
+ *         <xs:element name="Any" type="EmptyType"/>
+ *         <xs:element name="Bloom" type="Base64BinaryType"/> <!-- Bloom is deprecated --!>
+ *     </xs:choice>
+ *      <xs:sequence minOccurs="0" maxOccurs="unbounded">
+ *         <xs:element name="Component" type="Base64BinaryType"/>
+ *         <xs:choice minOccurs="0" maxOccurs="1">
+ *             <xs:element name="Any" type="EmptyType"/>
+ *             <xs:element name="Bloom" type="Base64BinaryType"/> <!-- Bloom is deprecated --!>
+ *         </xs:choice>
+ *      </xs:sequence>
+ *   </xs:sequence>
+ * </xs:complexType>
+ * 
+ * <!-- Binary representation of time, Unix time epoch, units 2**-12 sec (0.000244140625 sec) -->
+ * <!-- The length limit limit of 6 bytes is not actually to be enforced, but
+ *      it will be a loooooooong time before anyone cares. --> 
+ * 
+ * <!-- Binary representation of relative time, relative to "now" -->
+ * <xs:complexType name="FinegrainLifetimeType">
+ *   <xs:simpleContent>
+ *     <xs:extension base="BinaryTime12">
+ *       <xs:attribute name="ccnbencoding" type="xs:string" fixed="base64Binary"/>
+ *     </xs:extension>
+ *   </xs:simpleContent>
+ * </xs:complexType>
+ *
+ * <xs:simpleType name="BinaryTime12">
+ *     <xs:restriction base="xs:base64Binary">
+ *       <xs:length value="6" fixed="true"/>
+ *     </xs:restriction>
+ * </xs:simpleType>
+ *
+ **/
+
+  /**
+     NDN InterestPacket and routes to serialize/deserialize
+
+     Simplifications:
+     - Name:  binary name components are not supported
+     - MinSuffixComponents and MasSuffixComponents: if value is negative (default), will not be serialized
+     - ChildSelector, AnswerOriginKind: 0 - false, 1 - true, -1 not set
+     - Publisher* elements are not supported
+     - Exclude: only simple name matching is supported (Bloom support has been deprecated in CCNx)
+     - InterestLifetime: not used if negative
+     - Nonce: 32 bit random integer.  If value is 0, will not be serialized
+   */
+  class InterestHeader : public Header
+  {
+  public:
+    /**
+     * Constructor
+     *
+     * Creates a null header
+     **/
+    InterestHeader ();
+
+    /**
+     * \brief Set interest name
+     *
+     * Sets name of the interest. For example, SetName( Name::Components("prefix")("postfix") );
+     **/
+    void
+    SetName (const Ptr<Name::Components> &name);
+
+    const Name::Components&
+    GetName () const;
+
+    void
+    SetMinSuffixComponents (int32_t value);
+
+    int32_t
+    GetMinSuffixComponents () const;
+
+    void
+    SetMaxSuffixComponents (int32_t value);
+
+    int32_t
+    GetMaxSuffixComponents () const;
+
+    /**
+     * \brief Set exclude filer
+     *
+     * For example, SetExclude (Name::Components("exclude1")("exclude2")("exclude3"))
+     **/
+    void
+    SetExclude (const Ptr<Name::Components> &exclude);
+
+    const Name::Components&
+    GetExclude () const;
+
+    void
+    EnableChildSelector ();
+
+    bool
+    IsEnabledChildSelector () const;
+
+    void
+    EnableAnswerOriginKind ();
+
+    bool
+    IsEnabledAnswerOriginKind () const;
+
+    void
+    SetScope (int8_t scope);
+
+    int8_t
+    GetScope () const;
+
+    void
+    SetInterestLifetime (intmax_t lifetime);
+
+    intmax_t
+    GetInterestLifetime () const;
+
+    void
+    SetNonce (uint32_t nonce);
+
+    uint32_t
+    GetNonce () const;
+
+    //////////////////////////////////////////////////////////////////
+    
+    static TypeId GetTypeId (void);
+    virtual TypeId GetInstanceTypeId (void) const;
+    virtual void Print (std::ostream &os) const;
+    virtual uint32_t GetSerializedSize (void) const;
+    virtual void Serialize (Buffer::Iterator start) const;
+    virtual uint32_t Deserialize (Buffer::Iterator start);
+
+  private:
+    Ptr<Name::Components> m_name;
+    int32_t m_minSuffixComponents; ///< minimum suffix components. not used if negative
+    int32_t m_maxSuffixComponents; ///< maximum suffix components. not used if negative
+    Ptr<Name::Components> m_exclude; ///< exclude filter
+    bool m_childSelector;    
+    bool m_answerOriginKind; 
+    int8_t m_scope;            ///< -1 not set, 0 local scope, 1 this host, 2 immediate neighborhood
+    intmax_t m_interestLifetime; ///< InterestLifetime in 2^{-12} (0.000244140625 sec). not used if negative
+    uint32_t m_nonce; ///< Nonce. not used if zero
+  };
+
+
+  // Not sure that we need a separate NndPacket class. Everything useful will be inside (Interest|ContentObject)Header
+// class NdnPacket : public Packet 
+// {
+// public:
+//   NdnPacket( )
+    // ; 
   // InterestPacket (const unsigned char *name, uint32_t size);
   
           
@@ -52,7 +246,7 @@
       
   // uint32_t maxNameLength;
   
-};
+// };
   
 }
 }
diff --git a/model/name-builder.cc b/model/name-builder.cc
deleted file mode 100644
index 2ee432a..0000000
--- a/model/name-builder.cc
+++ /dev/null
@@ -1,66 +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 "name-builder.h"
-#include <ccn/ccn.h>
-
-using namespace std;
-
-namespace ns3 {
-namespace NDNabstraction {
-
-NameBuilder::NameBuilder ()
-{
-  m_value = ccn_charbuf_create ();
-  ccn_name_init(m_value);
-}
-
-NameBuilder::NameBuilder (const string &s)
-{
-  m_value = ccn_charbuf_create ();
-  ccn_name_init(m_value);
-  (*this) (s);
-}
-
-NameBuilder::~NameBuilder ()
-{
-  ccn_charbuf_destroy(&m_value);
-}
-
-const ccn_charbuf*
-NameBuilder::GetName () const
-{
-  return m_value;
-}
-
-NameBuilder&
-NameBuilder::operator () (const string &s)
-{
-  ccn_name_append_str (m_value,s.c_str());
-  return *this;
-}
-
-NameBuilder::operator const unsigned char* ()
-{
-  return m_value->buf;
-}
-  
-}
-}
diff --git a/model/name-builder.h b/model/name-builder.h
deleted file mode 100644
index 1198471..0000000
--- a/model/name-builder.h
+++ /dev/null
@@ -1,49 +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_NAMEBUILDER_H_
-#define _NDN_NAMEBUILDER_H_
-
-#include <string>
-
-class ccn_charbuf;
-
-namespace ns3 {
-namespace NDNabstraction {
-  
-class NameBuilder
-{
-public:
-  NameBuilder ();
-  NameBuilder (const std::string &s);
-  ~NameBuilder ();
-  
-  const ccn_charbuf* GetName () const;
-  NameBuilder& operator () (const std::string &s);
-
-  operator const unsigned char* ();
-private:
-  ccn_charbuf *m_value;
-};
-
-}
-}
-#endif // _NDN_NAMEBUILDER_H_
-
diff --git a/model/name-components.cc b/model/name-components.cc
new file mode 100644
index 0000000..f356a3b
--- /dev/null
+++ b/model/name-components.cc
@@ -0,0 +1,88 @@
+/* -*-  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 "name-components.h"
+#include "ccn/ccn.h"
+#include <iostream>
+
+using namespace std;
+
+namespace ns3 {
+namespace NDNabstraction {
+namespace Name {
+
+Components::Components ()
+{
+  // m_value = ccn_charbuf_create ();
+  // ccn_name_init(m_value);
+}
+
+Components::Components (const string &s)
+{
+  // m_value = ccn_charbuf_create ();
+  // ccn_name_init(m_value);
+  // (*this) (s);
+  m_prefix.push_back (s);
+}
+
+Components::~Components ()
+{
+  // ccn_charbuf_destroy(&m_value);
+}
+
+// const ccn_charbuf*
+// Components::GetName () const
+// {
+//   return m_value;
+// }
+
+Components&
+Components::operator () (const string &s)
+{
+  // ccn_name_append_str (m_value,s.c_str());
+  m_prefix.push_back (s);
+  return *this;
+}
+
+// Components::operator const unsigned char* ()
+// {
+//   return m_value->buf;
+// }
+
+void
+Components::Print (std::ostream &os) const
+{
+  for (const_iterator i=m_prefix.begin(); i!=m_prefix.end(); i++)
+    {
+      os << "/" << *i;
+    }
+}
+  
+std::ostream &
+operator << (std::ostream &os, const Components &components)
+{
+  components.Print (os);
+  return os;
+}
+
+}
+}
+}
+
diff --git a/model/name-components.h b/model/name-components.h
new file mode 100644
index 0000000..5c06bd9
--- /dev/null
+++ b/model/name-components.h
@@ -0,0 +1,67 @@
+/* -*-  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_NAME_COMPONENTS_H_
+#define _NDN_NAME_COMPONENTS_H_
+
+#include <string>
+#include <list>
+
+#include <ns3/simple-ref-count.h>
+
+namespace ns3 {
+namespace NDNabstraction {
+namespace Name {
+
+class Components : public SimpleRefCount<Components>
+{
+public:
+  Components ();
+  Components (const std::string &s);
+  ~Components ();
+  
+  Components& operator () (const std::string &s);
+  
+  // virtual uint32_t
+  // GetSerializedSize (void) const;
+
+  // virtual void
+  // Serialize (Buffer::Iterator start) const;
+
+  // virtual uint32_t
+  // Deserialize (Buffer::Iterator start);
+
+  void Print (std::ostream &os) const;
+  
+private:
+  std::list<std::string> m_prefix;
+
+  typedef std::list<std::string>::iterator iterator;
+  typedef std::list<std::string>::const_iterator const_iterator;
+};
+
+std::ostream & operator << (std::ostream &os, const Components &components);
+
+} // Namespace Name
+} // namespace NDNabstraction 
+} // namespace ns3
+
+#endif // _NDN_NAME_COMPONENTS_H_
+