-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
412 lines (304 loc) · 13.1 KB
/
Makefile
File metadata and controls
412 lines (304 loc) · 13.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
# GoBFD Makefile — all Go commands run inside Podman containers.
# NO local Go toolchain required.
#
# Usage:
# make up — start dev container
# make build — compile both binaries
# make test — run all tests with race detector
# make lint — run golangci-lint v2
# make proto-gen — generate protobuf Go code
# make proto-lint — lint proto definitions
# make all — build + test + lint
# make interop — run interop tests (bash, builds + tests + cleans up)
# make interop-test — run Go interop tests (stack must be running)
# make interop-up — start interop test stack (4 peers)
# make interop-down — stop interop test stack
# make integration — alias for interop
COMPOSE_FILE := deployments/compose/compose.dev.yml
DC := podman-compose -f $(COMPOSE_FILE)
EXEC := $(DC) exec -T dev
SEMGREP ?= semgrep
SEMGREP_CONFIG ?= p/golang
SEMGREP_COMMON_FLAGS := --config $(SEMGREP_CONFIG) --metrics=off --disable-version-check --timeout 15 --no-git-ignore --include='*.go' .
.PHONY: all build test lint semgrep semgrep-json semgrep-pro proto-gen proto-lint fuzz vulncheck osv-scan vulncheck-strict osv-scan-strict \
benchmark benchmark-all benchmark-save benchmark-compare \
test-report report-all \
coverage profile \
up down restart logs shell clean tidy \
interop interop-test interop-up interop-down interop-logs \
interop-capture interop-pcap interop-pcap-summary integration \
interop-bgp interop-bgp-test interop-bgp-up interop-bgp-down interop-bgp-logs \
interop-rfc interop-rfc-test interop-rfc-up interop-rfc-down interop-rfc-logs \
interop-clab interop-clab-test interop-clab-up interop-clab-down \
int-bgp-failover int-bgp-failover-up int-bgp-failover-down int-bgp-failover-logs \
int-haproxy int-haproxy-up int-haproxy-down int-haproxy-logs \
int-observability int-observability-up int-observability-down int-observability-logs \
int-exabgp-anycast int-exabgp-anycast-up int-exabgp-anycast-down int-exabgp-anycast-logs \
int-k8s int-k8s-up int-k8s-down \
benchmark-cross benchmark-report
# === Lifecycle ===
up:
$(DC) up -d --build
down:
$(DC) down
restart: down up
logs:
$(DC) logs -f dev
shell:
$(DC) exec dev bash
# === Build ===
all: build test lint
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
GIT_COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
BUILD_DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
BENCH_DIR := testdata/benchmarks
REPORT_DIR := reports
BENCH_VERSION ?= $(VERSION)
LDFLAGS := -s -w \
-X github.com/dantte-lp/gobfd/internal/version.Version=$(VERSION) \
-X github.com/dantte-lp/gobfd/internal/version.GitCommit=$(GIT_COMMIT) \
-X github.com/dantte-lp/gobfd/internal/version.BuildDate=$(BUILD_DATE)
build:
$(EXEC) go build -ldflags='$(LDFLAGS)' ./cmd/gobfd
$(EXEC) go build -ldflags='$(LDFLAGS)' ./cmd/gobfdctl
$(EXEC) go build -ldflags='$(LDFLAGS)' ./cmd/gobfd-haproxy-agent
$(EXEC) go build -ldflags='$(LDFLAGS)' ./cmd/gobfd-exabgp-bridge
# === Test ===
test:
$(EXEC) go test ./... -race -count=1
test-v:
$(EXEC) go test ./... -race -count=1 -v
test-run:
@test -n "$(RUN)" || (echo "Usage: make test-run RUN=TestFSMTransition PKG=./internal/bfd"; exit 1)
$(EXEC) go test -run '$(RUN)' $(PKG) -race -count=1 -v
fuzz:
@test -n "$(FUNC)" || (echo "Usage: make fuzz FUNC=FuzzControlPacket PKG=./internal/bfd"; exit 1)
$(EXEC) go test -fuzz=$(FUNC) $(PKG) -fuzztime=60s
test-integration:
$(EXEC) go test -tags integration ./test/integration/ -race -count=1 -v
# === Interop Tests (FRR + BIRD3 + aiobfd + Thoro/bfd — 4-peer topology) ===
INTEROP_COMPOSE := test/interop/compose.yml
INTEROP_DC := podman-compose -f $(INTEROP_COMPOSE)
interop:
./test/interop/run.sh
interop-test:
INTEROP_COMPOSE_FILE=$(INTEROP_COMPOSE) go test -tags interop -v -count=1 -timeout 300s ./test/interop/
interop-up:
$(INTEROP_DC) up --build -d
interop-down:
$(INTEROP_DC) down --volumes --remove-orphans
interop-logs:
$(INTEROP_DC) logs -f
interop-capture:
podman exec tshark-interop tshark -i any -f "udp port 3784" -V
interop-pcap:
podman exec tshark-interop tshark -r /captures/bfd.pcapng -V -Y bfd
interop-pcap-summary:
podman exec tshark-interop tshark -r /captures/bfd.pcapng -Y bfd \
-T fields -e frame.time_relative -e ip.src -e ip.dst \
-e bfd.version -e bfd.diag -e bfd.sta -e bfd.flags \
-e bfd.detect_time_multiplier -e bfd.my_discriminator \
-e bfd.your_discriminator -e bfd.desired_min_tx_interval \
-e bfd.required_min_rx_interval -E header=y -E separator=,
integration: interop
# === BGP+BFD Interop Tests (GoBGP + FRR + BIRD3 + ExaBGP — 3 scenarios) ===
INTEROP_BGP_COMPOSE := test/interop-bgp/compose.yml
INTEROP_BGP_DC := podman-compose -f $(INTEROP_BGP_COMPOSE)
interop-bgp:
./test/interop-bgp/run.sh
interop-bgp-test:
INTEROP_BGP_COMPOSE_FILE=$(INTEROP_BGP_COMPOSE) go test -tags interop_bgp -v -count=1 -timeout 300s ./test/interop-bgp/
interop-bgp-up:
$(INTEROP_BGP_DC) up --build -d
interop-bgp-down:
$(INTEROP_BGP_DC) down --volumes --remove-orphans
interop-bgp-logs:
$(INTEROP_BGP_DC) logs -f
# === RFC Interop Tests (RFC 7419 + RFC 9384 + RFC 9468 — 3 scenarios) ===
INTEROP_RFC_COMPOSE := test/interop-rfc/compose.yml
INTEROP_RFC_DC := podman-compose -f $(INTEROP_RFC_COMPOSE)
interop-rfc:
./test/interop-rfc/run.sh
interop-rfc-test:
INTEROP_RFC_COMPOSE_FILE=$(INTEROP_RFC_COMPOSE) go test -tags interop_rfc -v -count=1 -timeout 300s ./test/interop-rfc/
interop-rfc-up:
$(INTEROP_RFC_DC) up --build -d
interop-rfc-down:
$(INTEROP_RFC_DC) down --volumes --remove-orphans
interop-rfc-logs:
$(INTEROP_RFC_DC) logs -f
# === Containerlab Vendor Interop Tests (Arista + Nokia + Cisco + SONiC + VyOS) ===
CLAB_TOPO := test/interop-clab/gobfd-vendors.clab.yml
interop-clab:
./test/interop-clab/run.sh
interop-clab-test:
go test -tags interop_clab -v -count=1 -timeout 600s ./test/interop-clab/
interop-clab-up:
./test/interop-clab/run.sh --up-only
interop-clab-down:
containerlab --runtime podman destroy -t $(CLAB_TOPO) --cleanup 2>/dev/null || true
podman rm -f clab-gobfd-vendors-gobfd 2>/dev/null || true
# === Integration Examples ===
INT_BGP_DC := podman-compose -f deployments/integrations/bgp-fast-failover/compose.yml
INT_HAPROXY_DC := podman-compose -f deployments/integrations/haproxy-health/compose.yml
INT_OBS_DC := podman-compose -f deployments/integrations/observability/compose.yml
INT_EXABGP_DC := podman-compose -f deployments/integrations/exabgp-anycast/compose.yml
int-bgp-failover:
./deployments/integrations/bgp-fast-failover/run.sh
int-bgp-failover-up:
$(INT_BGP_DC) up --build -d
int-bgp-failover-down:
$(INT_BGP_DC) down --volumes --remove-orphans
int-bgp-failover-logs:
$(INT_BGP_DC) logs -f
int-haproxy:
./deployments/integrations/haproxy-health/run.sh
int-haproxy-up:
$(INT_HAPROXY_DC) up --build -d
int-haproxy-down:
$(INT_HAPROXY_DC) down --volumes --remove-orphans
int-haproxy-logs:
$(INT_HAPROXY_DC) logs -f
int-observability:
./deployments/integrations/observability/run.sh
int-observability-up:
$(INT_OBS_DC) up --build -d
int-observability-down:
$(INT_OBS_DC) down --volumes --remove-orphans
int-observability-logs:
$(INT_OBS_DC) logs -f
int-exabgp-anycast:
./deployments/integrations/exabgp-anycast/run.sh
int-exabgp-anycast-up:
$(INT_EXABGP_DC) up --build -d
int-exabgp-anycast-down:
$(INT_EXABGP_DC) down --volumes --remove-orphans
int-exabgp-anycast-logs:
$(INT_EXABGP_DC) logs -f
int-k8s:
./deployments/integrations/kubernetes/run.sh
int-k8s-up:
./deployments/integrations/kubernetes/setup-cluster.sh && kubectl apply -f deployments/integrations/kubernetes/manifests/
int-k8s-down:
./deployments/integrations/kubernetes/teardown.sh
# === Benchmarks & Profiling ===
benchmark:
$(EXEC) go test -buildvcs=false -bench=. -benchmem -count=6 -run='^$$' ./internal/bfd/ | tee benchmark.txt
benchmark-all:
$(EXEC) go test -buildvcs=false -bench=. -benchmem -count=6 -run='^$$' ./... | tee benchmark.txt
coverage:
$(EXEC) go test -buildvcs=false ./... -race -count=1 -coverprofile=coverage.out -covermode=atomic
$(EXEC) go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report: coverage.html"
coverage-func:
$(EXEC) go test -buildvcs=false ./... -race -count=1 -coverprofile=coverage.out -covermode=atomic
$(EXEC) go tool cover -func=coverage.out
profile:
$(EXEC) go test -buildvcs=false -bench=. -run='^$$' -cpuprofile=cpu.prof -memprofile=mem.prof ./internal/bfd/
@echo "CPU profile: cpu.prof — view with: go tool pprof -http=:8080 cpu.prof"
@echo "Memory profile: mem.prof — view with: go tool pprof -http=:8080 mem.prof"
# === Reports ===
# Save benchmarks tagged by version.
# Usage: make benchmark-save [BENCH_VERSION=v0.5.0]
benchmark-save:
@mkdir -p $(BENCH_DIR)/$(BENCH_VERSION)
$(EXEC) go test -buildvcs=false -bench=. -benchmem -count=6 -run='^$$' -timeout=120s \
./internal/bfd/ | tee $(BENCH_DIR)/$(BENCH_VERSION)/benchmark-bfd.txt
$(EXEC) go test -buildvcs=false -bench=. -benchmem -count=6 -run='^$$' -timeout=120s \
./internal/netio/ | tee $(BENCH_DIR)/$(BENCH_VERSION)/benchmark-netio.txt
@cat $(BENCH_DIR)/$(BENCH_VERSION)/benchmark-bfd.txt \
$(BENCH_DIR)/$(BENCH_VERSION)/benchmark-netio.txt \
> $(BENCH_DIR)/$(BENCH_VERSION)/benchmark.txt
@printf '{"version":"%s","commit":"%s","date":"%s","go":"%s","count":6}\n' \
"$(BENCH_VERSION)" "$(GIT_COMMIT)" "$(BUILD_DATE)" \
"$$($(EXEC) go env GOVERSION)" \
> $(BENCH_DIR)/$(BENCH_VERSION)/meta.json
@echo "=== Benchmarks saved to $(BENCH_DIR)/$(BENCH_VERSION)/ ==="
# Compare benchmarks between two versions via benchstat.
# Usage: make benchmark-compare OLD=v0.4.0 NEW=v0.5.0
OLD ?= baseline
NEW ?= $(BENCH_VERSION)
benchmark-compare:
@mkdir -p $(REPORT_DIR)/benchmarks
@old_file=""; new_file=""; \
if [ "$(OLD)" = "baseline" ]; then old_file="$(BENCH_DIR)/baseline.txt"; \
else old_file="$(BENCH_DIR)/$(OLD)/benchmark.txt"; fi; \
new_file="$(BENCH_DIR)/$(NEW)/benchmark.txt"; \
$(EXEC) benchstat "$$old_file" "$$new_file" | tee $(REPORT_DIR)/benchmarks/comparison.txt; \
printf '<!DOCTYPE html>\n<html><head><meta charset="utf-8">\n<title>GoBFD Benchmark Comparison: %s vs %s</title>\n<style>\nbody{font-family:system-ui,sans-serif;margin:2em;background:#1a1a2e;color:#e0e0e0}\nh1{color:#00d4ff}pre{background:#16213e;padding:1.5em;border-radius:8px;overflow-x:auto;font-size:14px;line-height:1.6;border:1px solid #0f3460}\n.meta{color:#888;font-size:13px}\n</style></head><body>\n<h1>GoBFD Benchmark Comparison</h1>\n<p class="meta">Old: %s — New: %s — Generated: %s</p>\n<pre>\n' \
"$(OLD)" "$(NEW)" "$(OLD)" "$(NEW)" "$(BUILD_DATE)" \
> $(REPORT_DIR)/benchmarks/comparison.html; \
cat $(REPORT_DIR)/benchmarks/comparison.txt >> $(REPORT_DIR)/benchmarks/comparison.html; \
printf '</pre></body></html>\n' >> $(REPORT_DIR)/benchmarks/comparison.html; \
echo "=== Comparison: $(REPORT_DIR)/benchmarks/comparison.html ==="
# Generate test report (JUnit XML -> standalone HTML).
# Usage: make test-report
test-report:
@mkdir -p $(REPORT_DIR)/tests
$(EXEC) gotestsum \
--junitfile $(REPORT_DIR)/tests/unit-report.xml \
--jsonfile $(REPORT_DIR)/tests/unit-report.json \
--format short-verbose \
-- -buildvcs=false ./... -race -count=1
$(EXEC) junit2html $(REPORT_DIR)/tests/unit-report.xml \
$(REPORT_DIR)/tests/unit-report.html
@echo "=== Test report: $(REPORT_DIR)/tests/unit-report.html ==="
# Full pipeline: tests + benchmarks + comparison.
# Usage: make report-all [OLD=v0.4.0]
report-all: test-report benchmark-save benchmark-compare
@echo "=== All reports in $(REPORT_DIR)/ ==="
# === Cross-Implementation Benchmarks ===
BENCH_COMPOSE := bench/compose.yml
BENCH_DC := podman-compose -f $(BENCH_COMPOSE)
BENCH_RESULTS := bench-results
benchmark-cross:
@mkdir -p $(BENCH_RESULTS)
$(BENCH_DC) build
$(BENCH_DC) run --rm bench-c
$(BENCH_DC) run --rm bench-python
$(BENCH_DC) run --rm bench-go
@echo "=== All benchmarks completed. Results in $(BENCH_RESULTS)/ ==="
benchmark-report:
./scripts/gen-report.sh $(BENCH_RESULTS)
# === Quality ===
lint:
$(EXEC) golangci-lint run ./...
lint-fix:
$(EXEC) golangci-lint run --fix ./...
semgrep:
$(SEMGREP) scan $(SEMGREP_COMMON_FLAGS)
semgrep-json:
$(SEMGREP) scan $(SEMGREP_COMMON_FLAGS) --json
semgrep-pro:
$(SEMGREP) scan --pro $(SEMGREP_COMMON_FLAGS)
vulncheck:
$(EXEC) go run ./scripts/vuln-audit.go
osv-scan: vulncheck
vulncheck-strict:
$(EXEC) govulncheck ./...
osv-scan-strict:
$(EXEC) osv-scanner scan -r .
# === Proto ===
proto-gen:
$(EXEC) buf generate
proto-lint:
$(EXEC) buf lint
proto-breaking:
$(EXEC) buf breaking --against '.git#branch=master'
proto-update:
$(EXEC) buf dep update
# === Dependencies ===
tidy:
$(EXEC) go mod tidy
download:
$(EXEC) go mod download
# === Clean ===
clean:
$(EXEC) rm -f gobfd gobfdctl
$(EXEC) go clean -cache -testcache
# === Info ===
versions:
@echo "=== Go ===" && $(EXEC) go version
@echo "=== Buf ===" && $(EXEC) buf --version
@echo "=== golangci-lint ===" && $(EXEC) golangci-lint version --short
@echo "=== govulncheck ===" && $(EXEC) govulncheck -version 2>/dev/null || echo "installed"