use ascii writer

This commit is contained in:
Guillaume Seguin
2009-08-13 12:54:22 +02:00
parent c11373476e
commit 0ff784c41f
9 changed files with 98 additions and 102 deletions

View File

@@ -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 <string>
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<AsciiWriter> 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<PcapWriter> writer, Ptr<const Packet> packet)
}
void
CsmaHelper::AsciiEnqueueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet)
CsmaHelper::AsciiEnqueueEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> 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<const Packet> packet)
CsmaHelper::AsciiDequeueEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> 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<const Packet> packet)
CsmaHelper::AsciiDropEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> 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<const Packet> packet)
CsmaHelper::AsciiRxEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet)
{
*os << "r " << Simulator::Now ().GetSeconds () << " ";
*os << path << " " << *packet << std::endl;
writer->WritePacket (AsciiWriter::RX, path, packet);
}
} // namespace ns3

View File

@@ -21,7 +21,6 @@
#define CSMA_HELPER_H
#include <string>
#include <ostream>
#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<PcapWriter> writer, Ptr<const Packet> packet);
static void AsciiRxEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
static void AsciiEnqueueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
static void AsciiDequeueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
static void AsciiDropEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
static void AsciiRxEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet);
static void AsciiEnqueueEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet);
static void AsciiDequeueEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet);
static void AsciiDropEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet);
ObjectFactory m_queueFactory;
ObjectFactory m_deviceFactory;

View File

@@ -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<AsciiWriter> 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<PcapWriter> writer, Ptr<const Packet> packet)
writer->WritePacket (packet);
}
void
EmuHelper::AsciiEnqueueEvent (
std::ostream *os,
std::string path,
Ptr<const Packet> packet)
void
EmuHelper::AsciiEnqueueEvent (Ptr<AsciiWriter> writer,
std::string path,
Ptr<const Packet> 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<const Packet> packet)
void
EmuHelper::AsciiDequeueEvent (Ptr<AsciiWriter> writer,
std::string path,
Ptr<const Packet> 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<const Packet> packet)
void
EmuHelper::AsciiDropEvent (Ptr<AsciiWriter> writer,
std::string path,
Ptr<const Packet> 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<const Packet> packet)
void
EmuHelper::AsciiRxEvent (Ptr<AsciiWriter> writer,
std::string path,
Ptr<const Packet> 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

View File

@@ -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<NetDevice> InstallPriv (Ptr<Node> node) const;
static void SniffEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet);
static void AsciiRxEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
static void AsciiEnqueueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
static void AsciiDequeueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
static void AsciiDropEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
static void AsciiRxEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet);
static void AsciiEnqueueEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet);
static void AsciiDequeueEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet);
static void AsciiDropEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet);
ObjectFactory m_queueFactory;
ObjectFactory m_deviceFactory;

View File

@@ -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<AsciiWriter> writer = AsciiWriter::Get (os);
Packet::EnablePrinting ();
std::ostringstream oss;
for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
{
Ptr<Node> 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<const Packet> packet)
InternetStackHelper::AsciiDropEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet)
{
*os << "d " << Simulator::Now ().GetSeconds () << " ";
*os << path << " " << *packet << std::endl;
writer->WritePacket (AsciiWriter::DROP, path, packet);
}
} // namespace ns3

View File

@@ -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<PcapWriter> writer;
};
static void AsciiDropEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
static void AsciiDropEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet);
static std::string m_pcapBaseFilename;
static uint32_t GetNodeIndex (std::string context);
static std::vector<Trace> m_traces;

View File

@@ -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<AsciiWriter> 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<PcapWriter> writer, Ptr<const Packet> packet
writer->WritePacket (packet);
}
void
PointToPointHelper::AsciiEnqueueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet)
void
PointToPointHelper::AsciiEnqueueEvent (Ptr<AsciiWriter> writer, std::string path,
Ptr<const Packet> 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<const Packet> packet)
void
PointToPointHelper::AsciiDequeueEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> 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<const Packet> packet)
void
PointToPointHelper::AsciiDropEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> 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<const Packet> packet)
void
PointToPointHelper::AsciiRxEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet)
{
*os << "r " << Simulator::Now ().GetSeconds () << " ";
*os << path << " " << *packet << std::endl;
writer->WritePacket (AsciiWriter::RX, path, packet);
}
} // namespace ns3

View File

@@ -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<PcapWriter> writer, Ptr<const Packet> packet);
void EnableAscii (Ptr<Node> node, Ptr<NetDevice> device);
static void AsciiRxEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
static void AsciiEnqueueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
static void AsciiDequeueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
static void AsciiDropEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
static void AsciiRxEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet);
static void AsciiEnqueueEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet);
static void AsciiDequeueEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet);
static void AsciiDropEvent (Ptr<AsciiWriter> writer, std::string path, Ptr<const Packet> packet);
ObjectFactory m_queueFactory;
ObjectFactory m_channelFactory;

View File

@@ -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<PcapWriter> writer, Ptr<const Packet> packet,
}
static void AsciiPhyTxEvent (std::ostream *os, std::string context,
static void AsciiPhyTxEvent (Ptr<AsciiWriter> writer, std::string path,
Ptr<const Packet> 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<const Packet> packet, double snr, WifiMode mode,
static void AsciiPhyRxOkEvent (Ptr<AsciiWriter> writer, std::string path,
Ptr<const Packet> 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<AsciiWriter> 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)