Skip to content

Commit

Permalink
Add pipeline-tar support and restructure the repo (#1)
Browse files Browse the repository at this point in the history
 - add new device "stratum-bfrt" to PTF
 - restructure repo
   - move p4 source code to /p4src
   - new script to build pipeline tar
 - add new pipeconf for stratum_bfrt
   - Needs "RAW_DEVICE_CONFIG" extension support
- update PTF test script
- custom flags for stratum-bfrt docker container
- Use stratum-bfrt as the default stratum binary
  • Loading branch information
Yi Tseng committed Jun 10, 2020
1 parent c5ebac0 commit 8547b8c
Show file tree
Hide file tree
Showing 34 changed files with 1,867 additions and 54 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ onos_curl := curl --fail -sSL --user onos:rocks --noproxy localhost
pipeconf_app_name := org.stratumproject.fabric-tna
pipeconf_oar_file := $(shell ls -1 ${curr_dir}/target/fabric-tna-*.oar)

p4-build := ./src/main/p4/build.sh
p4-build := ./p4src/build.sh

.PHONY: pipeconf

Expand Down Expand Up @@ -81,5 +81,5 @@ clean:

deep-clean: clean
-rm -rf target
-rm -rf p4c-out
-rm -rf src/main/resources/p4c-out
-docker rm ${mvn_container} > /dev/null 2>&1
35 changes: 20 additions & 15 deletions src/main/p4/build.sh → p4src/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ SDE_DOCKER_IMG=${SDE_DOCKER_IMG:-opennetworking/bf-sde:9.2.0}

# DIR is this file directory.
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ROOT_DIR="$( cd "${DIR}/../../../" && pwd )"
ROOT_DIR="$( cd "${DIR}/../" && pwd )"

P4_SRC_DIR=${ROOT_DIR}/src/main/p4
P4_SRC_DIR=${ROOT_DIR}/p4src

set -e

Expand All @@ -19,10 +19,10 @@ OTHER_PP_FLAGS=$2

# PWD is the directory where this script is called from (should be the root of
# this repo).
P4C_OUT=${PWD}/tmp/${PROFILE}
P4C_OUT=${ROOT_DIR}/tmp/${PROFILE}

# Where the compiler output should be placed to be included in the pipeconf.
DEST_DIR=${DIR}/../resources/p4c-out/${PROFILE}/tofino
DEST_DIR=${ROOT_DIR}/src/main/resources/p4c-out/${PROFILE}


# If SDE_DOCKER_IMG env is set, use containerized version of the compiler
Expand All @@ -44,7 +44,6 @@ function do_p4c() {
p4c_flags="--auto-init-metadata"
mkdir -p ${P4C_OUT}/${pltf}
(
set -x
$P4C_CMD --arch tna -g --create-graphs --verbose 2 \
-o ${P4C_OUT}/${pltf} -I ${P4_SRC_DIR} \
${pp_flags} ${OTHER_PP_FLAGS} \
Expand All @@ -54,17 +53,23 @@ function do_p4c() {
${DIR}/fabric-tna.p4
)

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

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

echo
}

do_p4c "montara" ${MONTARA_CPU_PORT}
do_p4c "mavericks" ${MAVERICKS_CPU_PORT}

do_p4c "montara" "${MONTARA_CPU_PORT}"
do_p4c "mavericks" "${MAVERICKS_CPU_PORT}"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ SPDX-License-Identifier: Apache-2.0
<version>${onos.version}</version>
</dependency>

<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-protocols-p4runtime-model</artifactId>
<version>${onos.version}</version>
</dependency>

</dependencies>

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

DEVICE ?= tofino
DEVICE_CONFIG ?= "--tofino-bin /p4c-out/pipe/tofino.bin --tofino-ctx-json /p4c-out/pipe/context.json"

define run_tests
python -u ptf_runner.py --device tofino --port-map port_map.veth.json \
python -u ptf_runner.py --device $(DEVICE) --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 \
--tofino-bin /p4c-out/pipe/tofino.bin \
--tofino-ctx-json /p4c-out/pipe/context.json \
$(DEVICE_CONFIG) \
$(2)
endef

Expand Down
10 changes: 5 additions & 5 deletions ptf/run/tm/run
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ SDE_VERSION=${SDE_VERSION:-9.2.0}
# Use image sha to pin a specific stratum_bmv2 build and have reproducible runs.
# We could instrument CI to test on both a stable version and the latest one.
STRATUM_BF_DOCKER_IMG=${STRATUM_BF_DOCKER_IMG:-stratumproject/stratum-bf:9.2.0}
STRATUM_BF_DOCKER_FLAG=${STRATUM_BF_DOCKER_FLAG:-}

if [[ -z "${FABRIC_TNA}" ]]; then
echo "ERROR: FABRIC_TNA env not defined"
Expand Down Expand Up @@ -57,12 +58,8 @@ fi

# Find Tofino compiled artifacts
sdeVer_=$(echo "${SDE_VERSION}" | tr . _) # Replace dots with underscores
P4C_OUT=${FABRIC_TNA}/src/main/resources/p4c-out/${fabricProfile}/tofino/mavericks_sde_${sdeVer_}
P4C_OUT=${FABRIC_TNA}/src/main/resources/p4c-out/${fabricProfile}/stratum_bfrt/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}"
exit 1
fi

# Fix a name for each container so we can stop them
randomNum=${RANDOM}
Expand Down Expand Up @@ -108,6 +105,7 @@ docker run --name ${stratumBfRunName} -d --privileged \
--network "container:${tmRunName}" \
-v "${DIR}":/workdir -w /workdir \
--entrypoint ./stratum_entrypoint.sh \
${STRATUM_BF_DOCKER_FLAG} \
"${STRATUM_BF_DOCKER_IMG}"
sleep 5
wait_for ${stratumBfRunName} 28000 60
Expand All @@ -117,6 +115,8 @@ docker run --name ${testerRunName} -it --privileged --rm \
--network "container:${tmRunName}" \
-v "${FP4TEST_ROOT}":/fabric-p4test \
-v "${P4C_OUT}":/p4c-out \
-e DEVICE=stratum-bfrt \
-e "DEVICE_CONFIG=--tofino-pipeline-tar /p4c-out/pipeline.tar.bz2" \
--entrypoint /fabric-p4test/run/tm/start_test.sh \
"${FP4TEST_DOCKER_IMG}" \
${@}
2 changes: 1 addition & 1 deletion ptf/run/tm/stratum_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mount -t hugetlbfs nodev /mnt/huge
# Log files will be copied out of this container once stopped (see run.)
mkdir /tmp/workdir
cd /tmp/workdir
stratum_bf \
/usr/bin/stratum_bfrt \
-bf_sde_install=/usr \
-bf_switchd_background=true \
-bf_switchd_cfg=/usr/share/stratum/tofino_skip_p4.conf \
Expand Down
27 changes: 24 additions & 3 deletions ptf/tests/ptf/ptf_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,16 @@ def build_tofino_config(prog_name, bin_path, cxt_json_path):
return device_config


def build_tofino_pipeline_tar_config(pipeline_tar_path):
device_config = ""
with open(pipeline_tar_path, 'rb') as pipeline_tar_f:
device_config += pipeline_tar_f.read()
return device_config


def update_config(p4info_path, bmv2_json_path, tofino_bin_path,
tofino_cxt_json_path, grpc_addr, device_id):
tofino_cxt_json_path, tofino_pipeline_tar_path,
grpc_addr, device_id):
"""
Performs a SetForwardingPipelineConfig on the device
"""
Expand Down Expand Up @@ -142,6 +150,8 @@ def get_stream_packet(type_, timeout=1):
google.protobuf.text_format.Merge(p4info_f.read(), config.p4info)
if bmv2_json_path is not None:
device_config = build_bmv2_config(bmv2_json_path)
elif tofino_pipeline_tar_path is not None:
device_config = build_tofino_pipeline_tar_config(tofino_pipeline_tar_path)
else:
device_config = build_tofino_config("name", tofino_bin_path,
tofino_cxt_json_path)
Expand Down Expand Up @@ -233,13 +243,16 @@ def main():
parser.add_argument('--device',
help='Target device',
type=str, action="store", required=True,
choices=['tofino', 'bmv2', 'stratum-bmv2'])
choices=['tofino', 'bmv2', 'stratum-bmv2', 'stratum-bfrt'])
parser.add_argument('--p4info',
help='Location of p4info proto in text format',
type=str, action="store", required=True)
parser.add_argument('--bmv2-json',
help='Location BMv2 JSON output from p4c (if target is bmv2)',
type=str, action="store", required=False)
parser.add_argument('--tofino-pipeline-tar',
help='Location of Tofino pipeline archive(tar.bz2) which includes pipeline configs',
type=str, action="store", required=False)
parser.add_argument('--tofino-bin',
help='Location of Tofino .bin output from p4c (if target is tofino)',
type=str, action="store", required=False)
Expand Down Expand Up @@ -280,6 +293,7 @@ def main():
bmv2_json = None
tofino_ctx_json = None
tofino_bin = None
tofino_pipeline_tar = None
if not os.path.exists(args.p4info):
error("P4Info file {} not found".format(args.p4info))
sys.exit(1)
Expand All @@ -299,8 +313,14 @@ def main():
error("BMv2 json file {} not found".format(args.bmv2_json))
sys.exit(1)
bmv2_json = args.bmv2_json
elif device == 'stratum-bfrt':
if not os.path.exists(args.tofino_pipeline_tar):
error("Tofino binary config file {} not found".format(
args.tofino_pipeline_tar))
sys.exit(1)
tofino_pipeline_tar = args.tofino_pipeline_tar
if not os.path.exists(args.port_map):
print "Port map path '{}' does not exist".format(args.port_map)
print("Port map path '{}' does not exist".format(args.port_map))
sys.exit(1)

success = True
Expand All @@ -310,6 +330,7 @@ def main():
bmv2_json_path=bmv2_json,
tofino_bin_path=tofino_bin,
tofino_cxt_json_path=tofino_ctx_json,
tofino_pipeline_tar_path=tofino_pipeline_tar,
grpc_addr=args.grpc_addr,
device_id=args.device_id)
if not success:
Expand Down
Loading

0 comments on commit 8547b8c

Please sign in to comment.