op_pk_copy()

Abstract

Creates a new packet that is a duplicate of a specified original packet.

Syntax

op_pk_copy (pkptr)
Argument Type Description
pkptr Packet* pointer to the original 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

Packet*

Pointer to the duplicate packet that is created by this KP.

Example

/* receive a frame from upper layer */
ul_pkptr = op_pk_get (0);

/* copy and send to all active network interfaces */
for (i = 0; i < num_interfaces; i++)
	{
	if (interface_array [i].active)
		{
		cp_pkptr = op_pk_copy (ul_pkptr);
		op_pk_send (cp_pkptr, i);
		}
	}

Details

This KP creates a new packet and copies the header of the specified original packet into the new packet. The new packet references the fields in the original packet. Later, if a field of either the original packet or the copy is to be changed, all of the packet fields are copied to the packet copy before the changes happen. (This approach to copying reduces simulation time and conserves memory.)

Both unformatted and formatted packets can be copied using this KP; the copied packet will have the same type as the original packet. Duplication of structure fields (OPC_FIELD_TYPE_STRUCT) uses the field’s associated allocation procedure, as specified by the KPs op_pk_fd_set() or op_pk_nfd_set(). Duplication of packet fields (OPC_FIELD_TYPE_PACKET) causes a recursive copy of the encapsulated packet. All other field types are copied as simple data items.

The copied packet is issued a unique packet ID, which corresponds to the next available ID when this KP is invoked. The packet’s creation time is set to the simulation time when this KP is invoked, and the creation module is set to the module running the process that called this KP (if the KP is not invoked by a process, or an indirect process function call, the creation module object ID is set to the constant OPC_OBJID_INVALID). The packet’s time stamp and module are copied from the original packet, so that the stamp “follows” the copied packet fields and only changes due to explicit calls to op_pk_stamp() (this policy allows stamps to be used for end-to-end transmission delay computations).

Any ICIs associated with the original packet are also associated with the copied packet (the ICI is not copied; instead, both packets have pointers to the same ICI). Routes associated with the original packet are copied and the copied route is associated with the copied packet.

Purpose

Provides a mechanism to clone packets for uses such as:

  • generating multiple transmissions of the same data in a packet-flooding procedure
  • saving a copy of an outgoing packet transmission in case retransmission is required later

Errors

  • Program Abort: Segmentation violation. (due to an invalid packet pointer, malformed packet, or malformed structure or packet field within the packet)
  • Program Abort: Bus Error. (due to an invalid address specified for the allocation procedure of a structure field contained within the packet)
  • Program Abort: Packet pointer is NIL.
  • Program Abort: Packet pointer references destroyed packet.
  • Program Abort: Packet pointer references unowned packet (<pk_id>).
  • Program Abort: Allocation of memory failed.

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