Table Example - 2022.2 English - UG1308

Vitis Networking P4 User Guide (UG1308)

Document ID
UG1308
Version
2022.2 English
Revision

This section summarizes the Target API functions to control a table P4 element. This example C program is based on the FiveTuple example design and is provided at the following location:

<project_name>/<project_name>.gen/sources_1/ip/<inst_name>/src/sw/drivers/target/examples/five_tuple_example.c

This program demonstrates target driver function calls to achieve the following functionality:

  • Initialize the driver using XilVitisNetP4TargetInit()
  • Obtain a handle for table using XilVitisNetP4TargetGetTableByName()
  • Obtain an action identifier using XilVitisNetP4TableGetActionId()
  • Perform the following table entry operations:
    • insert using XilVitisNetP4TableInsert()
    • update using XilVitisNetP4TableUpdate()
    • delete using XilVitisNetP4TableDelete()
  • Exit driver using XilVitisNetP4TargetExit()

The example application uses the packed byte arrays “FiveTupleKeyArray” and “FiveTupleActionParamsArray”. These arrays use a big-endian format and are packed in the order that they are declared in the P4 file. In the FiveTuple P4 file the table is defined as follows:

table FiveTuple {
        key            = { hdr.ipv4.src      : exact;
                           hdr.ipv4.dst      : exact;
	                       hdr.ipv4.protocol : exact;
	                       table_key_sport   : exact;
	                       table_key_dport   : exact; }
	actions        = { InsertVLAN; 
                       NoAction; }
	size           = 8192;
	default_action = NoAction;
    }

with the field sizes defined as follows:

• hdr.ipv4.src: 32-bit field

• hdr.ipv4.dst: 32-bit field

• hdr.ipv4.protocol: 8-bit field

• table_key_sport: 16-bit field

• table_dport: 16-bit field

The fields for each key in the “FiveTupleKeyArray” are ordered as shown in the following figure:

Figure 1. FiveTuple Key Packed Byte Array

In the example, all the keys result in a "InsertVLAN" action which is defined as follows:

action InsertVLAN(bit<3> pcp, bit<1> cfi, bit<12> vid)

resulting in a packed action parameter byte array ordered as shown in the following figure:

Figure 2. InsertVLAN Action Packed Byte Array