Simulate A Learning Switch MAC Address Table With Aging

Last updated: November 29, 2026

Quick Overview

Implement the forwarding decision of a Layer 2 switch: learn source MACs per VLAN, forward known unicast out one port, flood broadcast and unknown unicast within the VLAN, filter frames whose destination is on the ingress port, and age out entries after a timeout.

Cisco
Software Engineering Fundamentals
Software Engineer
Cisco
November 29, 2026
Software Engineer
Technical Screen
Software Engineering Fundamentals
Easy

0

0

0 solved


Implement the forwarding decision of a Layer 2 switch: learn source MACs per VLAN, forward known unicast out one port, flood broadcast and unknown unicast within the VLAN, filter frames whose destination is on the ingress port, and age out entries after a timeout.

Catalyst and Meraki switches all run this logic in hardware, and Cisco loops for platform and network OS roles often check that a candidate understands it well enough to code it. The interviewer looks for per-VLAN keys, host moves, lazy aging, and knowing when to flood versus filter.

What the Interviewer Expects
  • Keys the table by (VLAN, MAC), not MAC alone
  • Learns or refreshes the source on every frame, which also handles host moves
  • Floods broadcast and unknown unicast to all VLAN ports except ingress
  • Filters when the destination port equals the ingress port
  • Implements aging, lazily or with a sweep, and explains the trade-off
Key Topics to Cover
MAC learning
VLANs
flooding
aging timers
hash tables
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • How does a CAM table overflow attack work, and how does port security limit it?
  • Why does a topology change in spanning tree shorten the aging timer?
  • How would you make aging O(1) per frame without scanning the whole table?
  • What is different about how hardware stores this table versus a Python dict?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements

Method receive(now, vlan, in_port, src, dst, vlan_ports) returns the egress port list. Behaviors: learn src on in_port; broadcast floods; unknown unicast floods; known unicast goes to one port; ...

High-Level Design

A hash map from (vlan, mac) to (port, last_seen). Learning always overwrites, so a host that moves from port 1 to port 3 is updated on its first frame from the new port. Aging is lazy: on lookup, ...


Submit Your Answer
Markdown supported

Related Questions