Behavioral Model Use Case - 2022.2 English

Vitis Networking P4 User Guide (UG1308)

Document ID
UG1308
Version
2022.2 English
Revision

To verify the functionality of a P4 program <testname>.p4 (along with input packet data <packetname>_in.pcap|user) using the behavioral model, complete the following steps:

  1. Compile the P4 program using p4c-vitisnet. This generates a JSON file that can be used in the behavioral model:

    p4c-vitisnet <testname>.p4 -o <json_name>.json

  2. Create a <testcase>.txt text file containing a command to run the traffic data, ensuring that the input packet data file follows the <name>_in.pcap|user naming convention. If there are any tables in the P4 program, the table entries should be added to this testcase file (before the run_traffic command):

    echo "run_traffic <packetname>" > <testcase>.txt

    The format of a table_add command looks as follows:

    table_add <table_name> <action_name> <key0> <key1> <key2>... => <response0> <response1>...

    For example:

    table_add FiveTuple InsertVLAN 0x6e39cb7c 0x945e726d 0x06 0xc4aa 0x8ca2 => 0x3 0x1 0x060
  3. Run the run-p4bm-vitisnet application to generate outputs from the model:

    run-p4bm-vitisnet -j <json_name>.json -s <testcase>.txt

Both the compiler and the behavioral model CLI programs need to be executed from within a Vivado context. The following example illustrates this using the supplied FiveTuple example design with the command:

vivado -mode batch -source cli_example.tcl

where the TCL script cli_example.tcl is:
exec p4c-vitisnet $::env(XILINX_VIVADO)/data/ip/xilinx/vitis_net_p4_v1_0/example_design/examples/five_tuple/fiveTuple.p4 -o cli_example.json

exec cp $::env(XILINX_VIVADO)/data/ip/xilinx/vitis_net_p4_v1_0/example_design/examples/five_tuple/traffic_in.user .

exec run-p4bm-vitisnet -p 9091 -s $::env(XILINX_VIVADO)/data/ip/xilinx/vitis_net_p4_v1_0/example_design/examples/five_tuple/cli_commands.txt -j cli_example.json

exec ls -l traffic_out.user traffic_out.meta