op_pk_fields_convert_to_vvec()
Abstract
Iterates through a formatted packet’s fields, calling each field’s conversion function.
Syntax
op_pk_fields_convert_to_vvec (pk_ptr, vvec, vvec_index)
| Argument | Type | Description |
|---|---|---|
pk_ptr |
Packet* |
pointer to a formatted packet [The packet’s fields are written to a value vector using the conversion function specified for each field.] |
vvec |
Vvec_Vector |
existing value vector that stores the bit sequence generated [The value vector, which must be already be allocated, receives the bit sequence generated by the conversion functions.] |
vvec_index |
int |
index number of position to receive first bit of bit sequence [The conversion methods used by this KP generate a bit sequence based on the contents of the formatted packet’s user-defined fields. This argument specifies the position in the value vector at which to insert this bit sequence.] |
Return Type
Compcode
Completion code indicating whether the conversion completed successfully.
[This value can be compared to the two symbolic constants OPC_COMPCODE_SUCCESS and OPC_COMPCODE_FAILURE.]
Example
/* Build a value vector representation of the opnet */
/* packet, but without changing the original packet. */
vvec = op_vvec_create (OPC_TYPE_BIT);
/* Have each field's contents written into "vvec". */
/* The first 16 bits of the value vector */
/* representation of the packet will store a */
/* checksum, so the conversion of the fields is */
/* started offset 15 bits into "vvec' */
return_code = op_pk_fields_convert_to_vvec (pkptr, vvec, 15);
/* Set the checksum value... */
Details
This function, typically called by a packet conversion method, calls each field’s conversion method to set values in a value vector. It iterates through each field using the fields’ conversion order attributes to determine the order in which the fields are converted. When using a field to set the value vector, the KP calls the conversion specified by the field’s conversion method attribute.
WARNING: The field conversion routines of a newly created packet format are set to “NONE”, which does nothing. Before calling this function, the required conversion routines must be set to either a user-supplied routine or one of the default routines provided with Riverbed Modeler (these are applicable only to a small subset of packet formats; see Chapter 5 “Packet Conversion” on page 29.
op_pk_fields_convert_to_vvec() passes four arguments to the field conversion method:
- a pointer to a packet
- a field index
- a value vector of type bit (Vvec_Vector)
- an index for the position of the field in the value vector. The Simulation Kernel calculates this position by using the bit sizes of the fields defined in the packet format.
Note: The Simulation Kernel may not always be able to calculate the exact position. In such cases, it passes OPC_FIELD_BIT_POSE_UNKNOWN constant to the conversion method.
The conversion method prototype is:
typedef int
default_convert_field_to_vvec (Packet * pkptr, int fd_index,
Vvec_Vector vvec, int pos)
This function must be in a .pff.c file named to match the base part of the function name. For example, a function named my_convert_field_to_vvec() should be defined in the file my_convert.pff.c.
Purpose
Provides a mechanism to iterate through a packet’s fields, calling each field’s conversion function to set values in a value vector.
Errors
- Program Abort: Packet pointer references unowned packet (
<pk_id>). - Program Abort: Packet format (
<packet_format>) does not support converison. - Program Abort: Packet ID (
<pk_id>) can not be converted. - Recoverable Error: Value vector is not owned by client.
- Recoverable Error: Value vector is invalid.
Reference
- Use the KP op_pk_type() to determine the type of a packet
- Use the KP op_pk_vvec_is_set() to see if a value vector packet contains a value vector
- Use the KP op_pk_convert_to_vvec() to convert a formatted packet to a value vector packet
- Use the KP op_pk_fields_convert_from_vvec() to use the field conversion orders and methods specified in the packet format when converting a value vector packet to a formatted packet