其他分享
首页 > 其他分享> > 001

001

作者:互联网

Barefoot Networks Software Development Environment
(c) Barefoot Networks Inc, 2019

Table of contents
1. Introduction
2. Building SDE
2.1 Building SDE using P4 Studio Build tool
2.1.1 Building SDE packages required for P4-14 development
2.1.2 Building SDE packages required for P4-16 development
2.1.3 Building SDE packages for switch.p4-16 application
2.1.4 Building SDE packages for Tofino diagnostics application
2.1.5 Building all commonly used SDE packages
2.1.6 Customized building of SDE packages
2.2 Building SDE components individually
2.2.1 Minimum requirements for building BF-SDE packages
2.2.2 Extracting the BF-SDE Packages
2.2.3 Directory for installing package artifacts
2.2.4 Order of building packages
3. Exercising PTF Tests
3.1 Exercising PTF Tests for P4 programs using Tofino model
3.1.1 Loading P4 programs on the Tofino model
3.1.2 Running PTF Tests associated with P4 programs

  1. Introduction

The Barefoot Networks Software Development Environment (BF-SDE) is made
available in the form of tarball packages. Each package is versioned as
<major_version>.<medium_version>.<minor_version>

The SDE can be built for a target environment (OS and CPU architecture)
depending on the use-case.

The use-cases can vary from:
- Evaluate Tofino and provided P4 programs with Tofino model
- Evaluate Tofino and provided P4 programs on hardware
- Develop P4 programs and the associated control plane for these programs
using SDE
- Leverage Barefoot provided 'switch.p4' program included along with the
SDE for deployment or for integration with Network Operating System (NOS)

Building the needed components will require additional 3rd party packages that
would need to be downloaded and installed to resolve required dependencies.

  1. Building SDE

Barefoot SDE includes an easy to use 'P4 Studio Build' tool that streamlines
building various required components. Use of this tool is highly encouraged
to build SDE components.

Please refer to the SDE Release notes for the supported Operating Systems
distributions and CPU architectures.

2.1 Building SDE using P4 Studio Build tool

P4 Studio Build is a tool that helps users to install dependencies, build and
install all the required components of SDE and included example P4 programs.

The root directory of the extracted BF-SDE is referred to as $SDE. Set the SDE
environment variable. [The following commands are provided for bash syntax]
export SDE=/path/to/extracted/dir

P4 Studio Build tool is located at the top-level in SDE:
cd $SDE/p4studio_build

p4studio_build is a Python based tool and requires Python 2.7 to be installed
prior to invocation.

p4studio_build can be invoked in the following modes:

- Interactive mode (default)
  In this mode, the tool interactively takes input about the use case and
  creates a build profile for building and installing SDE components
  relevant to the use case.

- Profile mode
  In the profile mode, the P4 Studio Build tool builds the SDE based on a
  build profile, either pre-defined or one created by the user. A build
  profile contains information about which components of the SDE to build
  and any additional parameters that are required to build the components.
  For more details, please refer to the README file under p4studio_build
  directory

- Command line mode
  In the command line mode, the P4 Studio Build tool builds the SDE based on
  the arguments provided by the user. For more details, please refer to the
  README file under p4studio_build directory

Sections 2.1.1 through 2.1.7 describe building SDE for common use cases by
engaging pre-defined p4studio_build profiles

2.1.1 Building SDE packages required for P4-14 development

For building SDE packages required for P4-14 development with examples use the
pre-defined 'p414_examples_profile' option

cd $SDE/p4studio_build
./p4studio_build.py --use-profile p414_examples_profile

2.1.2 Building SDE packages required for P4-16 development

For building SDE packages required for P4-16 development with examples use the
pre-defined 'p416_examples_profile' option

cd $SDE/p4studio_build
./p4studio_build.py --use-profile p416_examples_profile

2.1.3 Building SDE packages for switch.p4-16 application

package included in BF-SDE is a P4-16 based networking application
stack providing commonly used networking features. To build SDE packages for
the switch.p4-16 application, use the pre-defined 'switch_p416_profile' option

cd $SDE/p4studio_build
./p4studio_build.py --use-profile switch_p416_profile

2.1.4 Building SDE packages for Tofino diagnostics application

package included in BF-SDE provides with commonly used diagnostic
functions for Tofino based systems. For building related SDE packages
use the pre-defined 'diags_profile' option

cd $SDE/p4studio_build
./p4studio_build.py --use-profile diags_profile

2.1.5 Building all commonly used SDE packages

To build all the commonly used packages of the SDE for Tofino (including
switch.p4-16 application) use the pre-defined 'all_profile' option
cd $SDE/p4studio_build
./p4studio_build.py --use-profile all_profile

2.1.6 Customized building of SDE packages

If you would like to customize SDE packages to be built, please refer to
$SDE/p4studio_build/README for instructions on using the interactive mode to
create a customized build profile for p4studio_build.

2.2 Building SDE components individually

Barefoot SDE contains following packages tarballs and each package uses the
following name format:
.<major_version>.<medium_version>.<minor_version>.tgz

