Correcting GlobalRouting lookups.  Adding Ipv4SeqsAppTracer
diff --git a/apps/ccnx-consumer.cc b/apps/ccnx-consumer.cc
index 44573b6..0010be2 100644
--- a/apps/ccnx-consumer.cc
+++ b/apps/ccnx-consumer.cc
@@ -230,8 +230,6 @@
 
   m_seqMax = floor(1.0 + size * 1024.0 * 1024.0 / m_payloadSize);
   NS_LOG_DEBUG ("MaxSeqNo: " << m_seqMax);
-
-  std::cout << "MaxSeqNo = " << m_seqMax << "\n";
 }
 
 
diff --git a/examples/congestion-pop.cc b/examples/congestion-pop.cc
index 2b30ae8..51a5fa0 100644
--- a/examples/congestion-pop.cc
+++ b/examples/congestion-pop.cc
@@ -55,6 +55,11 @@
 class Experiment
 {
 public:
+  Experiment ()
+    : m_rand (0,52)
+    , reader ("/sprint")
+  { }
+  
   void
   ConfigureCcnxTopology ()
   {
@@ -63,8 +68,6 @@
     string weights   ("./src/NDNabstraction/examples/sprint-pops.weights");
     string latencies ("./src/NDNabstraction/examples/sprint-pops.latencies");
     string positions ("./src/NDNabstraction/examples/sprint-pops.positions");
-    string strategy  ("ns3::CcnxBestRouteStrategy");
-    // string strategy ("ns3::CcnxFloodingStrategy");
   
     RocketfuelWeightsReader reader ("/sprint");
 
@@ -96,74 +99,25 @@
     stack.Install (reader.GetNodes ());
 
     reader.AssignIpv4Addresses (Ipv4Address ("10.0.0.0"));
-
+    
     // Install CCNx stack
     NS_LOG_INFO ("Installing CCNx stack");
     CcnxStackHelper ccnxHelper;
-    ccnxHelper.SetForwardingStrategy (strategy);
+    ccnxHelper.SetForwardingStrategy ("ns3::CcnxBestRouteStrategy");
     ccnxHelper.EnableLimits (true, Seconds(0.1));
     ccnxHelper.SetDefaultRoutes (false);
     ccnxHelper.InstallAll ();
-
-    // // Populate FIB based on IPv4 global routing controller
-    ccnxHelper.InstallFakeGlobalRoutes ();
-    ccnxHelper.InstallRoutesToAll ();
-
-    m_rand = UniformVariable (0, reader.GetNodes ().GetN());
   }
 
   void
-  ConfigureIpv4Topology ()
+  ConfigureRouting ()
   {
-    Names::Clear ();
-    
-    string weights   ("./src/NDNabstraction/examples/sprint-pops.weights");
-    string latencies ("./src/NDNabstraction/examples/sprint-pops.latencies");
-    string positions ("./src/NDNabstraction/examples/sprint-pops.positions");
-    string strategy  ("ns3::CcnxBestRouteStrategy");
-    // string strategy ("ns3::CcnxFloodingStrategy");
-  
-    RocketfuelWeightsReader reader ("/sprint");
-
-    reader.SetFileName (positions);
-    reader.SetFileType (RocketfuelWeightsReader::POSITIONS);
-    reader.Read ();
-  
-    reader.SetFileName (weights);
-    reader.SetFileType (RocketfuelWeightsReader::WEIGHTS);    
-    reader.Read ();
-
-    reader.SetFileName (latencies);
-    reader.SetFileType (RocketfuelWeightsReader::LATENCIES);    
-    reader.Read ();
-    
-    reader.Commit ();
-    NS_ASSERT_MSG (reader.LinksSize () != 0, "Problems reading the topology file. Failing.");
-    
-    NS_LOG_INFO("Nodes = " << reader.GetNodes ().GetN());
-    NS_LOG_INFO("Links = " << reader.LinksSize ());
-  
-    // ------------------------------------------------------------
-    // -- Read topology data.
-    // --------------------------------------------
-        
-    InternetStackHelper stack;
-    Ipv4GlobalRoutingHelper ipv4RoutingHelper;
-    stack.SetRoutingHelper (ipv4RoutingHelper);
-    stack.Install (reader.GetNodes ());
-
-    reader.AssignIpv4Addresses (Ipv4Address ("10.0.0.0"));
-
-    // Install CCNx stack
-    NS_LOG_INFO ("Installing CCNx stack");
     CcnxStackHelper ccnxHelper;
-    ccnxHelper.InstallFakeGlobalRoutesImpl ();
-    Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
-
-    m_rand = UniformVariable (0, reader.GetNodes ().GetN());
+    // // Populate FIB based on IPv4 global routing controller
+    ccnxHelper.InstallFakeGlobalRoutes ();
+    ccnxHelper.InstallRoutesToAll ();
   }
   
-  
   ApplicationContainer
   AddCcnxRandomApplications (uint16_t numStreams)
   {
@@ -210,53 +164,6 @@
     return apps;
   }
 
-  ApplicationContainer
-  AddTcpRandomApplications (uint16_t numStreams)
-  {
-    map<uint32_t, set<uint32_t> > streams;
-    ApplicationContainer apps;
-
-    const static uint32_t base_port = 1000;
-    uint16_t createdStreams = 0;
-    uint16_t guard = 0;
-    while (createdStreams < numStreams && guard < (numeric_limits<uint16_t>::max ()-1))
-      {
-        guard ++;
-        
-        uint32_t node1_num = m_rand.GetValue ();
-        uint32_t node2_num = m_rand.GetValue ();
-
-        if (node1_num == node2_num)
-          continue;
-
-        if (streams[node1_num].count (node2_num) > 0) // don't create duplicate streams
-          continue;
-        
-        streams[node1_num].insert (node2_num);
-
-        Ptr<Node> node1 = Names::Find<Node> ("/sprint", lexical_cast<string> (node1_num));
-        Ptr<Node> node2 = Names::Find<Node> ("/sprint", lexical_cast<string> (node2_num));
-
-        // to make sure we don't reuse the same port numbers for different flows, just make all port numbers unique
-        PacketSinkHelper consumerHelper ("ns3::TcpSocketFactory",
-                                         InetSocketAddress (Ipv4Address::GetAny (), base_port + createdStreams));
-
-        BulkSendHelper producerHelper ("ns3::TcpSocketFactory",
-                                       InetSocketAddress (Ipv4Address(node1->GetId ()), base_port + createdStreams));
-        producerHelper.SetAttribute ("MaxBytes", UintegerValue (2080000)); // equal to 2000 ccnx packets
-        
-        apps.Add
-          (consumerHelper.Install (node1));
-
-        apps.Add
-          (producerHelper.Install (node2));
-
-        createdStreams ++;
-      }
-
-    return apps;
-  }
-
   void
   Run (const Time &finishTime)
   {
@@ -269,6 +176,7 @@
   }
 
   UniformVariable m_rand;
+  RocketfuelWeightsReader reader;
 };
 
 
