p4 spec v1.1 (1185620), страница 10
Текст из файла (страница 10)
Not all targets may support all primitive actions. Target switches may have limits on when variables are bound and whatcombinations of parameter types are allowed.Here is a brief summary of primitive actions. More detailed documentation is below.5210.1 Primitive Actions10 ACTIONSprimitive nameadd_headercopy_headerremove_headermodify_fieldmodify_field_with_hash_based_offsettruncatedropno_oppushpopcountmetergenerate_digestresubmitrecirculateclone_ingress_pkt_to_ingressclone_egress_pkt_to_ingressclone_ingress_pkt_to_egressclone_egress_pkt_to_egressSummaryAdd a header to the packet’s Parsed RepresentationCopy one header instance to another.Mark a header instance as invalid.Set the value of a field in the packet’s ParsedRepresentation.Apply a field list calculation and use the result to generate an offset value.Truncate the packet on egress.Drop a packet (in the egress pipeline).Placeholder action with no effect.Push all header instances in an array downand add a new header at the top.Pop header instances from the top of an array, moving all subsequent array elementsup.Update a counter.Execute a meter operation.Generate a packet digest and send to a receiver.Resubmit the original packet to the parserwith metadata.Resubmit the packet after all egress modifications.Send a copy of the original packet to theparser.
Alias: clone_i2i.Send a copy of the egress packet to theparser. Alias: clone_e2i.Send a copy of the original packet to theBuffer Mechanism. Alias: clone_i2e.Send a copy of the egress packet to theBuffer Mechanism. Alias: clone_e2e.Table 13: Primitive ActionsParameters of the primitive actions are typed as follows:5310.1 Primitive ActionsNotationHDRARRFLDFLDLISTVALC-REFM-REFR-REFFLC-REF10 ACTIONSType DescriptionThe literal name of a header instance.The name of a header instance array, with no subscript.A field reference of form header_instance.field_name whichrefers to the Parsed Representation.A field list instance declared with field_list.An immediate value or a value from a table entry’s action parameters. The latter is represented as a parameter from theenclosing function (see examples below).The name of a counter array; determined at compile time.The name of a meter array; determined at compile time.The name of a register array; determined at compile time.Field list calculation reference; determined at compile time.Table 14: Action Parameter TypesHere is the API specification for standard primitive actions.add_header(header_instance)SummaryAdd a header to the packet’s Parsed RepresentationParametersheader_(HDR) The name of the header instance to add.instanceDescriptionIf the header_instance is not an element in a header stack, the indicatedheader instance is set valid.
If the header instance was invalid, all itsfields are initialized to 0. If the header instance is already valid, it is notchanged.If header_instance is an element in a header stack, the effect is to pusha new header into the stack at the indicated location. Any existing validinstances from the given index or higher are copied to the next higherindex. The given instance is set to valid.
If the array is fully populatedwhen this operation is executed, then no change is made to the ParsedRepresentation.5410.1 Primitive Actions10 ACTIONScopy_header(destination, source)SummaryCopy one header instance to another.Parametersdestination(HDR) The name of the destination header instance.source(HDR) The name of the source header instance.DescriptionCopy all the field values from the source header instance into the destination header instance. If the source header instance was invalid, thedestination header instance becomes invalid; otherwise the destinationwill be valid after the operation.
The source and destination instancesmust be of the same type.remove_header(header_instance)SummaryMark a header instance as invalid.Parametersheader_(HDR) The name of the header instance to remove.instanceDescriptionIf the header_instance is not an element in a header stack, then theindicated header instance is marked invalid. It will not be available formatching in subsequent match+action stages. The header will not be serialized on egress.
All field values in the header instance become uninitialized.If the header_instance is an element in a header stack, the effect is topop the indicated element from the stack. Any valid instances in thestack at higher indices are copied to the next lower index.5510.1 Primitive Actions10 ACTIONSmodify_field(dest, value [, mask] )SummarySet the value of the given field in packet’s Parsed RepresentationParametersdest(FLD or R-REF) The name of the field instance tomodify (destination).value(VAL, FLD or R-REF) The value to use (source).mask(VAL) An optional mask to use identifying the bits tochange.DescriptionUpdate the indicated field’s value.
The value parameter may be any of:• An immediate value (a number).• A value from the matching entry’s action parameter data; in thiscase, the name of a parameter from the enclosing function is used.• A Parsed Representation field reference.• A register reference.This allows the programmer to copy one field to another. An implicitcast is inserted by the compiler if the types of the source and destinationdiffer, as described in Section 2.4.If the parent header instance of dest is not valid, the action has no effect.
If value is a field reference and its parent header is not valid, theoperation has no effect.If mask is specified, then the field becomes (current_value & ∼ mask)| (value & mask). If mask is not specified, the operation has the effectof a "set", modifying all bits of the destination.5610.1 Primitive Actions10 ACTIONSmodify_field_with_hash_based_offset(dest, base, field_list_calc, size)SummaryAdd a value to a field.Parametersdest(FLD or R-REF) The name of the field instance to bemodified (destination)base(VAL) The base value to use for the index.field_list_(FLC-REF) The field list calculation to use to generatecalcthe hash value.size(VAL) The maximum value to use for the index if > 0.DescriptionThe field list calculation is executed to generate a hash value. If size isnot zero, the hash value is used to generate a value between base and(base + size - 1) by calculating (base + (hash_value % size)).If size is 0 then the value used is (base + hash_value).Normal value conversion takes place when setting dest to the result.truncate(length)SummaryTruncate the packet on egress.Parameterslength(VAL) The number of bytes to transmit.DescriptionIndicate that the packet should be truncated on egress.
The number ofbytes to transmit from the packet is indicated in the parameter to theaction. If the packet has fewer bytes than length, then it will not bechanged.Normally this action would be specified on the egress pipeline, thoughthis is not required.5710.1 Primitive Actions10 ACTIONSdrop()SummaryDrop the packet on egress.DescriptionIndicate that the packet should not be transmitted.
This primitive is intended for the egress pipeline where it is the only way to indicate that thepacket should not be transmitted. On the ingress pipeline, this primitiveis equivalent to setting the egress_spec metadata to a drop value (specific to the target).If executed on the ingress pipeline, the packet will continue throughthe end of the pipeline. A subsequent table may change the value ofegress_spec which will override the drop action. The action cannot beoverridden in the egress pipeline.no_op()SummaryTake no action.DescriptionThis indicates that no action should be taken on the packet.
Controlflow continues as per the current control function specification.push(array [, count])SummaryPush all header instances in an array down and add a new header at thetop.Parametersarray(ARR) The name of the instance array to be modified.count(VAL) An optional value indicating the number of elements to push, by default 1.DescriptionThis primitive is used to make room for a new element in an array ofheader instances without knowing in advance how many elements arealready valid. An element at index N will be moved to index N+1, andthe element at index 0 will be zeroed out and set valid.If a count is specified, elements will be shifted by count instead of 1 andcount header instances will be zeroed and set valid.This primitive leaves the array’s size constant; if an array is already full,elements pushed to indices beyond the static array size will be lost.5810.1 Primitive Actions10 ACTIONSpop(array [, count])SummaryPop header instances from the top of an array, moving all subsequentarray elements up.Parametersarray(ARR) The name of the instance array to be modified.count(VAL) An optional value indicating the number of elements to pop, by default 1.DescriptionThis primitive is used to remove elements from an array of header instances without knowing in advance how many elements are alreadyvalid.