Chapter 12

Preview:

DESCRIPTION

Chapter 12. Transmission Control Protocol. TCP/IP protocol suite. 12.1 TCP SERVICES. It is connection –oriented protocol. It creates a connection between two TCPs to send data. Services provided by TCP/IP:. Process-to-Process Communication Stream Delivery Service - PowerPoint PPT Presentation

Citation preview

TCP/IP Protocol Suite 1

Chapter 12Chapter 12

TransmissionTransmissionControl ProtocolControl Protocol

TCP/IP Protocol Suite 2

TCP/IP protocol suite

TCP/IP Protocol Suite 3

12.1 TCP SERVICES

Services provided by TCP/IP:Services provided by TCP/IP:

Process-to-Process CommunicationProcess-to-Process CommunicationStream Delivery ServiceStream Delivery ServiceFull-Duplex CommunicationFull-Duplex CommunicationConnection-Oriented ServiceConnection-Oriented ServiceReliable ServiceReliable Service

•It is connection –oriented protocol.•It creates a connection between two TCPs to send data.

TCP/IP Protocol Suite 4

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

Like UDP, TCP provides process-to-process communication using port numbers.

TCP/IP Protocol Suite 5

Stream delivery

•TCP allows the sending process to deliver data as a stream of bytes & allows the receiving process to obtain data as a stream of bytes.

•TCP creates an environment in which two process seem to be connected by an imaginary tube that carries their data across the Internet.

TCP/IP Protocol Suite 6

Sending and receiving buffers

•Circular array of 1-byte location.

•Sending & receiving buffer.

TCP/IP Protocol Suite 7

TCP segments

•Buffer handles disparity between speed of producing & consuming process.

•Service provider for TCP send data in packets not in stream of bytes.

•Segments are not of same size.

TCP/IP Protocol Suite 8

Full Duplex Communication

•As data can flow in both direction at the same time.

Connection Oriented Service•Like UDP, TCP first establish connection between sender & receiver, exchanged data in both direction, connection is terminated.

Reliable Service•It is reliable protocol, uses acknowledgement mechanism to check the safe 7 sound arrival of data.

TCP/IP Protocol Suite 9

12.2 TCP FEATURES

The features of TCP include:The features of TCP include:

Numbering System: Sequence & acknwoledgment number Numbering System: Sequence & acknwoledgment number

Flow Control: The receiver of the data controls how much data are Flow Control: The receiver of the data controls how much data are to be sent by the sender. to be sent by the sender.

Error Control: Implements an error control mechanism.Error Control: Implements an error control mechanism.

Congestion Control: TCP takes into account congestion in the Congestion Control: TCP takes into account congestion in the network.network.

TCP/IP Protocol Suite 10

The bytes of data being transferred in each connection are numbered by TCP. The numbering starts with a randomly

generated number.

Note:Note:

TCP/IP Protocol Suite 11

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

of the first data byte containedin that segment.

Note:Note:

TCP/IP Protocol Suite 12

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:Note:

TCP/IP Protocol Suite 13

12.3 SEGMENT

• A packet in TCP is called a segmentA packet in TCP is called a segment

TCP/IP Protocol Suite 14

TCP segment format

20-60 Bytes

TCP/IP Protocol Suite 15

Control field

TCP/IP Protocol Suite 16

II

Description of flags in the control fieldDescription of flags in the control field

TCP/IP Protocol Suite 17

Pseudoheader added to the TCP datagram

TCP/IP Protocol Suite 18

The calculation of the checksum in TCP is mandatory.

Note:Note:

TCP/IP Protocol Suite 19

Encapsulation and decapsulation

•A TCP segment is encapsulated in an IP datagram , which in turn is encapsulated in a frame at the data link layer.

TCP/IP Protocol Suite 20

12.4 A TCP CONNECTION