@@ -290,32 +198,29 @@
   for (uint32_t run = startRun; run < startRun + maxRuns; run++)
     {
       Config::SetGlobal ("RngRun", IntegerValue (run));
-      
+      cout << "seed = " << SeedManager::GetSeed () << ", run = " << SeedManager::GetRun () << endl;
+
       Experiment experiment;
       cout << "Run " << run << endl;
       
-      experiment.ConfigureTopology ();
-      // ApplicationContainer apps = experiment.AddCcnxRandomApplications (20);
-      ApplicationContainer apps = experiment.AddTcpRandomApplications (20);
+      experiment.ConfigureCcnxTopology ();
+      ApplicationContainer apps = experiment.AddCcnxRandomApplications (20);
+      experiment.ConfigureRouting ();
+  
+      string prefix = "run-" + lexical_cast<string> (run) + "-";
 
+      ofstream of_nodes ((prefix + "apps.log").c_str ());
       for (uint32_t i = 0; i < apps.GetN () / 2; i++) 
         {
-          cout << "From " << apps.Get (i*2)->GetNode ()->GetId ()
-               << " to "  << apps.Get (i*2 + 1)->GetNode ()->GetId ();
-          cout << "\n";
+          of_nodes << "From " << apps.Get (i*2)->GetNode ()->GetId ()
+                   << " to "  << apps.Get (i*2 + 1)->GetNode ()->GetId ();
+          of_nodes << "\n";
         }
-  
-      // CcnxTraceHelper traceHelper;
-      // traceHelper.EnableAggregateAppAll ("ns3::CcnxConsumer");
-      // traceHelper.EnableAggregateAppAll ("ns3::CcnxProducer");
-      // traceHelper.SetAppTraceFile (prefix + "trace-app.log");
+      of_nodes.close ();
 
-      // string prefix = "run-" + lexical_cast<string> (run) + "-";
-      
-      // traceHelper.EnableAggregateL3All ();
-      // traceHelper.SetL3TraceFile ("trace-l3.log");
-      // traceHelper.EnableRateL3All (prefix + "rate-trace.log");
-      // traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumer", prefix + "consumers-seqs.log");
+      CcnxTraceHelper traceHelper;
+      traceHelper.EnableRateL3All (prefix + "rate-trace.log");
+      traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumer", prefix + "consumers-seqs.log");
 
       experiment.Run (Seconds (200.0));
     }
