TCP

33
06/27/22 CST 415 - Computer Networks 1 TCP CST 415

description

TCP. CST 415. Topics. Definitions Motivation Properties. Definitions. TCP – T ransmission C ontrol P rotocol IP provides unreliable packet delivery. Send it and forget it - PowerPoint PPT Presentation

Transcript of TCP

Page 1: TCP

04/20/23 CST 415 - Computer Networks 1

TCP

CST 415

Page 2: TCP

04/20/23 CST 415 - Computer Networks 2

Topics• Definitions

• Motivation

• Properties

Page 3: TCP

04/20/23 CST 415 - Computer Networks 3

Definitions• TCP – Transmission Control Protocol

IP provides unreliable packet delivery.» Send it and forget it

TCP sits on top of IP and adds the functionality to turn a unreliable packet delivery into reliable packet delivery.

Reliable Delivery – The packet is guaranteed to get to the recipient.

Page 4: TCP

04/20/23 CST 415 - Computer Networks 4

Definitions• TCP – Transmission Control Protocol

TCP is a stream oriented transport service.– On the application layer, information is

transferred as a stream of bits.– The TCP layer breaks the information into

octets and groups them into packets.– The sender sends a stream of octets.– The receiver receives the stream of octets in the

same order the sender sent them.

Page 5: TCP

04/20/23 CST 415 - Computer Networks 5

Motivation for TCPWith IP as a transport mechanism:

• Packets can be lost in transit across a network.

• Fragmented packets may arrive out of order.

• Pieces of a fragmented packet may be lost.

• Duplicate packets may be delivered.

Page 6: TCP

04/20/23 CST 415 - Computer Networks 6

Motivation for TCPIf IP were our only method for delivering

packets over a network, application programmers would have to manage packet transmission.– Build an ACK/NAK protocol.

Page 7: TCP

04/20/23 CST 415 - Computer Networks 7

TCP

The definition of TCP provides for an efficient protocol to avoid the necessity of application programs providing their own “ack/nack” protocol.

Page 8: TCP

04/20/23 CST 415 - Computer Networks 8

TCP – Properties• Stream Oriented – Sender sends a stream of

octets. Receiver receives those octets in the order the sender sent them.

• Virtual Circuit Based – Even though the data transmission is connectionless (e.g. over IP), the sender and receiver perceive they are communicating over a circuit (analogous to a phone call).

Page 9: TCP

04/20/23 CST 415 - Computer Networks 9

TCP – Properties• Buffered Transfer – Underlying protocol software

will choose an optimal transmission size. TCP will buffer data until it gets a packet the size it wishes to send.– To avoid buffering, data must be “pushed” through the

stream.

• Unstructured Stream – Hey, let’s face it…bits is bits.

• Full Duplex Communications – From the application point of view, sending and receiving of information can be done concurrently.

Page 10: TCP

04/20/23 CST 415 - Computer Networks 10

ReliabilitySimple Ack Protocol

A Full Success Scenario (nothing lost)

Page 11: TCP

04/20/23 CST 415 - Computer Networks 11

ReliabilitySimple Ack Protocol

Packet Lost Scenario

Page 12: TCP

04/20/23 CST 415 - Computer Networks 12

Reliability• Sliding window protocol

– Set up a window for packet “group” transmission.

– Move the window forward as the sequence of packets gets “acked” by the receiver.

– Allow the receiver to “ack” groups of packets.– Packets not “acked” will be retransmitted.

Page 13: TCP

04/20/23 CST 415 - Computer Networks 13

Reliability – SWP Example

1 32 4 5 6 7 8 9 10

Sender Packets

Window Size = 4

Sender Receiver

Window

Page 14: TCP

04/20/23 CST 415 - Computer Networks 14

Reliability – SWP Example

1 32 4 5 6 7 8 9 10

Sender Packets

Window Size = 4

Sender Receiver

Window

1

Page 15: TCP

04/20/23 CST 415 - Computer Networks 15

Reliability – SWP Example

32 4 5 6 7 8 9 10

Sender Packets

Window Size = 4

Sender Receiver

Window

1

Page 16: TCP

04/20/23 CST 415 - Computer Networks 16

Reliability – SWP Example

32 4 5 6 7 8 9 10

Sender Packets

Window Size = 4

Sender Receiver

Window

1 2 3

Page 17: TCP

04/20/23 CST 415 - Computer Networks 17

Reliability – SWP Example

4 5 6 7 8 9 10

Sender Packets

Window Size = 4

Sender Receiver

Window

1 2 3

Page 18: TCP

04/20/23 CST 415 - Computer Networks 18

Reliability – SWP Example

4 5 6 7 8 9 10

Sender Packets

Window Size = 4

Sender Receiver

Window

1 2 3 4 6 7

Hit by noise

Page 19: TCP

04/20/23 CST 415 - Computer Networks 19

Reliability – SWP Example

5 6 7 8 9 10

Sender Packets

Window Size = 4

Sender Receiver

Window

1 2 3 4

Page 20: TCP

04/20/23 CST 415 - Computer Networks 20

Reliability – SWP Example

5 6 7 8 9 10

Sender Packets

Window Size = 4

Sender Receiver

Window

1 2 3 4 5 6 7 8

