MODULE 03 · COMPUTER NETWORKS
NETWORK LAYER — DEVICES, IP ADDRESSING, ROUTING
01
Layer 3

Network Layer & Packet Switching

Network Layer (OSI Layer 3) — end-to-end delivery of packets across multiple networks. Unlike Data Link (same network), Network Layer handles cross-network routing via IP addresses.

5 Key Functions

FunctionWhat it does
Logical AddressingAssigns unique IP addresses; identifies host + network
RoutingFinds optimal path using algorithms (Dijkstra, Bellman-Ford)
Packet ForwardingMoves packet from input interface → correct output interface
Fragmentation & ReassemblySplits packets to fit MTU; reassembles at destination
Error/Congestion ControlDetects errors, notifies upper layers, prevents congestion

Packet Switching

Data is broken into packets that travel independently through the network — no dedicated path (unlike circuit switching used in old PSTN).
✔ Advantages
  • Efficient resource utilization (shared links)
  • Resilient — reroutes around failures
  • Scalable — handles bursty traffic
  • Cost-effective — no dedicated circuit
✘ Disadvantages
  • Variable delay (jitter)
  • Possible packet loss → retransmission
  • Out-of-order delivery

Packet Structure

PartContains
HeaderSource IP, Dest IP, Sequence #, Protocol type (TCP/UDP), TTL
PayloadActual data being transmitted
MTU (Maximum Transmission Unit) — max packet size a network can carry. Ethernet MTU = 1500 bytes. Packets larger than MTU are fragmented.
02
Devices

Networking & Internetworking Devices

Quick Comparison — All Devices

DeviceOSI LayerAddresses UsedBroadcast?Key Role
RepeaterLayer 1 (Physical)NoneYesSignal amplification/regeneration
HubLayer 1 (Physical)NoneYes (all ports)Multi-port repeater
BridgeLayer 2 (Data Link)MAC addressSelectiveConnects two LAN segments
SwitchLayer 2 (Data Link)MAC addressNo (unicast)Intelligent multi-port bridge
RouterLayer 3 (Network)IP addressNoConnects different networks
GatewayLayer 4–7 (up to App)IP + ProtocolNoProtocol conversion between hetero networks
FirewallLayer 3 + 7IP, Port, ProtocolNoTraffic filtering & security
L1Repeater

Operates at Physical Layer. Amplifies/regenerates electrical signals to extend network distance.

Simple, inexpensive, extends cable distance
No filtering — forwards noise too. No MAC/IP awareness.
L1Hub
Multi-port repeater. Broadcasts every incoming signal to ALL ports. All devices share one collision domain.
  1. Device A sends frame → hub receives on port 1
  2. Hub regenerates signal → broadcasts to ALL other ports
  3. Only device with matching MAC accepts it; others discard
✔ Pros✘ Cons
Simple, cheap, plug-and-playBroadcasts to all → collisions
Signal regenerationShared bandwidth degraded with more devices
Star topology supportNo traffic filtering, no security
Largely replaced by Switches which handle data intelligently at Layer 2.
L2Bridge
Operates at Data Link Layer. Connects two LAN segments. Learns MAC addresses and forwards frames only to the segment where the destination lives.
  • Maintains a MAC address table (learned by observing source addresses)
  • Reduces collision domain (each segment is separate)
  • Filters traffic between segments — less congestion
L2Switch
A multi-port bridge. Each port = its own collision domain. Uses MAC address table (CAM table) to forward frames only to the correct port.
  1. Frame arrives → switch reads source MAC → updates CAM table
  2. Looks up destination MAC in table
  3. Forwards frame only to destination port (unicast)
  4. If unknown destination → floods all ports (like hub)
Full bandwidth per port, no collisions, intelligent forwarding
L3Router
Operates at Network Layer. Connects different networks. Uses IP addresses and routing tables to determine optimal path.

How a Router Forwards a Packet

  1. Packet arrives at input interface
  2. Router reads destination IP from header
  3. Searches routing table for longest prefix match
  4. Selects best path (using routing algorithm)
  5. Forwards out appropriate interface → next hop
  6. Repeat at each router until destination reached
Routing Table Entry contains:
Dest Network | Subnet Mask | Next-Hop IP | Interface | Metric
Subnet Example:
IP: 192.168.1.10 | Mask: 255.255.255.0 → Network: 192.168.1.0 | Host: 10
✔ Pros✘ Cons
Inter-network communicationComplex config
Optimal path selectionHigher cost than hub/switch
Traffic management & filteringProcessing latency
Protocol independenceRouting table maintenance overhead
L7Gateway
Protocol converter between heterogeneous networks (different architectures/protocols). Operates up to Application Layer.
Use case: Connecting a TCP/IP network to a legacy IBM SNA mainframe — Gateway translates HTTP ↔ SNA.
  • Address conversion (IP ↔ SNA address)
  • Protocol conversion (TCP/IP ↔ SNA)
  • Data format/encoding conversion
  • Acts as security checkpoint (proxy)
