Transport Control Protocol

TCP

Connection-Oriented Service

Connection-oriented service has a handshake period

During this time, a logical connection is made with the destination node

The connection is ‘logical’, since all packets are forwarded individually, just like with UDP

Typically, connection-oriented service provides reliability, meaning:
 

Acknowledgements are used to ensure packets arrive Checksums/CRCs are used to ensure data integrity

Transport Control Protocol (TCP)

Like X.25, TCP provides connection-oriented delivery at a high level layer
  

X.25 provides it at the Transport OSI layer TCP provides it at the Transport IP layer Providing connection-oriented delivery at a high level allows TCP to be applied to any network  Thus the ability to use TCP/IP over Ethernet, Token Ring, etc. However, providing connection-orientation at a high level means that the network is not necessarily optimized for connection-oriented delivery  For example, Ethernet is optimized for connectionless delivery

the transport layer (and layers below it) must handle:   Segmentation and reassembly (SAR) Acknowledgements .TCP   The essence of TCP is to provide an apparently continuous stream of data Thus. above the transport layer:    Data is not fragmented (into packets) Data is in order Lost packets do not occur  Thus.

Fragmentation  Segmentation is basically the same as fragmentation. to divide the data into packets (above TCP layer data is continuous)  Only the source host will segment packets  Segmentation is a normal part of TCP’s job .Segmentation vs. with a few differences:   Fragmentation (IP layer):  …only occurs when transmitting a packet whose size is larger than the MTU of the destination network  Any router (connecting two different network types) could theoretically fragment packets  Fragmentation can almost be considered an emergency practice (what to do when something goes wrong) Segmentation (TCP layer):  Occurs for all data streams.

only has to reorder those messages into an apparently continuous stream of data flow .TCP  TCP is a reliable protocol    All data sent through TCP is automatically divided into packets Each of these packets is ensured to be sent by requiring the destination acknowledge the packets when they are received The destination. knowing it will eventually receive all messages.

