300 likes | 527 Views
TCP : Transmission Control Protocol. Computer Network System Sirak Kaewjamnong. Agenda. Service provide by TCP TCP format How TCP reliable TCP connection TCP state. TCP Encapsulation. With Ethernet frame. Segment. Ethernet header. IP header. TCP header. data. TCP and UDP Services.
E N D
TCP : Transmission Control Protocol Computer Network System Sirak Kaewjamnong
Agenda • Service provide by TCP • TCP format • How TCP reliable • TCP connection • TCP state
TCP Encapsulation • With Ethernet frame Segment Ethernet header IP header TCP header data
TCP and UDP Services TCP : Transmission Control Protocol • RFC 793 • connection-oriented service • full duplex • reliable service by adding more overhead to manage acknowledgement, flow control and timer
TCP TCP performs typical transport layer function • passed data to relevant application-level services • error recovery • flow control data stream (avoid buffer overflow)
TCP Properties • Byte stream with full duplex transferring • adaptive to LAN/WAN • congestion avoidance and control
TCP Data Stream • TCP provides a full duplex that simultaneous manages two streams of data • Stream of octets passed between sender and receiver Application Receive Send Application Send Receive
Ports • Port : A 16 bits address allocated for the most common application level service • UDP and TCP use port addressing to deliver information to applications • Service are known by port number • FTP 20, TELNET 23, SMTP 25, HTTP 80
Ports • Port numbers are generally allocated by • 0 not used • 1- 255 Reserves port to well known service • 256 - 1023 Other reserve port • 1024 - 65535 user defined server ports • UNIX store general used ports in /etc/service
Transmission Control Protocol • TCP passed block of data to IP, consisting of the TCP header and application layer data, called SEGMENT • Adding reliability in TCP achieved by • Error detection and correction (due to segment corrupted) • Flow control (prevent a transmitter overrunning a receiver owing a resource limitations) • Resequencing (IP and deliver datagrams in any order) • Removing duplicate segments (due to error recovery mechanism used by TCP)
How TCP handles Reliability • Using sequence number to identify data • positive acknowledgments of data received in the correct sequence • retransmission of segments which have not been acknowledgment within a variable time limit • Let’s see these mechanisms in TCP header
0 15 16 31 Source Port : 16 Destination Port : 16 Sequence Number : 32 Acknowledgment Number : 32 Data offs :4 Resv:6 Flag:6 Window Size : 16 Checksum : 16 Urgent Pointer : 16 Option and Padding TCP Header
TCP Header Details (I) • Source, destination port: 16, 16 - identify application at ends of the connection • sequence : 32 - indicates 1st data octet in this segment • acknowledgment : 32 - next expected sequence number, valid only when the ACK bit (reside in flag) is set • data offset : 4 - 32 bit words offset tells the receiver where user data begins
TCP Header Details (II) • Reserve : 6 - not used • Flag : 6 • URG : validity of urgent pointer field • ACK : validity of acknowledgment field • PSH : push request (pass segment to application layer immediately) • RST : reset the connection • SYN : initial synchronization • FIN : send at end of byte stream
TCP Header Details (III) • Window: 16 - advertise amount of buffer space this node has allocated • checksum : 16 - 16 bits one’s complement of pseudo header, TCP header and data • urgent pointer : 16 - byte position of data that should be processed first • options : - variable length option e.g. max segment size tells destination node
TCP in Action • Before data could be transferred, a connection must be opened • Server do passive open (listen) • Client do active open (connect) • When it finished, the connection is closed • TCP has general 3 phases • Connection setup phase • Data phase • Connection close phase
TCP Connection Establishment TCP uses 3-ways handshake to establish a connection • Exchange the sequence number • Ensures that both ends are ready and sync sequence number Host B Host A 1. send SYN (seq = x) 2. Send SYN (seq = y, ack = x+1) 3. send ACK (ack = y+1) Connection is setup
TCP Transfer Phase • Simple example with terminal connection such as telnet. Host echoes back each received character Host B Host A 1. SEQ = 92, ACK =109 Data = “W” Host echoes back “W” 2. SEQ = 109, ACK = 93, Data = “W” 3. SEQ = 93, ACK =110 Data = “ A”
Host B Host A TCP Connection Close • Use FIN flag to close connection 1. FIN_WAIT_1 Seq = x, 2. CLOASE_WAIT, Ack = x +1 3.FIN_WAIT_2 4. LAST_ACK, Seq = y 5.TIME_WAIT Ack = y+1 Connection is close
Open/Close Mechanisms • Haft open: one end has closed, aborted without the knowledge of the other end • Host may be crashed, power off • No detection if no data transfer • Reset segment (RST bit)is sent when detected • Half close: one end of connection terminated its output, but still receiving data from the other end • Simultaneous open: both end perform an active open to each other • Simultaneous close: both end perform an active close to each other
Sliding Window Principle • Send and wait for acknowledgment • no ACK within a certain time, retransmit the packet • use for flow control: • prevent sender from overloading receiver with data, e.g. fast server to slow PC • congestion inside network, e.g. router performance, slow link speed • How to provide flow control • set the appropriate size of sliding window size
Sliding Window Flow Control • Receiver advertises it’s window size in acknowledgments • Sender will adjusts its allowed to send pointer as receiver’s advertisement
Sliding Window : Small Window Size Window size = 1 • 1 byte window size utilizes efficiency of channel in haft (haft-duplex transmission) • Why not send many packets and get back cumulative ACK? Send 1 Receive 1 Ack 2 Sender Receiver Send 2 Receive 2 Ack 3
Sliding Window : Larger Window Size Window size = 3 Send 1 Send 2 Send 3 Receive ACK 4 Send 4 Send 5 Send 6 Receive 1 Receive 2 Receive 3 Send ACK 4 Receive 4 Receive 5 Receive 6 • A larger window size allows more data to be transmitted pending acknowledgment • Window size specifies how many bytes the receiver is willing to accept Receiver Sender
Sliding Window Buffer • Sender groups its packet to be transmitted with window indication Offer window SndWnd Sent and not ACK Can Send ASAP Can’t Send now Sent and ACK … 999 1000 …. 1099 1100…1199 1200 ... SndUna SndNxt SndUna + SndWnd
… 999 … 999 … 999 1000 …. 1099 1000 …. 1099 1000 …. 1099 1100…1199 1100…1199 1100…1199 1200 ... 1200 ... 1200 ... TCP in Action Movement of the right and left edges of the window Initial SndUna,SndNxt SndUna + SndWnd Send 100 bytes SndUna SndNxt SndUna + SndWnd More 100 bytes SndUna SndNxt, SndUna + SndWnd ACK 100 bytes … 999 1000 …. 1099 1100…1199 1200 ... 1299 SndUna SndNxt SndUna + SndWnd
Error Recovery (I) Host B • Receiver had to send ACK with sequence number • Sender reset timer when receives ACK Host A Segment #i, Start timer ACK i+1 Reset timer
Error Recovery (II) Host B • On time out, sender will retransmit the segment • This mechanism is used for error recovery Host A Segment #i, Start timer Timer expires, resend #i ACKi+ 1 Reset timer