0% found this document useful (0 votes)
15 views48 pages

Unite5 Part 2 TCP

Uploaded by

payuuu567
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views48 pages

Unite5 Part 2 TCP

Uploaded by

payuuu567
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 48

23-3 Transmission Control Protocol (TCP)

• TCP is a connection-oriented protocol; it creates a virtual connection between two


transport entities at two different devices to send and receive data.

• In addition, TCP uses flow and error control mechanisms at the transport level.

Topics discussed in this section:

TCP Services
TCP Features
Segment
A TCP Connection
Flow Control
Error Control
Table 23.2 Well-known ports used by TCP
Figure 23.13 Stream delivery

• TCP is stream oriented protocol where the stream is of → bytes


• TCP allows sending process to deliver data as a stream of bytes
• Similarly, receiving process obtains data as a stream of bytes
• TCP at both ends creates imaginary tube for flow or stream of
bytes
Figure 23.14 Sending and receiving buffers

Circular
Buffer

• Since sending and receiving processes may not write or read at same
time thus TCP employs buffers
• Two buffers – sending buffer and receiving buffer (duplex mode)
• Grey section → sent bytes but not ack, Red section → bytes to be sent,
& white → empty buffer’s byte-space that can be filled by process
Figure 23.15 TCP segments

• TCP forms segments by grouping together number of bytes plus


putting its header
• Such segments formed need not to be of same sizes
Note

The bytes of data being transferred in


each connection are numbered by TCP.
The numbering starts with a randomly
generated number.
Example 23.3

Suppose a TCP connection is transferring a file of 5,000


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 1,000 bytes?

Solution
The following shows the sequence number for each
segment:
Note

The value in the sequence number field


of a segment defines the
number of the first data byte
contained in that segment.
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.
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.
• If the acknowledgment number received is 2450 then
• Which are the bytes that have been successfully
acknowledged at the sender?
• What is the next sequence number the receiver is expecting?
Figure 23.16 TCP segment format

Mandatory
20 Bytes
Part

Optional
40 Bytes
Part
 Source Port Address:
 This is a 16-bit field that defines the port number of the application program
in the host that is sending the segment
 Destination Port Address:
 This is a 16-bit field that defines the port number of the application program
in the host that is receiving the segment
 Sequence number:
 This 32-bit field defines the number assigned to the first byte of data
contained in this segment
 Acknowledgment Number:
 This 32-bit field defines the byte number that the receiver of the segment is
expecting to receive from the other party
 Acknowledgment is piggybacked with the data
 HLEN: (Header length since the size of header is variable – 20 to 60 B)
 This 4-bit field indicates the number of 4-byte words in the TCP header
 The length of the header can be between 20 and 60 bytes
 Therefore, the value of this field can be between 20/4 = 5 and 60/4 = 15
 Reserved:
 This is a 6-bit field reserved for future use
Figure 23.17 Control field
Control Fields
Push Control Bit
• The application program (i.e., process) at the sender can request a push
operation. This means that the sending TCP must not wait for the window to
be filled. It must create a segment and send it immediately.

• The sending TCP must also set the push bit (PSH) to let the receiving TCP
know that the segment includes data that must be delivered to the receiving
application program as soon as possible and not to wait for more data to come.
Control Fields
 URG: Urgent pointer value is valid
 ACK: Acknowledgment No. value is valid
 PSH: Push the buffered data to the receiving
 RST: Reset the connection
 SYN: Synchronize the sequence number (only first packet)
 FIN: No more data from the sender
 Window Size:
 This field defines the size of the window, in bytes, that the other party must
follow (dynamic buffer management)
 Checksum:
 This 16-bit checksum field is mandatory for TCP.
 Urgent Pointer:
 This l6-bit field, which is valid only if the urgent flag is set, is used when the
segment contains urgent data
 It defines the number that must be added to the sequence number to obtain
the number of the last urgent byte in the data section of the segment.
Connection Establishment
• TCP transmits data in full-duplex mode

• Each party must initialise communication and get approval from the other
party before any data are transferred

• It uses three way handshaking protocol


Connection Establishment (1)
1. In example of client - server communication, first server will start
passively open connection by LISTEN and ACCEPT by specifying
either specific source or nobody

2. Client will execute CONNECT primitive by specifying IP, port number


and other necessary parameters.

3. When segment arrives at the destination

4. TCP will check, is there any process listening on the port specified by
Destination Port address

5. If yes, then TCP segment will be given to process

6. Process can either accept or reject

7. If it accept, the acknowledgement segment will be sent back


Phase 1: Connection Establishment Using Three-way Handshake

seq: 8000

UAPRS F
SYN
seq: 15000
ack: 8001
nd: 5000
U A P R S F rw
SYN + ACK
seq: 8000
ack: 15001
UAPRS F
rwnd: 10000
ACK
Means “no data” !
IF seq# = 8001 then it means carrying data
Chapter 15, TCP/IP Protocol by Forouzan AMK, CCE, MUJ
Phase 1: Connection Establishment Using Three-way Handshake

