Osi model

What is the OSI model?

7 layers each describe a specific networking component

  • layer 7 - Application - HTTP/FTP/gRPC
  • layer 6 - Presentation - Encoding and Serialization
  • Layer 5 - Session - Connection Estabilishment, TLS
  • Layer 4 - Transport - UDP/TCP
  • Layer 3 - Network- IP
  • Layer 2 - Datalink- Frames, Mac Address Ethernet
  • Layer 1 - Physical - Electical Signal, Fiber or radio waves

An Example (Sender)

  • layer 7 - Application
    • Post request with JSON data to HTTPS server
  • layer 6 - Presentation
    • Serialize JSON to flat byte strings
  • Layer 5 - Session
    • Request to establish TCP connection/TLS
  • Layer 4 - Transport [Segment]
    • Sends SYN request target port 443
  • Layer 3 - Network [Packet]
    • SYN is placed an IP packets and adds the source/dest IPs
  • Layer 2 - Datalink [Frame]
    • Each packet goes into a single frame and adds the source/dest MAC addressses
  • Layer 1 - Physical
    • Each frame becomes string of buts which concerted into either a radio signal, electric signal or light

An Example(Receiver):

  • layer 7 - Application
    • Application understands the JSON POST
  • layer 6 - Presentation
    • Deserialize flat byte string back to JSON for the app to consume
  • Layer 5 - Session
    • The connection sessino is established or identified
    • We only arrive at this layer when necessary (three way handshake is done)
  • Layer 4 - Transport
    • The IP packets from layer 3 are assembled into TCP segments
    • Deals with congestion control/flow control/retransmission in case of TCP
    • If Segment is SYN we dont need to go further into more layers as we are still processing the connection request
  • Layer 3 - Network
    • the frames from layer 2 are assembled into IP packet
  • Layer 2 - Datalink
    • the bits from layer 1 is assembled into frames
  • Layer 1 - Physical
    • Signal converted to digital bite

Middle layers:

  • Switch can peak to [DataLink, Physical] (Layer 2 device)
  • Router can peak to [Network, DataLink, Physical] (Layer 3 device)
  • Proxy/Firewall needs to look at IP and Port [Transport, Network, DataLink, Physical] (Layer 4)
  • Load Balancer/CDN needs to looks at application logic (hence layer 1)

Trivia: - TCP/IP model deals with Layer 5-6-7 as just one layer, application