1. The OSI 7-Layer Architecture
Understanding the 7 Layers of the OSI Model
The Open Systems Interconnection (OSI) model is a conceptual framework that standardizes the functions of a telecommunication or computing system into seven distinct layers. By breaking down network communication, we can isolate issues and define protocols for each stage of the data transit.
The layers are categorized as follows: Physical (Layer 1), Data Link (Layer 2), Network (Layer 3), Transport (Layer 4), Session (Layer 5), Presentation (Layer 6), and Application (Layer 7). Each layer communicates only with its corresponding layer on another device, passing data down the stack on the sender's side and up on the receiver's side.
# Using tcpdump to inspect physical/data link layer frame activity tcpdump -i eth0 -nn -c 5
Encapsulation and Decapsulation Process
Encapsulation is the process of wrapping data with protocol information at each layer of the OSI model. As data moves down the stack, each layer adds a header (and sometimes a trailer) containing control information. The unit of data changes names: Data (Apps) -> Segment (Transport) -> Packet (Network) -> Frame (Data Link) -> Bits (Physical).
Decapsulation is the reverse process: as the data travels up the receiver's stack, each layer strips away its corresponding header and processes the payload until the raw data is restored to the application.
import struct def encapsulate_mock_packet(payload): # Simulate a 16-byte header prepended to data header = struct.pack('!I', len(payload)) packet = header + payload.encode() return packet print(f'Encapsulated Data: {encapsulate_mock_packet("HelloVoidX").hex()}')
Comparing the OSI Model vs the TCP/IP 4-Layer Stack
While the OSI model is a theoretical reference, the TCP/IP stack is the practical implementation used in modern networking. The TCP/IP model collapses the OSI's top three layers (Session, Presentation, Application) into one Application layer and combines Physical and Data Link into a 'Network Access' layer.
| OSI Layer | TCP/IP Layer |
|---|---|
| Application/Presentation/Session | Application |
| Transport | Transport |
| Network | Internet |
| Data Link/Physical | Network Access |
# Querying DNS (Application Layer) via terminal dig google.com +short
Inspecting Protocol Headers
Analyzing protocol headers is vital for forensic analysis and identifying network anomalies. Using tools like Scapy in Python, we can craft or dissect raw packets to verify header fields like TTL (Time to Live) or sequence numbers.
Below is a demonstration of how to interpret raw byte streams from a TCP header capture.
import struct # Mock TCP header: 20 bytes raw_header = b'\x00\x50\x1f\x90\x00\x00\x00\x01\x00\x00\x00\x00\x50\x02\x72\x10\x00\x00\x00\x00' header = struct.unpack('!HHIIBBHHH', raw_header) print(f'Source Port: {header[0]}') print(f'Dest Port: {header[1]}')
Knowledge Check
Ready to test your understanding of 1. The OSI 7-Layer Architecture?