Add an InternetStackHelper method to do ascii tracing on drop events
authorTom Henderson <tomh@tomh.org>
Fri, 07 Nov 2008 06:54:21 -0800 (2008-11-07)
changeset 3863 4222173d1e6d
parent 3862 ed0dfce40459
child 3864 6180d3afa1a6
Add an InternetStackHelper method to do ascii tracing on drop events
src/helper/internet-stack-helper.cc
src/helper/internet-stack-helper.h
--- a/src/helper/internet-stack-helper.cc	Fri Nov 07 07:35:35 2008 -0800
+++ b/src/helper/internet-stack-helper.cc	Fri Nov 07 06:54:21 2008 -0800
@@ -92,6 +92,29 @@
 }
 
 void
+InternetStackHelper::EnableAscii (std::ostream &os, NodeContainer n)
+{
+  Packet::EnablePrinting ();
+  std::ostringstream oss;
+  for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
+    {
+      Ptr<Node> node = *i;
+      oss << "/NodeList/" << node->GetId () << "/$ns3::Ipv4L3Protocol/Drop";
+      Config::Connect (oss.str (), MakeBoundCallback (&InternetStackHelper::AsciiDropEvent, &os));
+      oss.str ("");
+      oss << "/NodeList/" << node->GetId () << "/$ns3::ArpL3Protocol/Drop";
+      Config::Connect (oss.str (), MakeBoundCallback (&InternetStackHelper::AsciiDropEvent, &os));
+      oss.str ("");
+    }
+}
+
+void
+InternetStackHelper::EnableAsciiAll (std::ostream &os)
+{
+  EnableAscii (os, NodeContainer::GetGlobal ());
+}
+
+void
 InternetStackHelper::EnablePcapAll (std::string filename)
 {
   Simulator::ScheduleDestroy (&InternetStackHelper::Cleanup);
@@ -157,4 +180,11 @@
   return trace.writer;
 }
 
+void
+InternetStackHelper::AsciiDropEvent (std::ostream *os, std::string path, Ptr<const Packet> packet)
+{
+  *os << "d " << Simulator::Now ().GetSeconds () << " ";
+  *os << path << " " << *packet << std::endl;
+}
+
 } // namespace ns3
--- a/src/helper/internet-stack-helper.h	Fri Nov 07 07:35:35 2008 -0800
+++ b/src/helper/internet-stack-helper.h	Fri Nov 07 06:54:21 2008 -0800
@@ -70,6 +70,25 @@
   void SetNscStack(std::string soname);
 
   /**
+   * \param os output stream
+   * \param n node container
+   *
+   * Enable ascii output on these drop traces, for each node in the NodeContainer..
+   * /NodeList/[i]/$ns3ArpL3Protocol/Drop 
+   * /NodeList/[i]/$ns3Ipv4L3Protocol/Drop 
+   */
+  static void EnableAscii (std::ostream &os, NodeContainer n);
+
+  /**
+   * \param os output stream
+   *
+   * Enable ascii output on these drop traces, for all nodes.
+   * /NodeList/[i]/$ns3ArpL3Protocol/Drop 
+   * /NodeList/[i]/$ns3Ipv4L3Protocol/Drop 
+   */
+  static void EnableAsciiAll (std::ostream &os);
+
+  /**
    * Enable pcap output on each protocol instance which is of the
    * ns3::Ipv4L3Protocol type.  Both Tx and Rx events will be logged.
    *
@@ -95,6 +114,7 @@
     uint32_t interfaceId;
     Ptr<PcapWriter> writer;
   };
+  static void AsciiDropEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
   static std::string m_pcapBaseFilename;
   static uint32_t GetNodeIndex (std::string context);
   static std::vector<Trace> m_traces;