IAE Academy

GATE 2023 CS Q.65: solution and answer

GATE 2023 · CSQ.65 · 2 marks · NAT

The forwarding table of a router is shown below.

A packet addressed to a destination address 200.150.68.118 arrives at the router. It will be forwarded to the interface with ID ______.

GATE 2023 CS question 65: A forwarding table with columns Subnet Number, Subnet Mask, Interface ID and five rows: (200.150.0.0, 255.255.0.0, 1)…Tap to open full size
Figure from the GATE 2023 CS paper. It is part of the question.
Figure description

A forwarding table with columns Subnet Number, Subnet Mask, Interface ID and five rows: (200.150.0.0, 255.255.0.0, 1), (200.150.64.0, 255.255.224.0, 2), (200.150.68.0, 255.255.255.0, 3), (200.150.68.64, 255.255.255.224, 4), (Default, blank mask, 0).

Answer and solution

ANSWER

The packet is forwarded to interface 3.

Official answer: 3Source: Official answer key, GATE 2023 CS (IIT Kanpur)

  1. A router forwards a packet by longest prefix match. For each entry, AND the destination 200.150.68.118 with the entry's mask and compare the result with the subnet number. Of all the entries that match, the one with the longest mask wins. The default route is used only when no other entry matches.

  2. Row 1, mask 255.255.0.0 (/16). The first two octets are 200.150, so the result is 200.150.0.0. This equals the subnet number, so the entry matches with prefix length 16.

  3. Row 2, mask 255.255.224.0 (/19). The third octet is , and the fourth octet becomes 0. The result is 200.150.64.0, which equals the subnet number. The entry matches with prefix length 19.

  4. Row 3, mask 255.255.255.0 (/24). The result is 200.150.68.0, which equals the subnet number. The entry matches with prefix length 24.

  5. Row 4, mask 255.255.255.224 (/27). The first three octets are 200.150.68. The last octet is . The result is 200.150.68.96, which is not 200.150.68.64. There is no match. (The block 200.150.68.64/27 covers 64 to 95, and 118 lies outside it.)

  6. Rows 1, 2 and 3 match, with prefix lengths 16, 19 and 24. The longest is /24, which is row 3. The default route is not used because other entries match.

  7. The packet is forwarded to interface 3.

KEY IDEA

Forwarding uses longest prefix match. Test every entry by ANDing the destination with its mask, keep the entries that match, and pick the one with the longest mask. Here that is 200.150.68.0/24, which gives interface 3.

WATCH OUT FOR

Choosing interface 4 because 200.150.68.64/27 has the longest mask and the address looks close to it. That entry covers 200.150.68.64 to 200.150.68.95 only, and 118 is outside this range, so it never matches. A second mistake is stopping at the first matching row (interface 1) or at the /19 row.

From the GATE 2023 CS paper. Every question of this paper · Download the full paper · All 20 IPv4 questions, with notes

More IPv4 questions