op_pk_format_print_proc_set()

Abstract

Associates a custom print procedure with the specified field for any formatted packet of the format specified.

Syntax

op_pk_format_print_proc_set (format_name, fd_name, print_proc)
Argument Type Description
format_name const char* Name of the packet format-of-interest.
fd_name const char* Name of the field-of-interest.
[This name should be a defined field within the packet’s format, with any field type except information.]
print_proc Procedure Print procedure; see Details for the prototype.

Return Type

Compcode

OPC_COMPCODE_SUCCESS if the print procedure was installed successfully; OPC_COMPCODE_FAILURE if an error occurred.

Example

/* Install a print procedure for the "address" field of all packet 																			*/
/* with the "data_req" packet format.																			*/
/* address_print_proc is defined in the function block as follows:																			*/
/*																			*/
/* void address_print_proc (void *structure_ptr, PrgT_List *dest_lptr)																			*/
/*		{																	*/
/*		char *char_line;																	*/
/*		ReqT_Address *addr_ptr;																	*/
/*																			*/
/*		addr_ptr = (ReqT_Address *) structure_ptr;																	*/
/*		char_line = op_prg_mem_alloc (sizeof (char) * 60);																	*/
/*		sprintf (char_line, "subnet: %d", addr_ptr->subnet);																	*/
/*		op_prg_list_insert (dest_lptr, char_line, OPC_LISTPOS_TAIL);																	*/
/*		char_line = op_prg_mem_alloc (sizeof (char) * 60);																	*/
/*		sprintf (char_line, "node : %s", addr_ptr->node_name);																	*/
/*		op_prg_list_insert (dest_lptr, char_line, OPC_LISTPOS_TAIL);																	*/
/*		}																	*/

op_pk_format_print_proc_set ("data_req", "address", address_print_proc)

Details

When the packet is printed (using pkprint in ODB or the op_pk_print() KP), the specified print_proc will be called by the Simulation Kernel to obtain custom text for the specified packet field.

The print_proc must have the following prototype:

void
Pk_Fd_Print_Proc (void *field_value_ptr, PrgT_List *dest_lptr);

The print_proc must add new entries to the PrgT_List *dest_lptr. Use prg_mem_alloc() to allocate strings for addition to the list. The Simulation Kernel deallocates all memory.

The contents of the field are passed in *field_value_ptr. This argument varies by data type:

Field Data Type *field_value_ptr Argument
int32, int64, double, pktid, objid address of the value (cast to appropriate type)
packet address of the packet
structure address of the structure

Purpose

Use this KP to specify a function to be called when the specified field of any packet with the specified packet format is printed by the ODB pkprint command or by the op_pk_print() KP. The field can be of any type except information. The print proc allows additional custom information about a field to be printed, in addition to the index, name, size, type, and value.

The print proc function can be useful if the field value is coded in some way. For example, if an int32 field contains information represented as a bitmap, the print proc can print a decoded version that makes debugging easier. The print proc also can be used for creating a textual representation of a data structure stored inside a structure type packet field. Such data structures can be complex, so a representation is useful in debugging.

Errors

  • Recoverable Error: No field named <field name> in format <format_name>.
  • Recoverable Error: Packet format <format_name> is unrecognized

Reference

  • Use the KP op_pk_create_fmt() to create a new formatted packet with the structure described by the specified packet format.
  • Use the KP op_pk_print() to print information (including the contents of packet fields and the values of field properties) about the specified packet to the standard output device

本站文档由 北京智网畅联科技有限公司 整理、翻译并提供 · 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