Part 2 6.4 User Datagram Protocol (UDP) 6.5 Transmission Control Protocol (TCP)
1
The Internet model has three protocols at the transport layer: UDP, TCP & SCTP The UDP is the simplest of the three. The TCP is a complex transport layer protocol. The SCTP is the new transport layer protocol that is designed for multihomed, multistream applications such as multimedia. 2
Position of UDP, TCP, and SCTP in TCP/IP suite
3
6.4: USER DATAGRAM PROTOCOL (UDP)
The User Datagram Protocol (UDP) is called a connectionless, unreliable transport protocol. It does not add anything to the services of IP except to provide process-to-process communication instead of host-to-host communication.
4
UDP is a simpler protocol compared to TCP. It has no connection, flow control, congestion control, sequencing, packet acknowledgement and reliability. There is no control mechanism for detecting lost packets, out-of-order packets and duplicate packets. It only provides error control for detecting corrupted packets using checksum. Processes which involved sending small message or do not care about reliability can use UDP. It is used by application protocols such as TFTP, SNMP, RTP and etc. UDP is also a suitable transport protocol for multicasting of real time multimedia. In transport layer of TCP/IP model. 5
Well-known ports used with UDP
Some ports number can be used by both UDP and TCP. 6
User datagram format
Source port number: the port number used by the process running on the source host. Destination port number: the port number used by the process running on the destination Check sum: detects errors over the entire user datagram, (header+data) Length: defines the total length of the user datagram, (header+data)
7
Note UDP length = IP length – IP header’s length
8
Pseudoheader for checksum calculation
The pseudoheader is a part of the header of the IP packet in which the user datagram is to be encapsulated with some fields filled with 0s. 9
Example 1 The next figure shows the checksum calculation for a very small user datagram with only 7 bytes of data. Because the number of bytes of data is odd, padding is added for checksum calculation. The pseudoheader as well as the padding will be dropped when the user datagram is delivered to IP.
10
Checksum calculation of a simple UDP user datagram
11
6.5: TCP
TCP is a connection-oriented protocol; it creates a virtual connection between two TCPs to send data. In addition, TCP uses flow and error control mechanisms at the transport level.
12
Well-known ports used by TCP
Like UDP, TCP provides process to process communication using port numbers. 13
Stream delivery TCP creates an environment in which the two processes seem to be connected by an imaginary ‘tube’ that carries their data across the Internet.
The sending process produces (write to) the stream of bytes, and the receiving Produces consumes (reads from) them.
14
Sending and receiving buffers
TCP needs buffers for storage because the sending and receiving may not write or read data at the same speed. 15
TCP segments The IP layer needs to send data in packets, not as stream of bytes.
At the transport layer- TCP groups a number of bytes together into a packet:segment, adds a header to each segment (for control purposes) and delivers the segment to the IP layer for transmission. 16
Note The bytes of data being transferred in each connection are numbered by TCP. The numbering starts with a randomly generated number.
17
Example 2 Suppose a TCP connection is transferring a file of 5000 bytes. The first byte is numbered 10,001. What are the sequence numbers for each segment if data are sent in five segments, each carrying 1000 bytes? Solution: The following shows the sequence number for each segment:
18
Note The value in the sequence number field of a segment defines the number of the first data byte contained in that segment.
19
Note The value of the acknowledgment field in a segment defines the number of the next byte a party expects to receive. The acknowledgment number is cumulative.
20
TCP segment format
21
Control field
These bits enable flow control, connection establishment and termination, connection abortion, and the mode of data transfer in TCP.
22
Description of flags in the control field
23
TCP Connection
Connection oriented transmission requires three phases: connection establishment, data transfer and connection termination. Connection establishment requires three-way handshaking; connection termination requires three- or four-way handshaking with a half-close option.
24
Connection establishment using three-way handshaking Phase 1:
25
Note A SYN segment cannot carry data, but it consumes one sequence number.
26
Note A SYN + ACK segment cannot carry data, but does consume one sequence number.
27
Note An ACK segment, if carrying no data, consumes no sequence number.
28
Data transfer Phase 2:
29
Connection termination using three-way handshaking Phase 3:
30
Note The FIN segment consumes one sequence number if it does not carry data.
31
Note The FIN + ACK segment consumes one sequence number if it does not carry data.
32
Half-close
Half-close: One end can stop sending data while still receiving data 33
Flow Control The sliding window is of TCP is of variable size and a byte-oriented.
The size of the window at one end is determined by the lesser of two values: receiver window (rwnd) or congestion window (cwnd)
34
Note A sliding window is used to make transmission more efficient as well as to control the flow of data so that the destination does not become overwhelmed with data. TCP sliding windows are byte-oriented.
35
Example 3 What is the value of the receiver window (rwnd) for host A if the receiver, host B, has a buffer size of 5000 bytes and 1000 bytes of received and unprocessed data?
Solution The value of rwnd = 5000 − 1000 = 4000. Host B can receive only 4000 bytes of data before overflowing its buffer. Host B advertises this value in its next segment to A.
36
Example 4 What is the size of the window for host A if the value of rwnd is 3000 bytes and the value of cwnd is 3500 bytes?
Solution The size of the window is the smaller of rwnd and cwnd, which is 3000 bytes.
37
Example 5 The next figure shows an unrealistic example of a sliding window. The sender has sent bytes up to 202. We assume that cwnd is 20 (in reality this value is thousands of bytes). The receiver has sent an acknowledgment number of 200 with an rwnd of 9 bytes (in reality this value is thousands of bytes). The size of the sender window is the minimum of rwnd and cwnd, or 9 bytes. Bytes 200 to 202 are sent, but not acknowledged. Bytes 203 to 208 can be sent without worrying about acknowledgment. Bytes 209 and above cannot be sent.
38
39
Note Some points about TCP sliding windows: The size of the window is the lesser of rwnd and cwnd. The source does not have to send a full window’ sworth of data. The window can be opened or closed by the receiver, but should not be shrunk. The destination can send an acknowledgment at any time as long as it does not result in a shrinking window. The receiver can temporarily shut down the window; the sender, however, can always send a segment of 1 byte after the window is shut down. 40
Note ACK segments do not consume sequence numbers and are not acknowledged.
41
Note In modern implementations, a retransmission occurs if the retransmission timer expires or three duplicate ACK segments have arrived.
42
Note No retransmission timer is set for an ACK segment.
43
Note Data may arrive out of order and be temporarily stored by the receiving TCP, but TCP guarantees that no out-of-order segment is delivered to the process.
44
Error Control
Error control is handled acknowledgement, and time-out.
by
the
checksum,
Corrupted and lost segments are retransmitted, and duplicate segments are discarded. Data may arrive out of order and are temporarily stored by the receiving TCP, but TCP guarantees that no out-oforder segment is delivered to the process.
45
Normal operation
46
Lost segment
47
Note The receiver TCP delivers only ordered data to the process.
48
Fast retransmission
49
Congestion Control
Congestion control refers to techniques and mechanisms that can either prevent congestion, before it happens, or remove congestion, after it has happened.
50
Slow start, exponential increase
51
Note In the slow-start algorithm, the size of the congestion window increases exponentially until it reaches a threshold.
52
Congestion avoidance, additive increase
53
Note In the congestion avoidance algorithm, the size of the congestion window increases additively until congestion is detected.
54
Note An implementation reacts to congestion detection in one of the following ways: If detection is by time-out, a new slow start phase starts. If detection is by three ACKs, a new congestion avoidance phase starts.
55
TCP congestion policy summary
56
TCP vs. UDP
TCP provides a reliable connection-oriented service, whereas UDP provides an unreliable connectionless service by delivering the UDP datagrams on a besteffort basis.
UDP is simpler than TCP. There is no connection, flow control, congestion control, sequencing, packet acknowledgement, and reliability required by UDP transmission.
57