blob: 9f2c558b4daae5151fe378928dcc8d9b7bcc7a12 [file] [log] [blame]
Carmelo Cascone228092b2018-06-15 20:41:10 +02001#!/usr/bin/env bash
2
Carmelo Casconeb5324e72018-11-25 02:26:32 -08003set -e
Carmelo Cascone228092b2018-06-15 20:41:10 +02004
5BMV2_CPU_PORT="255"
Carmelo Cascone0c8d73e2018-09-07 16:31:06 -07006BMV2_PP_FLAGS="-DTARGET_BMV2 -DCPU_PORT=${BMV2_CPU_PORT} -DWITH_PORT_COUNTER"
Carmelo Cascone228092b2018-06-15 20:41:10 +02007
8PROFILE=$1
9OTHER_PP_FLAGS=$2
Carmelo Cascone228092b2018-06-15 20:41:10 +020010
Carmelo Cascone4d8785b2019-05-31 17:11:26 -070011SRC_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
12OUT_DIR=${SRC_DIR}/p4c-out/${PROFILE}/bmv2/default
Carmelo Cascone228092b2018-06-15 20:41:10 +020013
Carmelo Casconeb5324e72018-11-25 02:26:32 -080014mkdir -p ${OUT_DIR}
15mkdir -p ${OUT_DIR}/graphs
16
17echo
18echo "## Compiling profile ${PROFILE} in ${OUT_DIR}..."
Carmelo Cascone4d8785b2019-05-31 17:11:26 -070019
Carmelo Casconed14497a2019-06-25 18:12:51 -070020dockerImage=opennetworking/p4c:stable
Carmelo Cascone4d8785b2019-05-31 17:11:26 -070021dockerRun="docker run --rm -w ${SRC_DIR} -v ${SRC_DIR}:${SRC_DIR} -v ${OUT_DIR}:${OUT_DIR} ${dockerImage}"
22
23# Generate preprocessed P4 source (for debugging).
24(set -x; ${dockerRun} p4c-bm2-ss --arch v1model \
Carmelo Cascone228092b2018-06-15 20:41:10 +020025 ${BMV2_PP_FLAGS} ${OTHER_PP_FLAGS} \
Carmelo Cascone4d8785b2019-05-31 17:11:26 -070026 --pp ${OUT_DIR}/_pp.p4 fabric.p4)
27
28# Generate BMv2 JSON and P4Info.
29(set -x; ${dockerRun} p4c-bm2-ss --arch v1model -o ${OUT_DIR}/bmv2.json \
30 ${BMV2_PP_FLAGS} ${OTHER_PP_FLAGS} \
31 --p4runtime-files ${OUT_DIR}/p4info.txt fabric.p4)
32
33# Graphs.
34(set -x; ${dockerRun} p4c-graphs ${BMV2_PP_FLAGS} ${OTHER_PP_FLAGS} \
35 --graphs-dir ${OUT_DIR}/graphs fabric.p4)
36
37# Convert .dot graphs to PDFs.
Carmelo Casconeb5324e72018-11-25 02:26:32 -080038for f in ${OUT_DIR}/graphs/*.dot; do
Carmelo Cascone4d8785b2019-05-31 17:11:26 -070039 (set -x; ${dockerRun} dot -Tpdf ${f} > ${f}.pdf)
Carmelo Casconeb5324e72018-11-25 02:26:32 -080040 rm -f ${f}
41done
Carmelo Cascone6880ba62018-09-06 00:04:34 -070042
Carmelo Cascone4d8785b2019-05-31 17:11:26 -070043# CPU port.
Carmelo Casconeb5324e72018-11-25 02:26:32 -080044(set -x; echo ${BMV2_CPU_PORT} > ${OUT_DIR}/cpu_port.txt)