def parse_q_enq_deq(line):
    """
    Parses a packet log line of a BESS queue log. Line should be of the form:
        ( "enq" or "deq", time ns, src port, seq, payload B, qsize, dropped,
          queued, batch size )
    """
    (event, time_ns, src_port, seq, payload_B, qsize, dropped, queued,
     batch_size) = [
         int(tok, 16) if tok.startswith("0x") else int(tok)
         for tok in line.split(",")]

    event_options = {0, 1}
    assert event in event_options, f"Event \"{event}\" not in {event_options}"
    if event == 0:
        event = "enq"
    else:
        event = "deq"

    return (
        event, time_ns / 1e3, src_port, seq, payload_B, qsize, dropped, queued,
        batch_size)