+-----------------------------------+--------------------------------+
|   Tarball Package                 |  Description                   |
+-----------------------------------+--------------------------------+
| bf-sde-<maj>.<med>.<min>.tgz      | All component tarball packages |
+-----------------------------------+--------------------------------+
| bf-diags-<maj>.<med>.<min>.tgz    | Barefoot diagnostics           |
+-----------------------------------+--------------------------------+
| bf-drivers-<maj>.<med>.<min>.tgz  | Barefoot Networks hardware     |
|                                   | device drivers                 |
+-----------------------------------+--------------------------------+
| bf-syslibs-<maj>.<med>.<min>.tgz  | System abstraction libraries   |
+-----------------------------------+--------------------------------+
| bf-utils-<maj>.<med>.<min>.tgz    | Utility modules used by        |
|                                   | SDE code                       |
+-----------------------------------+--------------------------------+
| p4-build-<maj>.<med>.<min>.tgz    | Building P4 programs           |
+-----------------------------------+--------------------------------+
| p4-compilers-<maj>.<med>.<min>.tgz| P4 compilers                   |
+-----------------------------------+--------------------------------+
| p4-examples-<maj>.<med>.<min>.tgz | Example P4 programs and        |
|                                   | corresponding PTF tests        |
+-----------------------------------+--------------------------------+
| p4-hlir-<maj>.<med>.<min>.tgz     | P4-High-Level-Intermediate-    |
|                                   | Representation (HLIR)          |
+-----------------------------------+--------------------------------+
| p4i-<maj>.<med>.<min>.tgz         | P4 Insight                     |
+-----------------------------------+--------------------------------+
| ptf-modules-<maj>.<med>.<min>.tgz | Packet Test Framework (PTF)    |
|                                   | modules                        |
+-----------------------------------+--------------------------------+
| switch-p4-16-<maj>.<med>.<min>.tgz| Switching P4-16 programs and   |
|                                   | libraries                      |
+-----------------------------------+--------------------------------+
| tofino-model-<maj>.<med>.<min>.tgz| Software models of the Tofino  |
|                                   | P4 device                      |
+-----------------------------------+--------------------------------+

2.2.1 Minimum requirements for building BF-SDE packages

BF-SDE packages are built using GNU Autotools. The following list is the
minimum list of tools that need to be installed before proceeding with
building the BF-SDE packages

- autoconf
- libtool
- make
- g++
- glibc dev
- python-setuptools

Individual packages may have additional requirements other than the above
listed ones, depending on the options used to build.

2.2.2 Extracting the BF-SDE Packages

Unpack the tarball
tar xzvf bf-sde-...tgz

Set the SDE environment variable
export SDE=

Extract all the packages of
cd $SDE
./extract_all.sh

This will extract all the package sources and install them in $SDE as
<package_name>-...
Please refer to $SDE/bf-sde-...manifest file for the version
numbers of each of the package. Instructions on building the sources in each
installed directory is provided in the section below.

Each of the packaged modules includes a README file listing

2.2.3 Directory for installing package artifacts

To install BF-SDE package artifacts (header files, libraries, binaries, data
files), it is recommended the install directory be set as
export SDE_INSTALL=$SDE/install

This helps artifacts of all BF-SDE packages to be installed within $SDE
location

