blob: 9a642e964eeaddc219f9529f9a803e4e2f89a33c [file] [log] [blame]
Matteo Scandolo4747d292019-08-05 11:50:18 -07001# 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
15VERSION ?= $(shell cat ./VERSION)
Matteo Scandolo84f7d482019-08-08 19:00:47 -070016DIFF ?= $(git diff --shortstat 2> /dev/null | tail -n1)
Zdravko Bozakov2da76342019-10-21 09:47:35 +020017GIT_STATUS ?= $(shell [ -z "$DIFF" ] && echo "Dirty" || echo "Clean")
Matteo Scandolo4747d292019-08-05 11:50:18 -070018
19## Docker related
20DOCKER_TAG ?= ${VERSION}
Matteo Scandolo5daa2ab2019-10-08 08:27:18 -070021DOCKER_REPOSITORY ?= ""
Matteo Scandolo4747d292019-08-05 11:50:18 -070022DOCKER_REGISTRY ?= ""
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -070023DOCKER_RUN_ARGS ?= ""
Zdravko Bozakov2da76342019-10-21 09:47:35 +020024DOCKER_PORTS ?= -p 50070:50070 -p 50060:50060 -p 50071:50071 -p 50072:50072 -p 50073:50073
25
26## protobuf related
Matteo Scandolo3de9de02019-11-14 13:40:03 -080027VOLTHA_PROTOS ?= $(shell GO111MODULE=on go list -f '{{ .Dir }}' -m github.com/opencord/voltha-protos/v2)
Zdravko Bozakov2da76342019-10-21 09:47:35 +020028GOOGLEAPI ?= $(shell GO111MODULE=on go list -f '{{ .Dir }}' -m github.com/grpc-ecosystem/grpc-gateway)
29TOOLS_DIR := tools
30TOOLS_BIN := $(TOOLS_DIR)/bin/
31
32export PATH=$(shell echo $$PATH):$(PWD)/$(TOOLS_BIN)
Matteo Scandolo4747d292019-08-05 11:50:18 -070033
34# Public targets
Matteo Scandolo4747d292019-08-05 11:50:18 -070035all: help
36
Zdravko Bozakov2da76342019-10-21 09:47:35 +020037# go installed tools.go
38GO_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
43GO_TOOLS_BIN := $(addprefix $(TOOLS_BIN), $(notdir $(GO_TOOLS)))
44GO_TOOLS_VENDOR := $(addprefix vendor/, $(GO_TOOLS))
45
46TEST_PACKAGES := github.com/opencord/bbsim/cmd/... \
47 github.com/opencord/bbsim/internal/...
48
49setup_tools: $(GO_TOOLS_BIN)
50
51$(GO_TOOLS_BIN): $(GO_TOOLS_VENDOR)
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -070052 GO111MODULE=on GOBIN="$(PWD)/$(TOOLS_BIN)" go install $(GO_TOOLS)
Zdravko Bozakov2da76342019-10-21 09:47:35 +020053
Matteo Scandolo3de9de02019-11-14 13:40:03 -080054protos: 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 Scandolo4747d292019-08-05 11:50:18 -070055
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -070056dep: protos # @HELP Download the dependencies to the vendor folder
Matteo Scandolo11006992019-08-28 11:29:46 -070057 GO111MODULE=on go mod vendor
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -070058 GO111MODULE=on go mod tidy
59 GO111MODULE=on go mod verify
Matteo Scandolo11006992019-08-28 11:29:46 -070060
Matteo Scandolo01d41ce2019-10-28 15:42:47 -070061_build: dep protos fmt build-bbsim build-bbsimctl build-bbr
62
Matteo Scandolo6866b8c2019-10-28 16:15:24 -070063.PHONY: build
Matteo Scandolo01d41ce2019-10-28 15:42:47 -070064build: # @HELP Build the binaries (it runs inside a docker container and output the built code on your local file system)
65 docker build -t ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim-builder:${DOCKER_TAG} -f build/ci/Dockerfile.builder .
Matteo Scandolod49da292019-10-28 16:30:51 -070066 docker run --rm -v $(shell pwd):/bbsim ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim-builder:${DOCKER_TAG} /bin/sh -c "cd /bbsim; make _build"
Matteo Scandolo4747d292019-08-05 11:50:18 -070067
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -070068test: clean dep fmt # @HELP Execute unit tests
Zdravko Bozakov2da76342019-10-21 09:47:35 +020069 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 Scandolo11006992019-08-28 11:29:46 -070070 go-junit-report < ./tests/results/go-test-results.out > ./tests/results/go-test-results.xml
71 gocover-cobertura < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml
Matteo Scandolo4747d292019-08-05 11:50:18 -070072
Matteo Scandolo38305492019-10-11 11:36:00 -070073fmt:
74 go fmt ./...
75
Matteo Scandolo01d41ce2019-10-28 15:42:47 -070076docker-build: # @HELP Build the BBSim docker container (contains BBSimCtl too)
Matteo Scandolo82c16d02019-09-24 09:34:32 -070077 docker build -t ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim:${DOCKER_TAG} -f build/package/Dockerfile .
Matteo Scandolo4747d292019-08-05 11:50:18 -070078
Matteo Scandolo01d41ce2019-10-28 15:42:47 -070079docker-push: # @HELP Push the docker container to a registry
Matteo Scandolo4747d292019-08-05 11:50:18 -070080 docker push ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim:${DOCKER_TAG}
81
Matteo Scandoloe383d5d2019-10-25 14:47:27 -070082docker-run: # @HELP Runs the container locally (available options: DOCKER_RUN_ARGS="-pon 2 -onu 2" make docker-run)
Zdravko Bozakov2da76342019-10-21 09:47:35 +020083 docker run -d ${DOCKER_PORTS} --privileged --rm --name bbsim ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim:${DOCKER_TAG} /app/bbsim ${DOCKER_RUN_ARGS}
Matteo Scandolo4b3fc7e2019-09-17 16:49:54 -070084
Matteo Scandoloe383d5d2019-10-25 14:47:27 -070085docker-run-dev: # @HELP Runs the container locally (intended for development purposes, not in detached mode)
Zdravko Bozakov2da76342019-10-21 09:47:35 +020086 docker run ${DOCKER_PORTS} --privileged --rm --name bbsim ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim:${DOCKER_TAG} /app/bbsim ${DOCKER_RUN_ARGS}
Matteo Scandoloe383d5d2019-10-25 14:47:27 -070087
Matteo Scandolo40e067f2019-10-16 16:59:41 -070088.PHONY: docs
Zdravko Bozakov2da76342019-10-21 09:47:35 +020089docs: swagger # @HELP Generate docs and opens them in the browser
90 cd docs; make doc_venv; make html; cd -
91 @echo -e "\nBBSim documentation generated in file://${PWD}/docs/build/html/index.html"
Matteo Scandolo40e067f2019-10-16 16:59:41 -070092
Matteo Scandolo8dea3992019-10-22 10:54:25 -070093# Release related items
94# Generates binaries in $RELEASE_DIR with name $RELEASE_NAME-$RELEASE_OS_ARCH
95# Inspired by: https://github.com/kubernetes/minikube/releases
96RELEASE_DIR ?= release
97RELEASE_OS_ARCH ?= linux-amd64 linux-arm64 windows-amd64 darwin-amd64
98
99RELEASE_BBR_NAME ?= bbr
100RELEASE_BBR_BINS := $(foreach rel,$(RELEASE_OS_ARCH),$(RELEASE_DIR)/$(RELEASE_BBR_NAME)-$(rel))
101RELEASE_BBSIM_NAME ?= bbsimctl
102RELEASE_BBSIM_BINS := $(foreach rel,$(RELEASE_OS_ARCH),$(RELEASE_DIR)/$(RELEASE_BBSIM_NAME)-$(rel))
103
104$(RELEASE_BBR_BINS):
105 export GOOS=$(rel_os) ;\
106 export GOARCH=$(rel_arch) ;\
107 GO111MODULE=on go build -i -v -mod vendor \
108 -ldflags "-w -X main.buildTime=$(shell date +”%Y/%m/%d-%H:%M:%S”) \
Matteo Scandolo8dea3992019-10-22 10:54:25 -0700109 -X main.gitStatus=${GIT_STATUS} \
110 -X main.version=${VERSION}" \
111 -o "$@" ./cmd/bbr
112
113$(RELEASE_BBSIM_BINS):
114 export GOOS=$(rel_os) ;\
115 export GOARCH=$(rel_arch) ;\
116 GO111MODULE=on go build -i -v -mod vendor \
117 -ldflags "-w -X main.buildTime=$(shell date +”%Y/%m/%d-%H:%M:%S”) \
Matteo Scandolo8dea3992019-10-22 10:54:25 -0700118 -X main.gitStatus=${GIT_STATUS} \
119 -X main.version=${VERSION}" \
120 -o "$@" ./cmd/bbsim
121
122.PHONY: release $(RELEASE_BBR_BINS) $(RELEASE_BBSIM_BINS)
Matteo Scandolo01d41ce2019-10-28 15:42:47 -0700123release: dep protos $(RELEASE_BBR_BINS) $(RELEASE_BBSIM_BINS) # @HELP Creates release ready bynaries for BBSimctl and BBR artifacts
Zdravko Bozakov2da76342019-10-21 09:47:35 +0200124swagger: docs/swagger/bbsim/bbsim.swagger.json docs/swagger/leagacy/bbsim.swagger.json # @HELP Generate swagger documentation for BBSim API
Matteo Scandolo8dea3992019-10-22 10:54:25 -0700125
Matteo Scandolo4747d292019-08-05 11:50:18 -0700126help: # @HELP Print the command options
127 @echo
128 @echo "\033[0;31m BroadBand Simulator (BBSim) \033[0m"
129 @echo
130 @echo Emulates the control plane of an openolt compatible device
131 @echo Useful for development and scale testing
132 @echo
133 @grep -E '^.*: .* *# *@HELP' $(MAKEFILE_LIST) \
134 | sort \
135 | awk ' \
136 BEGIN {FS = ": .* *# *@HELP"}; \
137 {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}; \
138 '
139
140
141# Internals
Matteo Scandolo8dea3992019-10-22 10:54:25 -0700142
Matteo Scandolo3de9de02019-11-14 13:40:03 -0800143clean:
Matteo Scandolo3de9de02019-11-14 13:40:03 -0800144 rm -f bbsim
145 rm -f bbsimctl
146 rm -f bbr
147 rm -rf tools/bin
Matteo Scandolo3de9de02019-11-14 13:40:03 -0800148
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700149build-bbr:
150 GO111MODULE=on go build -i -v -mod vendor \
151 -ldflags "-w -X main.buildTime=$(shell date +”%Y/%m/%d-%H:%M:%S”) \
152 -X main.commitHash=$(shell git log --pretty=format:%H -n 1) \
153 -X main.gitStatus=${GIT_STATUS} \
154 -X main.version=${VERSION}" \
155 ./cmd/bbr
156
Matteo Scandolo8df63df2019-09-12 10:34:32 -0700157build-bbsim:
158 GO111MODULE=on go build -i -v -mod vendor \
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700159 -ldflags "-w -X main.buildTime=$(shell date +”%Y/%m/%d-%H:%M:%S”) \
Matteo Scandolo8df63df2019-09-12 10:34:32 -0700160 -X main.commitHash=$(shell git log --pretty=format:%H -n 1) \
161 -X main.gitStatus=${GIT_STATUS} \
162 -X main.version=${VERSION}" \
Matteo Scandolo82c16d02019-09-24 09:34:32 -0700163 ./cmd/bbsim
Matteo Scandolo8df63df2019-09-12 10:34:32 -0700164
165build-bbsimctl:
166 GO111MODULE=on go build -i -v -mod vendor \
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700167 -ldflags "-w -X github.com/opencord/bbsim/internal/bbsimctl/config.BuildTime=$(shell date +”%Y/%m/%d-%H:%M:%S”) \
Matteo Scandolo82c16d02019-09-24 09:34:32 -0700168 -X github.com/opencord/bbsim/internal/bbsimctl/config.CommitHash=$(shell git log --pretty=format:%H -n 1) \
169 -X github.com/opencord/bbsim/internal/bbsimctl/config.GitStatus=${GIT_STATUS} \
170 -X github.com/opencord/bbsim/internal/bbsimctl/config.Version=${VERSION}" \
171 ./cmd/bbsimctl
Matteo Scandolo4747d292019-08-05 11:50:18 -0700172
Matteo Scandolo84f7d482019-08-08 19:00:47 -0700173api/openolt/openolt.pb.go: api/openolt/openolt.proto
Zdravko Bozakov2da76342019-10-21 09:47:35 +0200174 @protoc -I. \
175 -I${GOOGLEAPI}/third_party/googleapis \
Matteo Scandolo84f7d482019-08-08 19:00:47 -0700176 --go_out=plugins=grpc:./ \
177 $<
178
Zdravko Bozakov2da76342019-10-21 09:47:35 +0200179api/bbsim/bbsim.pb.go api/bbsim/bbsim.pb.gw.go: api/bbsim/bbsim.proto api/bbsim/bbsim.yaml
180 @protoc -I. \
181 -I${GOOGLEAPI}/third_party/googleapis \
Matteo Scandolo4747d292019-08-05 11:50:18 -0700182 --go_out=plugins=grpc:./ \
Zdravko Bozakov2da76342019-10-21 09:47:35 +0200183 --grpc-gateway_out=logtostderr=true,grpc_api_configuration=api/bbsim/bbsim.yaml,allow_delete_body=true:./ \
Matteo Scandolo4747d292019-08-05 11:50:18 -0700184 $<
185
Zdravko Bozakov2da76342019-10-21 09:47:35 +0200186api/legacy/bbsim.pb.go api/legacy/bbsim.pb.gw.go: api/legacy/bbsim.proto
187 @protoc -I. \
188 -I${GOOGLEAPI}/third_party/googleapis/ \
189 -I${GOOGLEAPI}/ \
190 -I${VOLTHA_PROTOS}/protos/ \
191 --go_out=plugins=grpc:./ \
192 --grpc-gateway_out=logtostderr=true,allow_delete_body=true:./ \
193 $<
194
195docs/swagger/bbsim/bbsim.swagger.json: api/bbsim/bbsim.yaml
196 @protoc -I ./api \
197 -I${GOOGLEAPI}/ \
198 -I${VOLTHA_PROTOS}/protos/ \
199 --swagger_out=logtostderr=true,allow_delete_body=true,grpc_api_configuration=$<:docs/swagger/ \
200 api/bbsim/bbsim.proto
201
202docs/swagger/leagacy/bbsim.swagger.json: api/legacy/bbsim.proto
203 @protoc -I ./api \
204 -I${GOOGLEAPI}/ \
205 -I${VOLTHA_PROTOS}/protos/ \
206 --swagger_out=logtostderr=true,allow_delete_body=true:docs/swagger/ \
207 $<