bug 638: add missing tx trace source
authorWilson Thong <wilsonwk@ee.cityu.edu.hk>
Thu, 13 Aug 2009 09:47:53 +0200
changeset 4710 e56da5fd6697
parent 4709 b0743dbc4e55
child 4711 3c9b7588ea4c
child 4713 3fdb8f60a863
bug 638: add missing tx trace source
src/applications/udp-echo/udp-echo-client.cc
src/applications/udp-echo/udp-echo-client.h
--- a/src/applications/udp-echo/udp-echo-client.cc	Thu Aug 13 09:36:53 2009 +0200
+++ b/src/applications/udp-echo/udp-echo-client.cc	Thu Aug 13 09:47:53 2009 +0200
@@ -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 @@
                    MakeUintegerAccessor (&UdpEchoClient::SetDataSize,
                                          &UdpEchoClient::GetDataSize),
                    MakeUintegerChecker<uint32_t> ())
+    .AddTraceSource ("Tx", "A new packet is created and is sent",
+                     MakeTraceSourceAccessor (&UdpEchoClient::m_txTrace))
     ;
   return tid;
 }
@@ -246,6 +249,7 @@
 
   NS_ASSERT (m_sendEvent.IsExpired ());
 
+  Ptr<Packet> p;
   if (m_dataSize)
     {
       //
@@ -256,8 +260,7 @@
       //
       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<Packet> p = Create<Packet> (m_data, m_dataSize);
-      m_socket->Send (p);
+      p = Create<Packet> (m_data, m_dataSize);
     }
   else
     {
@@ -268,9 +271,12 @@
       // 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<Packet> p = Create<Packet> (m_size);
-      m_socket->Send (p);
+      p = Create<Packet> (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;
 
--- a/src/applications/udp-echo/udp-echo-client.h	Thu Aug 13 09:36:53 2009 +0200
+++ b/src/applications/udp-echo/udp-echo-client.h	Thu Aug 13 09:47:53 2009 +0200
@@ -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 @@
   Ipv4Address m_peerAddress;
   uint16_t m_peerPort;
   EventId m_sendEvent;
-
+  /// Callbacks for tracing the packet Tx events
+  TracedCallback<Ptr<const Packet> > m_txTrace;
 };
 
 } // namespace ns3