conlink 2.0.3 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/run-tests.sh ADDED
@@ -0,0 +1,219 @@
1
+ #!/usr/bin/env bash
2
+
3
+ export VERBOSE=${VERBOSE:-}
4
+ export COMPOSE_PROJECT_NAME=${COMPOSE_PROJECT_NAME:-conlink-test}
5
+ declare TEST_NUM=0
6
+ declare -A RESULTS
7
+ declare PASS=0
8
+ declare FAIL=0
9
+
10
+ die() { echo >&2 "${*}"; exit 1; }
11
+ vecho() { [ "${VERBOSE}" ] && echo "${*}" || true; }
12
+ dc() { ${DOCKER_COMPOSE} "${@}"; }
13
+ mdc() { ./mdc "${@}" || die "mdc invocation failed"; }
14
+
15
+ # Determine compose command
16
+ for dc in "docker compose" "docker-compose"; do
17
+ ${dc} version 2>/dev/null >&2 && DOCKER_COMPOSE="${dc}" && break
18
+ done
19
+ [ "${DOCKER_COMPOSE}" ] || die "No compose command found"
20
+ echo >&2 "Using compose command '${DOCKER_COMPOSE}'"
21
+
22
+ dc_init() {
23
+ local cont="${1}" idx="${2}"
24
+ dc down --remove-orphans -t1
25
+ dc up -d --force-recreate "${@}"
26
+ while ! dc logs network | grep "All links connected"; do
27
+ vecho "waiting for conlink startup"
28
+ sleep 1
29
+ done
30
+ }
31
+
32
+ dc_run() {
33
+ local cont="${1}" svc= idx= result=0
34
+ case "${cont}" in
35
+ *_[0-9]|*_[0-9][0-9]) svc="${cont%_*}" idx="${cont##*_}" ;;
36
+ *) svc="${cont}" idx=1 ;;
37
+ esac
38
+ shift
39
+
40
+ #echo "target: ${1}, service: ${svc}, index: ${idx}"
41
+ if [ "${VERBOSE}" ]; then
42
+ vecho " Running: dc exec -T --index ${idx} ${svc} sh -c ${*}"
43
+ dc exec -T --index ${idx} ${svc} sh -c "${*}" || result=$?
44
+ else
45
+ dc exec -T --index ${idx} ${svc} sh -c "${*}" > /dev/null || result=$?
46
+ fi
47
+ return ${result}
48
+ }
49
+
50
+ do_test() {
51
+ local tries="${1}"; shift
52
+ local name="${TEST_NUM} ${GROUP}: ${@}" try=1 result=
53
+ TEST_NUM=$(( TEST_NUM + 1 ))
54
+ vecho " > Running test ${name}"
55
+ while true; do
56
+ result=0
57
+ if [ "${WITH_DC}" ]; then
58
+ dc_run "${@}" || result=$?
59
+ else
60
+ vecho " Running: eval ${*}"
61
+ if [ "${VERBOSE}" ]; then
62
+ sh -c "${*}" || result=$?
63
+ else
64
+ sh -c "${*}" >/dev/null || result=$?
65
+ fi
66
+ fi
67
+ [ "${result}" -eq 0 -o "${try}" -ge "${tries}" ] && break
68
+ echo " command failed (${result}), sleeping 2s before retry (${try}/${tries})"
69
+ sleep 2
70
+ try=$(( try + 1 ))
71
+ done
72
+ RESULTS["${name}"]=${result}
73
+ if [ "${RESULTS["${name}"]}" = 0 ]; then
74
+ PASS=$(( PASS + 1 ))
75
+ vecho " > PASS (0 for ${*})"
76
+ else
77
+ FAIL=$(( FAIL + 1 ))
78
+ echo " > FAIL (${RESULTS[${name}]} for ${*})"
79
+ fi
80
+ return ${result}
81
+ }
82
+
83
+ dc_wait() { WITH_DC=1 do_test "${@}"; }
84
+ dc_test() { WITH_DC=1 do_test 1 "${@}"; }
85
+
86
+
87
+ echo -e "\n\n>>> test1: combined config"
88
+ GROUP=test1
89
+ echo "COMPOSE_FILE=examples/test1-compose.yaml" > .env
90
+ dc_init || die "test1 startup failed"
91
+
92
+ echo " >> Ping nodes from other nodes"
93
+ dc_test h1 ping -c1 10.0.0.100
94
+ dc_test h2 ping -c1 192.168.1.100
95
+ dc_test h3 ping -c1 172.16.0.100
96
+
97
+ echo -e "\n\n>>> test2: separate config and scaling"
98
+ GROUP=test2
99
+ echo "COMPOSE_FILE=examples/test2-compose.yaml" > .env
100
+ dc_init || die "test2 startup failed"
101
+
102
+ echo " >> Cross-node ping and ping the 'internet'"
103
+ dc_test node_1 ping -c1 10.0.1.2
104
+ dc_test node_2 ping -c1 10.0.1.1
105
+ dc_test node_1 ping -c1 8.8.8.8
106
+ dc_test node_2 ping -c1 8.8.8.8
107
+
108
+ echo " >> Scale the nodes from 2 to 5"
109
+ dc up -d --scale node=5
110
+ dc_wait 10 node_5 'ip addr | grep "10\.0\.1\.5"' || die "test2 scale-up failed"
111
+ echo " >> Ping the fifth node from the second"
112
+ dc_test node_2 ping -c1 10.0.1.5
113
+
114
+
115
+ echo -e "\n\n>>> test4: multiple compose / mdc"
116
+ GROUP=test4
117
+ export MODES_DIR=./examples/test4-multiple/modes
118
+
119
+ mdc node1
120
+ dc_init; dc_wait 10 r0_1 'ip addr | grep "10\.1\.0\.100"' \
121
+ || die "test4 node1 startup failed"
122
+ echo " >> Ping the r0 router host from node1"
123
+ dc_test node1_1 ping -c1 10.0.0.100
124
+
125
+ mdc node1,nodes2
126
+ dc_init; dc_wait 10 node2_2 'ip addr | grep "10\.2\.0\.2"' \
127
+ || die "test4 node1,nodes2 startup failed"
128
+ echo " >> From both node2 replicas, ping node1 across the r0 router"
129
+ dc_test node2_1 ping -c1 10.1.0.1
130
+ dc_test node2_2 ping -c1 10.1.0.1
131
+ echo " >> From node1, ping both node2 replicas across the r0 router"
132
+ dc_test node1 ping -c1 10.2.0.1
133
+ dc_test node1 ping -c1 10.2.0.2
134
+
135
+ mdc all
136
+ dc_init; dc exec -T r0 /scripts/wait.sh -t 10.0.0.100:80 \
137
+ || die "test4 all startup failed"
138
+ echo " >> From node2, download from the web server in r0"
139
+ dc_test node2_1 wget -O- 10.0.0.100
140
+ dc_test node2_2 wget -O- 10.0.0.100
141
+
142
+
143
+ echo -e "\n\n>>> test7: MAC, MTU, and NetEm settings"
144
+ GROUP=test7
145
+ echo "COMPOSE_FILE=examples/test7-compose.yaml" > .env
146
+
147
+ dc_init; dc_wait 10 node_1 'ip addr | grep "10\.0\.1\.1"' \
148
+ || die "test7 startup failed"
149
+ echo " >> Ensure MAC and MTU are set correctly"
150
+ dc_test node_1 'ip link show eth0 | grep "ether 00:0a:0b:0c:0d:01"'
151
+ dc_test node_2 'ip link show eth0 | grep "ether 00:0a:0b:0c:0d:02"'
152
+ dc_test node_1 'ip link show eth0 | grep "mtu 4111"'
153
+ dc_test node_2 'ip link show eth0 | grep "mtu 4111"'
154
+ echo " >> Check for min round-trip ping delay of about 80ms"
155
+ dc_test node_1 'ping -c5 10.0.1.2 | grep "min/avg/max = 8[012345]\."'
156
+
157
+
158
+ echo -e "\n\n>>> test9: bridge modes and variable templating"
159
+ echo "COMPOSE_FILE=examples/test9-compose.yaml" > .env
160
+
161
+ echo -e "\n\n >> test9: bridge mode: auto"
162
+ GROUP=test9-auto
163
+ export BRIDGE_MODE=auto
164
+ dc_init; dc_wait 10 node_1 'ip addr | grep "10\.0\.1\.1"' \
165
+ || die "test9 (auto) startup failed"
166
+ echo " >> Check for round-trip ping connectivity (BRIDGE_MODE=auto)"
167
+ dc_test node_1 'ping -c2 10.0.1.2'
168
+
169
+ echo -e "\n\n >> test9: bridge mode: linux"
170
+ GROUP=test9-linux
171
+ export BRIDGE_MODE=linux
172
+ dc_init; dc_wait 10 node_1 'ip addr | grep "10\.0\.1\.1"' \
173
+ || die "test9 (linux) startup failed"
174
+ echo " >> Check for round-trip ping connectivity (BRIDGE_MODE=linux)"
175
+ dc_test node_1 'ping -c2 10.0.1.2'
176
+
177
+ echo -e "\n\n >> test9: bridge mode: patch"
178
+ GROUP=test9-patch
179
+ export BRIDGE_MODE=patch
180
+ dc_init; dc_wait 10 node_1 'ip addr | grep "10\.0\.1\.1"' \
181
+ || die "test9 startup failed"
182
+ echo " >> Ensure ingest filter rules exist (BRIDGE_MODE=patch)"
183
+ dc_test network 'tc filter show dev node_1-eth0 parent ffff: | grep "action order 1: mirred"'
184
+ echo " >> Check for round-trip ping connectivity (BRIDGE_MODE=patch)"
185
+ dc_test node_1 'ping -c2 10.0.1.2'
186
+
187
+ echo -e "\n\n>>> test10: port forwarding"
188
+ GROUP=test10
189
+ echo "COMPOSE_FILE=examples/test10-compose.yaml" > .env
190
+
191
+ dc_init; dc_wait 10 node1_1 'ip addr | grep "10\.0\.1\.1"' \
192
+ || die "test10 startup failed"
193
+ echo " >> Check ping between replicas"
194
+ dc_test node2_1 'ping -c2 10.0.2.2'
195
+ echo " >> Ensure ports are forwarded correctly"
196
+ do_test 10 'curl -s -S "http://0.0.0.0:3080" | grep "log"'
197
+ do_test 10 'curl -s -S "http://0.0.0.0:8080" | grep "log"'
198
+ do_test 10 'curl -s -S "http://0.0.0.0:80" | grep "share"'
199
+ do_test 10 'curl -s -S "http://0.0.0.0:81" | grep "share"'
200
+
201
+
202
+ echo -e "\n\n>>> Cleaning up"
203
+ dc down -t1 --remove-orphans
204
+ rm -f .env
205
+
206
+ if [ "${VERBOSE}" ]; then
207
+ for t in "${!RESULTS[@]}"; do
208
+ echo "RESULT: '${t}' -> ${RESULTS[${t}]}"
209
+ done
210
+ fi
211
+
212
+ if [ "${FAIL}" = 0 ]; then
213
+ echo -e "\n\n>>> ALL ${PASS} TESTS PASSED"
214
+ exit 0
215
+ else
216
+ echo -e "\n\n>>> ${FAIL} TESTS FAILED, ${PASS} TESTS PASSED"
217
+ exit 1
218
+ fi
219
+
package/schema.yaml CHANGED
@@ -45,6 +45,16 @@ properties:
45
45
  netem: {type: string}
46
46
  mode: {type: string}
47
47
  vlanid: {type: number}
48
+ forward:
49
+ type: array
50
+ items: {type: string, pattern: "^[0-9]{1,5}:[0-9]{1,5}/(tcp|udp)$"}
51
+
52
+ bridges:
53
+ type: array
54
+ items:
55
+ type: object
56
+ properties:
57
+ mode: {type: string, enum: [auto, ovs, linux, patch]}
48
58
 
49
59
  tunnels:
50
60
  type: array