14
1 Transport Layer: TCP and UDP • Overview of TCP/IP protocols • Comparing TCP and UDP • TCP connection: establishment, data transfer, and termination • Allocation of port numbers • Size matters: MTU, datagram, MSS, buffer • Standard Internet services and applications • Debugging techniques and tools

1 Transport Layer: TCP and UDP Overview of TCP/IP protocols Comparing TCP and UDP TCP connection: establishment, data transfer, and termination Allocation

Embed Size (px)

Citation preview

Page 1: 1 Transport Layer: TCP and UDP Overview of TCP/IP protocols Comparing TCP and UDP TCP connection: establishment, data transfer, and termination Allocation

1

Transport Layer: TCP and UDP• Overview of TCP/IP protocols

• Comparing TCP and UDP

• TCP connection: establishment, data transfer, and termination

• Allocation of port numbers

• Size matters: MTU, datagram, MSS, buffer

• Standard Internet services and applications

• Debugging techniques and tools

Page 2: 1 Transport Layer: TCP and UDP Overview of TCP/IP protocols Comparing TCP and UDP TCP connection: establishment, data transfer, and termination Allocation

2

Overview of TCP/IP Protocols

tcpdump mrouted ping traceroute applications

IGMP ICMP TCP UDP ICMPv6

ARP/RARP IPv4 IPv6

datalinkBPF/DLPI

Page 3: 1 Transport Layer: TCP and UDP Overview of TCP/IP protocols Comparing TCP and UDP TCP connection: establishment, data transfer, and termination Allocation

3

Comparing TCP and UDP

TCP UDP

Binding betweenclient and server

Yes (connection-oriented)

No (connection-less)

Data Byte-stream Record

Reliability Yes (ack, time-out, retx)

No

Sequencing Yes No

Flow control Yes (window-based)

No

Full-duplex Yes Yes

Page 4: 1 Transport Layer: TCP and UDP Overview of TCP/IP protocols Comparing TCP and UDP TCP connection: establishment, data transfer, and termination Allocation

4

TCP Connection: Establishment

Three-way handshake

client server

socket connect (blocks)(active open) SYN_SENT

ESTABLISHED connect returns

socket,bind,listenLISTEN(passive open)accept (blocks)

ESTABLISHEDaccept returnsread (blocks)

SYN j

SYN k, ack j+1

ack k+1

SYN_RCVD

TCP options (in SYN): MSS (maximum segment size) option, window scale option (advertized window up to 65535x2^14, 1GB), timestamp option (the latter two: long fat pipe options)

Page 5: 1 Transport Layer: TCP and UDP Overview of TCP/IP protocols Comparing TCP and UDP TCP connection: establishment, data transfer, and termination Allocation

5

TCP Connection: Data Transfer

client server

writeread(blocks)

read returns

writeread(blocks)

(server processes request)

read returns

request

replyack of request

ack of reply

Page 6: 1 Transport Layer: TCP and UDP Overview of TCP/IP protocols Comparing TCP and UDP TCP connection: establishment, data transfer, and termination Allocation

6

TCP Connection: Termination

Four-way handshakeclient server

ack n+1

FIN m

ack m+1

FIN n

close(active close) FIN_WAIT_1

CLOSE_WAIT (passive close)read returns 0

closeLAST_ACK

CLOSED

FIN_WAIT_2

TIME_WAIT

CLOSED

1~4 mins

TIME_WAIT to allow old duplicate segment to expire for reliable termination(the end performing active close might have to retx the final ACK)

Page 7: 1 Transport Layer: TCP and UDP Overview of TCP/IP protocols Comparing TCP and UDP TCP connection: establishment, data transfer, and termination Allocation

7

TCP State Transition Diagram

CLOSED

LISTEN

ESTABLISHED

FIN_WAIT_1

FIN_WAIT_2

CLOSING

TIME_WAIT

CLOSE_WAIT

LAST_ACK

SYN_SENTSYN_RSVD

appl:passive opensend:<nothing>

recv:SYN,send:SYN,ACK

recv:RST recv:SYN

send:SYN,ACK(simultaneous open)recv:ACK

send:<nothing>

recv:SYN,ACKsend:ACK

appl:active opensend:SYN

appl:closeor timeout

(data transfer state) recv:FINsend:ACK

appl:closesend:FIN

recv:FINsend:ACK

recv:ACKsend:<nothing>

recv:FINsend:ACK

recv:FIN,ACKsend:ACK

recv:ACKsend:<nothing>

2MSL timeout

