Correcting GlobalRouting lookups.  Adding Ipv4SeqsAppTracer
diff --git a/helper/ccnx-trace-helper.cc b/helper/ccnx-trace-helper.cc
index 8a53928..1742462 100644
--- a/helper/ccnx-trace-helper.cc
+++ b/helper/ccnx-trace-helper.cc
@@ -39,6 +39,7 @@
 #include "tracers/ccnx-aggregate-l3-tracer.h"
 #include "tracers/ccnx-rate-l3-tracer.h"
 #include "tracers/ccnx-seqs-app-tracer.h"
+#include "tracers/ipv4-seqs-app-tracer.h"
 
 #include "ns3/ccnx-interest-header.h"
 #include "ns3/ccnx-content-object-header.h"
@@ -55,6 +56,7 @@
 CcnxTraceHelper::CcnxTraceHelper ()
   : m_l3RateTrace (0)
   , m_appSeqsTrace (0)
+  , m_ipv4AppSeqsTrace (0)
 {
 }
 
@@ -63,6 +65,7 @@
   NS_LOG_FUNCTION (this);
   if (m_l3RateTrace != 0) delete m_l3RateTrace;
   if (m_appSeqsTrace != 0) delete m_appSeqsTrace;
+  if (m_ipv4AppSeqsTrace != 0) delete m_ipv4AppSeqsTrace;
   
   if (m_apps.size () > 0)
     {
@@ -243,5 +246,45 @@
     }
 }
 
+void
+CcnxTraceHelper::EnableIpv4SeqsAppAll (const std::string &trace)
+{
+  NS_LOG_FUNCTION (this);
+  m_ipv4AppSeqsTrace = new ofstream (trace.c_str (), ios::trunc);
+
+  for (NodeList::Iterator node = NodeList::Begin ();
+       node != NodeList::End ();
+       node++)
+    {
+      ObjectVectorValue apps;
+      (*node)->GetAttribute ("ApplicationList", apps);
+
+      NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ()));
+      
+      uint32_t appId = 0;
+      for (ObjectVectorValue::Iterator app = apps.Begin ();
+           app != apps.End ();
+           app++, appId++)
+        {
+          NS_LOG_DEBUG ("App: " << lexical_cast<string> (appId) << ", typeId: " << (*app)->GetInstanceTypeId ().GetName ());
+          if ((*app)->GetInstanceTypeId ().GetName () == "ns3::PacketSink" ||
+              (*app)->GetInstanceTypeId ().GetName () == "ns3::BulkSendApplication")
+            {
+              Ptr<Ipv4SeqsAppTracer> trace = Create<Ipv4SeqsAppTracer> (boost::ref(*m_ipv4AppSeqsTrace),
+                                                                        *node,
+                                                                        lexical_cast<string> (appId));
+              m_ipv4AppSeqs.push_back (trace);
+            }
+        }
+      
+    }
+
+  if (m_ipv4AppSeqs.size () > 0)
+    {
+      m_ipv4AppSeqs.front ()->PrintHeader (*m_ipv4AppSeqsTrace);
+      *m_ipv4AppSeqsTrace << "\n";
+    }
+}
+
 
 } // namespace ns3
diff --git a/helper/ccnx-trace-helper.h b/helper/ccnx-trace-helper.h
index 7a5eaf1..4079f9c 100644
--- a/helper/ccnx-trace-helper.h
+++ b/helper/ccnx-trace-helper.h
@@ -30,6 +30,7 @@
 
 class CcnxAppTracer;
 class CcnxL3Tracer;
+class Ipv4AppTracer;
 
 class CcnxTraceHelper
 {
@@ -87,6 +88,12 @@
   void
   EnableSeqsAppAll (const std::string &app, const std::string &appSeqsTrace = "app-seqs.log");
 
+  /**
+   * @brief Enable app-level IPv4 sequence tracing on all nodes (BulkSender + PacketSink)
+   */
+  void
+  EnableIpv4SeqsAppAll (const std::string &appSeqsTrace = "app-seqs.log");
+  
 private:
   std::string m_appTrace;
   std::list<Ptr<CcnxAppTracer> > m_apps;
@@ -99,6 +106,9 @@
 
   std::list<Ptr<CcnxAppTracer> > m_appSeqs;
   std::ostream *m_appSeqsTrace;
+
+  std::list<Ptr<Ipv4AppTracer> > m_ipv4AppSeqs;
+  std::ostream *m_ipv4AppSeqsTrace;
 };
 
 
