lecture 20 overview - otago · 2020. 9. 11. · lecture 20 overview • last lecture – transport...

24
Lecture 20 Overview Last Lecture Transport Control Protocol (1) This Lecture Transport Control Protocol (2) – Source: chapters 23, 24 Next Lecture Internet Applications Source: chapter 26 COSC244 Lecture 20 - Transport Control Protocol 2 1

Upload: others

Post on 18-Mar-2021

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture 20 Overview - Otago · 2020. 9. 11. · Lecture 20 Overview • Last Lecture – Transport Control Protocol (1) • This Lecture – Transport Control Protocol (2) – Source:

Lecture 20 Overview •  Last Lecture

–  Transport Control Protocol (1) •  This Lecture

–  Transport Control Protocol (2) –  Source: chapters 23, 24

•  Next Lecture –  Internet Applications –  Source: chapter 26

COSC244 Lecture 20 - Transport Control Protocol 2 1

Page 2: Lecture 20 Overview - Otago · 2020. 9. 11. · Lecture 20 Overview • Last Lecture – Transport Control Protocol (1) • This Lecture – Transport Control Protocol (2) – Source:

Error Control •  TCP is a reliable transport layer protocol

–  Deliver a stream of data in order, without error, and without any part lost or duplicated

–  Provide mechanisms for detecting •  Lost segments •  Duplicated segments •  Out-of order segments •  Corrupted segments

–  Provide a mechanism for error correction

•  Error detection and correction in TCP is achieved by –  Checksum –  Acknowledgement –  Time-out and retransmission

COSC244 Lecture 20 - Transport Control Protocol 2 2

Page 3: Lecture 20 Overview - Otago · 2020. 9. 11. · Lecture 20 Overview • Last Lecture – Transport Control Protocol (1) • This Lecture – Transport Control Protocol (2) – Source:

TCP Segment

DataHeader

Destination port address 16 bits

Sequence number 32 bits

Acknowledgement number 32 bits

Window size 16 bits

Source port address 16 bits

HLEN 4 bits

Reserved 6 bits

URG

ACK

PSH

RST

SYN

FIN

Checksum 16 bits

Urgent pointer 16 bits

Options and Padding

COSC244 Lecture 20 - Transport Control Protocol 2 3

Page 4: Lecture 20 Overview - Otago · 2020. 9. 11. · Lecture 20 Overview • Last Lecture – Transport Control Protocol (1) • This Lecture – Transport Control Protocol (2) – Source:

Error Control (cont.) •  Checksum

–  Each segment includes a checksum field to check for a corrupted segment

–  A corrupted segment is discarded and considered as lost

•  Acknowledgement –  Each segment except ACK segment is acknowledged on receipt

•  Retransmission •  Retransmission time-out (RTO) timer: retransmit when the timer

expires. The timer is set based on the round-trip time (RTT). •  Three-duplicate-ACKs rule: retransmit after receiving three

duplicate ACK segments. This is applied when the receiver receives many out-of-order segments that can not be buffered. This feature is referred to as fast retransmission.

COSC244 Lecture 20 - Transport Control Protocol 2 4

Page 5: Lecture 20 Overview - Otago · 2020. 9. 11. · Lecture 20 Overview • Last Lecture – Transport Control Protocol (1) • This Lecture – Transport Control Protocol (2) – Source:

Duplicate Segments •  Duplicate segments can be detected and discarded using

sequence number. Entity 1 Entity 2

SYN seq: 8000

SYN+ACK seq: 15000 ack: 8001

REJECT seq: 8000 ack:15001

old duplicate

The same for data segments

COSC244 Lecture 20 - Transport Control Protocol 2 5

Page 6: Lecture 20 Overview - Otago · 2020. 9. 11. · Lecture 20 Overview • Last Lecture – Transport Control Protocol (1) • This Lecture – Transport Control Protocol (2) – Source:

Out-of-order Segments •  Out-of-order segments can be detected using the sequence

number. •  Out-of-order segments are not discarded. Instead the receiver

maintains a sliding window that temporally buffers the out-of-order segments until the missing segment arrives.

•  Out-of-order segments will not be delivered to the process.

COSC244 Lecture 20 - Transport Control Protocol 2 6

Page 7: Lecture 20 Overview - Otago · 2020. 9. 11. · Lecture 20 Overview • Last Lecture – Transport Control Protocol (1) • This Lecture – Transport Control Protocol (2) – Source:

Lost/corrupted Segments •  A lost segment and a corrupted segment are treated in the

same way by the receiver. Both are considered lost. •  Time-out + Retransmission

–  The sender sets the RTO timer when sending a segment. If the sender does not receive the corresponding acknowledgement when the timer fires, it assumes the segment is lost and retransmits the segment.

•  What will happen if the FIN and ACK segments in three-way handshaking for connection termination are lost?

COSC244 Lecture 20 - Transport Control Protocol 2 7

