TCP
This presentation is the property of its rightful owner.
Sponsored Links
1 / 81

TCP PowerPoint PPT Presentation


  • 70 Views
  • Uploaded on
  • Presentation posted in: General

TCP. Contents. TCP TCP connection TCP flow control TCP congestion control TCP timer UDP. Transport Layer. End-to-end data transfer (cf) DLP(data link protocol) data transfer between adjacent nodes. DLP. DLP. DLP. DLP. DLP. Host. Host. Transport layer protocol.

Download Presentation

TCP

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Tcp

TCP


Contents

Contents

  • TCP

  • TCP connection

  • TCP flow control

  • TCP congestion control

  • TCP timer

  • UDP


Transport layer

Transport Layer

  • End-to-end data transfer

    (cf) DLP(data link protocol)

    • data transfer between adjacentnodes

DLP

DLP

DLP

DLP

DLP

Host

Host

Transport layer protocol


Transport layer services

Transport Layer services

  • Addressing the application process and delivering data between processes

  • What else should the transport layer do for application?

AP1

AP2

AP3

AP1

AP2

AP3

end-to-end

transport

Transport

IP

IP

IP

network

Access 2

network

access 1

network network

access1 access2

subnet 1

subnet 2


What the transport layer should do in the internet 1

What the transport layer should do in the Internet(1)

  • IP provides unreliable services to the upper layers.

    • no error control

      • IP does merely the header checksum, but do not send ACKs nor retransmit.

    • no flow control/no congestion control

      • IP doesn’t have any function to control the transmission rate depending on the states of receivers or networks.

    • duplicate packet discovery

      • When packets are not delivered within the predefined time limit to the receiver because of network congestion or taking detour, even though those packets are not lost on the way, the sender retransmits the same packets.

      • Also, the ACK packets are not delivered to the sender within the predefined time limit, the sender times out and retransmits the same packets.

      • The IP of receiver cannot detect those duplicate packets and delivers the packets to the upper layers.

    • out-of-order packet delivery

      • Because IP use the datagram mode, packets can take different paths, consequently they might arrive out of order.


What the transport layer should do in the internet 2

What the transport layer should do in the Internet(2)

  • The application data that are delivered by IP might

    • be lost due to error or congestion, or

    • arrive at the destination out of order, or

    • be duplicated at the destination.

  • Thus, the transport layer protocol in the Internet should

    • provide the reliable services to the application layers if the application requires reliable service. Otherwise all dirty work should be done by application itself.

    • There are two transport protocols in the Internet.

      • TCP – provide reliable services.

      • UDP - simple, streamlined delivery services to the application layers which do not need reliable service.


Internet transport layer protocols

Internet transport layer protocols

  • TCP(Transmission Control Protocol)

    • provide reliable services to the application layers.

      • Multiplexing (addressing the application services)

      • error control (error detection and retransmission)

      • flow control

      • congestion control

      • Guarantee no out-of-sequence of the packet order

  • UDP(User Datagram Protocol)

    • Provide unreliable services

    • UDP does very simple function compared to TCP.

      • Multiplexing (addressing the application services)

      • Error detection (optional)


Tcp service characteristics

TCP service characteristics

  • End-to-end reliable service

    • guarantee the reliable data transfer between application processes

    • No error, no loss, no out-of-sequence

  • connection-oriented service

    • Consists of three steps: connection setup, data transfer, connection release

  • full duplex transmission

    • TCP connection setup enables two-way connections.

  • stream-oriented transmission

    • TCP views messages from application processes as continuous byte stream, not as separate packets.

  • Graceful connection release

    • When the connection terminates, TCP releases the connection after data transfer is completed.


How to provide reliable services 1

How to provide reliable services(1)

  • Transmission unit is segment.

    • The data sent to TCP from application processes are fragmented to have the size proper for transmission. Each fragmented data is called a segment. So the segment is the transmission unit when TCP sends application process data.

    • On the contrary, UDP does not fragment the application data, instead send the data as it was given from application processes.

  • Management of the segment sequence

    • Each segment is given a sequence number (viewed as byte streams), so receiver TCP can recognize any loss of segments and the out-of-sequence of arriving segments.

  • ACK transmission

    • When TCP receives correct segments, it always replies with ACK segment.

    • For enhancing performance, it uses the accumulative ACK.

  • Timer management

    • When TCP sends segments, it starts a timer. When the ACK for the segments sent does not arrive until the timer times out, it resends the same segment.


How to provide reliable services 2

How to provide reliable services(2)

  • Error control (checksum)

    • TCP checks any error on the segments it received using the checksum field in the header. If it finds any error, it discards the segment.

    • Also using the sequence number on the segment, it checks any loss of segments or out-of-sequence of the segments.

  • Order control

    • The receiver stores the packets it receives in the buffer, and after keeping the order of segments, it delivers them to application processes.

  • Detection and discard of duplicate segments

    • When the same segments arrives, the receiver discard the segment.


How to provide reliable services 3

