Added tracing support to simple.tcl.cc (Craig)
This commit is contained in:
@@ -36,9 +36,38 @@
|
||||
#include "ns3/udp-socket.h"
|
||||
#include "ns3/ipv4-route.h"
|
||||
#include "ns3/drop-tail.h"
|
||||
#include "ns3/trace-writer.h"
|
||||
|
||||
using namespace ns3;
|
||||
|
||||
class Tracer : public TraceWriter{
|
||||
public:
|
||||
Tracer ()
|
||||
{
|
||||
};
|
||||
|
||||
Tracer (std::string const &filename)
|
||||
{
|
||||
Open(filename);
|
||||
};
|
||||
|
||||
Tracer (char const *filename) : m_tracer(filename)
|
||||
{
|
||||
Open(filename);
|
||||
};
|
||||
|
||||
~Tracer () {};
|
||||
|
||||
void Log (const char *s, const Packet &p)
|
||||
{
|
||||
m_filestr << s << &p << std::endl;
|
||||
}
|
||||
|
||||
protected:
|
||||
TraceWriter m_tracer;
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
GenerateTraffic (UdpSocket *socket, uint32_t size)
|
||||
{
|
||||
@@ -62,7 +91,7 @@ PrintTraffic (UdpSocket *socket)
|
||||
socket->SetDummyRxCallback (MakeCallback (&UdpSocketPrinter));
|
||||
}
|
||||
|
||||
#if 1
|
||||
#if 0
|
||||
static void
|
||||
PrintRoutingTable (InternetNode *a, std::string name)
|
||||
{
|
||||
@@ -86,15 +115,26 @@ PrintRoutingTable (InternetNode *a, std::string name)
|
||||
}
|
||||
#endif
|
||||
|
||||
static SerialChannel* AddDuplexLink(InternetNode* a, const Ipv4Address& addra,
|
||||
const MacAddress& macaddra, InternetNode* b, const Ipv4Address& addrb,
|
||||
const MacAddress& macaddrb, const Ipv4Mask& netmask
|
||||
/*, const Rate& rate, const Time& delay */) {
|
||||
|
||||
|
||||
static SerialChannel *
|
||||
AddDuplexLink(
|
||||
InternetNode* a,
|
||||
const Ipv4Address& addra,
|
||||
const MacAddress& macaddra,
|
||||
InternetNode* b,
|
||||
const Ipv4Address& addrb,
|
||||
const MacAddress& macaddrb,
|
||||
const Ipv4Mask& netmask,
|
||||
// const Rate& rate,
|
||||
// const Time& delay,
|
||||
TraceContainer &traceContainer,
|
||||
std::string &name)
|
||||
{
|
||||
std::string qName;
|
||||
SerialChannel* channel = new SerialChannel();
|
||||
|
||||
DropTailQueue* dtqa = new DropTailQueue();
|
||||
qName = name + "::Queue A";
|
||||
DropTailQueue* dtqa = new DropTailQueue(qName, traceContainer);
|
||||
|
||||
SerialNetDevice* neta = new SerialNetDevice(a, macaddra);
|
||||
neta->AddQueue(dtqa);
|
||||
Ipv4Interface *interfA = new ArpIpv4Interface (a, neta);
|
||||
@@ -106,7 +146,9 @@ static SerialChannel* AddDuplexLink(InternetNode* a, const Ipv4Address& addra,
|
||||
interfA->SetNetworkMask (netmask);
|
||||
interfA->SetUp ();
|
||||
|
||||
DropTailQueue* dtqb = new DropTailQueue();
|
||||
qName = name + "::Queue B";
|
||||
DropTailQueue* dtqb = new DropTailQueue(qName, traceContainer);
|
||||
|
||||
SerialNetDevice* netb = new SerialNetDevice(b, macaddrb);
|
||||
netb->AddQueue(dtqb);
|
||||
Ipv4Interface *interfB = new ArpIpv4Interface (b, netb);
|
||||
@@ -146,6 +188,13 @@ int main (int argc, char *argv[])
|
||||
InternetNode *n1 = new InternetNode();
|
||||
InternetNode *n2 = new InternetNode();
|
||||
InternetNode *n3 = new InternetNode();
|
||||
|
||||
TraceContainer traceContainer;
|
||||
|
||||
n0->SetName(std::string("Node 0"));
|
||||
n1->SetName(std::string("Node 1"));
|
||||
n2->SetName(std::string("Node 2"));
|
||||
n3->SetName(std::string("Node 3"));
|
||||
|
||||
// set f [open out.tr w]
|
||||
// $ns trace-all $f
|
||||
@@ -157,20 +206,28 @@ int main (int argc, char *argv[])
|
||||
// $ns duplex-link $n1 $n2 5Mb 2ms DropTail
|
||||
// $ns duplex-link $n2 $n3 1.5Mb 10ms DropTail
|
||||
// ** part of topology creation object? **
|
||||
std::string channelName;
|
||||
|
||||
channelName = "Channel 1";
|
||||
SerialChannel* ch1 = AddDuplexLink (
|
||||
n0, Ipv4Address("10.1.1.1"), MacAddress("00:00:00:00:00:01"),
|
||||
n2, Ipv4Address("10.1.1.2"), MacAddress("00:00:00:00:00:02"),
|
||||
Ipv4Mask("255.255.255.0"));
|
||||
Ipv4Mask("255.255.255.0"),
|
||||
traceContainer, channelName);
|
||||
|
||||
channelName = "Channel 2";
|
||||
SerialChannel* ch2 = AddDuplexLink (
|
||||
n1, Ipv4Address("10.1.2.1"), MacAddress("00:00:00:00:00:03"),
|
||||
n2, Ipv4Address("10.1.2.2"), MacAddress("00:00:00:00:00:04"),
|
||||
Ipv4Mask("255.255.255.0"));
|
||||
Ipv4Mask("255.255.255.0"),
|
||||
traceContainer, channelName);
|
||||
|
||||
channelName = "Channel 3";
|
||||
SerialChannel* ch3 = AddDuplexLink (
|
||||
n2, Ipv4Address("10.1.3.1"), MacAddress("00:00:00:00:00:05"),
|
||||
n3, Ipv4Address("10.1.3.2"), MacAddress("00:00:00:00:00:06"),
|
||||
Ipv4Mask("255.255.255.0"));
|
||||
Ipv4Mask("255.255.255.0"),
|
||||
traceContainer, channelName);
|
||||
|
||||
// $ns duplex-link-op $n0 $n2 orient right-up
|
||||
// $ns duplex-link-op $n1 $n2 orient right-down
|
||||
@@ -221,7 +278,36 @@ int main (int argc, char *argv[])
|
||||
|
||||
// $ns at 1.0 "$cbr0 start"
|
||||
// $ns at 1.1 "$cbr1 start"
|
||||
|
||||
|
||||
Tracer tracer("serial-net-test.log");
|
||||
|
||||
char buffer[80];
|
||||
|
||||
for (int i = 1; i <= 3; ++i) {
|
||||
for (int j = 0; j < 2; ++j) {
|
||||
sprintf(buffer, "Channel %d::Queue %c::Queue::Enque", i, 'A' + j);
|
||||
|
||||
NS_DEBUG_UNCOND("tracing event " << buffer)
|
||||
|
||||
traceContainer.SetCallback (buffer,
|
||||
MakeCallback (&Tracer::Log, &tracer));
|
||||
|
||||
sprintf(buffer, "Channel %d::Queue %c::Queue::Deque", i, 'A' + j);
|
||||
|
||||
NS_DEBUG_UNCOND("tracing event " << buffer)
|
||||
|
||||
traceContainer.SetCallback (buffer,
|
||||
MakeCallback (&Tracer::Log, &tracer));
|
||||
|
||||
sprintf(buffer, "Channel %d::Queue %c::Queue::Drop", i, 'A' + j);
|
||||
|
||||
NS_DEBUG_UNCOND("tracing event " << buffer)
|
||||
|
||||
traceContainer.SetCallback (buffer,
|
||||
MakeCallback (&Tracer::Log, &tracer));
|
||||
}
|
||||
}
|
||||
|
||||
GenerateTraffic (source0, 100);
|
||||
PrintTraffic (sink3);
|
||||
|
||||
|
||||
@@ -42,6 +42,20 @@ DropTailQueue::DropTailQueue (TraceContainer &traceContainer) :
|
||||
RegisterTraces(traceContainer);
|
||||
}
|
||||
|
||||
DropTailQueue::DropTailQueue (
|
||||
std::string &name,
|
||||
TraceContainer &traceContainer)
|
||||
:
|
||||
m_packets(),
|
||||
m_maxPackets(DTQ_NPACKETS_MAX_DEFAULT)
|
||||
{
|
||||
NS_DEBUG(
|
||||
"DropTailQueue::DropTailQueue (" << &traceContainer << ")")
|
||||
|
||||
m_name = name;
|
||||
RegisterTraces(traceContainer);
|
||||
}
|
||||
|
||||
DropTailQueue::~DropTailQueue ()
|
||||
{
|
||||
NS_DEBUG(
|
||||
|
||||
@@ -33,6 +33,7 @@ public:
|
||||
DropTailQueue ();
|
||||
|
||||
DropTailQueue (TraceContainer &traceContainer);
|
||||
DropTailQueue (std::string &name, TraceContainer &traceContainer);
|
||||
|
||||
virtual ~DropTailQueue();
|
||||
|
||||
|
||||
@@ -59,6 +59,12 @@ InternetNode::~InternetNode ()
|
||||
delete m_ipv4L4Demux;
|
||||
}
|
||||
|
||||
void
|
||||
InternetNode::SetName (std::string name)
|
||||
{
|
||||
m_name = name;
|
||||
}
|
||||
|
||||
void
|
||||
InternetNode::SetupLoopback (void)
|
||||
{
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#define INTERNET_NODE_H
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
#include "node.h"
|
||||
|
||||
@@ -46,12 +47,14 @@ public:
|
||||
virtual Udp * GetUdp (void) const;
|
||||
virtual Arp * GetArp (void) const;
|
||||
|
||||
void SetName(std::string name);
|
||||
private:
|
||||
void SetupLoopback (void);
|
||||
// Capabilities
|
||||
NetDeviceList* m_netDevices;
|
||||
L3Demux* m_l3Demux;
|
||||
Ipv4L4Demux* m_ipv4L4Demux;
|
||||
std::string m_name;
|
||||
};
|
||||
|
||||
}//namespace ns3
|
||||
|
||||
@@ -46,7 +46,9 @@ Queue::Enque (const Packet& p)
|
||||
NS_DEBUG("Queue::Enque (" << &p << ")")
|
||||
|
||||
NS_DEBUG("Queue::Enque (): m_traceEnque (p)")
|
||||
m_traceEnque ("+ <timestamp> ", p);
|
||||
|
||||
std::string buffer = m_name + " + <timestamp> ";
|
||||
m_traceEnque (buffer.c_str(), p);
|
||||
|
||||
bool retval = DoEnque (p);
|
||||
if (retval)
|
||||
@@ -73,7 +75,9 @@ Queue::Deque (Packet &p)
|
||||
NS_ASSERT (m_nPackets >= 0);
|
||||
|
||||
NS_DEBUG("Queue::Deque (): m_traceDeque (p)")
|
||||
m_traceDeque ("+ <timestamp> ", static_cast<const Packet &>(p));
|
||||
|
||||
std::string buffer = m_name + " - <timestamp> ";
|
||||
m_traceDeque (buffer.c_str(), static_cast<const Packet &>(p));
|
||||
}
|
||||
|
||||
return retval;
|
||||
@@ -116,9 +120,15 @@ Queue::RegisterTraces (TraceContainer &container)
|
||||
{
|
||||
NS_DEBUG("Queue::RegisterTraces (" << &container << ")")
|
||||
|
||||
container.RegisterCallback ("Queue::Enque", &m_traceEnque);
|
||||
container.RegisterCallback ("Queue::Deque", &m_traceDeque);
|
||||
container.RegisterCallback ("Queue::Drop", &m_traceDrop);
|
||||
container.RegisterCallback (
|
||||
std::string(m_name + "::Queue::Enque").c_str(),
|
||||
&m_traceEnque);
|
||||
container.RegisterCallback (
|
||||
std::string(m_name + "::Queue::Deque").c_str(),
|
||||
&m_traceDeque);
|
||||
container.RegisterCallback (
|
||||
std::string(m_name + "::Queue::Drop").c_str(),
|
||||
&m_traceDrop);
|
||||
}
|
||||
|
||||
uint32_t
|
||||
@@ -177,7 +187,8 @@ Queue::Drop (const Packet& p)
|
||||
m_nTotalDroppedBytes += p.GetSize ();
|
||||
|
||||
NS_DEBUG("Queue::Drop (): m_traceDrop (p)")
|
||||
m_traceEnque ("d <timestamp> ", p);
|
||||
std::string buffer = m_name + " d <timestamp> ";
|
||||
m_traceEnque (buffer.c_str(), p);
|
||||
}
|
||||
|
||||
}; // namespace ns3
|
||||
|
||||
@@ -93,6 +93,7 @@ protected:
|
||||
uint32_t m_nTotalReceivedPackets;
|
||||
uint32_t m_nTotalDroppedBytes;
|
||||
uint32_t m_nTotalDroppedPackets;
|
||||
std::string m_name;
|
||||
|
||||
private:
|
||||
CallbackTracer<const char *, const Packet &> m_traceEnque;
|
||||
|
||||
Reference in New Issue
Block a user