-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathMakefile
180 lines (146 loc) · 5.17 KB
/
Makefile
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
SHELL = /bin/bash
.PHONY: all
all: install deploy run
.PHONY: all-clab
all-clab: install deploy-clab run-otgen
.PHONY: clean
clean: remove-lab remove-clab
.PHONY: clean-all
clean-all: clean install-clean
###############################
# Install components
###############################
.PHONY: install
install: install-docker-compose install-clab install-otgen
install-docker-compose: /usr/local/bin/docker-compose
/usr/local/bin/docker-compose:
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$$(uname -s)-$$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
install-clab: /usr/bin/containerlab
/usr/bin/containerlab:
bash -c "$$(curl -sL https://get.containerlab.dev)" -- -v 0.46.2
install-otgen: /usr/local/bin/otgen
/usr/local/bin/otgen:
bash -c "$$(curl -sL https://get.otgcdn.net/otgen)" -- -v 0.6.2
install-clean:
-sudo rm -f `command -v docker-compose`
-sudo rm -f `command -v otgen`
-sudo apt remove containerlab -y
###############################
# Pull images
###############################
.PHONY: pull
pull: pull-private
pull-public:
sudo -E docker-compose pull traffic_engine_1
sudo -E docker-compose pull frr
pull-private:
sudo -E docker-compose pull controller protocol_engine_1
###############################
# Deploy lab
###############################
.PHONY: deploy
deploy: deploy-lab deploy-net
deploy-lab:
sudo -E docker-compose up -d
deploy-net:
sudo /bin/bash ../../utils/connect_containers_veth.sh cpdp-frr_traffic_engine_1_1 cpdp-frr_frr_1 veth0 veth1
sudo /bin/bash ../../utils/connect_containers_veth.sh cpdp-frr_traffic_engine_2_1 cpdp-frr_frr_1 veth2 veth3
deploy-clab:
sudo -E containerlab deploy --reconfigure
remove-lab:
-sudo docker-compose down
remove-clab:
-sudo containerlab destroy --cleanup
###############################
# Run tests
###############################
.PHONY: run
run: otg-set-config otg-start-protocols otg-fetch-arp otg-fetch-bgp otg-trasmit otg-metrics-flow otg-metrics-port
OTG_HOST=https://localhost:8443
otg-set-config:
@echo "############################################"
@echo "# Apply OTG configuration"
@echo
sleep 5 # pause for keng-controller to detect newly created interfaces
curl -sk "$(OTG_HOST)/config" \
-H "Content-Type: application/json" \
-d @otg.json | tee curl.out
@echo
cat curl.out | jq -e "if (.errors | length) > 0 then false else true end"
otg-start-protocols:
@echo "############################################"
@echo "# Start protocols"
@echo
curl -sk "$(OTG_HOST)/control/state" \
-H "Content-Type: application/json" \
-d '{"choice": "protocol","protocol": {"choice": "all","all": {"state": "start"}}}' | tee curl.out
@echo
cat curl.out | jq -e "if (.errors | length) > 0 then false else true end"
otg-fetch-arp:
@echo "############################################"
@echo "# Fetch ARP table"
@echo
sleep 2 # pause for ARP to complete
curl -sk "$(OTG_HOST)/monitor/states" \
-X POST \
-H 'Content-Type: application/json' \
-d '{ "choice": "ipv4_neighbors" }' | tee curl.out
@echo
cat curl.out | jq -e "if (.ipv4_neighbors | length) == 2 then true else false end"
otg-fetch-bgp:
@echo "############################################"
@echo "# Fetch BGP metrics"
@echo
sleep 5 # pause for BGP to converge
curl -sk "$(OTG_HOST)/monitor/metrics" \
-X POST \
-H 'Content-Type: application/json' \
-d '{ "choice": "bgpv4" }' | tee curl.out
@echo
cat curl.out | jq -e "if (.bgpv4_metrics | length) == 2 and \
.bgpv4_metrics[0].session_state == \"up\" and \
.bgpv4_metrics[0].routes_received == \"2\" and \
.bgpv4_metrics[1].session_state == \"up\" and \
.bgpv4_metrics[1].routes_received == \"2\" \
then true else false end"
otg-trasmit:
@echo "############################################"
@echo "# Start transmitting flows"
@echo
curl -sk "$(OTG_HOST)/control/state" \
-H "Content-Type: application/json" \
-d '{"choice": "traffic", "traffic": {"choice": "flow_transmit", "flow_transmit": {"state": "start"}}}' | tee curl.out
@echo
cat curl.out | jq -e "if (.errors | length) > 0 then false else true end"
otg-metrics-flow:
@echo "############################################"
@echo "# Fetch flow metrics"
@echo
sleep 10 # pause for traffic to finish
curl -sk "$(OTG_HOST)/monitor/metrics" \
-X POST \
-H 'Content-Type: application/json' \
-d '{ "choice": "flow" }' | tee curl.out
@echo
cat curl.out | jq -e "if (.flow_metrics | length) == 1 and \
.flow_metrics[0].transmit == \"stopped\" and \
.flow_metrics[0].frames_tx != \"0\" and \
.flow_metrics[0].frames_tx == .flow_metrics[0].frames_rx \
then true else false end"
otg-metrics-port:
@echo "############################################"
@echo "# Fetch port metrics"
@echo
curl -sk "$(OTG_HOST)/monitor/metrics" \
-X POST \
-H 'Content-Type: application/json' \
-d '{ "choice": "port" }' | tee curl.out
@echo
cat curl.out | jq -e "if (.port_metrics | length) == 2 \
then true else false end"
.PHONY: run-otgen
export OTG_API=https://localhost:8443
run-otgen:
sleep 5 # pause for all components to initialize
otgen --log debug run --insecure --file otg.json --json --rxbgp 2x --metrics flow | otgen transform --metrics flow