op_pk_fd_max_index()

Abstract

Provides the integer index which is the highest of any field defined in the specified packet.

Syntax

op_pk_fd_max_index (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

int

Integer value which is the maximum index of any field that currently is defined within the packet. The constant OPC_INT_INVALID will be returned for an unformatted packet that contains no fields.

Example

/* Obtain the newly arrived packet. */
pkptr = op_pk_get (op_intrpt_strm ());

/* Obtain the packet format name and verify that it is known */
op_pk_format (pkptr, format_name);
if (tp_verify_format (format_name) == OPC_FALSE)
	{
	/* Discard the packet since it is unrecognized. */
	op_pk_destroy (pkptr);
	}
else
	{
	/* Fields beyond TP_FD_INDEX_RTE_BASE are a record of the route travelled. */
	/* Determine how many hops there are. Include the base itself. */
	num_hops = op_pk_fd_max_index (pkptr) - TP_FD_INDEX_RTE_BASE + 1;

	/* Loop through the hops and update the local view of the nodes' conditions. */
	for (i = 0; i < num_hops; i++)
		{
		op_pk_fd_get (pkptr, TD_FD_INDEX_RTE_BASE + i, &node_id);
		...

Details

The behavior of this KP is straightforward for formatted packets that contain no "extended" fields (i.e., fields set beyond the last field in the packet's format); the value that is returned is one less than the number of fields defined by the format. This is true regardless of whether or not the formatted fields are set.

In the case of completely unformatted packets, or formatted packets that contain extended fields set via the KP op_pk_fd_set(), op_pk_fd_max_index() returns the index of the highest non-formatted field that is currently set; fields that were once set but have since been stripped via the KP op_pk_fd_strip() will not be considered.

Purpose

The value returned by this KP is typically used as an inclusive upper bound for a loop that operates on fields in a packet. This is most often used when there is no a priori knowledge of a packet's structure and each field must be examined to determine if it is set or if its contents are of interest.

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

本站文档由 北京智网畅联科技有限公司 整理、翻译并提供 · Documentation compiled and provided by Beijing ZNetLink Technology Co., Ltd.

交流群 · QQ Group:OPNET/智网妙算网络仿真交流群(群号 486383494)

原文档 © 2017 Riverbed Technology · 本站为公益翻译,由 AI 辅助完成,请仔细甄别

Original documentation © 2017 Riverbed Technology. Community translation, AI-assisted. Contact: jiazequn@znetlink.com