From 83dd618e5be3a5b9045a44f3fa679ecc13f6250d Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 11 Dec 2007 14:03:20 +0100 Subject: [PATCH] add tracing support to PacketSink --- src/applications/packet-sink/packet-sink.cc | 18 +++++++++++++++++- src/applications/packet-sink/packet-sink.h | 5 +++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/applications/packet-sink/packet-sink.cc b/src/applications/packet-sink/packet-sink.cc index e6bc0d024..9fe6ab925 100644 --- a/src/applications/packet-sink/packet-sink.cc +++ b/src/applications/packet-sink/packet-sink.cc @@ -25,6 +25,7 @@ #include "ns3/simulator.h" #include "ns3/socket-factory.h" #include "ns3/packet.h" +#include "ns3/composite-trace-resolver.h" #include "packet-sink.h" using namespace std; @@ -101,8 +102,23 @@ void PacketSink::Receive(Ptr socket, Ptr packet, NS_LOG_INFO ("Received " << packet->GetSize() << " bytes from " << address.GetIpv4() << " [" << address << "]---'" << packet->PeekData() << "'"); - // TODO: Add a tracing source here } + m_rxTrace (packet, from); +} + +Ptr +PacketSink::GetTraceResolver (void) const +{ + Ptr resolver = Create (); + resolver->AddSource ("rx", + TraceDoc ("A new packet has been received", + "Ptr", + "The newly-received packet.", + "const Address &", + "The source address of the received packet."), + m_rxTrace); + resolver->SetParentResolver (Application::GetTraceResolver ()); + return resolver; } } // Namespace ns3 diff --git a/src/applications/packet-sink/packet-sink.h b/src/applications/packet-sink/packet-sink.h index f13a4bca4..96fc7f98f 100644 --- a/src/applications/packet-sink/packet-sink.h +++ b/src/applications/packet-sink/packet-sink.h @@ -24,6 +24,8 @@ #include "ns3/application.h" #include "ns3/event-id.h" #include "ns3/ptr.h" +#include "ns3/callback-trace-source.h" +#include "ns3/address.h" namespace ns3 { @@ -68,6 +70,8 @@ private: // inherited from Application base class. virtual void StartApplication (void); // Called at time specified by Start virtual void StopApplication (void); // Called at time specified by Stop + // inherited from Object base class. + virtual Ptr GetTraceResolver (void) const; void Construct (Ptr n, const Address &local, @@ -78,6 +82,7 @@ private: Ptr m_socket; // Associated socket Address m_local; // Local address to bind to std::string m_iid; // Protocol name (e.g., "Udp") + CallbackTraceSource, const Address &> m_rxTrace; };