95
TCP/IP Protocol Suite 1 Chapter 12 Chapter 12 Upon completion you will be able to: Transmission Transmission Control Protocol Control Protocol Be able to name and understand the services offered by TCP Understand TCP’s flow and error control and congestion control Be familiar with the fields in a TCP segment Understand the phases in a connection-oriented connection Understand the TCP transition state diagram Be able to name and understand the timers used in TCP Objectives

TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

Embed Size (px)

Citation preview

Page 1: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 1

Chapter 12Chapter 12

Upon completion you will be able to:

TransmissionTransmissionControl ProtocolControl Protocol

• Be able to name and understand the services offered by TCP• Understand TCP’s flow and error control and congestion control• Be familiar with the fields in a TCP segment• Understand the phases in a connection-oriented connection• Understand the TCP transition state diagram• Be able to name and understand the timers used in TCP• Be familiar with the TCP options

Objectives

Page 2: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 2

Figure 12.1 TCP/IP protocol suite

TCP provides a set of services. What are those services?

Page 3: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 3

Table 12.1 Table 12.1 Well-known ports used by TCPWell-known ports used by TCP

TCP provides a process-to-process communication serviceusing port numbers.

Page 4: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 4

Figure 12.4 TCP segments

TCP provides a stream delivery service. It breaks up the data stream into segments of variable size. Each segment receivesa header and is handed off to the IP layer.

Page 5: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 5

Figure 12.4 TCP services and features

TCP can create a full-duplex service. Data can flow in bothdirections at the same time; buffers on each side hold thedata to be transmitted and sent.

TCP provides a connection-oriented service: the two TCPsestablish a connection, data is exchanged, and the connection isterminated.

TCP provides a reliable service.

Furthermore, TCP has a number of features.All bytes transferred are numbered by TCP. The numberingstarts with a random value.

Page 6: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 6

Suppose a TCP connection is transferring a file of 5000 bytes. The first byte is numbered 10001. What are the sequence numbers for each segment if data is sent in five segments, each carrying 1000 bytes?

Example 2

SolutionThe following shows the sequence number for each segment:

Segment 1 ➡ Sequence Number: 10,001 (range: 10,001 to 11,000)

Segment 2 ➡ Sequence Number: 11,001 (range: 11,001 to 12,000)

Segment 3 ➡ Sequence Number: 12,001 (range: 12,001 to 13,000)

Segment 4 ➡ Sequence Number: 13,001 (range: 13,001 to 14,000)

Segment 5 ➡ Sequence Number: 14,001 (range: 14,001 to 15,000)

Page 7: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 7

The value in the sequence number field of a segment defines the number

of the first data byte containedin that segment.

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.

Page 8: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 8

Figure 12.4 TCP services and features

TCP also provides flow control, error control, and congestioncontrol. We will examine each of these shortly.

Before we do, let’s examine the TCP header a little moreclosely.

The TCP packet is called a segment (but most people justcall it a packet).

Page 9: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 9

Figure 12.5 TCP segment format (packets in TCP are called segments)

Window size set by receiver with max = 65,535 bytes

Page 10: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 10

Figure 12.6 Control field

More on these bits later.

Page 11: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 11

Figure 12.7 Pseudoheader added to the TCP datagram to calculate checksum

Page 12: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 12

12.4 A TCP CONNECTION

TCP is connection-oriented. A connection-oriented transport protocol TCP is connection-oriented. A connection-oriented transport protocol establishes a virtual path between the source and destination. All of the establishes a virtual path between the source and destination. All of the segments belonging to a message are then sent over this virtual path. A segments belonging to a message are then sent over this virtual path. A connection-oriented transmission requires three phases: connection connection-oriented transmission requires three phases: connection establishment, data transfer, and connection termination.establishment, data transfer, and connection termination.

The topics discussed in this section include:The topics discussed in this section include:

Connection EstablishmentConnection EstablishmentData TransferData TransferConnection TerminationConnection TerminationConnection ResetConnection Reset

Page 13: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 13

Figure 12.9 Connection establishment using three-way handshaking

A server tellsits TCP that itis ready to makea connection - this is called apassive open.

+

rwnd is thereceiver windowsize, as we willsee later.

Note: SYN bitis set in firstpacket; 8000chosen randomly

Should this be 8001?

Page 14: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 14

A SYN segment cannot carry data, but it consumes one sequence number.

