TCP/IP-II

Transport Control Protocol (TCP)

· TCP is a connection oriented, reliable protocol used in internet to provide a reliable end- to-end byte stream over an unreliable internetwork (IP)

· An internetwork differs from a single network because different parts have different topologies, Bandwidths, Delays, Packet sizes and other parameters

· TCP has been designed to dynamically adapt to the properties of the internetwork.

· TCP is connection oriented, two processes hand shake each other to establish a connection

· Connection is established between two processes by initializing variables in a connection record called transmission control block (TCB).

· Connection is established bidirectional; hence data transfer takes place simultaneously in both directions.

· Stream Data Transfer:- transfers a contiguous stream of bytes across the network, with no indication of boundaries

· Doesn’t support multicasting or broadcasting.

· Uses selective repeat ARQ to implement reliability.

· A TCP connection is uniquely identified by 4 parameters:

1) Sender IP address

2) Sender port number

3) Receiver IP address

4) Receiver port number

Typically server is assigned a well known port number and client is assigned an ephemeral port number.

Port addresses

image_thumb

TCP Protocol

Source Port and Destination port:-The source and destination ports identify the sending and receiving applications.

Sequence number:- 32 bit sequence numbers are used for acknowledgements and window mechanism

The three phases of TCP communication are:-

1. TCP Connection establishment

2. Data transfer phase

3. TCP connection Termination

TCP Connection establishment

To establish a connection, TCP uses a three-way handshake. Before a client attempts to connect with a server, the server must first bind to a port to open it up for connections: this is called a passive open. Once the passive open is established, a client may initiate an active open.

To establish a connection, the three-way (or 3-step) handshake occurs:

1. The active open is performed by the client sending a SYN to the server.

2. In response, the server replies with a SYN-ACK.

3. Finally the client sends an ACK back to the server.

At this point, both the client and server have received an acknowledgment of the connection.

Example:

1. The initiating host (client) sends a synchronization packet (SYN flag set to 1) to initiate a connection. It sets the packet's sequence number to a random value x.

2. The other host receives the packet, records the sequence number x from the client, and replies with an acknowledgment and synchronization (SYN-ACK). The Acknowledgment is a 32-bit field in TCP segment header. It contains the next sequence number that this host is expecting to receive (x + 1). The host also initiates a return session. This includes a TCP segment with its own initial Sequence Number of value y.

3. The initiating host responds with the next Sequence Number (x + 1) and a simple Acknowledgment Number value of y + 1, which is the Sequence Number value of the other host + 1.

image_thumb[1]

 

Figure:- Three-way handshake

· Each SYN message during connection establishment can specify options such as maximum segment size (MSS), window scaling and time stamps.

· The three way handshake procedure ensures that both host’s agree on their initial sequence numbers.

Let us consider a situation why the initial sequence number must be different at every time and what happened if a host can always use the same initial sequence number.

image_thumb[2]

Figure: - Justifying a three way handshake: If a host always uses the same initial sequence, old segments cannot be distinguished from the current ones.

In above case, after connection is established, a delayed segment from the previous connection arrives.

Host B accepts this segment, since the sequence number is legal.

If a segment from current connection arrives later, it will be rejected by host B, thinking that the segment is a duplicate. Thus host B cannot distinguish a delayed segment from the new one.

The below figure is an example for client server application

image_thumb[3]

