op_pk_fd_size()
Abstract
Obtains the modeled size of a field in the specified packet; the field-of-interest is specified by a numeric index.
Syntax
op_pk_fd_size (pkptr, fd_index)
| Argument | Type | Description |
|---|---|---|
pkptr |
Packet* |
pointer to the packet-of-interest [A pointer to a packet can be obtained from many KPs, including op_pk_create(), op_pk_create_fmt(), op_pk_copy(), op_pk_get(), op_subq_pk_access(), and op_subq_pk_remove().] |
fd_index |
int |
numeric index of the field-of-interest [This value should be non-negative; however, no error will occur if it is not. Instead, the value OPC_FIELD_SIZE_INVALID will be returned indicating the specified field is not defined in the packet.] |
Return Type
OpT_Packet_Size
Modeled size of the specified field (in bits).
This value is set to OPC_FIELD_SIZE_INVALID if the specified field is not defined in the packet or if a recoverable error occurs.
Example
/* obtain an arriving packet */
pkptr = op_pk_get (0);
/* determine the size of the information field */
data_size = op_pk_fd_size (pkptr, 2);
/* write the data size out as a statistic */
op_stat_write (0, (double) data_size);
/* deallocate the packet */
op_pk_destroy (pkptr);
Details
Returns the size of the specified field, as it was last set via the size argument of the KPs op_pk_fd_set() or op_pk_nfd_set(), or as it was created by the KP op_pk_create_fmt().
Purpose
Provides a mechanism to determine the modeled size of a packet field. This is typically useful when an information field has a variable size, and its size is of interest in computing traffic statistics (as in the example on the previous page). This KP is usually applied to unformatted packets, but it can be applied to formatted packets as well (formatted packet field names may be converted into numeric indices using the KP op_pk_nfd_name_to_index()).
Errors
- Program Abort: Segmentation violation. (due to an invalid packet pointer or malformed packet)
- Program Abort: Packet pointer is NIL.
- Program Abort: Packet pointer references destroyed packet.
- Recoverable Error: No field with index (
<fd_index>) in packet (<pk_id>). - Recoverable Error: Field index (
<fd_index>) is out-of-range for packet (<pk_id>).
Reference
- Use the KP
op_pk_nfd_size()to determine the size of a field in a formatted packet, utilizing a name to specify the field-of-interest - Use the KP
op_pk_fd_type()to determine the type of a packet field - Use the KP
op_pk_fd_is_set()to determine if a packet field is set - Use the KP
op_pk_total_size_get()to determine the total size of a packet - Use the KP
op_pk_bulk_size_get()to determine the bulk data size of a packet