Transport Layer TCP and UDP IS 250 Spring

  • Slides: 25
Download presentation
Transport Layer TCP and UDP IS 250 Spring 2010 chuang@ischool. berkeley. edu John Chuang

Transport Layer TCP and UDP IS 250 Spring 2010 chuang@ischool. berkeley. edu John Chuang

Network Layers § Application (layer 7): specific to application need § Transport (layer 4):

Network Layers § Application (layer 7): specific to application need § Transport (layer 4): end-to-end delivery, congestion and flow control § Network (layer 3): addressing, routing § Data Link (layer 2): framing, error detection § Physical (layer 1): bits (0/1), voltages, frequencies, wires, pins, … John Chuang HTTP, FTP, NNTP, SMTP, telnet, . . . TCP, UDP IP Wi-Fi Ethernet FDDI, SONET coax, twisted pair, fiber, wireless, . . . 2

TCP/IP Model end-to-end Appl end-to-end Trans port Net work Link Host A John Chuang

TCP/IP Model end-to-end Appl end-to-end Trans port Net work Link Host A John Chuang Appl Router 1 point-to-point Trans port Net work Link Router 2 Host B 3

Transport Layer § Functions 1. Addressing (ports) 2. Data integrity (error detection) 3. Reliable

Transport Layer § Functions 1. Addressing (ports) 2. Data integrity (error detection) 3. Reliable data transport 4. Flow control 5. Congestion control § Protocols - Transmission Control Protocol (TCP) - Reliable data transport (1, 2, 3, 4, and 5) - User Datagram Protocol (UDP) - Unreliable data transport (1 and 2 only) John Chuang 4

TCP Segment Format Bit 0 Bit 31 Source Port # (16) Destination Port #

TCP Segment Format Bit 0 Bit 31 Source Port # (16) Destination Port # (16) Header Sequence Number (32 bits) Acknowledgement Number (32 bits) Hdr Len Reserved (6) (4) Flags (6) TCP Checksum (16) Window Size (16) Urgent Pointer (16) Data Options (if any) PAD Data (variable length) § Like the IPv 4 header, TCP header is also 20 bytes long without options John Chuang 5

UDP Header UDP Datagram Format 0 16 31 Source Port Number (16) Destination Port

UDP Header UDP Datagram Format 0 16 31 Source Port Number (16) Destination Port Number (16) Message Length (16) UDP Checksum (16) Data § UDP is considered light-weight : - low overhead; no connection setup - used for real-time applications (don’t need retransmission) John Chuang 6

TCP Maximum Segment Size § Note that TCP segment header does not include segment

TCP Maximum Segment Size § Note that TCP segment header does not include segment size field § Instead, Sequence Number field is used to identify location of segment in the TCP byte stream (more on SEQ later) § Sender constructs segments so that they do not need to be fragmented at the network layer MSS = MTU - IP header length - TCP header length Maximum Segment Size 20 bytes without Options Maximum Transmission Unit John Chuang 7

Transport Layer Functions 1. 2. 3. 4. 5. Addressing (ports) Data integrity (error detection)

Transport Layer Functions 1. 2. 3. 4. 5. Addressing (ports) Data integrity (error detection) Reliable data transport Flow control Congestion control John Chuang 8

L 4 Addressing § TCP/UDP ports identify processes on a host Bit 0 Bit

L 4 Addressing § TCP/UDP ports identify processes on a host Bit 0 Bit 31 TCP Header Source Port # (16) Destination Port # (16) Sequence Number (32 bits) Acknowledgement Number (32 bits) Hdr Len (4) Reserved (6) Flags (6) Window Size (16) TCP Checksum (16) Urgent Pointer (16) UDP Header Options (if any) 0 John Chuang PAD 16 Source Port Number (16) Message Length (16) 31 Destination Port Number (16) UDP Checksum (16) 9

Ports § Multiple processes can run on a single host - all processes share

Ports § Multiple processes can run on a single host - all processes share a single IP address - each process talks/listens via a different port 128. 2. 14. 60; port 50001 128. 32. 226. 87; port 21 ftp client ftp server http client http server 128. 2. 14. 60; port 50002 John Chuang 128. 32. 226. 87; port 80 Note: IP cannot distinguish ftp packets from http packets (they have the same source and destination IP addresses) 10

Ports § The port numbers are divided into three ranges: - Well known ports