Page 8: Lecture 20 Overview - Otago · 2020. 9. 11. · Lecture 20 Overview • Last Lecture – Transport Control Protocol (1) • This Lecture – Transport Control Protocol (2) – Source:

The Two Army Problem •  The set-up

–  A white army is encamped in a valley. –  On both of the surrounding hillsides are blue armies. –  The white army is larger than either of the blue armies alone,

but together they are larger than the white army. –  If either blue army attacks by itself, it will be defeated, but if

both blue armies attack simultaneously, they will be victorious.

–  The communication medium between the two blue armies is to send messengers on foot down into the valley, where they might be captured and the message lost.

COSC244 Lecture 20 - Transport Control Protocol 2 8

Page 9: Lecture 20 Overview - Otago · 2020. 9. 11. · Lecture 20 Overview • Last Lecture – Transport Control Protocol (1) • This Lecture – Transport Control Protocol (2) – Source:

The Two Army Problem (cont.) •  The question

–  Is there a protocol that guarantees the blue armies will win?

COSC244 Lecture 20 - Transport Control Protocol 2 9

Page 10: Lecture 20 Overview - Otago · 2020. 9. 11. · Lecture 20 Overview • Last Lecture – Transport Control Protocol (1) • This Lecture – Transport Control Protocol (2) – Source:

Three-way Handshake Disconnect with a Timer

•  Timer is used - If there is no TPDU from the other party for some time, disconnect anyway.

•  The protocol can fail if all transmissions except the initial connection request are all lost. –  The sender will give up and delete the connection, while

the other side knows nothing about the attempts to disconnect and is still fully active.

•  This situation is called half-open connection.

COSC244 Lecture 20 - Transport Control Protocol 2 10

Page 11: Lecture 20 Overview - Otago · 2020. 9. 11. · Lecture 20 Overview • Last Lecture – Transport Control Protocol (1) • This Lecture – Transport Control Protocol (2) – Source:

COSC244 Lecture 20 - Transport Control Protocol 2 11

Page 12: Lecture 20 Overview - Otago · 2020. 9. 11. · Lecture 20 Overview • Last Lecture – Transport Control Protocol (1) • This Lecture – Transport Control Protocol (2) – Source:

Flow Control •  Transport protocols resemble the data link protocols

–  Flow control, error control –  A sliding window is used for flow control

•  Why cannot use the same flow control scheme at data link layer? –  A router usually has only a few links to others, while a transport

entity may have numerous connections. This difference makes it impractical to implement a data link buffering strategy in the transport layer.

COSC244 Lecture 20 - Transport Control Protocol 2 12

Page 13: Lecture 20 Overview - Otago · 2020. 9. 11. · Lecture 20 Overview • Last Lecture – Transport Control Protocol (1) • This Lecture – Transport Control Protocol (2) – Source:

Flow Control (cont. ) •  TCP sliding window

–  is byte-oriented, not frame-oriented –  has a variable size.

–  The size of the window is determined by: •  Receiver window (rwnd) •  Congestion window (cwnd)

COSC244 Lecture 20 - Transport Control Protocol 2 13

… n-1 … …n n+1 m-1 m m+1 …

Window size = minimum (rwnd, cwnd)

Page 14: Lecture 20 Overview - Otago · 2020. 9. 11. · Lecture 20 Overview • Last Lecture – Transport Control Protocol (1) • This Lecture – Transport Control Protocol (2) – Source:

Flow Control (cont.) •  Dynamic buffer management - credit mechanism

–  Initially, the sender requests a certain number of buffers (credit), based on its perceived needs.

–  The receiver grants as many of these as it can afford. –  Every time the sender transmits a TPDU, it decreases its allocation

(credit), stopping when the allocation (credit) reaches zero. –  The receiver returns both acknowledgments and buffer allocations

(credit). •  May be piggybacked

COSC244 Lecture 20 - Transport Control Protocol 2 14

Page 15: Lecture 20 Overview - Otago · 2020. 9. 11. · Lecture 20 Overview • Last Lecture – Transport Control Protocol (1) • This Lecture – Transport Control Protocol (2) – Source:

Flow Control (cont.)

COSC244 Lecture 20 - Transport Control Protocol 2 15

Page 16: Lecture 20 Overview - Otago · 2020. 9. 11. · Lecture 20 Overview • Last Lecture – Transport Control Protocol (1) • This Lecture – Transport Control Protocol (2) – Source:

Flow Control (cont.) –  Assume that when the connection is established, entities A

and B have initial sequence numbers 100 and 700 respectively, and each entity agrees to a credit of 200 bytes.

–  Assume entities send 100 bytes in each TPDU. –  A starts by sending two TPDUs and then waits because it has

used up its credit. –  At time t2, B removes the first received TPDU from the

buffer and also finds 100 more bytes of buffer space; so B now has 200 bytes space available and tells A in the credit field of a TPDU.

–  After A receives the 200 bytes credit, it can send two additional TPDUs.

COSC244 Lecture 20 - Transport Control Protocol 2 16

