blob: 3ceea4105e18ac35050867a1d1ee7e8452f0e127 [file] [log] [blame]
Carmelo Cascone97efefb2019-12-05 16:40:45 -08001#!/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
16MAVERICKS_CPU_PORT=320
17MONTARA_CPU_PORT=192
18
19if [ -z "$ONOS_ROOT" ]; then
20 echo "Error: ONOS_ROOT is not set"
21 exit 1
22fi
23
24P4_SRC_DIR=${ONOS_ROOT}/pipelines/fabric/impl/src/main/resources
25
26if [ ! -d "${P4_SRC_DIR}" ]; then
27 echo "Error: unable to locate fabric P4 sources at ${P4_SRC_DIR}"
28fi
29
30set -e
31
32PROFILE=$1
33OTHER_PP_FLAGS=$2
34
35# PWD is the directory where this script is called from (should be the root of
36# this repo).
Carmelo Cascone91d92fb2019-12-16 18:34:26 -080037P4C_OUT=${PWD}/tmp/${PROFILE}
Carmelo Cascone97efefb2019-12-05 16:40:45 -080038
39# DIR is this file directory.
40DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
41
42# Where the compiler output should be placed to be included in the pipeconf.
43DEST_DIR=${DIR}/../resources/p4c-out/${PROFILE}/tofino
44
45# If SDE_DOCKER_IMG env is set, use containerized version of the compiler
46if [ -z "${SDE_DOCKER_IMG}" ]; then
47 P4C_CMD="bf-p4c"
48else
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"
50fi
51
52SDE_VER=$( ${P4C_CMD} --version | cut -d' ' -f2 )
53
54# shellcheck disable=SC2086
55function 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 Cascone91d92fb2019-12-16 18:34:26 -080064 $P4C_CMD --arch v1model -g --create-graphs --verbose 2 \
Carmelo Cascone97efefb2019-12-05 16:40:45 -080065 -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
81do_p4c "mavericks" ${MAVERICKS_CPU_PORT}
82do_p4c "montara" ${MONTARA_CPU_PORT}