op_pk_type()
Abstract
Determines the type of a specified packet.
Syntax
op_pk_type (pk_ptr)
| Argument | Type | Description |
|---|---|---|
pk_ptr |
Packet* |
pointer to the packet of interest |
Return Type
int
Constant indicating whether the packet is formatted (OPC_PACKET_TYPE_FORMATTED), unformatted (OPC_PACKET_TYPE_UNFORMATTED), or value vector (OPC_PACKET_TYPE_VVEC).
Example
/* Access a value vector representation from a packet that */
/* might be an SAR segment, an opnet field packet, or an */
/* opnet value vector packet. */
if (op_sar_pk_is_segment (pkptr))
{
/* Access the value vector in this SAR segment. */
/* This value vector will be a duplicate of the */
/* contents of the SAR segment. */
op_pk_vvec_get (pkptr, &sar_vvec);
}
else
{
/* This packet is not a SAR segment, and therefore */
/* either contains fields, or contains a value vector. */
if (op_pk_type (pkptr) == OPC_PACKET_TYPE_VVEC)
{
/* Access the value vector in this packet */
...
}
else
{
/* This packet contains fields. */
/* Convert the packet to its value vector form */
...
}
}
Details
A formatted packet contains fields defined prior to a simulation using the Packet Editor. An unformatted packet’s fields are specified dynamically during a simulation. A value vector packet does not contain specified fields, but rather a value vector.
Note: If the packet passed to op_pk_type() is a Sar segment, the KP identifies it as an unformatted packet unless the segment has been converted to a value vector packet, in which case the KP identifies it as such.
Purpose
Provides a mechanism to identify a packet’s type.
Errors
- Program Abort: Segmentation violation. (due to an invalid or malformed packet)
- Program Abort: Packet pointer is NIL.
- Program Abort: Packet pointer references destroyed packet.
Reference
- Use the KP op_pk_create() to create an unformatted packet
- Use the KP op_pk_create_fmt() to create a formatted packet
- Use the KP op_pk_create_vvec() to create a value vector packet