TCP Data Transfer

  • v TCP uses Selective Repeat ARQ protocol as sliding window mechanisms.
  • v TCP also applies flow control by dynamically advertising the window size (flow control is the mechanism of regulating the traffic between two points and is used to prevent the sender from overwhelming the receiver with too much data.
  • v In each TCP segment, the receiver specifies in the receive window field the amount of additional received data (in bytes) that it is willing to buffer for the connection.
  • v The sending host can send only up to that amount of data before it must wait for an acknowledgment and window update from the receiving host.

image_thumb[4]

Figure:-TCP Window flow control

The above figure illustrates an example for TCP Window flow control

  • Suppose at time t0, the TCP module in host B advertised a window of 2048 and expected next byte received to have a sequence number 2000. This advertised window size allows host A to transmit upto 2048 bytes of unacknowledged data.
  • At time t1, host A has only assumed 1024 bytes to transmits all the data starting with sequence number 2000, and this TCP entity also advertises a window of size 1024 bytes to host B and next byte expected to have a sequence number 1.
  • When the segment arrives, host B chooses to delay the acknowledgement for piggybacking (the technique of temporarily delaying outgoing acknowledgments so that they can be looked onto the next outgoing data frame is known as piggybacking). Meanwhile at t2, host A has another 1024 bytes of data and transmits it. After the transmission, A’s sending window closes completely. It is not allowed to transmit any more data until an acknowledgment comes back.
  • At time t3, host B has 128 bytes of data to transmit. Host B simply piggybacks the acknowledgment (ACK=4048) to the data segment. at this time also host B also advertises the window size of 512 bytes (because of some other connection the window size may shrink).
  • When host A receives the segment, at time t4, assume that host A has nearly 2048 bytes of data, but it is allowed only 512 bytes.

Like this, window advertisement dynamically controls the flow of data from one host to another and it prevents the receiver buffer from being overrun.

Nagle Algorithm

Situation: user types 1 character at a time

– Transmitter sends TCP segment per character (41B)

– Receiver sends ACK (40B)

– Receiver echoes received character (41B)

– Transmitter ACKs echo (40 B)

– 162 bytes transmitted to transfer 1 character!

• Solution:

– TCP sends data & waits for ACK

– New characters buffered

– Send new characters when ACK arrives

– Algorithm adjusts to RTT

• Short RTT send frequently at low efficiency

• Long RTT send less frequently at greater efficiency

Silly Window Syndrome

Situation:

  • Transmitter sends large amount of data
  • Receiver buffer depleted slowly, so buffer fills
  • Every time a few bytes read from buffer, a new advertisement to transmitter is generated
  • Sender immediately sends data & fills buffer
  • Many small, inefficient segments are transmitted
Solution:
  • Receiver does not advertise window until window is at least ½ of receiver buffer or maximum segment size
  • Transmitter refrains from sending small segments.
TCP Connection Termination
  • TCP provides two types of connection terminations i.e. graceful and abrupt termination.
  • A graceful termination can be initiated by an application, when it is having no more data to send.
  • The TCP entity completes transmission of its data and, upon receiving acknowledgement from the receiver, issues a segment with the FIN bit set.
  • Upon receiving the FIN segment, a TCP entity informs its application that other entity has terminated its transmission of data.

For example, in below figure,

  • The host A terminates its transmission by issuing a FIN segment.
  • Host B sends an ACK segment upon receiving the FIN segment from host A.
  • After B receives the FIN segment, host B sends 150 bytes of data in one segment, followed by FIN segment.
  • Host A sends then sends an acknowledgment.
  • Host A enters the TIME_WAIT state and starts TIME_WAIT timer with an initial value=2*MSL.
  • If such a FIN segment arrives while host A is the TIME_WAIT state, then the ACK segment is transmitted and the TIME_WAIT timer is restarted at 2MSL.
  • When TIME_WAIT timer expires, host A closes the connection.
image_thumb[5]
  • The second type of termination is an abrupt connection termination through reset (RST) segments.
  • If an application decides to terminate a connection abruptly, it issues an ABORT command, which causes TCP to discard any data that is queued for transmission and to send an RST segment.
  • The TCP that receives the RST segment then notifies its application process that the connection has been terminated.
TCP state Transition diagram

image_thumb[6]

Note: - thick solid line is normal state trajectory for a client and the dashed line is normal state trajectory for a server

  • A connection progresses through a series of states during its lifetime. The states are: LISTEN, SYN-SENT, SYNRECEIVED, ESTABLISHED, FIN-WAIT-1, FIN-WAIT-2, CLOSE-WAIT, CLOSING, LAST-ACK, TIME-WAIT, and the fictional state CLOSED.
  • CLOSED is fictional because it represents the state when there is no TCB, and therefore, no connection.

Briefly the meanings of the states are:

LISTEN represents waiting for a connection request from any remote TCP and port.

SYN-SENT represents waiting for a matching connection request after having sent a connection request.

SYN-RECEIVED represents waiting for a confirming connection request acknowledgment after having both received and sent a connection request.

ESTABLISHED represents an open connection, data received can be delivered to the user. The normal state for the data transfer phase of the connection.

FIN-WAIT-1 represents waiting for a connection termination request from the remote TCP, or an acknowledgment of the connection termination request previously sent.

FIN-WAIT-2 represents waiting for a connection termination request from the remote TCP.

CLOSE-WAIT represents waiting for a connection termination request from the local user. CLOSING represents waiting for a connection termination request acknowledgment from the remote TCP.

LAST-ACK represents waiting for an acknowledgment of the connection termination request previously sent to the remote TCP (which includes an acknowledgment of its connection termination request).

TIME-WAIT represents waiting for enough time to pass to be sure the remote TCP received the acknowledgment of its connection termination request.

CLOSED represents no connection state at all.

  • A TCP connection progresses from one state to another in response to events.
  • The events are the user calls, OPEN, SEND, RECEIVE, CLOSE, ABORT, and STATUS; the incoming segments, particularly those containing the SYN, ACK, RST and FIN flags; and timeouts.

TCP Congestion Control

  • TCP uses sliding window protocol for end-to-end flow control.
  • The receiver specifies in its acknowledgement (ACK) the amount of bytes it is willing to receive in advertised window. The advertised window ensures that the receiver’s buffer will never overflow, since
  • TCP uses a congestion window in the sender side to avoid congestion. The congestion window indicates the maximum amount of data that can be sent out on a connection without being acknowledged.
  • Advertised window size is used to ensure that receiver’s buffer will not overflow however, buffers at intermediate routers between source and destination may overflow
  • Congestion occurs when total arrival rate from all packet flows exceeds R over a sustained period of time.
  • Buffers at multiplexer will fill and packets will be lost.
  • Sources must control their sending rates so that aggregate arrival rate is just before knee.
  • TCP sender maintains a congestion window (cwnd) to control congestion at intermediate routers.
  • Effective window is minimum of congestion window and advertised window.
  • Problem: source does not know what its “fair” share of available bandwidth should be
  • Solution: adapt dynamically to available BW.
  • Sources probe the network by increasing cwnd.
  • When congestion detected, sources reduce rate, Ideally, sources sending rate stabilizes near ideal point
  • TCP detects congestion when it fails to receive an acknowledgement for a packet within the estimated timeout.
  • In such a situation, it decreases the congestion window to one maximum segment size (MSS), and under other cases it increases the congestion window by one MSS.
  • There also exists a congestion window threshold, which is set to half the congestion window size at the time when a re-transmit was required.

The operation of TCP congestion control algorithm may be divided into three phases and they are as follows:-

TCP Congestion Control: Slow Start

Slow start: increase congestion window size by one segment upon receiving an ACK from

receiver

  • initialized at ≤2 segments
  • used at (re)start of data transfer
  • congestion window increases exponentially
TCP Congestion Control: Congestion Avoidance
  • Algorithm progressively sets a congestion threshold
  • When cwnd > threshold, slow down rate at which cwnd is increased
  • Increase congestion window size by one segment per round-triptime (RTT)
  • Each time an ACK arrives cwnd is increased by 1/cwnd
  • In one RTT, cwnd segments are sent, so total increase in cwnd is cwnd x 1/cwnd = 1
  • cwnd grows linearly with time

Comments

Popular posts from this blog

Packet Switching Networks part2

TCP/IP-II:OSPF Link State Update

Packet Switching Networks:Traffic Management