transport layer (tcp/udp) - courses.cs.washington.edu · transport layer protocols •provide...

31
Transport Layer (TCP/UDP)

Upload: others

Post on 11-Jul-2020

10 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Transport layer protocols •Provide different kinds of data delivery across the network to applications CSE 461 University

Transport Layer (TCP/UDP)

Page 2: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Transport layer protocols •Provide different kinds of data delivery across the network to applications CSE 461 University

Recall the protocol stack

Computer Networks 2

Application – Programs that use network service

Transport – Provides end-to-end data delivery

Network – Send packets over multiple networks

Link – Send frames over one or more links

Physical – Send bits using signals

Page 3: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Transport layer protocols •Provide different kinds of data delivery across the network to applications CSE 461 University

Transport layer

Provides end-to-end connectivity to applications

CSE 461 University of Washington 3

Host Host

TransportNetwork

Client

TransportNetwork

Server

Page 4: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Transport layer protocols •Provide different kinds of data delivery across the network to applications CSE 461 University

Transport layer protocols

•Provide different kinds of data delivery across the network to applications

CSE 461 University of Washington 4

Unreliable ReliableMessages Datagrams (UDP)Bytestream Streams (TCP)

Page 5: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Transport layer protocols •Provide different kinds of data delivery across the network to applications CSE 461 University

Comparison of Internet transports

•TCP is full-featured, UDP is a glorified packet

CSE 461 University of Washington 5

TCP (Streams) UDP (Datagrams)Connections Datagrams

Bytes are delivered once, reliably, and in order

Messages may be lost, reordered, duplicated

Arbitrary length content Limited message sizeFlow control matches

sender to receiverCan send regardless

of receiver stateCongestion control matches

sender to networkCan send regardless

of network state

Page 6: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Transport layer protocols •Provide different kinds of data delivery across the network to applications CSE 461 University

Socket API

•Simple abstraction to use the network• The “network” API (really Transport service) used to write

all Internet apps• Part of all major OSes and languages; originally Berkeley

(Unix) ~1983•Supports both Internet transport services (Streams

and Datagrams)

CSE 461 University of Washington 6

Page 7: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Transport layer protocols •Provide different kinds of data delivery across the network to applications CSE 461 University

Socket API (2)

• Sockets let apps attach to the local network at different ports

CSE 461 University of Washington 7

Socket,Port #1

Socket,Port #2

Page 8: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Transport layer protocols •Provide different kinds of data delivery across the network to applications CSE 461 University

Socket API (3)•Same API used for Streams and Datagrams

CSE 461 University of Washington 8

Primitive MeaningSOCKET Create a new communication endpointBIND Associate a local address (port) with a socketLISTEN Announce willingness to accept connectionsACCEPT Passively establish an incoming connectionCONNECT Actively attempt to establish a connectionSEND(TO) Send some data over the socketRECEIVE(FROM) Receive some data over the socketCLOSE Release the socket

Only needed for Streams

To/From for Datagrams

Page 9: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Transport layer protocols •Provide different kinds of data delivery across the network to applications CSE 461 University

Ports

•Application process is identified by the tuple IP address, transport protocol, and port• Ports are 16-bit integers representing local “mailboxes”

that a process leases•Servers often bind to “well-known ports”• <1024, require administrative privileges

•Clients often assigned “ephemeral” ports• Chosen by OS, used temporarily

CSE 461 University of Washington 9

Page 10: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Transport layer protocols •Provide different kinds of data delivery across the network to applications CSE 461 University

Some Well-Known Ports

CSE 461 University of Washington 10

Port Protocol UseTCP/20, 21 FTP File transfer

TCP/22 SSH Remote login, replacement for TelnetTCP/25 SMTP EmailTCP/80 HTTP World Wide Web

TCP/443 HTTPS Secure Web (HTTP over SSL/TLS)TCP/3306 MYSQL MYSQL database access

UDP/53 DNS Domain name service

Full list: https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.txt

Page 11: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Transport layer protocols •Provide different kinds of data delivery across the network to applications CSE 461 University

Topics

• Service models• Socket API and ports• Datagrams, Streams

• User Datagram Protocol (UDP)• Connections (TCP)• Sliding Window (TCP)• Flow control (TCP)• Retransmission timers (TCP)• Congestion control (TCP)

CSE 461 University of Washington 11

Page 12: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Transport layer protocols •Provide different kinds of data delivery across the network to applications CSE 461 University

UDP

Page 13: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Transport layer protocols •Provide different kinds of data delivery across the network to applications CSE 461 University

User Datagram Protocol (UDP)

•Used by apps that don’t want reliability or bytestreams• Like what?

CSE 461 University of Washington 13

Page 14: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Transport layer protocols •Provide different kinds of data delivery across the network to applications CSE 461 University

User Datagram Protocol (UDP)

•Used by apps that don’t want reliability or bytestreams• Voice-over-IP • DNS• DHCP• Games

(If application wants reliability and messages then it has work to do!)

CSE 461 University of Washington 14

Page 15: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Transport layer protocols •Provide different kinds of data delivery across the network to applications CSE 461 University

Datagram Sockets

CSE 461 University of Washington 15

Client (host 1) Server (host 2)Time

request

reply

Page 16: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Transport layer protocols •Provide different kinds of data delivery across the network to applications CSE 461 University