diff --git a/examples/congestion-tcp-pop.cc b/examples/congestion-tcp-pop.cc
index 2b30ae8..c1ac443 100644
--- a/examples/congestion-tcp-pop.cc
+++ b/examples/congestion-tcp-pop.cc
@@ -28,6 +28,7 @@
 #include "ns3/random-variable.h"
 #include "ns3/internet-module.h"
 #include "ns3/applications-module.h"
+#include "ns3/config-store.h"
 
 #include <iostream>
 #include <sstream>
@@ -36,6 +37,8 @@
 #include <set>
 #include "ns3/rocketfuel-topology-reader.h"
 
+#include "../helper/tracers/ipv4-seqs-app-tracer.h"
+
 #include <boost/lexical_cast.hpp>
 #include <boost/foreach.hpp>
 
@@ -55,62 +58,10 @@
 class Experiment
 {
 public:
-  void
-  ConfigureCcnxTopology ()
-  {
-    Names::Clear ();
-    
-    string weights   ("./src/NDNabstraction/examples/sprint-pops.weights");
-    string latencies ("./src/NDNabstraction/examples/sprint-pops.latencies");
-    string positions ("./src/NDNabstraction/examples/sprint-pops.positions");
-    string strategy  ("ns3::CcnxBestRouteStrategy");
-    // string strategy ("ns3::CcnxFloodingStrategy");
-  
-    RocketfuelWeightsReader reader ("/sprint");
-
-    reader.SetFileName (positions);
-    reader.SetFileType (RocketfuelWeightsReader::POSITIONS);
-    reader.Read ();
-  
-    reader.SetFileName (weights);
-    reader.SetFileType (RocketfuelWeightsReader::WEIGHTS);    
-    reader.Read ();
-
-    reader.SetFileName (latencies);
-    reader.SetFileType (RocketfuelWeightsReader::LATENCIES);    
-    reader.Read ();
-    
-    reader.Commit ();
-    NS_ASSERT_MSG (reader.LinksSize () != 0, "Problems reading the topology file. Failing.");
-    
-    NS_LOG_INFO("Nodes = " << reader.GetNodes ().GetN());
-    NS_LOG_INFO("Links = " << reader.LinksSize ());
-  
-    // ------------------------------------------------------------
-    // -- Read topology data.
-    // --------------------------------------------
-        
-    InternetStackHelper stack;
-    Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops");
-    stack.SetRoutingHelper (ipv4RoutingHelper);
-    stack.Install (reader.GetNodes ());
-
-    reader.AssignIpv4Addresses (Ipv4Address ("10.0.0.0"));
-
-    // Install CCNx stack
-    NS_LOG_INFO ("Installing CCNx stack");
-    CcnxStackHelper ccnxHelper;
-    ccnxHelper.SetForwardingStrategy (strategy);
-    ccnxHelper.EnableLimits (true, Seconds(0.1));
-    ccnxHelper.SetDefaultRoutes (false);
-    ccnxHelper.InstallAll ();
-
-    // // Populate FIB based on IPv4 global routing controller
-    ccnxHelper.InstallFakeGlobalRoutes ();
-    ccnxHelper.InstallRoutesToAll ();
-
-    m_rand = UniformVariable (0, reader.GetNodes ().GetN());
-  }
+  Experiment ()
+    : m_rand (0,52)
+    , reader ("/sprint")
+  { }
 
   void
   ConfigureIpv4Topology ()
@@ -120,11 +71,7 @@
     string weights   ("./src/NDNabstraction/examples/sprint-pops.weights");
     string latencies ("./src/NDNabstraction/examples/sprint-pops.latencies");
     string positions ("./src/NDNabstraction/examples/sprint-pops.positions");
-    string strategy  ("ns3::CcnxBestRouteStrategy");
-    // string strategy ("ns3::CcnxFloodingStrategy");
   
-    RocketfuelWeightsReader reader ("/sprint");
-
     reader.SetFileName (positions);
     reader.SetFileType (RocketfuelWeightsReader::POSITIONS);
     reader.Read ();
@@ -142,81 +89,27 @@
     
     NS_LOG_INFO("Nodes = " << reader.GetNodes ().GetN());
     NS_LOG_INFO("Links = " << reader.LinksSize ());
-  
-    // ------------------------------------------------------------
-    // -- Read topology data.
-    // --------------------------------------------
-        
+
     InternetStackHelper stack;
-    Ipv4GlobalRoutingHelper ipv4RoutingHelper;
-    stack.SetRoutingHelper (ipv4RoutingHelper);
     stack.Install (reader.GetNodes ());
-
     reader.AssignIpv4Addresses (Ipv4Address ("10.0.0.0"));
+  }
 
