From 0523df88279235344cfc3e76d52b04d04a6c4e7a Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 20 Feb 2007 22:55:09 -0800 Subject: [PATCH] Added tracing support to simple.tcl.cc (Craig) --- samples/ns-2/simple.tcl.cc | 112 ++++++++++++++++++++++++++++++++----- src/node/drop-tail.cc | 14 +++++ src/node/drop-tail.h | 1 + src/node/internet-node.cc | 6 ++ src/node/internet-node.h | 3 + src/node/queue.cc | 23 ++++++-- src/node/queue.h | 1 + 7 files changed, 141 insertions(+), 19 deletions(-) diff --git a/samples/ns-2/simple.tcl.cc b/samples/ns-2/simple.tcl.cc index 240198343..49c417b0e 100644 --- a/samples/ns-2/simple.tcl.cc +++ b/samples/ns-2/simple.tcl.cc @@ -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); diff --git a/src/node/drop-tail.cc b/src/node/drop-tail.cc index f4a597faf..cc667bd77 100644 --- a/src/node/drop-tail.cc +++ b/src/node/drop-tail.cc @@ -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( diff --git a/src/node/drop-tail.h b/src/node/drop-tail.h index 264693758..42b092a9e 100644 --- a/src/node/drop-tail.h +++ b/src/node/drop-tail.h @@ -33,6 +33,7 @@ public: DropTailQueue (); DropTailQueue (TraceContainer &traceContainer); + DropTailQueue (std::string &name, TraceContainer &traceContainer); virtual ~DropTailQueue(); diff --git a/src/node/internet-node.cc b/src/node/internet-node.cc index 42e17243a..3624f6e60 100644 --- a/src/node/internet-node.cc +++ b/src/node/internet-node.cc @@ -59,6 +59,12 @@ InternetNode::~InternetNode () delete m_ipv4L4Demux; } + void +InternetNode::SetName (std::string name) +{ + m_name = name; +} + void InternetNode::SetupLoopback (void) { diff --git a/src/node/internet-node.h b/src/node/internet-node.h index 1b9e6378a..0f48cddf3 100644 --- a/src/node/internet-node.h +++ b/src/node/internet-node.h @@ -25,6 +25,7 @@ #define INTERNET_NODE_H #include +#include #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 diff --git a/src/node/queue.cc b/src/node/queue.cc index 7b2000cb3..72f986c81 100644 --- a/src/node/queue.cc +++ b/src/node/queue.cc @@ -46,7 +46,9 @@ Queue::Enque (const Packet& p) NS_DEBUG("Queue::Enque (" << &p << ")") NS_DEBUG("Queue::Enque (): m_traceEnque (p)") - m_traceEnque ("+ ", p); + + std::string buffer = m_name + " + "; + 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 ("+ ", static_cast(p)); + + std::string buffer = m_name + " - "; + m_traceDeque (buffer.c_str(), static_cast(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 ", p); + std::string buffer = m_name + " d "; + m_traceEnque (buffer.c_str(), p); } }; // namespace ns3 diff --git a/src/node/queue.h b/src/node/queue.h index cbe07ee35..9fb493fa9 100644 --- a/src/node/queue.h +++ b/src/node/queue.h @@ -93,6 +93,7 @@ protected: uint32_t m_nTotalReceivedPackets; uint32_t m_nTotalDroppedBytes; uint32_t m_nTotalDroppedPackets; + std::string m_name; private: CallbackTracer m_traceEnque;