A SYN + ACK segment cannot carry data, but does consume one

sequence number.

An ACK segment, if carrying no data, consumes no sequence number.

Page 15: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 15

SYN flooding attack is when a bad person floods a server with bogus SYN

packets.

The server spends a lot of time and resources replying to the SYN packets.

To counter these attacks, some servers postpone resource allocation until the

entire connection is set up using a cookie.

Page 16: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 16

Figure 12.10 Data transfer

Notice how the ACK andSEQ # are piggybacked.

Push flag means deliverthe data to the receiveras soon as it is received(don’t put it in a bufferand hold until you haveenough bytes for acomplete segment).This feature is usuallyignored.

Can also send Urgentdata by setting the Urgbit. This data is thenprocessed immediately.For example, you wantto send a Ctrl-C to stop.

Page 17: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 17

Figure 12.11 Connection termination using three-way handshaking

A FIN segment consumes one sequence number if it does not carry data. So should third segment be seq: x+1?

Page 18: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 18

Figure 12.12 Half-close

Client is finished,but Server is not yetfinished. So ServerACKs the Client’s FIN,but does not signal itsown FIN just yet.

y-1

x+1

Page 19: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 19

Connection Reset

Using the Reset flag (RST), one can:

• Deny a request for a connection

• Abort a current connection

• Terminate an idle connection

Page 20: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 20

12.5 STATE TRANSITION DIAGRAM

To keep track of all the different events happening during connection To keep track of all the different events happening during connection establishment, connection termination, and data transfer, the TCP establishment, connection termination, and data transfer, the TCP software is implemented as a finite state machine. . software is implemented as a finite state machine. .

The topics discussed in this section include:The topics discussed in this section include:

ScenariosScenarios

Page 21: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 21

Table 12.3 Table 12.3 States for TCPStates for TCP

Page 22: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 22

Figure 12.13 State transition diagram

Page 23: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 23

Figure 12.14 Common scenario

Page 24: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 24

The common value for MSL is between 30 seconds and 1 minute.

Note:Note:

Page 25: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 25

Figure 12.15 Three-way handshake

Page 26: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 26

Figure 12.16 Simultaneous open

Page 27: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 27

Figure 12.17 Simultaneous close

Page 28: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 28

Figure 12.18 Denying a connection

Page 29: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 29

Figure 12.19 Aborting a connection

Page 30: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 30

12.6 FLOW CONTROL

Flow control regulates the amount of data a source can send before Flow control regulates the amount of data a source can send before receiving an acknowledgment from the destination. TCP defines a receiving an acknowledgment from the destination. TCP defines a window that is imposed on the buffer of data delivered from the window that is imposed on the buffer of data delivered from the application program. application program.

The topics discussed in this section include:The topics discussed in this section include:

Sliding Window ProtocolSliding Window ProtocolSilly Window SyndromeSilly Window Syndrome

Page 31: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 31

Figure 12.20 Sliding window

rwnd is the receiver window size; cwnd is the congestionwindow size

Page 32: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 32

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’s sliding windows are byte oriented.

Note:Note:

Page 33: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 33

What is the value of the receiver window (rwnd) for host A if the receiver, host B, has a buffer size of 5,000 bytes and 1,000 bytes of received and unprocessed data?

Example 3

SolutionThe value of rwnd = 5,000 − 1,000 = 4,000. Host B can receive only 4,000 bytes of data before overflowing its buffer. Host B advertises this value in its next segment to A.

Page 34: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 34

What is the size of the window for host A if the value of rwnd is 3,000 bytes and the value of cwnd is 3,500 bytes?

Example 4

SolutionThe size of the window is the smaller of rwnd and cwnd, which is 3,000 bytes.

Page 35: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 35

Figure 12.21 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 yet acknowledged. Bytes 203 to 208 can be sent without worrying about acknowledgment. Bytes 209 and above cannot be sent.

Example 5

Page 36: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 36

Figure 12.21 Example 5

Next, the server receives a packet with an acknowledgment value of 202 and an rwnd of 9. The host has already sent bytes 203, 204, and 205. The value of cwnd is still 20. Show the new window.

Page 37: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 37

Figure 12.22 Example 6

Next, the sender receives a packet with an acknowledgment value of 206 and an rwnd of 12. The host has not sent any new bytes. The value of cwnd is still 20. Show the new window.

Page 38: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 38

Figure 12.23 Example 7