-    // Install CCNx stack
-    NS_LOG_INFO ("Installing CCNx stack");
-    CcnxStackHelper ccnxHelper;
-    ccnxHelper.InstallFakeGlobalRoutesImpl ();
+  void
+  ConfigureRouting ()
+  {
     Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
 
-    m_rand = UniformVariable (0, reader.GetNodes ().GetN());
+    // m_rand = UniformVariable (0, reader.GetNodes ().GetN());
   }
   
-  
-  ApplicationContainer
-  AddCcnxRandomApplications (uint16_t numStreams)
-  {
-    map<uint32_t, set<uint32_t> > streams;
-    ApplicationContainer apps;
-    
-    uint16_t createdStreams = 0;
-    uint16_t guard = 0;
-    while (createdStreams < numStreams && guard < (numeric_limits<uint16_t>::max ()-1))
-      {
-        guard ++;
-        
-        uint32_t node1_num = m_rand.GetValue ();
-        uint32_t node2_num = m_rand.GetValue ();
-
-        if (node1_num == node2_num)
-          continue;
-
-        if (streams[node1_num].count (node2_num) > 0) // don't create duplicate streams
-          continue;
-        
-        streams[node1_num].insert (node2_num);
-
-        Ptr<Node> node1 = Names::Find<Node> ("/sprint", lexical_cast<string> (node1_num));
-        Ptr<Node> node2 = Names::Find<Node> ("/sprint", lexical_cast<string> (node2_num));
-
-        CcnxAppHelper consumerHelper ("ns3::CcnxConsumer");
-        consumerHelper.SetPrefix ("/" + lexical_cast<string> (node2->GetId ()));
-        consumerHelper.SetAttribute ("MeanRate", StringValue ("2Mbps"));
-        consumerHelper.SetAttribute ("Size", StringValue ("1.983642578125")); //to make sure max seq # is 2000
-
-        CcnxAppHelper producerHelper ("ns3::CcnxProducer");
-        producerHelper.SetPrefix ("/" + lexical_cast<string> (node2->GetId ()));
-        
-        apps.Add
-          (consumerHelper.Install (node1));
-
-        apps.Add
-          (producerHelper.Install (node2));
-
-        createdStreams ++;
-      }
-
-    return apps;
-  }
-
   ApplicationContainer
   AddTcpRandomApplications (uint16_t numStreams)
   {
     map<uint32_t, set<uint32_t> > streams;
     ApplicationContainer apps;
 
-    const static uint32_t base_port = 1000;
+    const static uint32_t base_port = 10;
     uint16_t createdStreams = 0;
     uint16_t guard = 0;
     while (createdStreams < numStreams && guard < (numeric_limits<uint16_t>::max ()-1))
@@ -237,13 +130,17 @@
         Ptr<Node> node1 = Names::Find<Node> ("/sprint", lexical_cast<string> (node1_num));
         Ptr<Node> node2 = Names::Find<Node> ("/sprint", lexical_cast<string> (node2_num));
 
+        Ptr<Ipv4> ipv4 = node1->GetObject<Ipv4> ();
+        // ipv4->GetAddress (0, 0);
+
         // to make sure we don't reuse the same port numbers for different flows, just make all port numbers unique
         PacketSinkHelper consumerHelper ("ns3::TcpSocketFactory",
                                          InetSocketAddress (Ipv4Address::GetAny (), base_port + createdStreams));
 
         BulkSendHelper producerHelper ("ns3::TcpSocketFactory",
-                                       InetSocketAddress (Ipv4Address(node1->GetId ()), base_port + createdStreams));
-        producerHelper.SetAttribute ("MaxBytes", UintegerValue (2080000)); // equal to 2000 ccnx packets
+                                       InetSocketAddress (ipv4->GetAddress (1, 0).GetLocal (), base_port + createdStreams));
+        // cout << "SendTo: " <<  ipv4->GetAddress (1, 0).GetLocal () << endl;
+        producerHelper.SetAttribute ("MaxBytes", UintegerValue (2081040)); // equal to 2001 ccnx packets
         
         apps.Add
           (consumerHelper.Install (node1));
