String Structure Packet Field Conversion (default_string_convert)
This section describes the functionality and limitations of the default string structure packet field conversion method. This method is named default_string_convert and is provided in source code form in the file default_string_convert.pff.c, which resides in the <reldir>/models/std/base directory.
The default string 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 memory of the structure points to a C string.
The conversion functions default_string_convert_field_to_vvec() and default_string_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.
default_string_convert_field_to_vvec()
Prototype
int
default_string_convert_field_to_vvec (Packet * pkptr,
int fd_index, Vvec_Vector vvec, int pos)
Description
default_string_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 of the field.
- Extracts the string from the field.
- Determines the length of the string.
- Transfers to the value vector as many characters as allowed by the field size.
- Writes the value vector into the overall value vector.
- If the string length is less than the defined field size, fills the remaining area of the value vector with zeros.
- Sets the string back into the field using
op_prg_mem_alloc().
default_string_convert_field_from_vvec()
Prototype
int
default_string_convert_field_from_vvec (Packet * pkptr,
int fd_index, Vvec_Vector vvec, int pos)
Description
default_string_convert_field_from_vvec() is passed a packet pointer, field index, value vector, and bit index. The string will be allocated with op_prg_mem_alloc(), and have a terminating zero.
- Checks to see if the packet field is type “structure”.
- Determines the size of the packet field.
- Checks to see if the value vector contains enough bits to fill this field.
- Allocates space for a character string the size of this field, plus 1 for a terminating null.
- Extracts, one at a time, each character of the string from the value vector.
- Forces the last character to be a null.
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.
- All packet fields must be “set”.
- Bit index must be known.
- Field type must be “structure”.
- Value vector must be complete and fully represent all of the fields of a packet.
- Memory for the structure was allocated with
op_prg_mem_alloc()and can be deallocated withop_prg_mem_free().