1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/common/ascii-writer.cc Fri Jul 03 11:44:03 2009 +0200
1.3 @@ -0,0 +1,92 @@
1.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
1.5 +/*
1.6 + * Copyright (c) 2009 Guillaume Seguin <guillaume@segu.in>
1.7 + *
1.8 + * This program is free software; you can redistribute it and/or modify
1.9 + * it under the terms of the GNU General Public License version 2 as
1.10 + * published by the Free Software Foundation;
1.11 + *
1.12 + * This program is distributed in the hope that it will be useful,
1.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.15 + * GNU General Public License for more details.
1.16 + *
1.17 + * You should have received a copy of the GNU General Public License
1.18 + * along with this program; if not, write to the Free Software
1.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1.20 + *
1.21 + * Author: Guillaume Seguin <guillaume@segu.in>
1.22 + */
1.23 +
1.24 +#include <fstream>
1.25 +
1.26 +#include "ns3/log.h"
1.27 +#include "ns3/assert.h"
1.28 +#include "ns3/abort.h"
1.29 +#include "ns3/simulator.h"
1.30 +#include "ascii-writer.h"
1.31 +
1.32 +NS_LOG_COMPONENT_DEFINE ("AsciiWriter");
1.33 +
1.34 +namespace ns3 {
1.35 +
1.36 +AsciiWriter::AsciiWritersMap AsciiWriter::m_writersMap;
1.37 +
1.38 +Ptr<AsciiWriter>
1.39 +AsciiWriter::Get (std::ostream &os)
1.40 +{
1.41 + Ptr<AsciiWriter> writer = m_writersMap[&os];
1.42 + if (writer == 0)
1.43 + {
1.44 + writer = Create<AsciiWriter> (&os);
1.45 + m_writersMap[&os] = writer;
1.46 + }
1.47 + return writer;
1.48 +}
1.49 +
1.50 +AsciiWriter::AsciiWriter (std::ostream *os)
1.51 + : m_writer (os),
1.52 + m_lastTs (0),
1.53 + m_lastContext (0),
1.54 + m_needsReordering (false)
1.55 +{
1.56 + NS_LOG_FUNCTION (this);
1.57 + NS_LOG_LOGIC ("m_writer = 0");
1.58 + pthread_mutexattr_t lock_attr;
1.59 + pthread_mutexattr_init (&lock_attr);
1.60 + pthread_mutex_init (&m_writerLock, &lock_attr);
1.61 +}
1.62 +
1.63 +AsciiWriter::~AsciiWriter (void)
1.64 +{
1.65 + NS_LOG_FUNCTION (this);
1.66 + pthread_mutex_destroy (&m_writerLock);
1.67 +
1.68 + if (m_needsReordering)
1.69 + {
1.70 + Reorder ();
1.71 + }
1.72 +}
1.73 +
1.74 +void
1.75 +AsciiWriter::Reorder (void)
1.76 +{
1.77 + NS_LOG_INFO ("Ascii trace reordering needed");
1.78 +}
1.79 +
1.80 +void
1.81 +AsciiWriter::WriteMessage (uint64_t ts, uint32_t context, std::string message)
1.82 +{
1.83 + NS_LOG_FUNCTION_NOARGS ();
1.84 + pthread_mutex_lock (&m_writerLock);
1.85 + if (ts < m_lastTs || (ts == m_lastTs && context < m_lastContext))
1.86 + {
1.87 + m_needsReordering = true;
1.88 + }
1.89 + m_lastTs = ts;
1.90 + m_lastContext = context;
1.91 + *m_writer << message;
1.92 + pthread_mutex_unlock (&m_writerLock);
1.93 +}
1.94 +
1.95 +} // namespace ns3
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/src/common/ascii-writer.h Fri Jul 03 11:44:03 2009 +0200
2.3 @@ -0,0 +1,74 @@
2.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2.5 +/*
2.6 + * Copyright (c) 2009 Guillaume Seguin <guillaume@segu.in>
2.7 + *
2.8 + * This program is free software; you can redistribute it and/or modify
2.9 + * it under the terms of the GNU General Public License version 2 as
2.10 + * published by the Free Software Foundation;
2.11 + *
2.12 + * This program is distributed in the hope that it will be useful,
2.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2.15 + * GNU General Public License for more details.
2.16 + *
2.17 + * You should have received a copy of the GNU General Public License
2.18 + * along with this program; if not, write to the Free Software
2.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2.20 + *
2.21 + * Author: Guillaume Seguin <guillaume@segu.in>
2.22 + */
2.23 +
2.24 +#ifndef ASCII_WRITER_H
2.25 +#define ASCII_WRITER_H
2.26 +
2.27 +#include <stdint.h>
2.28 +#include <pthread.h>
2.29 +#include "ns3/ref-count-base.h"
2.30 +
2.31 +#include <map>
2.32 +
2.33 +namespace ns3 {
2.34 +
2.35 +class Packet;
2.36 +
2.37 +/**
2.38 + * \ingroup common
2.39 + *
2.40 + * \brief Ascii output for Packet logger
2.41 + *
2.42 + * Log Packets to a file in pcap format which can be
2.43 + * read by pcap readers.
2.44 + */
2.45 +class AsciiWriter : public RefCountBase
2.46 +{
2.47 +public:
2.48 + static Ptr<AsciiWriter> Get (std::ostream &os);
2.49 +
2.50 + AsciiWriter (std::ostream *os);
2.51 + ~AsciiWriter (void);
2.52 +
2.53 + /**
2.54 + * Reorders ASCII traces.
2.55 + */
2.56 + void Reorder (void);
2.57 +
2.58 + /**
2.59 + * Writes a message in the output file, checking if the files will
2.60 + * need to be reordered.
2.61 + */
2.62 + void WriteMessage (uint64_t ts, uint32_t context, std::string message);
2.63 +
2.64 +private:
2.65 + std::ostream *m_writer;
2.66 + pthread_mutex_t m_writerLock;
2.67 + uint64_t m_lastTs;
2.68 + uint32_t m_lastContext;
2.69 + bool m_needsReordering;
2.70 +
2.71 + typedef std::map<std::ostream*, Ptr<AsciiWriter> > AsciiWritersMap;
2.72 + static AsciiWritersMap m_writersMap;
2.73 +};
2.74 +
2.75 +} // namespace ns3
2.76 +
2.77 +#endif /* ASCII_WRITER_H */
3.1 --- a/src/common/wscript Thu Jul 02 10:09:54 2009 +0200
3.2 +++ b/src/common/wscript Fri Jul 03 11:44:03 2009 +0200
3.3 @@ -11,6 +11,7 @@
3.4 'header.cc',
3.5 'trailer.cc',
3.6 'pcap-writer.cc',
3.7 + 'ascii-writer.cc',
3.8 'data-rate.cc',
3.9 'error-model.cc',
3.10 'tag.cc',
3.11 @@ -29,6 +30,7 @@
3.12 'packet.h',
3.13 'packet-metadata.h',
3.14 'pcap-writer.h',
3.15 + 'ascii-writer.h',
3.16 'data-rate.h',
3.17 'error-model.h',
3.18 'tag.h',
4.1 --- a/src/helper/csma-helper.cc Thu Jul 02 10:09:54 2009 +0200
4.2 +++ b/src/helper/csma-helper.cc Fri Jul 03 11:44:03 2009 +0200
4.3 @@ -23,7 +23,6 @@
4.4 #include "ns3/queue.h"
4.5 #include "ns3/csma-net-device.h"
4.6 #include "ns3/csma-channel.h"
4.7 -#include "ns3/pcap-writer.h"
4.8 #include "ns3/config.h"
4.9 #include "ns3/packet.h"
4.10 #include "ns3/names.h"
4.11 @@ -139,19 +138,20 @@
4.12 void
4.13 CsmaHelper::EnableAscii (std::ostream &os, uint32_t nodeid, uint32_t deviceid)
4.14 {
4.15 + Ptr<AsciiWriter> writer = AsciiWriter::Get (os);
4.16 Packet::EnablePrinting ();
4.17 std::ostringstream oss;
4.18 oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/MacRx";
4.19 - Config::Connect (oss.str (), MakeBoundCallback (&CsmaHelper::AsciiRxEvent, &os));
4.20 + Config::Connect (oss.str (), MakeBoundCallback (&CsmaHelper::AsciiRxEvent, writer));
4.21 oss.str ("");
4.22 oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/TxQueue/Enqueue";
4.23 - Config::Connect (oss.str (), MakeBoundCallback (&CsmaHelper::AsciiEnqueueEvent, &os));
4.24 + Config::Connect (oss.str (), MakeBoundCallback (&CsmaHelper::AsciiEnqueueEvent, writer));
4.25 oss.str ("");
4.26 oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/TxQueue/Dequeue";
4.27 - Config::Connect (oss.str (), MakeBoundCallback (&CsmaHelper::AsciiDequeueEvent, &os));
4.28 + Config::Connect (oss.str (), MakeBoundCallback (&CsmaHelper::AsciiDequeueEvent, writer));
4.29 oss.str ("");
4.30 oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/TxQueue/Drop";
4.31 - Config::Connect (oss.str (), MakeBoundCallback (&CsmaHelper::AsciiDropEvent, &os));
4.32 + Config::Connect (oss.str (), MakeBoundCallback (&CsmaHelper::AsciiDropEvent, writer));
4.33 }
4.34 void
4.35 CsmaHelper::EnableAscii (std::ostream &os, NetDeviceContainer d)
4.36 @@ -294,31 +294,43 @@
4.37 }
4.38
4.39 void
4.40 -CsmaHelper::AsciiEnqueueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet)
4.41 +CsmaHelper::AsciiEnqueueEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet)
4.42 {
4.43 - *os << "+ " << Simulator::Now ().GetSeconds () << " ";
4.44 - *os << path << " " << *packet << std::endl;
4.45 + uint32_t context = Simulator::GetContext ();
4.46 + std::ostringstream message;
4.47 + message << "+ " << Simulator::Now ().GetSeconds () << " " << context << " ";
4.48 + message << path << " " << *packet << std::endl;
4.49 + writer->WriteMessage ((uint64_t) Simulator::Now ().GetTimeStep (), context, message.str ());
4.50 }
4.51
4.52 void
4.53 -CsmaHelper::AsciiDequeueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet)
4.54 +CsmaHelper::AsciiDequeueEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet)
4.55 {
4.56 - *os << "- " << Simulator::Now ().GetSeconds () << " ";
4.57 - *os << path << " " << *packet << std::endl;
4.58 + uint32_t context = Simulator::GetContext ();
4.59 + std::ostringstream message;
4.60 + message << "- " << Simulator::Now ().GetSeconds () << " " << context << " ";
4.61 + message << path << " " << *packet << std::endl;
4.62 + writer->WriteMessage ((uint64_t) Simulator::Now ().GetTimeStep (), context, message.str ());
4.63 }
4.64
4.65 void
4.66 -CsmaHelper::AsciiDropEvent (std::ostream *os, std::string path, Ptr<const Packet> packet)
4.67 +CsmaHelper::AsciiDropEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet)
4.68 {
4.69 - *os << "d " << Simulator::Now ().GetSeconds () << " ";
4.70 - *os << path << " " << *packet << std::endl;
4.71 + uint32_t context = Simulator::GetContext ();
4.72 + std::ostringstream message;
4.73 + message << "d " << Simulator::Now ().GetSeconds () << " " << context << " ";
4.74 + message << path << " " << *packet << std::endl;
4.75 + writer->WriteMessage ((uint64_t) Simulator::Now ().GetTimeStep (), context, message.str ());
4.76 }
4.77
4.78 void
4.79 -CsmaHelper::AsciiRxEvent (std::ostream *os, std::string path, Ptr<const Packet> packet)
4.80 +CsmaHelper::AsciiRxEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet)
4.81 {
4.82 - *os << "r " << Simulator::Now ().GetSeconds () << " ";
4.83 - *os << path << " " << *packet << std::endl;
4.84 + uint32_t context = Simulator::GetContext ();
4.85 + std::ostringstream message;
4.86 + message << "r " << Simulator::Now ().GetSeconds () << " " << context << " ";
4.87 + message << path << " " << *packet << std::endl;
4.88 + writer->WriteMessage ((uint64_t) Simulator::Now ().GetTimeStep (), context, message.str ());
4.89 }
4.90
4.91 } // namespace ns3
5.1 --- a/src/helper/csma-helper.h Thu Jul 02 10:09:54 2009 +0200
5.2 +++ b/src/helper/csma-helper.h Fri Jul 03 11:44:03 2009 +0200
5.3 @@ -21,18 +21,18 @@
5.4 #define CSMA_HELPER_H
5.5
5.6 #include <string>
5.7 -#include <ostream>
5.8 #include "ns3/attribute.h"
5.9 #include "ns3/object-factory.h"
5.10 #include "ns3/net-device-container.h"
5.11 #include "ns3/node-container.h"
5.12 #include "ns3/csma-channel.h"
5.13 #include "ns3/deprecated.h"
5.14 +#include "ns3/pcap-writer.h"
5.15 +#include "ns3/ascii-writer.h"
5.16
5.17 namespace ns3 {
5.18
5.19 class Packet;
5.20 -class PcapWriter;
5.21
5.22 /**
5.23 * \brief build a set of CsmaNetDevice objects
5.24 @@ -353,10 +353,10 @@
5.25
5.26 static void SniffEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet);
5.27
5.28 - static void AsciiRxEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
5.29 - static void AsciiEnqueueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
5.30 - static void AsciiDequeueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
5.31 - static void AsciiDropEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
5.32 + static void AsciiRxEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet);
5.33 + static void AsciiEnqueueEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet);
5.34 + static void AsciiDequeueEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet);
5.35 + static void AsciiDropEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet);
5.36
5.37 ObjectFactory m_queueFactory;
5.38 ObjectFactory m_deviceFactory;
6.1 --- a/src/helper/internet-stack-helper.cc Thu Jul 02 10:09:54 2009 +0200
6.2 +++ b/src/helper/internet-stack-helper.cc Fri Jul 03 11:44:03 2009 +0200
6.3 @@ -257,16 +257,17 @@
6.4 void
6.5 InternetStackHelper::EnableAscii (std::ostream &os, NodeContainer n)
6.6 {
6.7 + Ptr<AsciiWriter> writer = AsciiWriter::Get (os);
6.8 Packet::EnablePrinting ();
6.9 std::ostringstream oss;
6.10 for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
6.11 {
6.12 Ptr<Node> node = *i;
6.13 oss << "/NodeList/" << node->GetId () << "/$ns3::Ipv4L3Protocol/Drop";
6.14 - Config::Connect (oss.str (), MakeBoundCallback (&InternetStackHelper::AsciiDropEvent, &os));
6.15 + Config::Connect (oss.str (), MakeBoundCallback (&InternetStackHelper::AsciiDropEvent, writer));
6.16 oss.str ("");
6.17 oss << "/NodeList/" << node->GetId () << "/$ns3::ArpL3Protocol/Drop";
6.18 - Config::Connect (oss.str (), MakeBoundCallback (&InternetStackHelper::AsciiDropEvent, &os));
6.19 + Config::Connect (oss.str (), MakeBoundCallback (&InternetStackHelper::AsciiDropEvent, writer));
6.20 oss.str ("");
6.21 }
6.22 }
6.23 @@ -344,10 +345,13 @@
6.24 }
6.25
6.26 void
6.27 -InternetStackHelper::AsciiDropEvent (std::ostream *os, std::string path, Ptr<const Packet> packet)
6.28 +InternetStackHelper::AsciiDropEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet)
6.29 {
6.30 - *os << "d " << Simulator::Now ().GetSeconds () << " ";
6.31 - *os << path << " " << *packet << std::endl;
6.32 + uint32_t context = Simulator::GetContext ();
6.33 + std::ostringstream message;
6.34 + message << "d " << Simulator::Now ().GetSeconds () << " " << context << " ";
6.35 + message << path << " " << *packet << std::endl;
6.36 + writer->WriteMessage ((uint64_t) Simulator::Now ().GetTimeStep (), context, message.str ());
6.37 }
6.38
6.39 } // namespace ns3
7.1 --- a/src/helper/internet-stack-helper.h Thu Jul 02 10:09:54 2009 +0200
7.2 +++ b/src/helper/internet-stack-helper.h Fri Jul 03 11:44:03 2009 +0200
7.3 @@ -24,6 +24,7 @@
7.4 #include "node-container.h"
7.5 #include "net-device-container.h"
7.6 #include "ns3/pcap-writer.h"
7.7 +#include "ns3/ascii-writer.h"
7.8 #include "ns3/packet.h"
7.9 #include "ns3/ptr.h"
7.10 #include "ns3/object-factory.h"
7.11 @@ -141,7 +142,7 @@
7.12 uint32_t interfaceId;
7.13 Ptr<PcapWriter> writer;
7.14 };
7.15 - static void AsciiDropEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
7.16 + static void AsciiDropEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet);
7.17 static std::string m_pcapBaseFilename;
7.18 static uint32_t GetNodeIndex (std::string context);
7.19 static std::vector<Trace> m_traces;
8.1 --- a/src/helper/point-to-point-helper.cc Thu Jul 02 10:09:54 2009 +0200
8.2 +++ b/src/helper/point-to-point-helper.cc Fri Jul 03 11:44:03 2009 +0200
8.3 @@ -22,7 +22,6 @@
8.4 #include "ns3/point-to-point-net-device.h"
8.5 #include "ns3/point-to-point-channel.h"
8.6 #include "ns3/queue.h"
8.7 -#include "ns3/pcap-writer.h"
8.8 #include "ns3/config.h"
8.9 #include "ns3/packet.h"
8.10 #include "ns3/names.h"
8.11 @@ -131,19 +130,20 @@
8.12 void
8.13 PointToPointHelper::EnableAscii (std::ostream &os, uint32_t nodeid, uint32_t deviceid)
8.14 {
8.15 + Ptr<AsciiWriter> writer = AsciiWriter::Get (os);
8.16 Packet::EnablePrinting ();
8.17 std::ostringstream oss;
8.18 oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::PointToPointNetDevice/MacRx";
8.19 - Config::Connect (oss.str (), MakeBoundCallback (&PointToPointHelper::AsciiRxEvent, &os));
8.20 + Config::Connect (oss.str (), MakeBoundCallback (&PointToPointHelper::AsciiRxEvent, writer));
8.21 oss.str ("");
8.22 oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::PointToPointNetDevice/TxQueue/Enqueue";
8.23 - Config::Connect (oss.str (), MakeBoundCallback (&PointToPointHelper::AsciiEnqueueEvent, &os));
8.24 + Config::Connect (oss.str (), MakeBoundCallback (&PointToPointHelper::AsciiEnqueueEvent, writer));
8.25 oss.str ("");
8.26 oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::PointToPointNetDevice/TxQueue/Dequeue";
8.27 - Config::Connect (oss.str (), MakeBoundCallback (&PointToPointHelper::AsciiDequeueEvent, &os));
8.28 + Config::Connect (oss.str (), MakeBoundCallback (&PointToPointHelper::AsciiDequeueEvent, writer));
8.29 oss.str ("");
8.30 oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::PointToPointNetDevice/TxQueue/Drop";
8.31 - Config::Connect (oss.str (), MakeBoundCallback (&PointToPointHelper::AsciiDropEvent, &os));
8.32 + Config::Connect (oss.str (), MakeBoundCallback (&PointToPointHelper::AsciiDropEvent, writer));
8.33 }
8.34
8.35 void
8.36 @@ -257,31 +257,43 @@
8.37 }
8.38
8.39 void
8.40 -PointToPointHelper::AsciiEnqueueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet)
8.41 +PointToPointHelper::AsciiEnqueueEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet)
8.42 {
8.43 - *os << "+ " << Simulator::Now ().GetSeconds () << " ";
8.44 - *os << path << " " << *packet << std::endl;
8.45 + uint32_t context = Simulator::GetContext ();
8.46 + std::ostringstream message;
8.47 + message << "+ " << Simulator::Now ().GetSeconds () << " " << context << " ";
8.48 + message << path << " " << *packet << std::endl;
8.49 + writer->WriteMessage ((uint64_t) Simulator::Now ().GetTimeStep (), context, message.str ());
8.50 }
8.51
8.52 void
8.53 -PointToPointHelper::AsciiDequeueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet)
8.54 +PointToPointHelper::AsciiDequeueEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet)
8.55 {
8.56 - *os << "- " << Simulator::Now ().GetSeconds () << " ";
8.57 - *os << path << " " << *packet << std::endl;
8.58 + uint32_t context = Simulator::GetContext ();
8.59 + std::ostringstream message;
8.60 + message << "- " << Simulator::Now ().GetSeconds () << " " << context << " ";
8.61 + message << path << " " << *packet << std::endl;
8.62 + writer->WriteMessage ((uint64_t) Simulator::Now ().GetTimeStep (), context, message.str ());
8.63 }
8.64
8.65 void
8.66 -PointToPointHelper::AsciiDropEvent (std::ostream *os, std::string path, Ptr<const Packet> packet)
8.67 +PointToPointHelper::AsciiDropEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet)
8.68 {
8.69 - *os << "d " << Simulator::Now ().GetSeconds () << " ";
8.70 - *os << path << " " << *packet << std::endl;
8.71 + uint32_t context = Simulator::GetContext ();
8.72 + std::ostringstream message;
8.73 + message << "d " << Simulator::Now ().GetSeconds () << " " << context << " ";
8.74 + message << path << " " << *packet << std::endl;
8.75 + writer->WriteMessage ((uint64_t) Simulator::Now ().GetTimeStep (), context, message.str ());
8.76 }
8.77
8.78 void
8.79 -PointToPointHelper::AsciiRxEvent (std::ostream *os, std::string path, Ptr<const Packet> packet)
8.80 +PointToPointHelper::AsciiRxEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet)
8.81 {
8.82 - *os << "r " << Simulator::Now ().GetSeconds () << " ";
8.83 - *os << path << " " << *packet << std::endl;
8.84 + uint32_t context = Simulator::GetContext ();
8.85 + std::ostringstream message;
8.86 + message << "r " << Simulator::Now ().GetSeconds () << " " << context << " ";
8.87 + message << path << " " << *packet << std::endl;
8.88 + writer->WriteMessage ((uint64_t) Simulator::Now ().GetTimeStep (), context, message.str ());
8.89 }
8.90
8.91 } // namespace ns3
9.1 --- a/src/helper/point-to-point-helper.h Thu Jul 02 10:09:54 2009 +0200
9.2 +++ b/src/helper/point-to-point-helper.h Fri Jul 03 11:44:03 2009 +0200
9.3 @@ -24,6 +24,8 @@
9.4 #include "ns3/net-device-container.h"
9.5 #include "ns3/node-container.h"
9.6 #include "ns3/deprecated.h"
9.7 +#include "ns3/pcap-writer.h"
9.8 +#include "ns3/ascii-writer.h"
9.9 #include <string>
9.10
9.11 namespace ns3 {
9.12 @@ -32,6 +34,7 @@
9.13 class NetDevice;
9.14 class Node;
9.15 class PcapWriter;
9.16 +class AsciiWriter;
9.17
9.18 /**
9.19 * \brief build a set of PointToPointNetDevice objects
9.20 @@ -286,10 +289,10 @@
9.21 static void SniffEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet);
9.22
9.23 void EnableAscii (Ptr<Node> node, Ptr<NetDevice> device);
9.24 - static void AsciiRxEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
9.25 - static void AsciiEnqueueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
9.26 - static void AsciiDequeueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
9.27 - static void AsciiDropEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
9.28 + static void AsciiRxEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet);
9.29 + static void AsciiEnqueueEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet);
9.30 + static void AsciiDequeueEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet);
9.31 + static void AsciiDropEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet);
9.32
9.33 ObjectFactory m_queueFactory;
9.34 ObjectFactory m_channelFactory;
10.1 --- a/src/helper/yans-wifi-helper.cc Thu Jul 02 10:09:54 2009 +0200
10.2 +++ b/src/helper/yans-wifi-helper.cc Fri Jul 03 11:44:03 2009 +0200
10.3 @@ -46,19 +46,27 @@
10.4 }
10.5
10.6
10.7 -static void AsciiPhyTxEvent (std::ostream *os, std::string context,
10.8 +static void AsciiPhyTxEvent (Ptr<AsciiWriter> writer, std::string path,
10.9 Ptr<const Packet> packet,
10.10 WifiMode mode, WifiPreamble preamble,
10.11 uint8_t txLevel)
10.12 {
10.13 - *os << "+ " << Simulator::Now () << " " << context << " " << *packet << std::endl;
10.14 + uint32_t context = Simulator::GetContext ();
10.15 + std::ostringstream message;
10.16 + message << "+ " << Simulator::Now ().GetSeconds () << " " << context << " ";
10.17 + message << path << " " << *packet << std::endl;
10.18 + writer->WriteMessage ((uint64_t) Simulator::Now ().GetTimeStep (), context, message.str ());
10.19 }
10.20
10.21 -static void AsciiPhyRxOkEvent (std::ostream *os, std::string context,
10.22 +static void AsciiPhyRxOkEvent (Ptr<AsciiWriter> writer, std::string path,
10.23 Ptr<const Packet> packet, double snr, WifiMode mode,
10.24 enum WifiPreamble preamble)
10.25 {
10.26 - *os << "r " << Simulator::Now () << " " << context << " " << *packet << std::endl;
10.27 + uint32_t context = Simulator::GetContext ();
10.28 + std::ostringstream message;
10.29 + message << "r " << Simulator::Now ().GetSeconds () << " " << context << " ";
10.30 + message << path << " " << *packet << std::endl;
10.31 + writer->WriteMessage ((uint64_t) Simulator::Now ().GetTimeStep (), context, message.str ());
10.32 }
10.33
10.34
10.35 @@ -309,13 +317,14 @@
10.36 void
10.37 YansWifiPhyHelper::EnableAscii (std::ostream &os, uint32_t nodeid, uint32_t deviceid)
10.38 {
10.39 + Ptr<AsciiWriter> writer = AsciiWriter::Get (os);
10.40 Packet::EnablePrinting ();
10.41 std::ostringstream oss;
10.42 oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/RxOk";
10.43 - Config::Connect (oss.str (), MakeBoundCallback (&AsciiPhyRxOkEvent, &os));
10.44 + Config::Connect (oss.str (), MakeBoundCallback (&AsciiPhyRxOkEvent, writer));
10.45 oss.str ("");
10.46 oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/Tx";
10.47 - Config::Connect (oss.str (), MakeBoundCallback (&AsciiPhyTxEvent, &os));
10.48 + Config::Connect (oss.str (), MakeBoundCallback (&AsciiPhyTxEvent, writer));
10.49 }
10.50 void
10.51 YansWifiPhyHelper::EnableAscii (std::ostream &os, NetDeviceContainer d)
11.1 --- a/src/helper/yans-wifi-helper.h Thu Jul 02 10:09:54 2009 +0200
11.2 +++ b/src/helper/yans-wifi-helper.h Fri Jul 03 11:44:03 2009 +0200
11.3 @@ -22,6 +22,8 @@
11.4
11.5 #include "wifi-helper.h"
11.6 #include "ns3/yans-wifi-channel.h"
11.7 +#include "ns3/pcap-writer.h"
11.8 +#include "ns3/ascii-writer.h"
11.9
11.10 namespace ns3 {
11.11