op_pk_nfd_set()
DEPRECATED—Use explicitly typed op_pk_nfd_set_<type>()
Abstract
Sets a predefined information field in the specified packet; the field-of-interest is specified by name.
Note: This format is used for information fields only. For other field types, use an alternate format (see the Purpose section for details).
Syntax
op_pk_nfd_set (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 must be a defined field within the packet's format, or an error will occur.] |
Return Type
Compcode
Completion code indicating if the specified field was successfully assigned a new value. OPC_COMPCODE_FAILURE will be returned if a recoverable error occurs.
Example
/* create a formatted packet */
f_pkptr = op_pk_create_fmt ("info_pkt");
/* assign an integer code to the packet */
op_pk_nfd_set (f_pkptr, "fd_type", DATA_XFER);
/* set the information field in the packet */
op_pk_nfd_set (f_pkptr, "fd_data");
/* send the defined packet out of the processor */
op_pk_send (f_pkptr, OUTSTRM);
Details
For the information field type, the actual values of the data modeled by the field are not relevant to the simulation, so only the size of the field is stored in the packet. This format of the op_pk_nfd_set() KP only performs the function of setting information fields within formatted packets, because the size of these fields is automatically predefined in the format. Changing the size of information fields in formatted packets cannot be performed by a direct KP call, but it can be achieved by:
- converting the field name into a field index using the KP op_pk_name_to_index() or op_pk_nfd_name_to_index()
- setting the size of the information field using the KP op_pk_fd_set()
Getting the value of an information field via the KP op_pk_nfd_get() does not have a valid purpose, but instead of causing an error, the string “unspecified” is copied into the passed value pointer.
Purpose
Provides a mechanism to set the size of an information field within a packet. Because the packet is formatted, the size of the information field (which would need to be specified to the unformatted version of this KP, op_pk_fd_set()), is automatically looked up in the format.
Note: This KP should be applied only to formatted packets; otherwise an error will occur.
This format of op_pk_nfd_set() supports only information field types, because no field value is specified. Alternate formats of this KP support integer, double, or packet field types (op_pk_nfd_set()) and structure field types (op_pk_nfd_set()).
A data-type-specific version of this KP exists. The alternate KP is more efficient than this variable argument version. In addition, it allows the compiler to catch argument errors that are missed with this KP. For details, refer to op_pk_nfd_set_info().
Errors
- Program Abort: Segmentation violation. (due to an invalid packet pointer or fd_name argument)
- Program Abort: Packet pointer is NIL.
- Program Abort: Packet pointer references destroyed packet.
- Program Abort: Packet pointer references unowned packet (
<pk_id>). - Recoverable Error: No field named (
<fd_name>) in packet (<pk_id>).
Reference
- Use the alternate formats of this KP to assign values to integer, double, packet, or structure fields of a packet
- Use one of the variants of the KP op_pk_fd_set() to assign the value of a field in a packet, specifying the field by numeric index
- Use one of the variants of the KP op_pk_nfd_strip() to unset a field within a packet, subtracting out its contribution to total packet size