TCP - PowerPoint PPT Presentation

zavad
slide1 n.
Skip this Video
Loading SlideShow in 5 Seconds..
TCP PowerPoint Presentation
play fullscreen
1 / 81
Download Presentation
TCP
123 Views
Download Presentation

TCP

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. TCP

  2. Contents • TCP • TCP connection • TCP flow control • TCP congestion control • TCP timer • UDP

  3. Transport Layer • End-to-end data transfer (cf) DLP(data link protocol) • data transfer between adjacentnodes DLP DLP DLP DLP DLP Host Host Transport layer protocol

  4. Transport Layer services • Addressing the application process and delivering data between processes • What else should the transport layer do for application? AP1 AP2 AP3 AP1 AP2 AP3 end-to-end transport Transport IP IP IP network Access 2 network access 1 network network access1 access2 subnet 1 subnet 2

  5. What the transport layer should do in the Internet(1) • IP provides unreliable services to the upper layers. • no error control • IP does merely the header checksum, but do not send ACKs nor retransmit. • no flow control/no congestion control • IP doesn’t have any function to control the transmission rate depending on the states of receivers or networks. • duplicate packet discovery • When packets are not delivered within the predefined time limit to the receiver because of network congestion or taking detour, even though those packets are not lost on the way, the sender retransmits the same packets. • Also, the ACK packets are not delivered to the sender within the predefined time limit, the sender times out and retransmits the same packets. • The IP of receiver cannot detect those duplicate packets and delivers the packets to the upper layers. • out-of-order packet delivery • Because IP use the datagram mode, packets can take different paths, consequently they might arrive out of order.

  6. What the transport layer should do in the Internet(2) • The application data that are delivered by IP might • be lost due to error or congestion, or • arrive at the destination out of order, or • be duplicated at the destination. • Thus, the transport layer protocol in the Internet should • provide the reliable services to the application layers if the application requires reliable service. Otherwise all dirty work should be done by application itself. • There are two transport protocols in the Internet. • TCP – provide reliable services. • UDP - simple, streamlined delivery services to the application layers which do not need reliable service.

  7. Internet transport layer protocols • TCP(Transmission Control Protocol) • provide reliable services to the application layers. • Multiplexing (addressing the application services) • error control (error detection and retransmission) • flow control • congestion control • Guarantee no out-of-sequence of the packet order • UDP(User Datagram Protocol) • Provide unreliable services • UDP does very simple function compared to TCP. • Multiplexing (addressing the application services) • Error detection (optional)

  8. TCP service characteristics • End-to-end reliable service • guarantee the reliable data transfer between application processes • No error, no loss, no out-of-sequence • connection-oriented service • Consists of three steps: connection setup, data transfer, connection release • full duplex transmission • TCP connection setup enables two-way connections. • stream-oriented transmission • TCP views messages from application processes as continuous byte stream, not as separate packets. • Graceful connection release • When the connection terminates, TCP releases the connection after data transfer is completed.

  9. How to provide reliable services(1) • Transmission unit is segment. • The data sent to TCP from application processes are fragmented to have the size proper for transmission. Each fragmented data is called a segment. So the segment is the transmission unit when TCP sends application process data. • On the contrary, UDP does not fragment the application data, instead send the data as it was given from application processes. • Management of the segment sequence • Each segment is given a sequence number (viewed as byte streams), so receiver TCP can recognize any loss of segments and the out-of-sequence of arriving segments. • ACK transmission • When TCP receives correct segments, it always replies with ACK segment. • For enhancing performance, it uses the accumulative ACK. • Timer management • When TCP sends segments, it starts a timer. When the ACK for the segments sent does not arrive until the timer times out, it resends the same segment.

  10. How to provide reliable services(2) • Error control (checksum) • TCP checks any error on the segments it received using the checksum field in the header. If it finds any error, it discards the segment. • Also using the sequence number on the segment, it checks any loss of segments or out-of-sequence of the segments. • Order control • The receiver stores the packets it receives in the buffer, and after keeping the order of segments, it delivers them to application processes. • Detection and discard of duplicate segments • When the same segments arrives, the receiver discard the segment.

  11. How to provide reliable services(3) • Clear connection management • Clear connection setup using 3 way handshake • Also, clear connection release using 3 way handshake • When one end station happens to reboot, the station will setup another TCP connection in addition to the current TCP connection. In this case, TCP can distinguish the segments of the previous connection and the newly established connection. • Flow control • TCP uses a buffer, and notifies the other TCP on the connection of the available space in the buffer for receiving. So the other TCP can send only the amount of segments and stop. • Congestion control • TCP controls transmission rate depending on congestion state in the network.

  12. TCP Header IP datagram TCP segment IP header TCP header TCP data 20 octets 20 octets

  13. TCP Header 16-bit source port number 16-bit destination port number 32-bit sequence number TCP header 32-bit acknowledgement number 4bit hdr length Reserved (6 bits) U R G A C K P S H R S T S Y N F I N 16-bit window size 16-bit TCP checksum 16-bit urgent pointer Options (if any) Padding(if any) Data (if any)

  14. TCP Segment Format(code Bits) Bit position Name function 11 URG urgent pointer field valid 12 ACK acknowledgment field valid 13 PSH deliver data on receipt of this segment 14 RST reset the sequence/acknowledgment numbers 15 SYN synchronization 16 FIN end of byte stream from sender

  15. AP AP AP AP TCP TCP UDP UDP Port number: addressing application • A connection is identified uniquely by 5 elements. • (sender IP address, receiver IP address, protocol number, sender application process port number, receiver application process port number) • The combination of an IP address and a port number is sometimes called socket. Port TCP connection protocol IP addr IP IP IP H/W addr Network access Network access Network access subnet subnet

  16. Connection Identification addresses • IP address • identifies a specific host in the Internet. • has 1:1 mapping to the subnet physical address that the host is connected to. • Protocol number • identifies an upper layer protocol to which IP in the destination host should send data. • Port number • identifies an application process to which the receiver IP should deliver data . • well-known port numbers • the port numbers that were already decided by ICANN for their uses such as FTP server is 21, Telnet server is TCP 23, etc. • Ephemeral number • port numbers that is assigned temporarily for application processes established presently.

  17. Well Known TCP Ports(/etc/services) Keyword UNIX keyword Description 0 Reserved 1 TCPMUX - TCP Multiplexor 5 RJE - Remote Job Entry 7 ECHO echo Echo 9 DISCARD discard Discard 11 USERS systat Active Users 13 DAYTIME daytime Daytime 15 - netstat Network status program 17 QUOTE qotd Quote of the day 19 CHARGEN chargen Character Generator 20 FTP-DATA ftp-data File Transfer Protocol 21 FTP ftp File Transfer Protocol 23 TELNET telnet Terminal Connection 25 SMTP smtp Simple Mail Transport Protocol 37 TIME time Time 42 NAMESERVER name Host Name Server 43 NICNAME whois Who Is 53 DOMAIN nameserver Domain Name Server 77 - rje any private RJE service 79 FINGER finger Finger 93 DCP - Device Control Protocol 95 SUPDUP supdup SUPDUP Protocol

  18. Sequence Number • Segment number identifies the byte in the stream of data from the sending TCP to the receiving TCP, It represents the first byte of data in the segment. • The unit is not segments, but bytes.. • The size is 232 large enough to detect duplicate segments. TCP user TCP SEND (200 byte data) [seq=300, data] SEND (150 byte data) [seq=500, data] SEND (100 byte data) [seq=650, data]

  19. Sender TCP Receiver TCP [seq=1000, 100 byte data] [seq=1100, 200 byte data] [seq=1300, 100 byte data] [ACK=1400] Acknowledge Number • Accumulative ACK • By convention, the ACK number is the byte number of the segment that the receiver expects to receive next time.

  20. Duplicate segments in the same connection SN1 SN2 SN0 Transport Entity A Transport Entity B SN0 A times out and retransmits SN0 SN1 A times out and retransmits SN1 ACK3 SN3 ACK3 SN4 ACK4 Solution: sequence number space should be large enough SN5 ACK5 assumption: - seq. number: mod 8 - use the accumulative ACK SN6 ACK6 SN7 ACK7 ACK0 SN0 Obsolete SN0 arrives New SN0 arrives

  21. Duplicate segments in different connections(1) Transport entity A Transport entity B Old connection closed SN 2 SYN SYN New connection opened SN 0 SN 1 Obsolete segment SN = 2 is accepted; SN 2 valid segment SN = 2 is discarded as duplicate

  22. Duplicate segments in different connections(2) • Global numbering • If the sequence number of the last segment of the previous connection is N, new connection use the first sequence number that is distant from N. • TCP should remember the sequence number that was used in the last segment. • 2 MSL Timer • When TCP connection closes, new TCP connection is not allowed to open immediately. New connection can open after the amount of time has passed. • TCP implementation choose a value for the maximum segment life time(MSL). It is the max. amount of time any segment can exit in the network before being discarded. • TCP connection can be reused after 2MSL wait is over.

  23. Window Field • This field is used for TCP flow control (often called “Credit technique”). • It is used for a receiver to notify a sender of the size of empty space in the receiver TCP buffer. • The unit is bytes. • If the buffer size is larger than 216, it can be extended using the option field. • Its use is independent of the use of the acknowledge number field that denotes the success of failure of segment transmission.

  24. PUSH • Background • Normally, when the sending TCP receives data from the sending application process, TCP does not send the data immediately. Instead it stores the data in the its buffer, waiting for additional data arrive for the prevention of Silly Window Syindrom. • In the interactive application, however, the sending TCP is required to send data immediately. • PSH flag • The sending application process tells its TCP when to set the PUSH flag. • It is a notification to the sending TCP that the sending application process don’t want the data to hang around in the TCP buffer, waiting for additional data to fill the buffer. • When the receiver TCP receives the segment with the PSUH flag, it pass data to the receiver application process, telling not to wait until any additional data • The Socket API don’t provide a way for the application to tell its TCPto set the PUSH flag. Setting this flag is up to the TCP implementation. • BSD implementations ignores a received PUSH flag because they normally never delay the delivery of received data to the application.

  25. URGENT Bit & Urgent Pointer • Urgent mode • The sending TCP tell the other TCP that urgent data of some form has been placed into the normal stream of data. • The receiving TCP notifies the receiving application of the arrival of urgent data. The application process will decide what to do on its own way. • The URG bit is turned on and the urgent pointer is set to a positive offset that must be added to the sequence number field in the TCP header to obtain the sequence number of the last byte of urgent data. • In the socket API, sending application process can set this bit using SO OOB. • What is urgent mode used for? • The two most common uses are Telnet and Rlogin when interactive uses type the interrupt key(etc, ^C). Another is FTP, when interactive users abort a file transfer.

  26. TCP Option Fields • MSS (Maximum Segment Size) option • The maximum size of the data transmitted • When a connections established, each end can announce the MSS it expects to receive. An MSS option can only appear in a SYN segment. If one end does not receive an MSS option form the other end, a default of 536 bytes is assumed. • 576 (IP datagram default size) - 40 (IP/TCP header fixed size) • In general, the larger the MSS the better, until fragmentation occurs. • Window Scale Option • It increase the window size. It means the maximum window size can be 216x216=232. • New window size = window size defined in the header x 2window scale factor • The window size factor can be determined only during the connection setup phase. • Time stamp option • The sender fills the time stamp value when the segment leaves. When the receiver sends an ACK for this segment, it enters the time stamp value that it receives from the sender. When the sender receives the ACK, it can calculate the round trip time for this segment.

  27. Checksum 0 31 16 • The checksum applies to three parts: pseudo-header, TCP header, and the data coming form the application process) • Checking the pseudo-header prevent packets from being delivered to wrong hosts due to the corruption of the IP header. • Divide the total bits into 16-bit words. Add all 16-bit sections, using one’s complement arithmetic. Source IP address Pseudo-header Destination IP address Checksum scope Protocol id Segment length zero TCP header TCP segment User Data

  28. TCP summary • Connection establishment • 3 way handshake • Connection termination • support graceful close using the 3 way handshake. • also support abrupt close using ABORT primitive. • Data transfer • Each segment is assigned a sequence number with the unit of byte. • Error control by retransmission: selective repeat • Flow control by credit allocation • PUSH • URGENT POINTER • Reset service • RST

  29. primitive type Parameters UNSPECIFIED_PASSIVE_OPEN FULL_PASSIVE_OPEN ACTIVE_OPEN ACTIVE_OPEN_WITH_DATA OPEN_ID OPEN_SUCCESS OPEN_FAILURE SEND DELIVER ALLOCATE CLOSE CLOSING TERMINATE ABORT STATUS STATUS_RESPONSE ERROR Request Request Request  Request Local response Confirm Confirm Request Indication Request Request Indication Request Request Request Local Response Indicator S S C C C C C C/S C/S C/S C/S C/S C/S C/S C/S C/S C/S Source port, timeout, timeout-action, precedence, security range Source port, destination port, destination address, timeout, timeout-action, precedence, security range Source port, destination port, destination address, timeout, timeout-action, precedence, security range Source port, destination port, destination address, data, data length, push flag, urgent flag, timeout, timeout-action, precedence, security range Local connection name, source port, destination port, destination address Local connection name Local connection name Local connection name, data, data length, push flag, urgent flag, timeout, timeout-action Local connection name, data, data length, push flag, urgent flag Local connection name, data length Local connection name Local connection name Local connection name, reason code Local connection name Local connection name Local connection name, source port, source address, destination address, connection state, receive window, send window, waiting ack, waiting accept, urgent, precedence, security, timeout Local connection name, reason code Client/ Server TCP Primitives

  30. Usage of TCP Service Primitives TCP Client-IP-server Initiating(client)protocol Responding(server)protocol UNSPECIFIED_PASSIVE_OPEN ACTIVE_OPEN + ACTIVE_OPEN_WITH_DATA FULL_PASSIVE_OPEN + Connection establishment OPEN_ID OPEN_RECEIVED + OPEN_SUCCESS + OPEN_FAILURE SEND + + DELIVER Data transfer + + SEND DELIVER ALLOCATE ALLOCATE + + STATUS STATUS + Status/error reporting + STATUS_REPORT STATUS_REPORT + + ERROR ERROR CLOSE + + CLOSING + CLOSE + TERMINATE Connection clearing + TERMINATE ABORT + + TERMINATE

  31. Contents • TCP • TCP connection • TCP flow control • TCP congestion control • TCP timer • UDP

  32. TCP Connection setup and release client server SYN SYN, ACK ACK Application close FIN Deliver EOF to application ACK Application close FIN ACK

  33. TCP Connection Setup : 3 Way Handshake • Client-Server model Client TCP TCP Server ACTIVE_OPEN PASSIVE_OPEN Send SYN SYN=1, Seq=X Send SYN SYN=1, ACK=1, Seq=Y, ack=X=1 OPEN_RECEIVED Send ACK OPEN_SUCCESS ACK=1, Ack=Y+1

  34. TCP Connection Setup : 3 Way Handshake • Simultaneous open ACTIVE_OPEN ACTIVE_OPEN Send SYN SYN=1, Seq=Y Send SYN SYN=1, Seq=X Send ACK ACK=1, Ack=Y+1 ACK=1, Ack=X+1 Send ACK OPEN_SUCCESS OPEN_SUCCESS

  35. Robustness of 3 Way Handshake Obsolete SYN arrives B accept and acknowledges SYN i A rejects B’s connection SYN j, ACK i (a) Delayed SYN RST, ACK j SYN k, ACK p SYN i A initiates a connection. Old SYN arrives at A; A rejects B accepts and acknowledge RST, ACK k SYN j, ACK i ACK j A acknowledges and begins transmission SN i+1 (b) Delayed (SYN, ACK)

  36. TCP Half-Close: Graceful Disconnection client server Application shutdown FIN Deliver EOF to application ACK of FIN Application write data Application read ACK of data Application close FIN Deliver EOF to application ACK of FIN

  37. TCP Connection Release: 3 Way Handshake Server side Client side (a) TCP Server Client TCP ---- CLOSE FIN = 1, seq = X Send FIN Send ACK ACK = 1, ack = X+1 CLOSING Send FIN CLOSE FIN=1,seq=Y Send ACK TERMINATE ACK=1,ack=Y+1 ---- TERMINATE (b) ABORT Send RST RST = 1 TERMINATE

  38. Connection Release: 3 Way Handshake • Graceful disconnection – 3 way handshake • Since the TCP connection is full-duplex, when one end request termination, one way connection is terminate. But the other way connection can be maintained while the other end keeps sending data. • Abrupt disconnection • One-sided termination because of network failure, etc. In this case data can be lost.

  39. Connection Release: 3 Way Handshake • Graceful disconnection – 3 way handshake • Problem due to out-of-sequence • The one end sends FIN after sending the last segment. But the FIN segment arrives ahead of the last segment. • In this case, if the receiver TCP terminates as soon as it receives the FIN, the receiver loses the segment that arrives after connection closure. • To prevent this kind of loss, TCP assigns the sequence number to FIN segment, which have the number incremented from the sequence number of the last segment.. • When the other end is not cooperative to the termination request, • The requesting end terminates the connection when the timer times out.

  40. Crash & Connection Release • The half-open can happen when any end of the connection breaks down, since the other end cannot know the other end’s failure. • In the half-open, the other end keeps retransmitting segments allowed. If no reply arrives until the keepalive timer expires, it terminates the connection. • The TCP end that has broken down can terminate using RST segment after rebooting. • Since the rebooting TCP has lost all state information, it should send RST segments for all segment it received, and the other end that received RST segments must terminate the connection immediately.

  41. TCP Entity State Diagram SYN RECEIVE LAST ACK FIN WAIT 2 CLOSING TIME WAIT CLOSED FIN WAIT LISTEN CLOSED ESTAB CLOSE WAIT Receive SYN,ACK Send ACK Receive SYN,ACK Send ACK Receive FIN,ACK of SYN Send ACK Receive FIN Send ACK Receive FIN Send ACK Receive ACK of FIN Receive FIN,ACK Send ACK Unspecified Passive Open or Fully Specified Passive Open Active Open or Active Open with Data Initialize SV; Send SYN Initialize SV Close Clear SV Close Clear SV Receive SYN Receive SYN SYN SENT Send SYN ACK Send SYN ACK Receive ACK of SYN LEGEND SV = state vector MSL = maximum segment lifetime Close Send FIN Receive FIN Send ACK Close Send FIN Receive ACK of FIN Timeout (2MSL)

  42. Contents • TCP • TCP connection • TCP flow control • TCP congestion control • TCP timer • UDP

  43. TCP Traffic Control • Traffic control • There are two reasons for sender to reduce the rate of sending packets. • When receiver’s buffer space is not enough,  flow control • When the network is congested,  congestion control network congestion Small-capacity receiver

  44. Sliding Window Flow Control 0 0 1 1 2 2 3 3 0 0 1 1 2 2 3 3 Segments sent, but not acknowledged Segments that can be sent Window is shrinking as the segments are sent Window expands as the acks are received (a) sender’s window Segments that were received Segments that will be received Window is shrinking as the segments are received Window expands as acks are sent The last segment That was acked (b) receiver’s window

  45. Is the sliding window scheme enough? I(1) I(3) I(3) I(0) I(0) I(1) I(1) window size = 3 0 1 2 3 0 1 2 3 I(0) 0 1 2 3 0 1 2 3 I(2) 0 1 2 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 Window closed Window closed ACK(2) 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 3 0 1 0 1 2 3 0 1 2 3 Window closed ACKs not sent Window closed, BUSY CONDITION TIMEOUT Retransmit I(3),I(0),I(1) Make the receiver’s state worse!!

  46. What is wrong with the sliding window? • No distinction between the ACK and the current available buffer size. • When the receiver TCP receives segments uncorrupted and stores them in the buffer, but does not finish processing them, • If the TCP doesn’t send any ACK, then the sender’s timer expires and try to retransmit the segments. ==> It causes unnecessary loads to network! • Otherwise, if the TCP sends ACKs, then the sender transmits new segments, which may be discarded eventually. ==> aggravate the receiver’s condition! • Solution: credit allocation protocol • It distinguishes the ACK from the credit information. The ACK information informs the sender of successful transmission, while the credit information notifies the sender of the its current empty buffer size.

  47. Credit Allocation Protocol I(0) I(3) I(1) I(3) I(0) ACK 1, CDT 2 ACK 1, CDT 0 I(1) 0 1 2 3 0 1 2 3 window size = 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 I(2) 0 1 2 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 Closing Window Closing Window ACK 2, CDT 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 3 0 1 0 1 2 3 0 1 2 3 Closing Window Closing Window, BUSY CONDITION TIMEER Not retransmit I(3),I(0),I(1) 1 0 1 2 3 0 1 2 3 I(2) IDLE CONDITION Open Window

  48. Example of TCP Credit Allocation Mechanism. Transport Entity A Transport Entity B SN = 1401 ....1000 1001 2400 2401... ....1000 1001 2400 2401... SN = 1001 A may send 1400 octets B is prepared receive 1400 octets, SN = 1201 beginning with 1001 SN = 1601 .…2600 .…2600 ....1000 ....1600 ....1000 ....1600 2601 1601 1001 1001 1601 2601 1601 2401... 1601 ....1600 2601…. A shrinks its transmit window with each transmission A = 1601, W = 1000 B acknowledges 3 segments (600 octets) but is only prepared to receive 200 additional octets beyond the original budget (I.e., B will accept octets 1601 2401... 2001 through 2600 SN = 1601 SN = 1801 ....1600 1601 2001 2601…. 2001 2601…. A adjusts its window with each credit SN = 2001 SN = 2201 SN = 2401 2600 2601…. A exhausts its credit A = 2601, W = 1400 4000 4001.… 4000 4001.… B acknowledges 5 segments (1000 octets) and restore the original amount of credit A receive new credit

  49. 41 bytes IP packets A keystroke arrive 40 bytes ACK Application read 1 byte of keystroke 40 bytes window update Application echoes it 41 bytes IP packets Too Small Data & Immediate Window Update • Example of TELNET • When data arrives from application, if the sender TCP transmit it immediately, or the receiver TCP sends window update right after its buffer changes, then they have to exchange segments frequently, but do little.

  50. Application reads 1 byte Receiver’s buffer is full Room for one more byte Window update segment sent Header New byte arrives Header 1 byte Receiver’s buffer is full Silly Window Syndrome(caused by Receiver)