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