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} |
pier | bd6eaf0 | 2020-06-05 20:45:26 +0200 | [diff] [blame^] | 38 | # Prevent the creation by docker run |
| 39 | mkdir -p ${P4C_OUT} |
Carmelo Cascone | 97efefb | 2019-12-05 16:40:45 -0800 | [diff] [blame] | 40 | |
| 41 | # DIR is this file directory. |
| 42 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 43 | |
| 44 | # Where the compiler output should be placed to be included in the pipeconf. |
| 45 | DEST_DIR=${DIR}/../resources/p4c-out/${PROFILE}/tofino |
| 46 | |
| 47 | # If SDE_DOCKER_IMG env is set, use containerized version of the compiler |
| 48 | if [ -z "${SDE_DOCKER_IMG}" ]; then |
| 49 | P4C_CMD="bf-p4c" |
| 50 | else |
| 51 | 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" |
| 52 | fi |
| 53 | |
| 54 | SDE_VER=$( ${P4C_CMD} --version | cut -d' ' -f2 ) |
| 55 | |
| 56 | # shellcheck disable=SC2086 |
| 57 | function do_p4c() { |
| 58 | pltf="$1_sde_${SDE_VER//./_}" |
| 59 | cpu_port=$2 |
| 60 | echo "*** Compiling profile '${PROFILE}' for ${pltf} platform..." |
| 61 | echo "*** Output in ${P4C_OUT}/${pltf}" |
| 62 | pp_flags="-DCPU_PORT=${cpu_port}" |
Daniele Moro | 2ecec23 | 2020-01-16 11:10:51 -0800 | [diff] [blame] | 63 | p4c_flags="--auto-init-metadata" |
Carmelo Cascone | 97efefb | 2019-12-05 16:40:45 -0800 | [diff] [blame] | 64 | mkdir -p ${P4C_OUT}/${pltf} |
| 65 | ( |
| 66 | set -x |
Carmelo Cascone | 91d92fb | 2019-12-16 18:34:26 -0800 | [diff] [blame] | 67 | $P4C_CMD --arch v1model -g --create-graphs --verbose 2 \ |
Carmelo Cascone | 97efefb | 2019-12-05 16:40:45 -0800 | [diff] [blame] | 68 | -o ${P4C_OUT}/${pltf} -I ${P4_SRC_DIR} \ |
| 69 | ${pp_flags} ${OTHER_PP_FLAGS} \ |
Daniele Moro | 2ecec23 | 2020-01-16 11:10:51 -0800 | [diff] [blame] | 70 | ${p4c_flags} \ |
Carmelo Cascone | 97efefb | 2019-12-05 16:40:45 -0800 | [diff] [blame] | 71 | --p4runtime-files ${P4C_OUT}/${pltf}/p4info.txt \ |
| 72 | ${DIR}/fabric-tofino.p4 |
| 73 | ) |
| 74 | |
| 75 | # Copy only the relevant files to the pipeconf resources |
| 76 | mkdir -p ${DEST_DIR}/${pltf}/pipe |
| 77 | cp ${P4C_OUT}/${pltf}/p4info.txt ${DEST_DIR}/${pltf} |
| 78 | cp ${P4C_OUT}/${pltf}/pipe/context.json ${DEST_DIR}/${pltf}/pipe |
| 79 | cp ${P4C_OUT}/${pltf}/pipe/tofino.bin ${DEST_DIR}/${pltf}/pipe |
| 80 | echo "${cpu_port}" > ${DEST_DIR}/${pltf}/cpu_port.txt |
| 81 | |
| 82 | echo |
| 83 | } |
| 84 | |
| 85 | do_p4c "mavericks" ${MAVERICKS_CPU_PORT} |
| 86 | do_p4c "montara" ${MONTARA_CPU_PORT} |