The TCP/IP Model

Overview#

The OSI model mostly serves as a reference model and the TCP/IP model is a simpler version which is practically used.

As compared to 7 layers in the OSI model, the TCP/IP model has 4 layers.

The 4 Layers#

  • Application Layer
  • Transport Layer
  • Internet Layer
  • Network Access Layer

Source: https://i1.wp.com/networkustad.com/wp-content/uploads/2019/04/OSI-vs-TCPIP.png?fit=1024%2C995&ssl=1

Application Layer#

The application layer here performs the functions of the top 3 layers of the OSI model which are Application, Presentation and Session layers.

This layer supports protocols such as HTTP(S), FTP, TFTP, Telnet, SSH, SMTP, DNS, DHCP etc.

Host-to-Host Layer#

This layer is analogous to the transport layer of the OSI model. This layers supports the end-to-end communication and error-free data delivery.

The 2 main protocols here:

  1. Transmission Control Protocol (TCP) - Reliable and error-free communication. Performs sequencing and segmentation of data. Has an acknowledgement feature and has flow control mechanisms. However, it also comes with a increased overhead.
  2. User Datagram Protocol (UDP) - Does not have such features as TCP, but is very lightweight and fast. UDP is also connectionless. Very useful for real-time communication, where we do not usually require re-sending of faulty packets.

See below for a complete table of differences between the 2 protocols.

Internet Layer#

This layer is analogous to OSI's Network layer. It defines the protocols responsible for logical transmission of data over the network.

The protocols at this layer are:

  • Internet Protocol (IP): responsible for delivering packets from source to destination by identifying IP addresses in packet headers. IPv4 and IPv6 exist. IPv6 supports the growing number of IP addresses.
  • Internet Control Message Protocol (ICMP): Encapsulated within IP datagrams and is responsible for providing hosts with information about network problems.
  • Address Resolution Protocol (ARP): Finds the hardware address of a host from a known IP address.

Network Access Layer#

This layer corresponds to both the Data Link layer and Physical layer from OSI model.

It looks out for hardware addressing and protocols present here help with the physical transmission of data.

Adapted from: https://www.geeksforgeeks.org/tcp-ip-model/

TCP 3-Way Handshake#

The 3-way handshake is a method used to establish a TCP/IP connection over the IP network. A simplified sequence of events for this handshake is:

3-way handshake

Credits: GeeksforGeeks

  1. Host A sends a SYNchronize packet to Host B
  2. Host B receives this SYN packet
  3. Host B sends a SYNchronize-ACKnowledgement packet to Host A
  4. Host A receives the SYN-ACK packet
  5. Host A sends an ACKnowledge packet to Host B
  6. Host B receives the ACK packet
  7. TCP socket connection is now established

TCP vs UDP#

FactorTCPUDP
Acronym forTransmission Control ProtocolUser Datagram Protocol or Universal Datagram Protocol
ConnectionTCP is a connection-oriented protocol.UDP is a connectionless protocol.
FunctionAs a message makes its way across the internet from one computer to another. This is connection based.UDP is also a protocol used in message transport or transfer. This is not connection based which means that one program can send a load of packets to another and that would be the end of the relationship.
UsageTCP is suited for applications that require high reliability, and transmission time is relatively less critical.UDP is suitable for applications that need fast, efficient transmission, such as games. UDP's stateless nature is also useful for servers that answer small queries from huge numbers of clients.
Use by other protocolsHTTP, HTTPs, FTP, SMTP, TelnetDNS, DHCP, TFTP, SNMP, RIP, VOIP.
Ordering of data packetsTCP rearranges data packets in the order specified.UDP has no inherent order as all packets are independent of each other. If ordering is required, it has to be managed by the application layer.
Speed of transferThe speed for TCP is slower than UDP.UDP is faster because error recovery is not attempted. It is a "best effort" protocol.
ReliabilityThere is absolute guarantee that the data transferred remains intact and arrives in the same order in which it was sent.There is no guarantee that the messages or packets sent would reach at all.
Header SizeTCP header size is 20 bytesUDP Header size is 8 bytes.
Common Header FieldsSource port, Destination port, Check SumSource port, Destination port, Check Sum
Streaming of dataData is read as a byte stream, no distinguishing indications are transmitted to signal message (segment) boundaries.Packets are sent individually and are checked for integrity only if they arrive. Packets have definite boundaries which are honored upon receipt, meaning a read operation at the receiver socket will yield an entire message as it was originally sent.
WeightTCP is heavy-weight. TCP requires three packets to set up a socket connection, before any user data can be sent. TCP handles reliability and congestion control.UDP is lightweight. There is no ordering of messages, no tracking connections, etc. It is a small transport layer designed on top of IP.
Data Flow ControlTCP does Flow Control. TCP requires three packets to set up a socket connection, before any user data can be sent. TCP handles reliability and congestion control.UDP does not have an option for flow control
Error CheckingTCP does error checking and error recovery. Erroneous packets are retransmitted from the source to the destination.UDP does error checking but simply discards erroneous packets. Error recovery is not attempted.
Fields1.Sequence Number, 2. AcK number, 3. Data offset, 4. Reserved, 5. Control bit, 6. Window, 7. Urgent Pointer 8. Options, 9. Padding, 10. Check Sum, 11. Source port, 12. Destination port1.Length, 2. Source port, 3. Destination port, 4. Check Sum
AcknowledgementAcknowledgement segmentsNo Acknowledgment
HandshakeSYN, SYN-ACK, ACKNo handshake (connectionless protocol)

Source: http://www.diffen.com/difference/TCP_vs_UDP