Implement forgotten Timestamp and Nonce visitors and appropriate
InterestDecoding routines

Need to check whether timestamp parsing actually works
diff --git a/helper/ccnb-parser/visitors/ccnb-parser-interest-visitor.cc b/helper/ccnb-parser/visitors/ccnb-parser-interest-visitor.cc
index ccb40b2..70578e7 100644
--- a/helper/ccnb-parser/visitors/ccnb-parser-interest-visitor.cc
+++ b/helper/ccnb-parser/visitors/ccnb-parser-interest-visitor.cc
@@ -24,8 +24,13 @@
 #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>
 
@@ -41,6 +46,8 @@
 
   static NonNegativeIntegerVisitor nonNegativeIntegerVisitor;
   static NameComponentsVisitor     nameComponentsVisitor;
+  static TimestampVisitor          timestampVisitor;
+  static NonceVisitor              nonceVisitor;
   
   CcnxInterestHeader &interest = boost::any_cast<CcnxInterestHeader&> (param);
   
@@ -127,13 +134,21 @@
       if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag
         throw CcnbDecodingException ();
 
-      /// \todo Decode InterestLifetime
+      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 ();
 
-      /// \todo Decode Nonce
+      interest.SetNonce (
+               boost::any_cast<uint32_t> (
+                                          (*n.m_nestedTags.begin())->accept(
+                                                                           nonceVisitor
+                                                                           )));
       break;
     }
 }
diff --git a/helper/ccnb-parser/visitors/ccnb-parser-interest-visitor.h b/helper/ccnb-parser/visitors/ccnb-parser-interest-visitor.h
index e2cc574..136b173 100644
--- a/helper/ccnb-parser/visitors/ccnb-parser-interest-visitor.h
+++ b/helper/ccnb-parser/visitors/ccnb-parser-interest-visitor.h
@@ -22,8 +22,6 @@
 #define _CCNB_PARSER_INTEREST_VISITOR_H_
 
 #include "ccnb-parser-void-depth-first-visitor.h"
-#include "ccnb-parser-name-components-visitor.h"
-#include "ccnb-parser-non-negative-integer-visitor.h"
 
 namespace ns3 {
 namespace CcnbParser {
diff --git a/helper/ccnb-parser/visitors/ccnb-parser-nonce-visitor.cc b/helper/ccnb-parser/visitors/ccnb-parser-nonce-visitor.cc
new file mode 100644
index 0000000..7492adf
--- /dev/null
+++ b/helper/ccnb-parser/visitors/ccnb-parser-nonce-visitor.cc
@@ -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>
+ */
+
+#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/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_