Flow Control Using UDP in Linux

Problem

Flow control mechanism is needed by tools which transfer data faster than its data consuming mechanism. Practically, it transfers data quickly, but consumes data slowly. Flow control happens in layer data link.

Conditions:

  • There are two programs which are transmitter and receiver.
  • Sender: sending messages
  • Receiver: receiving messages
  • Sender sends messages too fast
  • Receiver consumes messages too slow

Solution: Buffering

Issue: buffering does not solve the exact problems, it only holds overflow and overrun.

Alternatives:

  • Feedback-based flow control
  • Rate-based flow control (discussed later)

Feedback-based flow control

It works by opening and closing the way of input data. Method used is XON/XOFF which is common method to control data flow. We denote XON and XOFF as ASCII number which are 0x11 and 0x13, respectively.

Transmitter (sender) has to identify two characters and react when receive the characters. On the other side, receiver has to identify buffer condition to send XON/XOFF to transmitter.

Illustration is shown below:

Transmitter Receiver
Send byte 1: ‘H’ Receive byte 1: ‘H’
Send byte 2: ‘e’ Receive byte 2: ‘e’
Send byte 3: ‘l’ Consume byte 1: ‘H’
Send byte 4: ‘l’ Receive byte 3: ‘l’
Send byte 5: ‘o’ Receive byte 4: ‘l’
Send byte 6: ‘ ’ Consume byte 2: ‘e’
Send byte 7: ‘w’ Receive byte 5: ‘o’
Send byte 8: ‘o’ Receive byte 6: ‘ ’
Noticed XOFF Consume byte 3: ‘l’
Waiting for XON Receive byte 7: ‘w’
Waiting for XON Receive byte 8: ‘o’

The implementation in C can be found here https://github.com/masphei/flow-control-udp

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s