Appearance
TCP IP Model Overview
Video: What is TCP/IP?
TCP/IP Model Overview
Network communication involves multiple layers of protocols working together to transmit data between systems. The TCP/IP model is the practical framework used in real-world networking, especially the internet. It has four layers, each responsible for specific aspects of network communication.
These models are designed around separation of concerns. Each layer is responsible for providing specific functionality on top of a lower layer and keeping it as generic and extensible as possible.
Layer 1: Network Access Layer
The Network Access layer handles the physical transmission of data over network media. This layer converts digital bytes to electrical, optical, or radio signals depending on the network medium. This is the lowest layer and its job is to enable the transmission of information from one device to another on the same local networkDevices are said to be on the same local network if they are connected to each other via wires or the same router/switch.
Responsibilities:
- Converting digital data to physical signals
- Defining how devices are physically connected
- Managing signal transmission and timing
Technologies:
- Ethernet (wired connections)
- Wi-Fi (wireless connections)
- Fiber optic, coaxial, and twisted pair cables
Layer 2: Internet Layer
The network layer has already enabled that two devices on the same local network can talk to each other. But what if we can give different devices on different networks globally unique addresses that can be used to send data to them?
The Internet layer handles routing and logical addressing across networks. It is responsible for identifying the network to which data needs to be sent and the specific device on that network using IP addresses. This layer sits on top of the network access layer and is responsible for connecting devices on different networks.
Responsibilities:
- Assigning logical addresses (IP addresses)
- Forwarding packets between networks
- Determining optimal paths for data packets
- Fragmenting large packets when necessary
Key Protocol:
- Internet Protocol (IP) - provides the addressing and routing functionality
Layer 3: Transport Layer
Great progress has been made. We can now send data from one device to another even if they are not on the same local network. But how do we ensure that the data reaches the correct process on the destination device?
The Transport layer provides end-to-end communication between applications. It ensures that data reaches the correct application on the destination device by using port numbers.
Now that the internet layer ensures that any data can be sent from one device to another even if they are not physically connected to the same network, the transport layer adds the functionality for programs running on the devices to communicate with each other.
Responsibilities:
- Ensuring data reaches the correct application
- Detecting and retransmitting lost data
- Managing data flow to prevent receiver overload
- Establishing and maintaining connections
Key Protocols:
- Transmission Control Protocol (TCP) - reliable, ordered delivery
- User Datagram Protocol (UDP) - fast, connectionless delivery
Layer 4: Application Layer
The Application layer provides network services to user applications. It defines how applications communicate with each other over the network.
Responsibilities:
- Providing services directly to applications
- Defining application-specific protocols
- Discovering available network services
- Enabling resource sharing
Key Protocols:
- Hypertext Transfer Protocol (HTTP/HTTPS) - web browsing
- Domain Name System (DNS) - name resolution
- File Transfer Protocol (FTP) - file transfer
- Simple Mail Transfer Protocol (SMTP) - email
These are protocols that are used by different systems to communicate with each other. For example, HTTP is used by web browsers to request and display web pages, and SMTP is used by email clients to send and receive emails.
When designing programs that require inter process communication, you have the choice to either use an existing protocol or, more usually, create your own. For example, if you are writing a program to broadcast messages to all connected clients, you could implement your own UDP sender and receiver to send and receive messages.
A lot of real world low latency programming requires you to create your own protocols.
How the Layers Work
How do these layers work?
Let's say you're authoring a protocol for the network access layer. You may be tempted to write a functino that looks a little something like this:
cpp
void sendData(int src_address, int dst_address, const void* data, size_t length) {
// Convert data to physical signal
// Send data over network
// Wait for acknowledgement
// If acknowledgement is not received, resend data
}But other devices on different networks need to see the function arguments as well so as to be able to send data to the correct device. So you can't just send the data as is. The solution is to encapsulate the data in a header that contains the function arguments.
The first few bytes can contain the src, dst addresses, and any other information required by your protocol. And then the rest of the data can follow.
Data encapsulation
As each layer uses the one below it, they each adds their own header to the data from the layer above. This process is called encapsulation.
Encapsulation Process
Let's say you are using HTTP to send a request to a server.
cpp
Application Data # Your GET/POST request
↓
[Application Header] + Application Data # Added by HTTP
↓
[Transport Header] + [Application Header] + Application Data # Added by TCP
↓
[Internet Header] + [Transport Header] + [Application Header] + Application Data # Added by IP
↓
[Network Access Header] + [Internet Header] + [Transport Header] + [Application Header] + Application Data + [Network Access Trailer] # Added by Ethernet
↓
Physical transmission as bitsThe data travels through the network in the following way:
- The network access layer first sends your packet to the appropriate router on your local network.
- The router then reads the IP header to identify the network to which the data needs to be sent.
- Once it reaches the destination network, the router reads the IP header to identify the device to which the data needs to be sent.
- The router then sends the packet to the destination device.
- The destination device reads the IP header to identify the protocol to which the data needs to be sent.
- The destination device then reads the transport header to identify the port to which the data needs to be sent.
- The destination device then reads the application header to identify the application to which the data needs to be sent.
- The destination device then sends the data to the application.
Performance Optimization
Understanding the layers helps optimize network performance:
- Application layer: Use efficient protocols and data formats
- Transport layer: Choose appropriate protocols (TCP vs UDP)
- Internet layer: Optimize routing and packet sizes
- Network Access layer: Use appropriate frame sizes and media
Understanding the TCP/IP model provides a foundation for comprehending network protocols, troubleshooting network issues, and designing efficient network applications. This model serves as a reference framework for understanding how different network components interact and how data flows through networks.
Questions
Q: How many layers does the TCP/IP model have?
The TCP/IP model has 4 layers: Network Access, Internet, Transport, and Application. This is simpler than the OSI model and represents the practical implementation used in real-world networking.
Q: Which layer of the TCP/IP model is responsible for routing packets between networks?
The Internet layer (Layer 2) is responsible for routing packets between networks. It handles logical addressing, routing, and forwarding of data packets across different networks using IP addresses.
Q: What is the main purpose of the Transport layer in the TCP/IP model?
The Transport layer provides end-to-end communication between applications. It ensures data reaches the correct application using port numbers and handles reliability through protocols like TCP and UDP.
Q: Which protocol operates at the Internet layer of the TCP/IP model?
IP (Internet Protocol) operates at the Internet layer. It's responsible for logical addressing and routing packets across networks using IP addresses.
Q: What is encapsulation in the context of the TCP/IP model?
Encapsulation is the process of adding headers to data as it moves down the layers. Each layer adds its own header to the data from the layer above it.
Q: Which layer handles the physical transmission of bits over the network medium?
The Network Access layer handles the physical transmission of bits over the network medium, including electrical signals, optical signals, or radio waves.
Q: What is the primary function of the Application layer?
The Application layer provides network services to user applications. It defines how applications communicate with each other over the network using protocols like HTTP, DNS, and FTP.
Q: Which TCP/IP layer combines the functions of the OSI Physical and Data Link layers?
The Network Access layer combines the functions of the OSI Physical and Data Link layers. It handles both physical transmission and data link functionality like frame creation and error detection.