Packet Field Conversion (default_convert)
This section describes the functionality and limitations of the default packet field conversion method. This method is named default_convert and is provided in source code form in the file default_convert.pff.c, which resides in the <reldir>/models/std/base directory.
The default packet field conversion method can be used to convert packet fields to and from value vector form whenever the packet field does not require any special processing and is not of type “structure”.
The conversion functions default_convert_field_to_vvec() and default_convert_field_from_vvec() are typically called as a result of calling the KPs op_pk_fields_convert_to_vvec() and op_pk_fields_convert_from_vvec(), respectively.
default_convert_field_to_vvec()
Prototype
int
default_convert_field_to_vvec (Packet * pkptr, int fd_index,
Vvec_Vector vvec, int pos)
Description
default_convert_field_to_vvec() is passed a packet pointer, field index, value vector, and value vector bit index.
The packet field conversion goes through the following steps:
- Determines the size in bits of the field.
- Determines if field is set or not set (the field must be set or conversion fails).
- Determines if the value vector bit index is unknown.
- Determines the type of the field.
- Determines the encoding of field.
- Obtains the field value.
- Writes the value vector that represents this field’s value into the overall value vector.
default_convert_field_from_vvec()
Prototype
int
default_convert_field_from_vvec (Packet * pkptr,
int fd_index, Vvec_Vector vvec, int pos)
Description
default_convert_field_from_vvec() is passed a packet pointer, a field index, a value vector, and a suggested value vector bit index.
The value vector conversion goes through the following steps:
- Checks for bit index value “unknown”.
- Determines the size of the packet field.
- Determines the encoding of the value vector.
- Sets the value of the field from the value of the vvec.
- If the field is for an encapsulated packet, checks for special field size “inherited”. If inherited, attempts to determine what range of bits from the value vector should be taken as representing the encapsulated packet.
Assumptions and Limitations
The default packet field conversion methods rely on certain assumptions. If these assumptions are not true, field conversion will fail and the simulation will terminate. The following must be true:
- Field size must be greater than 0.
- The packet field must be set.
- Suggested value vector bit index must be known.
- Field type must not be “structure”.
- Encapsulated packets must equal the size of their field.
- Packet can have no more than one packet field with size inherited.
- The value vector is complete and fully represents all of the fields of this packet.