blob: c92ae3914dd13a8af04ad9b74861c843d73c4a08 [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 Bozakov958d81c2019-12-13 22:09:48 +010024DOCKER_PORTS ?= -p 50070:50070 -p 50060:50060 -p 50071:50071 -p 50072:50072 -p 50073:50073 -p 50074:50074
Andrea Campanella64dffd52019-12-17 17:29:57 -080025TYPE ?= minimal
Zdravko Bozakov2da76342019-10-21 09:47:35 +020026
27## protobuf related
Matteo Scandolo3de9de02019-11-14 13:40:03 -080028VOLTHA_PROTOS ?= $(shell GO111MODULE=on go list -f '{{ .Dir }}' -m github.com/opencord/voltha-protos/v2)
Zdravko Bozakov2da76342019-10-21 09:47:35 +020029GOOGLEAPI ?= $(shell GO111MODULE=on go list -f '{{ .Dir }}' -m github.com/grpc-ecosystem/grpc-gateway)
30TOOLS_DIR := tools
31TOOLS_BIN := $(TOOLS_DIR)/bin/
32
33export PATH=$(shell echo $$PATH):$(PWD)/$(TOOLS_BIN)
Matteo Scandolo4747d292019-08-05 11:50:18 -070034
35# Public targets
Matteo Scandolo4747d292019-08-05 11:50:18 -070036all: help
37
Zdravko Bozakov2da76342019-10-21 09:47:35 +020038# go installed tools.go
39GO_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
44GO_TOOLS_BIN := $(addprefix $(TOOLS_BIN), $(notdir $(GO_TOOLS)))
45GO_TOOLS_VENDOR := $(addprefix vendor/, $(GO_TOOLS))
46
47TEST_PACKAGES := github.com/opencord/bbsim/cmd/... \
48 github.com/opencord/bbsim/internal/...
49
50setup_tools: $(GO_TOOLS_BIN)
Anand S Katti09541352020-01-29 15:54:01 +053051 GO111MODULE=on go mod download all
Zdravko Bozakov2da76342019-10-21 09:47:35 +020052
53$(GO_TOOLS_BIN): $(GO_TOOLS_VENDOR)
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -070054 GO111MODULE=on GOBIN="$(PWD)/$(TOOLS_BIN)" go install $(GO_TOOLS)
Zdravko Bozakov2da76342019-10-21 09:47:35 +020055
Matteo Scandolo3de9de02019-11-14 13:40:03 -080056protos: 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 -070057
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -070058dep: protos # @HELP Download the dependencies to the vendor folder
Matteo Scandolo11006992019-08-28 11:29:46 -070059 GO111MODULE=on go mod vendor
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -070060 GO111MODULE=on go mod tidy
61 GO111MODULE=on go mod verify
Matteo Scandolo11006992019-08-28 11:29:46 -070062
Matteo Scandolo01d41ce2019-10-28 15:42:47 -070063_build: dep protos fmt build-bbsim build-bbsimctl build-bbr
64
Matteo Scandolo6866b8c2019-10-28 16:15:24 -070065.PHONY: build
Matteo Scandolo01d41ce2019-10-28 15:42:47 -070066build: # @HELP Build the binaries (it runs inside a docker container and output the built code on your local file system)
67 docker build -t ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim-builder:${DOCKER_TAG} -f build/ci/Dockerfile.builder .
Matteo Scandolod49da292019-10-28 16:30:51 -070068 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 -070069
Matteo Scandolo569e7172019-12-20 11:51:51 -080070test: test-unit test-bbr
71
Matteo Scandolodf3f85d2020-01-15 12:50:48 -080072test-unit: clean dep fmt local-omci-sim # @HELP Execute unit tests
Zdravko Bozakov681364d2019-11-10 14:28:46 +010073 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 Scandolo11006992019-08-28 11:29:46 -070074 go-junit-report < ./tests/results/go-test-results.out > ./tests/results/go-test-results.xml
75 gocover-cobertura < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml
Matteo Scandolo4747d292019-08-05 11:50:18 -070076
Matteo Scandolo569e7172019-12-20 11:51:51 -080077test-bbr: build-bbr docker-build # @HELP Validate that BBSim and BBR are working together
Matteo Scandolo583f17d2020-02-13 10:35:17 -080078 DOCKER_RUN_ARGS="-auth -dhcp -pon 2 -onu 2" make docker-run
Matteo Scandolo569e7172019-12-20 11:51:51 -080079 sleep 5
Matteo Scandolo583f17d2020-02-13 10:35:17 -080080 ./bbr -pon 2 -onu 2
Matteo Scandolo569e7172019-12-20 11:51:51 -080081 docker rm -f bbsim
82
Matteo Scandolo38305492019-10-11 11:36:00 -070083fmt:
84 go fmt ./...
85
Matteo Scandoloca08fc72019-12-04 14:17:39 -080086docker-build: local-omci-sim# @HELP Build the BBSim docker container (contains BBSimCtl too)
Matteo Scandolo82c16d02019-09-24 09:34:32 -070087 docker build -t ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim:${DOCKER_TAG} -f build/package/Dockerfile .
Matteo Scandolo4747d292019-08-05 11:50:18 -070088
Matteo Scandolo01d41ce2019-10-28 15:42:47 -070089docker-push: # @HELP Push the docker container to a registry
Matteo Scandolo4747d292019-08-05 11:50:18 -070090 docker push ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim:${DOCKER_TAG}
91
Andrea Campanella64dffd52019-12-17 17:29:57 -080092docker-kind-load:
93 @if [ "`kind get clusters | grep voltha-$(TYPE)`" = '' ]; then echo "no voltha-$(TYPE) cluster found" && exit 1; fi
94 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/,$$//')
95
Matteo Scandoloe383d5d2019-10-25 14:47:27 -070096docker-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 +020097 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 -070098
Matteo Scandoloe383d5d2019-10-25 14:47:27 -070099docker-run-dev: # @HELP Runs the container locally (intended for development purposes, not in detached mode)
Zdravko Bozakov2da76342019-10-21 09:47:35 +0200100 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 -0700101
Zack Williams4b0ef4d2019-12-18 14:25:20 -0700102.PHONY: docs docs-lint
Zdravko Bozakov2da76342019-10-21 09:47:35 +0200103docs: swagger # @HELP Generate docs and opens them in the browser
Zack Williams4b0ef4d2019-12-18 14:25:20 -0700104 make -C docs html
Zdravko Bozakov2da76342019-10-21 09:47:35 +0200105 @echo -e "\nBBSim documentation generated in file://${PWD}/docs/build/html/index.html"
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700106
Zack Williams4b0ef4d2019-12-18 14:25:20 -0700107docs-lint:
108 make -C docs lint
109
Matteo Scandolo8dea3992019-10-22 10:54:25 -0700110# Release related items
111# Generates binaries in $RELEASE_DIR with name $RELEASE_NAME-$RELEASE_OS_ARCH
112# Inspired by: https://github.com/kubernetes/minikube/releases
113RELEASE_DIR ?= release
114RELEASE_OS_ARCH ?= linux-amd64 linux-arm64 windows-amd64 darwin-amd64
115
116RELEASE_BBR_NAME ?= bbr
117RELEASE_BBR_BINS := $(foreach rel,$(RELEASE_OS_ARCH),$(RELEASE_DIR)/$(RELEASE_BBR_NAME)-$(rel))
118RELEASE_BBSIM_NAME ?= bbsimctl
119RELEASE_BBSIM_BINS := $(foreach rel,$(RELEASE_OS_ARCH),$(RELEASE_DIR)/$(RELEASE_BBSIM_NAME)-$(rel))
120
121$(RELEASE_BBR_BINS):
122 export GOOS=$(rel_os) ;\
123 export GOARCH=$(rel_arch) ;\
124 GO111MODULE=on go build -i -v -mod vendor \
125 -ldflags "-w -X main.buildTime=$(shell date +”%Y/%m/%d-%H:%M:%S”) \
Matteo Scandolo8dea3992019-10-22 10:54:25 -0700126 -X main.gitStatus=${GIT_STATUS} \
127 -X main.version=${VERSION}" \
128 -o "$@" ./cmd/bbr
129
130$(RELEASE_BBSIM_BINS):
131 export GOOS=$(rel_os) ;\
132 export GOARCH=$(rel_arch) ;\
133 GO111MODULE=on go build -i -v -mod vendor \
134 -ldflags "-w -X main.buildTime=$(shell date +”%Y/%m/%d-%H:%M:%S”) \
Matteo Scandolo8dea3992019-10-22 10:54:25 -0700135 -X main.gitStatus=${GIT_STATUS} \
136 -X main.version=${VERSION}" \
137 -o "$@" ./cmd/bbsim
138
139.PHONY: release $(RELEASE_BBR_BINS) $(RELEASE_BBSIM_BINS)
Matteo Scandolo01d41ce2019-10-28 15:42:47 -0700140release: 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 +0200141swagger: 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 -0700142
Matteo Scandolo4747d292019-08-05 11:50:18 -0700143help: # @HELP Print the command options
144 @echo
145 @echo "\033[0;31m BroadBand Simulator (BBSim) \033[0m"
146 @echo
147 @echo Emulates the control plane of an openolt compatible device
148 @echo Useful for development and scale testing
149 @echo
150 @grep -E '^.*: .* *# *@HELP' $(MAKEFILE_LIST) \
151 | sort \
152 | awk ' \
153 BEGIN {FS = ": .* *# *@HELP"}; \
154 {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}; \
155 '
156
Matteo Scandoloca08fc72019-12-04 14:17:39 -0800157## Local Development Helpers
158local-omci-sim:
159ifdef LOCAL_OMCI_SIM
160 mkdir -p vendor/github.com/opencord/omci-sim/
161 cp -r ${LOCAL_OMCI_SIM}/* vendor/github.com/opencord/omci-sim/
162endif
Matteo Scandolo4747d292019-08-05 11:50:18 -0700163
164# Internals
Matteo Scandolo8dea3992019-10-22 10:54:25 -0700165
Matteo Scandolo3de9de02019-11-14 13:40:03 -0800166clean:
Matteo Scandolo3de9de02019-11-14 13:40:03 -0800167 rm -f bbsim
168 rm -f bbsimctl
169 rm -f bbr
170 rm -rf tools/bin
Matteo Scandolo3de9de02019-11-14 13:40:03 -0800171
Matteo Scandolodf3f85d2020-01-15 12:50:48 -0800172build-bbr: local-omci-sim
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700173 GO111MODULE=on go build -i -v -mod vendor \
174 -ldflags "-w -X main.buildTime=$(shell date +”%Y/%m/%d-%H:%M:%S”) \
175 -X main.commitHash=$(shell git log --pretty=format:%H -n 1) \
176 -X main.gitStatus=${GIT_STATUS} \
177 -X main.version=${VERSION}" \
178 ./cmd/bbr
179
Matteo Scandolo8df63df2019-09-12 10:34:32 -0700180build-bbsim:
181 GO111MODULE=on go build -i -v -mod vendor \
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700182 -ldflags "-w -X main.buildTime=$(shell date +”%Y/%m/%d-%H:%M:%S”) \
Matteo Scandolo8df63df2019-09-12 10:34:32 -0700183 -X main.commitHash=$(shell git log --pretty=format:%H -n 1) \
184 -X main.gitStatus=${GIT_STATUS} \
185 -X main.version=${VERSION}" \
Matteo Scandolo82c16d02019-09-24 09:34:32 -0700186 ./cmd/bbsim
Matteo Scandolo8df63df2019-09-12 10:34:32 -0700187
188build-bbsimctl:
189 GO111MODULE=on go build -i -v -mod vendor \
Matteo Scandolo40e067f2019-10-16 16:59:41 -0700190 -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 -0700191 -X github.com/opencord/bbsim/internal/bbsimctl/config.CommitHash=$(shell git log --pretty=format:%H -n 1) \
192 -X github.com/opencord/bbsim/internal/bbsimctl/config.GitStatus=${GIT_STATUS} \
193 -X github.com/opencord/bbsim/internal/bbsimctl/config.Version=${VERSION}" \
194 ./cmd/bbsimctl
Matteo Scandolo4747d292019-08-05 11:50:18 -0700195
Matteo Scandolo84f7d482019-08-08 19:00:47 -0700196api/openolt/openolt.pb.go: api/openolt/openolt.proto
Zdravko Bozakov2da76342019-10-21 09:47:35 +0200197 @protoc -I. \
198 -I${GOOGLEAPI}/third_party/googleapis \
Matteo Scandolo84f7d482019-08-08 19:00:47 -0700199 --go_out=plugins=grpc:./ \
200 $<
201
Zdravko Bozakov2da76342019-10-21 09:47:35 +0200202api/bbsim/bbsim.pb.go api/bbsim/bbsim.pb.gw.go: api/bbsim/bbsim.proto api/bbsim/bbsim.yaml
203 @protoc -I. \
204 -I${GOOGLEAPI}/third_party/googleapis \
Anand S Katti09541352020-01-29 15:54:01 +0530205 -I${VOLTHA_PROTOS}/protos/ \
Matteo Scandolo4747d292019-08-05 11:50:18 -0700206 --go_out=plugins=grpc:./ \
Zdravko Bozakov2da76342019-10-21 09:47:35 +0200207 --grpc-gateway_out=logtostderr=true,grpc_api_configuration=api/bbsim/bbsim.yaml,allow_delete_body=true:./ \
Matteo Scandolo4747d292019-08-05 11:50:18 -0700208 $<
209
Zdravko Bozakov2da76342019-10-21 09:47:35 +0200210api/legacy/bbsim.pb.go api/legacy/bbsim.pb.gw.go: api/legacy/bbsim.proto
211 @protoc -I. \
212 -I${GOOGLEAPI}/third_party/googleapis/ \
213 -I${GOOGLEAPI}/ \
214 -I${VOLTHA_PROTOS}/protos/ \
215 --go_out=plugins=grpc:./ \
216 --grpc-gateway_out=logtostderr=true,allow_delete_body=true:./ \
217 $<
218
219docs/swagger/bbsim/bbsim.swagger.json: api/bbsim/bbsim.yaml
220 @protoc -I ./api \
221 -I${GOOGLEAPI}/ \
222 -I${VOLTHA_PROTOS}/protos/ \
223 --swagger_out=logtostderr=true,allow_delete_body=true,grpc_api_configuration=$<:docs/swagger/ \
224 api/bbsim/bbsim.proto
225
226docs/swagger/leagacy/bbsim.swagger.json: api/legacy/bbsim.proto
227 @protoc -I ./api \
228 -I${GOOGLEAPI}/ \
229 -I${VOLTHA_PROTOS}/protos/ \
230 --swagger_out=logtostderr=true,allow_delete_body=true:docs/swagger/ \
Andrea Campanella64dffd52019-12-17 17:29:57 -0800231 $<