Skip to content

Commit

Permalink
Use Stratum device config binary format (#118)
Browse files Browse the repository at this point in the history
* Use Stratum device config binary format

* Simplify the pipeconf

 - Merge profiles for stratum_bf and stratum_bfrt

* remove device parameter from ptf_runner

* fix tests

* Apply suggestions from code review

Co-authored-by: Carmelo Cascone <carmelo@opennetworking.org>

* Minor cleanup to build.sh

* add pipeline config build image sha

* remove stratum_bf from pipeconf name

Co-authored-by: Carmelo Cascone <carmelo@opennetworking.org>
  • Loading branch information
Yi Tseng and ccascone committed Oct 23, 2020
1 parent 155c142 commit 5ab1073
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 235 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ constants:
docker run -v $(curr_dir):/root -w /root --rm \
--entrypoint ./util/gen-p4-constants.py onosproject/fabric-p4test:latest \
-o /root/src/main/java/org/stratumproject/fabric/tna/behaviour/P4InfoConstants.java \
p4info /root/src/main/resources/p4c-out/fabric-spgw-int/stratum_bf/mavericks_sde_9_2_0/p4info.txt
p4info /root/src/main/resources/p4c-out/fabric-spgw-int/mavericks_sde_9_2_0/p4info.txt

_mvn_package:
$(info *** Building ONOS app...)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ new Tofino-specific pipeconfs in the system, depending on the `fabric-tna.p4`
profiles compiled before and the Barefoot SDE/p4c version used:

```
New pipeconf registered: org.stratumproject.fabric.stratum_bfrt.mavericks_sde_9_2_0 (fingerprint=...)
New pipeconf registered: org.stratumproject.fabric.stratum_bfrt.montara_sde_9_2_0 (fingerprint=...)
New pipeconf registered: org.stratumproject.fabric.mavericks_sde_9_2_0 (fingerprint=...)
New pipeconf registered: org.stratumproject.fabric.montara_sde_9_2_0 (fingerprint=...)
...
```

Expand Down
43 changes: 17 additions & 26 deletions p4src/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
MAVERICKS_CPU_PORT=320
MONTARA_CPU_PORT=192
SDE_DOCKER_IMG=${SDE_DOCKER_IMG:-opennetworking/bf-sde:9.2.0}
PIPELINE_CONFIG_BUILDER_IMG=${PIPELINE_BUILD_IMG:-"stratumproject/stratum-bf-pipeline-builder@sha256:006db61b4c8797cc46f9008549b9d073ccfdc6c2e67641650fcb63afc318846a"}

# DIR is this file directory.
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
Expand Down Expand Up @@ -42,25 +43,31 @@ SDE_VER=$( ${P4C_CMD} --version | cut -d' ' -f2 )

# shellcheck disable=SC2086
function base_build() {
pltf="sde_${SDE_VER//./_}"
output_dir="${P4C_OUT}/sde_${SDE_VER//./_}"
echo "*** Compiling profile '${PROFILE}' for ${pltf}..."
echo "*** Output in ${P4C_OUT}/${pltf}"
echo "*** Output in ${output_dir}"
p4c_flags="--auto-init-metadata"
mkdir -p ${P4C_OUT}/${pltf}
mkdir -p ${output_dir}
(
$P4C_CMD --arch tna -g --create-graphs --verbose 2 \
-o ${P4C_OUT}/${pltf} -I ${P4_SRC_DIR} \
-o ${output_dir} -I ${P4_SRC_DIR} \
${pp_flags} ${OTHER_PP_FLAGS} \
${p4c_flags} \
--p4runtime-files ${P4C_OUT}/${pltf}/p4info.txt \
--p4runtime-files ${output_dir}/p4info.txt \
--p4runtime-force-std-externs \
${DIR}/fabric_tna.p4
)
# Adds register information to p4info file
# TODO: remove this part when compiler support it.
if [[ "$PROFILE" == *int ]]; then
$P4INFO_PATCH_SHELL "cat ${DIR}/p4info-register.txt >> ${P4C_OUT}/${pltf}/p4info.txt"
$P4INFO_PATCH_SHELL "cat ${DIR}/p4info-register.txt >> ${output_dir}/p4info.txt"
fi

# Generate the pipeline config binary
docker run --rm -v "${output_dir}:${output_dir}" -w "${output_dir}" \
${PIPELINE_CONFIG_BUILDER_IMG} \
-p4c_conf_file=./fabric_tna.conf \
-bf_pipeline_config_binary_file=./pipeline_config.pb.bin
}

# shellcheck disable=SC2086
Expand All @@ -70,26 +77,10 @@ function gen_profile() {
cpu_port=$2

# Copy only the relevant files to the pipeconf resources.
mkdir -p "${DEST_DIR}/stratum_bf/${pltf}/pipe"
mkdir -p "${DEST_DIR}/stratum_bfrt/${pltf}/pipe"
cp "${output_dir}/p4info.txt" "${DEST_DIR}/stratum_bf/${pltf}"
cp "${output_dir}/bfrt.json" "${DEST_DIR}/stratum_bf/${pltf}"
cp "${output_dir}/fabric_tna.conf" "${DEST_DIR}/stratum_bf/${pltf}"
cp "${output_dir}/pipe/context.json" "${DEST_DIR}/stratum_bf/${pltf}/pipe"
cp "${output_dir}/pipe/tofino.bin" "${DEST_DIR}/stratum_bf/${pltf}/pipe"
cp "${output_dir}/pipe/context.json" "${DEST_DIR}/stratum_bfrt/${pltf}/pipe/"
cp "${output_dir}/pipe/tofino.bin" "${DEST_DIR}/stratum_bfrt/${pltf}/pipe/"
echo "${cpu_port}" > "${DEST_DIR}/stratum_bf/${pltf}/cpu_port.txt"

# New pipeline format which uses tar ball
mkdir -p "${DEST_DIR}/stratum_bfrt/${pltf}"
tar cf "pipeline.tar.bz2" -C "${DEST_DIR}/stratum_bf/${pltf}" .
mv "pipeline.tar.bz2" "${DEST_DIR}/stratum_bfrt/${pltf}/"
cp "${output_dir}/p4info.txt" "${DEST_DIR}/stratum_bfrt/${pltf}/"
echo "${cpu_port}" > "${DEST_DIR}/stratum_bfrt/${pltf}/cpu_port.txt"

rm "${DEST_DIR}/stratum_bf/${pltf}/fabric_tna.conf"

mkdir -p "${DEST_DIR}/${pltf}"
cp "${output_dir}/p4info.txt" "${DEST_DIR}/${pltf}"
echo "${cpu_port}" > "${DEST_DIR}/${pltf}/cpu_port.txt"
cp "${output_dir}/pipeline_config.pb.bin" "${DEST_DIR}/${pltf}/"
echo
}

Expand Down
15 changes: 2 additions & 13 deletions ptf/run/tm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,12 @@
# SPDX-License-Identifier: Apache-2.0
# 320 cpu port is for mavericks (65Q)

DEVICE ?= stratum-bf

DEVICE_CONFIG_BF := --tofino-bin /p4c-out/pipe/tofino.bin --tofino-ctx-json /p4c-out/pipe/context.json
DEVICE_CONFIG_BFRT := --tofino-pipeline-tar /p4c-out/pipeline.tar.bz2

ifeq ($(DEVICE),stratum-bfrt)
config := $(DEVICE_CONFIG_BFRT)
else
config := $(DEVICE_CONFIG_BF)
endif

define run_tests
python -u ptf_runner.py --device $(DEVICE) --port-map port_map.veth.json \
python -u ptf_runner.py --port-map port_map.veth.json \
--ptf-dir fabric.ptf --cpu-port 320 --device-id 1 \
--grpc-addr "127.0.0.1:28000" \
--p4info /p4c-out/p4info.txt \
$(config) \
--tofino-pipeline-config /p4c-out/pipeline_config.pb.bin \
$(2)
endef

Expand Down
11 changes: 2 additions & 9 deletions ptf/run/tm/run
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fi

# Find Tofino compiled artifacts
sdeVer_=$(echo "${SDE_VERSION}" | tr . _) # Replace dots with underscores
P4C_OUT=${FABRIC_TNA}/src/main/resources/p4c-out/${fabricProfile}/stratum_bfrt/mavericks_sde_${sdeVer_}
P4C_OUT=${FABRIC_TNA}/src/main/resources/p4c-out/${fabricProfile}/mavericks_sde_${sdeVer_}
echo "*** Using P4 compiler output in ${P4C_OUT}..."

# Fix a name for each container so we can stop them
Expand Down Expand Up @@ -99,7 +99,7 @@ docker run --name ${tmRunName} -d -t --privileged \
"${SDE_DOCKER_IMG}"
sleep 5

# Run stratum_bf
# Run Stratum container
echo "*** Starting ${stratumBfRunName} (from ${STRATUM_BF_DOCKER_IMG})..."
docker run --name ${stratumBfRunName} -d --privileged \
--network "container:${tmRunName}" \
Expand All @@ -110,20 +110,13 @@ docker run --name ${stratumBfRunName} -d --privileged \
sleep 5
wait_for ${stratumBfRunName} 28000 600

testerDevice="stratum-bf"
if [[ "${STRATUM_BF_DOCKER_IMG}" == *"stratum-bfrt"* ]]; then
echo "*** Detected stratum-bfrt..."
testerDevice="stratum-bfrt"
fi

echo "*** Starting ${testerRunName}..."
# Do not attach stdin if running in an environment without it (e.g., Jenkins)
it=$(test -t 0 && echo "-it" || echo "-t")
docker run --name ${testerRunName} ${it} --privileged --rm \
--network "container:${tmRunName}" \
-v "${FP4TEST_ROOT}":/fabric-p4test \
-v "${P4C_OUT}":/p4c-out \
-e DEVICE=${testerDevice} \
-e PTF_FILTER=${PTF_FILTER} \
--entrypoint /fabric-p4test/run/tm/start_test.sh \
"${TESTER_DOCKER_IMG}" \
Expand Down
24 changes: 7 additions & 17 deletions ptf/run/tv/Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
# Copyright 2020-present Open Networking Foundation
# SPDX-License-Identifier: Apache-2.0

DEVICE ?= stratum-bf
PORTMAP ?= port_map.veth.json
GRPCADDR ?= 127.0.0.1:28000
CPUPORT ?= 320

DEVICE_CONFIG_BF := --tofino-bin /p4c-out/pipe/tofino.bin --tofino-ctx-json /p4c-out/pipe/context.json
DEVICE_CONFIG_BFRT := --tofino-pipeline-tar /p4c-out/pipeline.tar.bz2

ifeq ($(DEVICE),stratum-bfrt)
config := $(DEVICE_CONFIG_BFRT)
else
config := $(DEVICE_CONFIG_BF)
endif

define run_tests
python -u ptf_runner.py --device $(DEVICE) --port-map $(PORTMAP) \
--ptf-dir fabric.ptf --cpu-port $(CPUPORT) --device-id 1 \
--grpc-addr $(GRPCADDR) \
--p4info /p4c-out/p4info.txt \
$(config) \
--generate-tv \
$(2)
python -u ptf_runner.py --port-map $(PORTMAP) \
--ptf-dir fabric.ptf --cpu-port $(CPUPORT) --device-id 1 \
--grpc-addr $(GRPCADDR) \
--p4info /p4c-out/p4info.txt \
--tofino-pipeline-config /p4c-out/pipeline_config.pb.bin \
--generate-tv \
$(2)
endef

.DEFAULT_GOAL := all
Expand Down
8 changes: 4 additions & 4 deletions ptf/run/tv/run
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ fi

# Find Tofino compiled artifacts
sdeVer_=$(echo "${SDE_VERSION}" | tr . _) # Replace dots with underscores
#P4C_OUT=${FABRIC_TNA}/src/main/resources/p4c-out/${fabricProfile}/stratum_bfrt/montara_sde_${sdeVer_}
P4C_OUT=${FABRIC_TNA}/src/main/resources/p4c-out/${fabricProfile}/stratum_bfrt/mavericks_sde_${sdeVer_}
#P4C_OUT=${FABRIC_TNA}/src/main/resources/p4c-out/${fabricProfile}/montara_sde_${sdeVer_}
P4C_OUT=${FABRIC_TNA}/src/main/resources/p4c-out/${fabricProfile}/mavericks_sde_${sdeVer_}

echo "*** Using P4 compiler output in ${P4C_OUT}..."
if [ ! -f "${P4C_OUT}"/pipe/tofino.bin ]; then
echo "ERROR: missing tofino.bin in ${P4C_OUT}"
if [ ! -f "${P4C_OUT}"/pipeline_config.pb.bin ]; then
echo "ERROR: missing pipeline_config.pb.bin in ${P4C_OUT}"
exit 1
fi

Expand Down
7 changes: 0 additions & 7 deletions ptf/tests/ptf/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,6 @@ def setUp(self):
if self.cpu_port is None:
self.fail("CPU port is not set")

self.device = testutils.test_param_get("device")
if self.device is None:
self.fail("Device is not set")

pltfm = testutils.test_param_get("pltfm")
if pltfm is not None and pltfm == 'hw' and getattr(self, "_skip_on_hw", False):
raise SkipTest("Skipping test in HW")
Expand Down Expand Up @@ -239,9 +235,6 @@ def setUp(self):
self.stub = p4runtime_pb2_grpc.P4RuntimeStub(self.channel)
self.set_up_stream()

def is_bmv2(self):
return self.device is "bmv2"

# In order to make writing tests easier, we accept any suffix that uniquely
# identifies the object among p4info objects of the same type.
def import_p4info_names(self):
Expand Down
Loading

0 comments on commit 5ab1073

Please sign in to comment.