forked from free5gc/free5gc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_ci.sh
executable file
·238 lines (199 loc) · 5.61 KB
/
test_ci.sh
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
#!/usr/bin/env bash
# Check OS
if [ -f /etc/os-release ]; then
# freedesktop.org and systemd
. /etc/os-release
OS=$NAME
VER=$VERSION_ID
else
# Fall back to uname, e.g. "Linux <version>", also works for BSD, etc.
OS=$(uname -s)
VER=$(uname -r)
echo "This Linux version is too old: $OS:$VER, we don't support!"
exit 1
fi
sudo -v
if [ $? == 1 ]
then
echo "Without root permission, you cannot run the test due to our test is using namespace"
exit 1
fi
while getopts 'o' OPT;
do
case $OPT in
o) DUMP_NS=True;;
esac
done
shift $(($OPTIND - 1))
TEST_POOL="TestRegistration|TestGUTIRegistration|TestServiceRequest|TestXnHandover|TestN2Handover|TestDeregistration|TestPDUSessionReleaseRequest|TestPaging|TestNon3GPP|TestReSynchronization|TestDuplicateRegistration|TestEAPAKAPrimeAuthentication|TestMultiAmfRegistration|TestNasReroute"
if [[ ! "$1" =~ $TEST_POOL ]]
then
echo "Usage: $0 [ ${TEST_POOL//|/ | } ]"
exit 1
fi
GOPATH=$HOME/go
if [ $OS == "Ubuntu" ]; then
GOROOT=/usr/local/go
elif [ $OS == "Fedora" ]; then
GOROOT=/usr/lib/golang
fi
PATH=$PATH:$GOPATH/bin:$GOROOT/bin
UPFNS="UPFns"
EXEC_UPFNS="sudo -E ip netns exec ${UPFNS}"
export GIN_MODE=release
function terminate()
{
sleep 3
sudo killall -15 upf
if [ ${DUMP_NS} ]
then
# kill all tcpdump processes in the default network namespace
sudo killall tcpdump
sleep 1
fi
sudo ip link del veth0
sudo ip netns del ${UPFNS}
sudo ip addr del 10.60.0.1/32 dev lo
if [[ "$1" == "TestNon3GPP" ]]
then
if [ ${DUMP_NS} ]
then
cd .. && sudo ip xfrm state > ${PCAP_PATH}/NWu_SA_state.log
fi
sudo ip xfrm policy flush
sudo ip xfrm state flush
sudo ip netns del ${UENS}
removeN3iwfInterfaces
sudo ip link del veth2
sudo killall n3iwf
killall test.test
fi
if [[ "$1" == "TestMultiAmfRegistration" ]]
then
cd .. && ./force_kill.sh
fi
if [[ "$1" == "TestNasReroute" ]]
then
cd .. && ./force_kill.sh
fi
sleep 5
}
function removeN3iwfInterfaces()
{
# Remove all GRE interfaces
GREs=$(ip link show type gre | awk 'NR%2==1 {print $2}' | cut -d @ -f 1)
for GRE in ${GREs}; do
sudo ip link del ${GRE}
done
# Remove all XFRM interfaces
XFRMIs=$(ip link show type xfrm | awk 'NR%2==1 {print $2}' | cut -d @ -f 1)
for XFRMI in ${XFRMIs}; do
sudo ip link del ${XFRMI}
done
}
function handleSIGINT()
{
echo -e "\033[41;37m Terminating due to SIGINT ... \033[0m"
terminate $1
}
trap handleSIGINT SIGINT
function setupN3ueEnv()
{
UENS="UEns"
EXEC_UENS="sudo -E ip netns exec ${UENS}"
sudo ip netns add ${UENS}
sudo ip link add veth2 type veth peer name veth3
sudo ip addr add 192.168.127.1/24 dev veth2
sudo ip link set veth2 up
sudo ip link set veth3 netns ${UENS}
${EXEC_UENS} ip addr add 192.168.127.2/24 dev veth3
${EXEC_UENS} ip link set lo up
${EXEC_UENS} ip link set veth3 up
${EXEC_UENS} ip a
}
function tcpdumpN3IWF()
{
N3IWF_IPSec_iface_addr=192.168.127.1
N3IWF_IPsec_inner_addr=10.0.0.1
N3IWF_GTP_addr=10.200.200.2
UE_DN_addr=10.60.0.1
${EXEC_UENS} tcpdump -U -i any -w $PCAP_PATH/$UENS.pcap &
TCPDUMP_QUERY=" host $N3IWF_IPSec_iface_addr or \
host $N3IWF_IPsec_inner_addr or \
host $N3IWF_GTP_addr or \
host $UE_DN_addr"
sudo -E tcpdump -U -i any $TCPDUMP_QUERY -w $PCAP_PATH/n3iwf.pcap &
}
# Setup network namespace
sudo ip netns add ${UPFNS}
sudo ip link add veth0 type veth peer name veth1
sudo ip link set veth0 up
sudo ip addr add 10.60.0.1 dev lo
sudo ip addr add 10.200.200.1/24 dev veth0
sudo ip addr add 10.200.200.2/24 dev veth0
sudo ip link set veth1 netns ${UPFNS}
${EXEC_UPFNS} ip link set lo up
${EXEC_UPFNS} ip link set veth1 up
${EXEC_UPFNS} ip addr add 10.60.0.101 dev lo
${EXEC_UPFNS} ip addr add 10.200.200.101/24 dev veth1
${EXEC_UPFNS} ip addr add 10.200.200.102/24 dev veth1
if [ ${DUMP_NS} ]
then
PCAP_PATH=testpcap
mkdir -p ${PCAP_PATH}
${EXEC_UPFNS} tcpdump -U -i any -w ${PCAP_PATH}/${UPFNS}.pcap &
sudo -E tcpdump -U -i lo -w ${PCAP_PATH}/default_ns.pcap &
fi
${EXEC_UPFNS} ./bin/upf -c ./config/upfcfg.test.yaml &
sleep 2
if [[ "$1" == "TestNon3GPP" ]]
then
removeN3iwfInterfaces
# setup N3UE's namespace, interfaces for IPsec
setupN3ueEnv
if [ ${DUMP_NS} ]
then
tcpdumpN3IWF
fi
# Run CN
cd test && go test -v -vet=off -timeout 0 -run TestCN -args $2 &
sleep 10
# Run N3IWF
sudo -E ./bin/n3iwf -c ./config/n3iwfcfg.test.yaml &
sleep 5
# Run Test UE
cd test
if ! go test -v -vet=off -timeout 0 -run TestNon3GPPUE -args noinit $2; then
echo "Test result: Failed"
terminate $1
exit 1
else
echo "Test result: Succeeded"
fi
elif [[ "$1" == "TestMultiAmfRegistration" ]]
then
./bin/amf -c ./config/multiAMF/amfcfg.yaml &
sleep 0.1
./bin/amf -c ./config/multiAMF/amfcfg2.yaml &
sleep 0.1
cd test
$GOROOT/bin/go test -v -vet=off -run TestMultiAmfRegistration -args multiAmf $2
elif [[ "$1" == "TestNasReroute" ]]
then
./bin/amf -c ./config/multiAMF/amfcfg.yaml &
sleep 0.1
./bin/amf -c ./config/multiAMF/amfcfg2.yaml &
sleep 0.1
cd test
$GOROOT/bin/go test -v -vet=off -run TestNasReroute -args multiAmf $2
else
cd test
if ! go test -v -vet=off -run $1 -args $2; then
echo "Test result: Failed"
terminate $1
exit 1
else
echo "Test result: Succeeded"
fi
fi
terminate $1