ISO/OSI Reference Model
The ISO/OSI reference model is the network architecture standard defined by the International Organization for Standardization. It divides network communication into seven layers. This page covers the structure of the OSI model, the function of each layer, and the mechanisms that bind the layers together.
1. Background
The OSI (Open Systems Interconnection) reference model was drawn up by ISO in 1984 with the aim of giving network equipment from different vendors a common communication standard.
2. Characteristics
- Strong theoretical grounding: provides a complete theoretical framework for networking
- Fine-grained layering: divides network functions into seven layers
- Standardisation: supplies a standard for protocol design
- Generality: applies to any network technology
3. The Seven Layers
1. Physical Layer
Description
The physical layer transmits raw bit streams over a physical medium and offers the data link layer a transparent bit transfer service.
Main Functions
- Bit transmission: carries bit streams over the transmission medium
- Physical connection: establishes, maintains, and releases physical connections
- Signal encoding: turns digital signals into physical signals suited to transmission
- Transmission rate: determines the rate at which data is transferred
- Transmission direction: determines the direction of data transfer (simplex, half duplex, full duplex)
Protocol Example
// Physical layer protocol structure
typedef struct {
uint8_t signal_type; // Signal type (digital/analog)
uint32_t bit_rate; // Bit rate
uint8_t encoding_scheme; // Encoding scheme
uint8_t transmission_mode; // Transmission mode
} PhysicalLayerProtocol;
// Physical layer interface
typedef struct {
int (*transmit_bit)(uint8_t bit);
int (*receive_bit)(uint8_t* bit);
int (*set_bit_rate)(uint32_t rate);
int (*get_signal_quality)(void);
} PhysicalLayerInterface;
// Physical layer implementation example
typedef struct {
PhysicalLayerProtocol protocol;
PhysicalLayerInterface interface;
uint32_t current_bit_rate;
uint8_t signal_quality;
} PhysicalLayer;
Typical Devices
- Repeater: amplifies and regenerates signals
- Hub: a multi-port repeater
- Modem: converts between digital and analog signals
2. Data Link Layer
Description
The data link layer transfers frames reliably between adjacent nodes and provides error detection and flow control.
Main Functions
- Framing: organises the bit stream into frames
- Error detection: detects errors introduced during transmission
- Flow control: controls the sending rate of the sender
- Media access control: controls access to a shared medium
- Link management: establishes, maintains, and releases data links
Protocol Example
// Data link layer frame structure
typedef struct {
uint8_t preamble[8]; // Preamble
uint8_t dest_mac[6]; // Destination MAC address
uint8_t src_mac[6]; // Source MAC address
uint16_t ethertype; // Ethernet type
uint8_t data[1500]; // Data part
uint32_t fcs; // Frame check sequence
} EthernetFrame;
// Data link layer protocol
typedef struct {
uint8_t frame_type; // Frame type
uint16_t max_frame_size; // Maximum frame size
uint8_t error_detection; // Error detection method
uint8_t flow_control; // Flow control method
} DataLinkProtocol;
// Data link layer interface
typedef struct {
int (*send_frame)(const EthernetFrame* frame);
int (*receive_frame)(EthernetFrame* frame);
int (*get_mac_address)(uint8_t* mac_addr);
int (*set_mac_address)(const uint8_t* mac_addr);
} DataLinkInterface;
Typical Devices
- Bridge: connects different network segments
- Switch: a multi-port bridge
- NIC: network interface card
3. Network Layer
Description
The network layer transfers packets between different networks and provides route selection and packet forwarding.
Main Functions
- Routing: selects the best path for a packet
- Packet forwarding: forwards packets from the source towards the destination
- Address management: manages network addresses
- Congestion control: keeps the network from becoming congested
- Quality of service: offers different levels of service
Protocol Example
// IP packet structure
typedef struct {
uint8_t version; // Version number
uint8_t header_length; // Header length
uint8_t tos; // Type of service
uint16_t total_length; // Total length
uint16_t identification; // Identification
uint16_t flags_offset; // Flags and fragment offset
uint8_t ttl; // Time to live
uint8_t protocol; // Protocol
uint16_t checksum; // Checksum
uint32_t src_ip; // Source IP address
uint32_t dest_ip; // Destination IP address
uint8_t options[40]; // Options
uint8_t data[65535]; // Data part
} IPPacket;
// Network layer protocol
typedef struct {
uint8_t protocol_type; // Protocol type
uint32_t routing_table[256]; // Routing table
uint8_t congestion_control; // Congestion control
uint8_t qos_support; // QoS support
} NetworkProtocol;
// Network layer interface
typedef struct {
int (*route_packet)(const IPPacket* packet);
int (*forward_packet)(const IPPacket* packet, int interface);
int (*add_route)(uint32_t network, uint32_t mask, uint32_t next_hop);
int (*remove_route)(uint32_t network, uint32_t mask);
} NetworkInterface;
Typical Devices
- Router: connects different networks
- Layer 3 Switch: a switch with routing capability
4. Transport Layer
Description
The transport layer provides reliable data transfer between end systems and guarantees the integrity and the order of the data.
Main Functions
- End-to-end transfer: moves data between the source and the destination
- Reliable transfer: ensures data is neither lost, duplicated, nor reordered
- Flow control: controls the sending rate of the sender
- Congestion control: keeps the network from becoming congested
- Multiplexing: lets several applications use the network at the same time
Protocol Example
// TCP segment structure
typedef struct {
uint16_t src_port; // Source port
uint16_t dest_port; // Destination port
uint32_t sequence_num; // Sequence number
uint32_t ack_num; // Acknowledgement number
uint8_t header_length; // Header length
uint8_t flags; // Flags
uint16_t window_size; // Window size
uint16_t checksum; // Checksum
uint16_t urgent_ptr; // Urgent pointer
uint8_t options[40]; // Options
uint8_t data[65535]; // Data part
} TCPSegment;
// Transport layer protocol
typedef struct {
uint8_t protocol_type; // Protocol type (TCP/UDP)
uint32_t max_segment_size; // Maximum segment size
uint8_t flow_control; // Flow control
uint8_t congestion_control; // Congestion control
} TransportProtocol;
// Transport layer interface
typedef struct {
int (*send_segment)(const TCPSegment* segment);
int (*receive_segment)(TCPSegment* segment);
int (*open_connection)(uint32_t dest_ip, uint16_t dest_port);
int (*close_connection)(int connection_id);
} TransportInterface;
Typical Protocols
- TCP (Transmission Control Protocol): connection-oriented reliable transport protocol
- UDP (User Datagram Protocol): connectionless unreliable transport protocol
5. Session Layer
Description
The session layer establishes, manages, and terminates sessions, and provides session services to the presentation layer.
Main Functions
- Session establishment: opens a session connection
- Session management: manages the state of the session
- Session synchronisation: synchronises session data
- Session recovery: restores a session after a failure
- Session termination: closes the session in an orderly way
Protocol Example
// Session layer protocol structure
typedef struct {
uint32_t session_id; // Session identifier
uint8_t session_state; // Session state
uint32_t timeout; // Timeout
uint8_t sync_points; // Synchronisation points
uint8_t recovery_mode; // Recovery mode
} SessionProtocol;
// Session layer interface
typedef struct {
int (*create_session)(uint32_t* session_id);
int (*join_session)(uint32_t session_id);
int (*leave_session)(uint32_t session_id);
int (*sync_session)(uint32_t session_id);
int (*recover_session)(uint32_t session_id);
} SessionInterface;
Typical Applications
- RPC (Remote Procedure Call): remote procedure calls
- SQL: database session management
6. Presentation Layer
Description
The presentation layer converts data formats, encrypts and decrypts data, and compresses and decompresses it, providing data representation services to the application layer.
Main Functions
- Data format conversion: converts between different data formats
- Data encryption: encrypts data
- Data compression: compresses data
- Character encoding: handles different character encodings
- Data conversion: handles different data types
Protocol Example
// Presentation layer protocol structure
typedef struct {
uint8_t encoding_type; // Encoding type
uint8_t encryption_type; // Encryption type
uint8_t compression_type; // Compression type
uint8_t charset; // Character set
} PresentationProtocol;
// Presentation layer interface
typedef struct {
int (*encode_data)(const void* data, size_t length, void* encoded_data);
int (*decode_data)(const void* encoded_data, size_t length, void* data);
int (*encrypt_data)(const void* data, size_t length, void* encrypted_data);
int (*decrypt_data)(const void* encrypted_data, size_t length, void* data);
int (*compress_data)(const void* data, size_t length, void* compressed_data);
int (*decompress_data)(const void* compressed_data, size_t length, void* data);
} PresentationInterface;
Typical Standards
- ASCII/Unicode: character encoding standards
- JPEG/PNG: image formats
- MPEG: video format
- SSL/TLS: secure transport protocol
7. Application Layer
Description
The application layer provides network application services to users. It is the interface through which users interact with the network.
Main Functions
- File transfer: provides a file transfer service
- Electronic mail: provides an electronic mail service
- Remote login: provides a remote login service
- Network management: provides network management functions
- Name resolution: provides a domain name resolution service
Protocol Example
// Application layer protocol structure
typedef struct {
uint8_t protocol_type; // Protocol type
uint16_t port_number; // Port number
uint8_t data_format; // Data format
uint8_t security_level; // Security level
} ApplicationProtocol;
// Application layer interface
typedef struct {
int (*send_request)(const void* request, size_t length);
int (*receive_response)(void* response, size_t max_length);
int (*establish_connection)(const char* server, int port);
int (*close_connection)(void);
} ApplicationInterface;
Typical Protocols
- HTTP (Hypertext Transfer Protocol): hypertext transfer protocol
- FTP (File Transfer Protocol): file transfer protocol
- SMTP (Simple Mail Transfer Protocol): simple mail transfer protocol
- DNS (Domain Name System): domain name system
- SNMP (Simple Network Management Protocol): simple network management protocol
1. Encapsulation
// Data encapsulation
typedef struct {
void* application_data;
void* presentation_header;
void* session_header;
void* transport_header;
void* network_header;
void* datalink_header;
void* physical_header;
} EncapsulatedData;
// Encapsulation function
EncapsulatedData* encapsulate_data(const void* app_data, size_t length) {
EncapsulatedData* data = malloc(sizeof(EncapsulatedData));
if (!data) return NULL;
// Application layer data
data->application_data = malloc(length);
memcpy(data->application_data, app_data, length);
// Add the header of each layer
data->presentation_header = add_presentation_header(data->application_data);
data->session_header = add_session_header(data->presentation_header);
data->transport_header = add_transport_header(data->session_header);
data->network_header = add_network_header(data->transport_header);
data->datalink_header = add_datalink_header(data->network_header);
data->physical_header = add_physical_header(data->datalink_header);
return data;
}
2. Decapsulation
// Data decapsulation
void* decapsulate_data(const EncapsulatedData* data) {
void* result = data->application_data;
// Remove the header of each layer
remove_physical_header(data->physical_header);
remove_datalink_header(data->datalink_header);
remove_network_header(data->network_header);
remove_transport_header(data->transport_header);
remove_session_header(data->session_header);
remove_presentation_header(data->presentation_header);
return result;
}
1. Theoretical Completeness
- Provides a complete theoretical framework for networking
- Covers every aspect of network communication
- Gives network design a standard to follow
2. Clear Layering
- Every layer has a well-defined function
- The interfaces between layers are clear
- Easy to understand and to implement
3. Standardisation
- Gives network protocols a standard to follow
- Lets equipment from different vendors interoperate
- Makes the network easier to extend
1. Complexity
- Seven layers are more complex than needed
- Hard to implement in practice
- Carries a larger overhead
2. Practicality
- Strong on theory, weak on practice
- Few real networks follow the OSI model exactly
- It was superseded by the TCP/IP model
| Term | Abbreviation | Explanation |
|---|---|---|
| Open Systems Interconnection | OSI | Network reference model defined by ISO |
| Physical Layer | - | First layer of OSI |
| Data Link Layer | - | Second layer of OSI |
| Network Layer | - | Third layer of OSI |
| Transport Layer | - | Fourth layer of OSI |
| Session Layer | - | Fifth layer of OSI |
| Presentation Layer | - | Sixth layer of OSI |
| Application Layer | - | Seventh layer of OSI |
| International Organization for Standardization | ISO | Organisation that defined OSI |
| Institute of Electrical and Electronics Engineers | IEEE | Organisation that defines network standards |
| Connection-oriented | - | A connection is established before communication |
| Connectionless | - | Data is sent directly, with no connection |
| Acknowledgment | ACK | Acknowledgement received from the peer |
| Flow Control | - | Controls the sending rate |
| Error Control | - | Detects and corrects errors |
| Routing | - | Selects the transmission path |
| Congestion Control | - | Prevents the network from overloading |
