Dec 1

How TCP achieves reliability?

TCP achieves this by two basic mechanisms. They are as follows:
Acknowledgments
       + receiver will send an acknowledgment, when the data arrives. (This is also called positive acknowledgment)
-
Retransmission
      + sender will start a timer when a packet is transmitted
      + if timer expires before the acknowledgment arrives, then the sender retransmits the packet.
   e.g.:

basic TCP connection



What happens when a packet is lost?
   

two


    Hence, the receiver should be prepared to handle duplicate packets. Offsets are used to handle duplicate packets.

    The maximum limit to wait for a packet is 256 seconds.



How long should TCP wait before retransmitting?


    A retransmitting timer is used to determine the time it should wait for acknowledgment. If this timer is too short then too many unnecessary retransmissions will occur (this is called aggressive retransmission), and will result in bad use of network bandwidth.

 three

 
    On the other hand, if the timer is too long then the total throughput will be very low in the presence of packet loss.

           four


    The optimal retransmission time should be a little bit longer than the roundtrip time.

           five


TCP’s adaptive retransmission.

-         TCP computes the round trip time using packets that have been acknowledged correctly.

-         The estimate of the round trip is done using a “moving average” that assigns more weight to recent samples.

Example:  New estimate of retransmission time =

0.8 * previous estimate + 0.2 * round trip time of current packet.

-         We take the average round trip time to calculate retransmission timer as network speed differs at different time of the day.

Retransmission timer = avg. round trip time + alpha (standard deviation)

    We use standard deviation as it gives us a better estimate.

 six

   Thus, TCP adapts the retransmission timer depending on round trip time. This feature fine tunes TCP so that it works well in a high speed LAN or in a slow connection like a modem 


TCP flow control

-         The sender slows down the transmission if the receiver is not fast enough consuming bytes.
e.g. of this situation: a web application, that is sending a big image, and your computer is slow at doing compression

-         The receiver will advertises to the sender the available buffer space called window

-         The sender can send upto an entire window size before an acknowledge arrives.

 

 

    The window size is included in the acknowledgement that the receiver sends back to the sender

 

    When window size = zero, the sender stops temporally.

 


 What happens if a packet is lost?


    The sender will send both the packets as when the sender receives acknowledgment 4500, it means either packet 4501 to 5500 was lost or both 4501 to 5500 and 5501 to 6000 was lost. Thus, cumulative acknowledgement is good as long as things go well.

 




Dec 3

TCP features

-         Adaptive retransmission

-         Flow control
window = receiver’s buffer size
window size is sent back to the sender in each acknowledgement

-         Cumulative acknowledgement


Cumukative Acknowledgement

The acknowledgement sent to the sender is for the bytes received correctly so far with no gaps.


Advantage of cumulative retransmission is that it reduces the total number of acknowledgements needed the disadvantage is that it may cause many unneeded packets to be sent when packets are lost.

The alternative to cumulative acknowledgement is “selective acknowledgement”, where we acknowledge the ranges of data that have been received. However, it is not implemented in the standard TCP.


Congestion Control

-         In TCP, when network is congested packets are dropped.

-         If packets are lost, TCP may retransmit more packets, making the congestion worse.

-         To alleviate this problem, TCP being a “nice protocol”, starts a congestion control mechanism when packets are lost.

-         In the presence of congestion, TCP “slows down” the transmission by sending only one packet.
Diagram

-         If the first packet is received correctly then it sends two packets, after that four and this continues until it reaches the full window size.

-         This mechanism is known as slow start. (the size of a packet depends on the network you are connected to)

-         In adaptive transmission, packets, which have been received without retransmission, are used to calculate round trip time.

-         TCP doesn’t have the “aggressive retransmission” policy of other protocols

-         For TCP packet loss = network congestion.
This is because TCP doesn’t know the reason for packet loss. Moreover, as in the internet most of the packets are lost due to network congestion, hence it assumes that packets are lost due to network congestion.


Reliable Connection Startup and Shutdown

-         Why connection startup/shutdown is difficult?
    + packet lost / duplicated, etc.
    + either side can crash
    + duplicate shutdown messages may affect later connections.

-         TCP uses “three way hand shake” for reliable connection startup and shutdown.
to open connection

to close connection


-        
Denial of service attack consists of sending syn packets (lots of them) to a specific machine causing all the available TCP connections in the destination machine to hang.





Dec 5

 TCP contd.

Congestion Control

    For congestion control, TCP uses “slow start”.
    When a packet is lost, TCP starts retransmitting by sending one packet. If this succeeds then two packets are sent and this continues until it sends half a window size. This is the exponential part of “slow start”.
    From now on TCP continues increases the total number pf packets sent by one until total window size is reached. This is the liner part of “slow start” and the following graph summarizes “slow start”.

 

 


TCP packet format

 

A TCP connection is defined by the following four parameters

<ip src, src port, ip dest, dest port>

 

Client ports can be assigned randomly by the kernel as long as the port it is assigning is not being used. Server ports are well known. ip src is included as two connections can have the same port

Sequence number

          It is the offset of the data contained in a packet.

The receiver will accept the data only if it is in the range from sequence number to sequence number + window size. Any data outside the window size is rejected by the receiver

The initial sequence number is generated randomly by the sender and is negotiated with the receiver during connection set up.

Sequence numbers do not start from zero. This is to prevent packets from previous connections that have the same four values be accepted in the current connection.

Also by default, a port number cannot be reused immediately after it has been closed. This makes more unlikely that a lost packet from a dead connection can be used in a current connection. This option can be overwritten for server ports.

Acknowledgement number

          Number of consecutive bytes that have been received correctly. (cumulative acknowledgement)

Hlen
   This is the header length. (In 4-byte units)

NU
  Bits not used

Code bits
   Will represent either SYN, FIN or ACK. SYN means start connection, FIN is for closing a connection and ACK means acknowledge field is valid. 

Checksum
   Contains the checksum of the data to detect possible corruption.

Urgent Pointer
   It is a pointer to indicate urgent data, which will be delivered before any other data
   e.g.: TELNET uses urgent data to send ctrl – c.