Assume the sender has sent bytes 206 to 209. The sender’s window shrinks accordingly.

Now the sender receives a packet with an acknowledgment value of 210 and an rwnd of 5. The value of cwnd is still 20. Show the new window.

Page 39: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 39

Figure 12.24 Example 8

Page 40: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 40

How can the receiver avoid shrinking the window in the previous example?

Example 9

SolutionThe receiver needs to keep track of the last acknowledgment number and the last rwnd. If we add the acknowledgment number to rwnd we get the byte number following the right wall. If we want to prevent the right wall from moving to the left (shrinking), we must always have the following relationship.

new ack + new rwnd ≥ last ack + last rwndor

new rwnd ≥ (last ack + last rwnd) − new ack

Page 41: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 41

To avoid shrinking the sender window, the receiver must wait until more space

is available in its buffer.

Window Shutdown

While you shouldn’t shrink the window, you can send rwnd = 0 to close the window. Sender can still

send a “probe” packet.

Page 42: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 42

Some points about TCP’s sliding windows:

❏ The size of the window is the lesser of rwnd and cwnd.❏ The 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 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 one byte after the window is shut down.

Note:Note:

Page 43: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 43

Figure 12.24 Silly Window Syndrome

Silly Window Syndrome - What if TCP sends segments that areonly 1 byte long? You would have 40 bytes of header, 1 byteof data, for a total of 41 bytes. Very wasteful!

TCP should wait until it has more data before it sends a 1-bytesegment. But how long should it wait to assemble data?

Nagle’s Algorithm:1. The sending TCP sends the first piece of data it receivesfrom the sending application even if it is only 1 byte.2. After sending the first segment, the sending TCP accumulatesdata in the output buffer and waits until either the receivingTCP sends an ack or until enough data has accumulated to filla maximum-size segment. At this time, the sending TCP cansend the segment.3. Step 2 is repeated for the rest of the transmission.

Page 44: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 44

Figure 12.24 Silly Window Syndrome

Silly Window Syndrome - What happens if the receiving TCPhas a buffer size of 1000 bytes and the sending TCP has justsent 1000 bytes. The receiving buffer is now full so the receivertells the sender to stop (window size = 0).

The receiver now reads 1 byte of data, processes it, and sendsa window size of 1 (because now there is one space in the input buffer). The sender gets the window size and sends 1byte. This procedure continues.

Clark’s Solution - Acknowledge receipt right away, but don’tchange the window size until you have at least half the bufferspace available.

Or, delay the ack until there is a decent amount of buffer spaceavailable.

Page 45: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 45

12.7 ERROR CONTROL

TCP provides reliability using error control, which detects corrupted, TCP provides reliability using error control, which detects corrupted, lost, out-of-order, and duplicated segments. Error control in TCP is lost, out-of-order, and duplicated segments. Error control in TCP is achieved through the use of the checksum, acknowledgment, and time-achieved through the use of the checksum, acknowledgment, and time-out. out.

The topics discussed in this section include:The topics discussed in this section include:

ChecksumChecksumAcknowledgmentAcknowledgmentAcknowledgment TypeAcknowledgment TypeRetransmissionRetransmissionOut-of-Order Segments Out-of-Order Segments Some ScenariosSome Scenarios

Page 46: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 46

TCP Error Control

TCP supports basic error control.

It uses a 16-bit arithmetic checksum, similar to the oneswe have already seen.

TCP uses the ACK message to confirm receipt of segments.

There are a number of basic rules pertaining to ACKs:

Rule 1: When one ends sends data, it must piggyback theACK for any data received. (Example in just a moment)

Rule 2: If a receiver has no data to send and a segmentarrives, do not ACK it immediately. Wait until two segmentsarrive, then ACK. Or wait 500 ms after the first segment then ACK.

Page 47: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 47

Figure 12.25 Normal operation

Page 48: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 48

TCP Error Control

Rule 3: When a segment arrives with an expected sequencenumber and the previous in-order segment has not beenACKed, the receiver immediately sends an ACK. (Exampleon previous slide)

Rule 4: When a segment arrives with a sequence numberhigher than expected, the receiver immediately sends anACK announcing the sequence number it expected. Thisleads to fast retransmission, which we will see shortly.

Rule 5: When a missing segment arrives, the receiver sendsan ACK segment to announce the sequence number expected. This informs the receiver that segments reportedmissing have been received. (Example on next slide)