diff --git a/helper/tracers/ipv4-app-tracer.cc b/helper/tracers/ipv4-app-tracer.cc
new file mode 100644
index 0000000..57fb612
--- /dev/null
+++ b/helper/tracers/ipv4-app-tracer.cc
@@ -0,0 +1,70 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012 UCLA
+ *
+ * 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 "ipv4-app-tracer.h"
+#include "ns3/node.h"
+#include "ns3/packet.h"
+#include "ns3/config.h"
+#include "ns3/callback.h"
+#include "ns3/names.h"
+
+#include <boost/lexical_cast.hpp>
+
+using namespace std;
+using namespace boost;
+
+namespace ns3 {
+    
+Ipv4AppTracer::Ipv4AppTracer (Ptr<Node> node, const std::string &appId)
+  : m_appId (appId)
+  , m_nodePtr (node)
+{
+  m_node = boost::lexical_cast<string> (m_nodePtr->GetId ());
+
+  Connect ();
+
+  string name = Names::FindName (node);
+  if (!name.empty ())
+    {
+      m_node = name;
+    }
+}
+
+void
+Ipv4AppTracer::Connect ()
+{
+  Config::Connect ("/NodeList/"+m_node+"/$ns3::Ipv4L3Protocol/SendOutgoing",
+                   MakeCallback (&Ipv4AppTracer::Tx, this));
+
+  Config::Connect ("/NodeList/"+m_node+"/$ns3::Ipv4L3Protocol/LocalDeliver",
+                   MakeCallback (&Ipv4AppTracer::Rx, this));
+  
+  // Config::Connect ("/NodeList/"+m_node+"/$ns3::Ipv4L3Protocol/Tx",
+  //                  MakeCallback (&Ipv4AppTracer::Rx, this));
+
+  // Config::Connect ("/NodeList/"+m_node+"/ApplicationList/"+m_appId+"/$ns3::PacketSink/Rx",
+  //                  MakeCallback (&Ipv4AppTracer::InData, this));
+
+  // Config::Connect ("/NodeList/"+m_node+"/ApplicationList/"+m_appId+"/$ns3::BulkSendApplication/Tx",
+  //                  MakeCallback (&Ipv4AppTracer::OutData, this));
+}
+
+
+} // namespace ns3
diff --git a/helper/tracers/ipv4-app-tracer.h b/helper/tracers/ipv4-app-tracer.h
new file mode 100644
index 0000000..f24c6c3
--- /dev/null
+++ b/helper/tracers/ipv4-app-tracer.h
@@ -0,0 +1,74 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012 UCLA
+ *
+ * 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 IPV4_APP_TRACER_H
+#define IPV4_APP_TRACER_H
+
+#include "ns3/ptr.h"
+#include "ns3/simple-ref-count.h"
+#include "ns3/ipv4.h"
+
+namespace ns3 {
+
+class Ipv4Header;
+
+class Ipv4AppTracer : public SimpleRefCount<Ipv4AppTracer>
+{
+public:
+  Ipv4AppTracer (Ptr<Node> node, const std::string &appId = "*");
+  virtual ~Ipv4AppTracer ()  { };
+
+  void
+  Connect ();
+
+  virtual void
+  PrintHeader (std::ostream &os) const = 0;
+  
+  virtual void
+  Print (std::ostream &os) const = 0;
+
+  virtual void
+  Rx (std::string context,
+      const Ipv4Header &, Ptr<const Packet>, uint32_t) = 0;
+  
+  virtual void
+  Tx (std::string context,
+      const Ipv4Header &, Ptr<const Packet>, uint32_t) = 0;
+  
+protected:
+  std::string m_app;
+  std::string m_appId;
+  std::string m_node;
+  Ptr<Node> m_nodePtr;
+};
+
+inline std::ostream&
+operator << (std::ostream &os, const Ipv4AppTracer &tracer)
+{
+  os << "# ";
+  tracer.PrintHeader (os);
+  os << "\n";
+  tracer.Print (os);
+  return os;
+}
+
+} // namespace ns3
+
+#endif // IPV4_APP_TRACER_H
diff --git a/helper/tracers/ipv4-seqs-app-tracer.cc b/helper/tracers/ipv4-seqs-app-tracer.cc
new file mode 100644
index 0000000..3147ed0
--- /dev/null
+++ b/helper/tracers/ipv4-seqs-app-tracer.cc
@@ -0,0 +1,110 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 UCLA
+ *
+ * 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 "ipv4-seqs-app-tracer.h"
+#include "ns3/node.h"
+#include "ns3/packet.h"
+#include "ns3/config.h"
+#include "ns3/callback.h"
+#include "ns3/simulator.h"
+
+#include "ns3/tcp-l4-protocol.h"
+#include "ns3/tcp-header.h"
+#include "ns3/ipv4-header.h"
+
+namespace ns3 {
+    
+Ipv4SeqsAppTracer::Ipv4SeqsAppTracer (std::ostream &os, Ptr<Node> node, const std::string &appId)
+  : Ipv4AppTracer (node, appId)
+  , m_os (os)
+{
+}
+
+void
+Ipv4SeqsAppTracer::Reset ()
+{
+}
+
+void
+Ipv4SeqsAppTracer::PrintHeader (std::ostream &os) const
+{
+  os << "Time\t"
+     << "Node\t"
+     << "AppName\t"
+     << "AppId\t"
+     << "Type\t"
+     << "SeqNo";
+}
+
+void
+Ipv4SeqsAppTracer::Print (std::ostream &os) const
+{
+}
+
+#define PRINTER(type,size)                                         \
+ m_os                                                              \
+ << Simulator::Now ().ToDouble (Time::S) << "\t"                   \
+ << m_node << "\t"                                                 \
+ << m_app << "\t"                                                  \
+ << m_appId << "\t"                                                \
+ << type << "\t"                                                   \
+ << size / 1040.0 << std::endl;
+
+void
+Ipv4SeqsAppTracer::Tx (std::string context,
+    const Ipv4Header &ip, Ptr<const Packet>, uint32_t)
+{
+  if (ip.GetProtocol () != TcpL4Protocol::PROT_NUMBER) return;
+}
+
+void
+Ipv4SeqsAppTracer::Rx (std::string context,
+                       const Ipv4Header &ip, Ptr<const Packet> pktOrig, uint32_t)
+{
+  if (ip.GetProtocol () != TcpL4Protocol::PROT_NUMBER) return;
+
+  TcpHeader tcp;
+  Ptr<Packet> packet = pktOrig->Copy ();
+  packet->RemoveHeader (tcp);
+
+  if (tcp.GetFlags () | TcpHeader::ACK)
+    {
+      PRINTER("InAck", tcp.GetAckNumber ().GetValue ());
+    }
+}
+  
+
+// void
+// Ipv4SeqsAppTracer::InData (std::string context,
+//                            Ptr<const Packet> packet, const Address &address)
+// {
+//   PRINTER ("InData", m_inSeq);
+//   m_inSeq += packet->GetSize ();
+// }
+  
+// void
+// Ipv4SeqsAppTracer::OutData (std::string context,
+//                             Ptr<const Packet> packet)
+// {
+//   PRINTER ("OutData", m_outSeq);
+//   m_outSeq += packet->GetSize ();
+// }
+
+} // namespace ns3
diff --git a/helper/tracers/ipv4-seqs-app-tracer.h b/helper/tracers/ipv4-seqs-app-tracer.h
new file mode 100644
index 0000000..4805968
--- /dev/null
+++ b/helper/tracers/ipv4-seqs-app-tracer.h
@@ -0,0 +1,58 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 UCLA
+ *
+ * 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 IPV4_SEQS_APP_TRACER_H
+#define IPV4_SEQS_APP_TRACER_H
+
+#include "ns3/ipv4-app-tracer.h"
+
+namespace ns3 {
+
+class Ipv4SeqsAppTracer : public Ipv4AppTracer
+{
+public:
+  Ipv4SeqsAppTracer (std::ostream &os, Ptr<Node> node, const std::string &appId = "*");
+  virtual ~Ipv4SeqsAppTracer () { };
+
+  virtual void
+  PrintHeader (std::ostream &os) const;
+
+  virtual void
+  Print (std::ostream &os) const;
+
+  virtual void
+  Rx (std::string context,
+      const Ipv4Header &, Ptr<const Packet>, uint32_t);
+  
+  virtual void
+  Tx (std::string context,
+      const Ipv4Header &, Ptr<const Packet>, uint32_t);
+
+protected:
+  void
+  Reset ();
+
+protected:
+  std::ostream& m_os;
+};
+
+} // namespace ns3
+
+#endif // IPV4_AGGREGATE_APP_TRACER_H