op_pk_nfd_size()
Abstract
Obtains the modeled size (in bits) of a field in the specified packet; the field-of-interest is specified by name.
Syntax
op_pk_nfd_size (pkptr, fd_name)
| 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_fmt(), op_pk_copy(), op_pk_get(), op_subq_pk_access(), and op_subq_pk_remove().] |
fd_name |
const char* |
name of the field-of-interest [This name should be a defined field within the packet's format; 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).
The constant value OPC_FIELD_SIZE_INVALID will be returned 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_nfd_size (pkptr, "info_fd");
/* 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 originally defined in the format of the packet, as it was last set using the KP op_pk_fd_set(), or in the case of packet fields, as it was taken from an encapsulated packet assigned via op_pk_nfd_set() or op_pk_fd_set().
Purpose
Provides a mechanism to determine the modeled size of a packet's 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 should only be applied to formatted packets; otherwise the returned size for any field name passed to this KP will be zero.
Errors
- Program Abort: Segmentation violation. (due to an invalid packet pointer or
fd_nameargument) - Program Abort: Packet pointer is NIL.
- Program Abort: Packet pointer references destroyed packet.
- Recoverable Error: No field named (<fd_name>) in packet (<pk_id>).
Reference
- Use the KP
op_pk_fd_size()to determine the size of a field in an unformatted (or formatted) packet, specifying the field by numeric index - Use the KP
op_pk_nfd_type()to determine the type of a packet field - Use the KP
op_pk_nfd_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