GATE / CS ARCHIVE

GATE CSE 2024 SET 1 / QUESTION 58

Choose the longest matching IP prefix

Computer Networks · Routing Algorithms · Full GATE CSE 2024 Set 1 paper

GATE 2024 Set 1, Q58 2 marks · NAT
Report issue

Routing Algorithms

Question 58, GATE 2024: A router has routes 10.1.1.0/24→R1, 10.1.1.128/25→R2, 10.1.1.64/26→R3 and 10.1.1.192/26→R4. It sends 20 packets to each of 10.1.1.16, .72, .132, .191 and .205. How many packets use R2? The abbreviated destinations share prefix 10.1.1.
Tap to enlarge
Answer & solution

Official answer: 40

Step through it (7 steps)

Approach: A router uses the matching route with the greatest prefix length, not the first matching row or every matching route.
1. The /24 covers last-octet values 0–255. The /25 beginning at 128 covers 128–255. The /26 beginning at 64 covers 64–127, and the /26 beginning at 192 covers 192–255.
2. Destination .16 matches only the /24 and uses R1. Destination .72 matches the /24 and the 64/26; the longer /26 wins, so it uses R3.
3. Destinations .132 and .191 match the /24 and the 128/25, with no matching /26. Both therefore use R2.
4. Destination .205 also matches R2's /25, but it matches the more specific 192/26, so it uses R4 instead.
Exactly two hosts use R2, each with 20 packets: 2×20=40.
Answer: 40. Counting .205 for R2 would ignore longest-prefix selection.

Original paper, page 34 · Answer key