•TCP is connection-oriented. TCP is connection-oriented. •A connection-oriented transport protocol establishes a virtual path A connection-oriented transport protocol establishes a virtual path between the source and destination. between the source and destination. •A connection-oriented transmission requires three phases: connection A connection-oriented transmission requires three phases: connection establishment, data transfer, and connection termination.establishment, data transfer, and connection termination.

Three phases include:Three phases include:

Connection EstablishmentConnection EstablishmentData TransferData TransferConnection TerminationConnection TerminationConnection ResetConnection Reset

TCP/IP Protocol Suite 21

Connection establishment using three-way handshaking

TCP

TCP/IP Protocol Suite 22

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

Note:Note:

TCP/IP Protocol Suite 23

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

sequence number.

Note:Note:

TCP/IP Protocol Suite 24

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

Note:Note:

TCP/IP Protocol Suite 25

Data transfer

TCP/IP Protocol Suite 26

Connection termination using three-way handshaking

TCP/IP Protocol Suite 27

Half-close

In TCP one end can stop sending data while still receiving data, is called a half close.

TCP/IP Protocol Suite 28

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

TCP/IP Protocol Suite 29

States for TCPStates for TCP

TCP/IP Protocol Suite 30

State transition diagram

TCP/IP Protocol Suite 31

Common scenario(Connection Establishment & Termination)

Maximum segment lifetime

TCP/IP Protocol Suite 32

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

Note:Note:

TCP/IP Protocol Suite 33

Three-way handshake

•FIN-WAIT-2 Eliminate.•The rest is same as four-way shaking.

TCP/IP Protocol Suite 34

Simultaneous open

•Both application (there is no client or server) issues active open.•Both ends need to send SYN segments to each other.•Both TCP goes through SYN-SENT & SYN-RCVD state before established state.

TCP/IP Protocol Suite 35

Simultaneous close

•Both end issue an active close.•Both TCP goes to the FIN-WAIT-1 state.•Eliminate the connection establishment & data transfer phase.

TCP/IP Protocol Suite 36

Denying a connection

•After resetting the connection, it goes to the LISTEN state to wait for another connection.•Client goes to CLOSED state.

TCP/IP Protocol Suite 37

Aborting a connection

•Process can abort a connection instead of closing it.•TCP sends RST+ACK segment•Both TCPs go to the CLOSED state.

TCP/IP Protocol Suite 38

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. receiving an acknowledgment from the destination. •TCP defines a window that is imposed on the buffer of data delivered TCP defines a window that is imposed on the buffer of data delivered from the application program. from the application program.

Sliding Window ProtocolSliding Window Protocol

TCP/IP Protocol Suite 39

Sliding window

•Host uses a window for sending a data.•The bytes inside the window are the bytes that can be in transmit.•The size of the window at one end, is determined by lesser of two values: receiver window(rwnd) or congestion window(cwnd).•Receiver window is no. of bytes the other end can accept before its buffer overflows & data is discarded.•Congestion window is a value determined by the network to avoid congestion.

TCP/IP Protocol Suite 40

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:

TCP/IP Protocol Suite 41

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:

TCP/IP Protocol Suite 42

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. lost, out-of-order, and duplicated segments. •Error control in TCP is achieved through the use of the checksum, Error control in TCP is achieved through the use of the checksum, acknowledgment, and time-out. acknowledgment, and time-out.

The topics include:The topics include:

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

TCP/IP Protocol Suite 43

12.8 CONGESTION CONTROL

•Congestion occurs if the no of packets sent to the network is greater Congestion occurs if the no of packets sent to the network is greater than the capacity of the network.than the capacity of the network.•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. •Congestion happens in any system that involves waiting.Congestion happens in any system that involves waiting.

TCP/IP Protocol Suite 44

Router queues

TCP/IP Protocol Suite 45

Packet delay and network load

TCP/IP Protocol Suite 46

Throughput versus network load

TCP/IP Protocol Suite 47

Slow start, exponential increase

TCP/IP Protocol Suite 48

In the slow start algorithm, the size of the congestion window increases exponentially until it reaches a

