Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 1 | # Copyright 2019-present Open Networking Foundation |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | VERSION ?= $(shell cat ./VERSION) |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 16 | DIFF ?= $(git diff --shortstat 2> /dev/null | tail -n1) |
Zdravko Bozakov | 2da7634 | 2019-10-21 09:47:35 +0200 | [diff] [blame] | 17 | GIT_STATUS ?= $(shell [ -z "$DIFF" ] && echo "Dirty" || echo "Clean") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 18 | |
| 19 | ## Docker related |
| 20 | DOCKER_TAG ?= ${VERSION} |
Matteo Scandolo | 5daa2ab | 2019-10-08 08:27:18 -0700 | [diff] [blame] | 21 | DOCKER_REPOSITORY ?= "" |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 22 | DOCKER_REGISTRY ?= "" |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 23 | DOCKER_RUN_ARGS ?= "" |
Zdravko Bozakov | 2da7634 | 2019-10-21 09:47:35 +0200 | [diff] [blame] | 24 | DOCKER_PORTS ?= -p 50070:50070 -p 50060:50060 -p 50071:50071 -p 50072:50072 -p 50073:50073 |
| 25 | |
| 26 | ## protobuf related |
| 27 | VOLTHA_PROTOS ?= $(shell GO111MODULE=on go list -f '{{ .Dir }}' -m github.com/opencord/voltha-protos) |
| 28 | GOOGLEAPI ?= $(shell GO111MODULE=on go list -f '{{ .Dir }}' -m github.com/grpc-ecosystem/grpc-gateway) |
| 29 | TOOLS_DIR := tools |
| 30 | TOOLS_BIN := $(TOOLS_DIR)/bin/ |
| 31 | |
| 32 | export PATH=$(shell echo $$PATH):$(PWD)/$(TOOLS_BIN) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 33 | |
| 34 | # Public targets |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 35 | all: help |
| 36 | |
Zdravko Bozakov | 2da7634 | 2019-10-21 09:47:35 +0200 | [diff] [blame] | 37 | # go installed tools.go |
| 38 | GO_TOOLS := github.com/golang/protobuf/protoc-gen-go \ |
| 39 | github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway \ |
| 40 | github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger |
| 41 | |
| 42 | # tools |
| 43 | GO_TOOLS_BIN := $(addprefix $(TOOLS_BIN), $(notdir $(GO_TOOLS))) |
| 44 | GO_TOOLS_VENDOR := $(addprefix vendor/, $(GO_TOOLS)) |
| 45 | |
| 46 | TEST_PACKAGES := github.com/opencord/bbsim/cmd/... \ |
| 47 | github.com/opencord/bbsim/internal/... |
| 48 | |
| 49 | setup_tools: $(GO_TOOLS_BIN) |
| 50 | |
| 51 | $(GO_TOOLS_BIN): $(GO_TOOLS_VENDOR) |
| 52 | GO111MODULE=on GOBIN="$(PWD)/$(TOOLS_BIN)" go install -mod=vendor $(GO_TOOLS) |
| 53 | |
| 54 | protos: dep setup_tools api/bbsim/bbsim.pb.go api/bbsim/bbsim.pb.gw.go api/legacy/bbsim.pb.go api/legacy/bbsim.pb.gw.go # @HELP Build proto files |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 55 | |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame] | 56 | dep: # @HELP Download the dependencies to the vendor folder |
| 57 | GO111MODULE=on go mod vendor |
| 58 | |
Matteo Scandolo | 01d41ce | 2019-10-28 15:42:47 -0700 | [diff] [blame] | 59 | _build: dep protos fmt build-bbsim build-bbsimctl build-bbr |
| 60 | |
Matteo Scandolo | 6866b8c | 2019-10-28 16:15:24 -0700 | [diff] [blame] | 61 | .PHONY: build |
Matteo Scandolo | 01d41ce | 2019-10-28 15:42:47 -0700 | [diff] [blame] | 62 | build: # @HELP Build the binaries (it runs inside a docker container and output the built code on your local file system) |
| 63 | docker build -t ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim-builder:${DOCKER_TAG} -f build/ci/Dockerfile.builder . |
Matteo Scandolo | d49da29 | 2019-10-28 16:30:51 -0700 | [diff] [blame] | 64 | docker run --rm -v $(shell pwd):/bbsim ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim-builder:${DOCKER_TAG} /bin/sh -c "cd /bbsim; make _build" |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 65 | |
William Kurkian | c7966c7 | 2019-10-16 14:00:00 -0400 | [diff] [blame] | 66 | test: dep protos fmt # @HELP Execute unit tests |
Zdravko Bozakov | 2da7634 | 2019-10-21 09:47:35 +0200 | [diff] [blame] | 67 | GO111MODULE=on go test -v -mod vendor $(TEST_PACKAGES) -covermode count -coverprofile ./tests/results/go-test-coverage.out 2>&1 | tee ./tests/results/go-test-results.out |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame] | 68 | go-junit-report < ./tests/results/go-test-results.out > ./tests/results/go-test-results.xml |
| 69 | gocover-cobertura < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 70 | |
Matteo Scandolo | 3830549 | 2019-10-11 11:36:00 -0700 | [diff] [blame] | 71 | fmt: |
| 72 | go fmt ./... |
| 73 | |
Matteo Scandolo | 01d41ce | 2019-10-28 15:42:47 -0700 | [diff] [blame] | 74 | docker-build: # @HELP Build the BBSim docker container (contains BBSimCtl too) |
Matteo Scandolo | 82c16d0 | 2019-09-24 09:34:32 -0700 | [diff] [blame] | 75 | docker build -t ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim:${DOCKER_TAG} -f build/package/Dockerfile . |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 76 | |
Matteo Scandolo | 01d41ce | 2019-10-28 15:42:47 -0700 | [diff] [blame] | 77 | docker-push: # @HELP Push the docker container to a registry |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 78 | docker push ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim:${DOCKER_TAG} |
| 79 | |
Matteo Scandolo | e383d5d | 2019-10-25 14:47:27 -0700 | [diff] [blame] | 80 | docker-run: # @HELP Runs the container locally (available options: DOCKER_RUN_ARGS="-pon 2 -onu 2" make docker-run) |
Zdravko Bozakov | 2da7634 | 2019-10-21 09:47:35 +0200 | [diff] [blame] | 81 | docker run -d ${DOCKER_PORTS} --privileged --rm --name bbsim ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim:${DOCKER_TAG} /app/bbsim ${DOCKER_RUN_ARGS} |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 82 | |
Matteo Scandolo | e383d5d | 2019-10-25 14:47:27 -0700 | [diff] [blame] | 83 | docker-run-dev: # @HELP Runs the container locally (intended for development purposes, not in detached mode) |
Zdravko Bozakov | 2da7634 | 2019-10-21 09:47:35 +0200 | [diff] [blame] | 84 | docker run ${DOCKER_PORTS} --privileged --rm --name bbsim ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim:${DOCKER_TAG} /app/bbsim ${DOCKER_RUN_ARGS} |
Matteo Scandolo | e383d5d | 2019-10-25 14:47:27 -0700 | [diff] [blame] | 85 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 86 | .PHONY: docs |
Zdravko Bozakov | 2da7634 | 2019-10-21 09:47:35 +0200 | [diff] [blame] | 87 | docs: swagger # @HELP Generate docs and opens them in the browser |
| 88 | cd docs; make doc_venv; make html; cd - |
| 89 | @echo -e "\nBBSim documentation generated in file://${PWD}/docs/build/html/index.html" |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 90 | |
Matteo Scandolo | 8dea399 | 2019-10-22 10:54:25 -0700 | [diff] [blame] | 91 | # Release related items |
| 92 | # Generates binaries in $RELEASE_DIR with name $RELEASE_NAME-$RELEASE_OS_ARCH |
| 93 | # Inspired by: https://github.com/kubernetes/minikube/releases |
| 94 | RELEASE_DIR ?= release |
| 95 | RELEASE_OS_ARCH ?= linux-amd64 linux-arm64 windows-amd64 darwin-amd64 |
| 96 | |
| 97 | RELEASE_BBR_NAME ?= bbr |
| 98 | RELEASE_BBR_BINS := $(foreach rel,$(RELEASE_OS_ARCH),$(RELEASE_DIR)/$(RELEASE_BBR_NAME)-$(rel)) |
| 99 | RELEASE_BBSIM_NAME ?= bbsimctl |
| 100 | RELEASE_BBSIM_BINS := $(foreach rel,$(RELEASE_OS_ARCH),$(RELEASE_DIR)/$(RELEASE_BBSIM_NAME)-$(rel)) |
| 101 | |
| 102 | $(RELEASE_BBR_BINS): |
| 103 | export GOOS=$(rel_os) ;\ |
| 104 | export GOARCH=$(rel_arch) ;\ |
| 105 | GO111MODULE=on go build -i -v -mod vendor \ |
| 106 | -ldflags "-w -X main.buildTime=$(shell date +”%Y/%m/%d-%H:%M:%S”) \ |
Matteo Scandolo | 8dea399 | 2019-10-22 10:54:25 -0700 | [diff] [blame] | 107 | -X main.gitStatus=${GIT_STATUS} \ |
| 108 | -X main.version=${VERSION}" \ |
| 109 | -o "$@" ./cmd/bbr |
| 110 | |
| 111 | $(RELEASE_BBSIM_BINS): |
| 112 | export GOOS=$(rel_os) ;\ |
| 113 | export GOARCH=$(rel_arch) ;\ |
| 114 | GO111MODULE=on go build -i -v -mod vendor \ |
| 115 | -ldflags "-w -X main.buildTime=$(shell date +”%Y/%m/%d-%H:%M:%S”) \ |
Matteo Scandolo | 8dea399 | 2019-10-22 10:54:25 -0700 | [diff] [blame] | 116 | -X main.gitStatus=${GIT_STATUS} \ |
| 117 | -X main.version=${VERSION}" \ |
| 118 | -o "$@" ./cmd/bbsim |
| 119 | |
| 120 | .PHONY: release $(RELEASE_BBR_BINS) $(RELEASE_BBSIM_BINS) |
Matteo Scandolo | 01d41ce | 2019-10-28 15:42:47 -0700 | [diff] [blame] | 121 | release: dep protos $(RELEASE_BBR_BINS) $(RELEASE_BBSIM_BINS) # @HELP Creates release ready bynaries for BBSimctl and BBR artifacts |
Zdravko Bozakov | 2da7634 | 2019-10-21 09:47:35 +0200 | [diff] [blame] | 122 | swagger: docs/swagger/bbsim/bbsim.swagger.json docs/swagger/leagacy/bbsim.swagger.json # @HELP Generate swagger documentation for BBSim API |
Matteo Scandolo | 8dea399 | 2019-10-22 10:54:25 -0700 | [diff] [blame] | 123 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 124 | help: # @HELP Print the command options |
| 125 | @echo |
| 126 | @echo "\033[0;31m BroadBand Simulator (BBSim) \033[0m" |
| 127 | @echo |
| 128 | @echo Emulates the control plane of an openolt compatible device |
| 129 | @echo Useful for development and scale testing |
| 130 | @echo |
| 131 | @grep -E '^.*: .* *# *@HELP' $(MAKEFILE_LIST) \ |
| 132 | | sort \ |
| 133 | | awk ' \ |
| 134 | BEGIN {FS = ": .* *# *@HELP"}; \ |
| 135 | {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}; \ |
| 136 | ' |
| 137 | |
| 138 | |
| 139 | # Internals |
Matteo Scandolo | 8dea399 | 2019-10-22 10:54:25 -0700 | [diff] [blame] | 140 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 141 | build-bbr: |
| 142 | GO111MODULE=on go build -i -v -mod vendor \ |
| 143 | -ldflags "-w -X main.buildTime=$(shell date +”%Y/%m/%d-%H:%M:%S”) \ |
| 144 | -X main.commitHash=$(shell git log --pretty=format:%H -n 1) \ |
| 145 | -X main.gitStatus=${GIT_STATUS} \ |
| 146 | -X main.version=${VERSION}" \ |
| 147 | ./cmd/bbr |
| 148 | |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 149 | build-bbsim: |
| 150 | GO111MODULE=on go build -i -v -mod vendor \ |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 151 | -ldflags "-w -X main.buildTime=$(shell date +”%Y/%m/%d-%H:%M:%S”) \ |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 152 | -X main.commitHash=$(shell git log --pretty=format:%H -n 1) \ |
| 153 | -X main.gitStatus=${GIT_STATUS} \ |
| 154 | -X main.version=${VERSION}" \ |
Matteo Scandolo | 82c16d0 | 2019-09-24 09:34:32 -0700 | [diff] [blame] | 155 | ./cmd/bbsim |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 156 | |
| 157 | build-bbsimctl: |
| 158 | GO111MODULE=on go build -i -v -mod vendor \ |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 159 | -ldflags "-w -X github.com/opencord/bbsim/internal/bbsimctl/config.BuildTime=$(shell date +”%Y/%m/%d-%H:%M:%S”) \ |
Matteo Scandolo | 82c16d0 | 2019-09-24 09:34:32 -0700 | [diff] [blame] | 160 | -X github.com/opencord/bbsim/internal/bbsimctl/config.CommitHash=$(shell git log --pretty=format:%H -n 1) \ |
| 161 | -X github.com/opencord/bbsim/internal/bbsimctl/config.GitStatus=${GIT_STATUS} \ |
| 162 | -X github.com/opencord/bbsim/internal/bbsimctl/config.Version=${VERSION}" \ |
| 163 | ./cmd/bbsimctl |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 164 | |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 165 | api/openolt/openolt.pb.go: api/openolt/openolt.proto |
Zdravko Bozakov | 2da7634 | 2019-10-21 09:47:35 +0200 | [diff] [blame] | 166 | @protoc -I. \ |
| 167 | -I${GOOGLEAPI}/third_party/googleapis \ |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 168 | --go_out=plugins=grpc:./ \ |
| 169 | $< |
| 170 | |
Zdravko Bozakov | 2da7634 | 2019-10-21 09:47:35 +0200 | [diff] [blame] | 171 | api/bbsim/bbsim.pb.go api/bbsim/bbsim.pb.gw.go: api/bbsim/bbsim.proto api/bbsim/bbsim.yaml |
| 172 | @protoc -I. \ |
| 173 | -I${GOOGLEAPI}/third_party/googleapis \ |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 174 | --go_out=plugins=grpc:./ \ |
Zdravko Bozakov | 2da7634 | 2019-10-21 09:47:35 +0200 | [diff] [blame] | 175 | --grpc-gateway_out=logtostderr=true,grpc_api_configuration=api/bbsim/bbsim.yaml,allow_delete_body=true:./ \ |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 176 | $< |
| 177 | |
Zdravko Bozakov | 2da7634 | 2019-10-21 09:47:35 +0200 | [diff] [blame] | 178 | api/legacy/bbsim.pb.go api/legacy/bbsim.pb.gw.go: api/legacy/bbsim.proto |
| 179 | @protoc -I. \ |
| 180 | -I${GOOGLEAPI}/third_party/googleapis/ \ |
| 181 | -I${GOOGLEAPI}/ \ |
| 182 | -I${VOLTHA_PROTOS}/protos/ \ |
| 183 | --go_out=plugins=grpc:./ \ |
| 184 | --grpc-gateway_out=logtostderr=true,allow_delete_body=true:./ \ |
| 185 | $< |
| 186 | |
| 187 | docs/swagger/bbsim/bbsim.swagger.json: api/bbsim/bbsim.yaml |
| 188 | @protoc -I ./api \ |
| 189 | -I${GOOGLEAPI}/ \ |
| 190 | -I${VOLTHA_PROTOS}/protos/ \ |
| 191 | --swagger_out=logtostderr=true,allow_delete_body=true,grpc_api_configuration=$<:docs/swagger/ \ |
| 192 | api/bbsim/bbsim.proto |
| 193 | |
| 194 | docs/swagger/leagacy/bbsim.swagger.json: api/legacy/bbsim.proto |
| 195 | @protoc -I ./api \ |
| 196 | -I${GOOGLEAPI}/ \ |
| 197 | -I${VOLTHA_PROTOS}/protos/ \ |
| 198 | --swagger_out=logtostderr=true,allow_delete_body=true:docs/swagger/ \ |
| 199 | $< |