The layer models

Each layer does one job and trusts the one below

OSI modelTCP/IP modelexamplesunit7ApplicationHTTP, DNS, SMTPdata6PresentationTLS, JPEG, UTF-8data5SessionRPC, NetBIOSdata4TransportTCP, UDPsegment3NetworkIPv4, IPv6, ICMPpacket2Data linkEthernet, Wi-Fi, ARPframe1Physicalcopper, fibre, radiobitsApplicationTransportInternetLinkEach layer does one job and trusts the layer below to do the rest.OSI names seven layers and is the vocabulary of the exams and of every engineer (“a layer 2 problem”). The internetactually runs the four-layer TCP/IP model, which folds OSI’s top three into one and its bottom two into one.Transport and network, in purple, line up exactly in both, and that is where most of this course lives.

The OSI model names seven layers; the TCP/IP model the internet runs on names four.

Encapsulation

Each layer wraps the data in its own header

Application: the requestHTTP request420 bytesTransport adds ports and sequence numbersTCPHTTP request+ 20Network adds the source and destination IPTCPIPHTTP request+ 20Data link adds MACs and a checkTCPIPEthHTTP requestFCS+ 14 + 4Widths drawn to scale, 1 pixel per byte. Each header goes in front of what it was given.478 bytes on the wireEvery layer wraps what it was given in its own header. The receiver unwraps in reverse.This is encapsulation. A 420-byte request leaves as a 478-byte frame: TCP adds 20 bytes, IPv4 20, Ethernet 14 in front and a4-byte check sequence behind. No layer reads another layer’s header. That separation is why Wi-Fi can replace Ethernet,or IPv6 replace IPv4, without the web browser noticing.

Encapsulation: TCP, IP and Ethernet each add a header, so a 420-byte request leaves as a 478-byte frame.

Encapsulation · Going deeper · 1 of 3

The Ethernet frame, field by field

An Ethernet II frame, byte by byte (not to scale)Preamble + SFD8 bytessync, not part of the frameDestination MAC6 byteswho on this linkSource MAC6 byteswho sent itType2 bytes0x0800 IPv4, 0x86DD IPv6Payload46 to 1500 bytesFCS4 bytesCRC-32 checkSmallest frame: 64 bytes (shorter payloads are padded to 46). Largest: 1518 bytes, or 1522 with a VLAN tag.Per full frame the line also carries the preamble and a 12-byte gap: 1538 bytes of line time for 1460 bytes of TCP payload, 94.9% useful.A MAC address is 48 bits, written 00:1A:2B:3C:4D:5E. The first 24 bits name the maker (the OUI).The destination MAC comes first, so a switch can start forwarding before the frame has finished arriving.The 1500-byte payload limit is the MTU, the largest packet the link carries. Take away the IP and TCP headers and1460 bytes are left for data: the maximum segment size (MSS). Jumbo frames raise the MTU to about 9000 bytes insidedata centres. A frame whose FCS does not match is dropped and counted as a CRC error on the interface.

A frame carries 46 to 1500 bytes of payload. The MTU is 1500, which leaves an MSS of 1460 bytes for TCP data.

Encapsulation · Going deeper · 2 of 3

The IPv4 header, field by field

IPv4 header: 20 bytes, five rows of 32 bits08162431VersionIHLDSCPECNTotal lengthIdentificationFlagsFragment offsetTime to liveProtocolHeader checksumSource addressDestination addressTime to liveeach router subtracts 1 and drops the packet at 0,so a loop cannot run forever; starts at 64 or 128Protocolwhat is inside: 1 ICMP, 6 TCP, 17 UDP,47 GRE, 50 ESPDSCPpriority marking for quality of service;46 (Expedited Forwarding) marks voiceFlags, offsetlet a router split a packet too big for thenext link, unless Don’t Fragment is setRouters read the destination and decrement the time to live. They leave the rest of the packet alone.The IPv4 header is 20 bytes without options. IPv6 uses a simpler fixed 40-byte header with hop limit in place of timeto live, no checksum and no fragmenting by routers. Traceroute works by sending packets with a time to live of 1, 2, 3and collecting the “time exceeded” message each router sends back when it drops one.

A router reads the destination address and lowers the time to live by one. The protocol field says what is inside: 6 for TCP, 17 for UDP.

Encapsulation · Going deeper · 3 of 3

The TCP and UDP headers

TCP header: 20 bytes. UDP’s is 8: ports, length and checksum only.08162431Source portDestination portSequence numberAcknowledgement numberOffsetRsvdFlagsWindowChecksumUrgent pointerUDPSource portDestination portLengthChecksumPortswhich program: 443 is HTTPS, 53 is DNS.Sequence, acknumber every byte so loss and order are fixed.FlagsSYN, ACK, FIN, RST, PSH, URG, ECE, CWR.Windowhow many bytes the receiver can take now.The transport header carries the ports that pick a program, and TCP adds the numbers that make it reliable.Lesson 9 takes TCP apart: the handshake, sequence numbers, windows and retransmission. For now: the header is wherereliability lives, and UDP leaves it out on purpose, for speed.

TCP’s 20-byte header carries ports, sequence numbers, flags and a window. UDP’s 8 bytes carry only ports, length and a checksum.

Lesson complete

You finished “The layer model”

Nicely done.

Open in a new tab