Transport Over IP (II) - cpe.ku.ac.th

58
1 Transport Over IP (II) รศ.ดร. อนันต์ ผลเพิ.ม Asso. Prof. Anan Phonphoem, Ph.D. [email protected] http://www.cpe.ku.ac.th/~anan Computer Engineering Department Kasetsart University, Bangkok, Thailand

Transcript of Transport Over IP (II) - cpe.ku.ac.th

Page 1: Transport Over IP (II) - cpe.ku.ac.th

1

Transport Over IP (II)

รศ.ดร. อนันต์ ผลเพิ.มAsso. Prof. Anan Phonphoem, Ph.D.

[email protected]://www.cpe.ku.ac.th/~anan

Computer Engineering DepartmentKasetsart University, Bangkok, Thailand

Page 2: Transport Over IP (II) - cpe.ku.ac.th

2

Outline

n Transport Layern User Datagram Protocol (UDP)n Transmission Control Protocol (TCP)n Stream Control Transmission Protocol

(SCTP)n Real-Time Transport Protocol (RTP)

Transmission Control Protocol (TCP)

Page 3: Transport Over IP (II) - cpe.ku.ac.th

3

Transmission Control Protocol (TCP)

n Most popular/important in Internetn Reliable transport protocoln Connection-oriented

n need establishment n [IP+source port] « [IP+destination port]n guarantee delivery / error

n Checksum is mandatory

Page 4: Transport Over IP (II) - cpe.ku.ac.th

4

TCP Messages (Segment)

TCP Header

UDP Header

Page 5: Transport Over IP (II) - cpe.ku.ac.th

5

Connection Establishment

n Application requests connection through socket APIn not part of TCPn method to access services provided by TCP

n To start connection establishmentn receiver must be listening

Page 6: Transport Over IP (II) - cpe.ku.ac.th

6

Making connection

n Application on servern passive receive moden listening by issue Listen request to socket locally

n Application on Clientn request to socket API locally with

n destination IPn destination port n (source port: if not specify, TCP assigns private

port)

Server

Client

Page 7: Transport Over IP (II) - cpe.ku.ac.th

7

TCP Connection Establishment

Application TCP stack TCP stack Application

Server ClientInternet

Passive Open Active OpenSynchronize

Ack and Synchronize

Ack

Open Req

Open ReadyOpen Ready

3-way Handshake

Page 8: Transport Over IP (II) - cpe.ku.ac.th

TCP Connection Establishment

8

Page 9: Transport Over IP (II) - cpe.ku.ac.th

9

TCP Segment

n Segment sizen at source node = MTU local linkn fit in IP packetn may be fragment along the way

IP Header IP HeaderPayload Data

TCP Header DataTransport Layer

IP Layer

Page 10: Transport Over IP (II) - cpe.ku.ac.th

10

TCP Checksum

rsev (0)8 bits

TCP Length16 bits

Source IPv4 Address

Destination IPv4 Address

Protocol Type(TCP = 6)

Options

TCP Header20 bytes

Data

TCP header

Pseudoheader

Page 11: Transport Over IP (II) - cpe.ku.ac.th

11

Data Transmission (I)

Server ClientInternet

Send Req. 1500 bytes

Seq. 1 ; length 1000

Rec. 1000 bytesSeq. 1001 ; length 500 Push

Ack 1001

Ack 1501

Application TCP stack TCP stack Application

Rec. 500 bytes

Page 12: Transport Over IP (II) - cpe.ku.ac.th

Application

Transport

Network

Data Link

Physical

PHS (Push) Flag

