op_pk_total_size_set()
Abstract
Sets the total size of the specified packet to the specified value (if this value is valid).
Syntax
op_pk_total_size_set (pkptr, total_size)
| 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().] |
total_size |
OpT_Packet_Size |
total size (in bits) to assign to the specified packet [This number must be positive or zero; otherwise an error will occur.] |
Return Type
Compcode
Completion code indicating if size modification was successful.
If successful, this KP returns the value OPC_COMPCODE_SUCCESS; OPC_COMPCODE_FAILURE otherwise.
Example
Excerpt from: example model (models/std/fddi); process model (fddi_gen); state (ARRIVAL); enter execs.
/* create a packet to send to mac */
pkptr = op_pk_create_fmt ("fddi_llc_fr");
/* assign its overall size. */
op_pk_total_size_set (pkptr, pklen);
/* assign the time of creation */
op_pk_nfd_set (pkptr, "cr_time", op_sim_time ());
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. When the total size is directly modified via this KP, the bulk data size is proportionally modified.
The total size of a packet can be modified or accessed at any time. Both unformatted and formatted packets can have their sizes set via this KP.
If the new total size is less than the sum of the field sizes, the bulk data size will be negative. Negative bulk data sizes are useful for representing compression techniques that reduce the amount of transmitted data.You can also use op_pk_bulk_size_set() to set the bulk data size to a negative number.
Note: Even if the bulk data size is negative, the total packet size must be positive or zero.
Purpose
Provides a mechanism to modify a packet's total size, which is typically useful when a packet should have a specific total size independent of the current sizes of its fields.
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.
- Program Abort: Packet pointer references unowned packet (
<pk_id>). - Recoverable Error: Total packet size (
<size>) is negative.
Reference
- Use the KP op_pk_total_size_get() to obtain 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