Page 21: TCP

04/20/23 CST 415 - Computer Networks 21

Reliability – SWP Example

9 10

Sender Packets

Window Size = 4

Sender Receiver

Window

1 2 3 4 5 6 7 8

Page 22: TCP

04/20/23 CST 415 - Computer Networks 22

Reliability• The protocol can work with different

Ack/Nack schemes.– Go back N : This is what was shown above.

» Assume everything up to the last acknowledged packet is good. Resend everything after.

– Selective Nack : Allow the receiver to request retransmission of selected packets.

– Timer Retransmit : Set a timer for each sent packet.

» If a packet timer expires, resend the packet.

Page 23: TCP

04/20/23 CST 415 - Computer Networks 23

TCP – Sliding Window• TCP uses a modification of the sliding

window protocol.– Window size is adjusted “on the fly”– This allows the receiver to “throttle” down the

sender.– Receiver send a window size along with each

ack.– This forces the sender to either

» Increase window size – send faster please» Decrease window size – slow down transmission

please

Page 24: TCP

04/20/23 CST 415 - Computer Networks 24

TCP – Sliding Window• TCP uses a modification of the sliding

window protocol.– The window is on a “per byte” granularity.– Ack messages are sent for individual bytes. – The Ack message sends along the sequence

number of the next byte to send.– The next byte to send will be the next byte of

the longest contiguous sequence of bytes received so far.

Page 25: TCP

04/20/23 CST 415 - Computer Networks 25

TCP – Sliding Window• Retransmission is based on a timer.

– When TCP sends a segment of information, it will start a timer for that segment.

– If the sender does not receive an “ack” containing a sequence number covering the sent segment before the timer expires, the sender will resend the expired segment.

– To accommodate varying message latency times, TCP performs continuous monitoring of “send-ack” pairs and adjusts it’s timers dynamically.

Page 26: TCP

04/20/23 CST 415 - Computer Networks 26

TCP – Ports/Connections/Endpoints• Just like UDP, TCP uses ports as logical

addressing.– Provides associations between peer applications.– Applications are addressed via port and IP address.

» This provides a unique address for a specific application running on a specific hardware device.

» The combination is known as an “endpoint”.

• Unlike UDP, TCP is connection based.– TCP requires a logical division of labor in applications.– TCP must operate in a client/server mode.

» Server actively waits for a connection on a specific TCP port.» Clients will connect to that port to begin communication.

Page 27: TCP

04/20/23 CST 415 - Computer Networks 27

TCP – Ports/Connections/Endpoints

TCP lives in the transport layer along with UDP. Therefore TCP messages will be carried as data in an IP packet.

Page 28: TCP

04/20/23 CST 415 - Computer Networks 28

TCP – Ports/Connections/Endpoints

Server State Machine

Listen

Open PortSys Init

Open Success

SpawnConnection

Handler

Connection RequestConfirm

Connection

Handle Send

HandleReceive

HandleServer Thread

Send Message

Receive Message

Connection Handler Thread

Main Server Thread

ThreadSpawn

Handler SpawnSuccess

ConnectionAccepted

Page 29: TCP

04/20/23 CST 415 - Computer Networks 29

TCP – Ports/Connections/Endpoints• Open Port – The server opens the logical TCP port.• Listen – The server listens to the port, waiting for any

incoming connection requests.• Spawn Connection Handler – Upon receiving a

connection request, the server will spawn off a thread to handle the connection.– At this stage, the server may get a private TCP port and assign it to

the handler thread.– Communication will be performed over this private port from

within the handler thread.

• Confirm Connection – The server sends a confirmation message to the client. – In this confirmation message, the server will send the private port #

to be used for further communication.

Page 30: TCP

04/20/23 CST 415 - Computer Networks 30

TCP – Ports/Connections/Endpoints• Handle Server Thread – Given the new private

logical port:– Wait for activity on the logical port.

– Send/Receive protocol is controlled at the application layer by application logic.

– This logic is built into the server application handler thread.

• Handle Send – Send a message to the peer endpoint.

• Handle Receive – Receive a message from the peer endpoint and process it.

Page 31: TCP

04/20/23 CST 415 - Computer Networks 31

TCP – Ports/Connections/Endpoints

Note: For a TCP server to operate properly, the server must be capable of handling interaction from multiple clients.

Page 32: TCP

04/20/23 CST 415 - Computer Networks 32

TCP – Ports/Connections/Endpoints

Client State Machine

ConnectionConfrim

ConnectionRequest

Sys Init

Open Success

Handle SendHandleReceive

HandleClient Thread Send

Message

Receive Message

Main Client Thread

ConnectionAccepted

Ok

Ok

Page 33: TCP

04/20/23 CST 415 - Computer Networks 33

TCP – Ports/Connections/Endpoints• Connection Request – The client requests a connection

given the server IP address and TCP port number.• Connection Confirm – The server responds with a

confirmation message passing a private logical port on which further communication will be performed.

• Handle Client Thread – Given the new private logical port:– Wait for activity on the logical port.– Send/Receive protocol is controlled at the application layer by

application logic.– This logic is built into the client/server peer applications.

• Handle Send – Send a message to the peer endpoint.• Handle Receive – Receive a message from the peer

endpoint and process it.