Top Banner
1 © David Morgan 2003 Linux Networking: tcp David Morgan © David Morgan 2003 a network TCP process application process TCP process application process data data data data TCP context and interfaces Computer A Computer B
15

Linux Networking: tcp - Santa Monica Collegehomepage.smc.edu/morgan_david/linnetb/presentations/n-protocol-04... · data for 1st packet 0 1 1000 1 9 499,999 data for 2nd packet a

Jan 24, 2019

Download

Documents

phamquynh
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Linux Networking: tcp - Santa Monica Collegehomepage.smc.edu/morgan_david/linnetb/presentations/n-protocol-04... · data for 1st packet 0 1 1000 1 9 499,999 data for 2nd packet a

1

© David Morgan 2003

Linux Networking: tcp

David Morgan

© David Morgan 2003

a network

TCP process

application process

TCP process

application process

data

data

data

data

TCP context and interfacesComputer A Computer B

Page 2: Linux Networking: tcp - Santa Monica Collegehomepage.smc.edu/morgan_david/linnetb/presentations/n-protocol-04... · data for 1st packet 0 1 1000 1 9 499,999 data for 2nd packet a

2

© David Morgan 2003

TCP purposes and features

� Basic data transfer� Process-to-process multiplexing� Reliability� Flow control� Connections

© David Morgan 2003

Transport purposes and features

� process-to-process data transfer

� reliability

� flow control

� connections

TCP UDP

*

* discard, no recovery

Page 3: Linux Networking: tcp - Santa Monica Collegehomepage.smc.edu/morgan_david/linnetb/presentations/n-protocol-04... · data for 1st packet 0 1 1000 1 9 499,999 data for 2nd packet a

3

© David Morgan 2003

Basic data transfer method

� Sending TCP– “blocks” (segments) the data stream– gives each block its own packet (“segment”)

� Receiving TCP– reassembles the blocks into original stream

© David Morgan 2003

Multiplexed“process-to-process” transfer

� processes given identifying numbers (“ports”)� IP address/TCP port pair is a local “socket”� pair of sockets, one on each of 2 machines,

associated with a unique bilateral “connection”� packets between machines belong to a particular

one of the machines’ connections� overall packet flow contains separate flow for

each connection

Page 4: Linux Networking: tcp - Santa Monica Collegehomepage.smc.edu/morgan_david/linnetb/presentations/n-protocol-04... · data for 1st packet 0 1 1000 1 9 499,999 data for 2nd packet a

4

© David Morgan 2003

Reliability� problems with data

– damaged– lost– duplicated– delivered out-of-order

� solution– Sending TCP Receiving TCP– number the data acknowledge good data– require acknowledgement discard bad data– resend unacknowledged reassemble by the numbers

© David Morgan 2003

Flow control

� Problem– sending TCP might overwhelm receiving TCP

� Solution– constrain sender by requiring receiver’s

permission which data, by number range, may be transmitted

Page 5: Linux Networking: tcp - Santa Monica Collegehomepage.smc.edu/morgan_david/linnetb/presentations/n-protocol-04... · data for 1st packet 0 1 1000 1 9 499,999 data for 2nd packet a

5

© David Morgan 2003

TCP connections

� relability/flow control require state info� each TCP initializes/maintains it for each data

stream� connection ends, state info data structures

freed

© David Morgan 2003

TCP packet (segment) header

32 bits

Page 6: Linux Networking: tcp - Santa Monica Collegehomepage.smc.edu/morgan_david/linnetb/presentations/n-protocol-04... · data for 1st packet 0 1 1000 1 9 499,999 data for 2nd packet a

6

© David Morgan 2003

“Flag” bits

TCP Header

TCP flags field

URG = urgentACK= acknowledgementPSH = pushRST = resetSYN = synchronizeFIN = finish

© David Morgan 2003

Establishing a “connection”

� client sends packet with SYN bit set� server returns packet with SYN & ACK set� client sends packet with ACK set� called “3-way handshake”� connection establishment’s signature sequence

Page 7: Linux Networking: tcp - Santa Monica Collegehomepage.smc.edu/morgan_david/linnetb/presentations/n-protocol-04... · data for 1st packet 0 1 1000 1 9 499,999 data for 2nd packet a

7

© David Morgan 2003

3-way handshake

host1 host2

�T

i m e

SYN=1

SYN=1, ACK=1

ACK=1

© David Morgan 2003

TCP - SYN

SYN flag set indicates new connection request

Client Server

Page 8: Linux Networking: tcp - Santa Monica Collegehomepage.smc.edu/morgan_david/linnetb/presentations/n-protocol-04... · data for 1st packet 0 1 1000 1 9 499,999 data for 2nd packet a

8

© David Morgan 2003

TCP - SYN/ACK

SYN and ACK Flags set

1592481969 Ack = next expected Seq

© David Morgan 2003

TCP ACK

ACK Flag

Seq = 1592481969

