def header_type_field_offset(p4_header_type, fname):
    for idx, f in enumerate(p4_header_type.layout):
        if f == fname:
            return idx
    LOG_CRITICAL("No field {} in header type {}".format(  # pragma: no cover
        fname, p4_header_type.name))