@@ -269,17 +166,26 @@
   }
 
   UniformVariable m_rand;
+  RocketfuelWeightsReader reader;
 };
 
-
 int 
 main (int argc, char *argv[])
 {
   cout << "Begin congestion-pop scenario\n";
+  Packet::EnableChecking();
+  Packet::EnablePrinting();
   
   Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps"));
   Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20"));
+  Config::SetDefault ("ns3::TcpSocket::SegmentSize", StringValue ("1040"));
+  
+  Config::SetDefault ("ns3::BulkSendApplication::SendSize", StringValue ("1040"));
 
+  // Config::SetDefault ("ns3::ConfigStore::Filename", StringValue ("attributes.xml"));
+  // Config::SetDefault ("ns3::ConfigStore::Mode", StringValue ("Save"));
+  // Config::SetDefault ("ns3::ConfigStore::FileFormat", StringValue ("Xml"));
+  
   uint32_t maxRuns = 1;
   uint32_t startRun = 0;
   CommandLine cmd;
@@ -287,35 +193,35 @@
   cmd.AddValue ("runs", "Number of runs", maxRuns);
   cmd.Parse (argc, argv);
 
+  // ConfigStore config;
+  // config.ConfigureDefaults ();
+
   for (uint32_t run = startRun; run < startRun + maxRuns; run++)
     {
       Config::SetGlobal ("RngRun", IntegerValue (run));
+      cout << "seed = " << SeedManager::GetSeed () << ", run = " << SeedManager::GetRun () << endl;
       
       Experiment experiment;
       cout << "Run " << run << endl;
       
-      experiment.ConfigureTopology ();
-      // ApplicationContainer apps = experiment.AddCcnxRandomApplications (20);
+      experiment.ConfigureIpv4Topology ();
       ApplicationContainer apps = experiment.AddTcpRandomApplications (20);
+      experiment.ConfigureRouting ();
 
+      string prefix = "run-tcp-" + lexical_cast<string> (run) + "-";      
+
+      ofstream of_nodes ((prefix + "apps.log").c_str ());
       for (uint32_t i = 0; i < apps.GetN () / 2; i++) 
         {
-          cout << "From " << apps.Get (i*2)->GetNode ()->GetId ()
-               << " to "  << apps.Get (i*2 + 1)->GetNode ()->GetId ();
-          cout << "\n";
+          of_nodes << "From " << apps.Get (i*2)->GetNode ()->GetId ()
+                   << " to "  << apps.Get (i*2 + 1)->GetNode ()->GetId ();
+          of_nodes << "\n";
         }
-  
-      // CcnxTraceHelper traceHelper;
-      // traceHelper.EnableAggregateAppAll ("ns3::CcnxConsumer");
-      // traceHelper.EnableAggregateAppAll ("ns3::CcnxProducer");
-      // traceHelper.SetAppTraceFile (prefix + "trace-app.log");
 
-      // string prefix = "run-" + lexical_cast<string> (run) + "-";
-      
-      // traceHelper.EnableAggregateL3All ();
-      // traceHelper.SetL3TraceFile ("trace-l3.log");
-      // traceHelper.EnableRateL3All (prefix + "rate-trace.log");
-      // traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumer", prefix + "consumers-seqs.log");
+      CcnxTraceHelper traceHelper;
+      traceHelper.EnableIpv4SeqsAppAll (prefix + "consumers-seqs.log");
+
+      // config.ConfigureAttributes ();  
 
       experiment.Run (Seconds (200.0));
     }
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
diff --git a/utils/ipv4-global-routing-ordered-nexthops.cc b/utils/ipv4-global-routing-ordered-nexthops.cc
index a01c044..f206a69 100644
--- a/utils/ipv4-global-routing-ordered-nexthops.cc
+++ b/utils/ipv4-global-routing-ordered-nexthops.cc
@@ -110,9 +110,18 @@
 {
   NS_LOG_FUNCTION (this << dest << oif);
 
-  Ipv4AddressTrieMap::const_iterator longest_prefix_map = m_routes.longest_prefix_match (dest);
+  // Cheating with lookups. Need to redesign Trie
+  Ipv4AddressTrieMap::const_iterator longest_prefix_map;
+  Ipv4Mask mask ("255.255.255.255");
+  do {
+    NS_LOG_DEBUG ("Try mask " << mask);
+    longest_prefix_map = m_routes.longest_prefix_match (dest.CombineMask (mask));
+    mask = Ipv4Mask (mask.Get () << 8);
+  } while (longest_prefix_map == m_routes.end () && !mask.IsEqual (Ipv4Mask::GetZero ()));
+
   if (longest_prefix_map == m_routes.end ())
     {
+      NS_LOG_LOGIC ("Route not found...");
       return 0;
     }
 
diff --git a/utils/ipv4-global-routing-unordered-nexthops.cc b/utils/ipv4-global-routing-unordered-nexthops.cc
index 0fdce0b..a4f3660 100644
--- a/utils/ipv4-global-routing-unordered-nexthops.cc
+++ b/utils/ipv4-global-routing-unordered-nexthops.cc
@@ -141,9 +141,18 @@
   NS_ASSERT_MSG (entryNum < m_numLogicalEntries,
                "Number of requested logical entry should be smaller than total number of logical entries");
   
-  Ipv4AddressTrieMap::const_iterator longest_prefix_map = m_routes.longest_prefix_match (dest);
+  // Cheating with lookups. Need to redesign Trie
+  Ipv4AddressTrieMap::const_iterator longest_prefix_map;
+  Ipv4Mask mask ("255.255.255.255");
+  do {
+    NS_LOG_DEBUG ("Try mask " << mask);
+    longest_prefix_map = m_routes.longest_prefix_match (dest.CombineMask (mask));
+    mask = Ipv4Mask (mask.Get () << 8);
+  } while (longest_prefix_map == m_routes.end () && !mask.IsEqual (Ipv4Mask::GetZero ()));
+
   if (longest_prefix_map == m_routes.end ())
     {
+      NS_LOG_LOGIC ("Route not found...");
       return 0;
     }
 
diff --git a/wscript b/wscript
index 0d5d736..fcfd524 100644
--- a/wscript
+++ b/wscript
@@ -58,6 +58,7 @@
         "helper/ccnx-app-helper.h",
         "helper/ccnx-header-helper.h",
         "helper/ccnx-trace-helper.h",
+        "helper/tracers/ipv4-app-tracer.h",
         "helper/tracers/ccnx-app-tracer.h",
         "helper/tracers/ccnx-l3-tracer.h",
         "helper/ccnx-face-container.h",