Page 9: Linux Networking: tcp - Santa Monica Collegehomepage.smc.edu/morgan_david/linnetb/presentations/n-protocol-04... · data for 1st packet 0 1 1000 1 9 499,999 data for 2nd packet a

9

© David Morgan 2003

TCP is “stream oriented”

� data transmitted during connection viewed as one continuous stream

� bytes are consecutively numbered� stream segmented into packets for transmittal

© David Morgan 2003

File deconstructioninto sequenced packets

data for 1st packet

0 1 1000 1999 499,999

data for 2nd packet

a 500,000-byte file

byte numbers

1st packet – 02nd packet – 10003rd packet – 2000etc

sequence number assignments:Packet’s sequence number is the byte-stream number of the 1st

data byte in the packet.

Page 10: Linux Networking: tcp - Santa Monica Collegehomepage.smc.edu/morgan_david/linnetb/presentations/n-protocol-04... · data for 1st packet 0 1 1000 1 9 499,999 data for 2nd packet a

10

© David Morgan 2003

Sequence numbers

� Relative to byte stream, not packet series� Initial sequence number randomly chosen

– during connection setup handshake– actual byte count does not start from zero

� two number sequences– TCP carries 2 flows (full-duplex)– a separate sequence for each flow/direction

© David Morgan 2003

Acknowlegement number

� also byte-stream relative� is sequence number next-expected from partner� acknowledges receipt of all prior bytes� therefore called “cumulative” acknowlegement� acknowlegements are piggybacked

– client-to-server acks ride with server-to-client data– server-to-client acks ride with client-to-server data

Page 11: Linux Networking: tcp - Santa Monica Collegehomepage.smc.edu/morgan_david/linnetb/presentations/n-protocol-04... · data for 1st packet 0 1 1000 1 9 499,999 data for 2nd packet a

11

Numbering example*:(“C” keystroke in telnet)

host1 host2

�T

i m e SEQ=42 ACK=79

SEQ=79, ACK=43

SEQ= 43 ACK=80

Data=“C”

* Kurose & Ross, p. 234

Host ACKs receipt of “C”, echoes back “C”

Host ACKs receipt of “C”

Starting SEQs:host1: 42host2: 79

Data=“C”

© David Morgan 2003

Traffic control

� Flow control– adapt rate to partner’s capacity– depends on spare room in partner’s receive buffer

� Congestion control– adapt rate to intervening path’s capacity– depends on “just-about-anything”

Page 12: Linux Networking: tcp - Santa Monica Collegehomepage.smc.edu/morgan_david/linnetb/presentations/n-protocol-04... · data for 1st packet 0 1 1000 1 9 499,999 data for 2nd packet a

12

© David Morgan 2003

Flow control: receive window

receive “window” (variable size)

receive buffer (fixed size)

spare room TCP data in buffer

data from IP to application process

© David Morgan 2003

Partner given “willingness-to-accept”

spare room TCP data in buffer

n bytes

n

Page 13: Linux Networking: tcp - Santa Monica Collegehomepage.smc.edu/morgan_david/linnetb/presentations/n-protocol-04... · data for 1st packet 0 1 1000 1 9 499,999 data for 2nd packet a

13

© David Morgan 2003

Congestion control

� cap sent-but-unacknowledged data amount� congestion limit can exceed flow limit� vary the cap per perceived network congestion

– cap more severely when packet loss rate rises– relax cap when it drops

© David Morgan 2003

TCP Socket

� Connection defined by socket pair– Combination of IP address and port = socket

� Client IP = 10.100.13.138� Client Port = 32825

– Client Socket = 10.100.13.138:32825� Server IP = 216.239.39.100� Server Port = 80 (HTTP Default)

– Server Socket = 216.239.39.100:80

Page 14: Linux Networking: tcp - Santa Monica Collegehomepage.smc.edu/morgan_david/linnetb/presentations/n-protocol-04... · data for 1st packet 0 1 1000 1 9 499,999 data for 2nd packet a

14

© David Morgan 2003

well-known TCP ports

� 20 - FTP Control� 21 - FTP Data� 23 - Telnet� 25 - SMTP (Simple Mail Transport Protocol)� 80 - HTTP� 110 - POP3� 119 - Network News Transfer Protocol

© David Morgan 2003

TCP connection teardown

host1 host2

�T

i m e

FIN=1, ACK=1

FIN=1, ACK=1

ACK=1

Page 15: Linux Networking: tcp - Santa Monica Collegehomepage.smc.edu/morgan_david/linnetb/presentations/n-protocol-04... · data for 1st packet 0 1 1000 1 9 499,999 data for 2nd packet a

15

© David Morgan 2003

FIN/ACK

© David Morgan 2003

Biblio

� Computer Networking, Kurose & Ross, Addison-Wesley, 2003; Chapter 3 “Transport Layer”

� “Telnet Protocol Specification,” RFC 854, 1983