applications: Add trace sources to traffic generators

This commit is contained in:
Fernando J. Cintrón
2018-05-29 20:17:42 -07:00
parent e3eeb3b5c8
commit e248097d85
11 changed files with 98 additions and 1 deletions

View File

@@ -91,6 +91,9 @@ OnOffApplication::GetTypeId (void)
.AddTraceSource ("Tx", "A new packet is created and is sent",
MakeTraceSourceAccessor (&OnOffApplication::m_txTrace),
"ns3::Packet::TracedCallback")
.AddTraceSource ("TxWithAddresses", "A new packet is created and is sent",
MakeTraceSourceAccessor (&OnOffApplication::m_txTraceWithAddresses),
"ns3::Packet::TwoAddressTracedCallback")
;
return tid;
}
@@ -283,6 +286,8 @@ void OnOffApplication::SendPacket ()
m_txTrace (packet);
m_socket->Send (packet);
m_totBytes += m_pktSize;
Address localAddress;
m_socket->GetSockName (localAddress);
if (InetSocketAddress::IsMatchingType (m_peer))
{
NS_LOG_INFO ("At time " << Simulator::Now ().GetSeconds ()
@@ -291,6 +296,7 @@ void OnOffApplication::SendPacket ()
<< InetSocketAddress::ConvertFrom(m_peer).GetIpv4 ()
<< " port " << InetSocketAddress::ConvertFrom (m_peer).GetPort ()
<< " total Tx " << m_totBytes << " bytes");
m_txTraceWithAddresses (packet, localAddress, InetSocketAddress::ConvertFrom (m_peer));
}
else if (Inet6SocketAddress::IsMatchingType (m_peer))
{
@@ -300,6 +306,7 @@ void OnOffApplication::SendPacket ()
<< Inet6SocketAddress::ConvertFrom(m_peer).GetIpv6 ()
<< " port " << Inet6SocketAddress::ConvertFrom (m_peer).GetPort ()
<< " total Tx " << m_totBytes << " bytes");
m_txTraceWithAddresses (packet, localAddress, Inet6SocketAddress::ConvertFrom(m_peer));
}
m_lastStartTime = Simulator::Now ();
m_residualBits = 0;

View File

