Skip to content

Commit c11db44

Browse files
committed
Add tests for service bridge
These tests verify the correctness of the bridge. In each folder there are tests for each feature (connectivity, vlan, stp, vlan_and_stp). Signed-off-by: Gianluca Scopelliti <gianlu.1033@gmail.com>
1 parent 5d3a0fe commit c11db44

64 files changed

Lines changed: 4979 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
## Tests vlan
3+
4+
under `vlan` folder
5+
6+
7+
## Tests connectivity
8+
9+
under `connectivity` folder
10+
11+
12+
## General testing using pcn-bridge
13+
14+
under this folder
15+
16+
17+
## Tests STP using pcn-bridge
18+
19+
Under `stp_pcn` folder
20+
21+
test1x: configure a topology; wait for convergence; test connectivity
22+
23+
test2x: same as test1x plus make changes to topology, wait for convergence, retest connectivity
24+
25+
test3x: configure a topology, wait for convergence, test stp ports status
26+
27+
test4x: same as test 3x plus make changes to topology, wait for convergence, re-test ports stp status
28+
29+
30+
31+
## Tests STP using pcn-bridge + linux bridge
32+
33+
34+
Under `stp_pcn_lb` folder
35+
36+
test5x same as test1x
37+
38+
test6x same as test2x
39+
40+
test7x same as test3x
41+
42+
test8x same as test4x
43+
44+
## Tests VLAN and STP
45+
46+
Under `vlan_and_stp` folder
47+
48+
Testing multiple STP instances at the same time
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#! /bin/bash
2+
3+
#test 4 ports access mode
4+
5+
source "${BASH_SOURCE%/*}/../helpers.bash"
6+
7+
N=4
8+
FLAG="TC"
9+
10+
function cleanup {
11+
set +e
12+
del_bridges 1
13+
delete_veth $N
14+
}
15+
16+
if [ $# -gt 2 ]; then
17+
echo "Wrong number of arguments"
18+
echo "-D for XDP DRIVER MODE"
19+
echo "-S for XDP SKB MODE"
20+
echo "Empty for TC MODE"
21+
exit 1
22+
fi
23+
24+
if [ -n "$1" ] && [ "$1" != "-D" ] && [ "$1" != "-S" ]; then
25+
echo "Wrong arguments"
26+
echo "-D for XDP DRIVER MODE"
27+
echo "-S for XDP SKB MODE"
28+
echo "Empty for TC MODE"
29+
exit 1
30+
fi
31+
32+
if [ "$1" == "-D" ]; then
33+
FLAG="XDP_DRV"
34+
fi
35+
36+
if [ "$1" == "-S" ]; then
37+
FLAG="XDP_SKB"
38+
fi
39+
40+
trap cleanup EXIT
41+
set -x
42+
43+
# setup
44+
create_veth $N
45+
46+
set -e
47+
48+
add_bridges 1 $FLAG
49+
50+
for i in `seq 1 $N`;
51+
do
52+
bridge_add_port br1 veth$i
53+
done
54+
55+
#sleeping
56+
#sleep $CONVERGENCE_TIME
57+
#sleep 40
58+
59+
#testing connectivity
60+
ping_cycle $N
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
"${BASH_SOURCE%/*}/test1.sh" -S
Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
#!/usr/bin/env bash
2+
3+
# default const value
4+
CONVERGENCE_TIME="50"
5+
6+
function test_fail {
7+
set +e
8+
res=$($@)
9+
local status=$?
10+
set -e
11+
if [ $status -ne 0 ]; then
12+
return 0
13+
else
14+
return 1
15+
fi
16+
}
17+
18+
function get_bridge_mac_pcn {
19+
address=$(polycubectl $1 show mac)
20+
echo $(echo $address | tr -d ':"')
21+
}
22+
23+
function get_bridge_mac_lb {
24+
address=$(brctl showstp $1)
25+
echo $(echo $stp | awk '{print $4}' | cut -d. -f2)
26+
}
27+
28+
function set_br_priority {
29+
polycubectl $1 stp 1 set priority=$2
30+
}
31+
32+
function set_br_priority_lb {
33+
sudo brctl setbridgeprio $1 $2
34+
}
35+
36+
function set_br_priority_ovs {
37+
sudo ovs-vsctl set Bridge $1 other_config:stp-priority=$2
38+
}
39+
40+
function add_bridges_ovs {
41+
for i in `seq $1 $2`;
42+
do
43+
sudo ovs-vsctl add-br br$i
44+
sudo ovs-vsctl set Bridge br$i stp_enable=true
45+
done
46+
}
47+
48+
function add_bridges_lb {
49+
for i in `seq $1 $2`;
50+
do
51+
sudo brctl addbr br$i
52+
sudo brctl stp br$i on
53+
sudo ip link set br$i up
54+
done
55+
}
56+
57+
function add_bridges {
58+
for i in `seq 1 $1`;
59+
do
60+
if [ -n "$2" ]; then
61+
polycubectl bridge add br$i type=$2
62+
else
63+
polycubectl bridge add br$i
64+
fi
65+
done
66+
}
67+
68+
function add_bridges_stp {
69+
for i in `seq 1 $1`;
70+
do
71+
polycubectl bridge add br$i stp-enabled=true
72+
done
73+
}
74+
75+
function del_bridges_ovs {
76+
for i in `seq $1 $2`;
77+
do
78+
sudo ovs-vsctl del-br br$i
79+
done
80+
}
81+
82+
function del_bridges_lb {
83+
for i in `seq $1 $2`;
84+
do
85+
sudo ip link set br$i down
86+
sudo brctl delbr br$i
87+
done
88+
}
89+
90+
function del_bridges {
91+
for i in `seq 1 $1`;
92+
do
93+
polycubectl br$i del
94+
done
95+
}
96+
97+
function bridge_add_port {
98+
polycubectl $1 ports add $2
99+
polycubectl $1 ports $2 set peer=$2
100+
}
101+
102+
function bridge_add_port_lb {
103+
sudo brctl addif $1 $2
104+
}
105+
106+
function bridge_add_port_ovs {
107+
sudo ovs-vsctl add-port $1 $2
108+
}
109+
110+
function ping_cycle {
111+
for i in `seq 1 $1`;
112+
do
113+
for j in `seq 1 $1`;
114+
do
115+
if [ "$i" -ne "$j" ]; then
116+
sudo ip netns exec ns$i ping 10.0.0.$j -c 2 -i 0.5
117+
fi
118+
done
119+
done
120+
}
121+
122+
function create_veth {
123+
for i in `seq 1 $1`;
124+
do
125+
sudo ip netns add ns${i}
126+
sudo ip link add veth${i}_ type veth peer name veth${i}
127+
sudo ip link set veth${i}_ netns ns${i}
128+
sudo ip netns exec ns${i} ip link set dev veth${i}_ up
129+
sudo ip link set dev veth${i} up
130+
sudo ip netns exec ns${i} ifconfig veth${i}_ 10.0.0.${i}/24
131+
done
132+
}
133+
134+
function create_link {
135+
for i in `seq 1 $1`;
136+
do
137+
sudo ip link add link${i}1 type veth peer name link${i}2
138+
sudo ip link set dev link${i}1 up
139+
sudo ip link set dev link${i}2 up
140+
done
141+
}
142+
143+
function delete_veth {
144+
for i in `seq 1 $1`;
145+
do
146+
sudo ip link del veth${i}
147+
sudo ip netns del ns${i}
148+
done
149+
}
150+
151+
function delete_link {
152+
for i in `seq 1 $1`;
153+
do
154+
sudo ip link del link${i}1
155+
done
156+
}
157+
158+
function test_forwarding_ovs {
159+
test_forward echo $(sudo ovs-ofctl show $1 | grep -A 2 $2 | grep state | awk '{print $2}')
160+
}
161+
162+
function test_forwarding_lb {
163+
test_forwarding echo $(brctl showstp $1 | grep -A 1 $2 | grep state | awk '{print $5}')
164+
}
165+
166+
function test_forwarding_pcn {
167+
test_forwarding polycubectl $1 ports $2 stp 1 show state
168+
}
169+
170+
function test_forwarding {
171+
res=$($@)
172+
local status=$?
173+
if [ $status -ne 0 ]; then
174+
return $status
175+
else
176+
echo "$res"
177+
if [[ "$res" == *"forwarding"* ]]; then
178+
return $status
179+
else
180+
echo "expected port state forwarding"
181+
return 1
182+
fi
183+
fi
184+
return $status
185+
}
186+
187+
function test_forward {
188+
res=$($@)
189+
local status=$?
190+
if [ $status -ne 0 ]; then
191+
return $status
192+
else
193+
echo "$res"
194+
if [[ "$res" == *"FORWARD"* ]]; then
195+
return $status
196+
else
197+
echo "expected port state forwarding"
198+
return 1
199+
fi
200+
fi
201+
return $status
202+
}
203+
204+
function test_blocking_ovs {
205+
test_block echo $(sudo ovs-ofctl show $1 | grep -A 2 $2 | grep state | awk '{print $2}')
206+
}
207+
208+
function test_blocking_lb {
209+
test_blocking echo $(brctl showstp $1 | grep -A 1 $2 | grep state | awk '{print $5}')
210+
}
211+
212+
function test_blocking_pcn {
213+
test_blocking polycubectl $1 ports $2 stp 1 show state
214+
}
215+
216+
function test_blocking {
217+
res=$($@)
218+
local status=$?
219+
if [ $status -ne 0 ]; then
220+
return $status
221+
else
222+
echo "$res"
223+
if [[ "$res" == *"blocking"* ]]; then
224+
return $status
225+
else
226+
echo "expected port state blocking"
227+
return 1
228+
fi
229+
fi
230+
return $status
231+
}
232+
233+
function test_block {
234+
res=$($@)
235+
local status=$?
236+
if [ $status -ne 0 ]; then
237+
return $status
238+
else
239+
echo "$res"
240+
if [[ "$res" == *"BLOCK"* ]]; then
241+
return $status
242+
else
243+
echo "expected port state blocking"
244+
return 1
245+
fi
246+
fi
247+
return $status
248+
}

0 commit comments

Comments
 (0)