Skip to the selected question
ASIC.FYI

ASIC Question Bank

1,000+ hardware interview questions
DescriptionQ1083
Page ↗
Q1083DVASIC interview problem

Model a token bucket with one-time aging bypass

TechniquesPythonToken bucketRate limitingAging
DifficultyHard
TopicReference Models
LanguagePython
Requirements4 checkpoints
01

Problem

Implement a token-bucket checker with capacity 16, four new tokens every ten cycles, one token consumed per send, and one no-token bypass for a packet that has waited more than twenty cycles.

Example input and output

Use this case to check your interpretation
Input
at cycle 21: tokens=0, packet id=9 has waited since cycle 0 after intervening legal sends consumed refills; send id9 twice
Output
first send uses its one aging bypass and removes id9; second send is rejected as unknown/duplicate
Explanation

Age 21 is greater than twenty and no token exists, so exactly one bypass is legal; successful removal prevents replay.

02

Requirements (4)

  • Apply every elapsed refill interval, cap the bucket at 16, and preserve the ten-cycle refill phase.
  • Track enqueue time by packet ID and reject sends for packets that were never enqueued.
  • Permit a bypass only when no token exists, age is greater than 20, and that packet has never bypassed.
  • Remove successful packets from the wait table and reject duplicate sends.