applications: Add Tx traces in UdpClient

This commit is contained in:
pagmatt
2023-03-28 15:49:06 -04:00
committed by Tommaso Pecorella
parent 4ea10a84b9
commit 31b67e8cdd
4 changed files with 31 additions and 2 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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<uint32_t>(12, 65507));
MakeUintegerChecker<uint32_t>(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<Packet> p = Create<Packet>(m_size - (8 + 4)); // 8+4 : the size of the seqTs header
NS_ABORT_IF(m_size < seqTs.GetSerializedSize());
Ptr<Packet> p = Create<Packet>(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)

View File

@@ -26,6 +26,7 @@
#include "ns3/event-id.h"
#include "ns3/ipv4-address.h"
#include "ns3/ptr.h"
#include <ns3/traced-callback.h>
namespace ns3
{
@@ -82,6 +83,12 @@ class UdpClient : public Application
*/
void Send();
/// Traced Callback: transmitted packets.
TracedCallback<Ptr<const Packet>> m_txTrace;
/// Callbacks for tracing the packet Tx events, includes source and destination addresses
TracedCallback<Ptr<const Packet>, 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