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 | 958d81c | 2019-12-13 22:09:48 +0100 | [diff] [blame] | 24 | DOCKER_PORTS ?= -p 50070:50070 -p 50060:50060 -p 50071:50071 -p 50072:50072 -p 50073:50073 -p 50074:50074 |
Andrea Campanella | 64dffd5 | 2019-12-17 17:29:57 -0800 | [diff] [blame] | 25 | TYPE ?= minimal |
Zdravko Bozakov | 2da7634 | 2019-10-21 09:47:35 +0200 | [diff] [blame] | 26 | |
| 27 | ## protobuf related |
Matteo Scandolo | 3de9de0 | 2019-11-14 13:40:03 -0800 | [diff] [blame] | 28 | VOLTHA_PROTOS ?= $(shell GO111MODULE=on go list -f '{{ .Dir }}' -m github.com/opencord/voltha-protos/v2) |
Zdravko Bozakov | 2da7634 | 2019-10-21 09:47:35 +0200 | [diff] [blame] | 29 | GOOGLEAPI ?= $(shell GO111MODULE=on go list -f '{{ .Dir }}' -m github.com/grpc-ecosystem/grpc-gateway) |
| 30 | TOOLS_DIR := tools |
| 31 | TOOLS_BIN := $(TOOLS_DIR)/bin/ |
| 32 | |
| 33 | export PATH=$(shell echo $$PATH):$(PWD)/$(TOOLS_BIN) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 34 | |
| 35 | # Public targets |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 36 | all: help |
| 37 | |
Zdravko Bozakov | 2da7634 | 2019-10-21 09:47:35 +0200 | [diff] [blame] | 38 | # go installed tools.go |
| 39 | GO_TOOLS := github.com/golang/protobuf/protoc-gen-go \ |
| 40 | github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway \ |
| 41 | github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger |
| 42 | |
| 43 | # tools |
| 44 | GO_TOOLS_BIN := $(addprefix $(TOOLS_BIN), $(notdir $(GO_TOOLS))) |
| 45 | GO_TOOLS_VENDOR := $(addprefix vendor/, $(GO_TOOLS)) |
| 46 | |
| 47 | TEST_PACKAGES := github.com/opencord/bbsim/cmd/... \ |
| 48 | github.com/opencord/bbsim/internal/... |
| 49 | |
| 50 | setup_tools: $(GO_TOOLS_BIN) |
| 51 | |
| 52 | $(GO_TOOLS_BIN): $(GO_TOOLS_VENDOR) |
Matteo Scandolo | a6a3aee | 2019-11-26 13:30:14 -0700 | [diff] [blame] | 53 | GO111MODULE=on GOBIN="$(PWD)/$(TOOLS_BIN)" go install $(GO_TOOLS) |
Zdravko Bozakov | 2da7634 | 2019-10-21 09:47:35 +0200 | [diff] [blame] | 54 | |
Matteo Scandolo | 3de9de0 | 2019-11-14 13:40:03 -0800 | [diff] [blame] | 55 | protos: 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] | 56 | |
Matteo Scandolo | a6a3aee | 2019-11-26 13:30:14 -0700 | [diff] [blame] | 57 | dep: protos # @HELP Download the dependencies to the vendor folder |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame] | 58 | GO111MODULE=on go mod vendor |
Matteo Scandolo | a6a3aee | 2019-11-26 13:30:14 -0700 | [diff] [blame] | 59 | GO111MODULE=on go mod tidy |
| 60 | GO111MODULE=on go mod verify |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame] | 61 | |
Matteo Scandolo | 01d41ce | 2019-10-28 15:42:47 -0700 | [diff] [blame] | 62 | _build: dep protos fmt build-bbsim build-bbsimctl build-bbr |
| 63 | |
Matteo Scandolo | 6866b8c | 2019-10-28 16:15:24 -0700 | [diff] [blame] | 64 | .PHONY: build |
Matteo Scandolo | 01d41ce | 2019-10-28 15:42:47 -0700 | [diff] [blame] | 65 | build: # @HELP Build the binaries (it runs inside a docker container and output the built code on your local file system) |
| 66 | 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] | 67 | 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] | 68 | |
Matteo Scandolo | 569e717 | 2019-12-20 11:51:51 -0800 | [diff] [blame] | 69 | test: test-unit test-bbr |
| 70 | |
| 71 | test-unit: clean dep fmt # @HELP Execute unit tests |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 72 | GO111MODULE=on go test -v -mod vendor $(TEST_PACKAGES) -timeout 10s -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] | 73 | go-junit-report < ./tests/results/go-test-results.out > ./tests/results/go-test-results.xml |
| 74 | 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] | 75 | |
Matteo Scandolo | 569e717 | 2019-12-20 11:51:51 -0800 | [diff] [blame] | 76 | test-bbr: build-bbr docker-build # @HELP Validate that BBSim and BBR are working together |
| 77 | DOCKER_RUN_ARGS="-auth -dhcp" make docker-run |
| 78 | sleep 5 |
| 79 | ./bbr |
| 80 | docker rm -f bbsim |
| 81 | |
Matteo Scandolo | 3830549 | 2019-10-11 11:36:00 -0700 | [diff] [blame] | 82 | fmt: |
| 83 | go fmt ./... |
| 84 | |
Matteo Scandolo | ca08fc7 | 2019-12-04 14:17:39 -0800 | [diff] [blame] | 85 | docker-build: local-omci-sim# @HELP Build the BBSim docker container (contains BBSimCtl too) |
Matteo Scandolo | 82c16d0 | 2019-09-24 09:34:32 -0700 | [diff] [blame] | 86 | 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] | 87 | |
Matteo Scandolo | 01d41ce | 2019-10-28 15:42:47 -0700 | [diff] [blame] | 88 | docker-push: # @HELP Push the docker container to a registry |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 89 | docker push ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim:${DOCKER_TAG} |
| 90 | |
Andrea Campanella | 64dffd5 | 2019-12-17 17:29:57 -0800 | [diff] [blame] | 91 | docker-kind-load: |
| 92 | @if [ "`kind get clusters | grep voltha-$(TYPE)`" = '' ]; then echo "no voltha-$(TYPE) cluster found" && exit 1; fi |
| 93 | kind load docker-image ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim:${DOCKER_TAG} --name=voltha-$(TYPE) --nodes $(shell kubectl get nodes --template='{{range .items}}{{.metadata.name}},{{end}}' | sed 's/,$$//') |
| 94 | |
Matteo Scandolo | e383d5d | 2019-10-25 14:47:27 -0700 | [diff] [blame] | 95 | 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] | 96 | 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] | 97 | |
Matteo Scandolo | e383d5d | 2019-10-25 14:47:27 -0700 | [diff] [blame] | 98 | 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] | 99 | 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] | 100 | |
Zack Williams | 4b0ef4d | 2019-12-18 14:25:20 -0700 | [diff] [blame] | 101 | .PHONY: docs docs-lint |
Zdravko Bozakov | 2da7634 | 2019-10-21 09:47:35 +0200 | [diff] [blame] | 102 | docs: swagger # @HELP Generate docs and opens them in the browser |
Zack Williams | 4b0ef4d | 2019-12-18 14:25:20 -0700 | [diff] [blame] | 103 | make -C docs html |
Zdravko Bozakov | 2da7634 | 2019-10-21 09:47:35 +0200 | [diff] [blame] | 104 | @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] | 105 | |
Zack Williams | 4b0ef4d | 2019-12-18 14:25:20 -0700 | [diff] [blame] | 106 | docs-lint: |
| 107 | make -C docs lint |
| 108 | |
Matteo Scandolo | 8dea399 | 2019-10-22 10:54:25 -0700 | [diff] [blame] | 109 | # Release related items |
| 110 | # Generates binaries in $RELEASE_DIR with name $RELEASE_NAME-$RELEASE_OS_ARCH |
| 111 | # Inspired by: https://github.com/kubernetes/minikube/releases |
| 112 | RELEASE_DIR ?= release |
| 113 | RELEASE_OS_ARCH ?= linux-amd64 linux-arm64 windows-amd64 darwin-amd64 |
| 114 | |
| 115 | RELEASE_BBR_NAME ?= bbr |
| 116 | RELEASE_BBR_BINS := $(foreach rel,$(RELEASE_OS_ARCH),$(RELEASE_DIR)/$(RELEASE_BBR_NAME)-$(rel)) |
| 117 | RELEASE_BBSIM_NAME ?= bbsimctl |
| 118 | RELEASE_BBSIM_BINS := $(foreach rel,$(RELEASE_OS_ARCH),$(RELEASE_DIR)/$(RELEASE_BBSIM_NAME)-$(rel)) |
| 119 | |
| 120 | $(RELEASE_BBR_BINS): |
| 121 | export GOOS=$(rel_os) ;\ |
| 122 | export GOARCH=$(rel_arch) ;\ |
| 123 | GO111MODULE=on go build -i -v -mod vendor \ |
| 124 | -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] | 125 | -X main.gitStatus=${GIT_STATUS} \ |
| 126 | -X main.version=${VERSION}" \ |
| 127 | -o "$@" ./cmd/bbr |
| 128 | |
| 129 | $(RELEASE_BBSIM_BINS): |
| 130 | export GOOS=$(rel_os) ;\ |
| 131 | export GOARCH=$(rel_arch) ;\ |
| 132 | GO111MODULE=on go build -i -v -mod vendor \ |
| 133 | -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] | 134 | -X main.gitStatus=${GIT_STATUS} \ |
| 135 | -X main.version=${VERSION}" \ |
| 136 | -o "$@" ./cmd/bbsim |
| 137 | |
| 138 | .PHONY: release $(RELEASE_BBR_BINS) $(RELEASE_BBSIM_BINS) |
Matteo Scandolo | 01d41ce | 2019-10-28 15:42:47 -0700 | [diff] [blame] | 139 | 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] | 140 | 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] | 141 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 142 | help: # @HELP Print the command options |
| 143 | @echo |
| 144 | @echo "\033[0;31m BroadBand Simulator (BBSim) \033[0m" |
| 145 | @echo |
| 146 | @echo Emulates the control plane of an openolt compatible device |
| 147 | @echo Useful for development and scale testing |
| 148 | @echo |
| 149 | @grep -E '^.*: .* *# *@HELP' $(MAKEFILE_LIST) \ |
| 150 | | sort \ |
| 151 | | awk ' \ |
| 152 | BEGIN {FS = ": .* *# *@HELP"}; \ |
| 153 | {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}; \ |
| 154 | ' |
| 155 | |
Matteo Scandolo | ca08fc7 | 2019-12-04 14:17:39 -0800 | [diff] [blame] | 156 | ## Local Development Helpers |
| 157 | local-omci-sim: |
| 158 | ifdef LOCAL_OMCI_SIM |
| 159 | mkdir -p vendor/github.com/opencord/omci-sim/ |
| 160 | cp -r ${LOCAL_OMCI_SIM}/* vendor/github.com/opencord/omci-sim/ |
| 161 | endif |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 162 | |
| 163 | # Internals |
Matteo Scandolo | 8dea399 | 2019-10-22 10:54:25 -0700 | [diff] [blame] | 164 | |
Matteo Scandolo | 3de9de0 | 2019-11-14 13:40:03 -0800 | [diff] [blame] | 165 | clean: |
Matteo Scandolo | 3de9de0 | 2019-11-14 13:40:03 -0800 | [diff] [blame] | 166 | rm -f bbsim |
| 167 | rm -f bbsimctl |
| 168 | rm -f bbr |
| 169 | rm -rf tools/bin |
Matteo Scandolo | 3de9de0 | 2019-11-14 13:40:03 -0800 | [diff] [blame] | 170 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 171 | build-bbr: |
| 172 | GO111MODULE=on go build -i -v -mod vendor \ |
| 173 | -ldflags "-w -X main.buildTime=$(shell date +”%Y/%m/%d-%H:%M:%S”) \ |
| 174 | -X main.commitHash=$(shell git log --pretty=format:%H -n 1) \ |
| 175 | -X main.gitStatus=${GIT_STATUS} \ |
| 176 | -X main.version=${VERSION}" \ |
| 177 | ./cmd/bbr |
| 178 | |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 179 | build-bbsim: |
| 180 | GO111MODULE=on go build -i -v -mod vendor \ |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 181 | -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] | 182 | -X main.commitHash=$(shell git log --pretty=format:%H -n 1) \ |
| 183 | -X main.gitStatus=${GIT_STATUS} \ |
| 184 | -X main.version=${VERSION}" \ |
Matteo Scandolo | 82c16d0 | 2019-09-24 09:34:32 -0700 | [diff] [blame] | 185 | ./cmd/bbsim |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 186 | |
| 187 | build-bbsimctl: |
| 188 | GO111MODULE=on go build -i -v -mod vendor \ |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 189 | -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] | 190 | -X github.com/opencord/bbsim/internal/bbsimctl/config.CommitHash=$(shell git log --pretty=format:%H -n 1) \ |
| 191 | -X github.com/opencord/bbsim/internal/bbsimctl/config.GitStatus=${GIT_STATUS} \ |
| 192 | -X github.com/opencord/bbsim/internal/bbsimctl/config.Version=${VERSION}" \ |
| 193 | ./cmd/bbsimctl |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 194 | |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 195 | api/openolt/openolt.pb.go: api/openolt/openolt.proto |
Zdravko Bozakov | 2da7634 | 2019-10-21 09:47:35 +0200 | [diff] [blame] | 196 | @protoc -I. \ |
| 197 | -I${GOOGLEAPI}/third_party/googleapis \ |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 198 | --go_out=plugins=grpc:./ \ |
| 199 | $< |
| 200 | |
Zdravko Bozakov | 2da7634 | 2019-10-21 09:47:35 +0200 | [diff] [blame] | 201 | api/bbsim/bbsim.pb.go api/bbsim/bbsim.pb.gw.go: api/bbsim/bbsim.proto api/bbsim/bbsim.yaml |
| 202 | @protoc -I. \ |
| 203 | -I${GOOGLEAPI}/third_party/googleapis \ |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 204 | --go_out=plugins=grpc:./ \ |
Zdravko Bozakov | 2da7634 | 2019-10-21 09:47:35 +0200 | [diff] [blame] | 205 | --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] | 206 | $< |
| 207 | |
Zdravko Bozakov | 2da7634 | 2019-10-21 09:47:35 +0200 | [diff] [blame] | 208 | api/legacy/bbsim.pb.go api/legacy/bbsim.pb.gw.go: api/legacy/bbsim.proto |
| 209 | @protoc -I. \ |
| 210 | -I${GOOGLEAPI}/third_party/googleapis/ \ |
| 211 | -I${GOOGLEAPI}/ \ |
| 212 | -I${VOLTHA_PROTOS}/protos/ \ |
| 213 | --go_out=plugins=grpc:./ \ |
| 214 | --grpc-gateway_out=logtostderr=true,allow_delete_body=true:./ \ |
| 215 | $< |
| 216 | |
| 217 | docs/swagger/bbsim/bbsim.swagger.json: api/bbsim/bbsim.yaml |
| 218 | @protoc -I ./api \ |
| 219 | -I${GOOGLEAPI}/ \ |
| 220 | -I${VOLTHA_PROTOS}/protos/ \ |
| 221 | --swagger_out=logtostderr=true,allow_delete_body=true,grpc_api_configuration=$<:docs/swagger/ \ |
| 222 | api/bbsim/bbsim.proto |
| 223 | |
| 224 | docs/swagger/leagacy/bbsim.swagger.json: api/legacy/bbsim.proto |
| 225 | @protoc -I ./api \ |
| 226 | -I${GOOGLEAPI}/ \ |
| 227 | -I${VOLTHA_PROTOS}/protos/ \ |
| 228 | --swagger_out=logtostderr=true,allow_delete_body=true:docs/swagger/ \ |
Andrea Campanella | 64dffd5 | 2019-12-17 17:29:57 -0800 | [diff] [blame] | 229 | $< |