Quiz 2

Network Layer — IP Addressing, Subnetting, Routing

679 words
3 min read
Python Week 1: the first filter for runtime behavior
Visual companion
Python
Type and operator map

Python Week 1: the first filter for runtime behavior

View
Revision summary

What this note is really saying

Short form

# Network Layer — IP Addressing, Subnetting, Routing ## 🎯 Learning Objectives - Calculate subnet masks, network addresses, and broadcast addresses - Apply CIDR notation and VLSM - Trace Dijkstra's algorithm for link-state routing - Compare distance vector (RIP) and link-state (OSPF) routing * * * ## 1. IP Addressin...

Network Layer — IP Addressing, Subnetting, Routing

🎯 Learning Objectives

  • Calculate subnet masks, network addresses, and broadcast addresses
  • Apply CIDR notation and VLSM
  • Trace Dijkstra's algorithm for link-state routing
  • Compare distance vector (RIP) and link-state (OSPF) routing

1. IP Addressing

1.1 IPv4 Address Structure

An IPv4 address is 32 bits, typically written in dotted decimal: 192.168.1.1
pseudo
Bits:   |  8 bits  |  8 bits  |  8 bits  |  8 bits  |
        192        168        1          1
        Network ────────────┤├──── Host ───────┤

1.2 Address Classes (Historical)

ClassStartPrefixNetwork BitsHost BitsAddresses per Network
A0.0.0.0 - 127.255.255.255/882416,777,214
B128.0.0.0 - 191.255.255.255/16161665,534
C192.0.0.0 - 223.255.255.255/24248254

1.3 CIDR (Classless Inter-Domain Routing)

CIDR notation: 192.168.1.0/24 means the first 24 bits are the network prefix.
CIDRSubnet MaskTotal AddressesUsable Hosts
/30255.255.255.25242
/29255.255.255.24886
/28255.255.255.2401614
/27255.255.255.2243230
/26255.255.255.1926462
/25255.255.255.128128126
/24255.255.255.0256254
/16255.255.0.065,53665,534
/8255.0.0.016,777,21616,777,214

1.4 Subnetting Worked Example

Problem: You have network 192.168.1.0/24. Create 4 subnets with equal hosts. Step 1: 4 subnets need ceil(log2(4)) = 2 extra bits → /26 Step 2: Subnet boundaries:
SubnetNetworkFirst HostLast HostBroadcast
1192.168.1.0/26.1.62.63
2192.168.1.64/26.65.126.127
3192.168.1.128/26.129.190.191
4192.168.1.192/26.193.254.255
Step 3: Binary representation of subnet 1:
pseudo
Network:   192.168.1.00 000000 → 192.168.1.0
Mask:      255.255.255.11 000000 → /26
First:     192.168.1.00 000001 → .1
Last:      192.168.1.00 111110 → .62
Broadcast: 192.168.1.00 111111 → .63

2. Routing Algorithms

Used by OSPF. Each router knows the full network topology and computes the shortest path. (Diagram) Dijkstra from A:
StepVisitedDist(A)Dist(B)Dist(C)Dist(D)Dist(E)Dist(F)
0{A}02 (A)5 (A)
1{A,B}02*5 (A)3 (B)5 (B)
2{A,B,D}024 (D)3*5 (B)5 (D)
3{A,B,D,C}024*35 (B)5 (D)
4{A,B,D,C,E}02435*5 (D)
5{A,B,D,C,E,F}024355*
Routing table for A:
DestinationNext HopCost
BB2
CB (via D)4
DB3
EB5
FB (via D)5

2.2 Distance Vector Routing (RIP)

Each router shares its distance vector (list of distances to all destinations) with neighbors only. Bellman-Ford equation: dx(y)=minv{c(x,v)+dv(y)}d_x(y) = \min_v\{c(x,v) + d_v(y)\} Example: Router B's DV evolves:
sql
Initial:  B → A:2, C:∞, D:1, E:3, F:∞
After receiving from A: A→C:5, A→D:∞, A→E:∞, A→F:∞
  B→C = min(∞, 2+5=7) = 7 via A
Problems: Count-to-infinity, routing loops. RIP uses hop count (max 15) and split horizon to mitigate.

2.3 OSPF vs RIP vs BGP

PropertyRIP (DV)OSPF (LS)BGP (Path Vector)
AlgorithmBellman-FordDijkstraPath vector
MetricHop countCost (bandwidth)Path attributes
ConvergenceSlowFast (flooding)Slow (policy)
ScopeIntra-ASIntra-ASInter-AS
Max hops15No limitNo limit
UpdatesEvery 30sEvent-drivenEvent-driven

3. ICMP and ARP

3.1 ICMP (Internet Control Message Protocol)

Used for error reporting and diagnostics:
TypeCodeMeaning
00Echo Reply (ping reply)
30Destination Network Unreachable
31Destination Host Unreachable
80Echo Request (ping)
110TTL Expired (traceroute)

3.2 ARP (Address Resolution Protocol)

Maps IP addresses to MAC addresses: (Diagram)

4. 📝 Practice Questions

Q1: Given network 172.16.0.0/16, create 8 subnets. What is the subnet mask and address ranges?
Answer: 8 subnets = 3 bits → /19. Subnet mask: 255.255.224.0. Each subnet has 8192 addresses (8190 usable).
Subnets: 172.16.0.0/19, 172.16.32.0/19, 172.16.64.0/19, ..., 172.16.224.0/19 Q2: Apply Dijkstra's algorithm to find the shortest path from D to F in the graph above.
Answer: From A's routing table above, D→F via D→C→F (cost 1+4=5) or D→F directly (cost 2). Direct path D→F (cost 2) is shortest. Q3: Why does RIP have a maximum hop count of 15?
Answer: To prevent count-to-infinity loops. If a route's metric reaches 16 (infinity), it's considered unreachable. This bounds the convergence time of the distance vector algorithm. Q4: What problem does CIDR solve that classful addressing couldn't?
Answer: CIDR allows flexible subnetting (VLSM) and aggregation (route summarization). Classful addressing wasted addresses (a Class C is too small for many, Class B too large). CIDR also reduces routing table size through supernetting. Q5: How does ARP work when the destination is on a different network?
Answer: The host checks if the destination IP is on the same network (using its subnet mask). If not, it sends the packet to the default gateway (router). It uses ARP to find the gateway's MAC address, not the destination's.

5. 🔗 Cross-References

Document outline

Keep your place and jump directly to a heading.

Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.