TCP flags are now printed using string instead of numbers
This patch improves readability when TCP flags are involved.
--- a/src/internet/model/tcp-l4-protocol.cc Mon Jul 13 08:23:40 2015 -0700
+++ b/src/internet/model/tcp-l4-protocol.cc Mon Jul 13 08:26:43 2015 -0700
@@ -352,7 +352,7 @@
NS_LOG_LOGIC ("TcpL4Protocol " << this
<< " receiving seq " << incomingTcpHeader.GetSequenceNumber ()
<< " ack " << incomingTcpHeader.GetAckNumber ()
- << " flags " << std::hex << (int)incomingTcpHeader.GetFlags () << std::dec
+ << " flags "<< TcpHeader::FlagsToString (incomingTcpHeader.GetFlags ())
<< " data size " << packet->GetSize ());
if (!incomingTcpHeader.IsChecksumOk ())
@@ -527,7 +527,7 @@
NS_LOG_LOGIC ("TcpL4Protocol " << this
<< " sending seq " << outgoing.GetSequenceNumber ()
<< " ack " << outgoing.GetAckNumber ()
- << " flags " << std::hex << (int)outgoing.GetFlags () << std::dec
+ << " flags " << TcpHeader::FlagsToString (outgoing.GetFlags ())
<< " data size " << packet->GetSize ());
NS_LOG_FUNCTION (this << packet << saddr << daddr << oif);
// XXX outgoingHeader cannot be logged
@@ -578,7 +578,7 @@
NS_LOG_LOGIC ("TcpL4Protocol " << this
<< " sending seq " << outgoing.GetSequenceNumber ()
<< " ack " << outgoing.GetAckNumber ()
- << " flags " << std::hex << (int)outgoing.GetFlags () << std::dec
+ << " flags " << TcpHeader::FlagsToString (outgoing.GetFlags ())
<< " data size " << packet->GetSize ());
NS_LOG_FUNCTION (this << packet << saddr << daddr << oif);
// XXX outgoingHeader cannot be logged
--- a/src/internet/model/tcp-socket-base.cc Mon Jul 13 08:23:40 2015 -0700
+++ b/src/internet/model/tcp-socket-base.cc Mon Jul 13 08:26:43 2015 -0700
@@ -1078,7 +1078,7 @@
{ // Received RST or the TCP flags is invalid, in either case, terminate this socket
if (tcpflags != TcpHeader::RST)
{ // this must be an invalid flag, send reset
- NS_LOG_LOGIC ("Illegal flag " << tcpflags << " received. Reset packet is sent.");
+ NS_LOG_LOGIC ("Illegal flag " << TcpHeader::FlagsToString (tcpflags) << " received. Reset packet is sent.");
SendRST ();
}
CloseAndNotify ();
@@ -1203,7 +1203,8 @@
{ // Other in-sequence input
if (tcpflags != TcpHeader::RST)
{ // When (1) rx of FIN+ACK; (2) rx of FIN; (3) rx of bad flags
- NS_LOG_LOGIC ("Illegal flag " << std::hex << static_cast<uint32_t> (tcpflags) << std::dec << " received. Reset packet is sent.");
+ NS_LOG_LOGIC ("Illegal flag " << TcpHeader::FlagsToString (tcpflags) <<
+ " received. Reset packet is sent.");
SendRST ();
}
CloseAndNotify ();
@@ -1283,7 +1284,8 @@
{ // Other in-sequence input
if (tcpflags != TcpHeader::RST)
{ // When (1) rx of SYN+ACK; (2) rx of FIN; (3) rx of bad flags
- NS_LOG_LOGIC ("Illegal flag " << tcpflags << " received. Reset packet is sent.");
+ NS_LOG_LOGIC ("Illegal flag " << TcpHeader::FlagsToString (tcpflags) <<
+ " received. Reset packet is sent.");
if (m_endPoint)
{
m_endPoint->SetPeer (InetSocketAddress::ConvertFrom (fromAddress).GetIpv4 (),
@@ -1339,7 +1341,8 @@
{ // This is a RST or bad flags
if (tcpflags != TcpHeader::RST)
{
- NS_LOG_LOGIC ("Illegal flag " << tcpflags << " received. Reset packet is sent.");
+ NS_LOG_LOGIC ("Illegal flag " << TcpHeader::FlagsToString (tcpflags) <<
+ " received. Reset packet is sent.");
SendRST ();
}
CloseAndNotify ();
@@ -1396,7 +1399,7 @@
}
else if (tcpflags != TcpHeader::RST)
{ // Receive of SYN or SYN+ACK or bad flags or pure data
- NS_LOG_LOGIC ("Illegal flag " << tcpflags << " received. Reset packet is sent.");
+ NS_LOG_LOGIC ("Illegal flag " << TcpHeader::FlagsToString (tcpflags) << " received. Reset packet is sent.");
SendRST ();
}
CloseAndNotify ();
@@ -1433,7 +1436,7 @@
}
else
{ // Received a SYN or SYN+ACK or bad flags
- NS_LOG_LOGIC ("Illegal flag " << tcpflags << " received. Reset packet is sent.");
+ NS_LOG_LOGIC ("Illegal flag " << TcpHeader::FlagsToString (tcpflags) << " received. Reset packet is sent.");
SendRST ();
CloseAndNotify ();
}
@@ -1911,7 +1914,8 @@
(Simulator::Now () + m_rto.Get ()).GetSeconds () );
m_retxEvent = Simulator::Schedule (m_rto, &TcpSocketBase::ReTxTimeout, this);
}
- NS_LOG_LOGIC ("Send packet via TcpL4Protocol with flags 0x" << std::hex << static_cast<uint32_t> (flags) << std::dec);
+ NS_LOG_LOGIC ("Send packet via TcpL4Protocol with flags" <<
+ TcpHeader::FlagsToString (flags));
if (m_endPoint)
{
m_tcp->SendPacket (p, header, m_endPoint->GetLocalAddress (),