> For the complete documentation index, see [llms.txt](https://amartyushov.gitbook.io/tech/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://amartyushov.gitbook.io/tech/os-components/network/osi-model.md).

# OSI model

Mnemonics to remember layer names from top to bottom:

{% hint style="info" %}
All people seem to need data processing
{% endhint %}

## `7` Application

network related APIs which can be used e.g. by email apps. These are not applications themselves, this is only OS API to work with network.

## `6` Presentation

Data convertion: encryption, decryption, compression.

## `5` Session

Initiate sessions, accept incoming sessions, opens and closes existing sessions.

This is the layer responsible for opening and closing communication between the two devices. The time between when the communication is opened and closed is known as the session. The session layer ensures that the session stays open long enough to transfer all the data being exchanged, and then promptly closes the session in order to avoid wasting resources. The session layer also synchronizes data transfer with checkpoints.

`netstat -a` shows all sessions

## `4` Transport

<mark style="background-color:red;">**Segmentation**</mark>: transport protocol breaks up the data into chunks: **datagrams/segments with sequence number** ( wrapped in IP packets, later wrapped in frames) send to receiver, and it will **reassemble** the data back from packets (plus check correctness, FCS)

## `3` Network

IP (Internet Protocol) (logical address)

decimal notation: 192.168.4.132

8 bit each octet \[0..255], 2^8 - 1 = 255

<figure><img src="https://415484505-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LxtoAXZwwOc4XGto8vb%2Fuploads%2FhOKccWYpsfc0GVONACjm%2FScreenshot%202023-09-25%20at%2009.44.32.png?alt=media&amp;token=f31a3798-7244-46aa-8993-9bdbca021648" alt=""><figcaption></figcaption></figure>

When the frame is passed from one router to another, particular router strips off the frame to understand where to send the data based on IP address, then it wraps the packet to new frame and send further. The new frame type will be the appropriate for whatever technology is used for further router connection (cable, DSL).

## `2` Data link

Any device which deals with MAC (physical address) address is part of this Layer 2 (NIC, switch).

* NIC (Network Interface card, сетевая карта):
  * creates and sends frames&#x20;
    * frame (PDU) - encapsulated data for transmission
      * FCS - Frame check sequence (4 bytes). It uses CRC - cyclic redundancy check.

<figure><img src="https://415484505-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LxtoAXZwwOc4XGto8vb%2Fuploads%2FJsg58dqYE8CpgZOrqf9n%2FScreenshot%202023-09-25%20at%2009.01.45.png?alt=media&amp;token=1399ed02-96fa-42d7-9ed0-60eea060cf94" alt=""><figcaption></figcaption></figure>

* NIC has two aspects:
  * LLC (Logical link control) - talks to OS using drivers
  * MAC (Media access control) - creates and addresses frames

## `1` Physical

* cables, hubs

<mark style="color:green;">Unit of data specified by protocol at each level - protocol data unit (PDU). E.g. frame is a PDU for layer 2.</mark>
