bug 170
authorCraig Dowell <craigdo@ee.washington.edu>
Thu, 08 May 2008 11:16:12 -0700
changeset 3009 db5fab391eac
parent 3008 a6ff01929caf
child 3010 ad669f4f7e58
bug 170
src/helper/internet-stack-helper.cc
src/helper/internet-stack-helper.h
--- a/src/helper/internet-stack-helper.cc	Wed May 07 14:40:03 2008 -0700
+++ b/src/helper/internet-stack-helper.cc	Thu May 08 11:16:12 2008 -0700
@@ -25,12 +25,28 @@
 #include "ns3/internet-stack.h"
 #include "ns3/packet-socket-factory.h"
 #include "ns3/config.h"
+#include "ns3/simulator.h"
 
 namespace ns3 {
 
 std::vector<InternetStackHelper::Trace> InternetStackHelper::m_traces;
 std::string InternetStackHelper::m_pcapBaseFilename;
 
+void
+InternetStackHelper::Cleanup (void)
+{
+  uint32_t illegal = std::numeric_limits<uint32_t>::max();
+
+  for (std::vector<Trace>::iterator i = m_traces.begin ();
+       i != m_traces.end (); i++)
+  {
+    i->nodeId = illegal;
+    i->interfaceId = illegal;
+    i->writer = 0;
+  }
+  m_traces.clear ();
+}
+
 void 
 InternetStackHelper::Install (NodeContainer c)
 {
@@ -52,6 +68,8 @@
 void
 InternetStackHelper::EnablePcapAll (std::string filename)
 {
+  Simulator::ScheduleDestroy (&InternetStackHelper::Cleanup);
+
   InternetStackHelper::m_pcapBaseFilename = filename;
   Config::Connect ("/NodeList/*/$ns3::Ipv4L3Protocol/Tx",
                               MakeCallback (&InternetStackHelper::LogTxIp));
--- a/src/helper/internet-stack-helper.h	Wed May 07 14:40:03 2008 -0700
+++ b/src/helper/internet-stack-helper.h	Thu May 08 11:16:12 2008 -0700
@@ -49,10 +49,18 @@
    *
    * Enable pcap output on each protocol instance which is of the
    * ns3::Ipv4L3Protocol type.  Both Tx and Rx events will be logged.
+   *
+   * \warning If you perform multiple simulations in a single script,
+   * each iteration of the simulation will result in the trace files
+   * being overwritten.  We don't attempt to anticipate what a user
+   * might actually want to do, so we leave it up to them.  If you want
+   * to save any particular data, do so manually at inter-simulation 
+   * time.
    */
   static void EnablePcapAll (std::string filename);
 
 private:
+  static void Cleanup (void);
   static void LogRxIp (std::string context, Ptr<const Packet> packet, uint32_t deviceId);
   static void LogTxIp (std::string context, Ptr<const Packet> packet, uint32_t deviceId);
   static Ptr<PcapWriter> GetStream (uint32_t nodeId, uint32_t interfaceId);