Search code examples
tcpfreertosflow-controllwip

flow control implementation - how


I'm sending 1k data using TCP/IP (using FreeRTOS + LwiP). From documents I understood that TCP/IP protocol has its flow control inside its stack itself, but this flow control is dependent on the Network buffers. I'm not sure how this can be handled in my scenario which is described below.

  1. Receive data of 1k size using TCP/IP from wifi (this data rate will be in 20Mb/s)

  2. The received Wifi data is put into a queue of 10k size10 block, each block having a size of 1K

  3. From the queue, each block is taken and send to another interface at lower rate 1Mb/s

So in this scenario, do I have to implement flow control manually between data from wifi <-> queue? How can I achieve this?


Solution

  • No you do not have to implement flow control yourself, the TCP algorithm takes care of it internally.

    Basically what happens is that when a TCP segment is received from your sender LwIP will send back an ACK that includes the available space remaining in its buffers (the window size). Since the data is arriving faster than you can process it the stack will eventually send back an ACK with a window size of zero. This tells the sender's stack to back off and try again later, which it will do automatically. When you get around to extracting more data from the network buffers the stack should re-ACK the last segment it received, only this time it opens up the window to say that it can receive more data.

    What you want to avoid is something called silly window syndrome because it can have a drastic effect on your network utilisation and performance. Try to read data off the network in big chunks if you can. Avoid tight loops that fill a buffer 1-byte at a time.