op_pk_total_size_get()
Abstract
Obtains the total size of the specified packet.
Syntax
op_pk_total_size_get (pkptr)
| 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().] |
Return Type
OpT_Packet_Size
Total size (in bits) of the specified packet.
Example
Excerpt from: example model (models/std/eth_net); process model (eth_mac); function block (eth_mac_llc_pk_accept()).
/* acquire the packet */
llc_pkptr = op_pk_get (HIGH_LAYER_INPUT_STREAM);
/* llc data larger than the maximum acceptable size will */
/* cause an error and the data will be discarded. */
if (op_pk_total_size_get (llc_pkptr) > MAX_DATA_SIZE)
{
/* compose and display the error message */
sprintf (err_str, "large packet with (%g) bits",
op_pk_total_size_get (llc_pkptr));
op_sim_message ("ethernet mac layer discarding excessively", err_str);
/* throw away the packet and return from invocation. */
op_pk_destroy (llc_pkptr);
FOUT
}
Details
A packet's total size is the sum of the bulk data size and the sizes of each of the set fields. The total size can be modified directly, by modifiying the bulk data size, by setting or unsetting the packet's fields, or by modifying the sizes of the packet's fields. Both unformatted and formatted packets can be operated on via this KP.
Purpose
Provides a mechanism to determine a packet's total size, which is useful for statistics gathering, resource allocation, or categorization of packets by size.
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.
Reference
- Use the KP op_pk_total_size_set() to assign a packet's total size
- Use the KP op_pk_bulk_size_set() to set only the bulk data size of a packet
- Use the KP op_pk_bulk_size_get() to obtain only the bulk data size of a packet
- Use the KP op_pk_fd_set() to modify the size of a field in an unformatted packet (and set its value)
- Use the KPs op_pk_fd_strip() or op_pk_nfd_strip() to strip off a field in a packet, thus eliminating its contribution to the total size of a packet