diff --git a/src/common/ascii-writer.cc b/src/common/ascii-writer.cc new file mode 100644 index 000000000..e00b6f485 --- /dev/null +++ b/src/common/ascii-writer.cc @@ -0,0 +1,89 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2009 INRIA + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Guillaume Seguin + */ +#include "ascii-writer.h" + +#include "ns3/log.h" +#include "ns3/simulator.h" +#include "ns3/simulation-singleton.h" +#include "ns3/packet.h" + +#include +#include + + +NS_LOG_COMPONENT_DEFINE ("AsciiWriter"); + +namespace ns3 { + +typedef std::map > AsciiWritersMap; + +Ptr +AsciiWriter::Get (std::ostream &os) +{ + AsciiWritersMap *map = SimulationSingleton::Get (); + Ptr writer = (*map)[&os]; + if (writer == 0) + { + // don't call Create<> because constructor is private + writer = Ptr (new AsciiWriter (&os), false); + (*map)[&os] = writer; + } + return writer; +} + +AsciiWriter::AsciiWriter (std::ostream *os) + : m_writer (os) +{ + NS_LOG_FUNCTION (this); +} + +AsciiWriter::~AsciiWriter (void) +{ + NS_LOG_FUNCTION (this); +} + +void +AsciiWriter::WritePacket (enum Type type, std::string message, Ptr packet) +{ + std::string typeString; + switch (type) + { + case ENQUEUE: + typeString = "+"; + break; + case DEQUEUE: + typeString = "-"; + break; + case RX: + typeString = "r"; + break; + case TX: + typeString = "t"; + break; + case DROP: + typeString = "d"; + break; + } + NS_LOG_FUNCTION (this << typeString << message); + *m_writer << typeString << " " << Simulator::Now ().GetSeconds () << " " + << message << " " << *packet << std::endl; +} + +} // namespace ns3 diff --git a/src/common/ascii-writer.h b/src/common/ascii-writer.h new file mode 100644 index 000000000..03cdc7cf4 --- /dev/null +++ b/src/common/ascii-writer.h @@ -0,0 +1,67 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2009 INRIA + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Guillaume Seguin + */ + +#ifndef ASCII_WRITER_H +#define ASCII_WRITER_H + +#include +#include +#include "ns3/ref-count-base.h" +#include "ns3/ptr.h" + +namespace ns3 { + +class Packet; + +/** + * \ingroup common + * + * \brief Ascii output + */ +class AsciiWriter : public RefCountBase +{ +public: + static Ptr Get (std::ostream &os); + + enum Type { + ENQUEUE, + DEQUEUE, + DROP, + TX, + RX + }; + + ~AsciiWriter (void); + + /** + * Writes a message in the output file, checking if the files will + * need to be reordered. + */ + void WritePacket (enum Type type, std::string message, Ptr p); + +private: + AsciiWriter (std::ostream *os); + + std::ostream *m_writer; +}; + +} // namespace ns3 + +#endif /* ASCII_WRITER_H */ diff --git a/src/common/wscript b/src/common/wscript index e8e028511..d6f0d8d09 100644 --- a/src/common/wscript +++ b/src/common/wscript @@ -17,6 +17,7 @@ def build(bld): 'byte-tag-list.cc', 'tag-buffer.cc', 'packet-tag-list.cc', + 'ascii-writer.cc', ] headers = bld.new_task_gen('ns3header') @@ -35,4 +36,5 @@ def build(bld): 'byte-tag-list.h', 'tag-buffer.h', 'packet-tag-list.h', + 'ascii-writer.h', ] diff --git a/src/helper/csma-helper.cc b/src/helper/csma-helper.cc index 34c55f143..234a75c2f 100644 --- a/src/helper/csma-helper.cc +++ b/src/helper/csma-helper.cc @@ -23,10 +23,11 @@ #include "ns3/queue.h" #include "ns3/csma-net-device.h" #include "ns3/csma-channel.h" -#include "ns3/pcap-writer.h" #include "ns3/config.h" #include "ns3/packet.h" #include "ns3/names.h" +#include "ns3/pcap-writer.h" +#include "ns3/ascii-writer.h" #include namespace ns3 { @@ -139,19 +140,20 @@ CsmaHelper::EnablePcapAll (std::string filename, bool promiscuous) void CsmaHelper::EnableAscii (std::ostream &os, uint32_t nodeid, uint32_t deviceid) { + Ptr writer = AsciiWriter::Get (os); Packet::EnablePrinting (); std::ostringstream oss; oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/MacRx"; - Config::Connect (oss.str (), MakeBoundCallback (&CsmaHelper::AsciiRxEvent, &os)); + Config::Connect (oss.str (), MakeBoundCallback (&CsmaHelper::AsciiRxEvent, writer)); oss.str (""); oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/TxQueue/Enqueue"; - Config::Connect (oss.str (), MakeBoundCallback (&CsmaHelper::AsciiEnqueueEvent, &os)); + Config::Connect (oss.str (), MakeBoundCallback (&CsmaHelper::AsciiEnqueueEvent, writer)); oss.str (""); oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/TxQueue/Dequeue"; - Config::Connect (oss.str (), MakeBoundCallback (&CsmaHelper::AsciiDequeueEvent, &os)); + Config::Connect (oss.str (), MakeBoundCallback (&CsmaHelper::AsciiDequeueEvent, writer)); oss.str (""); oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/TxQueue/Drop"; - Config::Connect (oss.str (), MakeBoundCallback (&CsmaHelper::AsciiDropEvent, &os)); + Config::Connect (oss.str (), MakeBoundCallback (&CsmaHelper::AsciiDropEvent, writer)); } void CsmaHelper::EnableAscii (std::ostream &os, NetDeviceContainer d) @@ -294,31 +296,27 @@ CsmaHelper::SniffEvent (Ptr writer, Ptr packet) } void -CsmaHelper::AsciiEnqueueEvent (std::ostream *os, std::string path, Ptr packet) +CsmaHelper::AsciiEnqueueEvent (Ptr writer, std::string path, Ptr packet) { - *os << "+ " << Simulator::Now ().GetSeconds () << " "; - *os << path << " " << *packet << std::endl; + writer->WritePacket (AsciiWriter::ENQUEUE, path, packet); } void -CsmaHelper::AsciiDequeueEvent (std::ostream *os, std::string path, Ptr packet) +CsmaHelper::AsciiDequeueEvent (Ptr writer, std::string path, Ptr packet) { - *os << "- " << Simulator::Now ().GetSeconds () << " "; - *os << path << " " << *packet << std::endl; + writer->WritePacket (AsciiWriter::DEQUEUE, path, packet); } void -CsmaHelper::AsciiDropEvent (std::ostream *os, std::string path, Ptr packet) +CsmaHelper::AsciiDropEvent (Ptr writer, std::string path, Ptr packet) { - *os << "d " << Simulator::Now ().GetSeconds () << " "; - *os << path << " " << *packet << std::endl; + writer->WritePacket (AsciiWriter::DROP, path, packet); } void -CsmaHelper::AsciiRxEvent (std::ostream *os, std::string path, Ptr packet) +CsmaHelper::AsciiRxEvent (Ptr writer, std::string path, Ptr packet) { - *os << "r " << Simulator::Now ().GetSeconds () << " "; - *os << path << " " << *packet << std::endl; + writer->WritePacket (AsciiWriter::RX, path, packet); } } // namespace ns3 diff --git a/src/helper/csma-helper.h b/src/helper/csma-helper.h index 4f6aa6025..490fb2923 100644 --- a/src/helper/csma-helper.h +++ b/src/helper/csma-helper.h @@ -21,7 +21,6 @@ #define CSMA_HELPER_H #include -#include #include "ns3/attribute.h" #include "ns3/object-factory.h" #include "ns3/net-device-container.h" @@ -33,6 +32,7 @@ namespace ns3 { class Packet; class PcapWriter; +class AsciiWriter; /** * \brief build a set of CsmaNetDevice objects @@ -353,10 +353,10 @@ private: static void SniffEvent (Ptr writer, Ptr packet); - static void AsciiRxEvent (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 (Ptr writer, std::string path, Ptr packet); + static void AsciiEnqueueEvent (Ptr writer, std::string path, Ptr packet); + static void AsciiDequeueEvent (Ptr writer, std::string path, Ptr packet); + static void AsciiDropEvent (Ptr writer, std::string path, Ptr packet); ObjectFactory m_queueFactory; ObjectFactory m_deviceFactory; diff --git a/src/helper/emu-helper.cc b/src/helper/emu-helper.cc index a5298834f..758a259f1 100644 --- a/src/helper/emu-helper.cc +++ b/src/helper/emu-helper.cc @@ -25,6 +25,7 @@ #include "ns3/queue.h" #include "ns3/emu-net-device.h" #include "ns3/pcap-writer.h" +#include "ns3/ascii-writer.h" #include "ns3/config.h" #include "ns3/packet.h" @@ -140,23 +141,24 @@ void EmuHelper::EnableAscii (std::ostream &os, uint32_t nodeid, uint32_t deviceid) { NS_LOG_FUNCTION (&os << nodeid << deviceid); + Ptr writer = AsciiWriter::Get (os); Packet::EnablePrinting (); std::ostringstream oss; oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::EmuNetDevice/MacRx"; - Config::Connect (oss.str (), MakeBoundCallback (&EmuHelper::AsciiRxEvent, &os)); + Config::Connect (oss.str (), MakeBoundCallback (&EmuHelper::AsciiRxEvent, writer)); oss.str (""); oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::EmuNetDevice/TxQueue/Enqueue"; - Config::Connect (oss.str (), MakeBoundCallback (&EmuHelper::AsciiEnqueueEvent, &os)); + Config::Connect (oss.str (), MakeBoundCallback (&EmuHelper::AsciiEnqueueEvent, writer)); oss.str (""); oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::EmuNetDevice/TxQueue/Dequeue"; - Config::Connect (oss.str (), MakeBoundCallback (&EmuHelper::AsciiDequeueEvent, &os)); + Config::Connect (oss.str (), MakeBoundCallback (&EmuHelper::AsciiDequeueEvent, writer)); oss.str (""); oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::EmuNetDevice/TxQueue/Drop"; - Config::Connect (oss.str (), MakeBoundCallback (&EmuHelper::AsciiDropEvent, &os)); + Config::Connect (oss.str (), MakeBoundCallback (&EmuHelper::AsciiDropEvent, writer)); } void @@ -238,48 +240,40 @@ EmuHelper::SniffEvent (Ptr writer, Ptr packet) writer->WritePacket (packet); } -void -EmuHelper::AsciiEnqueueEvent ( - std::ostream *os, - std::string path, - Ptr packet) +void +EmuHelper::AsciiEnqueueEvent (Ptr writer, + std::string path, + Ptr packet) { - NS_LOG_FUNCTION (&os << path << packet); - *os << "+ " << Simulator::Now ().GetSeconds () << " "; - *os << path << " " << *packet << std::endl; + NS_LOG_FUNCTION (writer << path << packet); + writer->WritePacket (AsciiWriter::ENQUEUE, path, packet); } -void -EmuHelper::AsciiDequeueEvent ( - std::ostream *os, - std::string path, - Ptr packet) +void +EmuHelper::AsciiDequeueEvent (Ptr writer, + std::string path, + Ptr packet) { - NS_LOG_FUNCTION (&os << path << packet); - *os << "- " << Simulator::Now ().GetSeconds () << " "; - *os << path << " " << *packet << std::endl; + NS_LOG_FUNCTION (writer << path << packet); + writer->WritePacket (AsciiWriter::DEQUEUE, path, packet); } -void -EmuHelper::AsciiDropEvent ( - std::ostream *os, - std::string path, - Ptr packet) +void +EmuHelper::AsciiDropEvent (Ptr writer, + std::string path, + Ptr packet) { - NS_LOG_FUNCTION (&os << path << packet); - *os << "d " << Simulator::Now ().GetSeconds () << " "; - *os << path << " " << *packet << std::endl; + NS_LOG_FUNCTION (writer << path << packet); + writer->WritePacket (AsciiWriter::DROP, path, packet); } -void -EmuHelper::AsciiRxEvent ( - std::ostream *os, - std::string path, - Ptr packet) +void +EmuHelper::AsciiRxEvent (Ptr writer, + std::string path, + Ptr packet) { - NS_LOG_FUNCTION (&os << path << packet); - *os << "r " << Simulator::Now ().GetSeconds () << " "; - *os << path << " " << *packet << std::endl; + NS_LOG_FUNCTION (writer << path << packet); + writer->WritePacket (AsciiWriter::RX, path, packet); } } // namespace ns3 diff --git a/src/helper/emu-helper.h b/src/helper/emu-helper.h index 2aeb297ec..8ea9a018e 100644 --- a/src/helper/emu-helper.h +++ b/src/helper/emu-helper.h @@ -31,6 +31,7 @@ namespace ns3 { class Packet; class PcapWriter; +class AsciiWriter; /** * \brief build a set of EmuNetDevice objects @@ -208,10 +209,10 @@ private: Ptr InstallPriv (Ptr node) const; static void SniffEvent (Ptr writer, Ptr packet); - static void AsciiRxEvent (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 (Ptr writer, std::string path, Ptr packet); + static void AsciiEnqueueEvent (Ptr writer, std::string path, Ptr packet); + static void AsciiDequeueEvent (Ptr writer, std::string path, Ptr packet); + static void AsciiDropEvent (Ptr writer, std::string path, Ptr packet); ObjectFactory m_queueFactory; ObjectFactory m_deviceFactory; diff --git a/src/helper/internet-stack-helper.cc b/src/helper/internet-stack-helper.cc index 03fc978ed..87dc99f44 100644 --- a/src/helper/internet-stack-helper.cc +++ b/src/helper/internet-stack-helper.cc @@ -161,6 +161,8 @@ #include "ns3/callback.h" #include "ns3/node.h" #include "ns3/core-config.h" +#include "ns3/pcap-writer.h" +#include "ns3/ascii-writer.h" #include "internet-stack-helper.h" #include "ipv4-list-routing-helper.h" #include "ipv4-static-routing-helper.h" @@ -279,16 +281,17 @@ InternetStackHelper::Install (std::string nodeName) const void InternetStackHelper::EnableAscii (std::ostream &os, NodeContainer n) { + Ptr writer = AsciiWriter::Get (os); Packet::EnablePrinting (); std::ostringstream oss; for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i) { Ptr node = *i; oss << "/NodeList/" << node->GetId () << "/$ns3::Ipv4L3Protocol/Drop"; - Config::Connect (oss.str (), MakeBoundCallback (&InternetStackHelper::AsciiDropEvent, &os)); + Config::Connect (oss.str (), MakeBoundCallback (&InternetStackHelper::AsciiDropEvent, writer)); oss.str (""); oss << "/NodeList/" << node->GetId () << "/$ns3::ArpL3Protocol/Drop"; - Config::Connect (oss.str (), MakeBoundCallback (&InternetStackHelper::AsciiDropEvent, &os)); + Config::Connect (oss.str (), MakeBoundCallback (&InternetStackHelper::AsciiDropEvent, writer)); oss.str (""); } } @@ -366,10 +369,9 @@ InternetStackHelper::GetStream (uint32_t nodeId, uint32_t interfaceId) } void -InternetStackHelper::AsciiDropEvent (std::ostream *os, std::string path, Ptr packet) +InternetStackHelper::AsciiDropEvent (Ptr writer, std::string path, Ptr packet) { - *os << "d " << Simulator::Now ().GetSeconds () << " "; - *os << path << " " << *packet << std::endl; + writer->WritePacket (AsciiWriter::DROP, path, packet); } } // namespace ns3 diff --git a/src/helper/internet-stack-helper.h b/src/helper/internet-stack-helper.h index 396b564d4..734096e43 100644 --- a/src/helper/internet-stack-helper.h +++ b/src/helper/internet-stack-helper.h @@ -23,7 +23,6 @@ #include "node-container.h" #include "net-device-container.h" -#include "ns3/pcap-writer.h" #include "ns3/packet.h" #include "ns3/ptr.h" #include "ns3/object-factory.h" @@ -169,7 +168,7 @@ private: uint32_t interfaceId; Ptr writer; }; - static void AsciiDropEvent (std::ostream *os, std::string path, Ptr packet); + static void AsciiDropEvent (Ptr writer, std::string path, Ptr packet); static std::string m_pcapBaseFilename; static uint32_t GetNodeIndex (std::string context); static std::vector m_traces; diff --git a/src/helper/point-to-point-helper.cc b/src/helper/point-to-point-helper.cc index e6f04b76f..d3d182e6d 100644 --- a/src/helper/point-to-point-helper.cc +++ b/src/helper/point-to-point-helper.cc @@ -22,10 +22,11 @@ #include "ns3/point-to-point-net-device.h" #include "ns3/point-to-point-channel.h" #include "ns3/queue.h" -#include "ns3/pcap-writer.h" #include "ns3/config.h" #include "ns3/packet.h" #include "ns3/names.h" +#include "ns3/pcap-writer.h" +#include "ns3/ascii-writer.h" namespace ns3 { @@ -131,19 +132,20 @@ PointToPointHelper::EnablePcapAll (std::string filename) void PointToPointHelper::EnableAscii (std::ostream &os, uint32_t nodeid, uint32_t deviceid) { + Ptr writer = AsciiWriter::Get (os); Packet::EnablePrinting (); std::ostringstream oss; oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::PointToPointNetDevice/MacRx"; - Config::Connect (oss.str (), MakeBoundCallback (&PointToPointHelper::AsciiRxEvent, &os)); + Config::Connect (oss.str (), MakeBoundCallback (&PointToPointHelper::AsciiRxEvent, writer)); oss.str (""); oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::PointToPointNetDevice/TxQueue/Enqueue"; - Config::Connect (oss.str (), MakeBoundCallback (&PointToPointHelper::AsciiEnqueueEvent, &os)); + Config::Connect (oss.str (), MakeBoundCallback (&PointToPointHelper::AsciiEnqueueEvent, writer)); oss.str (""); oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::PointToPointNetDevice/TxQueue/Dequeue"; - Config::Connect (oss.str (), MakeBoundCallback (&PointToPointHelper::AsciiDequeueEvent, &os)); + Config::Connect (oss.str (), MakeBoundCallback (&PointToPointHelper::AsciiDequeueEvent, writer)); oss.str (""); oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::PointToPointNetDevice/TxQueue/Drop"; - Config::Connect (oss.str (), MakeBoundCallback (&PointToPointHelper::AsciiDropEvent, &os)); + Config::Connect (oss.str (), MakeBoundCallback (&PointToPointHelper::AsciiDropEvent, writer)); } void @@ -256,32 +258,29 @@ PointToPointHelper::SniffEvent (Ptr writer, Ptr packet writer->WritePacket (packet); } -void -PointToPointHelper::AsciiEnqueueEvent (std::ostream *os, std::string path, Ptr packet) +void +PointToPointHelper::AsciiEnqueueEvent (Ptr writer, std::string path, + Ptr packet) { - *os << "+ " << Simulator::Now ().GetSeconds () << " "; - *os << path << " " << *packet << std::endl; + writer->WritePacket (AsciiWriter::ENQUEUE, path, packet); } -void -PointToPointHelper::AsciiDequeueEvent (std::ostream *os, std::string path, Ptr packet) +void +PointToPointHelper::AsciiDequeueEvent (Ptr writer, std::string path, Ptr packet) { - *os << "- " << Simulator::Now ().GetSeconds () << " "; - *os << path << " " << *packet << std::endl; + writer->WritePacket (AsciiWriter::DEQUEUE, path, packet); } -void -PointToPointHelper::AsciiDropEvent (std::ostream *os, std::string path, Ptr packet) +void +PointToPointHelper::AsciiDropEvent (Ptr writer, std::string path, Ptr packet) { - *os << "d " << Simulator::Now ().GetSeconds () << " "; - *os << path << " " << *packet << std::endl; + writer->WritePacket (AsciiWriter::DROP, path, packet); } -void -PointToPointHelper::AsciiRxEvent (std::ostream *os, std::string path, Ptr packet) +void +PointToPointHelper::AsciiRxEvent (Ptr writer, std::string path, Ptr packet) { - *os << "r " << Simulator::Now ().GetSeconds () << " "; - *os << path << " " << *packet << std::endl; + writer->WritePacket (AsciiWriter::RX, path, packet); } } // namespace ns3 diff --git a/src/helper/point-to-point-helper.h b/src/helper/point-to-point-helper.h index b55734e10..4edfa5499 100644 --- a/src/helper/point-to-point-helper.h +++ b/src/helper/point-to-point-helper.h @@ -32,6 +32,7 @@ class Queue; class NetDevice; class Node; class PcapWriter; +class AsciiWriter; /** * \brief build a set of PointToPointNetDevice objects @@ -286,10 +287,10 @@ private: static void SniffEvent (Ptr writer, Ptr packet); void EnableAscii (Ptr node, Ptr device); - static void AsciiRxEvent (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 (Ptr writer, std::string path, Ptr packet); + static void AsciiEnqueueEvent (Ptr writer, std::string path, Ptr packet); + static void AsciiDequeueEvent (Ptr writer, std::string path, Ptr packet); + static void AsciiDropEvent (Ptr writer, std::string path, Ptr packet); ObjectFactory m_queueFactory; ObjectFactory m_channelFactory; diff --git a/src/helper/yans-wifi-helper.cc b/src/helper/yans-wifi-helper.cc index 4848cb268..9af1ed6b2 100644 --- a/src/helper/yans-wifi-helper.cc +++ b/src/helper/yans-wifi-helper.cc @@ -25,6 +25,7 @@ #include "ns3/yans-wifi-phy.h" #include "ns3/wifi-net-device.h" #include "ns3/pcap-writer.h" +#include "ns3/ascii-writer.h" #include "ns3/simulator.h" #include "ns3/config.h" #include "ns3/names.h" @@ -46,19 +47,19 @@ static void PcapSniffRxEvent (Ptr writer, Ptr packet, } -static void AsciiPhyTxEvent (std::ostream *os, std::string context, +static void AsciiPhyTxEvent (Ptr writer, std::string path, Ptr packet, - WifiMode mode, WifiPreamble preamble, + WifiMode mode, WifiPreamble preamble, uint8_t txLevel) { - *os << "+ " << Simulator::Now () << " " << context << " " << *packet << std::endl; + writer->WritePacket (AsciiWriter::TX, path, packet); } -static void AsciiPhyRxOkEvent (std::ostream *os, std::string context, - Ptr packet, double snr, WifiMode mode, +static void AsciiPhyRxOkEvent (Ptr writer, std::string path, + Ptr packet, double snr, WifiMode mode, enum WifiPreamble preamble) { - *os << "r " << Simulator::Now () << " " << context << " " << *packet << std::endl; + writer->WritePacket (AsciiWriter::RX, path, packet); } @@ -307,13 +308,14 @@ YansWifiPhyHelper::EnablePcapAll (std::string filename) void YansWifiPhyHelper::EnableAscii (std::ostream &os, uint32_t nodeid, uint32_t deviceid) { + Ptr writer = AsciiWriter::Get (os); Packet::EnablePrinting (); std::ostringstream oss; oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/RxOk"; - Config::Connect (oss.str (), MakeBoundCallback (&AsciiPhyRxOkEvent, &os)); + Config::Connect (oss.str (), MakeBoundCallback (&AsciiPhyRxOkEvent, writer)); oss.str (""); oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/Tx"; - Config::Connect (oss.str (), MakeBoundCallback (&AsciiPhyTxEvent, &os)); + Config::Connect (oss.str (), MakeBoundCallback (&AsciiPhyTxEvent, writer)); } void YansWifiPhyHelper::EnableAscii (std::ostream &os, NetDeviceContainer d)