-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrun.sh
executable file
·219 lines (209 loc) · 5.33 KB
/
run.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
#!/bin/bash
VERSION="f2.4.0-En-3"
IMAGEList=("oam" "nat" "amf" "smf" "pcf" "upf" "nrf")
IMAGEListSize=${#IMAGEList[@]}
createComponentConf()
{
rm $runPath/conf/component.conf
for ((IMAGEIndex=2; IMAGEIndex<$IMAGEListSize; IMAGEIndex++));do
cat >> $runPath/conf/component.conf <<- EOFComponent
${IMAGEList[$IMAGEIndex]^^} =
{
Image = "iii5gc/iii${IMAGEList[$IMAGEIndex]}:$VERSION";
Name = "iii${IMAGEList[$IMAGEIndex]^^}";
Ip = "192.168.6.$[ $IMAGEIndex + 1]";
status = "stop";
};
EOFComponent
done
}
rmImage()
{
for ((IMAGEIndex=0; IMAGEIndex<$IMAGEListSize; IMAGEIndex++));do
docker rmi iii5gc/iii${IMAGEList[$IMAGEIndex]}:$VERSION
done
}
checkNicIpReady()
{
for interfaceName in $NIC1 $NIC2
do
if [[ -z `ip link show |grep "$interfaceName"` ]]; then
echo "Interface $interfaceName is not exist"
exit
else
if [[ `ethtool $interfaceName|grep "Link detected:"|awk '{print $(NF)}'` == "no" ]]; then
echo "please enable $interfaceName"
exit
fi
fi
done
}
#createOamMacvlan()
#{
# echo "create macvlan name $SN"
## docker network create -d macvlan --subnet=$NsbiCIDR --gateway=$sbiGW -o parent=$NIC1 $SN
#}
#
#createNatAndConnect()
#{
# echo "create macvlan name $NN"
## docker network create -d macvlan --subnet=$NatCIDR --gateway=$NGW -o parent=$NIC2 $NN
#}
pullOAMImage()
{
for ((IMAGEIndex=0; IMAGEIndex<$IMAGEListSize; IMAGEIndex++));do
docker pull iii5gc/iii${IMAGEList[$IMAGEIndex]}:$VERSION
done
}
installRequire()
{
apt update -y
apt install docker.io docker-compose -y
}
enableOAM()
{
cat > ./docker-compose.yml <<-EOF
version: '2'
services:
oam:
container_name: oam
image: iii5gc/iii${IMAGEList[0]}:$VERSION
privileged: true
networks:
sbiNetwork:
ipv4_address: $OamIp
volumes:
- $runPath/conf:/home/iii/conf
- /usr/bin/docker:/usr/bin/docker
- /var/run/docker.sock:/var/run/docker.sock
environment:
FLASK_ENV: development
mountPath: $runPath/conf
sbiName: sbiNetwork
n6Name: n6NatBridge
natcontainer:
container_name: natcontainer
image: iii5gc/iii${IMAGEList[1]}:$VERSION
privileged: true
networks:
n6NatBridge:
ipv4_address: 10.254.254.7
natNetwork:
ipv4_address: $NatIp
volumes:
- /home/VEPClogs:/root/VEPClogsOnHost
environment:
NatIp: $NatIp
NatGw: $NGW
networks:
sbiNetwork:
driver: macvlan
driver_opts:
parent: $NIC1
ipam:
config:
- subnet: "$NsbiCIDR"
gateway: "$sbiGW"
natNetwork:
driver: macvlan
driver_opts:
parent: $NIC2
ipam:
config:
- subnet: "$NatCIDR"
gateway: "$NGW"
n6NatBridge:
driver: bridge
ipam:
driver: default
config:
- subnet: "10.254.254.0/24"
EOF
docker-compose -f ./docker-compose.yml up -d
}
usage()
{
echo "usage: ./OAMinit.sh [-nic1 NameOfSbiInterface ex: eth0] [-nic2 NameOfNatInterface ex: eth5] "
echo " [-oamIp OamIpInNsbi ex: x.x.x.x] [-sbi sbiIpCIDR ex: x.x.x.x/x] [-sbiGw nsbiGateway ex: x.x.x.x]"
echo " [-natIp WanIpForNat ex: x.x.x.x] [-nat natCIDR ex: x.x.x.x/x] [-natGw natGateway ex: x.x.x.x]"
echo ""
echo " [-k killAllContainerAndNetwork]"
echo " [-l listCurrentContainer]"
echo " [-ln listCurrentNetowkr]"
echo " [-i installRequirement] [-h help]"
}
if [ $# -eq 0 ]; then
usage
exit
elif [ $# -eq 1 ]; then
while [ "$1" != "" ]; do
case $1 in
-i | --installRequirement) installRequire
exit
;;
-h | --help ) usage
exit
;;
-k | --killdown) docker-compose down
exit
;;
-ki | --killImage) docker-compose down
rmImage
exit
;;
-ln | --list ) docker network ls
exit
;;
-l | --list ) docker ps -a
exit
;;
* ) usage
exit 1
esac
done
elif [ $# -ne 16 ]; then # if combinations of key and value are not 16
usage
exit
else
while [ "$1" != "" ]; do
case $1 in
-d | --deamom ) DEAMON="true"
;;
-nic1 | --nic1name ) shift
NIC1=$1
;;
-oamIp | --sbiIpCIDR ) shift
OamIp=$1
;;
-sbi | --sbiIpCIDR ) shift
NsbiCIDR=$1
;;
-sbiGw | --OamNsbiGW) shift
sbiGW=$1
;;
-nic2 | --nic2name ) shift
NIC2=$1
;;
-natIp | --natIp ) shift
NatIp=$1
;;
-nat | --natIpCIDR ) shift
NatCIDR=$1
;;
-natGw | --NatGW) shift
NGW=$1
;;
* ) usage
exit 1
esac
shift
done
runPath=`cd ./5gc_oam; pwd`
# confPath=`cd ./conf; pwd`
checkNicIpReady
createComponentConf
#createOamMacvlan
#createNatAndConnect
pullOAMImage
enableOAM
fi