Ports § The port numbers are divided into three ranges: - Well known ports (0 -1023) - Registered ports (1024 -49151) - Dynamic and/or private ports (49152 – 65535) § Some “well known ports” - ftp (21); ssh (22); telnet (23); smtp (25); finger (79); http (80) - Assigned by Internet Assigned Numbers Authority (http: //www. iana. org/numbers. html) John Chuang 11

Transport Layer Functions 1. 2. 3. 4. 5. Addressing (ports) Data integrity (error detection)

Transport Layer Functions 1. 2. 3. 4. 5. Addressing (ports) Data integrity (error detection) Reliable data transport Flow control Congestion control John Chuang 12

Data Integrity § TCP/UDP checksums cover entire segment/datagram Bit 0 Bit 31 TCP Header

Data Integrity § TCP/UDP checksums cover entire segment/datagram Bit 0 Bit 31 TCP Header Source Port # (16) Destination Port # (16) Sequence Number (32 bits) Acknowledgement Number (32 bits) Hdr Len (4) Reserved (6) Flags (6) Window Size (16) TCP Checksum (16) Urgent Pointer (16) UDP Header Options (if any) 0 John Chuang PAD 16 Source Port Number (16) Message Length (16) 31 Destination Port Number (16) UDP Checksum (16) 13

Transport Layer Functions 1. 2. 3. 4. 5. Addressing (ports) Data integrity (error detection)

Transport Layer Functions 1. 2. 3. 4. 5. Addressing (ports) Data integrity (error detection) Reliable data transport Flow control Congestion control John Chuang 14

Reliable Data Transport § Connection (or Session) Management - Agreement on start and end

Reliable Data Transport § Connection (or Session) Management - Agreement on start and end of connection/session § Error Control - Data delivered without deletions, insertions, duplications, reordering John Chuang 15

Connection Management § TCP establishes a session with ordered and bi -directional reliable delivery

Connection Management § TCP establishes a session with ordered and bi -directional reliable delivery of bytes - Establishment: - Informs receiving port of connection - Initializes packet sequence number (to a random number) - Sets congestion and flow control state - Teardown: - By either peer - Frees state and resources John Chuang 16

A TCP Session Process A Process B SYN 3 -Way handshake to establish TCP

A TCP Session Process A Process B SYN 3 -Way handshake to establish TCP session SYN + ACK Data Can be merged into one Data + ACK Conversation Data + ACK FIN + ACK Teardown ACK John Chuang time 17

TCP Header Flags § Flags: URG, ACK, PSH, RST, SYN, FIN Bit 0 Bit

TCP Header Flags § Flags: URG, ACK, PSH, RST, SYN, FIN Bit 0 Bit 31 Source Port # (16) Destination Port # (16) Sequence Number (32 bits) Acknowledgement Number (32 bits) Hdr Len Reserved (6) (4) Flags (6) TCP Checksum (16) Options (if any) John Chuang Window Size (16) Urgent Pointer (16) PAD 18

Error Control § Original data stream: “I am here” Can Can data be deleted?

Error Control § Original data stream: “I am here” Can Can data be deleted? “I here” data be reordered? “here I am” data be duplicated? “I am am here” non-data be inserted? “I am not here” John Chuang 19 § §

Reliable Delivery § Positive Acknowledgment with retransmission § Sequence and acknowledgement numbers 0 16

Reliable Delivery § Positive Acknowledgment with retransmission § Sequence and acknowledgement numbers 0 16 TCP Header Source Port Number (16) 31 Destination Port Number (16) Sequence Number (32) Acknowledgement Number (32) Hdr Len Reserved (6) Flags (6) (4) TCP Checksum (16) Options (if any) Window Size (16) Urgent Pointer (16) Padding Data John Chuang 20

Reliable Delivery § Each packet has a sequence number (SEQ) - SEQ represents byte

Reliable Delivery § Each packet has a sequence number (SEQ) - SEQ represents byte offset with respect to initial SEQ - Duplicate packets can be detected and discarded - Out of order packets can be re-ordered § Each packet carries acknowledgment of received packet - ACK = sequence number of next byte expected by the receiver § Lost packet can be detected by missing ACK § Lost packet can be retransmitted after a timeout period John Chuang 21

A TCP Session Process A Process B SYN (Seq=x) 3 -Way handshake to establish

A TCP Session Process A Process B SYN (Seq=x) 3 -Way handshake to establish TCP session SYN (Seq=y; Ack=x+1) Data (Seq=x+1; Ack=y+1) Data (Seq=y+1; Ack=x+2) Conversation Data (Seq=x+2; Ack=y+2) Data (Seq=y+2; Ack=x+3) FIN (Seq=x+3; Ack=y+3) FIN (Seq=y+3; Ack=x+4) Teardown ACK (Ack=y+4) Notes: • Processes pick random initial values for x and y • SEQ incremented by one for illustrative purposes only John Chuang (in practice, SEQ incremented by MSS) time 22

ACK and Packet Retransmission Process A Process B Data (Seq=x+1) Data (Seq=y+1; Ack=x+2) Data

ACK and Packet Retransmission Process A Process B Data (Seq=x+1) Data (Seq=y+1; Ack=x+2) Data (Seq=x+2; Ack=y+2) Timeout IP loses packet Data (Seq=x+2; Ack=y+2) TCP resends packet ACK (Ack=x+3) John Chuang time 23

ACK and Packet Retransmission Process A Process B Data (Seq=x+1) Data (Ack=x+3) Timeout Data

ACK and Packet Retransmission Process A Process B Data (Seq=x+1) Data (Ack=x+3) Timeout Data (Ack=x+2) Data (Seq=x+2) IP loses ACK Data (Seq=x+2) TCP resends packet ACK (Ack=x+3) TCP resends ACK; drops duplicate John Chuang time 24

Adaptive Retransmission (Timeout) § Round trip time (RTT): elapsed time between sending of a

Adaptive Retransmission (Timeout) § Round trip time (RTT): elapsed time between sending of a TCP segment and the receipt of the corresponding ACK Est. RTT = (a*Est. RTT) + ((1 - a)*Sample. RTT) Timeout = b * Est. RTT § In the original spec, suggested values for a and b are 0. 9 and 2. In Jacobson/Karels algorithm, timeout is set adaptively to avoid spurious Johnretransmissions Chuang 25