n To allow applications to read write to the socket at any timen buffers are needed (both sides/ both direction of a

TCP connection

12

Application

Transport

Network

Data Link

Physical

TCP BufferTCP Buffer

Page 13: Transport Over IP (II) - cpe.ku.ac.th

13

PHS (Push) Flag

n To “Push” out data immediately, PHS flag is set n Sender: sent out immediatelyn Receiver: immediately forward the segment up to

application

Page 14: Transport Over IP (II) - cpe.ku.ac.th

14

Data Transmission (II)

Server ClientInternet

Send Req. 2500 bytes

Seq. 1 ; length 1000

Rec. 500 bytes

Ack 1001

Ack 2501

Application TCP stack TCP stack Application

Rec. 2000 bytesSeq. 2001 ; length 500 Push

Seq. 1001 ; length 1000

Page 15: Transport Over IP (II) - cpe.ku.ac.th

15

Data Transmission (III)

Server ClientInternet

Send Req. 3500 bytes Seq. 1 ; length 1000

Rec. 2500 bytes

Ack 1001Ack 1001

Application TCP stack TCP stack Application

Rec. 1000 bytesSeq. 2001 ; length 1000

Seq. 1001 ; length 1000

Seq. 1001 ; length 1000

Seq. 3001 ; length 500; Push

Ack 3501

Page 16: Transport Over IP (II) - cpe.ku.ac.th

16

TCP Window Control Send Buffer Recv. Buffer

Win

Win

Win

Win

Page 17: Transport Over IP (II) - cpe.ku.ac.th

17

Poor TCP Window Control“Silly Window Syndrome”

Send Buffer Recv. Buffer

Page 18: Transport Over IP (II) - cpe.ku.ac.th

18

URG (Urgent Data) Flag

n Set Urgent bit in the flag fieldn Overtake any byte in queue (e.g. Esc)

indicates how much of the data in the segment is urgent (from 1st byte)

Page 19: Transport Over IP (II) - cpe.ku.ac.th

19

Closing Connection (By either end)

Server ClientInternet

DataLast Data Segment (Fin Flag)

Data

Fin Flag; Ack = n+2; Seq.= m + 1

Ack

(Empty Data) Fin Flag; Seq.= n + 1

Application TCP stack TCP stack Application

CloseClose req

Close

Ack = m + 2 Close Resp

3-way Handshake

1 byte

Page 20: Transport Over IP (II) - cpe.ku.ac.th

Closing Connection

20

Page 21: Transport Over IP (II) - cpe.ku.ac.th

Example: 3-way Handshake

21

Page 22: Transport Over IP (II) - cpe.ku.ac.th

22

TCP State Machine

Passive open / -

Close / FIN

Send / SYNSYN / S

YN, ACK

RST / -passive open

SYN / SYN, ACK

simultaneous open

SYN,ACK / ACK

ACK / -

Close / FIN

FIN / ACK

FIN / ACK

ACK / - ACK / -

FIN, ACK / ACK

simultaneous close

FIN / ACK

passive close

active close

ACK / -

active open

Close, Timeout, Reset / -

LISTEN

SYN_RCVD

ESTABLISHED

FIN_WAIT_1 CLOSING

FIN_WAIT_2 TIME_WAIT

CLOSE_WAIT

LAST_ACK

SYN_SENT

Close

CLOSED

Active open / -

Timeout = 2MSL

Close / FIN

Server

Client

Page 23: Transport Over IP (II) - cpe.ku.ac.th

23

Errors in TCP

n Corrupted segmentn Wrong sequence segmentn Lost and redundant segment

Page 24: Transport Over IP (II) - cpe.ku.ac.th

24

Error Control in TCP

n Checksumn Acknowledgementn Retransmission

n Retransmission Timen 3-duplicate ACKs à Immediately ACK (Fast Retransmission)

Page 25: Transport Over IP (II) - cpe.ku.ac.th

25

Acknowledgement

Seq 1001-1200, ACK 4001 Seq 1001-1200, ACK 4001

Seq 4001-4200, ACK 1201Seq 4001-4200, ACK 1201

1201

ACK 4201

1201

ACK 4601ACK 4601

Seq 4201-4400, ACKSeq 4201-4400, ACK

Seq 4401-4600, ACK 1201Seq 4401-4600, ACK 1201

Station A Station B

Delay Time before ACK

Delay Time before ACK

Page 26: Transport Over IP (II) - cpe.ku.ac.th

26

Lost Segment

Seq 401-500, ACK 201

ACK 601

Seq 501-600, ACK 201 Seq 601-700, ACK 201

Seq 701-800, ACK 201

Seq 601-700, ACK 201 Ret

rans

mis

sion

Tim

e ¹

ACK 801

ACK 601

Station A Station B

Page 27: Transport Over IP (II) - cpe.ku.ac.th

27

Fast Retransmission

Seq 201-300, ACK 201

ACK 401

Seq 301-400, ACK 201

Seq 501-600, ACK 201

Seq 401-500, ACK 201

Seq 601-700, ACK 201 ACK 401

Seq 701-800, ACK 201 ACK 401

ACK 401Seq 401-500, ACK 201

Station A Station B

1

2

3

Page 28: Transport Over IP (II) - cpe.ku.ac.th

28

Congestion Control

Does Window Control help ?No concern with the network status.Every station keeps retransmitting.

Page 29: Transport Over IP (II) - cpe.ku.ac.th

29

Congestion Window

n cwndn Concern about network status

n Different from “receiver window size”n Concern about Buffer @ receiver

Amount data send = min (cwnd, window size)

Page 30: Transport Over IP (II) - cpe.ku.ac.th

30

Slow Start

02468

10121416182022242628303234363840

1 3 5 7 9 11 13 15 17 19 21 23

ssthresh = 32

ssthresh = 36/2= 18

cwnd (Max = 64)

cwnd starts with value = 1ssthresh: slow start threshold

Congestion Avoidance à Linear Retransmission

36

3-Dup ACKs

Linear

Linear

Fast Recoverycwnd = 20/2 = 10

20

Page 31: Transport Over IP (II) - cpe.ku.ac.th

31

Understanding TCP Characteristics

n Keep-alive mechanism n Sequence number

n wrapping boundaryn Slow startn No congestion detection in TCP

n use ICMP source quench messagen destination cannot receive too fast info., issue

ICMP source quench to slow down sender

Page 32: Transport Over IP (II) - cpe.ku.ac.th

32

Data

TCP Options

Page 33: Transport Over IP (II) - cpe.ku.ac.th

33

TCP Options

TCP Header

Data

1st Option Type8 bits

1st Option Data16 bits

1st Option Len8 bits

1st Option Data(Con’t) 2nd Option Type 2nd Option Len 2nd Option Data

2nd Option Data Padding

n Encoded as Type-Length-Variable (TLV)sequences

Page 34: Transport Over IP (II) - cpe.ku.ac.th

34

TCP Options

Type =2(1 byte)

Max Segment Size in byte(2 bytes)

Length =4(1 byte)

Timestamp(Con’t) Echoed Timestamp

Echoed Timestamp(Con’t)

To advertise the value of max. support TCP segment size

Type =3 Window Scaling FactorLength =3

To announce the window scaling factor

Type =8 TimestampLength =10

To utilize time stamp

Page 35: Transport Over IP (II) - cpe.ku.ac.th

35

Choosing between TCP and UDP

n TCPn reliable transport services

n UDPn only delivery data to specific port

Page 36: Transport Over IP (II) - cpe.ku.ac.th

36

Protocols that use TCP

n File Transfer Protocol (FTP)n Hypertext Transfer Protocol (HTTP)n Simple Mail Transfer Protocol (SMTP)n Post Office Protocol (POP3)n Telnetn Border Gateway Protocol (BGP-4)n Label Distribution Protocol (LDP)

Page 37: Transport Over IP (II) - cpe.ku.ac.th

TCP well-known ports

37

Page 38: Transport Over IP (II) - cpe.ku.ac.th

TCP vs UDP

38https://knowledgeofthings.com/tcpip-vs-udp-internet-protocol-suite/

Page 39: Transport Over IP (II) - cpe.ku.ac.th

TCP vs UDP Communication

39https://www.colocationamerica.com/blog/tcp-ip-vs-udp

Page 40: Transport Over IP (II) - cpe.ku.ac.th

Port Forwarding

40

Page 41: Transport Over IP (II) - cpe.ku.ac.th

41

Outline

n Transport Layern User Datagram Protocol (UDP)n Transmission Control Protocol (TCP)n Stream Control Transmission Protocol

(SCTP)n Real-Time Transport Protocol (RTP)

Stream Control Transmission Protocol(SCTP)

Page 42: Transport Over IP (II) - cpe.ku.ac.th

Stream Control Transmission Protocol (SCTP)

n RFC 2960n Transport Packet Switched Telephone

Network (PSTN) connections over IP networksn Reliable Connection-Orientedn Support large blocks data transfern Includes sender pacing and congestion

avoidancen Establish and maintain multiple streams

between same pair of end points42

Page 43: Transport Over IP (II) - cpe.ku.ac.th

43

Multiple Streams

Application Streams

SCTP

IP

Application Streams

SCTP

IP

IP network

Different IP Address

Port Port

Page 44: Transport Over IP (II) - cpe.ku.ac.th

44

Performance Enhancements

n Bundle multiple SCTP messages into a single SCTP packetn reduces network overheadn reduce processing overhead

n Improve network-level fault tolerancen multihoming (multiple IP add.)n distinct routes

n Additional security for flooding /masquerate

Page 45: Transport Over IP (II) - cpe.ku.ac.th

45

SCTP Message Formats

SCTPHeader

SCTPChunk

SCTPChunk

SCTPChunk

SCTP Packet

SCTP Header: association and verification detailsSCTP Chunk: control message / data for a stream

Page 46: Transport Over IP (II) - cpe.ku.ac.th

46

SCTP Message Formats

Source Port(16 bits)

Destination Port(16 bits)

Verification Tag

Checksum (not using pseudo header)

SCTP Header

Chunk Type(8 bits)

Chunk Length(16 bits)

Chunk Data

SCTP ChunkChunk Flag

(8 bits)

Page 47: Transport Over IP (II) - cpe.ku.ac.th

47

Association and Management

Internet

Initiation

Initiation Ack

Association Initiator Association Responder

Cookie Echo

Cookie Echo Ack

Heartbeat

Heartbeat Ack

… 4-way Handshake

Page 48: Transport Over IP (II) - cpe.ku.ac.th

48

State Cookie

n Used for authenticationn Message Authentication Code (MAC)

n Implement timer for controlling association

Page 49: Transport Over IP (II) - cpe.ku.ac.th

49

Association and Management

Internet

Association Initiator Association Responder

Data

Selective Ack

……

Shutdown

Shutdown Ack

Shutdown Complete

3-way Handshake

Peer

Page 50: Transport Over IP (II) - cpe.ku.ac.th

50

Data Transfer

n Same as TCP managementn Each chunk has Transmission Sequence

Number (TSN)n identify 1st byte

n Most important feature – multiplex many streams onto same associationn Stream Sequence Number

Page 51: Transport Over IP (II) - cpe.ku.ac.th

51

Multiplexing Data Streams

S1 S2SCTP

SenderSCTP

Receiver S2 S1

M#1, 3000 bytes

M#5, 1000 bytes

TSN=1; L=1000; S1; M#1

TSN=1001; L=1000; S2; M#5M#5, 1000 bytesM#6, 2000 bytes

TSN=2001; L=1000; S1; M#1

TSN=3001; L=1000; S2; M#6

TSN=4001; L=1000; S1; M#1

TSN=5001; L=1000; S2; M#6M#5, 2000 bytes

M#1, 3000 bytes

Transmission Sequence Number : TSN

Page 52: Transport Over IP (II) - cpe.ku.ac.th

52

Note on SCTP

n Not commonly usen Lack of availabilityn both ends must implement SCTP

n Use in private networksn Protocols that use SCTP

n SIPn MTP2

Page 53: Transport Over IP (II) - cpe.ku.ac.th

53

Outline

n Transport Layern User Datagram Protocol (UDP)n Transmission Control Protocol (TCP)n Stream Control Transmission Protocol

(SCTP)n Real-Time Transport Protocol (RTP)Real-Time Transport Protocol (RTP)

Page 54: Transport Over IP (II) - cpe.ku.ac.th

54

Real-Time Transport Protocol (RTP)

n Monitor and maintain QoS of real-time applications

n Lightweightn Run over another transport protocol

n Top-up protocoln top of UDP

n RTP needs management protocoln Real-Time Transport Control Protocol (RTCP)

Page 55: Transport Over IP (II) - cpe.ku.ac.th

RTP Implementation

55http://interedes2012.blogspot.com/p/redes-conmutadas.html

Page 56: Transport Over IP (II) - cpe.ku.ac.th

56

RTP Header

V Sequence Number(16 bits)

Timestamp

Synchronous Source ID

P X CC M Payload Type

Synchronous Source ID

Synchronous Source ID

At le

ast 1

2 By

tes

Version 2

Page 57: Transport Over IP (II) - cpe.ku.ac.th

57

RTP over UDP

IP Header(20 Bytes)

UDP Header(8 Bytes)

RTP Header(12 Bytes) Payload

40 bytes Overhead (IPv4)

For Audio: 16 bytes 71.4 % overhead

Page 58: Transport Over IP (II) - cpe.ku.ac.th

58

Summary

n Transport Layern User Datagram Protocol (UDP)n Transmission Control Protocol (TCP)n Stream Control Transmission Protocol

(SCTP)n Real-Time Transport Protocol (RTP)