add tracing support to PacketSink
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user