Rule 6: If a duplicate segment arrives, receiver immediatelysends an ACK. This solves some problems when an ACKitself is lost. (Example on next slide)

Page 49: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 49

Figure 12.26 Lost segment

Page 50: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 50

TCP Error Control

Furthermore, a retransmission will occur if the retransmissiontimer (RTO) expires, or three duplicate ACKs arrive in order.

(For RTO example, see previous slide.)

(For three ACKs, see next slide.)

Page 51: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 51

Figure 12.27 Three ACKs in a row, fast retransmission

Page 52: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 52

Figure 12.28 Lost acknowledgment

Page 53: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 53

Figure 12.29 Lost acknowledgment corrected by resending a segment

Page 54: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 54

12.8 CONGESTION CONTROL

Congestion control refers to the mechanisms and techniques to keep the Congestion control refers to the mechanisms and techniques to keep the load below the capacity. load below the capacity.

The topics discussed in this section include:The topics discussed in this section include:

Network PerformanceNetwork PerformanceCongestion Control MechanismsCongestion Control MechanismsCongestion Control in TCPCongestion Control in TCP

Page 55: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 55

Figure 12.30 Router queues

Page 56: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 56

Figure 12.31 Packet delay and network load

Page 57: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 57

Figure 12.32 Throughput versus network load

Page 58: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 58

Generic Types of Congestion Control

Open loop - no feedback used; try to control congestion before it happens

Retransmission policy

Acknowledgment policy

Discard policy

Closed loop - feedback tries to control congestion as it ishappening

Back pressure

Choke point (similar to ICMP’s source quench)

Implicit signaling (observing some other behavior)

Explicit signaling

Page 59: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 59

TCP Congestion Control

How does TCP spell relief?

Congestion window - recall the cwnd value? Network setsthis value and source takes minimum(rwnd, cwnd)

Slow start algorithm - cwnd starts at 1. With each ACK received, cwnd doubles. So second time cwnd = 2, then 4, then 8, etc.

The cwnd value does not increase forever. cwnd stopswhen it equals ssthresh, which has a max size of 65,535.

When cwnd equals ssthresh, slow start stops and additivephase begins. Additive phase increases the cwnd by 1each time an ACK is received.

Page 60: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 60

Figure 12.33 Slow start, exponential increase

Page 61: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 61

Figure 12.34 Congestion avoidance, additive increase

Page 62: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 62

TCP Congestion Control

What happens if congestion occurs?

If an RTO timer times out, there is probably congestion.So cut the threshold in half, set cwnd back to 1,and restart the slow start phase again (ouch!).

If three ACKs in a row are received, there may becongestion. So cut the threshold in half, set cwnd to thevalue of the threshold, and restart the avoidance phase.

Page 63: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 63

Figure 12.35 TCP congestion policy summary

Page 64: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 64

Figure 12.36 Congestion example

Page 65: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 65

12.9 TCP TIMERS

To perform its operation smoothly, most TCP implementations use at To perform its operation smoothly, most TCP implementations use at least four timers:least four timers:

Retransmission TimerRetransmission TimerPersistence TimerPersistence TimerKeepalive TimerKeepalive TimerTIME-WAIT TimerTIME-WAIT Timer

Page 66: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 66

Retransmission Timer

To retransmit a lost segment, TCP employs a retransmissiontimer that handles the retransmission time-out (RTO), thewaiting time for an ACK of a segment.

If an ACK is received before the timer goes off, toss the timer.

If timer goes off before ACK is received, segment isretransmitted and timer is reset.

To calculate the RTO value, we’ll need a couple other values.

Page 67: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 67

Retransmission Timer

The first value we need to know is the roundtrip time (RTT) of sending a segment and then gettingthe ACK.

To calculate RTT, we could use the RTT Measured value(simply time ACK received minus time packet sent),but this value varies greatly on today’s Internet.

So instead, we will calculate RTT Smoothed.

First time: RTT Smoothed = RTT Measured

After that:RTT Smoothed = (1-a) x RTT Smoothed + a x RTT Measured

where a normally is set to 1/8.

Page 68: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 68

Retransmission Timer

Most implementations also use the RTT Deviation.

First time: RTT Deviation = RTT Measured / 2

After that:

RTT Deviation = (1-b) x RTT Deviation +b x |Smoothed RTT - Measured RTT|

Where b usually equals 1/4.

