add tracing support to PacketSink

This commit is contained in:
Mathieu Lacage
2007-12-11 14:03:20 +01:00
parent ffc992893f
commit 83dd618e5b
2 changed files with 22 additions and 1 deletions

View File

@@ -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> socket, Ptr<Packet> 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<TraceResolver>
PacketSink::GetTraceResolver (void) const
{
Ptr<CompositeTraceResolver> resolver = Create<CompositeTraceResolver> ();
resolver->AddSource ("rx",
TraceDoc ("A new packet has been received",
"Ptr<const Packet>",
"The newly-received packet.",
"const Address &",
"The source address of the received packet."),
m_rxTrace);
resolver->SetParentResolver (Application::GetTraceResolver ());
return resolver;
}
} // Namespace ns3

View File

@@ -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<TraceResolver> GetTraceResolver (void) const;
void Construct (Ptr<Node> n,
const Address &local,
@@ -78,6 +82,7 @@ private:
Ptr<Socket> m_socket; // Associated socket
Address m_local; // Local address to bind to
std::string m_iid; // Protocol name (e.g., "Udp")
CallbackTraceSource<Ptr<const Packet>, const Address &> m_rxTrace;
};