This topic contains further example that demonstrates the using Task/Function parameters and P4API parameter passing:

Suppose you have a PROIV Function that takes three parameters:

Name

Type

Size

Array/Number of Elements

Purpose

FParam1

Numeric

10

Scalar, not array

Account number

FParam2

Alpha

20

4 elements

Address lines

FParam3

Alpha

20

Scalar, not array

Name

Assume you define a Task with that function as the only member function. Corresponding Task parameters that match those function parameters could be:

Name

Type

Size

Array

T_Param1

N

10

<blank>

T_Param2

A

20

4

T_Param3

A

20

<blank>

If you want to invoke that task using P4API calls, you might send the following strings as the sParams parameter in a p4ExecTask() call:

Example 2A

Delimiter separated list stream format to invoke task with parameters using a comma as the delimiter (sParamFormat set to 'D,' in the p4ExecTask() call):

T_Param1=12345,T_Param2()=(1 Main Street,Anytown,Anywhere,AnyCountry),T_Param3=John Smith

Example 2B

Length-Prefixed Stream Format using same data.  As all elements of the Address array are being passed, the short form can be used.

<0x00><0x08>T_Param1<0x00><0x05>12345<0x00><0x0a>T_Param2()<0x00><0x04><0x00><0x30>
<0x00><0x0d>1 Main Street<0x00><0x07>Anytown<0x00><0x08>Anywhere
<0x00><0x0a>AnyCountry<0x00><0x08>T_Param3<0x00><0x0a>John Smith

Explanation

Section

Reason

<0x00><0x08>T_Param1

The number of bytes in the literal 'T_Param1 'is eight. Represented as two hex bytes with that value. Followed by the name of the Task parameter defined in the Task definition.

<0x00><0x05>12345

The number of bytes in the literal '12345' is five. Represented as two hex bytes with that value. Followed by the value of the T_Param1 parameter.

<0x00><0x0a>T_Param2()

The number of bytes in the literal 'T_Param2()' is ten. Represented as two hex bytes with that value. Followed by the name of the Task parameter defined in the Task definition.

<0x00><0x04>

The number of array elements being passed (four), represented as two hex bytes with that value.

<0x00><0x2e>

The number of bytes from this point (not including these two characters) to the end of the last T_Param2 data element. This totals 48 characters. Represent this total as two hex bytes. To accumulate the total, count 2 for these two hex bytes, add two for the length count of the first element (the two bytes <0x00> and <0x0d>), add thirteen for the number of bytes in the literal '1 Main Street', and so on, with the final accumulation being ten bytes for the literal 'AnyCountry'.

<0x00><0x0d>1 Main Street

Details of the first element of the T_Param2() array. The number of bytes in the literal '1 Main Street' is 13. Represented as two hex bytes with this value. Followed by the value of the first element.

<0x00><0x07>Anytown

Details of the second element of the T_Param2() array. The number of bytes in the literal 'Anytown' is seven. Represented as two hex bytes with this value. Followed by the value of the second element.

This sequence is repeated for the third and fourth elements of the T_Param2() array

 

<0x00><0x08>T_Param3

The number of bytes in the literal 'T_Param3' is eight. Represented as two hex bytes with that value. Followed by the name of the Task parameter defined in the Task definition.

<0x00><0x0a>John Smith

The number of bytes in the literal 'John Smith' is ten. Represented as two hex bytes with that value. Followed  by the value of the T_Param3 parameter

Example 2C

Length-Prefixed Stream Format using same data but with the fourth element of the Address not being sent. The short form can be used only if a null value is supplied for the fourth element:

<0x00><0x08>T_Param1<0x05>12345<0x00><0x0a>T_Param2()<0x00><0x04><0x00><0x24>
<0x00><0x0d>1 Main Street<0x00><0x07>Anytown<0x00><0x08>Anywhere
<0x00><0x00><0x00><0x0a>John Smith

Explanation

 The explanation for Example 2C is similar to the previous explanation, with these new elements:

Section

Reason

<0x00><0x04>

 

The number of elements in the array (four) being passed, expressed as two hex bytes with that value.

<0x00><0x24>

 

The count of bytes (36, in decimal) to the end of the last byte of the last element of the T_Param2() array, not including these two size bytes. Represented as two hex bytes with this value.

<0x00><0x00>

Shows that there is a parameter of zero length in that position. The last NUL character is the last byte of the last element in the T_Param2() array.

Example 2D

Length-Prefixed Stream Format using same data but with the fourth element of the Address not being sent.  The alternative to the stream shown in Example 2C is to pass name-and-value information for each element. Note this can be used to only send specific elements, leaving other, non-specified, elements set to null.

<0x00><0x08>T_Param1<0x05>12345<0x00><0x0b>T_Param2(1)
<0x00><0x0d>1 Main Street<0x00><0x0b>T_Param2(2)<0x00><0x07>Anytown
<0x00><0x0b>T_Param2(3)<0x00><0x08>Anywhere
<0x00><0x08>T_Param3<0x00><0x0a>John Smith

Example 2E

Delimiter separated list stream format using the same data, with parameters using a comma as the delimiter (sParamFormat set to 'D,' in the p4ExecTask() call):

T_Param1=12345,T_Param2(1)=1 Main Street,T_Param2(2)=Anytown,T_Param2(3)=Anywhere,
T_Param3=John Smith

Example 2F

Another way of doing Example 2E. As the T_Param2() elements being passed are consecutive elements beginning with the first, you can use:

T_Param1=12345,T_Param2()=(1 Main Street,Anytown,Anywhere),T_Param3=John Smith

And the fourth element will be set to null.

 

Comment on this topic

Topic ID: 540054