How to provide reliable services(3)

  • Clear connection management

    • Clear connection setup using 3 way handshake

    • Also, clear connection release using 3 way handshake

    • When one end station happens to reboot, the station will setup another TCP connection in addition to the current TCP connection. In this case, TCP can distinguish the segments of the previous connection and the newly established connection.

  • Flow control

    • TCP uses a buffer, and notifies the other TCP on the connection of the available space in the buffer for receiving. So the other TCP can send only the amount of segments and stop.

  • Congestion control

    • TCP controls transmission rate depending on congestion state in the network.


Tcp header

TCP Header

IP datagram

TCP segment

IP header

TCP header

TCP data

20 octets

20 octets


Tcp header1

TCP Header

16-bit source port number

16-bit destination port number

32-bit sequence number

TCP

header

32-bit acknowledgement number

4bit hdr

length

Reserved

(6 bits)

U

R

G

A

C

K

P

S

H

R

S

T

S

Y

N

F

I

N

16-bit window size

16-bit TCP checksum

16-bit urgent pointer

Options (if any)

Padding(if any)

Data (if any)


Tcp segment format code bits

TCP Segment Format(code Bits)

Bit position Name function

11 URG urgent pointer field valid

12 ACK acknowledgment field valid

13 PSH deliver data on receipt of this segment

14 RST reset the sequence/acknowledgment numbers

15 SYN synchronization

16 FIN end of byte stream from sender


Port number addressing application

AP

AP

AP

AP

TCP

TCP

UDP

UDP

Port number: addressing application

  • A connection is identified uniquely by 5 elements.

    • (sender IP address, receiver IP address, protocol number, sender application process port number, receiver application process port number)

    • The combination of an IP address and a port number is sometimes called socket.

Port

TCP connection

protocol

IP addr

IP

IP

IP

H/W addr

Network

access

Network

access

Network

access

subnet

subnet


Connection identification addresses

Connection Identification addresses

  • IP address

    • identifies a specific host in the Internet.

    • has 1:1 mapping to the subnet physical address that the host is connected to.

  • Protocol number

    • identifies an upper layer protocol to which IP in the destination host should send data.

  • Port number

    • identifies an application process to which the receiver IP should deliver data .

    • well-known port numbers

      • the port numbers that were already decided by ICANN for their uses such as FTP server is 21, Telnet server is TCP 23, etc.

    • Ephemeral number

      • port numbers that is assigned temporarily for application processes established presently.


Well known tcp ports etc services

Well Known TCP Ports(/etc/services)

KeywordUNIX keywordDescription

0Reserved

1TCPMUX-TCP Multiplexor

5RJE-Remote Job Entry

7ECHOechoEcho

9DISCARDdiscardDiscard

11USERSsystatActive Users

13DAYTIMEdaytimeDaytime

15-netstatNetwork status program

17QUOTEqotdQuote of the day

19CHARGENchargenCharacter Generator

20FTP-DATAftp-dataFile Transfer Protocol

21FTPftpFile Transfer Protocol

23TELNETtelnetTerminal Connection

25SMTPsmtpSimple Mail Transport Protocol

37TIMEtimeTime

42NAMESERVERnameHost Name Server

43NICNAMEwhoisWho Is

53DOMAINnameserverDomain Name Server

77-rjeany private RJE service

79FINGERfingerFinger

93DCP-Device Control Protocol

95SUPDUPsupdupSUPDUP Protocol


Sequence number

Sequence Number

  • Segment number identifies the byte in the stream of data from the sending TCP to the receiving TCP, It represents the first byte of data in the segment.

  • The unit is not segments, but bytes..

  • The size is 232 large enough to detect duplicate segments.

TCP user

TCP

SEND (200 byte data)

[seq=300, data]

SEND (150 byte data)

[seq=500, data]

SEND (100 byte data)

[seq=650, data]


Acknowledge number

Sender TCP

Receiver TCP

[seq=1000, 100 byte data]

[seq=1100, 200 byte data]

[seq=1300, 100 byte data]

[ACK=1400]

Acknowledge Number

  • Accumulative ACK

  • By convention, the ACK number is the byte number of the segment that the receiver expects to receive next time.


Duplicate segments in the same connection

Duplicate segments in the same connection

SN1

SN2

SN0

Transport

Entity A

Transport

Entity B

SN0

A times out and retransmits SN0

SN1

A times out and retransmits SN1

ACK3

SN3

ACK3

SN4

ACK4

Solution: sequence number space should be large enough

SN5

ACK5

assumption:

- seq. number: mod 8

- use the accumulative ACK

SN6

ACK6

SN7

ACK7

ACK0

SN0

Obsolete SN0 arrives

New SN0 arrives


Duplicate segments in different connections 1

Duplicate segments in different connections(1)

Transport entity A

Transport entity B

Old connection closed

SN 2

SYN

SYN

New connection opened

SN 0

SN 1

Obsolete segment SN = 2 is accepted;

SN 2

valid segment SN = 2 is discarded as duplicate


Duplicate segments in different connections 2

