net/tcp: debug feature to drop the tx/rx packet

Add 2 configurations
1. Config to drop recived packet
CONFIG_NET_TCP_DEBUG_DROP_RECV=y
CONFIG_NET_TCP_DEBUG_DROP_RECV_PROBABILITY=50 /* Default drop probability is 1/50 */

2. Config to drop sent packet
CONFIG_NET_TCP_DEBUG_DROP_SEND=y
CONFIG_NET_TCP_DEBUG_DROP_SEND_PROBABILITY=50 /* Default drop probability is 1/50 */

Iperf2 client/server test on esp32c3:

---------------------------------------------------------
|  TCP Config            | Server | Client |            |
|-------------------------------------------------------|
|  Original              |   12   |     9  |  Mbits/sec |
|  Drop(1/50)            |  0.6   |   0.3  |  Mbits/sec |
|  Drop(1/50) + OFO/SACK |    8   |     8  |  Mbits/sec |
---------------------------------------------------------

Signed-off-by: chao an <anchao@xiaomi.com>
This commit is contained in:
chao an 2023-01-13 13:40:08 +08:00 committed by Xiang Xiao
parent 246a677045
commit 22348c890b
3 changed files with 98 additions and 0 deletions

View File

@ -233,4 +233,43 @@ config NET_SENDFILE
files out a TCP connection.
endif # NET_TCP && !NET_TCP_NO_STACK
if NET_STATISTICS
config NET_TCP_DEBUG_DROP_RECV
bool "TCP/IP debug feature to drop receive packet"
default n
---help---
This is the debug feature to drop TCP/IP received packet
if NET_TCP_DEBUG_DROP_RECV
config NET_TCP_DEBUG_DROP_RECV_PROBABILITY
int "TCP/IP drop probability of received packet"
range 50 10000
default 50
---help---
This is the drop probability of received packet, Default: 1/50
endif # NET_TCP_DEBUG_DROP_RECV
config NET_TCP_DEBUG_DROP_SEND
bool "TCP/IP debug feature to drop send packet"
default n
---help---
This is the debug feature to drop TCP/IP send packet
if NET_TCP_DEBUG_DROP_SEND
config NET_TCP_DEBUG_DROP_SEND_PROBABILITY
int "TCP/IP drop probability of send packet"
range 50 10000
default 50
---help---
This is the drop probability of send packet, Default: 1/50
endif # NET_TCP_DEBUG_DROP_SEND
endif # NET_STATISTICS
endmenu # TCP/IP Networking

View File

@ -628,6 +628,37 @@ found:
dev->d_len -= (len + iplen);
#if defined(CONFIG_NET_STATISTICS) && \
defined(CONFIG_NET_TCP_DEBUG_DROP_RECV)
#pragma message \
"CONFIG_NET_TCP_DEBUG_DROP_RECV is selected, this is debug " \
"feature to drop the tcp received packet on the floor, " \
"please confirm the configuration again if you do not want " \
"debug the TCP stack."
/* Debug feature to drop the tcp received packet on the floor */
if (dev->d_len > 0)
{
if ((g_netstats.tcp.recv %
CONFIG_NET_TCP_DEBUG_DROP_RECV_PROBABILITY) == 0)
{
uint32_t seq = tcp_getsequence(tcp->seqno);
g_netstats.tcp.drop++;
ninfo("TCP DROP RCVPKT: "
"[%d][%" PRIu32 " : %" PRIu32 " : %d]\n",
g_netstats.tcp.drop, seq, TCP_SEQ_ADD(seq, dev->d_len),
dev->d_len);
dev->d_len = 0;
return;
}
}
#endif
/* Check if the sequence number of the incoming packet is what we are
* expecting next. If not, we send out an ACK with the correct numbers
* in, unless we are in the SYN_RCVD state and receive a SYN, in which

View File

@ -575,6 +575,34 @@ void tcp_synack(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn,
/* Complete the common portions of the TCP message */
tcp_sendcommon(dev, conn, tcp);
#if defined(CONFIG_NET_STATISTICS) && \
defined(CONFIG_NET_TCP_DEBUG_DROP_SEND)
#pragma message \
"CONFIG_NET_TCP_DEBUG_DROP_SEND is selected, this is debug " \
"feature to drop the tcp send packet on the floor, " \
"please confirm the configuration again if you do not want " \
"debug the TCP stack."
/* Debug feature to drop the tcp received packet on the floor */
if ((flags & TCP_PSH) != 0)
{
if ((g_netstats.tcp.sent %
CONFIG_NET_TCP_DEBUG_DROP_SEND_PROBABILITY) == 0)
{
uint32_t seq = tcp_getsequence(tcp->seqno);
ninfo("TCP DROP SNDPKT: "
"[%d][%" PRIu32 " : %" PRIu32 " : %d]\n",
g_netstats.tcp.sent, seq, TCP_SEQ_ADD(seq, dev->d_sndlen),
dev->d_sndlen);
dev->d_len = 0;
}
}
#endif
}
/****************************************************************************