Page 17: Lecture 20 Overview - Otago · 2020. 9. 11. · Lecture 20 Overview • Last Lecture – Transport Control Protocol (1) • This Lecture – Transport Control Protocol (2) – Source:

Congestion Control in TCP

COSC244 Lecture 20 - Transport Control Protocol 2 17

•  Congestion policy has three phases: –  Slow start

•  The cwnd starts with one maximum segment size (MSS) •  The cwnd increases one MSS each time an ACK is received. •  Start slowly, but grows exponentially.

–  Congestion avoidance •  Use additive increase instead of exponential increase. •  When the size of the congestion window reaches the slow-start threshold, the

slow-start phase stops, and the additive phase begins.

–  Congestion detection •  Multiplicative decrease: the size of the cwnd is dropped to one-half.

When to quit the slow start phase?Mahdi Arghavani, Haibo Zhang, David Eyers, Abbas Arghavani, StopEG: detecting when to stop exponential growth in TCP slow-start, accepted by IEEE 45th Conference on Local Computer Networks, 2020.

Page 18: Lecture 20 Overview - Otago · 2020. 9. 11. · Lecture 20 Overview • Last Lecture – Transport Control Protocol (1) • This Lecture – Transport Control Protocol (2) – Source:

Congestion Control in TCP (cont.)

COSC244 Lecture 20 - Transport Control Protocol 2 18

cwndThreshold=16

Threshold=20

Threshold=10

time

3dupACKsTaho TCP

Reno TCPcwnd

Threshold=16

Threshold=20

Threshold=10

time

3dupACKs

Page 19: Lecture 20 Overview - Otago · 2020. 9. 11. · Lecture 20 Overview • Last Lecture – Transport Control Protocol (1) • This Lecture – Transport Control Protocol (2) – Source:

User Datagram Protocol (UDP) •  Connectionless unreliable transport protocol

•  Simple interface between IP and higher layer protocols –  Add nothing to the services of IP except to provide process to process

communication.

•  Why needs this protocol? –  A simple protocol using a minimum of overhead –  Useful in applications that require simple request-response communication

with little concern for flow and error control.

TCP UDP

IP and ICMP

Lower layer protocols

SMTP FTP TELNET DNS Application layer

Transport layer

Network layer

Data link layer

COSC244 Lecture 20 - Transport Control Protocol 2 19

Page 20: Lecture 20 Overview - Otago · 2020. 9. 11. · Lecture 20 Overview • Last Lecture – Transport Control Protocol (1) • This Lecture – Transport Control Protocol (2) – Source:

User Datagram Protocol (cont.) •  User datagram format

•  No flow control mechanism

•  No error control mechanism except the checksum

DataHeader

Destination port address 16 bits

Source port address 16 bits

Total length16 bits

Checksum16 bits

COSC244 Lecture 20 - Transport Control Protocol 2 20

Page 21: Lecture 20 Overview - Otago · 2020. 9. 11. · Lecture 20 Overview • Last Lecture – Transport Control Protocol (1) • This Lecture – Transport Control Protocol (2) – Source:

How to Develop the Program? •  Socket Programming•  What is a socket?

–  Sockets represent endpoints in a line of communication.–  A socket is a software component characterized by a unique

combination of •  Local socket address: local IP address and port number•  Remote socket address: only for TCP sockets•  Protocol: TCP, UDP

telephone network

COSC244 Lecture 20 - Transport Control Protocol 2 21

Page 22: Lecture 20 Overview - Otago · 2020. 9. 11. · Lecture 20 Overview • Last Lecture – Transport Control Protocol (1) • This Lecture – Transport Control Protocol (2) – Source:

Socket Programming

•  Socket Address: the combination of an IP address and a port number (a 16-bit unsigned integer, ranging from 0 to 65535).

•  Socket API: an application programming interface, usually provided by the operating system.

COSC244 Lecture 20 - Transport Control Protocol 2 22

Page 23: Lecture 20 Overview - Otago · 2020. 9. 11. · Lecture 20 Overview • Last Lecture – Transport Control Protocol (1) • This Lecture – Transport Control Protocol (2) – Source:

Socket Programming (cont.) •  Primitives for socket

–  socket - create a communication end point –  (bind - attach a local address to a socket) –  (listen - wait for a connection) –  accept - accept a connection request –  (connect - attempt to establish a connection) –  send/write - send data over the connection –  recv/read - receive data from the connection –  close - close the connection

COSC244 Lecture 20 - Transport Control Protocol 2 23

COSC402 introduces how to develop robust network programs using Socket programming.

Page 24: Lecture 20 Overview - Otago · 2020. 9. 11. · Lecture 20 Overview • Last Lecture – Transport Control Protocol (1) • This Lecture – Transport Control Protocol (2) – Source:

Summary •  Concepts

–  TCP –  TCP segment and its format –  Credit mechanism –  UDP –  Socket

•  Flow control and error control in transport layer –  Differences of flow control between transport and data link

layers –  Why error control in transport layer

•  Sockets

COSC244 Lecture 20 - Transport Control Protocol 2 24