Duplicate segments in different connections(2)

  • Global numbering

    • If the sequence number of the last segment of the previous connection is N, new connection use the first sequence number that is distant from N.

    • TCP should remember the sequence number that was used in the last segment.

  • 2 MSL Timer

    • When TCP connection closes, new TCP connection is not allowed to open immediately. New connection can open after the amount of time has passed.

    • TCP implementation choose a value for the maximum segment life time(MSL). It is the max. amount of time any segment can exit in the network before being discarded.

    • TCP connection can be reused after 2MSL wait is over.


Window field

Window Field

  • This field is used for TCP flow control (often called “Credit technique”).

  • It is used for a receiver to notify a sender of the size of empty space in the receiver TCP buffer.

  • The unit is bytes.

  • If the buffer size is larger than 216, it can be extended using the option field.

  • Its use is independent of the use of the acknowledge number field that denotes the success of failure of segment transmission.


Tcp

PUSH

  • Background

    • Normally, when the sending TCP receives data from the sending application process, TCP does not send the data immediately. Instead it stores the data in the its buffer, waiting for additional data arrive for the prevention of Silly Window Syindrom.

    • In the interactive application, however, the sending TCP is required to send data immediately.

  • PSH flag

    • The sending application process tells its TCP when to set the PUSH flag.

    • It is a notification to the sending TCP that the sending application process don’t want the data to hang around in the TCP buffer, waiting for additional data to fill the buffer.

    • When the receiver TCP receives the segment with the PSUH flag, it pass data to the receiver application process, telling not to wait until any additional data

    • The Socket API don’t provide a way for the application to tell its TCPto set the PUSH flag. Setting this flag is up to the TCP implementation.

    • BSD implementations ignores a received PUSH flag because they normally never delay the delivery of received data to the application.


Urgent bit urgent pointer

URGENT Bit & Urgent Pointer

  • Urgent mode

    • The sending TCP tell the other TCP that urgent data of some form has been placed into the normal stream of data.

    • The receiving TCP notifies the receiving application of the arrival of urgent data. The application process will decide what to do on its own way.

    • The URG bit is turned on and the urgent pointer is set to a positive offset that must be added to the sequence number field in the TCP header to obtain the sequence number of the last byte of urgent data.

    • In the socket API, sending application process can set this bit using SO OOB.

  • What is urgent mode used for?

    • The two most common uses are Telnet and Rlogin when interactive uses type the interrupt key(etc, ^C). Another is FTP, when interactive users abort a file transfer.


Tcp option fields

TCP Option Fields

  • MSS (Maximum Segment Size) option

    • The maximum size of the data transmitted

    • When a connections established, each end can announce the MSS it expects to receive. An MSS option can only appear in a SYN segment. If one end does not receive an MSS option form the other end, a default of 536 bytes is assumed.

      • 576 (IP datagram default size) - 40 (IP/TCP header fixed size)

    • In general, the larger the MSS the better, until fragmentation occurs.

  • Window Scale Option

    • It increase the window size. It means the maximum window size can be 216x216=232.

      • New window size = window size defined in the header x 2window scale factor

    • The window size factor can be determined only during the connection setup phase.

  • Time stamp option

    • The sender fills the time stamp value when the segment leaves. When the receiver sends an ACK for this segment, it enters the time stamp value that it receives from the sender. When the sender receives the ACK, it can calculate the round trip time for this segment.


Checksum

Checksum

0

31

16

  • The checksum applies to three parts: pseudo-header, TCP header, and the data coming form the application process)

  • Checking the pseudo-header prevent packets from being delivered to wrong hosts due to the corruption of the IP header.

  • Divide the total bits into 16-bit words. Add all 16-bit sections, using one’s complement arithmetic.

Source IP address

Pseudo-header

Destination IP address

Checksum scope

Protocol id

Segment length

zero

TCP header

TCP

segment

User Data


Tcp summary

TCP summary

  • Connection establishment

    • 3 way handshake

  • Connection termination

    • support graceful close using the 3 way handshake.

    • also support abrupt close using ABORT primitive.

  • Data transfer

    • Each segment is assigned a sequence number with the unit of byte.

    • Error control by retransmission: selective repeat

    • Flow control by credit allocation

    • PUSH

    • URGENT POINTER

  • Reset service

    • RST


Tcp primitives

primitive

type

Parameters

UNSPECIFIED_PASSIVE_OPEN

FULL_PASSIVE_OPEN

ACTIVE_OPEN

ACTIVE_OPEN_WITH_DATA

OPEN_ID

OPEN_SUCCESS

OPEN_FAILURE

SEND

DELIVER

ALLOCATE

CLOSE

CLOSING

TERMINATE

ABORT

STATUS

STATUS_RESPONSE

ERROR

Request

Request

Request

 Request

Local

response

Confirm

Confirm

Request

Indication

Request

Request

Indication

Request

Request

Request

Local

Response

Indicator

S

S

C

C

C

C

C

C/S

C/S

C/S

C/S

C/S

C/S

C/S

C/S

C/S

