Wednesday, September 4, 2013

TCP and UDP

Transport Layer Protocols

The Transport layer is responsible for providing mechanisms for multiplexing upper-layer applications, establishing sessions, and tearing down virtual circuits. It also hides details of any network-dependent information from the higher layers by providing transparent data transfer.
The two most common Transport layer protocols of TCP/IP protocol suite are Transmission Control Protocol (TCP) and User Datagram Protocol (UDP). Both protocols manage the communication of multiple applications. The differences between the two are the specific functions that each protocol implements.

Flow Control

Data integrity is ensured at the Transport layer by maintaining flow control and by allowing
users to request reliable data transport between systems. Flow control prevents a sending host
on one side of the connection from overflowing the buffers in the receiving host—an event that
can result in lost data. Reliable data transport employs a connection-oriented communications
session between systems, and the protocols involved ensure that the following will be achieved:
  • The segments delivered are acknowledged back to the sender upon their reception.
  • Any segments not acknowledged are retransmitted.
  • Segments are sequenced back into their proper order upon arrival at their destination.
  • A manageable data flow is maintained in order to avoid congestion, overloading, and data loss.

The Transport layer provides for the segmentation of data and the control necessary to reassemble these pieces into the various communication streams. Its primary responsibilities to accomplish this are:
  1. Tracking the individual communication between applications on the source and destination hosts
  2. Segmenting data and managing each piece
  3. Reassembling the segments into streams of application data
  4. Identifying the different applications


 Transmission Control Protocol (TCP)

Transmission Control Protocol (TCP) takes large blocks of information from an application and breaks them into segments. It numbers and sequences each segment so that the destination’s TCP stack can put the segments back into the order the application intended. After these segments are sent, TCP (on the transmitting host) waits for an acknowledgment of the receiving end’s TCP virtual circuit session, retransmitting those that aren’t acknowledged.

This type of communication is called connection-oriented. During this initial handshake, the two TCP layers also agree on the amount of information that’s going to be sent before the recipient’s TCP sends back an acknowledgment. With everything agreed upon in advance, the path is paved for reliable communication to take place.

TCP is a full-duplex, connection-oriented, reliable, and accurate protocol, but establishing all
these terms and conditions, in addition to error checking, is no small task. TCP is very complicated
and, not surprisingly, costly in terms of network overhead. And since today’s networks are
much more reliable than those of yore, this added reliability is often unnecessary.

Connection-Oriented Communication

In reliable transport operation, a device that wants to transmit sets up a connection-oriented
communication with a remote device by creating a session. The transmitting device first establishes
a connection-oriented session with its peer system, which is called a call setup or a three way
handshake. Data is then transferred; when the transfer is finished, a call termination takes
place to tear down the virtual circuit.

TCP Segment Format

The TCP header is 20 bytes long, or up to 24 bytes with options. You need to understand
what each field in the TCP segment is:
  1. Source port The port number of the application on the host sending the data.
  2. Destination port The port number of the application requested on the destination host.
  3. Sequence number A number used by TCP that puts the data back in the correct order or retransmits missing or damaged data, a process called sequencing.
  4. Acknowledgment number The TCP octet that is expected next. Header length The number of 32-bit words in the TCP header. This indicates where the data begins. The TCP header (even one including options) is an integral number of 32 bits in length.
  5. Reserved Always set to zero.
  6. Code bits Control functions used to set up and terminate a session.
  7. Window The window size the sender is willing to accept, in octets.
  8. Checksum The cyclic redundancy check (CRC), because TCP doesn’t trust the lower layers
    and checks everything. The CRC checks the header and data fields.
  9. Urgent A valid field only if the Urgent pointer in the code bits is set. If so, this value indicates
    the offset from the current sequence number, in octets, where the first segment of non-urgent
    data begins.
  10. Data Handed down to the TCP protocol at the Transport layer, which includes the upperlayer
    headers.

User Datagram Protocol (UDP) 

UDP is a simple, connectionless protocol, described in RFC 768. It has the advantage of providing for low overhead data delivery. The pieces of communication in UDP are called datagrams. These datagrams are sent as "best effort" by this Transport layer protocol.

Applications that use UDP include:
  • Domain Name System (DNS)
  • Video Streaming
  • Voice over IP (VoIP)
UDP does not sequence the segments and does not care in which order the segments arrive at the destination. But after that, UDP sends the segments off and forgets about them. It doesn’t follow through, check up on them, or even allow for an acknowledgment of safe arrival—complete abandonment. Because of this, it’s referred to as an unreliable protocol