Chapter 15, TCP/IP Protocol by Forouzan AMK, CCE, MUJ


Phase 1: Connection Establishment Using Three-way Handshake

seq: 8000

UAPRS F
SYN

Chapter 15, TCP/IP Protocol by Forouzan AMK, CCE, MUJ


Phase 1: Connection Establishment Using Three-way Handshake

seq: 8000

UAPRS F
SYN
seq: 15000
ack: 8001
nd: 5000
U A P R S F rw
SYN + ACK

Chapter 15, TCP/IP Protocol by Forouzan AMK, CCE, MUJ


Phase 1: Connection Establishment Using Three-way Handshake

seq: 8000

UAPRS F
SYN
seq: 15000
ack: 8001
nd: 5000
U A P R S F rw
SYN + ACK
seq: 8000
ack: 15001
UAPRS F
rwnd: 10000
ACK

Chapter 15, TCP/IP Protocol by Forouzan AMK, CCE, MUJ


Phase 1: Connection Establishment Using Three-way Handshake

seq: 8000

UAPRS F
SYN
seq: 15000
ack: 8001
nd: 5000
U A P R S F rw
SYN + ACK
seq: 8000
ack: 15001
UAPRS F
rwnd: 10000
ACK
Means “no data” !
IF seq# = 8001 then it means carrying data
Chapter 15, TCP/IP Protocol by Forouzan AMK, CCE, MUJ
Client -> Server
This is synchronisation of sequence
number

A SYN segment cannot carry no real data,


but it consumes one sequence number.
Server -> Client
It is a SYN segment for communication in
the other direction and also the
acknowledgment for the SYN segment.
A SYN + ACK segment cannot
carry data, but does consume one
sequence number.
Client -> Server

Segment with the ACK flag and


acknowledgment number field

An ACK segment, if carrying no data,


consumes no sequence number.
Figure 23.19 Data transfer using three-way handshaking
Figure 23.20 Connection termination using three-way handshaking
Note

The FIN segment consumes one


sequence number if it does
not carry data.
Note

The FIN + ACK segment consumes


one sequence number if it
does not carry data.
Connection Establishment
• Simultaneous Open:
• A rare situation
• may occur when both processes issue an active open.
• In this case, both TCPs transmit a SYN + ACK segment to each other
• one single connection is established between them, because connections
are identified by both end-points
• SYN flood attack:
• happens when an attacker sends a large number of SYN segment
• pretend that each segment is coming from different host
• sever will allocate resources to each segment
• denial - of - service attack
• can limit the no. of connection for specified period
• filter segments from unwanted sources
• postpone resource allocation until connection set-up
Figure 23.21 Half-close
Flow Control
• TCP uses sliding window protocol

• It is somewhere between Go-back-N and Selective


Repeat
• It is not using NAK
• Receiver holds out-of-order segments until missing
one is arrived

• Sliding window is byte-oriented instead of Frame


oriented

• Window is of variable size instead of fixed size (i.e.,


dynamic)
Figure 23.22 Sliding window
• Window spans a portion of the buffer containing bytes received from the process
• The bytes inside the window are the bytes that can be in transit; they can be sent
without worrying about acknowledgment
• The window is opened, closed, or shrunk.
• These three activities are in the control of the receiver
• Sender’s window closes when it receives ACK from receiver
• Sender’s window opens when it receives higher rwnd from receiver
• rwnd = receiver window and cwnd = congestion window
• Window size is minimum of (rwnd, cwnd)
Example 23.4

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.
Example 23.5

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.
Example 23.6

Figure 23.23 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.
Figure 23.23 Example 23.6
Conti…
• Some points about TCP sliding windows:
• Window size is lesser of (rwnd, cwnd)

• Source does not have to send a full window’s worth of data

• The window can be opened or closed by the receiver, but should not be shrunk

• The destination can send an ack. at any time as long as it does not result in a
shrinking window
Error Control
• For reliable delivery of message, application layer is
relies on TCP to deliver the entire stream reliably

• TCP uses error control. In include mechanism for


detecting corrupted segments, lost segments, out-of-
order segments and duplicated segments

• Three simple tools are use:


• Checksum
• Acknowledgment
• Time-out
Conti…
• Retransmission
• It is heart of error control mechanism

• When a segment is corrupted, lost or delayed, it is


retransmitted

• In modern implementations, a retransmission occurs if


• The retransmission timer expires
• Three duplicate ACK segments have arrived

• No retransmission for segment that do not consume


sequence number
Conti…
• Retransmission after RTO (Retransmission
Time Out)

• Retransmission after three duplicate ACK:


• After Receiving out-of-order segments,
receiver will send 3 ACKs to sender
• Sender will send missing segment
immediately
• Out-of-order
Figure 23.24 Normal operation
Figure 23.25 Lost segment
Note

The receiver TCP delivers only ordered


data to the process.
Figure 23.26 Fast retransmission

You might also like