@@ -167,6 +167,9 @@ private:
/// 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;
private:
/**
* \brief Schedule the next packet transmission

View File

@@ -59,6 +59,9 @@ PacketSink::GetTypeId (void)
"A packet has been received",
MakeTraceSourceAccessor (&PacketSink::m_rxTrace),
"ns3::Packet::AddressTracedCallback")
.AddTraceSource ("RxWithAddresses", "A packet has been received",
MakeTraceSourceAccessor (&PacketSink::m_rxTraceWithAddresses),
"ns3::Packet::TwoAddressTracedCallback")
;
return tid;
}
@@ -165,6 +168,7 @@ void PacketSink::HandleRead (Ptr<Socket> socket)
NS_LOG_FUNCTION (this << socket);
Ptr<Packet> packet;
Address from;
Address localAddress;
while ((packet = socket->RecvFrom (from)))
{
if (packet->GetSize () == 0)
@@ -190,7 +194,9 @@ void PacketSink::HandleRead (Ptr<Socket> socket)
<< " port " << Inet6SocketAddress::ConvertFrom (from).GetPort ()
<< " total Rx " << m_totalRx << " bytes");
}
socket->GetSockName (localAddress);
m_rxTrace (packet, from);
m_rxTraceWithAddresses (packet, from, localAddress);
}
}

View File

@@ -133,6 +133,9 @@ private:
/// Traced Callback: received packets, source address.
TracedCallback<Ptr<const Packet>, const Address &> m_rxTrace;
/// Callback for tracing the packet Rx events, includes source and destination addresses
TracedCallback<Ptr<const Packet>, const Address &, const Address &> m_rxTraceWithAddresses;
};
} // namespace ns3

View File

@@ -70,6 +70,15 @@ UdpEchoClient::GetTypeId (void)
.AddTraceSource ("Tx", "A new packet is created and is sent",
MakeTraceSourceAccessor (&UdpEchoClient::m_txTrace),
"ns3::Packet::TracedCallback")
.AddTraceSource ("Rx", "A packet has been received",
MakeTraceSourceAccessor (&UdpEchoClient::m_rxTrace),
"ns3::Packet::TracedCallback")
.AddTraceSource ("TxWithAddresses", "A new packet is created and is sent",
MakeTraceSourceAccessor (&UdpEchoClient::m_txTraceWithAddresses),
"ns3::Packet::TwoAddressTracedCallback")
.AddTraceSource ("RxWithAddresses", "A packet has been received",
MakeTraceSourceAccessor (&UdpEchoClient::m_rxTraceWithAddresses),
"ns3::Packet::TwoAddressTracedCallback")
;
return tid;
}
@@ -324,11 +333,20 @@ UdpEchoClient::Send (void)
//
p = Create<Packet> (m_size);
}
Address localAddress;
m_socket->GetSockName (localAddress);
// 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);
if (Ipv4Address::IsMatchingType (m_peerAddress))
{
m_txTraceWithAddresses (p, localAddress, InetSocketAddress (Ipv4Address::ConvertFrom (m_peerAddress), m_peerPort));
}
else if (Ipv6Address::IsMatchingType (m_peerAddress))
{
m_txTraceWithAddresses (p, localAddress, Inet6SocketAddress (Ipv6Address::ConvertFrom (m_peerAddress), m_peerPort));
}
m_socket->Send (p);
++m_sent;
if (Ipv4Address::IsMatchingType (m_peerAddress))
@@ -364,6 +382,7 @@ UdpEchoClient::HandleRead (Ptr<Socket> socket)
NS_LOG_FUNCTION (this << socket);
Ptr<Packet> packet;
Address from;
Address localAddress;
while ((packet = socket->RecvFrom (from)))
{
if (InetSocketAddress::IsMatchingType (from))
@@ -378,6 +397,9 @@ UdpEchoClient::HandleRead (Ptr<Socket> socket)
Inet6SocketAddress::ConvertFrom (from).GetIpv6 () << " port " <<
Inet6SocketAddress::ConvertFrom (from).GetPort ());
}
socket->GetSockName (localAddress);
m_rxTrace (packet);
m_rxTraceWithAddresses (packet, from, localAddress);
}
}

View File

@@ -172,6 +172,16 @@ private:
/// Callbacks for tracing the packet Tx events
TracedCallback<Ptr<const Packet> > m_txTrace;
/// Callbacks for tracing the packet Rx events
TracedCallback<Ptr<const Packet> > m_rxTrace;
/// Callbacks for tracing the packet Tx events, includes source and destination addresses
TracedCallback<Ptr<const Packet>, const Address &, const Address &> m_txTraceWithAddresses;
/// Callbacks for tracing the packet Rx events, includes source and destination addresses
TracedCallback<Ptr<const Packet>, const Address &, const Address &> m_rxTraceWithAddresses;
};
} // namespace ns3

View File

@@ -49,6 +49,12 @@ UdpEchoServer::GetTypeId (void)
UintegerValue (9),
MakeUintegerAccessor (&UdpEchoServer::m_port),
MakeUintegerChecker<uint16_t> ())
.AddTraceSource ("Rx", "A packet has been received",
MakeTraceSourceAccessor (&UdpEchoServer::m_rxTrace),
"ns3::Packet::TracedCallback")
.AddTraceSource ("RxWithAddresses", "A packet has been received",
MakeTraceSourceAccessor (&UdpEchoServer::m_rxTraceWithAddresses),
"ns3::Packet::TwoAddressTracedCallback")
;
return tid;
}
@@ -153,8 +159,12 @@ UdpEchoServer::HandleRead (Ptr<Socket> socket)
Ptr<Packet> packet;
Address from;
Address localAddress;
while ((packet = socket->RecvFrom (from)))
{
socket->GetSockName (localAddress);
m_rxTrace (packet);
m_rxTraceWithAddresses (packet, from, localAddress);
if (InetSocketAddress::IsMatchingType (from))
{
NS_LOG_INFO ("At time " << Simulator::Now ().GetSeconds () << "s server received " << packet->GetSize () << " bytes from " <<

View File

@@ -23,6 +23,7 @@
#include "ns3/event-id.h"
#include "ns3/ptr.h"
#include "ns3/address.h"
#include "ns3/traced-callback.h"
namespace ns3 {
@@ -72,6 +73,12 @@ private:
Ptr<Socket> m_socket; //!< IPv4 Socket
Ptr<Socket> m_socket6; //!< IPv6 Socket
Address m_local; //!< local multicast address
/// Callbacks for tracing the packet Rx events
TracedCallback<Ptr<const Packet> > m_rxTrace;
/// Callbacks for tracing the packet Rx events, includes source and destination addresses
TracedCallback<Ptr<const Packet>, const Address &, const Address &> m_rxTraceWithAddresses;
};
} // namespace ns3

View File

@@ -59,6 +59,12 @@ UdpServer::GetTypeId (void)
MakeUintegerAccessor (&UdpServer::GetPacketWindowSize,
&UdpServer::SetPacketWindowSize),
MakeUintegerChecker<uint16_t> (8,256))
.AddTraceSource ("Rx", "A packet has been received",
MakeTraceSourceAccessor (&UdpServer::m_rxTrace),
"ns3::Packet::TracedCallback")
.AddTraceSource ("RxWithAddresses", "A packet has been received",
MakeTraceSourceAccessor (&UdpServer::m_rxTraceWithAddresses),
"ns3::Packet::TwoAddressTracedCallback")
;
return tid;
}
@@ -162,8 +168,12 @@ UdpServer::HandleRead (Ptr<Socket> socket)
NS_LOG_FUNCTION (this << socket);
Ptr<Packet> packet;
Address from;
Address localAddress;
while ((packet = socket->RecvFrom (from)))
{
socket->GetSockName (localAddress);
m_rxTrace (packet);
m_rxTraceWithAddresses (packet, from, localAddress);
if (packet->GetSize () > 0)
{
SeqTsHeader seqTs;

View File

@@ -27,7 +27,9 @@
#include "ns3/event-id.h"
#include "ns3/ptr.h"
#include "ns3/address.h"
#include "ns3/traced-callback.h"
#include "packet-loss-counter.h"
namespace ns3 {
/**
* \ingroup applications
@@ -100,6 +102,13 @@ private:
Ptr<Socket> m_socket6; //!< IPv6 Socket
uint64_t m_received; //!< Number of received packets
PacketLossCounter m_lossCounter; //!< Lost packet counter
/// Callbacks for tracing the packet Rx events
TracedCallback<Ptr<const Packet> > m_rxTrace;
/// Callbacks for tracing the packet Rx events, includes source and destination addresses
TracedCallback<Ptr<const Packet>, const Address &, const Address &> m_rxTraceWithAddresses;
};
} // namespace ns3

View File

@@ -701,6 +701,16 @@ public:
typedef void (* AddressTracedCallback)
(Ptr<const Packet> packet, const Address &address);
/**
* TracedCallback signature for packet and source/destination addresses.
*
* \param [in] packet The packet.
* \param [in] srcAddress The source address.
* \param [in] destAddress The destination address.
*/
typedef void (* TwoAddressTracedCallback)
(const Ptr<const Packet> packet, const Address &srcAddress, const Address &destAddress);
/**
* TracedCallback signature for packet and Mac48Address.
*