recv:ACKsend:<nothing>

appl:closesend:FIN

(simultaneous close)activeclose

passive close

Page 8: 1 Transport Layer: TCP and UDP Overview of TCP/IP protocols Comparing TCP and UDP TCP connection: establishment, data transfer, and termination Allocation

8

Allocation of Port Numbers

IANA(Internet AssignedNumbers Authority)

BSD

Solaris

1 1023 1024 49151 49152 65535

IANAwell-known ports

IANAregistered ports

IANAdynamic or private ports

BSDreserved ports

BSDephemeral ports

BSDnonprivileged servers

1 1023 1024 50000 50001 65535

rrsevport

513-1023 32768 65535

Solarisephemeral ports

Page 9: 1 Transport Layer: TCP and UDP Overview of TCP/IP protocols Comparing TCP and UDP TCP connection: establishment, data transfer, and termination Allocation

9

Multiple Sockets with the Same Port (in Concurrent Server)

server(*.21,*.*)

server (child1)(206.62.226.35.21,198.69.10.2.1500)

server (child2)(206.62.226.35.21,198.69.10.2.1501)

client1(198.69.10.2.1500,206.62.226.35.21)

client2(198.69.10.2.1501,206.62.226.35.21)

listening socket

connected socket

connected socket

All TCP segments destined for port 21, with socket pairs different from (206.62.226.35.21,198.69.10.2.1500) and (206.62.226.35.21,198.69.10.2.1501), are delivered to the original server with the listening socket.

Page 10: 1 Transport Layer: TCP and UDP Overview of TCP/IP protocols Comparing TCP and UDP TCP connection: establishment, data transfer, and termination Allocation

10

Size Matters:MTU, datagram, TCP MSS, buffer

• Link MTU (maximum transmission unit): Ethernet MTU: 1500 bytes, PPP MTU: configurable

• Path MTU: the smallest link MTU in the path, can be discovered by IP DF (don’t fragment) bit

• Maximum IP datagram: 65535 (IPv4), 65575 (IPv6) (IPv6 has 32-bit jumbo payload option), minimum IP reassembly buffer size

• TCP MSS (maximum segment size): actual value of reassembly buffer size, often the link MTU minus IP and TCP headers, to avoid fragmentation

Page 11: 1 Transport Layer: TCP and UDP Overview of TCP/IP protocols Comparing TCP and UDP TCP connection: establishment, data transfer, and termination Allocation

11

TCP Output and UDP Output

application

TCP

IP

output queue datalink

application

UDP

IP

output queue datalink

application buffer

socket send buffer (SO_SNDBUF)

MSS-sized TCPsegment

MTU-sized packet

application buffer

UDP datagram

MTU-sized packet

write sendto

no bufferingbut SO_SNDBUFexists

user processkernel

Page 12: 1 Transport Layer: TCP and UDP Overview of TCP/IP protocols Comparing TCP and UDP TCP connection: establishment, data transfer, and termination Allocation

12

Standard Internet Services and Applications

• Standard services provided by inetd daemon: echo/port7/RFC862, discard/port9/RFC863, daytime/port13/RFC867, chargen/port19/RFC864, time/port37/RFC868

• tested by “telnet machine service”, service mapped by /etc/services

• Common application types: diagnostic, routing protocol, datagram, virtual circuit, etc.

Page 13: 1 Transport Layer: TCP and UDP Overview of TCP/IP protocols Comparing TCP and UDP TCP connection: establishment, data transfer, and termination Allocation

13

Protocol Usage of Various Common ApplicationsApplication IP ICMP UDP TCPPing xTraceroute x xOSPF xRIP xBGP xBOOTP xDHCP xNTP xTFTP xSNMP xSMTP xTelnet xFTP xHTTP xNNTP xDNS x xNFS x xRPC x x

Page 14: 1 Transport Layer: TCP and UDP Overview of TCP/IP protocols Comparing TCP and UDP TCP connection: establishment, data transfer, and termination Allocation

14

Debugging Techniques and Tools• System call tracing: truss (in SVR4), ktrace &

kdump (in BSD) (Note that socket is a system call in BSD, while putmsg and getmsg are the actual system calls in SVR4)

• sock developed by W.R. Stevens: used to generate special case conditions, as stdin/stdout client, stdin/stdout server, source client, sink server

• tcpdump: dump packets matching some criteria• netstat: status of interfaces, multicast groups, per-

protocol statistics, routing table, etc.• lsof (list open files): which process has a socket

open on a specified IP address or port