applications: Extend logging for some applications

This commit is contained in:
Sébastien Deronne
2024-06-02 12:23:55 +02:00
parent 467d8a4a4b
commit f5a28141dc
4 changed files with 35 additions and 5 deletions

View File

@@ -139,14 +139,21 @@ PacketSink::StartApplication() // Called at time specified by Start
if (local.IsInvalid())
{
local = InetSocketAddress(Ipv4Address::GetAny(), m_port);
NS_LOG_INFO(this << " Binding on port " << m_port << " / " << local << ".");
}
else if (InetSocketAddress::IsMatchingType(local))
{
m_port = InetSocketAddress::ConvertFrom(local).GetPort();
const auto ipv4 = InetSocketAddress::ConvertFrom(local).GetIpv4();
NS_LOG_INFO(this << " Binding on " << ipv4 << " port " << m_port << " / " << local
<< ".");
}
else if (Inet6SocketAddress::IsMatchingType(local))
{
m_port = Inet6SocketAddress::ConvertFrom(local).GetPort();
const auto ipv6 = Inet6SocketAddress::ConvertFrom(local).GetIpv6();
NS_LOG_INFO(this << " Binding on " << ipv6 << " port " << m_port << " / " << local
<< ".");
}
if (m_socket->Bind(local) == -1)
{

View File

@@ -236,11 +236,14 @@ UdpClient::StartApplication()
std::stringstream peerAddressStringStream;
if (InetSocketAddress::IsMatchingType(m_peer))
{
peerAddressStringStream << InetSocketAddress::ConvertFrom(m_peer).GetIpv4();
peerAddressStringStream << InetSocketAddress::ConvertFrom(m_peer).GetIpv4() << ":"
<< InetSocketAddress::ConvertFrom(m_peer).GetPort();
;
}
else if (Inet6SocketAddress::IsMatchingType(m_peer))
{
peerAddressStringStream << Inet6SocketAddress::ConvertFrom(m_peer).GetIpv6();
peerAddressStringStream << Inet6SocketAddress::ConvertFrom(m_peer).GetIpv6() << ":"
<< Inet6SocketAddress::ConvertFrom(m_peer).GetPort();
}
m_peerString = peerAddressStringStream.str();
#endif // NS3_LOG_ENABLE

View File

@@ -128,6 +128,22 @@ UdpServer::StartApplication()
if (local.IsInvalid())
{
local = InetSocketAddress(Ipv4Address::GetAny(), m_port);
NS_LOG_INFO(this << " Binding on port " << m_port << " / " << local << ".");
}
else
{
if (InetSocketAddress::IsMatchingType(m_local))
{
const auto ipv4 = InetSocketAddress::ConvertFrom(m_local).GetIpv4();
NS_LOG_INFO(this << " Binding on " << ipv4 << " port " << m_port << " / " << m_local
<< ".");
}
else if (Ipv6Address::IsMatchingType(m_local))
{
const auto ipv6 = Inet6SocketAddress::ConvertFrom(m_local).GetIpv6();
NS_LOG_INFO(this << " Binding on " << ipv6 << " port " << m_port << " / " << m_local
<< ".");
}
}
if (m_socket->Bind(local) == -1)
{

View File

@@ -375,15 +375,19 @@ UdpTraceClient::SendPacket(uint32_t size)
seqTs.SetSeq(m_sent);
p->AddHeader(seqTs);
std::stringstream addressString;
std::stringstream addressString{};
#ifdef NS3_LOG_ENABLE
if (InetSocketAddress::IsMatchingType(m_peer))
{
addressString << InetSocketAddress::ConvertFrom(m_peer).GetIpv4();
addressString << InetSocketAddress::ConvertFrom(m_peer).GetIpv4() << ":"
<< InetSocketAddress::ConvertFrom(m_peer).GetPort();
}
else if (Inet6SocketAddress::IsMatchingType(m_peer))
{
addressString << Inet6SocketAddress::ConvertFrom(m_peer).GetIpv6();
addressString << Inet6SocketAddress::ConvertFrom(m_peer).GetIpv6() << ":"
<< Inet6SocketAddress::ConvertFrom(m_peer).GetPort();
}
#endif
if ((m_socket->Send(p)) >= 0)
{