C/S

Source port, timeout, timeout-action, precedence, security range

Source port, destination port, destination address, timeout, timeout-action, precedence, security range

Source port, destination port, destination address, timeout, timeout-action, precedence, security range

Source port, destination port, destination address, data, data length, push flag, urgent flag, timeout, timeout-action, precedence, security range

Local connection name, source port, destination port, destination address

Local connection name

Local connection name

Local connection name, data, data length, push flag, urgent flag, timeout, timeout-action

Local connection name, data, data length, push flag, urgent flag

Local connection name, data length

Local connection name

Local connection name

Local connection name, reason code

Local connection name

Local connection name

Local connection name, source port, source address, destination address, connection state, receive window, send window, waiting ack, waiting accept, urgent, precedence, security, timeout

Local connection name, reason code

Client/

Server

TCP Primitives


Usage of tcp service primitives

Usage of TCP Service Primitives

TCP

Client-IP-server

Initiating(client)protocol

Responding(server)protocol

UNSPECIFIED_PASSIVE_OPEN

ACTIVE_OPEN

+

ACTIVE_OPEN_WITH_DATA

FULL_PASSIVE_OPEN

+

Connection

establishment

OPEN_ID

OPEN_RECEIVED

+

OPEN_SUCCESS

+

OPEN_FAILURE

SEND

+

+

DELIVER

Data

transfer

+

+

SEND

DELIVER

ALLOCATE

ALLOCATE

+

+

STATUS

STATUS

+

Status/error

reporting

+

STATUS_REPORT

STATUS_REPORT

+

+

ERROR

ERROR

CLOSE

+

+

CLOSING

+

CLOSE

+

TERMINATE

Connection

clearing

+

TERMINATE

ABORT

+

+

TERMINATE


Contents1

Contents

  • TCP

  • TCP connection

  • TCP flow control

  • TCP congestion control

  • TCP timer

  • UDP


Tcp connection setup and release

TCP Connection setup and release

client

server

SYN

SYN, ACK

ACK

Application close

FIN

Deliver EOF to application

ACK

Application close

FIN

ACK


Tcp connection setup 3 way handshake

TCP Connection Setup : 3 Way Handshake

  • Client-Server model

Client

TCP

TCP

Server

ACTIVE_OPEN

PASSIVE_OPEN

Send SYN

SYN=1, Seq=X

Send SYN

SYN=1, ACK=1, Seq=Y, ack=X=1

OPEN_RECEIVED

Send ACK

OPEN_SUCCESS

ACK=1, Ack=Y+1


Tcp connection setup 3 way handshake1

TCP Connection Setup : 3 Way Handshake

  • Simultaneous open

ACTIVE_OPEN

ACTIVE_OPEN

Send SYN

SYN=1, Seq=Y

Send SYN

SYN=1, Seq=X

Send ACK

ACK=1, Ack=Y+1

ACK=1, Ack=X+1

Send ACK

OPEN_SUCCESS

OPEN_SUCCESS


Robustness of 3 way handshake

Robustness of 3 Way Handshake

Obsolete SYN arrives

B accept and acknowledges

SYN i

A rejects B’s connection

SYN j, ACK i

(a) Delayed SYN

RST, ACK j

SYN k, ACK p

SYN i

A initiates a connection.

Old SYN arrives at A; A rejects

B accepts and acknowledge

RST, ACK k

SYN j, ACK i

ACK j

A acknowledges and begins transmission

SN i+1

(b) Delayed (SYN, ACK)


Tcp half close graceful disconnection

TCP Half-Close: Graceful Disconnection

client

server

Application shutdown

FIN

Deliver EOF to application

ACK of FIN

Application write

data

Application read

ACK of data

Application close

FIN

Deliver EOF to application

ACK of FIN


Tcp connection release 3 way handshake

TCP Connection Release: 3 Way Handshake

Server side

Client side

(a)

TCP

Server

Client

TCP

----

CLOSE

FIN = 1, seq = X

Send FIN

Send ACK

ACK = 1, ack = X+1

CLOSING

Send FIN

CLOSE

FIN=1,seq=Y

Send ACK

TERMINATE

ACK=1,ack=Y+1

----

TERMINATE

(b)

ABORT

Send RST

RST = 1

TERMINATE


Connection release 3 way handshake

Connection Release: 3 Way Handshake

  • Graceful disconnection – 3 way handshake

    • Since the TCP connection is full-duplex, when one end request termination, one way connection is terminate. But the other way connection can be maintained while the other end keeps sending data.

  • Abrupt disconnection

    • One-sided termination because of network failure, etc. In this case data can be lost.


Connection release 3 way handshake1

Connection Release: 3 Way Handshake

  • Graceful disconnection – 3 way handshake

    • Problem due to out-of-sequence

      • The one end sends FIN after sending the last segment. But the FIN segment arrives ahead of the last segment.

      • In this case, if the receiver TCP terminates as soon as it receives the FIN, the receiver loses the segment that arrives after connection closure.

      • To prevent this kind of loss, TCP assigns the sequence number to FIN segment, which have the number incremented from the sequence number of the last segment..

  • When the other end is not cooperative to the termination request,

    • The requesting end terminates the connection when the timer times out.


