Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Model a token bucket with one-time aging bypass

Hardware interview practice

Model a token bucket with one-time aging bypass

HardReference ModelsPYTHON

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.

Try it in the question bankReason first. Then compare.

Keep this exact question selected while you check your answer and review the full solution.

Practice this question →
Reviewed example

Work through one case

Input
at cycle 21: tokens=0, packet id=9 has waited since cycle 0 after intervening legal sends consumed refills; send id9 twice
Expected output
first send uses its one aging bypass and removes id9; second send is rejected as unknown/duplicate

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

What to cover

Requirements

  1. Apply every elapsed refill interval, cap the bucket at 16, and preserve the ten-cycle refill phase.
  2. Track enqueue time by packet ID and reject sends for packets that were never enqueued.
  3. Permit a bypass only when no token exists, age is greater than 20, and that packet has never bypassed.
  4. Remove successful packets from the wait table and reject duplicate sends.
asic.fyi · Learn silicon end to end.info@asic.fyi