Token Bucket Policer for Control Plane Traffic Classes

Last updated: November 29, 2026

Quick Overview

Implement a token bucket rate limiter and use it to police control-plane packets per traffic class (for example ARP, BGP, LLDP), each with its own rate and burst, counting drops per class.

Arista Networks
Coding & Algorithms
Software Engineer
Arista Networks
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Easy

0

0

0 solved


Implement a token bucket rate limiter and use it to police control-plane packets per traffic class (for example ARP, BGP, LLDP), each with its own rate and burst, counting drops per class.

Control plane policing keeps an ARP storm from starving BGP on the switch CPU, and EOS applies per-class policers to traffic punted from the ASIC. The interviewer checks a correct lazy-refill token bucket and the reasoning behind rate versus burst.

What the Interviewer Expects
  • Refill lazily from elapsed time instead of a timer thread
  • Cap tokens at the burst size
  • Start full so an idle class can absorb a burst
  • Keep independent buckets and drop counters per class
  • Guard against time going backwards
Key Topics to Cover
token bucket
rate limiting
control plane policing
simulation
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 make this safe when many threads call admit concurrently?
  • What is the difference between policing and shaping?
  • How would you pick rate and burst for BGP on a switch with 500 peers?
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

admit(now, cls) returns whether a packet of class cls is allowed at time now. Each class has (rate_pps, burst). Dropped packets are counted. Time is in seconds as a float....

High-Level Design

A token bucket holds up to burst tokens and gains rate tokens per second. On each request, add elapsed * rate, cap at burst, and spend one token if available. This gives a long-run rate of `ra...


Submit Your Answer
Markdown supported

Related Questions