OSI and TCP/IP Models
Layered architecture, encapsulation.
OSI Reference Model Layers
The OSI (Open Systems Interconnection) model has 7 layers (bottom-to-top): Physical, Data Link, Network, Transport, Session, Presentation, Application. Mnemonic (bottom-up): 'Please Do Not Throw Sausage Pizza Away'. Top-down: 'All People Seem To Need Data Processing'. Layers 1-3 are network/media layers (hardware-oriented); Layers 5-7 are host/application layers (software-oriented); Transport (4) is the bridge. Each layer serves the layer above and is served by the layer below. Communication uses Protocol Data Units (PDUs): bits (Physical), frames (Data Link), packets/datagrams (Network), segments (Transport), and data (upper layers). Remember the PDU sequence as you climb up: Bits-Frames-Packets-Segments-Data.
Physical: transmission of raw bits, encoding, signaling, bit-rate, topology, mechanical/electrical specs. Data Link: framing, MAC addressing, error detection (CRC), flow control, access control; sublayers LLC and MAC. Network: logical (IP) addressing, routing, path determination, fragmentation, congestion control. Transport: end-to-end delivery, segmentation, port addressing, reliability, flow/error control (TCP/UDP). Session: dialog control, synchronization, checkpointing, session establishment/teardown. Presentation: translation, encryption/decryption, compression, syntax (data format). Application: user interface to network services (HTTP, FTP, SMTP, DNS). Shortcut: Routing=Network, Framing=Data Link, Port=Transport, Encryption/Compression=Presentation, Dialog/Sync=Session.
Knowing which device operates at which layer is a frequent GATE question. Hub and Repeater operate at the Physical layer (Layer 1) - they regenerate/broadcast signals with no intelligence. Bridge and Switch operate at the Data Link layer (Layer 2) - they use MAC addresses and maintain forwarding tables. Router operates at the Network layer (Layer 3) - uses IP addresses for routing between networks. Gateway typically operates up to the Application layer (Layer 7), translating between different protocol stacks. A Layer-3 switch combines switching with routing. Memory aid: Hub=1, Switch/Bridge=2, Router=3, Gateway=all-the-way-up.
TCP/IP Protocol Suite
The TCP/IP model (Internet model) is the practical foundation of the Internet. The original RFC model has 4 layers: Application, Transport, Internet, Network Access (Link). Many textbooks (Forouzan) use a 5-layer version: Application, Transport, Network (Internet), Data Link, Physical. The TCP/IP Application layer combines OSI's Application + Presentation + Session. The TCP/IP Network Access layer combines OSI's Data Link + Physical (in the 4-layer view). Key protocols by layer: Application = HTTP, FTP, SMTP, DNS, SNMP, TELNET; Transport = TCP, UDP; Internet = IP, ICMP, IGMP, ARP (debated placement); Link = Ethernet, Wi-Fi. Remember: TCP/IP has fewer layers and was built before its model was formally defined.
OSI has 7 layers; TCP/IP has 4 (or 5). OSI is a reference/theoretical model (protocols defined after the model); TCP/IP is protocol-driven (model defined after protocols). OSI strictly separates services, interfaces, and protocols; TCP/IP does not. OSI's Network layer supports both connectionless and connection-oriented service; OSI Transport is only connection-oriented. TCP/IP's Internet (Network) layer is connectionless only; its Transport layer supports both (TCP=connection-oriented, UDP=connectionless). OSI was a documentation model that largely failed commercially; TCP/IP succeeded as the Internet standard. Mapping: OSI top 3 (App+Pres+Session) = TCP/IP Application; OSI bottom 2 = TCP/IP Network Access.
GATE frequently tests which protocol sits at which TCP/IP layer. Application layer: HTTP(80), HTTPS(443), FTP(20/21), SMTP(25), DNS(53), TELNET(23), DHCP, SNMP(161), POP3(110), IMAP(143). Transport layer: TCP (reliable, connection-oriented), UDP (unreliable, connectionless). Internet/Network layer: IP, ICMP (ping/error reporting), IGMP (multicast), ARP/RARP (often shown at the boundary of Link and Network). Link layer: Ethernet, PPP, Wi-Fi (802.11), Token Ring. Tip: DNS and DHCP use UDP primarily; HTTP/FTP/SMTP use TCP. ICMP and IGMP are encapsulated within IP datagrams but are considered Network-layer companions to IP.
Encapsulation and Data Flow
As data travels down the sending host's protocol stack, each layer adds its own header (and the Data Link layer adds a trailer too) - this is encapsulation. The unit grows: Data -> Segment (TCP header) -> Packet (IP header) -> Frame (Frame header + trailer) -> Bits. At the receiver, each layer removes (decapsulates) its corresponding header/trailer as data moves up. Key insight: a layer's header is read only by the peer layer on the other host (peer-to-peer communication / horizontal logical communication), while physical transfer is vertical. The Data Link layer is unique in adding BOTH a header and a trailer (the trailer holds the CRC/FCS for error detection).
Memorize these for numericals: TCP header = 20 bytes minimum, 60 bytes maximum (with options). UDP header = 8 bytes (fixed). IPv4 header = 20 bytes minimum, 60 bytes maximum. IPv6 header = 40 bytes (fixed, no options in base header). Ethernet frame: header 14 bytes (6 dest MAC + 6 src MAC + 2 type) + 4 bytes CRC trailer = 18 bytes overhead; payload 46-1500 bytes (MTU). Total overhead for TCP/IP/Ethernet (minimum) = 20 + 20 + 18 = 58 bytes. Efficiency = payload / (payload + headers). These figures appear constantly in throughput and overhead numericals.
Q: An application sends 1000 bytes using TCP over IPv4 over Ethernet (minimum headers). What is the transmission efficiency at the Data Link layer (ignoring preamble)? Solution: Total bytes on wire = data + TCP header + IP header + Ethernet overhead = 1000 + 20 + 20 + 18 = 1058 bytes. Efficiency = useful data / total = 1000 / 1058 = 0.9452 = 94.52%. If using UDP instead of TCP: 1000 + 8 + 20 + 18 = 1046, efficiency = 1000/1046 = 95.6%. Note the Ethernet overhead of 18 bytes = 14-byte header + 4-byte FCS trailer. Always include the trailer for Data Link layer.
Addressing Across Layers
TCP/IP uses four distinct address types, one per relevant layer: (1) Physical/MAC address - 48-bit (6-byte), at the Data Link layer, e.g., 00:1A:2B:3C:4D:5E, used for node-to-node delivery on a LAN. (2) Logical/IP address - 32-bit (IPv4) or 128-bit (IPv6), at the Network layer, for host-to-host delivery across networks. (3) Port address - 16-bit (0-65535), at the Transport layer, identifies the specific process/application. (4) Specific/Application address - e.g., email addresses or URLs, at the Application layer, human-friendly. Memory aid (bottom-up): MAC -> IP -> Port -> Name, mirroring Physical -> Network -> Transport -> Application.
MAC address: 48 bits, globally unique (assigned by manufacturer OUI), flat addressing, changes hop-by-hop in a packet's journey (rewritten by each router). IP address: 32 bits (IPv4) / 128 bits (IPv6), hierarchical, generally constant end-to-end (except with NAT). Port number: 16 bits; well-known ports 0-1023, registered 1024-49151, dynamic/ephemeral 49152-65535. Key exam insight: during routing, the source/destination IP addresses remain unchanged across hops, but the source/destination MAC addresses are rewritten at every router. The combination of IP address + Port + protocol forms a socket, the endpoint of a connection.
Memorize these for matching questions: FTP data=20, FTP control=21, SSH=22, TELNET=23, SMTP=25, DNS=53, DHCP server=67/client=68, HTTP=80, POP3=110, IMAP=143, SNMP=161, HTTPS=443. Tip groupings: email cluster = SMTP 25, POP3 110, IMAP 143; web = HTTP 80, HTTPS 443; remote access = SSH 22, TELNET 23. Ports 0-1023 are well-known and require privilege to bind. A socket = (IP address, port number). A connection is uniquely identified by a 5-tuple: (source IP, source port, destination IP, destination port, protocol).