Con: Single point of failure — if gateway goes down, inter-network comm stops.
L3+7Firewall
Monitors, filters, and controls traffic based on predefined security rules. Barrier between trusted internal ↔ untrusted external networks.

Types of Firewalls

TypeHow it worksState-aware?
Packet Filtering (Stateless)Checks each packet header (src IP, dest IP, port, protocol) against rules independentlyNo
Stateful InspectionTracks active connection state — only allows packets matching established sessionsYes
Proxy-basedIntermediary — client ↔ firewall ↔ server; full application-level inspectionYes
Flexible rules (IP, port, protocol, application), VPN support, data leakage prevention
Cannot protect against internal threats or sophisticated app-layer attacks alone.
03
Addressing

IPv4 — Logical Addressing

IPv4 — 32-bit address, written as 4 octets in dotted-decimal notation. 192.168.1.10. Total ~4.3 billion addresses (2³²).

IPv4 Header (20 bytes minimum)

Bits→ 0 16 32 Ver(4) IHL(4) Type of Service(8) Total Length (16) Identification (16) Flags(3) Fragment Offset (13) TTL (8) Protocol (8) Header Checksum (16) Source IP Address (32) Destination IP Address (32) Options (variable) + Padding Control Fields Address Fields Other Fields Key Fields: TTL: hop count, decremented at each router Protocol: 6=TCP, 17=UDP, 1=ICMP IHL: header length in 32-bit words Flags: DF (don't fragment), MF (more frags) Frag Offset: position of this frag in datagram

IPv4 Address Classes

ClassFirst Octet RangeDefault Subnet MaskNetworksHosts/NetworkUse
A1–126255.0.0.0 (/8)12616,777,214Large orgs, ISPs
B128–191255.255.0.0 (/16)16,38465,534Universities, mid-size
C192–223255.255.255.0 (/24)2M+254Small networks, homes
D224–239N/AMulticast
E240–255N/AResearch/Reserved
127.x.x.x = Loopback (localhost). 169.254.x.x = APIPA (no DHCP). 10.x, 172.16–31.x, 192.168.x = Private ranges (RFC 1918).

Subnetting & CIDR

CIDR (Classless Inter-Domain Routing) — uses prefix notation /n to define variable-length subnet masks. Replaces classful addressing.
CIDRSubnet MaskHostsExample Use
/8255.0.0.016,777,214Class A equiv
/16255.255.0.065,534Class B equiv
/24255.255.255.0254Class C equiv
/30255.255.255.2522Point-to-point links
Hosts = 2(32-prefix) − 2 (subtract network & broadcast address)

IPv4 Datagram Delivery

TypeDescriptionExample
Direct DeliverySource & destination on same network — no routing needed192.168.1.5 → 192.168.1.20
Indirect DeliveryPasses through one or more routers192.168.1.5 → 8.8.8.8 via ISP router
UnicastOne source → one destinationHTTP request to server
BroadcastOne source → all hosts in networkARP request: 255.255.255.255
MulticastOne source → group of interested receivers (Class D)OSPF routers (224.0.0.5)
04
IPv6

IPv6 — Next Generation IP

IPv6 — 128-bit address. Written as 8 groups of 4 hex digits separated by colons.
2001:0db8:85a3:0000:0000:8a2e:0370:7334
Total = 2128 ≈ 3.4 × 1038 addresses — effectively unlimited.

Why IPv6? — IPv4 Problems Solved

IPv4 ProblemIPv6 Solution
Address exhaustion (only ~4.3B)128-bit = 340 undecillion addresses
Complex header with options overheadFixed 40-byte header, extension headers for options
Fragmentation by routersOnly source fragments; routers drop oversized + send ICMPv6
No built-in securityIPSec mandatory in IPv6 spec
Manual / DHCP address configSLAAC — Stateless Address Autoconfiguration
Checksum in header (redundant)No header checksum — upper layers handle it
Broadcast (wastes bandwidth)No broadcast — uses multicast & anycast instead

IPv6 Header (Fixed 40 bytes)

Version(4) Traffic Class(8) Flow Label (20) Payload Length (16) Next Hdr(8) Hop Limit (8) Source IP Address (128 bits) Destination IP Address (128 bits) vs IPv4: ✔ No checksum field ✔ No fragmentation fields ✔ Flow Label for QoS ✔ TTL → Hop Limit ✔ Options → Extension headers ✔ Fixed 40B (IPv4 = 20–60B) Next Header: like Protocol field points to next extension hdr or upper layer (6=TCP, 17=UDP)

IPv6 Address Types

TypePrefixDescription
Unicast — Global2000::/3Routable on internet (like public IPv4)
Unicast — Link-LocalFE80::/10Auto-configured, same link only (like 169.254.x.x)
Unicast — Loopback::1Localhost (like 127.0.0.1)
MulticastFF00::/8One-to-many (replaces broadcast)
AnycastSame as unicastOne-to-nearest (routed to closest node in group)
Unspecified::Source before address assigned (like 0.0.0.0)
No broadcast in IPv6! Replaced by multicast (e.g., All-nodes: FF02::1, All-routers: FF02::2)

IPv6 Address Shortening Rules

  1. Drop leading zeros in each group: 004242
  2. Replace one longest run of all-zero groups with :: (only once)
2001:0db8:0000:0000:0000:0000:0000:00012001:db8::1

Multicasting (IPv4 & IPv6)

Multicast = one source → multiple interested receivers simultaneously. Efficient — source sends one copy; network replicates at branch points.
FeatureIPv4 MulticastIPv6 Multicast
Address Range224.0.0.0–239.255.255.255 (Class D)FF00::/8
Group mgmt protocolIGMP (Internet Group Management Protocol)MLD (Multicast Listener Discovery)
Example224.0.0.5 — all OSPF routersFF02::1 — all nodes on link
Well-known groups224.0.0.1 all hosts, 224.0.0.2 all routersFF02::2 all routers
IGMP — hosts use IGMP to tell routers which multicast groups they want to join/leave.
05
NAT

Network Address Translation

NAT — translates private IP addresses to a public IP (and vice versa) at the router/gateway. Solves IPv4 exhaustion by letting many devices share one public IP.

How NAT Works

Private LAN PC1: 192.168.1.10 PC2: 192.168.1.11 PC3: 192.168.1.12 NAT Router Public IP: 203.0.113.5 Internet Server: 8.8.8.8 Web: 142.250.x.x src: 192.168.1.10 src: 203.0.113.5 NAT Table Private → Public .10:1234→:5000 .11:2345→:5001 .12:3456→:5002

Types of NAT

TypeMappingUse Case
Static NAT1 private IP ↔ 1 public IP (permanent)Servers that need fixed public IP
Dynamic NATPrivate IP → any available public IP from poolMultiple users sharing a pool
PAT / NAT OverloadMany private IPs → 1 public IP (differentiated by port)Home routers (most common)
PAT (Port Address Translation) = most common. Each session gets unique source port. The NAT table maps (private IP:port) ↔ (public IP:port).

NAT Pros & Cons

  • Conserves IPv4 addresses
  • Hides internal topology (security)
  • Easy to change ISP (only public IP changes)
  • Breaks end-to-end connectivity
  • Complicates P2P apps (VoIP, gaming)
  • State table overhead on router
  • Not needed with IPv6 (enough addresses)
06
Error Reporting

ICMP — Internet Control Message Protocol

ICMP — Layer 3 protocol (encapsulated in IP). Used for error reporting and diagnostics — NOT for data transfer. Protocol number = 1.

ICMP Message Types

TypeCodeMeaningSent by
Echo Request8Ping — "are you alive?"Source host
Echo Reply0Ping response — "yes, alive"Destination host
Dest Unreachable3Packet can't reach destinationRouter/dest host
Time Exceeded11TTL reached 0 (used by traceroute)Router
Redirect5Better route availableRouter
Source Quench4Congestion — slow down (deprecated)Router
Frag Needed3/4Packet too big, DF bit setRouter
ping uses Echo Request/Reply. traceroute uses TTL Exceeded — sends packets with incrementing TTL to map the path.

ICMPv6 — New in IPv6

  • Combines ICMPv4 + ARP + IGMP functions
  • Neighbor Discovery Protocol (NDP) — replaces ARP for MAC address resolution
  • Router Solicitation/Advertisement — for SLAAC autoconfiguration
  • MLD (Multicast Listener Discovery) — replaces IGMP
  • Path MTU Discovery — finds minimum MTU along path
07
Routing

Forwarding, Delivery & Routing Algorithms

Routing = determining the optimal path from source to destination through the network. Routing algorithms populate the routing table used for forwarding decisions.

Routing Algorithm Classification

Routing Algorithms Non-Adaptive (Static) Adaptive (Dynamic) Flooding Random Walk Distance Vector (DVR) Link State (LSR) Routes fixed at startup Adapts to network changes

Algorithm Comparison

PropertyDistance Vector (DVR)Link State (LSR)
AlgorithmBellman-FordDijkstra's SPF
Information sharedDistance vector (routing table) with neighborsFull topology (LSAs) flooded to all routers
KnowledgeLocal — only knows what neighbors sayGlobal — each router has complete map
ConvergenceSlow — count-to-infinity problemFast — immediate after LSA flood
BandwidthLow overheadHigh overhead (flooding LSAs)
CPU/MemoryLowHigh (Dijkstra per router)
ProtocolsRIP (max 15 hops)OSPF, IS-IS
ScaleSmall networksLarge enterprise networks
08
DVR

Distance Vector Routing — Bellman-Ford

Each router maintains a table: for every destination, the distance (cost) and the next hop. Routers periodically share this table with direct neighbors and update based on received info.

Bellman-Ford Equation

Dx(y) = min over all neighbors v { cost(x,v) + Dv(y) }

Dx(y) = best known distance from x to y. For each neighbor v, add link cost to v + v's known distance to y. Take the minimum.

DVR Algorithm Steps

  1. Each router initializes table: distance to itself = 0, to direct neighbors = link cost, to others = ∞
  2. Periodically sends its full distance table to all direct neighbors
  3. On receiving a neighbor's table, recalculates distances using Bellman-Ford
  4. If a shorter path is found, update table and next-hop entry
  5. Repeat until no more updates (convergence)

DVR Example

A B C D 2 5 3 1 4 A's Table Dest | Dist | Next A | 0 | — B | 2 | B C | 5 | C D | 5 | B (A→B→D = 2+3)

Count-to-Infinity Problem

Problem: When a link fails, routers may iteratively and incorrectly increment distance, slowly counting up to infinity (∞ = 16 in RIP) before marking route as unreachable.
FixHow
Split HorizonDon't advertise a route back to the neighbor you learned it from
Poison ReverseAdvertise failed routes with ∞ cost back to source neighbor
Hold-down timersDon't accept updates about a failed route for a fixed period
Triggered updatesSend update immediately when route changes (don't wait for timer)

RIP — Routing Information Protocol

  • DVR protocol, uses hop count as metric
  • Max hop count = 15 (16 = unreachable/∞)
  • Updates every 30 seconds
  • RIPv1 = classful; RIPv2 = classless (CIDR support)
  • Suitable only for small networks
09
LSR + Dijkstra

Link State Routing & Dijkstra's Algorithm

Each router builds a complete map of the network topology using Link State Advertisements (LSAs) flooded to all routers. Then runs Dijkstra's Shortest Path First (SPF) to calculate best routes.

LSR Process (5 Steps)

  1. Discover neighbors — send Hello packets to learn directly connected routers and link costs
  2. Build LSA — create Link State Advertisement: {router ID, neighbor list, link costs}
  3. Flood LSAs — broadcast LSA to ALL routers in network (reliable flooding)
  4. Build topology map — each router assembles a Link State Database (LSDB) — complete network graph
  5. Run Dijkstra's SPF — compute shortest path tree from self to every destination
OSPF (Open Shortest Path First) is the dominant LSR protocol in enterprise networks.

Dijkstra's Shortest Path Algorithm

Finds shortest path from a source node to all other nodes in a weighted graph with non-negative weights.

Algorithm

Initialize: dist[src]=0, dist[all others]=∞, visited={} Repeat until all nodes visited: 1. Pick unvisited node u with minimum dist[u] 2. Mark u as visited 3. For each neighbor v of u: if dist[u] + cost(u,v) < dist[v]: dist[v] = dist[u] + cost(u,v) prev[v] = u // track path

Worked Example

A B C D E F 4 2 3 5 6 1 2 4

Dijkstra Table (Source = A)

StepVisitedABCDEF
Init0
1A4(A)2(A)
2A,C4(A)7(C)
3A,C,B7(B)7(C)
4A,C,B,D8(D)9(D)
5A,C,B,D,E9(D)
FinalAll042789
Shortest path A→F = A→C→B→D→E... wait: A→C(2)→B? No. A→B(4)→D(7)→E? D→E=1 → 8. D→F=2 → 9. So A→F = 9 via A→B→D→F. ✓
Time Complexity: O(V²) naive, O((V+E) log V) with priority queue. Used in OSPF.

OSPF — Open Shortest Path First

  • LSR protocol, uses Dijkstra's SPF
  • Metric = cost (based on bandwidth: 100Mbps/link bandwidth)
  • Uses Hello packets to discover and maintain neighbor relationships
  • Hierarchical: organizes into Areas (Area 0 = backbone)
  • Fast convergence, scales to large networks
  • Supports VLSM (Variable Length Subnet Mask) and CIDR
10
Transition

IPv4 to IPv6 Transition Mechanisms

The internet cannot switch from IPv4 to IPv6 overnight. Transition mechanisms allow coexistence and gradual migration so IPv4 and IPv6 devices can communicate.

Three Main Transition Strategies

StrategyHow it WorksUse Case
Dual StackDevice runs both IPv4 and IPv6 simultaneously. Uses IPv6 when available, falls back to IPv4.Most common today — OS/router level support
TunnelingIPv6 packets are encapsulated inside IPv4 packets to cross IPv4-only networks. IPv6-in-IPv4 tunnel.Connecting IPv6 islands over IPv4 backbone
Translation (NAT64)Gateway translates between IPv4 and IPv6 headers. IPv6-only device can communicate with IPv4-only server.Operators migrating to IPv6-only networks

Tunneling Types

TypeDescription
6in4Manual tunnel — IPv6 encapsulated in IPv4 protocol 41
6to4Automatic — uses 2002::/16 prefix. Embeds IPv4 address in IPv6 address
TeredoTunnels through NAT using UDP. Last-resort method (Microsoft)
ISATAPIntra-site — tunnels IPv6 within IPv4 enterprise networks

IPv4 vs IPv6 — Complete Comparison

FeatureIPv4IPv6
Address length32 bits (4 bytes)128 bits (16 bytes)
Address notationDotted decimal: 192.168.1.1Hex colon: 2001:db8::1
Total addresses~4.3 billion~340 undecillion
Header size20–60 bytes (variable)40 bytes (fixed)
FragmentationRouters & sourceSource only
ChecksumYes (in header)No (removed for efficiency)
BroadcastYesNo (multicast replaces it)
Security (IPSec)OptionalMandatory
ConfigManual / DHCPSLAAC / DHCPv6
Address classesA, B, C, D, EUnicast, Multicast, Anycast
NAT neededYes (address exhaustion)No
QoSToS fieldFlow Label (dedicated QoS)
FC
Study

Flashcards

Tap card to reveal answer

Quick Ref

Master Cheatsheet

All Key Facts — One Table

TopicKey Fact
Network LayerOSI Layer 3 — end-to-end delivery, IP addressing, routing
Packet SwitchingData split into packets; each routed independently; reassembled at dest
MTUMax packet size; Ethernet = 1500 bytes; fragmentation if exceeded
HubLayer 1, broadcasts to all ports, shared collision domain
SwitchLayer 2, MAC table (CAM), unicast forwarding, separate collision domains
RouterLayer 3, IP addresses, routing table, connects different networks
GatewayLayer 7, protocol converter, heterogeneous network bridge
Firewall typesStateless (packet filter) | Stateful | Proxy
IPv4 address32-bit, dotted-decimal, ~4.3B addresses
Class A1–126, /8, ~16M hosts
Class B128–191, /16, ~65K hosts
Class C192–223, /24, 254 hosts
Class D224–239, Multicast
Private ranges10.x, 172.16-31.x, 192.168.x (RFC 1918)
IPv6 address128-bit, hex colon notation, 2¹²⁸ addresses
IPv6 loopback::1
IPv6 link-localFE80::/10
IPv6 multicastFF00::/8; All-nodes FF02::1; All-routers FF02::2
NAT typesStatic (1:1), Dynamic (pool), PAT/Overload (many:1 via port)
ICMP EchoType 8 = Request, Type 0 = Reply (ping)
ICMP Time ExceededType 11 — TTL = 0 (used by traceroute)
DVR algorithmBellman-Ford; shares routing table with neighbors; slow convergence
DVR problemCount-to-infinity; fix: split horizon, poison reverse
RIP max hops15; 16 = unreachable; updates every 30s
LSR algorithmDijkstra's SPF; floods LSAs globally; fast convergence
OSPF metricCost = 100Mbps / link bandwidth; uses Hello packets
Dijkstra complexityO(V²) naive; O((V+E)logV) with priority queue
IPv4→IPv6 transitionDual Stack | Tunneling (6in4, 6to4, Teredo) | NAT64 Translation
Multicast (IPv4)Class D (224–239), IGMP for group management
SLAACIPv6 Stateless Address Autoconfiguration — no DHCP needed
ICMPv6 / NDPReplaces ARP + IGMP; used for neighbor discovery & SLAAC