Crash connection release

Crash & Connection Release

  • The half-open can happen when any end of the connection breaks down, since the other end cannot know the other end’s failure.

  • In the half-open, the other end keeps retransmitting segments allowed. If no reply arrives until the keepalive timer expires, it terminates the connection.

  • The TCP end that has broken down can terminate using RST segment after rebooting.

    • Since the rebooting TCP has lost all state information, it should send RST segments for all segment it received, and the other end that received RST segments must terminate the connection immediately.


Tcp entity state diagram

TCP Entity State Diagram

SYN RECEIVE

LAST ACK

FIN WAIT 2

CLOSING

TIME WAIT

CLOSED

FIN WAIT

LISTEN

CLOSED

ESTAB

CLOSE WAIT

Receive SYN,ACK

Send ACK

Receive SYN,ACK

Send ACK

Receive FIN,ACK of SYN

Send ACK

Receive FIN

Send ACK

Receive FIN

Send ACK

Receive

ACK of FIN

Receive FIN,ACK

Send ACK

Unspecified Passive Open or

Fully Specified Passive Open

Active Open or Active

Open with Data

Initialize SV;

Send SYN

Initialize SV

Close

Clear SV

Close

Clear SV

Receive SYN

Receive SYN

SYN SENT

Send SYN

ACK

Send SYN

ACK

Receive ACK

of SYN

LEGEND

SV = state vector

MSL = maximum segment lifetime

Close

Send FIN

Receive FIN

Send ACK

Close

Send FIN

Receive

ACK of FIN

Timeout

(2MSL)


Contents2

Contents

  • TCP

  • TCP connection

  • TCP flow control

  • TCP congestion control

  • TCP timer

  • UDP


Tcp traffic control

TCP Traffic Control

  • Traffic control

    • There are two reasons for sender to reduce the rate of sending packets.

    • When receiver’s buffer space is not enough,  flow control

    • When the network is congested,  congestion control

network

congestion

Small-capacity

receiver


Sliding window flow control

Sliding Window Flow Control

0

0

1

1

2

2

3

3

0

0

1

1

2

2

3

3

Segments sent, but

not acknowledged

Segments that can be sent

Window is shrinking

as the segments are sent

Window expands

as the acks are received

(a) sender’s window

Segments that were received

Segments that will be received

Window is shrinking

as the segments are received

Window expands

as acks are sent

The last segment

That was acked

(b) receiver’s window


Is the sliding window scheme enough

Is the sliding window scheme enough?

I(1)

I(3)

I(3)

I(0)

I(0)

I(1)

I(1)

window size = 3

0

1

2

3

0

1

2

3

I(0)

0

1

2

3

0

1

2

3

I(2)

0

1

2

0

1

2

3

0

1

2

3

0

1

2

3

0

1

2

3

Window closed

Window closed

ACK(2)

0

1

2

3

0

1

2

3

0

1

2

3

0

1

2

3

0

1

2

3

0

1

2

3

3

0

1

0

1

2

3

0

1

2

3

Window closed

ACKs not sent

Window closed, BUSY CONDITION

TIMEOUT

Retransmit I(3),I(0),I(1)

Make the receiver’s state worse!!


What is wrong with the sliding window

What is wrong with the sliding window?

  • No distinction between the ACK and the current available buffer size.

    • When the receiver TCP receives segments uncorrupted and stores them in the buffer, but does not finish processing them,

      • If the TCP doesn’t send any ACK, then the sender’s timer expires and try to retransmit the segments. ==> It causes unnecessary loads to network!

      • Otherwise, if the TCP sends ACKs, then the sender transmits new segments, which may be discarded eventually. ==> aggravate the receiver’s condition!

  • Solution: credit allocation protocol

    • It distinguishes the ACK from the credit information. The ACK information informs the sender of successful transmission, while the credit information notifies the sender of the its current empty buffer size.


Credit allocation protocol

Credit Allocation Protocol

I(0)

I(3)

I(1)

I(3)

I(0)

ACK 1, CDT 2

ACK 1, CDT 0

I(1)

0

1

2

3

0

1

2

3

window size = 3

0

1

2

3

0

1

2

3

0

1

2

3

0

1

2

3

I(2)

0

1

2

0

1

2

3

0

1

2

3

0

1

2

3

0

1

2

3

Closing Window

Closing Window

ACK 2, CDT 3

0

1

2

3

0

1

2

3

0

1

2

3

0

1

2

3

0

1

2

3

0

1

2

3

3

0

1

0

1

2

3

0

1

2

3

Closing Window

Closing Window, BUSY CONDITION

TIMEER

Not retransmit I(3),I(0),I(1)

1

0

1

2

3

0

1

2

3

I(2)

IDLE CONDITION

Open Window


Example of tcp credit allocation mechanism

Example of TCP Credit Allocation Mechanism.