Binary packages contain executables that need to be copied over to
\(SDE_INSTALL/bin for completeness. Setting PATH as below ensures the required executables needed for the further building of packages will be picked up from the SDE's install directory export PATH=\)SDE_INSTALL/bin:$PATH

2.2.4 Order of building packages

Each of the packages needs to be individually built. Each package contains a
README file that describes the steps to build and install its artifacts. Some
packages produce header files that are needed to build other packages. This
introduces ordering requirements for building the packages. The build and
install order priorities for packages are listed below as P1, P2, etc.

#
# Building for Barefoot HW targets
#
P1: Install binary package executables to $SDE_INSTALL/bin
   
P2: Build and install $SDE/bf-syslibs-<maj>.<med>.<min>
P3: Build and install $SDE/bf-utils-<maj>.<med>.<min>
P4: Build and install $SDE/bf-drivers-<maj>.<med>.<min>
P5: Build and install BFN provide P4 applications
    $SDE/switch-p4-16-<maj>.<med>.<min> OR $SDE/bf-diags-<maj>.<med>.<min>
P5: Build and install any P4 program using $SDE/p4-build-<maj>.<med>.<min>
P6: Build and install $SDE/p4-examples-<maj>.<med>.<min>
P6: Build and install $SDE/ptf-modules-<maj>.<med>.<min>

#
# Build P4 HLIR tools
#
P1: Build and install $SDE/p4-hlir-<maj>.<med>.<min>
  1. Exercising PTF Tests

Once all the packages have been built and their artifacts installed (through
either the 'P4 Studio Build tool' (Refer 2.1) or individually (Section 2.2),
they can be exercised using PTF tests.

The following steps are pre-requisite for exercising PTF tests

-Install packages needed for PTF testing.
 [skip if P4 Studio Build" is used for compile SDE]

- PTF uses virtual ethernet interfaces for sending/receving packets.
  veth interfaces are to be setup as follows
    sudo $SDE_INSTALL/bin/veth_setup.sh

3.1 Exercising PTF Tests using Tofino model

Once all the packages have been built and their artifacts installed, they can
be exercised using PTF tests.

There are three parts to exercising PTF test against Tofino model

- Start the Tofino model
- Start the 'bf_switchd' application
- Running the PTF tests associated with the P4 program

Ensure the PATH variables are set to include \(SDE_INSTALL directory export PATH=\)SDE_INSTALL/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/lib:
\(SDE_INSTALL/lib:\)LD_LIBRARY_PATH

3.1.1. Loading P4 programs on the Tofino model

Change to SDE base directory

cd $SDE

Launch the Tofino model program

sudo env "PATH=$PATH" tofino-model \
        [-f $SDE/<p4-examples/ptf-tests/<p4_program_name>/ports.json]

# A convenience script that does the same as above.  The script will allow
# the model to instantiate either a Tofino or Tofino2 chip, the default is
# Tofino.
$SDE/run_tofino_model.sh \
          -p <p4_program_name> --arch <chip architecture>
Examples:
./run_tofino_model.sh -p basic_ipv4
./run_tofino_model.sh -p switch

Start the 'bf_switchd' application program

 sudo env "PATH=$PATH" "LD_LIBRARY_PATH=$LD_LIBRARY_PATH"    \
        bf_switchd --conf-file \
        $SDE_INSTALL/share/p4/targets/<chip_arch>/<p4_program_name>.conf

# A convenience script that does the same as above.  Note the -p option
# will find a conf file based on the program name, since the same name may
# exist in multiple chip_arch directories the --arch option should be used
# with the -p option
 $SDE/run_switchd.sh -p <p4_program_name>
Examples:
 ./run_switchd.sh -p basic_ipv4
 ./run_switchd.sh -c $SDE_INSTALL/share/p4/targets/tofino/switch.conf

# starting bf_switchd for switch.p4-16
# Switch API
 ./run_switchd.sh -p switch

# Switch API for Tofino2
 ./run_switchd.sh -p switch --arch tofino2

# Switch SAI OCP
 ./run_switchd.sh -c \
        $SDE_INSTALL/share/p4/targets/tofino/switch-sai-cpu-veth.conf

3.1.2 Running PTF tests associated with P4 programs

Run tests for an arbitraty P4 program in SDE/p4-examples

 sudo env "PATH=$PATH" python \
  $SDE_INSTALL/lib/python2.7/site-packages/p4testutils/run_ptf_tests.py \
  --test-dir $SDE/p4-examples/ptf-tests/<p4_program_name>

A convenience script that does the same as above

   $SDE/run_p4_tests.sh -p <p4_program_name>
  Examples:
   ./run_p4_tests.sh -p basic_ipv4
   ./run_p4_tests.sh -p basic_ipv4 -s test.TestAddRoute

Note: This convenience script assumes that tests to exercise are located
in:
   $SDE/p4-examples/ptf-tests/<p4_program_name>

When tests are in a different location, the test directory can be
explicitly specified by including an additional argument:
  -t <path_to_tests>

Exercising the packaged P4-16 examples requires specifying this extra test
directory argument.
  Example:
   ./run_p4_tests.sh -p tna_counter \
    -t pkgsrc/p4-examples/p4_16_programs/tna_counter \
    -s test.DirectCounterTest

Running switch.p4 tests from package

# Running PTF for tofino
 sudo env "PATH=$PATH" python \
  $SDE_INSTALL/lib/python2.7/site-packages/p4testutils/run_ptf_tests.py \
  --test-dir $SDE/<switch>/ptf-tests/base/api-tests --arch Tofino \
  --target asic-model

# Running PTF for tofino2
 sudo env "PATH=$PATH" python \
  $SDE_INSTALL/lib/python2.7/site-packages/p4testutils/run_ptf_tests.py \
  --test-dir $SDE/<switch>/ptf-tests/base/api-tests --arch Tofino2 \
  --target asic-model

A convenience script that does the same as above

 $SDE/run_p4_tests.sh -t $SDE/<switch>/ptf-tests/<test_dir>

  Examples:
  Run on Tofino:
   ./run_p4_tests.sh -t $SDE/<switch>/ptf/api -p switch
  Run on Tofino2:
   ./run_p4_tests.sh -t $SDE/<switch>/ptf/api -p switch --arch tofino2

   ./run_p4_tests.sh -t <switch>/ptf/sai -p switch
    --arch Tofino --target asic-model -s l2 -f <switch>/ptf/ports.json \
    --test-params "test_port=3;port_map_file=\
    '<switch>/ptf/sai/default_interface_to_front_map.ini'"

标签:tests,p4,P4,SDE,001,build,packages
来源: https://www.cnblogs.com/yuboyuan/p/14848020.html