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) |
| 17 | GIT_STATUS ?= $(shell [[ $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 ?= "" |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 24 | |
| 25 | # Public targets |
| 26 | |
| 27 | all: help |
| 28 | |
Matteo Scandolo | d54283a | 2019-08-13 16:22:31 -0700 | [diff] [blame] | 29 | protos: api/bbsim/bbsim.pb.go # @HELP Build proto files |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 30 | |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame] | 31 | dep: # @HELP Download the dependencies to the vendor folder |
| 32 | GO111MODULE=on go mod vendor |
| 33 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 34 | build: dep protos fmt build-bbsim build-bbsimctl build-bbr # @HELP Build the binary |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 35 | |
William Kurkian | c7966c7 | 2019-10-16 14:00:00 -0400 | [diff] [blame] | 36 | test: dep protos fmt # @HELP Execute unit tests |
Matteo Scandolo | 2bf742a | 2019-10-01 11:33:34 -0700 | [diff] [blame] | 37 | GO111MODULE=on go test -v -mod vendor ./... -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] | 38 | go-junit-report < ./tests/results/go-test-results.out > ./tests/results/go-test-results.xml |
| 39 | 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] | 40 | |
Matteo Scandolo | 3830549 | 2019-10-11 11:36:00 -0700 | [diff] [blame] | 41 | fmt: |
| 42 | go fmt ./... |
| 43 | |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 44 | docker-build: # @HELP Build a docker container |
Matteo Scandolo | 82c16d0 | 2019-09-24 09:34:32 -0700 | [diff] [blame] | 45 | 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] | 46 | |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 47 | docker-push: # @HELP Push a docker container to a registry |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 48 | docker push ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim:${DOCKER_TAG} |
| 49 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 50 | docker-run: # @HELP Run the container locally (intended for development purposes: DOCKER_RUN_ARGS="-pon 2 -onu 2" make docker-run) |
Matteo Scandolo | ecbd6a1 | 2019-10-21 10:51:03 -0700 | [diff] [blame] | 51 | docker run -d -p 50070:50070 -p 50060:50060 --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] | 52 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 53 | .PHONY: docs |
| 54 | docs: # @HELP Generate docs and serve them in the browser |
| 55 | @echo "\033[36m Open your browser at localhost:6060 \033[0m" |
| 56 | godoc -http=localhost:6060 |
| 57 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 58 | help: # @HELP Print the command options |
| 59 | @echo |
| 60 | @echo "\033[0;31m BroadBand Simulator (BBSim) \033[0m" |
| 61 | @echo |
| 62 | @echo Emulates the control plane of an openolt compatible device |
| 63 | @echo Useful for development and scale testing |
| 64 | @echo |
| 65 | @grep -E '^.*: .* *# *@HELP' $(MAKEFILE_LIST) \ |
| 66 | | sort \ |
| 67 | | awk ' \ |
| 68 | BEGIN {FS = ": .* *# *@HELP"}; \ |
| 69 | {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}; \ |
| 70 | ' |
| 71 | |
| 72 | |
| 73 | # Internals |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 74 | build-bbr: |
| 75 | GO111MODULE=on go build -i -v -mod vendor \ |
| 76 | -ldflags "-w -X main.buildTime=$(shell date +”%Y/%m/%d-%H:%M:%S”) \ |
| 77 | -X main.commitHash=$(shell git log --pretty=format:%H -n 1) \ |
| 78 | -X main.gitStatus=${GIT_STATUS} \ |
| 79 | -X main.version=${VERSION}" \ |
| 80 | ./cmd/bbr |
| 81 | |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 82 | build-bbsim: |
| 83 | GO111MODULE=on go build -i -v -mod vendor \ |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 84 | -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] | 85 | -X main.commitHash=$(shell git log --pretty=format:%H -n 1) \ |
| 86 | -X main.gitStatus=${GIT_STATUS} \ |
| 87 | -X main.version=${VERSION}" \ |
Matteo Scandolo | 82c16d0 | 2019-09-24 09:34:32 -0700 | [diff] [blame] | 88 | ./cmd/bbsim |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 89 | |
| 90 | build-bbsimctl: |
| 91 | GO111MODULE=on go build -i -v -mod vendor \ |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 92 | -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] | 93 | -X github.com/opencord/bbsim/internal/bbsimctl/config.CommitHash=$(shell git log --pretty=format:%H -n 1) \ |
| 94 | -X github.com/opencord/bbsim/internal/bbsimctl/config.GitStatus=${GIT_STATUS} \ |
| 95 | -X github.com/opencord/bbsim/internal/bbsimctl/config.Version=${VERSION}" \ |
| 96 | ./cmd/bbsimctl |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 97 | |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 98 | api/openolt/openolt.pb.go: api/openolt/openolt.proto |
| 99 | @protoc -I . \ |
| 100 | -I${GOPATH}/src \ |
| 101 | -I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \ |
| 102 | --go_out=plugins=grpc:./ \ |
| 103 | $< |
| 104 | |
| 105 | api/bbsim/bbsim.pb.go: api/bbsim/bbsim.proto |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 106 | @protoc -I . \ |
| 107 | -I${GOPATH}/src \ |
| 108 | -I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \ |
| 109 | --go_out=plugins=grpc:./ \ |
| 110 | $< |
| 111 | |