Loading
network: Pretty-print an Ip[v4|v6]Address stored as an Address
This is a proposal to pretty-print ns3::Address as a formatted IPv4 address (dotted decimal) or IPv6 address (colon hex). Classes that handle the polymorphic ns3::Address often print these addresses in log statements, where they are rendered with the default Address stream operator that prints a raw type-tagged hex such as 05-10-fe:80:...:02, making it hard to decipher.
Old log statement format example
void
NhdpClient::HandleLinkFailure(const Address& neighborAddr)
{
NS_LOG_FUNCTION(this << neighborAddr);
...
NS_LOG_INFO("LinkFailure to existing neighbor " << neighborAddr << " reported");prints:
+4.500000000s -1 NhdpClient:HandleLinkFailure(0x1510837e0, 01-04-07:00:00:02)
+4.500000000s -1 NhdpClient:HandleLinkFailure(): [INFO ] LinkFailure to existing neighbor 01-04-07:00:00:02 reportedWhen using this patch:
void
NhdpClient::HandleLinkFailure(const Address& neighborAddr)
{
NS_LOG_FUNCTION(this << addressUtils::FormatAddress(neighborAddr));
...
NS_LOG_INFO("LinkFailure to existing neighbor " << addressUtils::FormatAddress(neighborAddr)
<< " reported");prints:
+4.500000000s -1 NhdpClient:HandleLinkFailure(0x13310c710, "7.0.0.2")
+4.500000000s -1 NhdpClient:HandleLinkFailure(): [INFO ] LinkFailure to existing neighbor 7.0.0.2 reported