Presentation on theme: "資 管 Lee Lesson 9 Transmission Control Protocol (TCP)"— Presentation transcript:
資 管 Lee Lesson 9 Transmission Control Protocol (TCP)
資 管 Lee UDP TCP/IP protocol suite specifies two protocols for the transport layer:UDP and TCP ICMP IP ARP RARP TCP UDP IGMP SMTPFTPTFTPDNSSNMP BOOTP Application layer Transport layer Network layer Data link layer Physical layer Underlying LAN or WAN technology
資 管 Lee Internet Process (Running application program) Process (Running application program) Domain of IP protocol Domain of TCP protocol Port Numbers are integers between 0 and 65,535
資 管 Lee IP header … TCP header Port number selects the process Processes PortProtocolDescription 7EchoEchoes a received datagram back to the sender 9DiscardDiscards any datagram that is received 11UsersActive users 13DaytimeReturns the date and the time 17QuoteReturns a quote of the day 19ChargenReturns a string of characters 20FTP, DataFTP, data connection 21FTP, ControlFTP, control connection 23TELNETTerminal Network 25SMTPSimple Mail Transfer Protocol 53DNSDomain Name Server 67BOOTPBootstrap protocol 79Finger 80HTTPHypertext Transfer Protocol 111RPCRemote Procedure Call Socket address TCP Services Stream Data Service Full-Duplex Service Reliable Service
資 管 Lee Segment in TCP unit of data Source port number (16 bits) Destination port number (16 bits) Sequence number 32 bits Acknowledge number 32 bits HLEN + Reserved (4 +6)bits Window size 16 bits Checksum 16 bits Urgent pointer 16 bits Options & padding HeaderData TCP Segment format Seq. number: 32 bits tells the dest. Which byte in this sequence comprises the first byte in the segment. ACK number: defines the byte number that the source of the segment is expecting to receive from the other party. Header length (4bits): 20 to 60 bytes, value is 5 to 15. Reserved(6 bits): future use. Control: six control bits or flags. Windows size: defines the size of window in bytes. Checksum: 16 bits Urgent pointer: defines the number that must be added to the sequence number to obtain the number of the last urgent byte. FlagDescription URGThe value of the urgent pointer field is valid ACKThe value of the acknowledge field is valid PSHPush the data RSTThe connection must be reset SYNSynchronize sequence numbers during connection FINTerminate the connection
資 管 Lee Options in TCP Header Up to 40 bytes of optional information. Five options: end of option, no operation, Maximum segment size, window scale factor, and timestamp. Code: Code: End of optionMax. segment size option: define the max size of data, determined by the destination, default is 536. Code: Length: Maximum segment size No option 1 byte 2 bytes
資 管 Lee Options in TCP Header Window scale factor: 16 bits means from 0 to bytes. For a high channel (fiber-optic). Need a big window size. New = defined x 2 window size factor Code: Length: Scale factor 1 byte Code: Length: Timestamp value Timestamp echo reply Timestamp: 10-byte option. The timestamp field is filled by the source when segment leaves. The destination receives the segment and stores the timestamp value. When the destination sends an acknowledgement for the bytes, it enters the previously stored value in the echo reply field. The source checks the current time versus this value. The difference is the round-trip time.
資 管 Lee 資 管 Checksum field in TCP packet 32-bit source IP address 32-bit destination IP address All 0s 8-bit protocol (6) 16-bit TCP total length Source port number (16 bits) Destination port number (16 bits) Sequence number 32 bits Acknowledge number 32 bits HLEN 4 bits Window size 16 bits Checksum 16 bits Urgent pointer 16 bits Options & padding Data Pseudoheader Header + options Data
資 管 Lee Flow Control Sliding Window for flow control Sliding window Sliding window Pointer Bytes 4 to 7 have been sent Bytes 8 to 13 can be sent Bytes 14~ cannot be sent TCP uses two buffers and one window to control the flow of data. The sending part has a buffer and the size of the window. The size of the window in the sending TCP is determined by the receiver and is announced in the ACK segments.
資 管 Lee Window management Sender Seq: 1001, 4000 bytes ack: 5001 win: 0 ack: 5001 win:1000 Seq: 5001, 1000 bytes Receiver 4000 Buffer 1000 Buffer The sending TCP sends 4K of data in its first segment. The buffer of the receiver windows becomes full. The receiver TCP ACK the receipt of the segment, but announces a window size of zero. The sending TP can not send any more data. It must wait for ack advertising a nonzero window size.
資 管 Lee Silly Window Syndrome Sending application creates data slowly or the receiving application consumes data slowly. If TCP contain only 1 byte of data. It means that we are sending a 41-byte that transfer only 1 byte. Meaning that using the capacity of the network very inefficiently. Syndrome Created by the sender: Nagle’s Algorithm ◦ The sending TCP sends the first piece of data it receives from the sending application program even if it is only one byte. ◦ After sending the first segment, the sending TCP accumulates data in the output buffer and waits until either the receiver TCP sends an ack or until enough data has accumulated to fill a max. segment. ◦ The above procedure is repeated. Syndrome created by the receiver: Clark’s solution and delayed Acknowledgement. ◦ Clark’s solution is to send an ack as soon as the data arrives, but to announce a window size of zero until either there is enough space to accommodate a segment of max-size or until half of the buffer is empty. ◦ Delayed ack is to delay sending the ack. This means that when a segment arrives, it is not ack immediately. The receiver waits until there is a decent amount of space in its incoming buffer before ack the arrived segments. Delayed ack bring another advantage, it reduces traffic. Yet, there also is a disadvantage that it may force the sender to retransmit the unpacked segment.
資 管 Lee Error Control TCP is a reliable transport layer protocol. Reliable means segments in order, without error, and without any part lost or duplicated. TCP provides reliability using error control. Error control includes mechanisms for detecting corrupted segments, lost segments, out-of-order segments, and duplicated segments. Error detection in TCP is achieved through the use of three simple tools: checksum, acknowledge, and time-out. Case 1: Corrupted Segment: Sender resend the corrupted segment after time-out, the receiver discarded the corrupted segment. Case 2: Lost Segment: Sender resend the corrupted segment after time-out. Case 3: Duplicate Segment: sender resend the segment after time-out but the ACK is only delayed. The receiver simply discard the duplicate segment. Case 4: Out-of-Order Segment: the segment that receiver before its previous segment would not ACK immediately instead they are buffer until its previous segments are all received and the ACK is resend. Case 5: Lost ACK: TCP uses an accumulative ACK system. Any ACK confirm everything up to the byte specified by the ACK number. So, if ACK 1601 is lost, but ACK 1801 is received, there is a confirmation up to 1801.
資 管 Lee Error Detection and Correction Sender Seq: 1201, 200 bytes ack: 1601 Receiver Seq: 1201, 200 bytes Seq: 1401, 200 bytes Seq: 1601, 200 bytes Time-out ack: 1801 OK Data corrupted
資 管 Lee TCP Timers TCP uses the four timers: retransmission timer, Persistence timer, Keepalive Timer, and Time-Waited Timer. retransmission timer: handles the waiting time for an acknowledgement of a segment. Retransmission time = 2 x RTT (round-trip time) RTT = x previous RTT + (1- ) x current RTT Persistence timer: when face with the zero window-size advertisement, TCP need this timer to solve the might deadlock problem if the receive resume to send the ack, but lost in the transmit. Keepalive timer: prevent a long idle connection between two TCPs. Suppose that a client opens a TCP connection to a server, transfers some data, and becomes silent. Time-waited timer: used during connection termination. When TCP closes a connection, it doesn’t consider the connection really closed. The connection is held in limbo for a time-waited period.
資 管 Lee Connection_Three way handshaking Sender Seq: 1201, 200 bytes Seq: 4800, ack:1201 Receiver Seq: 1200, ack: -- TCP is a connection-oriented protocol which establishes a virtual path between the source and destination. Three-way Handshaking Seq: 1201, ack=4801 Segment 1: SYN Segment 3: ACK Segment 2: SYN+ ACK Step 1: the client sends the first segment, a SYN segment. The segment includes the source and destination port numbers,… Step 2: the server sends the second segment, a SYN and ACK segment. This segment has a dual propose. First, it acknowledges the receipt of the first segment using the ACK flag and ack number. Second, the segment is used as the initialization segment for the server. Step 3: The client sends the third segment. This is just an ACK segment.
資 管 Lee Connection Termination_ Four-way Handshaking Four-way Handshaking to terminate the connection. Sender Seq: 1201, 200 bytes Seq: 7000, ack:2501 Receiver Seq: 2500, ack: -- Seq: 2501, ack=7002 Segment 1: FIN Segment 4: ACK Segment 2: ACK Seq: 7001, ack:2501 Segment 3: FIN Step 1: the client sends the first segment, a FIN segment. Step 2: the server sends the second segment, a ACK segment to confirm the receipt of the FIN segment. Step 3: the server TCP can continue sending data in the server-client direction. When it does not have any more data to send, it sends the third segment. FIN segment. Step 4: the client TCP sends the fourth segment an ACK segment to confirm the receipt of the FIN segment.
資 管 Lee TCP Operation Message from process TCP header TCP data IP header IP data Frame header Frame data Process a. Encapsulation b. Decapsulation Message from process TCP header TCP data IP header IP data Frame header Frame data Process
資 管 Lee TCP Operation TCP TELNET client Port Incoming queue Outgoing queue TCP TELNETserver Port 23 Incoming queue Outgoing queue Use of TCP TCP uses a buffer to store the stream of data coming from the sending application program, the sending TCP has the choice to create segments of any size from the stream. The receiving TCP also buffers the data when they arrive and delivers them to the application program when the application program is ready or when receiving is o.k. Push operation is used when a keystore in the interactive way.
資 管 Lee TCP design_state transition diagram Urgent Data TCP uses a buffer to store the stream of data coming from the sending application program. It wants to abort the process, but it has already sent a huge amount of data. If it issues a abort command (control+C), these two characters will be stored at the end of the receiving TCP buffer. The solution is to send a segment with the URG bit set. The sending application tells the sending TCP that the piece of data is urgent. The sending TCP creates a segment and inserts the urgent data at the beginning of the segment. statedescription CLOSEDThere is no connection LISTENThe server is waiting for calls from the client SYN-SENTA connection request is sent; waiting for ack SYN-RCVDA connection request is received ESTABLISHEDConnection is established FIN-WAIT-1The application has requested the closing of the connection FIN-WAIT-2The other side has accepted the closing of the connection CLOSINGBoth sides have decided to close simultaneously TIME-WAITWaiting for retransmitted segments to die CLOSE-WAITThe server is waiting for the application to close LAST-ACKThe server is waiting for the last ack
資 管 Lee CLOSED LISTEN SYN-SENT ESTABLISHED CLOSING FIN WAIT-1 CLOSE WAIT SYN-RCVD FIN WAIT-2 TIME- WAIT Active open/SYN SYN /SYN+ACK SYN+ACK/ACK Close /FIN ACK /- FIN/ACK (Time-out) passive open/- SYN/SYN+ACK ACK/- FIN/ACK Close /ACK LAST ACK ACK/- FIN /ACK ACK/- Send /SYN RST /- FIN+ACK/ACK Close or time-out/- time-out/RST Green line for Client Red line for server Dot line for unusual situations States shown in ovals. Directed lines defines transition. Each line has two strings separated by a slash. The first is the input, what TCP receives, the second is the output, what TCP sends.
資 管 Lee Client Diagram Initiations: ◦ The client TCP starts in the CLOSED state. Connection establishment: ◦ While in this state, the client TCP can receive an active open reuest from the client application. It sends s SYN segment to the server TCP and goes to the SYN-SENT state. ◦ In this state, the client TCP can receive an SYN+ACK segment from the other TCP. It sends an ACK segment to the other TCP and goes to the ESTABLISHED state. Data transfer state. ◦ In the ESTABLISHED state, data transfers. The client remains in this state as long as it is sending and receiving data. Connection termination: ◦ While in this state, the client TCP can receive a close request from the client application. It sends a FIN segment to the other TCP and goes to the FIN-WAIT-1 state. ◦ While in this state, the client TCP waits to receive an ACK from the server TCP. When the ACK is received, it goes to the FIN-WAIT-2 state. It does not send anything. Now the connection is closed in one direction. ◦ The client remains in this state for the server to close the connection from the other end. If the client receives a FIN segment from the other end, it sends an ACK segment and goes to the TIME-WAIT state. ◦ When the client is in this state, it starts a timer and waits until this timer goes off. the value of this timer is set to double the lifetime estimate of a segment of maximum size. The client remains in the state before totally closing to let all duplicate packets, if any, arrive at their destination to be discarded. After the time-out, the client goes to the CLOSED state, where it began.
資 管 Lee Server Diagram Initiation: ◦ The server TCP starts in the CLOSED state. Passive for connection: ◦ While in this state, the server TCP can receive an passive open request from the server application. it goes to the LISTEN state. ◦ In this state, the server TCP can receive an SYN segment from the client TCP. It sends an SYN+ACK segment to the client TCP and goes to the SYN-RCVD state. ◦ While in this state, the server TCP can receive an ACK segment from the client TCP. It goes to the ESTABLISHED state. This is the data transfer state. Data transfer: ◦ In the ESTABLISHED state, data transfer. The server remains in this state as long as it is sending and receiving data. Passive for termination: ◦ While in this state, the server TCP can receive a FIN segment from the client TCP. It can send an ACK segment to the client and goes to the CLOSE-WAIT state. ◦ While in this state, the server TCP waits until it receives a close request from the server program. It then sends a FIN segment to the client and goes to the LAST-ACK state. ◦ When the server is in this state, the server waits for the last ACK segment. It then goes to the CLOSED state.
資 管 Lee TCP Design Output Processing module 4 components: (two data-structures plus three modules) Control-block table: keep tracks of the open ports. Four fields: the state, the Process ID, the port number, and the corresponding queue number. Input Queues: s set of input queues, one for each process. Control-block module …… TCBs TCP Segment IP TCP Input Processing module TCP Segment Application layer Message from application
資 管 Lee Transmission Control Blocks (TCBs) StateProcessLocal IP address…..Pointer State: defines the state of connection Process: process ID and server/client, … Local IP address: Local port number: Remote IP address: Remote port number: Interface: local interface Local window: comprise several subfields, holds information about the window at the local TCP Remote window: Sending sequence number: Receiving sequence number: Sending ACK number: Round-trip time: several fields holds information about the RTT Time out values: several fields hold the values of different time-out values such as retransmission time-out, persistence time-out,… Buffer size. Buffer pointer
資 管 Lee Main Module operation Receive: a TCP segment, a message from an application or a time-out event 1. Search the TCB table 2. if (corresponding TCB is not found) 1) Create a TCB with the state CLOSED 3. find the state of the entry in the TCB table. 4. case (state) CLOSED: 1. if (passive open” message from application received) 1. change the state to LISTEN 2. if (“active open” message from application received) 1. send a SYN segment 2. change the state to SYN-SENT 3. if(any segment receive) 1. send an RST segment 4. if (any other message received) 1. issue an error message 5. return LISTEN: ….
資 管 Lee Quiz 1 Question 2: The following is a dump of a TCP header in hexadecimal format FF Q: What is the source port number, destination port number, sequence number, ack number, length of the header, type of the segment, and the window size? Question 1: Fill the procedures in the MAIN operation for the LISTEN state?
資 管 Lee Main Module operation ANS 1: case (state) LISTEN: 1. if (” send data” message from application received) 1. send a SN segment. 2. change the state to SYN-SENT. 2. if (SYN segment received) 1. send a SYN+ACK segment 2. change the state to SYN-RCVD 3. if (any other message received) 1. issue an error message 4. return ANS 2:
資 管 Lee Quiz 2 1. Explain connection establishment procedure in TCP? 2. Explain connection termination procedure in TCP? 3. Explain flow control in TCP? 4. Explain error control in TCP? 5. Write out the Main module operation for State: SYN-SENT? 6. Compare TCP and UDP in terms of connection, flow control, and error control? 7. Compare the header between TCP and UDP?