Question

An IP router implementing Classless Inter-domain Routing (CIDR) receives a packet with address 131.23.151.76. The router's routing table has the following entries:

Prefix Output Interface Identifier
131.16.0.0/12 3
131.28.0.0/14 5
131.19.0.0/16 2
131.22.0.0/15 1

The identifier of the output interface on which this packet will be forwarded is _____.

Official answer and solution
Official answer
1
From
Official GATE 2014 answer key

Solution

Convert the destination IP address and routing table prefixes to binary to find the matching entries and select the one with the longest prefix length.

  1. Destination IP Address:
    131.23.151.76

    • First octet: 131131.
    • Second octet in binary: 23=00010111223 = 00010111_2.
  2. Evaluate Routing Table Entries:

    • Prefix 1: 131.16.0.0/12 (length 12, interface 3)
      The first 12 bits consist of all 8 bits of octet 1 (131) and the first 4 bits of octet 2.
      For 16, binary is 00010000200010000_2, so first 4 bits are 0001.
      For 23, first 4 bits are 0001.
      Since 0001 matches 0001, this prefix matches. (Prefix length = 12)

    • Prefix 2: 131.28.0.0/14 (length 14, interface 5)
      Requires matching first 6 bits of octet 2.
      For 28, binary is 00011100200011100_2 -> first 6 bits are 000111.
      For 23, first 6 bits are 000101.
      000111 != 000101, so no match.

    • Prefix 3: 131.19.0.0/16 (length 16, interface 2)
      Requires matching all 8 bits of octet 2 (19=00010011219 = 00010011_2).
      Packet has 23≠1923 \ne 19, so no match.

    • Prefix 4: 131.22.0.0/15 (length 15, interface 1)
      Requires matching first 7 bits of octet 2.
      For 22, binary is 00010110200010110_2 -> first 7 bits are 0001011.
      For 23, binary is 00010111200010111_2 -> first 7 bits are 0001011.
      Since 0001011 matches 0001011, this prefix matches! (Prefix length = 15)

  3. Longest Prefix Match Rule:
    Between the matching prefixes /12 (interface 3) and /15 (interface 1), the longest prefix is /15.
    The associated interface identifier is 1.

Final answer

1

Common trap

Selecting the first matching entry in table order instead of finding the longest matching prefix.

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2014 Computer Science and Information Technology (CS) Session 3
Question
36 of 65, printed as CS Q.26
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.