MAC Address Table With Aging and Station Moves

Last updated: November 29, 2026

Quick Overview

Implement a switch MAC address table keyed by (VLAN, MAC) that learns source addresses on ports, ages out entries not seen within a timeout, evicts the least recently seen entry when full, and flushes all entries on a port that goes down.

Arista Networks
Coding & Algorithms
Software Engineer
Arista Networks
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Implement a switch MAC address table keyed by (VLAN, MAC) that learns source addresses on ports, ages out entries not seen within a timeout, evicts the least recently seen entry when full, and flushes all entries on a port that goes down.

Layer 2 learning is a bread-and-butter EOS feature, and the software copy of the MAC table must age entries, handle hosts moving between ports, and react to link-down events. The interviewer looks for an O(1) structure and correct expiry semantics, not a periodic full scan.

What the Interviewer Expects
  • Key by (VLAN, MAC), since the same MAC can live in different VLANs
  • Refresh on relearn and update the port on a station move
  • Expire lazily from the oldest end in amortized O(1)
  • Evict least recently seen when at capacity
  • Return a miss (flood) for unknown or expired destinations
Key Topics to Cover
hash map
LRU
ordered dict
Layer 2 switching
timeouts
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you keep a MAC from flapping between two ports during a loop, and what would you log?
  • How would hardware learning and software tables stay in sync?
  • How does MLAG change learning when two switches share a port-channel?
  • Make flush_port O(entries on that port) instead of O(table).
Sharpen Your Skills on Codemia

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

Practice DSA Problems
Sample Answer
Requirements

learn(now, vlan, mac, port), lookup(now, vlan, mac) returning the port or None (meaning flood), flush_port(port). An entry lives for age seconds after it was last seen. Timestamps are non-de...

High-Level Design

Use an OrderedDict ordered by last-seen time. Learning moves the key to the end, so the front is always the oldest entry. Because every refresh moves to the end with the current time, the front entr...


Submit Your Answer
Markdown supported

Related Questions