Finally, RTO = RTT Smoothed + 4 x RTT Deviation

Page 69: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 69

Let us give a hypothetical example. Figure 12.38 shows part of a connection. The figure shows the connection establishment and part of the data transfer phases.

Example 10

1. When the SYN segment is sent, there is no value for RTTM , RTTS , or RTTD . The value of RTO is initially set to 6.00 seconds. The following shows the value of these variables at this moment:

RTTM = RTTS =

RTTD = RTO = 6.00

2. When the SYN+ACK segment arrives, RTTM is measured and is equal to 1.5 seconds. The next slide shows the values of these variables:

Page 70: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 70

Example 10 (continued)

RTTM = 1.5 RTTS = 1.5RTTD = 1.5 / 2 = 0.75 RTO = 1.5 + 4 x 0.75 = 4.5

3.When the first data segment is sent, a new RTT measurement starts. Note that the sender does not start an RTT measurement when it sends the ACK segment, because it does not consume a sequence number and there is no time-out. No RTT measurement starts for the second data segment because a measurement is already in progress.

RTTM = 2.5RTTS = 7/8 (1.5) + 1/8 (2.5) = 1.625RTTD = 3/4 (.75) + 1/4 |1.625 − 2.5| = 0.78 TYPO HERE IN BOOK!!

RTO = 1.625 + 4 (0.78) = 4.74

Page 71: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 71

Figure 12.38 Example 10

Page 72: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 72

Karn’s Algorithm

When the sending TCP receives an ACK for a segment, is thisthe ACK for the original segment, or for the retransmittedsegment?

Depending upon which one you choose can affect the calculation of your RTO timer.

So Karn says do not consider the round trip time of aretransmitted segment in the calculation of the new RTT.

Do not update the value of RTT until you send a segmentand receive an ACK without the need for retransmission.

Page 73: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 73

Exponential Backoff

What is the value of RTO if a retransmission occurs?

Most TCP implementations use an exponential backoffstrategy.

The value of RTO is doubled for each retransmission.

See the next slide for an example of this.

Page 74: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 74

Figure 12.39 is a continuation of the previous example. There is retransmission and Karn’s algorithm is applied. The first segment in the figure is sent, but lost. The RTO timer expires after 4.74 seconds. The segment is retransmitted and the timer is set to 9.48, twice the previous value of RTO. This time an ACK is received before the time-out. We wait until we send a new segment and receive the ACK for it before recalculating the RTO (Karn’s algorithm).

Example 11

Page 75: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 75

Figure 12.39 Example 11

Page 76: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 76

The Other Timers

What about the other timers?

Persistence Timer

What if a receiver sends you a window size of 0? You stop transmitting until you receive an ACKwith a new window size.

What happens if this ACK is lost? Connection goes dead.

So set the persistence timer to say, 60s when you receivea window size of 0. If you hear nothing after 60s, send aspecial probe.

No answer again after 60s, send another probe.

Page 77: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 77

The Other Timers

Keepalive Timer

If two sides transfer data and then go silent, is the connectionstill valid? Or did it die somehow?

Each time a server hears something from the other side, setthe Keepalive Timer to say, 2 hours. If the server doesn’thear anything within 2 hours, it sends a probe.

No response after 10 probes (each of which is 75s apart)? Then terminate the connection.

Page 78: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 78

12.10 OPTIONS

The TCP header can have up to 40 bytes of optional information. The TCP header can have up to 40 bytes of optional information. Options convey additional information to the destination or align other Options convey additional information to the destination or align other options.options.

Page 79: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 79

Figure 12.40 Options

Page 80: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 80

Figure 12.43 Maximum-segment-size option

This option (set during connection initialization) defines the maximum size of the data field withina segment. Max size is 65,536 bytes; default is 536 bytes.

Page 81: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 81

Figure 12.44 Window-scale-factor option

In case a window size of 16 bits (65,536 bytes) is not bigenough, you can set the window-scale factor.

The new window size if found by first raising 2 to the numberspecified in the window scale factor, then this result is multiplied by the value of the window size in the header.

For example, if window size in header is already set at 32,768and scale factor = 3, then 2^3 * 32768 = 262,144 bytes.

This can only be set during connection establishment time.

Page 82: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 82

Figure 12.45 Timestamp option

Can use this option to calculate round trip time RTT.

Page 83: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 83

