merge with HEAD
This commit is contained in:
89
src/common/ascii-writer.cc
Normal file
89
src/common/ascii-writer.cc
Normal file
@@ -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 <guillaume@segu.in>
|
||||
*/
|
||||
#include "ascii-writer.h"
|
||||
|
||||
#include "ns3/log.h"
|
||||
#include "ns3/simulator.h"
|
||||
#include "ns3/simulation-singleton.h"
|
||||
#include "ns3/packet.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("AsciiWriter");
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
typedef std::map<std::ostream*, Ptr<AsciiWriter> > AsciiWritersMap;
|
||||
|
||||
Ptr<AsciiWriter>
|
||||
AsciiWriter::Get (std::ostream &os)
|
||||
{
|
||||
AsciiWritersMap *map = SimulationSingleton<AsciiWritersMap>::Get ();
|
||||
Ptr<AsciiWriter> writer = (*map)[&os];
|
||||
if (writer == 0)
|
||||
{
|
||||
// don't call Create<> because constructor is private
|
||||
writer = Ptr<AsciiWriter> (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<const Packet> 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
|
||||
67
src/common/ascii-writer.h
Normal file
67
src/common/ascii-writer.h
Normal file
@@ -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 <guilla...@segu.in>
|
||||
*/
|
||||
|
||||
#ifndef ASCII_WRITER_H
|
||||
#define ASCII_WRITER_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <ostream>
|
||||
#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<AsciiWriter> 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<const Packet> p);
|
||||
|
||||
private:
|
||||
AsciiWriter (std::ostream *os);
|
||||
|
||||
std::ostream *m_writer;
|
||||
};
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
#endif /* ASCII_WRITER_H */
|
||||
@@ -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',
|
||||
]
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user