Field Sub-Package

Packet fields contain single data elements of several possible types (integer, double, data structure, encapsulated packet, or information). Packet fields impose structure on the models of transmitted data, and support convenient access of flags and other information which will affect protocol or algorithm processing. In unformatted packets, fields are not predefined based on a packet format, but are dynamically defined through the assignment operation. Fields in unformatted packets are specified via a numeric field index, which starts at zero. All of the KPs in the Field sub-package have the prefix “op_pk_fd_” and, although primarily designed for unformatted packets, can also be applied to formatted packets.

The contents of fields depend on their designated type, but generic operators are provided for accessing them. The KP op_pk_fd_set() assigns the contents of a field, as well as the size of the field (measured in bits). The symmetric KP op_pk_fd_get() obtains the contents of a field. As a packet propagates through a network, and is repeatedly processed by different processes, its contents can change many times. The KP op_pk_fd_access_ptr() provides access to a data structure stored in a packet without removing the structure from the packet, and op_pk_fd_access_read_only_ptr() provides efficient read-only access to a structure field.

Both op_pk_fd_set() and op_pk_fd_get() have type-specific versions that are more efficient and allow the compiler to catch argument errors that are missed with the generic KPs. Table 9 lists these type-specific versions.

Table 9: Typed Packet Field Get/Set KPs

op_pk_fd_get_dbl() op_pk_fd_set_dbl()
op_pk_fd_get_int32() op_pk_fd_set_int32()
op_pk_fd_get_int64() op_pk_fd_set_int64()
op_pk_fd_get_objid() op_pk_fd_set_objid()
op_pk_fd_get_pkid() op_pk_fd_set_pkid()
op_pk_fd_get_pkt() op_pk_fd_set_pkt()
op_pk_fd_get_ptr() op_pk_fd_set_ptr()
op_pk_fd_set_info()

As fields are assigned via one of the op_pk_fd_set… KPs, their sizes are also set. If the size of a field changes as a packet is processed, the packet’s size can change. In order to determine the current size of a field, the KP op_pk_fd_size() can be used. If a particular field within a packet has completely lost its value, the field can be stripped, thus removing both its contents and its size from the affected packet. To strip a field, the KP op_pk_fd_strip() is used. The assignments of numeric indices to particular fields are not affected by the stripping operation; stripped fields are tagged as being unset, but they continue to occupy their index “slot”.

Packets of unknown structure can be manipulated by processes, but only if the packet structure can be dynamically determined. A KP introduced in the previous section, op_pk_fd_max_index(), returns the number of fields so that a process can loop through each field. The KP op_pk_fd_type() provides the “guts” of such a loop by determining the type of each field. A switch statement with appropriate cases can be framed around this KP. When a formatted packet of unknown structure is being processed, it is sometimes useful to obtain the name of each field, a service provided by the KP op_pk_fd_index_to_name().

Because unformatted packets do not have a predefined group of fields, any positive integer identifies a valid field. When a field has an assigned contents and bit size, it is considered to be set; undefined fields with no contents or size are unset. The KP op_pk_fd_is_set() can be used to determine if a field is set.