Figure 12.46 shows an example that calculates the round-trip time for one end. Everything must be flipped if we want to calculate the RTT for the other end.

Example 12

The sender simply inserts the value of the clock (for example, the number of seconds past from midnight) in the timestamp field for the first and second segment. When an acknowledgment comes (the third segment), the value of the clock is checked and the value of the echo reply field is subtracted from the current time. RTT is 12 s in this scenario.

Page 84: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 84

The receiver’s function is more involved. It keeps track of the last acknowledgment sent (12000). When the first segment arrives, it contains the bytes 12000 to 12099. The first byte is the same as the value of lastack. It then copies the timestamp value (4720) into the tsrecent variable. The value of lastack is still 12000 (no new acknowledgment has been sent). When the second segment arrives, since none of the byte numbers in this segment include the value of lastack, the value of the timestamp field is ignored. When the receiver decides to send an accumulative acknowledgment with acknowledgment 12200, it changes the value of lastack to 12200 and inserts the value of tsrecent in the echo reply field. The value of tsrecent will not change until it isreplaced by a new segment that carries byte 12200 (next segment).

Example 12 (Continued)

Page 85: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 85

Note that as the example shows, the RTT calculated is the time difference between sending the first segment and receiving the third segment. This is actually the meaning of RTT: the time difference between a packet sent and the acknowledgment received. The third segment carries the acknowledgment for the first and second segments.

Example 12 (Continued)

Page 86: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 86

Figure 12.46 Example 12

The time-stamp option can also be usedfor PAWS (protection against wrappedsequence numbers)

Page 87: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 87

Figure 12.47 SACK

Page 88: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 88

Let us see how the SACK option is used to list out-of-order blocks. In Figure 12.48 an end has received five segments of data.

Example 13

The first and second segments are in consecutive order. An accumulative acknowledgment can be sent to report the reception of these two segments. Segments 3, 4, and 5, however, are out of order with a gap between the second and third and a gap between the fourth and the fifth. An ACK and a SACK together can easily clear the situation for the sender. The value of ACK is2001, which means that the sender need not worry about bytes 1 to 2000. The SACK has two blocks. The first block announces that bytes 4001 to 6000 have arrived out of order. The second block shows that bytes 8001 to 9000 have also arrived out of order. This means that bytes 2001 to 4000 and bytes 6001 to 8000 are lost or discarded. The sender can resend only these bytes.

Page 89: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 89

Figure 12.48 Example 13

Page 90: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 90

The example in Figure 12.49 shows how a duplicate segment can be detected with a combination of ACK and SACK. In this case, we have some out-of-order segments (in one block) and one duplicate segment. To show both out-of-order and duplicate data, SACK uses the first block, in this case, to show the duplicate data and other blocks to show out-of-order data. Note that only the first block can be used for duplicate data. The natural question is how the sender, when it receives these ACK and SACK values knows that the first block is for duplicate data (compare this example with the previous example). The answer is that the bytes in the first block are already acknowledged in the ACK field; therefore, this block must be a duplicate.

Example 14

Page 91: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 91

Figure 12.49 Example 14

Page 92: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 92

The example in Figure 12.50 shows what happens if one of the segments in the out-of-order section is also duplicated. In this example, one of the segments (4001:5000) is duplicated. The SACK option announces this duplicate data first and then the out-of-order block. This time, however, the duplicated block is not yet acknowledged by ACK, but because it is part of the out-of-order block (4001:5000 is part of 4001:6000), it is understood by the sender that it defines the duplicate data.

Example 15

Page 93: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 93

Figure 12.50 Example 15

Page 94: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 94

12.11 TCP PACKAGE

We present a simplified, bare-bones TCP package to simulate the heart We present a simplified, bare-bones TCP package to simulate the heart of TCP. The package involves tables called transmission control blocks, of TCP. The package involves tables called transmission control blocks, a set of timers, and three software modules.a set of timers, and three software modules.

The topics discussed in this section include:The topics discussed in this section include:

Transmission Control Blocks (TCBs)Transmission Control Blocks (TCBs)TimersTimersMain ModuleMain ModuleInput Processing ModuleInput Processing ModuleOutput Processing ModuleOutput Processing Module

Page 95: TCP/IP Protocol Suite 1 Chapter 12 Upon completion you will be able to: Transmission Control Protocol Be able to name and understand the services offered

TCP/IP Protocol Suite 95

Figure 12.51 TCP package