From 4fc3138b1ebd89612321f3aeb0e9448f82db0926 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Sun, 30 Mar 2008 21:05:50 -0700 Subject: [PATCH] Prepend ascii trace lines with action and time --- src/helper/csma-helper.cc | 33 +++++++++++++++++++++++++++++---- src/helper/csma-helper.h | 5 ++++- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/helper/csma-helper.cc b/src/helper/csma-helper.cc index 3698d5321..8da9b1722 100644 --- a/src/helper/csma-helper.cc +++ b/src/helper/csma-helper.cc @@ -1,4 +1,5 @@ #include "csma-helper.h" +#include "ns3/simulator.h" #include "ns3/object-factory.h" #include "ns3/queue.h" #include "ns3/csma-net-device.h" @@ -94,13 +95,16 @@ CsmaHelper::EnableAscii (std::ostream &os, uint32_t nodeid, uint32_t deviceid) Packet::EnableMetadata (); std::ostringstream oss; oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/Rx"; - Config::Connect (oss.str (), MakeBoundCallback (&CsmaHelper::AsciiEvent, &os)); + Config::Connect (oss.str (), MakeBoundCallback (&CsmaHelper::AsciiRxEvent, &os)); oss.str (""); oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/TxQueue/Enqueue"; - Config::Connect (oss.str (), MakeBoundCallback (&CsmaHelper::AsciiEvent, &os)); + Config::Connect (oss.str (), MakeBoundCallback (&CsmaHelper::AsciiEnqueueEvent, &os)); oss.str (""); oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/TxQueue/Dequeue"; - Config::Connect (oss.str (), MakeBoundCallback (&CsmaHelper::AsciiEvent, &os)); + Config::Connect (oss.str (), MakeBoundCallback (&CsmaHelper::AsciiDequeueEvent, &os)); + oss.str (""); + oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/TxQueue/Drop"; + Config::Connect (oss.str (), MakeBoundCallback (&CsmaHelper::AsciiDropEvent, &os)); } void CsmaHelper::EnableAscii (std::ostream &os, NetDeviceContainer d) @@ -169,10 +173,31 @@ CsmaHelper::RxEvent (Ptr writer, Ptr packet) writer->WritePacket (packet); } void -CsmaHelper::AsciiEvent (std::ostream *os, std::string path, Ptr packet) +CsmaHelper::AsciiEnqueueEvent (std::ostream *os, std::string path, Ptr packet) { + *os << "+ " << Simulator::Now ().GetSeconds () << " "; *os << path << " " << *packet << std::endl; } +void +CsmaHelper::AsciiDequeueEvent (std::ostream *os, std::string path, Ptr packet) +{ + *os << "- " << Simulator::Now ().GetSeconds () << " "; + *os << path << " " << *packet << std::endl; +} + +void +CsmaHelper::AsciiDropEvent (std::ostream *os, std::string path, Ptr packet) +{ + *os << "d " << Simulator::Now ().GetSeconds () << " "; + *os << path << " " << *packet << std::endl; +} + +void +CsmaHelper::AsciiRxEvent (std::ostream *os, std::string path, Ptr packet) +{ + *os << "r " << Simulator::Now ().GetSeconds () << " "; + *os << path << " " << *packet << std::endl; +} } // namespace ns3 diff --git a/src/helper/csma-helper.h b/src/helper/csma-helper.h index 91db6340d..892998116 100644 --- a/src/helper/csma-helper.h +++ b/src/helper/csma-helper.h @@ -92,7 +92,10 @@ public: private: static void RxEvent (Ptr writer, Ptr packet); static void EnqueueEvent (Ptr writer, Ptr packet); - static void AsciiEvent (std::ostream *os, std::string path, Ptr packet); + static void AsciiEnqueueEvent (std::ostream *os, std::string path, Ptr packet); + static void AsciiDequeueEvent (std::ostream *os, std::string path, Ptr packet); + static void AsciiDropEvent (std::ostream *os, std::string path, Ptr packet); + static void AsciiRxEvent (std::ostream *os, std::string path, Ptr packet); ObjectFactory m_queueFactory; ObjectFactory m_deviceFactory; ObjectFactory m_channelFactory;