Skip to content

Three lifecycle pieces, one class

write-from-scratch / multi-constraint / lifecycle-hook / array

A NIC frame has an 8-bit header, a variable-length payload and an 8-bit CRC. The interesting part is where each piece is decided:

  • header’s low 4 bits come from a global flag (jumbo_mode_en) before the solver runs. That’s pre_randomize()’s job; header isn’t rand.
  • The payload size depends on that, through ->. Constrain only the jumbo case and a non-jumbo frame can still roll a payload over 1500 bytes: each case needs its own ->.
  • crc is arithmetic over values the solver already picked, so it belongs in post_randomize().

Fix the class below.

Requirements

  1. pre_randomize() sets header[3:0] to 4’b1111 if jumbo_mode_en is set, else 4’b0000.
  2. When header[3:0] == 4’b1111, payload.size() is in [1501:2048]. When header[3:0] == 4’b0000, payload.size() is in [46:1500].
  3. post_randomize() sets crc to the 8-bit sum (wrapping) of header and every payload byte, inverted if crc_corrupt came out set.

Source on GitHub

l2_frame_fuzzer.sv