TCP IP(Network series blog 3)

shubham kumar singh
DevOps-Journey
Published in
4 min readDec 16, 2020

--

This is the third blog in the network series to include the details about TCP/IP. I believe this will be the most commonly used protocol on the internet. While it may not directly be used for communication, it is encapsulated under other protocols like HTTP(s)?, FTP, and SFTP, etc… We will try to cover the typical use of TCP/IP and compare the same with the OSI model.

CREDITS

Let's get started with details about TCP/IP. TCP is known as a transmission control protocol, which is a connection-oriented protocol unlike our friend UDP. This protocol relies on sequential data transfer and guarantees the delivery. While these may seem an essential thing, this adds a certain amount of complexities to the implementation as well.

OSI vs TCP/IP

A few things to know

  1. TCP keeps infomration about segments using sequence number. This number is a rondom generated starting number not nesseraly to be 0
  2. For every sequence number a corosponding acknolegement number is maintained. Acknoledgement number given by the receiver with below formula “the value of sequence number + bytes received + 1 “ to suggest sender to start sending next segment with above sequenec number.

Transmission Strategy

Unlike UDP, TCP/IP is a stream-oriented protocol. This means that it allows to send and receive data as a stream of bytes by creating a sending process and a receiving process. In order to manage that TCP/IP uses a concept of buffers, as it allocates a process to send and receive buffers. This is to ensure that system of both sides of tubes may not have the same set of resources.

Sending buffer:

  1. locations that can be filled by sending process (W)
  2. bytes to be sent (P)
  3. bytes that have been sent but not yet acknowledged (B)

Receiving buffer:

  1. locations to be filled by bytes received from the network (W)
  2. bytes to be consumed by receiving process (P)

A little more about segments

In OSI model, we covered some details around segments; however, there is still a lot to cover. To start with lets presume we are sending data, in that case tcp created group of bytes together in a segement before passing it down to IP layer. IP layer handles the data in the set of packets, and starts transmissing it. Segments are not in the same size for reasons mentioned below:

  1. Packets should not be too small as TCP/IP has its own headers of 20 bytes each.
  2. Packets should not be too large, max limit is 65,535 bytes

TCP Flow control

TCP flow-control is used to control the amount of data that sender and send and match the speed of which receiver and receive the data.

Sender Window

TCP uses a concept called sliding window to understand if receiver can receive the data.

Here sender is responsible to move its points (left and right ) based on the acknowledgement received. So in this case the left pointer shall move for data sent, that is in PINK, while right pointer shall move for acknowdelgement.

Receiver window

A variable that is tranmitted with ack to give sender information about how much data can receiver take in. Such variable is required to ensure that sender is not sending too much data that receiver can’t take or overwhelm the network.

  1. RcvBuffer is allocated upon connection establishment — buffer size = buffer size = RcvBuffer
  2. As the receiver starts receiving in sequence data in buffer, spare room in buffer = RcvWindow = RcvBuffer — [Last Byte Received — Last Byte ]
  3. Then receiver acknowledges that by placing RcvWindow as window size in tcp headers i.e. available buffer space.

With this in mind sender window can be operated to send accounted data that receiver can receive.

However, there is special condition when receiver wants the window to be closed. In that instance it send the windowsize=0. This can happen if receiver buffer is completly full. Things to notice here is

  1. It is possible that receiver does not have anythigng to send back to sender. In this event sender remains unknown about when/if it has to startign sending again i.e. receiver window is open.
  2. In this case sender send 1-byte data to which receiver can acknowlege and re-initiate the window-size.

TCP Error control

TBD (Work in progress)

--

--

shubham kumar singh
DevOps-Journey

Googler | Cloud computing| Kubernetes | Containers | Monitoring | Python