a format where the data is oriented in such a way as to appear as a direct stream from source to destination  In reality. however.TCP: Stream Delivery Protocol  TCP abstracts data communication to appear as an apparent stream of flowing data:    The source sends data as a stream into the network The destination node receives data from the network in an identical form  The data arrives in the same order as it was sent  All data sent. for example) . the data is sent as packets (using IP datagrams. arrives (in its proper position) This is known as ‘stream orientation’.

where they can be read (byte by byte) . the source will retransmit the packet The destination node buffers the incoming packets into memory. until a certain amount has been obtained This data is packaged into one or more network packets (e. IP datagrams) and sent to the destination using connectionless delivery The destination should send an acknowledgement back to the source If this acknowledgement fails to arrive after a specified length of time.TCP: Stream Delivery Protocol  TCP is normally achieved by using buffering      Data is collected from the stream (and stored into memory).g.

TCP: Stream Delivery Protocol  The TCP/IP service layers do not contain a Presentation layer     For this reason. both UDP and TCP require that the applications recognize their own data formats For example. using TCP to connect and send an E-Mail message can be achieved using the existing data format (or language) known as SMTP (Simple Mail Transfer Protocol) Using TCP to connect and request WWW pages can be achieved using HTTP (HyperText Transfer Protocol) These protocols are implemented (generated and recognized) inside the applications themselves .

IP datagrams).TCP: Stream Delivery Protocol  Since TCP is actually implemented using packets (e.g. it was possible for TCP to ensure bi-directional communication across its connections  Transfer across TCP streams is full duplex .

is sent by B The third message (ACK) is an acknowledgement to B (from A) for the second message . both an acknowledgement of the first message as well as a request for connection to A. is a request for connection to the destination (B) The second message (SYN/ACK). sent by the machine issuing the ‘active open’ request (A).Connection Establishment  TCP uses a three-way handshake to establish a connection     This means 3 messages are exchanged before a connection exists The first message (SYN).

TCP Handshake SYN SYN/ACK Connection Establishment (Handshake) ACK Transmission of data .

and so on. an ACK is sent back to the source When the source receives the ACK.TCP Reliability  TCP provides reliability by requiring recipient nodes to send acknowledgments  Acknowledgements are sometimes called ACKs    When a packet is received by the destination. it sends the next packet And so on. … .

TCP Reliability S M M M M A A A A Network M M M A A A D .

but the ACK was somehow lost   TCP networks treat both situations identically The destination will receive the packet again. the acknowledgement will be received . and no ACK is received within a certain time.TCP Reliability  If a packet is sent. ignore it (it already has the data). the message will be retransmitted  This time is called the ‘timeout’  It is possible that the original packet was received. and acknowledge it again  Hopefully this time.

TCP Reliability S 10 6 5 4 3 2 9 8 7 1 M M M M Network M M M D .

TCP Reliability   If each node waited for acknowledgements without transmitting data. it would involve wasteful delays between packets in a series TCP uses a scheme called the ‘sliding window technique’ to solve this problem .

Sliding Window Technique     The sliding window technique allows a transmitting node to transmit more than one packet without waiting for an ACK Nodes cannot transmit more than S packets beyond the first unacknowledged packet  S is known as the window size Thus. another packet can be sent  The window index can be increased by one . transmitting nodes have a ‘window’ of up to S packets. all of which have already been sent  Some of these packets may be acknowledged  At least the first packet is unacknowledged (but sent) When an ACK is received for the first packet in the window.

Data: abcd efgh ijkl mnop Passage of Time Connection established …etc… .Sliding Window Technique  Let’s see an example without a sliding window:  Packet size: 4.

Data: abcd efgh ijkl mnop Passage of Time Connection established . Window size: 3.Sliding Window Technique  Let’s see the same example with a sliding window:  Packet size: 4.

only the sequencing number is required to indicate that a message has been received  Sequencing numbers are discussed later  Rather than send a small packet (ACK) followed by a larger packet (data). the ACK can be added to the packet and sent to B as one packet Essentially. the node sends a single larger packet (data with piggybacked acknowledgement) .Piggybacked ACKs  Often two node communicate back and forth   When an acknowledgement is to be sent from A to B. as well as a data packet.

TCP Layers Application Transport Control Protocol (TCP) Internet Protocol (IP) Network Interface Hardware .

TCP/UDP Layers Application TCP UDP Internet Protocol (IP) Network Interface Hardware .

TCP is built on top of IP datagrams   These datagrams must arrive correctly Therefore.TCP Header Information  As stated previously. . TCP streams are often created using the same information as would be used in the IP datagram header:    Address (network and machine portion) Header checksum etc.

ports should be used to represent which stream is which These ports are the same ones used for UDP This makes sense.Ports  Multiple TCP streams can be active on any machine    Therefore. considering both use IP datagrams for their implementation .

a socket are associated with a network port on the machine  A machine (and even a single program) may have several open sockets at any time . to programmers. represent connections to the network  In some sense.Sockets  Sockets.

sockets can be shared:   Datagrams from different destinations can be received on the same socket Datagrams can be sent to multiple destinations through the same socket  In TCP.Sockets  In UDP. sockets can not be shared:   TCP sockets (or stream sockets) represent an active connection with the other side Both source and destination must have an active socket open for communication to occur .

and can be used by the initiating node when requesting the connection The initiating node requests a connection with a given machine (specified by its address) at a particular port If the machine has a passive open registered at that port.Stream Sockets  With stream sockets. the connection will be accepted. otherwise it will not  The side that initiates a connection requests an ‘active open’   . one side must initiate the connection  The side that will accept a connection requests a ‘passive open’ with its operating system   This indicates that the OS should accept incoming connection requests A port is associated with the passive open.

Stream Sockets  The socket that represents a ‘passive open’:   Is called a server socket Represents the willingness to accept connections  The socket that represents an ‘active open’:   Is called a client socket Represents the act of actually connecting to a server socket .

data is retransmitted . the checksum computed using the data at the destination will be different than the checksum computed on the source side (and transmitted along with the data) If checksums do not match:  Data is corrupt  The checksum is corrupt  Both situations are treated identically in TCP.Data Corruption  TCP uses a 16 octet checksum to ensure that data has not been corrupted   If data is changed in any way.

in any amount of time. unacknowledged packets are sent after increasing timeouts   This prevents packets from being indefinitely lost because the timeout value is too short for extremely high network usage situations Unless a message is undeliverable. the message will eventually reach its destination and be acknowledged .Retransmission  Similar to re-collision avoidance backoff.

Connection Use   Once a connection has been made. sequence numbers are used to represent packets that make up the data stream Sequence numbers indicate the position of the data in the packet in the data stream .