threshold.

Note:Note:

TCP/IP Protocol Suite 49

Figure 12.34 Congestion avoidance, additive increase

TCP/IP Protocol Suite 50

In the congestion avoidance algorithm the size of the congestion window

increases additively until congestion is detected.

Note:Note:

TCP/IP Protocol Suite 51

Most implementations react differently to congestion detection:

❏ If detection is by time-out, a new slow start phase starts.

❏ If detection is by three ACKs, a new congestion avoidance phase starts.

Note:Note:

TCP/IP Protocol Suite 52

Figure 12.35 TCP congestion policy summary

TCP/IP Protocol Suite 53

Figure 12.36 Congestion example

TCP/IP Protocol Suite 54

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.

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

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

TCP/IP Protocol Suite 55

Figure 12.37 TCP timers

TCP/IP Protocol Suite 56

In TCP, there can be only be one RTT measurement in progress at any time.

Note:Note:

TCP/IP Protocol Suite 57

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 set to 6.00 seconds. The following shows the value of these variables at this moment:

RTTM = 1.5 RTTS = 1.5

RTTD = 1.5 / 2 = 0.75 RTO = 1.5 + 4 . 0.75 = 4.5

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:

TCP/IP Protocol Suite 58

Example 10 (continued)

RTTM = 1.5 RTTS = 1.5RTTD = 1.5 / 2 = 0.75 RTO = 1.5 + 4 . 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 (7.5) + 1/4 |1.625 − 2.5| = 0.78RTO = 1.625 + 4 (0.78) = 4.74

TCP/IP Protocol Suite 59

Figure 12.38 Example 10

TCP/IP Protocol Suite 60

TCP does not consider the RTT of a retransmitted segment in its calculation of a new RTO.

Note:Note:

TCP/IP Protocol Suite 61

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

TCP/IP Protocol Suite 62

Figure 12.39 Example 11

TCP/IP Protocol Suite 63

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.

TCP/IP Protocol Suite 64

Figure 12.40 Options

TCP/IP Protocol Suite 65

Figure 12.41 End-of-option option

TCP/IP Protocol Suite 66

EOP can be used only once.

Note:Note:

TCP/IP Protocol Suite 67

Figure 12.42 No-operation option

TCP/IP Protocol Suite 68

NOP can be used more than once.

Note:Note:

TCP/IP Protocol Suite 69

Figure 12.43 Maximum-segment-size option

TCP/IP Protocol Suite 70

The value of MSS is determined during connection establishment and

does not change during the connection.

Note:Note:

TCP/IP Protocol Suite 71

Figure 12.44 Window-scale-factor option

TCP/IP Protocol Suite 72

The value of the window scale factor can be determined only during

connection establishment; it does not change during the connection.

Note:Note:

TCP/IP Protocol Suite 73

Figure 12.45 Timestamp option

TCP/IP Protocol Suite 74

One application of the timestamp option is the calculation of round trip

time (RTT).

Note:Note:

TCP/IP Protocol Suite 75

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.

TCP/IP Protocol Suite 76

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)

TCP/IP Protocol Suite 77

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)

TCP/IP Protocol Suite 78

Figure 12.46 Example 12

TCP/IP Protocol Suite 79

The timestamp option can also be used for PAWS.

Note:Note:

TCP/IP Protocol Suite 80

Figure 12.47 SACK

TCP/IP Protocol Suite 81

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.

TCP/IP Protocol Suite 82

Figure 12.48 Example 13

TCP/IP Protocol Suite 83

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

TCP/IP Protocol Suite 84

Figure 12.49 Example 14

TCP/IP Protocol Suite 85

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

TCP/IP Protocol Suite 86

Figure 12.50 Example 15

TCP/IP Protocol Suite 87

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

TCP/IP Protocol Suite 88

Figure 12.51 TCP package

TCP/IP Protocol Suite 89

Figure 12.52 TCBs

Recommended