diff --git a/src/applications/udp-echo/udp-echo-client.cc b/src/applications/udp-echo/udp-echo-client.cc index 7553f0306..363e74c3f 100644 --- a/src/applications/udp-echo/udp-echo-client.cc +++ b/src/applications/udp-echo/udp-echo-client.cc @@ -24,6 +24,7 @@ #include "ns3/socket-factory.h" #include "ns3/packet.h" #include "ns3/uinteger.h" +#include "ns3/trace-source-accessor.h" #include "udp-echo-client.h" namespace ns3 { @@ -62,6 +63,8 @@ UdpEchoClient::GetTypeId (void) MakeUintegerAccessor (&UdpEchoClient::SetDataSize, &UdpEchoClient::GetDataSize), MakeUintegerChecker ()) + .AddTraceSource ("Tx", "A new packet is created and is sent", + MakeTraceSourceAccessor (&UdpEchoClient::m_txTrace)) ; return tid; } @@ -246,6 +249,7 @@ UdpEchoClient::Send (void) NS_ASSERT (m_sendEvent.IsExpired ()); + Ptr p; if (m_dataSize) { // @@ -256,8 +260,7 @@ UdpEchoClient::Send (void) // NS_ASSERT_MSG (m_dataSize == m_size, "UdpEchoClient::Send(): m_size and m_dataSize inconsistent"); NS_ASSERT_MSG (m_data, "UdpEchoClient::Send(): m_dataSize but no m_data"); - Ptr p = Create (m_data, m_dataSize); - m_socket->Send (p); + p = Create (m_data, m_dataSize); } else { @@ -268,9 +271,12 @@ UdpEchoClient::Send (void) // this case, we don't worry about it either. But we do allow m_size // to have a value different from the (zero) m_dataSize. // - Ptr p = Create (m_size); - m_socket->Send (p); + p = Create (m_size); } + // call to the trace sinks before the packet is actually sent, + // so that tags added to the packet can be sent as well + m_txTrace (p); + m_socket->Send (p); ++m_sent; diff --git a/src/applications/udp-echo/udp-echo-client.h b/src/applications/udp-echo/udp-echo-client.h index c8514640b..faabcd781 100644 --- a/src/applications/udp-echo/udp-echo-client.h +++ b/src/applications/udp-echo/udp-echo-client.h @@ -23,6 +23,7 @@ #include "ns3/event-id.h" #include "ns3/ptr.h" #include "ns3/ipv4-address.h" +#include "ns3/traced-callback.h" namespace ns3 { @@ -140,7 +141,8 @@ private: Ipv4Address m_peerAddress; uint16_t m_peerPort; EventId m_sendEvent; - + /// Callbacks for tracing the packet Tx events + TracedCallback > m_txTrace; }; } // namespace ns3