Structure Packet Field Conversion (default_structure_convert)
This section describes the functionality and limitations of the default structure packet field conversion method. This method is named default_structure_convert and is provided in source code form in the file default_structure_convert.pff.c, which resides in the <reldir>/models/std/base directory.
The default structure packet field conversion method can be used to convert packet fields to and from value vector form whenever the packet field is type “structure” and the structure contains a flat C data structure.
The conversion functions default_structure_convert_field_to_vvec() and default_structure_convert_field_from_vvec() are typically called as a result of calling the KP op_pk_fields_convert_to_vvec() and op_pk_fields_convert_from_vvec(), respectively. These conversion functions work with fields of type “structure”, which contain a pointer to an area of memory. For this conversion method to work, the pointer must be pointing to a flat C data structure allocated with the KP op_prg_mem_alloc().
default_structure_convert_field_to_vvec()
Prototype
int
default_structure_convert_field_to_vvec (Packet * pkptr,
int fd_index, Vvec_Vector vvec, int pos)
Description
default_structure_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 if the field is type “structure”.
- Determines the size of the field.
- Checks that the packet field size is a multiple of 8.
- Extracts the field value from the memory area indicated by the pointer.
- Assumes the memory area is the same number of bytes as the size of the field in bytes.
- Transfers each byte of the structure to the value vector, writing the value vector that represents this byte into the overall value vector.
- Sets the structure back into the field, using
op_prg_mem_alloc().
default_structure_convert_field_from_vvec()
Prototype
int
default_structure_convert_field_from_vvec (Packet * pkptr,
int fd_index, Vvec_Vector vvec, int pos)
Description
default_structure_convert_field_from_vvec() is passed a packet pointer, field index, value vector, and bit index.
The value vector conversion goes through the following steps:
- Checks to see if packet field is type “structure”.
- Determines size of packet field.
- Checks that the packet field size is a multiple of 8.
- Allocates memory equal to the size of the packet field in bytes.
- Checks that the value vector has enough bits present to fill the packet field just allocated.
- Extracts each byte from the value vector. Writes each byte extracted from the value vector into the structured packet field.
Assumptions and Limitations
The default packet field conversion method relies on certain assumptions. If these assumptions are not true, packet conversion will fail and the simulation will terminate. The following must be true:
- Field size must be greater than 0 and a multiple of 8.
- The field must be set.
- Bit index must be known.
- Field type must be “structure”.
- Value vector must be complete; it must contain bits for all of the fields in the packet format.
- Memory for the structure was allocated with
op_prg_mem_alloc()and can be deallocated withop_prg_mem_free().