Datagram Sockets (2)

CSE 461 University of Washington 16

Client (host 1) Server (host 2)Time

1: socket 2: bind1: socket

6: sendto

3: recvfrom*4: sendto

5: recvfrom*

7: close 7: close*= call blocks

request

reply

Page 17: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Transport layer protocols •Provide different kinds of data delivery across the network to applications CSE 461 University

UDP Buffering

CSE 461 University of Washington 17

App

Port Mux/Demux

App AppApplication

Transport(UDP)

Network (IP) packet

Message queues

Ports

Page 18: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Transport layer protocols •Provide different kinds of data delivery across the network to applications CSE 461 University

UDP Header

•Uses ports to identify sending and receiving application processes•Datagram length up to 64K•Checksum (16 bits) for reliability

CSE 461 University of Washington 18

Page 19: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Transport layer protocols •Provide different kinds of data delivery across the network to applications CSE 461 University

UDP Header (2)

•Optional checksum covers UDP segment and IP pseudoheader• Checks key IP fields (addresses)• Value of zero means “no checksum”

CSE 461 University of Washington 19

Page 20: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Transport layer protocols •Provide different kinds of data delivery across the network to applications CSE 461 University

TCP

Page 21: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Transport layer protocols •Provide different kinds of data delivery across the network to applications CSE 461 University

TCP

•TCP Consists of 3 primary phases:• Connection Establishment (Setup)• Sliding Windows/Flow Control• Connection Release (Teardown)

Page 22: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Transport layer protocols •Provide different kinds of data delivery across the network to applications CSE 461 University

Connection Establishment

•Both sender and receiver must be ready before we start the transfer of data• Need to agree on a set of parameters• e.g., the Maximum Segment Size (MSS)

•This is signaling• It sets up state at the endpoints• Like “dialing” for a telephone call

CSE 461 University of Washington 22

Page 23: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Transport layer protocols •Provide different kinds of data delivery across the network to applications CSE 461 University

CSE 461 University of Washington 23

Three-Way Handshake• Used in TCP; opens connection for

data in both directions• Each side probes the other with a

fresh Initial Sequence Number (ISN)• Sends on a SYNchronize segment• Echo on an ACKnowledge segment

• Chosen to be robust even against delayed duplicates

Active party(client)

Passive party(server)

Page 24: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Transport layer protocols •Provide different kinds of data delivery across the network to applications CSE 461 University

CSE 461 University of Washington 24

Three-Way Handshake (2)

•Three steps:• Client sends SYN(x)• Server replies with SYN(y)ACK(x+1)• Client replies with ACK(y+1)• SYNs are retransmitted if lost

•Sequence and ack numbers carried on further segments

1

2

3

Active party(client)

Passive party(server)

SYN (SEQ=x)

SYN (SEQ=y, ACK=x+1)

(SEQ=x+1, ACK=y+1)Time

Page 25: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Transport layer protocols •Provide different kinds of data delivery across the network to applications CSE 461 University

CSE 461 University of Washington 25

Three-Way Handshake (3)

•Suppose delayed, duplicate copies of the SYN and ACK arrive at the server!• Improbable, but anyhow …

Active party(client)

Passive party(server)

SYN (SEQ=x)

(SEQ=x+1,ACK=z+1)

Page 26: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Transport layer protocols •Provide different kinds of data delivery across the network to applications CSE 461 University

CSE 461 University of Washington 26

Three-Way Handshake (4)

•Suppose delayed, duplicate copies of the SYN and ACK arrive at the server!• Improbable, but anyhow …

•Connection will be cleanly rejected on both sides J

Active party(client)

Passive party(server)

SYN (SEQ=x)

SYN (SEQ=y, ACK=x+1)

(SEQ=x+1,ACK=z+1)

XXREJECT

REJECT

Page 27: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Transport layer protocols •Provide different kinds of data delivery across the network to applications CSE 461 University

TCP Connection State Machine

•Captures the states ([]) and transitions (->)• A/B means event A triggers the transition, with action B

Both parties run instances of this state

machine

Page 28: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Transport layer protocols •Provide different kinds of data delivery across the network to applications CSE 461 University

TCP Connections (2)

• Follow the path of the client:

Page 29: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Transport layer protocols •Provide different kinds of data delivery across the network to applications CSE 461 University

TCP Connections (3)

• And the path of the server:

Page 30: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Transport layer protocols •Provide different kinds of data delivery across the network to applications CSE 461 University

TCP Connections (4)

• Again, with states …

CSE 461 University of Washington 30

LISTEN

SYN_RCVD

SYN_SENT

ESTABLISHED

ESTABLISHED

1

2

3

Active party (client) Passive party (server)

SYN (SEQ=x)

SYN (SEQ=y, ACK=x+1)

(SEQ=x+1, ACK=y+1)Time

CLOSEDCLOSED

Page 31: Transport Layer (TCP/UDP) - courses.cs.washington.edu · Transport layer protocols •Provide different kinds of data delivery across the network to applications CSE 461 University

TCP Connections (5)

•Finite state machines are a useful tool to specify and check the handling of all cases that may occur

•TCP allows for simultaneous open• i.e., both sides open instead of the client-server pattern• Try at home to confirm it works J

CSE 461 University of Washington 31