From 418a3fae425b5024a146ce7883efde885e172567 Mon Sep 17 00:00:00 2001 From: Craig Dowell Date: Thu, 8 May 2008 11:16:12 -0700 Subject: [PATCH] bug 170 --- src/helper/internet-stack-helper.cc | 18 ++++++++++++++++++ src/helper/internet-stack-helper.h | 8 ++++++++ 2 files changed, 26 insertions(+) diff --git a/src/helper/internet-stack-helper.cc b/src/helper/internet-stack-helper.cc index 8285f29d8..8b6661bfb 100644 --- a/src/helper/internet-stack-helper.cc +++ b/src/helper/internet-stack-helper.cc @@ -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::m_traces; std::string InternetStackHelper::m_pcapBaseFilename; +void +InternetStackHelper::Cleanup (void) +{ + uint32_t illegal = std::numeric_limits::max(); + + for (std::vector::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 @@ InternetStackHelper::Install (NodeContainer c) void InternetStackHelper::EnablePcapAll (std::string filename) { + Simulator::ScheduleDestroy (&InternetStackHelper::Cleanup); + InternetStackHelper::m_pcapBaseFilename = filename; Config::Connect ("/NodeList/*/$ns3::Ipv4L3Protocol/Tx", MakeCallback (&InternetStackHelper::LogTxIp)); diff --git a/src/helper/internet-stack-helper.h b/src/helper/internet-stack-helper.h index 9241ee3a0..74f1054e0 100644 --- a/src/helper/internet-stack-helper.h +++ b/src/helper/internet-stack-helper.h @@ -49,10 +49,18 @@ public: * * 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 packet, uint32_t deviceId); static void LogTxIp (std::string context, Ptr packet, uint32_t deviceId); static Ptr GetStream (uint32_t nodeId, uint32_t interfaceId);