Transport Entity A

Transport Entity B

SN = 1401

....1000

1001

2400

2401...

....1000

1001

2400

2401...

SN = 1001

A may send 1400 octets

B is prepared receive 1400 octets,

SN = 1201

beginning with 1001

SN = 1601

.…2600

.…2600

....1000

....1600

....1000

....1600

2601

1601

1001

1001

1601

2601

1601

2401...

1601

....1600

2601….

A shrinks its transmit window with each

transmission

A = 1601, W = 1000

B acknowledges 3 segments (600 octets) but is only

prepared to receive 200 additional octets beyond the

original budget (I.e., B will accept octets 1601

2401...

2001

through 2600

SN = 1601

SN = 1801

....1600

1601

2001

2601….

2001

2601….

A adjusts its window with each credit

SN = 2001

SN = 2201

SN = 2401

2600

2601….

A exhausts its credit

A = 2601, W = 1400

4000

4001.…

4000

4001.…

B acknowledges 5 segments (1000 octets) and

restore the original amount of credit

A receive new credit


Too small data immediate window update

41 bytes IP packets

A keystroke arrive

40 bytes ACK

Application read 1 byte

of keystroke

40 bytes

window update

Application echoes it

41 bytes IP packets

Too Small Data & Immediate Window Update

  • Example of TELNET

    • When data arrives from application, if the sender TCP transmit it immediately, or the receiver TCP sends window update right after its buffer changes, then they have to exchange segments frequently, but do little.


Silly window syndrome caused by receiver

Application reads 1 byte

Receiver’s buffer is full

Room for one more byte

Window update segment sent

Header

New byte arrives

Header

1 byte

Receiver’s buffer is full

Silly Window Syndrome(caused by Receiver)


Silly window syndrome caused by sender

Application writes 1 byte

Sender’s buffer has 1 byte.

Sender’s Buffer is empty

TCP sends 1 byte.

1 byte

Header

Silly Window Syndrome(caused by Sender)


Avoiding sws from the sender

Avoiding SWS from the sender

  • Background

    • Suppose the case that data from application arrives at TCP 1 byte at a time. In that case TCP does not need to send small segment immediately every time it receives data.

  • Nagle’s algorithm

    • If data arrives 1 byte at a time, TCP sends the first byte in a small segment, and collect the next bytes in its buffer.

    • TCP sends the data in the buffer as a single segment when the ACK for the first segment arrives.

    • And TCP store the next bytes in the buffer again until it receives the ACK for the segment.


Avoiding sws from the receiver

Avoiding SWS from the receiver

  • Clark’s solution

    • The receiver TCP does not send window update until before its buffer is half empty or the size of data in the buffer becomes as large as the MSS.

  • Delayed ACK

    • TCP does not send an ACK the moment it receives a segment. Instead, it delays the ACK, hoping to have data going to the same host as the ACK for piggybacking.

    • Most implementations use a 200 ms delay.


Contents3

Contents

  • TCP

  • TCP connection

  • TCP flow control

  • TCP congestion control

  • TCP timer

  • UDP


Congestion control

Congestion Control

  • Background

    • Too much traffic has been injected into the network. The traffic inflow at this moment is exceeding the capacity that the network can accommodate.

  • So, the solution is simple. The traffic influx should be pull down below the network capacity level. But the rate should be reduced way ahead of reaching the full capacity level. (need very early action!!)

  • How can the network detect the early symptom of the congestion?

    • Monitoring the buffer size of network nodes (eg, routers)

    • Keeping track of the round-trip time of packets


Tcp and congestion control

TCP and congestion control

  • In the Internet, TCP is responsible for the congestion control. (It is somewhat odd!)

  • Then, how does TCP detect the congestion?

    • Timeout: No ACKs has arrived until timer expires.

    • The timeout can be triggered by two occasions: One is the transmission error, and the other is packet loss by congestion. But in the current network, the transmission error happens very rarely, so we give the congestion the benefit of the doubt.

  • TCP Congestion control methods

    • Slow start

    • Congestion avoidance

    • Fast retransmit

    • Fast recovery


Slow start

Slow Start

  • Control parameters

    • Awnd (advertised window by receiver)

      • At the initial setup, the sender informs the receiver of its maximum buffer size, which is the initial value of awnd.

      • Every time the sender transmits an ACK, it advertises its current available buffer size.

    • Cwnd (congestion window)

      • Determine how many segments can be sent without receiving ACKs..

  • Slow Start

    Initialize: cwnd = 1 MSS (max. segment size);

    Every time each ACK arrives:

    cwnd = cwnd + 1 MSS until min(cwnd, awnd) /* exponential growth */

Initial rate is slow, but ramp up exponentially fast.


Effect of slow start

Effect of Slow Start

receiver

sender

Segment 1

Cwnd = 1

ACK 2

Cwnd = 2

Segment 2

Segment 3

ACK 3

Cwnd = 3

ACK 4

Cwnd = 4

Segment 4

...

Segment 7

ACK 5

.....

ACK 8

Cwnd = 8


Congestion avoidance

Congestion Avoidance

  • If no ACKs arrive until timeout, TCP starts the Congestion Avoidance algorithm.

  • Congestion Avoidance algorithm

    If (segment timeout) {

    1. Set ssthresh = cwnd / 2 /* slow start threshold */

    2. Set cwnd = 1 MSS

    Restart “slow-start” until (cwnd=ssthresh)

    3. If (cwnd  ssthresh)

    cwnd = cwnd + 1 MSS every roundtrip time

    }


Slow start and congestion avoidance

Slow Start and Congestion Avoidance

A

CWND=1

B

A

CWND=1

B

CWND=2

CWND=2

CWND=3

CWND=3

CWND=4

CWND=4

CWND=5

CWND=5

CWND=6

CWND=6

CWND=7

CWND=7

CWND=8

CWND=8

CWND=9

Congestion avoidance

CWND=10

CWND=11

CWND=12

CWND=9

CWND=13

CWND=14

CWND=15

CWND=16

CWND=10

(a) Slow start, ending with a time out

(b) Slow start followed by congestion avoidance


Slow start and congestion avoidance1

Slow Start and Congestion Avoidance

20

Time out occurs

15

10

cwnd

Threshold

5

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

Round-trip times


Fast retransmission and fast recovery

Fast Retransmission and Fast Recovery

  • Background

    • TCP is required to generate an immediate acknowledgement (a duplicate ACK) when an out-of-order segment is received.

    • We don’t know whether a duplicate ACK is caused by a lost segment or just a reordering of segments.

    • If three or more duplicate ACKs are received in a row, it is a strong indication that a segment has been lost. Three or more duplicate ACKs implies that there is a flow of segments over the network.

    • Therefore the Congestion Avoidance is too conservative approach to this case.

  • Fast retransmission

    • If 4 consecutive ACKs are received before timeout, then TCP do not wait for the timeout and retransmit the segment immediately.


Fast retransmit

A

B

SN=1001

A=801

SN=1201(lost)

A=1001

SN=1401

A=1201

SN=1601

SN=1801

A=1201

SN=2001

A=1201

SN=2201

Elapsed time less than current RTO

A=1201

SN=2401

A=1201

SN=2601

A=1201

SN=1201(retransmission)

A=1201

A=2601

SN=2801

A=2801

SN=3001

SN=3201

Fast Retransmit


Fast recovery

Fast Recovery

  • Fast recovery algorithm (avoiding initial slow start phase)

    1. When the third duplicate ACK is received,

    Set ssthresh = cwnd / 2;

    Retransmit the missing segment;

    cwnd = ssthresh + 3 ;

    2. Each time another duplicate ACK arrives,

    Increment cwnd by the segment size;

    Transmit a new segment (if allowed by the new cwnd value);

    3. When the next ACK arrives that acknowledges new data,

    cwnd = ssthresh ;

    cwnd = cwnd + 1 every roundtrip time ;


Fast retransmission and fast recovery1

Fast Retransmission and Fast Recovery

seq #

&

cwnd

cwnd

sequence number

send time (sec)


Contents4

Contents

  • TCP

  • TCP connection

  • TCP flow control

  • TCP congestion control

  • TCP timer

  • UDP


Round trip time timeout

Round Trip Time & Timeout

  • RTT is important because the timeout value is determined based on RTT.

  • RTT can change over time as route might change and as network traffic changes.

  • So, TCP should track these changes and modify its timeout accordingly.


Round trip time timeout1

Round Trip Time & Timeout

  • Original TCP specification

    RTT(n+1) = a * RTT(n) + (1-a) * RTT_SAMPLE(n)

    /* recommendation : a=0.9 */

    RTO = b * RTT(n+1) /* recommendation : b = 2 */

    RTO: Retransmission Timeout value

    RTT_SAMPLE : measured RTT

  • Karn’s algorithm

    • We cannot update the RTT estimation when an ACK for retransmitted segment arrives because we don’t know to which segment the ACK corresponds, the original one or the retransmitted one?

    • Don’t calculate a new RTO until an acknowledgement is received for a segment that was not retransmitted.

    • Set the timeout after retransmission as follows:

      Timeout = 2 * RTT(n) /* exponential growth */

    • After the ACK for the retransmitted segment arrives, restart the calculation of RTT_SAMPLE.


Jacobson s algorithm

Jacobson’s Algorithm

  • Background

    • We can have better performance when we consider variance together rather than use simple RTT average values alone.

  • Jacobson’s algorithm

    DIFF(n+1) = RTT_SAMPLE(n+1) - RTT(n)

    DEV(n+1) = DEV(n) + h * (|DIFF(n+1)| - DEV(n)) /* typically h = 1/8 */

    RTT(n+1) = RTT(n) + g * DIFF(n+1) /* typically g = 1/4 */

    Timeout(n+1) = RTT(n+1) + 4 * DEV(n+1)


Tcp timers

TCP Timers

  • Retransmission timer

  • Persist timer

  • Keepalive timer

  • 2MSL timer


Retransmission timer

Retransmission Timer

  • It is used for determining how long the TCP sender wait for retransmission (timeout).

  • In the real implementation, there are not each timer operating for each segment. There is only one timer for each connection.


Tcp persist timer

TCP Persist Timer

  • Background

    • When the TCP receiver advertises window = 0, the TCP sender stops sending temporarily. Afterwards, the receiver lets the sender know it can receive segments again by sending new window advertisement. But if this new window advertisement is lost, the sender will wait for the new advertisement forever. (Deadlock!!)

  • Solution

    • After the sender knows window=0, the sender transmits window probe segment periodically to check out if the receiver is ready to accept. The window probe is sent according to the persist timer.

    • Window probe is a segment of 1 byte length.

    • TCP allows sender to transmit one byte even if the receiver’s window is closed.

    • TCP persist timer is increasing exponentially.


Tcp persist timer1

TCP Persist Timer

win=0

window probe

win=0

ACK(win=0)

win=256

window probe

lost

ACK(win=0)

window probe

Deadlock

ACK(win=0)

Persist Timer

(normal TCP Exponential backoff)


Tcp keepalive timer

TCP Keepalive Timer

  • If there is no activity on a given connection for a period of time, the server sends a probe segment to see if the client is still alive.

  • The keepalive timer specifies the interval at which the server want to know if client’s host has either crashed or is down. The interval is normally 2 hours.

  • When the Keepalive timer expires, the server sends a probe segment:

    • (1) if the client is still alive,

      • It will respond and there will be no more prove for next 2

    • (2) if the client is down,

      • It times out after 75 seconds, and the server sends a total of 10 probes, 75 seconds apart, and if no response, the server terminates the connection.

    • (3) if the client is rebooted,

      • There is a response for the probe, but the reponse will be a reset.  terminating the connection

    • (4) if the client is alive but not unreachable,

      • same as in case (2)


2 msl timer

2 MSL Timer

  • 2 MSL(Maximum Segment Lifetime)

    • It is the maximum amount of time any segment can exist in the network before being discarded.

    • When TCP performs an active close and sends the final ACK(reponse to the FIN), that connection must stay in the TIME_WAIT state for twice the MSL.

    • If the final ACK is lost, the other TCP can resend the FIN segment.

    • And, new TCP connection will open after 2 M니. (Some systems prevents from using the port numbers existed during 2 M니)

  • Quiet time concept

    • Suppose that a host crashed before the timeout while it is in the 2 MSLwait state, and then rebooted immediately. If the host open a new TCP connection as soon as it reboot, it cannot distinguish old segment in the previous connection from new segments in the new connection.

    • To avoid this confusion, TCP is not allowed to open new connection for 1 MSL right after rebooting. This 1 MSL time is called quiet time.


2 msl timer1

2 MSL Timer

FIN m

FIN m

FIN n

ACK m+1

SN n-1

ACK n+1

ACK m+1

FIN n

ACK n

closed

closed

ACK n+1

closed

Wait for 2 MSL and then terminate

closed

Wait for 2 MSL and then terminate

(b) Closing simultaneously

(a) Closing connections sequentially


Contents5

Contents

  • TCP

  • TCP connection

  • TCP flow control

  • TCP congestion control

  • TCP timer

  • UDP


Tcp

UDP

  • Addressing and checksum

  • Providing unreliable service to application

  • Datagram-oriented

    • one application data -> one UDP datagram


Udp header

16-bit source port number

16-bit destination port number

8

octets

16-bit Length

16-bit Checksum

Data (if any)

UDP Header

IP datagram

UDP datagram

IP header

UDP header

UDP data

20 octets

8 octets


A few well known udp ports

Decimal Keyword UNIX Keyword Description

0 -- Reserved

7 ECHOecho Echo

9 DISCARDdiscard Discard

11 USERSsystat Active Users

13 DAYTIMEdaytime Daytime

15 -netstat Who is up or NETSTAT

17 QUOTEqotd Quote of the Day

19 CHARGENchargen Character Generator

37 TIMEtime Time

42 NAMESERVERname Host Name Server

43 NICNAMEwhois Who is

53 DOMAINnameserver Domain Name Server

67 BOOTPSbootps Bootstrap Protocol Server

68 BOOTPCbootpc Bootstrap Protocol Client

69 TFTPtftp Trivial File Transfer

111 SUNRPCsunrpc Sun Microsystems RPC

123 NTPntp Network Time Protocol

161 -snmp SNMP net monitor

162 -snmp-trap SNMP traps

512 -biff UNIX comsat

513 - who UNIX rwho daemon

514 -syslog system log

525 -timed Time daemon

A Few Well-known UDP Ports


Tcp and udp

TCP

connection-oriented

Reliable service provisioning

Error control and flow control

stream-oriented

Good for stable transmission of long persistent data

UDP

connectionless

Unreliable services

No error control and no flow control

datagram-oriented

Good for short data or data that is permissible to error

TCP and UDP


  • Login