Carmelo Cascone | 97efefb | 2019-12-05 16:40:45 -0800 | [diff] [blame^] | 1 | PROFILES ?= all |
| 2 | ONOS_HOST ?= localhost |
| 3 | |
| 4 | mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST))) |
| 5 | curr_dir := $(patsubst %/,%,$(dir $(mkfile_path))) |
| 6 | curr_dir_sha := $(shell echo -n "$(curr_dir)" | shasum | cut -c1-7) |
| 7 | |
| 8 | mvn_image := maven:3.6.1-jdk-11-slim |
| 9 | mvn_container := mvn-build-${curr_dir_sha} |
| 10 | |
| 11 | onos_url := http://${ONOS_HOST}:8181/onos |
| 12 | onos_curl := curl --fail -sSL --user onos:rocks --noproxy localhost |
| 13 | |
| 14 | pipeconf_app_name := org.opencord.fabric-tofino |
| 15 | pipeconf_app_version := 2.2.1-SNAPSHOT |
| 16 | |
| 17 | tofino_compile := ./src/main/p4/tofino-compile.sh |
| 18 | |
| 19 | .PHONY: pipeconf |
| 20 | |
| 21 | build: clean $(PROFILES) pipeconf |
| 22 | |
| 23 | all: fabric fabric-bng fabric-spgw fabric-int fabric-spgw-int |
| 24 | |
| 25 | fabric: |
| 26 | @${tofino_compile} fabric "" |
| 27 | |
| 28 | fabric-simple: |
| 29 | @${tofino_compile} fabric-simple "-DWITH_SIMPLE_NEXT" |
| 30 | |
| 31 | fabric-bng: |
| 32 | @${tofino_compile} fabric-bng "-DWITH_BNG -DWITH_DOUBLE_VLAN_TERMINATION -DWITHOUT_XCONNECT" |
| 33 | |
| 34 | fabric-int: |
| 35 | @${tofino_compile} fabric-int "-DWITH_INT_SOURCE -DWITH_INT_TRANSIT" |
| 36 | |
| 37 | fabric-spgw: |
| 38 | @${tofino_compile} fabric-spgw "-DWITH_SPGW" |
| 39 | |
| 40 | fabric-spgw-int: |
| 41 | @${tofino_compile} fabric-spgw-int "-DWITH_SPGW -DWITH_INT_SOURCE -DWITH_INT_TRANSIT" |
| 42 | |
| 43 | # Reuse the same container to persist mvn repo cache. |
| 44 | _create_mvn_container: |
| 45 | @if ! docker container ls -a --format '{{.Names}}' | grep -q ${mvn_container} ; then \ |
| 46 | docker create -v ${curr_dir}:/mvn-src -w /mvn-src --name ${mvn_container} ${mvn_image} mvn clean package verify; \ |
| 47 | fi |
| 48 | |
| 49 | _mvn_package: |
| 50 | $(info *** Building ONOS app...) |
| 51 | @mkdir -p target |
| 52 | @docker start -a -i ${mvn_container} |
| 53 | |
| 54 | pipeconf: _create_mvn_container _mvn_package |
| 55 | $(info *** ONOS pipeconf .oar package created succesfully) |
| 56 | @ls -1 ${curr_dir}/target/*.oar |
| 57 | |
| 58 | pipeconf-install: |
| 59 | $(info *** Installing and activating pipeconf app in ONOS at ${ONOS_HOST}...) |
| 60 | ${onos_curl} -X POST -HContent-Type:application/octet-stream \ |
| 61 | '${onos_url}/v1/applications?activate=true' \ |
| 62 | --data-binary @target/fabric-tofino-${pipeconf_app_version}.oar |
| 63 | @echo |
| 64 | |
| 65 | pipeconf-uninstall: |
| 66 | $(info *** Uninstalling pipeconf app from ONOS (if present) at ${ONOS_HOST}...) |
| 67 | -${onos_curl} -X DELETE ${onos_url}/v1/applications/${pipeconf_app_name} |
| 68 | @echo |
| 69 | |
| 70 | netcfg: |
| 71 | $(info *** Pushing tofino-netcfg.json to ONOS at ${ONOS_HOST}...) |
| 72 | ${onos_curl} -X POST -H 'Content-Type:application/json' \ |
| 73 | ${onos_url}/v1/network/configuration -d@./tofino-netcfg.json |
| 74 | @echo |
| 75 | |
| 76 | clean: |
| 77 | -rm -rf src/main/resources/p4c-out |
| 78 | |
| 79 | deep-clean: clean |
| 80 | -rm -rf target |
| 81 | -rm -rf p4c-out |
| 82 | -docker rm ${mvn_container} > /dev/null 2>&1 |