Carmelo Cascone | 97efefb | 2019-12-05 16:40:45 -0800 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | # Copyright 2019-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | MAVERICKS_CPU_PORT=320 |
| 17 | MONTARA_CPU_PORT=192 |
| 18 | |
| 19 | if [ -z "$ONOS_ROOT" ]; then |
| 20 | echo "Error: ONOS_ROOT is not set" |
| 21 | exit 1 |
| 22 | fi |
| 23 | |
| 24 | P4_SRC_DIR=${ONOS_ROOT}/pipelines/fabric/impl/src/main/resources |
| 25 | |
| 26 | if [ ! -d "${P4_SRC_DIR}" ]; then |
| 27 | echo "Error: unable to locate fabric P4 sources at ${P4_SRC_DIR}" |
| 28 | fi |
| 29 | |
| 30 | set -e |
| 31 | |
| 32 | PROFILE=$1 |
| 33 | OTHER_PP_FLAGS=$2 |
| 34 | |
| 35 | # PWD is the directory where this script is called from (should be the root of |
| 36 | # this repo). |
Carmelo Cascone | 91d92fb | 2019-12-16 18:34:26 -0800 | [diff] [blame] | 37 | P4C_OUT=${PWD}/tmp/${PROFILE} |
Carmelo Cascone | 97efefb | 2019-12-05 16:40:45 -0800 | [diff] [blame] | 38 | |
| 39 | # DIR is this file directory. |
| 40 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 41 | |
| 42 | # Where the compiler output should be placed to be included in the pipeconf. |
| 43 | DEST_DIR=${DIR}/../resources/p4c-out/${PROFILE}/tofino |
| 44 | |
| 45 | # If SDE_DOCKER_IMG env is set, use containerized version of the compiler |
| 46 | if [ -z "${SDE_DOCKER_IMG}" ]; then |
| 47 | P4C_CMD="bf-p4c" |
| 48 | else |
| 49 | P4C_CMD="docker run --rm -v ${P4C_OUT}:${P4C_OUT} -v ${P4_SRC_DIR}:${P4_SRC_DIR} -v ${DIR}:${DIR} -w ${DIR} ${SDE_DOCKER_IMG} bf-p4c" |
| 50 | fi |
| 51 | |
| 52 | SDE_VER=$( ${P4C_CMD} --version | cut -d' ' -f2 ) |
| 53 | |
| 54 | # shellcheck disable=SC2086 |
| 55 | function do_p4c() { |
| 56 | pltf="$1_sde_${SDE_VER//./_}" |
| 57 | cpu_port=$2 |
| 58 | echo "*** Compiling profile '${PROFILE}' for ${pltf} platform..." |
| 59 | echo "*** Output in ${P4C_OUT}/${pltf}" |
| 60 | pp_flags="-DCPU_PORT=${cpu_port}" |
| 61 | mkdir -p ${P4C_OUT}/${pltf} |
| 62 | ( |
| 63 | set -x |
Carmelo Cascone | 91d92fb | 2019-12-16 18:34:26 -0800 | [diff] [blame] | 64 | $P4C_CMD --arch v1model -g --create-graphs --verbose 2 \ |
Carmelo Cascone | 97efefb | 2019-12-05 16:40:45 -0800 | [diff] [blame] | 65 | -o ${P4C_OUT}/${pltf} -I ${P4_SRC_DIR} \ |
| 66 | ${pp_flags} ${OTHER_PP_FLAGS} \ |
| 67 | --p4runtime-files ${P4C_OUT}/${pltf}/p4info.txt \ |
| 68 | ${DIR}/fabric-tofino.p4 |
| 69 | ) |
| 70 | |
| 71 | # Copy only the relevant files to the pipeconf resources |
| 72 | mkdir -p ${DEST_DIR}/${pltf}/pipe |
| 73 | cp ${P4C_OUT}/${pltf}/p4info.txt ${DEST_DIR}/${pltf} |
| 74 | cp ${P4C_OUT}/${pltf}/pipe/context.json ${DEST_DIR}/${pltf}/pipe |
| 75 | cp ${P4C_OUT}/${pltf}/pipe/tofino.bin ${DEST_DIR}/${pltf}/pipe |
| 76 | echo "${cpu_port}" > ${DEST_DIR}/${pltf}/cpu_port.txt |
| 77 | |
| 78 | echo |
| 79 | } |
| 80 | |
| 81 | do_p4c "mavericks" ${MAVERICKS_CPU_PORT} |
| 82 | do_p4c "montara" ${MONTARA_CPU_PORT} |