diff --git a/CHANGES.md b/CHANGES.md index 758c69dba..9313bcf51 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -23,6 +23,7 @@ Changes from ns-3.38 to ns-3-dev * (network) Added `Mac16Address::ConvertToInt`. Converts a Mac16Address object to a uint16_t. * (network) Added `Mac16Address::Mac16Address(uint16t addr)` and `Mac16Address::Mac64Address(uint64t addr)` constructors. * (lr-wpan) Added `LrwpanMac::MlmeGetRequest` function and the corresponding confirm callbacks as well as `LrwpanMac::SetMlmeGetConfirm` function. +* (applications) Added `Tx` and `TxWithAddresses` trace sources in `UdpClient`. ### Changes to existing API diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 9eb6cfc30..a11a54ec6 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -24,6 +24,7 @@ Release 3-dev - (network) !1405 - Add ConvertToInt to Mac64Address - (lr-wpan) !1402 - Add attributes to MLME-SET and MLME-GET - (lr-wpan) !1410 - Add Mac16 and Mac64 functions +- (applications) !1412 - Add Tx and TxWithAddresses trace sources in UdpClient ### Bugs fixed diff --git a/src/applications/model/udp-client.cc b/src/applications/model/udp-client.cc index f5b4c9379..56d3ba3e4 100644 --- a/src/applications/model/udp-client.cc +++ b/src/applications/model/udp-client.cc @@ -76,7 +76,15 @@ UdpClient::GetTypeId() "the size of the header carrying the sequence number and the time stamp.", UintegerValue(1024), MakeUintegerAccessor(&UdpClient::m_size), - MakeUintegerChecker(12, 65507)); + MakeUintegerChecker(12, 65507)) + .AddTraceSource("Tx", + "A new packet is created and sent", + MakeTraceSourceAccessor(&UdpClient::m_txTrace), + "ns3::Packet::TracedCallback") + .AddTraceSource("TxWithAddresses", + "A new packet is created and sent", + MakeTraceSourceAccessor(&UdpClient::m_txTraceWithAddresses), + "ns3::Packet::TwoAddressTracedCallback"); return tid; } @@ -203,9 +211,20 @@ UdpClient::Send() { NS_LOG_FUNCTION(this); NS_ASSERT(m_sendEvent.IsExpired()); + + Address from; + Address to; + m_socket->GetSockName(from); + m_socket->GetPeerName(to); SeqTsHeader seqTs; seqTs.SetSeq(m_sent); - Ptr p = Create(m_size - (8 + 4)); // 8+4 : the size of the seqTs header + NS_ABORT_IF(m_size < seqTs.GetSerializedSize()); + Ptr p = Create(m_size - seqTs.GetSerializedSize()); + + // Trace before adding header, for consistency with PacketSink + m_txTrace(p); + m_txTraceWithAddresses(p, from, to); + p->AddHeader(seqTs); if ((m_socket->Send(p)) >= 0) diff --git a/src/applications/model/udp-client.h b/src/applications/model/udp-client.h index 0f241ab5a..d5a14d93a 100644 --- a/src/applications/model/udp-client.h +++ b/src/applications/model/udp-client.h @@ -26,6 +26,7 @@ #include "ns3/event-id.h" #include "ns3/ipv4-address.h" #include "ns3/ptr.h" +#include namespace ns3 { @@ -82,6 +83,12 @@ class UdpClient : public Application */ void Send(); + /// Traced Callback: transmitted packets. + TracedCallback> m_txTrace; + + /// Callbacks for tracing the packet Tx events, includes source and destination addresses + TracedCallback, const Address&, const Address&> m_txTraceWithAddresses; + uint32_t m_count; //!< Maximum number of packets the application will send Time m_interval; //!< Packet inter-send time uint32_t m_size; //!< Size of the sent packet (including the SeqTsHeader) @@ -92,6 +99,7 @@ class UdpClient : public Application Address m_peerAddress; //!< Remote peer address uint16_t m_peerPort; //!< Remote peer port EventId m_sendEvent; //!< Event to send the next packet + #ifdef NS3_LOG_ENABLE std::string m_peerAddressString; //!< Remote peer address string #endif // NS3_LOG_ENABLE