When does TCP sends ACK? - tcp

I have an application and I am seeing packets being re-transmitted multiple times. connection is reset after multiple re-transmits.
In Wireshark, I can see the packet reaching the server, but I do not see the packet at the application level. I want to know how I can check if the packet is dropped at the TCP layer?
When does TCP send DATA packet ACK? After delivering the packet to an application or after receiving the DATA packet on the socket?

When does TCP send DATA packet ACK? After delivering the packet to an application or after receiving the DATA packet on the socket?
The ACK is sent by the OS after the data are successfully put into the sockets read buffer. No application logic is involved here yet.

Related

TCP Server sends [ACK] followed by [PSH,ACK]

I am working on a high-performance TCP server, and I see the server not processing fast enough on and off when I pump high traffic using a TCP client. Upon close inspection, I see spikes in "delta time" on the TCP server. And, I see the server sending an ACK and 0.8 seconds later sending PSH,ACK for the same seqno. I am seeing this pattern multiple times in the pcap. Can experts comment on why the server is sending an ACK followed by a PSH,ACK with a delay in between?
TCP SERVER PCAP
To simplify what ACK and PSH means
ACK will always be present, it simply informs the client what was the last received byte by the server.
PSH tells the client/server to push the bytes to the application layer (the bytes forms a full message).
The usual scenario you are used to, is more or less the following:
The OS has a buffer where it stores received data from the client.
As soon as a packet is received, it is added to the buffer.
The application calls the socket receive method and takes the data out of the buffer
The application writes back data into the socket (response)
the OS sends a packet with flags PSH,ACK
Now imagine those scenarios:
step 4 does not happen (application does not write back any data, or takes too long to write it)
=> OS acknowledge the reception with just an ACK (the packet will not have any data in it), if the application decides later on to send something, it will be sent with PSH,ACK.
the message/data sent by the server is too big to fit in one packet:
the first packets will not have PSH flag, and will only have the ACK flag
the the last packet will have the flags PSH,ACK, to inform the end of the message.

Server not getting duplicate ACKs

I am using raw sockets to communicate with a TCP server. For the purposes of my project, I need to emulate a TCP timeout.
Whenever a timeout occurs, server re-transmits the first lost packet. On receiving ACK for this packet, the sever re-transmits the second packet and also sends a packet that was previously unseen (due to F-RTO algorithm). In order to stop F-RTO, I need to send duplicate ACK for the later packet.
Lets says the congestion window is 20 at the time of time out. Server will send packet 1 and I will ACK packet 1. Server will then send packet 2 and packet 21. I will ACK packet 2 and send duplicate ACK for packet 21 to stop F-RTO. The problem that I am having is that although client is sending 2 ACKs, for some unknown reasons server is only getting one ACK. As a results it gets stuck in F-RTO.
Wireshark shows client sends multiple duplicate ACKs but from server side I can only see a single ACK. Since the second ACK is duplicate to first one, their fields and checksums are same. Can some one please help me out?

How to send exactly one Tcp packet unsing netperf/ipperf and confirm using tcpdump about the same?

I am trying to find out a way to send exactly one TCP packet and verify this on Rx side that same has been received (no other packet) using tcpdump. I am new to networking world. Hence any help/explaination would be much appreciated.
These tools are for performance measurements and not for packet crafting. They always establish a full TCP connection for measurements. Since even a TCP connection with no data transfer consists of 6 packets (initial handshake to establish connection and handshake for connection close) you will not be able to send a single TCP packet using these tools.
Just a thought - configure the Rx side NOT to accept a tcp-ip connection from the Tx side, then attempt a connection from Tx side. You should see a (single) SYN packet on the Rx side, to which it won't respond. [Unfortunately, the Tx side will then retry the SYN packet a number of times].

TCP sender sends more data packets in between retransmissions

I am facing a problem related to the TCP retransmissions.
My Sender starts sending some data to receiver (which is not in the network after opening the connection), after sending 3 packets, it retransmits first packet 3 times (as per the retransmission timeouts)and start sending next packets.
Then it retransmits first packet again. I am not able to understand this behavior and want to know if there is some way I can disable this and force TCP to retransmit first packet and then close the connection if no ack is received.
Thanks.
No there isn't. It's a streaming protocol, not a datagram protocol.

tcp application exit will send FIN always?

When a TCP application exits it will send a FIN packet.
Consider a tcp client which get connected to a always listening server(server never exits).
if the tcp client is exiting abruptly after few exchange of packets, will it always send a FIN packet to the server?
Thx!
Under normal operation , a FIN will be sent ,yes.
Here's a few cases where a FIN is not going to be sent.
Someone yanks out the network cable of the client.
The client gets nuked
The FIN packets are dropped on the way.
The OS on the kernel crashes hard.

Resources